File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -1106,9 +1106,12 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
11061106 dyn->d_un .d_ptr = findSection (" .dynsym" ).sh_addr ;
11071107 else if (d_tag == DT_HASH)
11081108 dyn->d_un .d_ptr = findSection (" .hash" ).sh_addr ;
1109- else if (d_tag == DT_GNU_HASH)
1110- dyn->d_un .d_ptr = findSection (" .gnu.hash" ).sh_addr ;
1111- else if (d_tag == DT_JMPREL) {
1109+ else if (d_tag == DT_GNU_HASH) {
1110+ auto shdr = findSection2 (" .gnu.hash" );
1111+ // some binaries might this section stripped
1112+ // in which case we just ignore the value.
1113+ if (shdr) dyn->d_un .d_ptr = shdr->sh_addr ;
1114+ } else if (d_tag == DT_JMPREL) {
11121115 auto shdr = findSection2 (" .rel.plt" );
11131116 if (!shdr) shdr = findSection2 (" .rela.plt" ); /* 64-bit Linux, x86-64 */
11141117 if (!shdr) shdr = findSection2 (" .rela.IA_64.pltoff" ); /* 64-bit Linux, IA-64 */
Original file line number Diff line number Diff line change @@ -30,7 +30,8 @@ src_TESTS = \
3030 build-id.sh \
3131 invalid-elf.sh \
3232 endianness.sh \
33- contiguous_note_sections.sh
33+ contiguous_note_sections.sh \
34+ no-gnu-hash.sh
3435
3536build_TESTS = \
3637 $(no_rpath_arch_TESTS )
Original file line number Diff line number Diff line change 1+ #! /bin/sh -e
2+ SCRATCH=scratch/$( basename $0 .sh)
3+
4+ rm -rf ${SCRATCH}
5+ mkdir -p ${SCRATCH}
6+
7+ cp simple ${SCRATCH} /
8+
9+ strip --remove-section=.gnu.hash ${SCRATCH} /simple
10+
11+ # Check if patchelf handles binaries with GNU_HASH in dynamic section but
12+ # without .gnu.hash section
13+ ../src/patchelf --set-interpreter /oops ${SCRATCH} /simple
You can’t perform that action at this time.
0 commit comments