diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-05-28 12:29:23 (GMT) |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-05-28 12:29:23 (GMT) |
commit | dd00c212272e6871983421a480475becc3cdbd40 (patch) | |
tree | 10885e50c4b7783d516e271f7ac726cc9a0fb479 /tests | |
parent | 36f96d03dba4a3bf19a3a228786aac5e69ea85d2 (diff) | |
download | patchelf-dd00c212272e6871983421a480475becc3cdbd40.zip patchelf-dd00c212272e6871983421a480475becc3cdbd40.tar.gz patchelf-dd00c212272e6871983421a480475becc3cdbd40.tar.bz2 |
* A test for setting the rpath on a library.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 22 | ||||
-rwxr-xr-x | tests/set-rpath-library.sh | 57 | ||||
-rwxr-xr-x | tests/set-rpath.sh | 10 |
3 files changed, 74 insertions, 15 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 5772fbb..668ec31 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,8 @@ -check_PROGRAMS = main simple big-dynstr +check_PROGRAMS = main main-scoped simple big-dynstr TESTS = plain-fail.sh plain-run.sh shrink-rpath.sh set-interpreter-short.sh \ - set-interpreter-long.sh set-rpath.sh no-rpath.sh big-dynstr.sh + set-interpreter-long.sh set-rpath.sh no-rpath.sh big-dynstr.sh \ + set-rpath-library.sh TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 @@ -10,19 +11,28 @@ simple_SOURCES = simple.c main: main.o libfoo.so - LD_LIBRARY_PATH=. gcc -o main main.o -L . -lfoo + LD_LIBRARY_PATH=. gcc -Wl,--disable-new-dtags -o main main.o -L . -lfoo + +main-scoped: main.o libfoo-scoped.so + LD_LIBRARY_PATH=. gcc -Wl,--enable-new-dtags -o main-scoped main.o -L . -lfoo-scoped main.o: main.c $(CC) -fpic -o main.o -c main.c libfoo.so: foo.o libbar.so - $(CC) -shared -o libfoo.so foo.o -L . -lbar + NIX_DONT_SET_RPATH=1 $(CC) -Wl,--disable-new-dtags -shared -o libfoo.so foo.o -L . -lbar + +libfoo-scoped.so: foo.o libbar-scoped.so + NIX_DONT_SET_RPATH=1 $(CC) -Wl,--enable-new-dtags -shared -o libfoo-scoped.so foo.o -L . -lbar-scoped foo.o: foo.c $(CC) -fpic -o foo.o -c foo.c libbar.so: bar.o - NIX_DONT_SET_RPATH=1 $(CC) -shared -o libbar.so bar.o -L . -Wl,-rpath,`pwd`/no-such-path + NIX_DONT_SET_RPATH=1 $(CC) -Wl,--disable-new-dtags -shared -o libbar.so bar.o -L . -Wl,-rpath,`pwd`/no-such-path + +libbar-scoped.so: bar.o + NIX_DONT_SET_RPATH=1 $(CC) -Wl,--enable-new-dtags -shared -o libbar-scoped.so bar.o bar.o: bar.c $(CC) -fpic -o bar.o -c bar.c @@ -31,7 +41,7 @@ bar.o: bar.c big_dynstr_SOURCES = big-dynstr.c big-dynstr: big-dynstr.o libfoo.so - LD_LIBRARY_PATH=. gcc -o big-dynstr big-dynstr.o -L . -lfoo + LD_LIBRARY_PATH=. gcc -Wl,--disable-new-dtags -o big-dynstr big-dynstr.o -L . -lfoo big-dynstr.c: main.c cat main.c > big-dynstr.c diff --git a/tests/set-rpath-library.sh b/tests/set-rpath-library.sh new file mode 100755 index 0000000..9800d0e --- /dev/null +++ b/tests/set-rpath-library.sh @@ -0,0 +1,57 @@ +#! /bin/sh -e + +rm -rf scratch +mkdir -p scratch +mkdir -p scratch/libsA +mkdir -p scratch/libsB + +cp main-scoped scratch/ +cp libfoo-scoped.so scratch/libsA/ +cp libbar-scoped.so scratch/libsB/ + +oldRPath=$(../src/patchelf --print-rpath scratch/main-scoped) +if test -z "$oldRPath"; then oldRPath="/oops"; fi +../src/patchelf --force-rpath --set-rpath $oldRPath:$(pwd)/scratch/libsA:$(pwd)/scratch/libsB scratch/main-scoped + +#oldRPath=$(../src/patchelf --print-rpath scratch/libsB/libbar.so) +#if test -z "$oldRPath"; then oldRPath="/oops"; fi +#../src/patchelf --set-rpath $oldRPath:$(pwd)/scratch/libsC scratch/libsB/libbar.so + +# "main" contains libbar in its RUNPATH, but that's ignored when +# resolving libfoo. So libfoo won't find libbar and this will fail. +exitCode=0 +(cd scratch && ./main-scoped) || exitCode=$? + +if test "$exitCode" = 46; then + echo "expected failure" + exit 1 +fi + +# So set an RUNPATH on libfoo as well. +oldRPath=$(../src/patchelf --print-rpath scratch/libsA/libfoo-scoped.so) +if test -z "$oldRPath"; then oldRPath="/oops"; fi +../src/patchelf --set-rpath $oldRPath:$(pwd)/scratch/libsB scratch/libsA/libfoo-scoped.so + +exitCode=0 +(cd scratch && ./main-scoped) || exitCode=$? + +if test "$exitCode" != 46; then + echo "bad exit code!" + exit 1 +fi + +# Remove the libbar PATH from main using --shrink-rpath. +../src/patchelf --shrink-rpath scratch/main-scoped +if ../src/patchelf --print-rpath scratch/main-scoped | grep /libsB; then + echo "shrink failed" + exit 1 +fi + +# And it should still run. +exitCode=0 +(cd scratch && ./main-scoped) || exitCode=$? + +if test "$exitCode" != 46; then + echo "bad exit code!" + exit 1 +fi diff --git a/tests/set-rpath.sh b/tests/set-rpath.sh index 999acb4..b797017 100755 --- a/tests/set-rpath.sh +++ b/tests/set-rpath.sh @@ -13,20 +13,12 @@ oldRPath=$(../src/patchelf --print-rpath scratch/main) if test -z "$oldRPath"; then oldRPath="/oops"; fi ../src/patchelf --force-rpath --set-rpath $oldRPath:$(pwd)/scratch/libsA:$(pwd)/scratch/libsB scratch/main -#oldRPath=$(../src/patchelf --print-rpath scratch/libsA/libfoo.so) -#if test -z "$oldRPath"; then oldRPath="/oops"; fi -#../src/patchelf --set-rpath $oldRPath:$(pwd)/scratch/libsB scratch/libsA/libfoo.so - -#oldRPath=$(../src/patchelf --print-rpath scratch/libsB/libbar.so) -#if test -z "$oldRPath"; then oldRPath="/oops"; fi -#../src/patchelf --set-rpath $oldRPath:$(pwd)/scratch/libsC scratch/libsB/libbar.so - if test "$(uname)" = FreeBSD; then export LD_LIBRARY_PATH=$(pwd)/scratch/libsB fi exitCode=0 -cd scratch && ./main || exitCode=$? +(cd scratch && ./main) || exitCode=$? if test "$exitCode" != 46; then echo "bad exit code!" |