Uploaded image for project: 'Libmongocrypt'
  1. Libmongocrypt
  2. MONGOCRYPT-294

Build static libs with -fPIC by default

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.1.0
    • Affects Version/s: None
    • Component/s: C library
    • None

      Though the homebrew package for libmongocrypt works on macOS, it receives an error on Linux:

      brew install mongodb/brew/libmongocrypt
      

      Results in this error:

      [ 90%] Building C object CMakeFiles/test-mongocrypt.dir/test/test-mongocrypt-ctx-decrypt.c.o
      /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-5 -DBSON_STATIC -DKMS_MSG_STATIC -DMONGOCRYPT_STATIC_DEFINE -I/tmp/libmongocrypt-20201114-12769-nbi6q6/libmongocrypt-1.0.4/./src -I/tmp/libmongocrypt-20201114-12769-nbi6q6/libmongocrypt-1.0.4/kms-message/src -I/tmp/libmongocrypt-20201114-12769-nbi6q6/libmongocrypt-1.0.4/src -isystem /home/linuxbrew/.linuxbrew/include/libbson-1.0 -Wall -Werror -Wno-missing-braces -DNDEBUG -fPIC -std=gnu99 -o CMakeFiles/test-mongocrypt.dir/test/test-mongocrypt-ctx-decrypt.c.o -c /tmp/libmongocrypt-20201114-12769-nbi6q6/libmongocrypt-1.0.4/test/test-mongocrypt-ctx-decrypt.c
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_b64.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_decrypt_request.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_encrypt_request.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_request.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_request_str.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_response_parser.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(hexlify.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /home/linuxbrew/.linuxbrew/bin/ld: kms-message/libkms_message-static.a(kms_kv_list.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      collect2: error: ld returned 1 exit status
      CMakeFiles/mongocrypt.dir/build.make:518: recipe for target 'libmongocrypt.so.0.0.0' failed
      make[2]: *** [libmongocrypt.so.0.0.0] Error 1
      

      This is because the package formula does not include the -fPIC compiler flag, so the static KMS message library does not link into libmongocrypt.

      The formula could be modified to include -fPIC, as the libmongocrypt readme instructs, but I think a better solution is to enable -fPIC by default on the static libraries built (as was done in CDRIVER-3225.

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: