]> granicus.if.org Git - llvm/commitdiff
Revert r361630 "[llvm-readelf] - Allow dumping of the .dynamic section even if there...
authorGeorge Rimar <grimar@accesssoftek.com>
Fri, 24 May 2019 11:24:42 +0000 (11:24 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Fri, 24 May 2019 11:24:42 +0000 (11:24 +0000)
It broke BB:
http://lab.llvm.org:8011/builders/ppc64le-lld-multistage-test/builds/3748

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361631 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-readobj/elf-dynamic-no-pt-dynamic.test
tools/llvm-readobj/ELFDumper.cpp

index 5a03d04ab4d5406e67f896019e5e106a299b26be..3ef293714a89779caa9100e3b2000bcbf3eceb37 100644 (file)
@@ -1,23 +1,16 @@
-## Show that dumping occurs even if there is no PT_DYNAMIC header.
-## This is inconsistent with the GNU behavior, but seems to be more reasonable.
+# Show that no dumping occurs if there is no PT_DYNAMIC header.
 # RUN: yaml2obj %s -o %t.no-phdr
 # RUN: llvm-readobj --dynamic-table %t.no-phdr | FileCheck %s --check-prefix=LLVM
-# RUN: llvm-readelf --dynamic-table %t.no-phdr | FileCheck %s --check-prefix=GNU
+# RUN: llvm-readelf --dynamic-table %t.no-phdr | FileCheck %s --check-prefix=GNU --allow-empty
 
 # LLVM:      File: {{.*}}.no-phdr
 # LLVM-NEXT: Format: ELF64-x86-64
 # LLVM-NEXT: Arch: x86_64
 # LLVM-NEXT: AddressSize: 64bit
 # LLVM-NEXT: LoadName:{{ *}}
-# LLVM-NEXT: DynamicSection [ (1 entries)
-# LLVM-NEXT:   Tag                Type Name/Value
-# LLVM-NEXT:   0x0000000000000000 NULL 0x0
-# LLVM-NEXT: ]
+# LLVM-NOT:  {{.}}
 
-# GNU:      DynamicSection [ (1 entries)
-# GNU-NEXT:   Tag                Type Name/Value
-# GNU-NEXT:   0x0000000000000000 NULL 0x0
-# GNU-NEXT: ]
+# GNU-NOT: {{.}}
 
 --- !ELF
 FileHeader:
index b86a6c192cab3756ea5551f70ada96aea7eb8faf..159e300de305851b59bd0d96ae51b4f795e15776 100644 (file)
@@ -1331,7 +1331,6 @@ static const char *getElfMipsOptionsOdkType(unsigned Odk) {
 
 template <typename ELFT>
 void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
-  // Try to locate the PT_DYNAMIC header.
   const Elf_Phdr *DynamicPhdr = nullptr;
   for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
     if (Phdr.p_type != ELF::PT_DYNAMIC)
@@ -1340,6 +1339,11 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
     break;
   }
 
+  // We do not want to dump dynamic section if we have no PT_DYNAMIC header.
+  // This matches GNU's behavior.
+  if (!DynamicPhdr)
+    return;
+
   // Try to locate the .dynamic section in the sections header table.
   const Elf_Shdr *DynamicSec = nullptr;
   for (const Elf_Shdr &Sec : unwrapOrError(Obj->sections())) {
@@ -1354,16 +1358,9 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
   // Ignore sh_entsize and use the expected value for entry size explicitly.
   // This allows us to dump the dynamic sections with a broken sh_entsize
   // field.
-  if (DynamicSec) {
+  if (DynamicSec)
     DynamicTable = checkDRI({ObjF->getELFFile()->base() + DynamicSec->sh_offset,
                              DynamicSec->sh_size, sizeof(Elf_Dyn)});
-    parseDynamicTable();
-  }
-
-  // If we have a PT_DYNAMIC header, we will either check the found dynamic
-  // section or take the dynamic table data directly from the header.
-  if (!DynamicPhdr)
-    return;
 
   if (DynamicPhdr->p_offset + DynamicPhdr->p_filesz >
       ObjF->getMemoryBufferRef().getBufferSize())
@@ -1377,6 +1374,7 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
   }
 
   StringRef Name = unwrapOrError(Obj->getSectionName(DynamicSec));
+
   if (DynamicSec->sh_addr + DynamicSec->sh_size >
           DynamicPhdr->p_vaddr + DynamicPhdr->p_memsz ||
       DynamicSec->sh_addr < DynamicPhdr->p_vaddr)
@@ -1388,6 +1386,8 @@ void ELFDumper<ELFT>::loadDynamicTable(const ELFFile<ELFT> *Obj) {
     reportWarning("The SHT_DYNAMIC section '" + Name +
                   "' is not at the start of "
                   "PT_DYNAMIC segment");
+
+  parseDynamicTable();
 }
 
 template <typename ELFT>