Skip to content

Commit 38cb5c8

Browse files
authored
Merge pull request #304 from NixOS/nobits
Don't try to parse .dynamic section of type NOBITS + test
2 parents a4e4924 + 64fe89b commit 38cb5c8

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ Makefile
2929
/tests/too-many-strtab
3030
/tests/big-dynstr*
3131
/tests/main-scoped
32+
/tests/libbig-dynstr.debug

src/patchelf.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,11 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op,
13301330
{
13311331
auto shdrDynamic = findSection(".dynamic");
13321332

1333+
if (rdi(shdrDynamic.sh_type) == SHT_NOBITS) {
1334+
debug("no dynamic section\n");
1335+
return;
1336+
}
1337+
13331338
/* !!! We assume that the virtual address in the DT_STRTAB entry
13341339
of the dynamic section corresponds to the .dynstr section. */
13351340
auto shdrDynStr = findSection(".dynstr");

tests/Makefile.am

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
LIBS =
22

3+
STRIP ?= strip
4+
35
check_PROGRAMS = simple main too-many-strtab main-scoped big-dynstr no-rpath contiguous-note-sections
46

57
no_rpath_arch_TESTS = \
@@ -32,7 +34,8 @@ src_TESTS = \
3234
invalid-elf.sh \
3335
endianness.sh \
3436
contiguous-note-sections.sh \
35-
no-gnu-hash.sh
37+
no-gnu-hash.sh \
38+
no-dynamic-section.sh
3639

3740
build_TESTS = \
3841
$(no_rpath_arch_TESTS)
@@ -73,13 +76,23 @@ main_scoped_LDFLAGS = $(LDFLAGS_local)
7376

7477
big-dynstr.c: main.c
7578
cat $< > big-dynstr.c
76-
for i in $$(seq 1 2000); do echo "void f$$i(void) { };" >> big-dynstr.c; done
79+
for i in $$(seq 1 2000); do echo "void f$$i(void) { };"; done >> big-dynstr.c
7780

7881
nodist_big_dynstr_SOURCES = big-dynstr.c
7982
big_dynstr_LDADD = -lfoo $(AM_LDADD)
8083
big_dynstr_DEPENDENCIES = libfoo.so
8184
big_dynstr_LDFLAGS = $(LDFLAGS_local)
8285

86+
# somehow bug does not trigger if we use
87+
# normal autotools rules to build the program:
88+
# https://github.com/NixOS/patchelf/pull/303
89+
libbig-dynstr.so: big-dynstr.c
90+
$(CC) -fPIC -shared -o $@ $<
91+
libbig-dynstr.debug: libbig-dynstr.so
92+
$(STRIP) --only-keep-debug libbig-dynstr.so -o libbig-dynstr.debug
93+
check_DATA = libbig-dynstr.debug
94+
95+
8396
# declare local shared libraries as programs as:
8497
# - without libtool, only archives (static libraries) can be built by automake
8598
# - with libtool, it is difficult to control options

tests/no-dynamic-section.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/sh -e
2+
3+
# print rpath on library with stripped dynamic section
4+
../src/patchelf --print-rpath libbig-dynstr.debug

0 commit comments

Comments
 (0)