@@ -491,69 +491,53 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
491
491
auto SecOrErr = EF.getSection (Rel.d .a );
492
492
if (!SecOrErr)
493
493
return errorToErrorCode (SecOrErr.takeError ());
494
- const Elf_Shdr *Sec = *SecOrErr;
495
- auto SymTabOrErr = EF.getSection (Sec->sh_link );
496
- if (!SymTabOrErr)
497
- return errorToErrorCode (SymTabOrErr.takeError ());
498
- const Elf_Shdr *SymTab = *SymTabOrErr;
499
- assert (SymTab->sh_type == ELF::SHT_SYMTAB ||
500
- SymTab->sh_type == ELF::SHT_DYNSYM);
501
- auto StrTabSec = EF.getSection (SymTab->sh_link );
502
- if (!StrTabSec)
503
- return errorToErrorCode (StrTabSec.takeError ());
504
- auto StrTabOrErr = EF.getStringTable (*StrTabSec);
505
- if (!StrTabOrErr)
506
- return errorToErrorCode (StrTabOrErr.takeError ());
507
- StringRef StrTab = *StrTabOrErr;
494
+
508
495
int64_t Addend = 0 ;
509
496
// If there is no Symbol associated with the relocation, we set the undef
510
497
// boolean value to 'true'. This will prevent us from calling functions that
511
498
// requires the relocation to be associated with a symbol.
499
+ //
500
+ // In SHT_REL case we would need to read the addend from section data.
501
+ // GNU objdump does not do that and we just follow for simplicity atm.
512
502
bool Undef = false ;
513
- switch (Sec->sh_type ) {
514
- default :
515
- return object_error::parse_failed;
516
- case ELF::SHT_REL: {
517
- // TODO: Read implicit addend from section data.
518
- break ;
519
- }
520
- case ELF::SHT_RELA: {
503
+ if ((*SecOrErr)->sh_type == ELF::SHT_RELA) {
521
504
const Elf_Rela *ERela = Obj->getRela (Rel);
522
505
Addend = ERela->r_addend ;
523
506
Undef = ERela->getSymbol (false ) == 0 ;
524
- break ;
525
- }
507
+ } else if ((*SecOrErr)-> sh_type != ELF::SHT_REL) {
508
+ return object_error::parse_failed;
526
509
}
527
- std::string Target;
510
+
511
+ // Default scheme is to print Target, as well as "+ <addend>" for nonzero
512
+ // addend. Should be acceptable for all normal purposes.
513
+ std::string FmtBuf;
514
+ raw_string_ostream Fmt (FmtBuf);
515
+
528
516
if (!Undef) {
529
517
symbol_iterator SI = RelRef.getSymbol ();
530
- const Elf_Sym *symb = Obj->getSymbol (SI->getRawDataRefImpl ());
531
- if (symb ->getType () == ELF::STT_SECTION) {
518
+ const Elf_Sym *Sym = Obj->getSymbol (SI->getRawDataRefImpl ());
519
+ if (Sym ->getType () == ELF::STT_SECTION) {
532
520
Expected<section_iterator> SymSI = SI->getSection ();
533
521
if (!SymSI)
534
522
return errorToErrorCode (SymSI.takeError ());
535
523
const Elf_Shdr *SymSec = Obj->getSection ((*SymSI)->getRawDataRefImpl ());
536
524
auto SecName = EF.getSectionName (SymSec);
537
525
if (!SecName)
538
526
return errorToErrorCode (SecName.takeError ());
539
- Target = *SecName;
527
+ Fmt << *SecName;
540
528
} else {
541
- Expected<StringRef> SymName = symb ->getName (StrTab );
529
+ Expected<StringRef> SymName = SI ->getName ();
542
530
if (!SymName)
543
531
return errorToErrorCode (SymName.takeError ());
544
532
if (Demangle)
545
- Target = demangle (*SymName);
533
+ Fmt << demangle (*SymName);
546
534
else
547
- Target = *SymName;
535
+ Fmt << *SymName;
548
536
}
549
- } else
550
- Target = " *ABS*" ;
537
+ } else {
538
+ Fmt << " *ABS*" ;
539
+ }
551
540
552
- // Default scheme is to print Target, as well as "+ <addend>" for nonzero
553
- // addend. Should be acceptable for all normal purposes.
554
- std::string FmtBuf;
555
- raw_string_ostream Fmt (FmtBuf);
556
- Fmt << Target;
557
541
if (Addend != 0 )
558
542
Fmt << (Addend < 0 ? " " : " +" ) << Addend;
559
543
Fmt.flush ();
0 commit comments