[llvm-branch-commits] [llvm] 01e4920 - [llvm-readelf/obj] - Refine the error message about the broken string table.
Georgii Rymar via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 2 01:18:00 PST 2020
Author: Georgii Rymar
Date: 2020-12-02T12:06:16+03:00
New Revision: 01e49204b82057f356ad3fe0cabba139635ac733
URL: https://github.com/llvm/llvm-project/commit/01e49204b82057f356ad3fe0cabba139635ac733
DIFF: https://github.com/llvm/llvm-project/commit/01e49204b82057f356ad3fe0cabba139635ac733.diff
LOG: [llvm-readelf/obj] - Refine the error message about the broken string table.
This:
1) Changes `reportWarning` to `reportUniqueWarning` (no-op here).
2) Adds more context to the message.
3) Merges `broken-dynsym-link.test` into `dyn-symbols.test`, adds more testing.
Differential revision: https://reviews.llvm.org/D92380
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
llvm/test/tools/llvm-readobj/ELF/broken-dynsym-link.test
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/broken-dynsym-link.test b/llvm/test/tools/llvm-readobj/ELF/broken-dynsym-link.test
deleted file mode 100644
index 179aff1d5652..000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/broken-dynsym-link.test
+++ /dev/null
@@ -1,57 +0,0 @@
-## Test that we are able to dump section headers even if the
-## .dynsym section's sh_link field is broken.
-
-## Case 1: sh_link is set to 0.
-# RUN: yaml2obj --docnum=1 -DLINK=0 %s -o %t1
-# RUN: llvm-readobj -S %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefixes=LLVM,ERR
-# RUN: llvm-readelf -S %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefixes=GNU,ERR
-
-# ERR: warning: '[[FILE]]': invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
-
-# LLVM: Name: .dynsym
-# LLVM-NEXT: Type: SHT_DYNSYM
-# LLVM-NEXT: Flags [
-# LLVM-NEXT: SHF_ALLOC
-# LLVM-NEXT: ]
-# LLVM-NEXT: Address: 0x0
-# LLVM-NEXT: Offset: 0x40
-# LLVM-NEXT: Size: 24
-# LLVM-NEXT: Link: 0
-
-# GNU: Section Headers:
-# GNU-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
-# GNU-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
-# GNU-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 0
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
-Sections:
- - Name: .dynsym
- Type: SHT_DYNSYM
- Link: [[LINK]]
-
-## Case 2: sh_link is set to 255, which is larger than the number of the sections.
-# RUN: yaml2obj --docnum=1 -DLINK=255 %s -o %t2
-
-# RUN: llvm-readobj -S %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefixes=LLVM2,ERR2
-# RUN: llvm-readelf -S %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefixes=GNU2,ERR2
-
-# ERR2: warning: '[[FILE]]': invalid section index: 255
-
-# LLVM2: Name: .dynsym
-# LLVM2-NEXT: Type: SHT_DYNSYM
-# LLVM2-NEXT: Flags [
-# LLVM2-NEXT: SHF_ALLOC
-# LLVM2-NEXT: ]
-# LLVM2-NEXT: Address: 0x0
-# LLVM2-NEXT: Offset: 0x40
-# LLVM2-NEXT: Size: 24
-# LLVM2-NEXT: Link: 255
-
-# GNU2: Section Headers:
-# GNU2-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
-# GNU2-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
-# GNU2-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 255
diff --git a/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test b/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
index 0ccb24a2f4bd..eb976f673b93 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
@@ -610,6 +610,7 @@ Sections:
- Name: .dynsym
Type: SHT_DYNSYM
EntSize: [[ENTSIZE=<none>]]
+ Link: [[LINK=<none>]]
ShOffset: [[OFFSET=<none>]]
ShSize: [[SIZE=<none>]]
DynamicSymbols:
@@ -642,3 +643,65 @@ DynamicSymbols:
# SIZE-BROKEN-LLVM: DynamicSymbols [
# SIZE-BROKEN-LLVM-NEXT: ]
+
+## d) check we report a warning when the sh_link field of the SHT_DYNSYM section
+## is not a valid section index or is not an index of a valid string table.
+# RUN: yaml2obj --docnum=14 %s -DLINK=0xffffffff -o %t16.link
+# RUN: llvm-readobj %t16.link --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
+# RUN: --check-prefixes=LINK-BROKEN1,LINK-BROKEN-LLVM --implicit-check-not=warning:
+# RUN: llvm-readelf %t16.link --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
+# RUN: --check-prefixes=LINK-BROKEN1,LINK-BROKEN-GNU --implicit-check-not=warning:
+
+## Also test that we are able to dump section headers even if the .dynsym section's sh_link field is broken.
+# RUN: llvm-readobj %t16.link --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
+# RUN: --check-prefixes=LINK-BROKEN1,LINK-SEC-HDRS-LLVM,LINK-BROKEN-LLVM --implicit-check-not=warning:
+# RUN: llvm-readelf %t16.link --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link \
+# RUN: --check-prefixes=LINK-BROKEN1,LINK-SEC-HDRS-GNU,LINK-BROKEN-GNU
+
+# RUN: yaml2obj --docnum=14 %s -DLINK=0x0 -o %t16.link.0
+# RUN: llvm-readobj %t16.link.0 --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
+# RUN: --check-prefixes=LINK-BROKEN2,LINK-BROKEN-LLVM --implicit-check-not=warning:
+# RUN: llvm-readelf %t16.link.0 --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
+# RUN: --check-prefixes=LINK-BROKEN2,LINK-BROKEN-GNU --implicit-check-not=warning:
+
+## Also test that we are able to dump section headers even if the .dynsym section's sh_link field is broken.
+# RUN: llvm-readobj %t16.link.0 --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
+# RUN: --check-prefixes=LINK-BROKEN2,LINK-SEC-HDRS-LLVM,LINK-BROKEN-LLVM --implicit-check-not=warning:
+# RUN: llvm-readelf %t16.link.0 --section-headers --dyn-symbols 2>&1 | FileCheck %s -DFILE=%t16.link.0 \
+# RUN: --check-prefixes=LINK-BROKEN2,LINK-SEC-HDRS-GNU,LINK-BROKEN-GNU --implicit-check-not=warning:
+
+# LINK-BROKEN1: warning: '[[FILE]]': unable to get the string table for the SHT_DYNSYM section with index 1: invalid section index: 4294967295
+# LINK-BROKEN2: warning: '[[FILE]]': unable to get the string table for the SHT_DYNSYM section with index 1: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
+
+# LINK-SEC-HDRS-LLVM: Sections [
+# LINK-SEC-HDRS-GNU: There are 5 section headers, starting at offset 0x80:
+
+# LINK-BROKEN-LLVM: DynamicSymbols [
+# LINK-BROKEN-LLVM-NEXT: warning: '[[FILE]]': st_name (0x0) is past the end of the string table of size 0x0
+# LINK-BROKEN-LLVM-NEXT: Symbol {
+# LINK-BROKEN-LLVM-NEXT: Name: <?> (0)
+# LINK-BROKEN-LLVM-NEXT: Value: 0x0
+# LINK-BROKEN-LLVM-NEXT: Size: 0
+# LINK-BROKEN-LLVM-NEXT: Binding: Local (0x0)
+# LINK-BROKEN-LLVM-NEXT: Type: None (0x0)
+# LINK-BROKEN-LLVM-NEXT: Other: 0
+# LINK-BROKEN-LLVM-NEXT: Section: Undefined (0x0)
+# LINK-BROKEN-LLVM-NEXT: }
+# LINK-BROKEN-LLVM-NEXT: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x0
+# LINK-BROKEN-LLVM-NEXT: Symbol {
+# LINK-BROKEN-LLVM-NEXT: Name: <?> (1)
+# LINK-BROKEN-LLVM-NEXT: Value: 0x0
+# LINK-BROKEN-LLVM-NEXT: Size: 0
+# LINK-BROKEN-LLVM-NEXT: Binding: Local (0x0)
+# LINK-BROKEN-LLVM-NEXT: Type: None (0x0)
+# LINK-BROKEN-LLVM-NEXT: Other: 0
+# LINK-BROKEN-LLVM-NEXT: Section: Undefined (0x0)
+# LINK-BROKEN-LLVM-NEXT: }
+# LINK-BROKEN-LLVM-NEXT: ]
+
+# LINK-BROKEN-GNU: Symbol table '.dynsym' contains 2 entries:
+# LINK-BROKEN-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# LINK-BROKEN-GNU-NEXT: warning: '[[FILE]]': st_name (0x0) is past the end of the string table of size 0x0
+# LINK-BROKEN-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND <?>
+# LINK-BROKEN-GNU-NEXT: warning: '[[FILE]]': st_name (0x1) is past the end of the string table of size 0x0
+# LINK-BROKEN-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT UND <?>
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 2167fc3e3dff..be018e18a912 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -2044,7 +2044,8 @@ ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> &O,
if (Expected<StringRef> E = Obj.getStringTableForSymtab(Sec))
DynamicStringTable = *E;
else
- reportWarning(E.takeError(), ObjF.getFileName());
+ reportUniqueWarning("unable to get the string table for the " +
+ describe(Sec) + ": " + toString(E.takeError()));
} else {
reportUniqueWarning("unable to read dynamic symbols from " +
describe(Sec) + ": " +
More information about the llvm-branch-commits
mailing list