[MONGOCRYPT-294] Build static libs with -fPIC by default Created: 14/Nov/20  Updated: 28/Oct/23  Resolved: 14/Nov/20

Status: Closed
Project: Libmongocrypt
Component/s: C library
Affects Version/s: None
Fix Version/s: 1.1.0

Type: Improvement Priority: Major - P3
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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.



 Comments   
Comment by Githook User [ 14/Nov/20 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: MONGOCRYPT-294 build with -fPIC by default (#137)
Branch: master
https://github.com/mongodb/libmongocrypt/commit/3755e98b2e8258c24ed2bdfc3d2bac324f25caaf

Comment by Kevin Albertson [ 14/Nov/20 ]

PR: https://github.com/mongodb/libmongocrypt/pull/137

Generated at Thu Feb 08 09:08:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.