diff --git a/.gitignore b/.gitignore index ef4abeb..8fcfb2a 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ Makefile /tests/too-many-strtab /tests/big-dynstr* /tests/main-scoped +/tests/libbig-dynstr.debug diff --git a/src/patchelf.cc b/src/patchelf.cc index 4b7ef43..3ca16c7 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -1330,6 +1330,11 @@ void ElfFile::modifyRPath(RPathOp op, { auto shdrDynamic = findSection(".dynamic"); + if (rdi(shdrDynamic.sh_type) == SHT_NOBITS) { + debug("no dynamic section\n"); + return; + } + /* !!! We assume that the virtual address in the DT_STRTAB entry of the dynamic section corresponds to the .dynstr section. */ auto shdrDynStr = findSection(".dynstr"); diff --git a/tests/Makefile.am b/tests/Makefile.am index 2196401..90fe906 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,7 @@ LIBS = +STRIP ?= strip + check_PROGRAMS = simple main too-many-strtab main-scoped big-dynstr no-rpath contiguous-note-sections no_rpath_arch_TESTS = \ @@ -32,7 +34,8 @@ src_TESTS = \ invalid-elf.sh \ endianness.sh \ contiguous-note-sections.sh \ - no-gnu-hash.sh + no-gnu-hash.sh \ + no-dynamic-section.sh build_TESTS = \ $(no_rpath_arch_TESTS) @@ -73,13 +76,23 @@ main_scoped_LDFLAGS = $(LDFLAGS_local) big-dynstr.c: main.c cat $< > big-dynstr.c - for i in $$(seq 1 2000); do echo "void f$$i(void) { };" >> big-dynstr.c; done + for i in $$(seq 1 2000); do echo "void f$$i(void) { };"; done >> big-dynstr.c nodist_big_dynstr_SOURCES = big-dynstr.c big_dynstr_LDADD = -lfoo $(AM_LDADD) big_dynstr_DEPENDENCIES = libfoo.so big_dynstr_LDFLAGS = $(LDFLAGS_local) +# somehow bug does not trigger if we use +# normal autotools rules to build the program: +# https://github.com/NixOS/patchelf/pull/303 +libbig-dynstr.so: big-dynstr.c + $(CC) -fPIC -shared -o $@ $< +libbig-dynstr.debug: libbig-dynstr.so + $(STRIP) --only-keep-debug libbig-dynstr.so -o libbig-dynstr.debug +check_DATA = libbig-dynstr.debug + + # declare local shared libraries as programs as: # - without libtool, only archives (static libraries) can be built by automake # - with libtool, it is difficult to control options diff --git a/tests/no-dynamic-section.sh b/tests/no-dynamic-section.sh new file mode 100755 index 0000000..3e74b38 --- /dev/null +++ b/tests/no-dynamic-section.sh @@ -0,0 +1,4 @@ +#! /bin/sh -e + +# print rpath on library with stripped dynamic section +../src/patchelf --print-rpath libbig-dynstr.debug