Merge pull request #304 from NixOS/nobits

Don't try to parse .dynamic section of type NOBITS + test
This commit is contained in:
Jörg Thalheim 2021-08-23 20:12:47 +01:00 committed by GitHub
commit 38cb5c8e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

1
.gitignore vendored
View File

@ -29,3 +29,4 @@ Makefile
/tests/too-many-strtab /tests/too-many-strtab
/tests/big-dynstr* /tests/big-dynstr*
/tests/main-scoped /tests/main-scoped
/tests/libbig-dynstr.debug

View File

@ -1330,6 +1330,11 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
{ {
auto shdrDynamic = findSection(".dynamic"); 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 /* !!! We assume that the virtual address in the DT_STRTAB entry
of the dynamic section corresponds to the .dynstr section. */ of the dynamic section corresponds to the .dynstr section. */
auto shdrDynStr = findSection(".dynstr"); auto shdrDynStr = findSection(".dynstr");

View File

@ -1,5 +1,7 @@
LIBS = LIBS =
STRIP ?= strip
check_PROGRAMS = simple main too-many-strtab main-scoped big-dynstr no-rpath contiguous-note-sections check_PROGRAMS = simple main too-many-strtab main-scoped big-dynstr no-rpath contiguous-note-sections
no_rpath_arch_TESTS = \ no_rpath_arch_TESTS = \
@ -32,7 +34,8 @@ src_TESTS = \
invalid-elf.sh \ invalid-elf.sh \
endianness.sh \ endianness.sh \
contiguous-note-sections.sh \ contiguous-note-sections.sh \
no-gnu-hash.sh no-gnu-hash.sh \
no-dynamic-section.sh
build_TESTS = \ build_TESTS = \
$(no_rpath_arch_TESTS) $(no_rpath_arch_TESTS)
@ -73,13 +76,23 @@ main_scoped_LDFLAGS = $(LDFLAGS_local)
big-dynstr.c: main.c big-dynstr.c: main.c
cat $< > big-dynstr.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 nodist_big_dynstr_SOURCES = big-dynstr.c
big_dynstr_LDADD = -lfoo $(AM_LDADD) big_dynstr_LDADD = -lfoo $(AM_LDADD)
big_dynstr_DEPENDENCIES = libfoo.so big_dynstr_DEPENDENCIES = libfoo.so
big_dynstr_LDFLAGS = $(LDFLAGS_local) 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: # declare local shared libraries as programs as:
# - without libtool, only archives (static libraries) can be built by automake # - without libtool, only archives (static libraries) can be built by automake
# - with libtool, it is difficult to control options # - with libtool, it is difficult to control options

4
tests/no-dynamic-section.sh Executable file
View File

@ -0,0 +1,4 @@
#! /bin/sh -e
# print rpath on library with stripped dynamic section
../src/patchelf --print-rpath libbig-dynstr.debug