[llvm] 6567f82 - [llvm-readobj/elf] - Refine the warning about the broken PT_DYNAMIC segment.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 04:57:43 PDT 2020
Author: Georgii Rymar
Date: 2020-08-17T14:57:19+03:00
New Revision: 6567f822160ea7c4d13a7e3358883eafc61af337
URL: https://github.com/llvm/llvm-project/commit/6567f822160ea7c4d13a7e3358883eafc61af337
DIFF: https://github.com/llvm/llvm-project/commit/6567f822160ea7c4d13a7e3358883eafc61af337.diff
LOG: [llvm-readobj/elf] - Refine the warning about the broken PT_DYNAMIC segment.
Splitted out from D85519.
Currently we report "PT_DYNAMIC segment offset + size exceeds the size of the file",
this changes it to
"PT_DYNAMIC segment offset (0x1234) + file size (0x5678) exceeds the size of the file (0x68ab)"
Differential revision: https://reviews.llvm.org/D85654
Added:
Modified:
llvm/test/Object/invalid.test
llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test
index c3dc175f399c..8d9068a1ba07 100644
--- a/llvm/test/Object/invalid.test
+++ b/llvm/test/Object/invalid.test
@@ -489,7 +489,7 @@ Sections:
# RUN: yaml2obj %s --docnum=22 -o %t22
# RUN: llvm-readobj --dyn-relocations %t22 2>&1 | FileCheck -DFILE=%t22 --check-prefix=DYN-TABLE-PHDR %s
-# DYN-TABLE-PHDR: warning: '[[FILE]]': PT_DYNAMIC segment offset + size exceeds the size of the file
+# DYN-TABLE-PHDR: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffff0000) + file size (0x0) exceeds the size of the file (0x150)
--- !ELF
FileHeader:
@@ -506,7 +506,9 @@ ProgramHeaders:
# RUN: yaml2obj %s --docnum=23 -o %t23
# RUN: llvm-readobj --dyn-relocations %t23 2>&1 \
-# RUN: | FileCheck -DFILE=%t23 --check-prefix=DYN-TABLE-PHDR %s
+# RUN: | FileCheck -DFILE=%t23 --check-prefix=DYN-TABLE-PHDR2 %s
+
+# DYN-TABLE-PHDR2: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x78) + file size (0xffff0000) exceeds the size of the file (0x1a8)
--- !ELF
FileHeader:
diff --git a/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test b/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test
index a6aa2915aa47..3ffdd57486a0 100644
--- a/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test
+++ b/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test
@@ -13,14 +13,18 @@
# within the file.
# RUN: cp %t.stripped %t.truncated1
# RUN: %python -c "with open(r'%t.truncated1', 'r+') as f: f.truncate(0x1001)"
-# RUN: llvm-readobj %t.truncated1 --dynamic-table 2>&1 | FileCheck -DFILE=%t.truncated1 %s
+# RUN: llvm-readobj %t.truncated1 --dynamic-table 2>&1 | \
+# RUN: FileCheck -DFILE=%t.truncated1 %s --check-prefix=WARN1
+
+# WARN1: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0x10) exceeds the size of the file (0x1001)
# Test case where the offset is too large to be in the file.
# RUN: cp %t.stripped %t.truncated2
# RUN: %python -c "with open(r'%t.truncated2', 'r+') as f: f.truncate(0xFFF)"
-# RUN: llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck -DFILE=%t.truncated2 %s
+# RUN: llvm-readobj %t.truncated2 --dynamic-table 2>&1 | \
+# RUN: FileCheck -DFILE=%t.truncated2 %s --check-prefix=WARN2
-# CHECK: warning: '[[FILE]]': PT_DYNAMIC segment offset + size exceeds the size of the file
+# WARN2: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0x10) exceeds the size of the file (0xfff)
--- !ELF
FileHeader:
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index b18c841ead91..461d1894d1ec 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1894,10 +1894,12 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
if (DynamicPhdr && DynamicPhdr->p_offset + DynamicPhdr->p_filesz >
ObjF->getMemoryBufferRef().getBufferSize()) {
- reportWarning(
- createError(
- "PT_DYNAMIC segment offset + size exceeds the size of the file"),
- ObjF->getFileName());
+ reportUniqueWarning(createError(
+ "PT_DYNAMIC segment offset (0x" +
+ Twine::utohexstr(DynamicPhdr->p_offset) + ") + file size (0x" +
+ Twine::utohexstr(DynamicPhdr->p_filesz) +
+ ") exceeds the size of the file (0x" +
+ Twine::utohexstr(ObjF->getMemoryBufferRef().getBufferSize()) + ")"));
// Don't use the broken dynamic header.
DynamicPhdr = nullptr;
}
More information about the llvm-commits
mailing list