File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -1030,6 +1030,18 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
10301030
10311031 firstPage -= neededPages * getPageSize ();
10321032 startOffset += neededPages * getPageSize ();
1033+ } else {
1034+ Elf_Off rewrittenSectionsOffset = sizeof (Elf_Ehdr) + phdrs.size () * sizeof (Elf_Phdr);
1035+ for (auto & phdr : phdrs)
1036+ if (rdi (phdr.p_type ) == PT_LOAD &&
1037+ rdi (phdr.p_offset ) <= rewrittenSectionsOffset &&
1038+ rdi (phdr.p_offset ) + rdi (phdr.p_filesz ) > rewrittenSectionsOffset &&
1039+ rdi (phdr.p_filesz ) < neededSpace)
1040+ {
1041+ wri (phdr.p_filesz , neededSpace);
1042+ wri (phdr.p_memsz , neededSpace);
1043+ break ;
1044+ }
10331045 }
10341046
10351047
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ src_TESTS = \
5050 rename-dynamic-symbols.sh \
5151 overlapping-segments-after-rounding.sh \
5252 shared-rpath.sh \
53+ short-first-segment.sh \
5354 empty-note.sh
5455
5556build_TESTS = \
@@ -58,7 +59,7 @@ build_TESTS = \
5859TESTS = $(src_TESTS ) $(build_TESTS )
5960
6061EXTRA_DIST = no-rpath-prebuild $(src_TESTS ) no-rpath-prebuild.sh invalid-elf endianness empty-note \
61- overlapping-segments-after-rounding
62+ overlapping-segments-after-rounding short-first-segment.gz
6263
6364TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 STRIP=$(STRIP ) OBJDUMP=$(OBJDUMP ) READELF=$(READELF ) OBJCOPY=$(OBJCOPY )
6465
Original file line number Diff line number Diff line change 1+ #! /bin/sh -e
2+
3+ PATCHELF=$( readlink -f " ../src/patchelf" )
4+ SCRATCH=" scratch/$( basename " $0 " .sh) "
5+ READELF=${READELF:- readelf}
6+
7+ EXEC_NAME=" short-first-segment"
8+
9+ if ! gzip --version > /dev/null; then
10+ echo " skipping test: gzip not found"
11+ exit 77
12+ fi
13+
14+ if test " $( uname -i) " ! = x86_64 || test " $( uname) " ! = Linux; then
15+ echo " skipping test: not supported on x86_64 Linux"
16+ exit 77
17+ fi
18+
19+ rm -rf " ${SCRATCH} "
20+ mkdir -p " ${SCRATCH} "
21+
22+ gzip -c -d " ${srcdir:? } /${EXEC_NAME} .gz" > " ${SCRATCH} /${EXEC_NAME} "
23+ cd " ${SCRATCH} "
24+
25+ ldd " ${EXEC_NAME} "
26+
27+ ${PATCHELF} --add-rpath lalalalalalalala --output modified1 " ${EXEC_NAME} "
28+ ldd modified1
29+
30+ ${PATCHELF} --add-needed " libXcursor.so.1" --output modified2 modified1
31+ ldd modified2
You can’t perform that action at this time.
0 commit comments