From 94f38d26bce27c813858223f9c3818b7435438e7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 31 Jan 2007 15:08:42 +0000 Subject: * .rel.plt is called .rela.plt on x86_64-linux. --- src/patchelf.cc | 8 ++++++-- tests/Makefile.am | 2 +- tests/shrink-rpath.sh | 30 ++++++++++++++++++++++++++++++ tests/shrink.sh | 22 ---------------------- 4 files changed, 37 insertions(+), 25 deletions(-) create mode 100755 tests/shrink-rpath.sh delete mode 100755 tests/shrink.sh diff --git a/src/patchelf.cc b/src/patchelf.cc index 9dba988..4e84877 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -480,8 +480,12 @@ void ElfFile::rewriteSections() dyn->d_un.d_ptr = findSection(".dynsym").sh_addr; else if (dyn->d_tag == DT_HASH) dyn->d_un.d_ptr = findSection(".hash").sh_addr; - else if (dyn->d_tag == DT_JMPREL) - dyn->d_un.d_ptr = findSection(".rel.plt").sh_addr; + else if (dyn->d_tag == DT_JMPREL) { + Elf_Shdr * shdr = findSection2(".rel.plt"); + if (!shdr) shdr = findSection2(".rela.plt"); /* 64-bit Linux */ + if (!shdr) error("cannot find .rel.plt or .rela.plt"); + dyn->d_un.d_ptr = shdr->sh_addr; + } else if (dyn->d_tag == DT_REL) { /* !!! hack! */ Elf_Shdr * shdr = findSection2(".rel.dyn"); /* no idea if this makes sense, but it was needed for some diff --git a/tests/Makefile.am b/tests/Makefile.am index 1b8baba..5772fbb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ check_PROGRAMS = main simple big-dynstr -TESTS = plain-fail.sh plain-run.sh shrink.sh set-interpreter-short.sh \ +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 TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 diff --git a/tests/shrink-rpath.sh b/tests/shrink-rpath.sh new file mode 100755 index 0000000..e0c82c1 --- /dev/null +++ b/tests/shrink-rpath.sh @@ -0,0 +1,30 @@ +#! /bin/sh -e + +rpath=$(../src/patchelf --print-rpath ./libbar.so) +echo "RPATH before: $rpath" +if ! echo "$rpath" | grep -q /no-such-path; then + echo "incomplete RPATH" + exit 1 +fi + +rm -rf scratch +mkdir -p scratch +cp libbar.so scratch/ +../src/patchelf --shrink-rpath scratch/libbar.so + +rpath=$(../src/patchelf --print-rpath scratch/libbar.so) +echo "RPATH after: $rpath" +if echo "$rpath" | grep -q /no-such-path; then + echo "RPATH not shrunk" + exit 1 +fi + +cp libfoo.so scratch/ + +exitCode=0 +cd scratch && LD_LIBRARY_PATH=. ../main || exitCode=$? + +if test "$exitCode" != 46; then + echo "bad exit code!" + exit 1 +fi diff --git a/tests/shrink.sh b/tests/shrink.sh deleted file mode 100755 index a60911c..0000000 --- a/tests/shrink.sh +++ /dev/null @@ -1,22 +0,0 @@ -#! /bin/sh -e - -rpath=$(../src/patchelf --print-rpath ./libbar.so) -echo "RPATH before: $rpath" -if ! echo "$rpath" | grep -q /no-such-path; then - echo "incomplete RPATH" - exit 1 -fi - -rm -rf scratch -mkdir -p scratch -cp libbar.so scratch/ -../src/patchelf --shrink-rpath scratch/libbar.so - -rpath=$(../src/patchelf --print-rpath scratch/libbar.so) -echo "RPATH after: $rpath" -if echo "$rpath" | grep -q /no-such-path; then - echo "RPATH not shrunk" - exit 1 -fi - -LD_LIBRARY_PATH=. ./main -- cgit v0.12