Skip to content

Commit

Permalink
Disable overriding the dynamic symbols from other libraries
Browse files Browse the repository at this point in the history
This should allow using both libzstd-jni.so and libzstd.so from the same
process without zstd-jni using functions defined in libzstd.so.

We use a linker flag that affects only ELF platforms. From man ld:

-Bsymbolic

   When creating a shared library, bind references to global symbols to
   the definition within the shared library, if any.  Normally, it is
   possible for a program linked against a shared library to override
   the definition within the shared library.  This option is only
   meaningful on ELF platforms which support shared libraries.
  • Loading branch information
luben committed Oct 8, 2024
1 parent d82a029 commit 0c2051b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jniGccFlags := (
else
// the default is compilation with GCC
jniGccFlags.value ++ Seq(
"-static-libgcc", "-Wl,--version-script=" + PWD + "/libzstd-jni.so.map")
"-static-libgcc", "-Wl,--version-script=" + PWD + "/libzstd-jni.so.map", "-Wl,-Bsymbolic")
)

// Special case the jni platform header on windows (use the one from the repo)
Expand Down
2 changes: 1 addition & 1 deletion make_so.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ compile () {
scp -r src/main/native $HOST:
scp ./libzstd-jni.so.map $HOST:
fi
ssh $HOST 'export PATH=$HOME/bin:$PATH; '$CC' -Wl,--version-script=./libzstd-jni.so.map -shared -flto -fPIC -O3 -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -I/usr/include -I./jni -I./native -I./native/common -I./native/legacy -std=c99 -lpthread -o libzstd-jni-'$VERSION'.so native/*.c native/legacy/*.c native/common/*.c native/compress/*.c native/decompress/*.[cS] native/dictBuilder/*.c'
ssh $HOST 'export PATH=$HOME/bin:$PATH; '$CC' -Wl,--version-script=./libzstd-jni.so.map -Wl,-Bsymbolic -shared -flto -fPIC -O3 -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -I/usr/include -I./jni -I./native -I./native/common -I./native/legacy -std=c99 -lpthread -o libzstd-jni-'$VERSION'.so native/*.c native/legacy/*.c native/common/*.c native/compress/*.c native/decompress/*.[cS] native/dictBuilder/*.c'
mkdir -p $INSTALL
scp $HOST:libzstd-jni-$VERSION.so $INSTALL
}
Expand Down
2 changes: 1 addition & 1 deletion make_so_cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ compile() {
rsync ./libzstd-jni.so.map $BUILD_DIR

pushd $BUILD_DIR
$CC -shared -static-libgcc -Wl,--version-script=./libzstd-jni.so.map -fPIC -O3 -flto -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -I/usr/include -I./jni -I./native -I./native/common -I./native/legacy -std=c99 -lpthread -o libzstd-jni-$VERSION.so native/*.c native/legacy/*.c native/common/*.c native/compress/*.c native/decompress/*.c native/dictBuilder/*.c
$CC -shared -static-libgcc -Wl,--version-script=./libzstd-jni.so.map -Wl,-Bsymbolic -fPIC -O3 -flto -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -I/usr/include -I./jni -I./native -I./native/common -I./native/legacy -std=c99 -lpthread -o libzstd-jni-$VERSION.so native/*.c native/legacy/*.c native/common/*.c native/compress/*.c native/decompress/*.c native/dictBuilder/*.c
popd

mkdir -p $INSTALL
Expand Down
2 changes: 1 addition & 1 deletion make_so_cross_buster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ compile() {
rsync ./libzstd-jni.so.map buster:$BUILD_DIR


ssh buster 'cd '$BUILD_DIR'; '$CC' -shared -static-libgcc -Wl,--version-script=./libzstd-jni.so.map -fPIC -O3 -flto -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -I/usr/include -I./jni -I./native -I./native/common -I./native/legacy -std=c99 -lpthread -o libzstd-jni-'$VERSION'.so native/*.c native/legacy/*.c native/common/*.c native/compress/*.c native/decompress/*.c native/dictBuilder/*.c'
ssh buster 'cd '$BUILD_DIR'; '$CC' -shared -static-libgcc -Wl,--version-script=./libzstd-jni.so.map -Wl,-Bsymbolic -fPIC -O3 -flto -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -I/usr/include -I./jni -I./native -I./native/common -I./native/legacy -std=c99 -lpthread -o libzstd-jni-'$VERSION'.so native/*.c native/legacy/*.c native/common/*.c native/compress/*.c native/decompress/*.c native/dictBuilder/*.c'

mkdir -p $INSTALL
rsync buster:$BUILD_DIR/libzstd-jni-$VERSION.so $INSTALL
Expand Down

0 comments on commit 0c2051b

Please sign in to comment.