@@ -471,7 +471,7 @@ std::string ElfFile<ElfFileParamNames>::getSectionName(const Elf_Shdr & shdr) co
471
471
template <ElfFileParams>
472
472
Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sectionName)
473
473
{
474
- auto shdr = findSection2 (sectionName);
474
+ auto shdr = tryFindSectionHeader (sectionName);
475
475
if (!shdr) {
476
476
std::string extraMsg;
477
477
if (sectionName == " .interp" || sectionName == " .dynamic" || sectionName == " .dynstr" )
@@ -483,7 +483,7 @@ Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sec
483
483
484
484
485
485
template <ElfFileParams>
486
- std::optional<std::reference_wrapper<Elf_Shdr>> ElfFile<ElfFileParamNames>::findSection2 (const SectionName & sectionName)
486
+ std::optional<std::reference_wrapper<Elf_Shdr>> ElfFile<ElfFileParamNames>::tryFindSectionHeader (const SectionName & sectionName)
487
487
{
488
488
auto i = getSectionIndex (sectionName);
489
489
if (i)
@@ -967,7 +967,7 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
967
967
/* Update all those nasty virtual addresses in the .dynamic
968
968
section. Note that not all executables have .dynamic sections
969
969
(e.g., those produced by klibc's klcc). */
970
- auto shdrDynamic = findSection2 (" .dynamic" );
970
+ auto shdrDynamic = tryFindSectionHeader (" .dynamic" );
971
971
if (shdrDynamic) {
972
972
auto dyn_table = (Elf_Dyn *) (fileContents->data () + rdi ((*shdrDynamic).get ().sh_offset ));
973
973
unsigned int d_tag;
@@ -981,30 +981,30 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
981
981
else if (d_tag == DT_HASH)
982
982
dyn->d_un .d_ptr = findSectionHeader (" .hash" ).sh_addr ;
983
983
else if (d_tag == DT_GNU_HASH) {
984
- auto shdr = findSection2 (" .gnu.hash" );
984
+ auto shdr = tryFindSectionHeader (" .gnu.hash" );
985
985
// some binaries might this section stripped
986
986
// in which case we just ignore the value.
987
987
if (shdr) dyn->d_un .d_ptr = (*shdr).get ().sh_addr ;
988
988
} else if (d_tag == DT_JMPREL) {
989
- auto shdr = findSection2 (" .rel.plt" );
990
- if (!shdr) shdr = findSection2 (" .rela.plt" );
989
+ auto shdr = tryFindSectionHeader (" .rel.plt" );
990
+ if (!shdr) shdr = tryFindSectionHeader (" .rela.plt" );
991
991
/* 64-bit Linux, x86-64 */
992
- if (!shdr) shdr = findSection2 (" .rela.IA_64.pltoff" ); /* 64-bit Linux, IA-64 */
992
+ if (!shdr) shdr = tryFindSectionHeader (" .rela.IA_64.pltoff" ); /* 64-bit Linux, IA-64 */
993
993
if (!shdr) error (" cannot find section corresponding to DT_JMPREL" );
994
994
dyn->d_un .d_ptr = (*shdr).get ().sh_addr ;
995
995
}
996
996
else if (d_tag == DT_REL) { /* !!! hack! */
997
- auto shdr = findSection2 (" .rel.dyn" );
997
+ auto shdr = tryFindSectionHeader (" .rel.dyn" );
998
998
/* no idea if this makes sense, but it was needed for some
999
999
program */
1000
- if (!shdr) shdr = findSection2 (" .rel.got" );
1000
+ if (!shdr) shdr = tryFindSectionHeader (" .rel.got" );
1001
1001
/* some programs have neither section, but this doesn't seem
1002
1002
to be a problem */
1003
1003
if (!shdr) continue ;
1004
1004
dyn->d_un .d_ptr = (*shdr).get ().sh_addr ;
1005
1005
}
1006
1006
else if (d_tag == DT_RELA) {
1007
- auto shdr = findSection2 (" .rela.dyn" );
1007
+ auto shdr = tryFindSectionHeader (" .rela.dyn" );
1008
1008
/* some programs lack this section, but it doesn't seem to
1009
1009
be a problem */
1010
1010
if (!shdr) continue ;
@@ -1017,7 +1017,7 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
1017
1017
else if (d_tag == DT_MIPS_RLD_MAP_REL) {
1018
1018
/* the MIPS_RLD_MAP_REL tag stores the offset to the debug
1019
1019
pointer, relative to the address of the tag */
1020
- auto shdr = findSection2 (" .rld_map" );
1020
+ auto shdr = tryFindSectionHeader (" .rld_map" );
1021
1021
if (shdr) {
1022
1022
auto rld_map_addr = findSectionHeader (" .rld_map" ).sh_addr ;
1023
1023
auto dyn_offset = ((char *)dyn) - ((char *)dyn_table);
0 commit comments