[llvm] 5a2bee0 - [llvm-objdump]Correct .dynstr finding of getDynamicStrTab() (#127975)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 24 02:39:43 PST 2025


Author: Ruoyu Qiu
Date: 2025-02-24T10:39:40Z
New Revision: 5a2bee04d08868d1b8c2ddb1719be1cee0f577bf

URL: https://github.com/llvm/llvm-project/commit/5a2bee04d08868d1b8c2ddb1719be1cee0f577bf
DIFF: https://github.com/llvm/llvm-project/commit/5a2bee04d08868d1b8c2ddb1719be1cee0f577bf.diff

LOG: [llvm-objdump]Correct .dynstr finding of getDynamicStrTab() (#127975)

The dynamic string table used by the dynamic section is referenced by
the sh_link field of that section, so we should use that directly,
rather than going via the dynamic symbol table.
More info:
https://github.com/llvm/llvm-project/pull/125679#discussion_r1961333454

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>

Added: 
    

Modified: 
    llvm/test/tools/llvm-objdump/ELF/private-headers.test
    llvm/tools/llvm-objdump/ELFDump.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objdump/ELF/private-headers.test b/llvm/test/tools/llvm-objdump/ELF/private-headers.test
index eefdc8440385c..c90cf59f4ed7d 100644
--- a/llvm/test/tools/llvm-objdump/ELF/private-headers.test
+++ b/llvm/test/tools/llvm-objdump/ELF/private-headers.test
@@ -30,6 +30,7 @@ Sections:
   - Name:    .dynamic
     Type:    SHT_DYNAMIC
     Flags:   [ SHF_ALLOC ]
+    Link:    1
     Entries:
      - Tag:   DT_NEEDED
        Value: 0x1

diff  --git a/llvm/tools/llvm-objdump/ELFDump.cpp b/llvm/tools/llvm-objdump/ELFDump.cpp
index e9e5b059f1786..bce308c870ddf 100644
--- a/llvm/tools/llvm-objdump/ELFDump.cpp
+++ b/llvm/tools/llvm-objdump/ELFDump.cpp
@@ -78,8 +78,8 @@ static Expected<StringRef> getDynamicStrTab(const ELFFile<ELFT> &Elf) {
     return SectionsOrError.takeError();
 
   for (const typename ELFT::Shdr &Sec : *SectionsOrError) {
-    if (Sec.sh_type == ELF::SHT_DYNSYM)
-      return Elf.getStringTableForSymtab(Sec);
+    if (Sec.sh_type == ELF::SHT_DYNAMIC)
+      return Elf.getLinkAsStrtab(Sec);
   }
 
   return createError("dynamic string table not found");


        


More information about the llvm-commits mailing list