[llvm] 7448e64 - [llvm-readobj/elf] - Don't use unwrapOrError when reporting errors about SHT_DYNAMIC sections.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 05:01:46 PDT 2020


Author: Georgii Rymar
Date: 2020-09-14T14:55:16+03:00
New Revision: 7448e64a790bfed10a04a550c14b91429cda07e0

URL: https://github.com/llvm/llvm-project/commit/7448e64a790bfed10a04a550c14b91429cda07e0
DIFF: https://github.com/llvm/llvm-project/commit/7448e64a790bfed10a04a550c14b91429cda07e0.diff

LOG: [llvm-readobj/elf] - Don't use unwrapOrError when reporting errors about SHT_DYNAMIC sections.

This changes messages reported to stop using dynamic section names (use `describe()` instead).
This allows to avoid `unwrapOrError` and improves diagnostics.

Differential revision: https://reviews.llvm.org/D87503

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/dynamic-not-in-pt-dynamic.test
    llvm/test/tools/llvm-readobj/ELF/non-dynamic-in-pt-dynamic.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/dynamic-not-in-pt-dynamic.test b/llvm/test/tools/llvm-readobj/ELF/dynamic-not-in-pt-dynamic.test
index 8c33931468c6..20dd7c0ef630 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dynamic-not-in-pt-dynamic.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dynamic-not-in-pt-dynamic.test
@@ -11,7 +11,7 @@
 # RUN: llvm-readelf --dynamic-table %t1.o 2>&1 \
 # RUN:   | FileCheck -DFILE=%t1.o --check-prefixes=WARNING1,GNU1 %s
 
-# WARNING1: warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not contained within the PT_DYNAMIC segment
+# WARNING1: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 is not contained within the PT_DYNAMIC segment
 # WARNING1: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x1){{$}}
 # WARNING1: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
 # WARNING1: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
@@ -69,7 +69,7 @@ ProgramHeaders:
 # RUN: llvm-readelf --dynamic-table %t2.o 2>&1 \
 # RUN:   | FileCheck -DFILE=%t2.o --check-prefixes=WARNING2,GNU2 %s
 
-# WARNING2: warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not contained within the PT_DYNAMIC segment
+# WARNING2: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 is not contained within the PT_DYNAMIC segment
 # WARNING2: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
 
 # LLVM2:      DynamicSection [ (1 entries)

diff  --git a/llvm/test/tools/llvm-readobj/ELF/non-dynamic-in-pt-dynamic.test b/llvm/test/tools/llvm-readobj/ELF/non-dynamic-in-pt-dynamic.test
index 5905ccb2902c..12bcdf6b7216 100644
--- a/llvm/test/tools/llvm-readobj/ELF/non-dynamic-in-pt-dynamic.test
+++ b/llvm/test/tools/llvm-readobj/ELF/non-dynamic-in-pt-dynamic.test
@@ -10,7 +10,7 @@
 # RUN: llvm-readelf --dynamic-table %t1.o 2>&1 \
 # RUN:   | FileCheck %s --DFILE=%t1.o --check-prefixes=WARNING,GNU
 
-# WARNING: warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not at the start of PT_DYNAMIC segment
+# WARNING: warning: '[[FILE]]': SHT_DYNAMIC section with index 2 is not at the start of PT_DYNAMIC segment
 # WARNING: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x21){{$}}
 # WARNING: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
 # WARNING: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index a1cf62f546c7..70584e8a161c 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1886,19 +1886,17 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
   }
 
   if (DynamicPhdr && DynamicSec) {
-    StringRef Name =
-        unwrapOrError(ObjF->getFileName(), Obj->getSectionName(DynamicSec));
     if (DynamicSec->sh_addr + DynamicSec->sh_size >
             DynamicPhdr->p_vaddr + DynamicPhdr->p_memsz ||
         DynamicSec->sh_addr < DynamicPhdr->p_vaddr)
-      reportWarning(createError("The SHT_DYNAMIC section '" + Name +
-                                "' is not contained within the "
+      reportWarning(createError(describe(*DynamicSec) +
+                                " is not contained within the "
                                 "PT_DYNAMIC segment"),
                     ObjF->getFileName());
 
     if (DynamicSec->sh_addr != DynamicPhdr->p_vaddr)
-      reportWarning(createError("The SHT_DYNAMIC section '" + Name +
-                                "' is not at the start of "
+      reportWarning(createError(describe(*DynamicSec) +
+                                " is not at the start of "
                                 "PT_DYNAMIC segment"),
                     ObjF->getFileName());
   }


        


More information about the llvm-commits mailing list