[llvm] 066e209 - [llvm-readelf/readobj] - Fix the behavior when a sections is included in two groups at the same time.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 22 03:32:04 PDT 2020
Author: Georgii Rymar
Date: 2020-07-22T13:29:54+03:00
New Revision: 066e209c9d5d8a2c9ff2d7feb5630cfc9616b38d
URL: https://github.com/llvm/llvm-project/commit/066e209c9d5d8a2c9ff2d7feb5630cfc9616b38d
DIFF: https://github.com/llvm/llvm-project/commit/066e209c9d5d8a2c9ff2d7feb5630cfc9616b38d.diff
LOG: [llvm-readelf/readobj] - Fix the behavior when a sections is included in two groups at the same time.
The current behavior was introduced by me in D37567 and it is a bit strange. It prints the
"Error: ...." message to the errs() manually and stops dumping the group section which has this error.
This behavior is consistent with GNU though, but it is very inconsistent with what the regular llvm-readelf
code usually does/prints, so I suggest to change the implementation:
1) Instead of printing "Error: ...." to errs() - just report a warning.
2) Try to continue dumping the section.
3) Merge broken-group.test to group.text.
This is what this patch does.
Differential revision: https://reviews.llvm.org/D84170
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/groups.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
llvm/test/tools/llvm-readobj/ELF/broken-group.test
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/broken-group.test b/llvm/test/tools/llvm-readobj/ELF/broken-group.test
deleted file mode 100644
index 23bd76a821ef..000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/broken-group.test
+++ /dev/null
@@ -1,80 +0,0 @@
-# RUN: yaml2obj %s -o %t.o
-
-# RUN: llvm-readelf --elf-section-groups \
-# RUN: %t.o >%tout.log 2>%terr.log
-# RUN: FileCheck %s -check-prefix=GNU-STDERR < %terr.log
-# GNU-STDERR: Error: section [ 3] in group section [ 4] already in group section [ 2]
-# RUN: FileCheck %s -check-prefix=GNU-STDOUT < %tout.log
-# GNU-STDOUT: COMDAT group section [ 2] `.group' [bar] contains 1 sections:
-# GNU-STDOUT-NEXT: [Index] Name
-# GNU-STDOUT-NEXT: [ 3] .foo
-# GNU-STDOUT: COMDAT group section [ 4] `.group1' [zed] contains 1 sections:
-# GNU-STDOUT-NEXT: [Index] Name
-
-# RUN: llvm-readobj --elf-section-groups \
-# RUN: %t.o >%t2out.log 2>%t2err.log %t.o
-# RUN: FileCheck %s -check-prefix=LLVM-STDERR < %t2err.log
-# LLVM-STDERR: Error: .foo (3) in a group .group1 (4) is already in a group .group (2)
-# RUN: FileCheck %s -check-prefix=LLVM-STDOUT < %t2out.log
-# LLVM-STDOUT: Groups {
-# LLVM-STDOUT-NEXT: Group {
-# LLVM-STDOUT-NEXT: Name: .group
-# LLVM-STDOUT-NEXT: Index: 2
-# LLVM-STDOUT-NEXT: Link: 5
-# LLVM-STDOUT-NEXT: Info: 1
-# LLVM-STDOUT-NEXT: Type: COMDAT
-# LLVM-STDOUT-NEXT: Signature: bar
-# LLVM-STDOUT-NEXT: Section(s) in group [
-# LLVM-STDOUT-NEXT: .foo (3)
-# LLVM-STDOUT-NEXT: ]
-# LLVM-STDOUT-NEXT: }
-# LLVM-STDOUT-NEXT: Group {
-# LLVM-STDOUT-NEXT: Name: .group1
-# LLVM-STDOUT-NEXT: Index: 4
-# LLVM-STDOUT-NEXT: Link: 5
-# LLVM-STDOUT-NEXT: Info: 2
-# LLVM-STDOUT-NEXT: Type: COMDAT
-# LLVM-STDOUT-NEXT: Signature: zed
-# LLVM-STDOUT-NEXT: Section(s) in group [
-# LLVM-STDOUT-NEXT: ]
-# LLVM-STDOUT-NEXT: }
-# LLVM-STDOUT-NEXT: }
-
-!ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
-Sections:
- - Name: .text
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- AddressAlign: 0x0000000000000004
- Content: ''
- - Name: .group
- Type: SHT_GROUP
- Link: .symtab
- AddressAlign: 0x0000000000000004
- Info: bar
- Members:
- - SectionOrType: GRP_COMDAT
- - SectionOrType: .foo
- - Name: .foo
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]
- AddressAlign: 0x0000000000000001
- Content: ''
- - Name: .group1
- Type: SHT_GROUP
- Link: .symtab
- AddressAlign: 0x0000000000000004
- Info: zed
- Members:
- - SectionOrType: GRP_COMDAT
- - SectionOrType: .foo
-Symbols:
- - Name: bar
- Section: .group
- - Name: zed
- Section: .group1
diff --git a/llvm/test/tools/llvm-readobj/ELF/groups.test b/llvm/test/tools/llvm-readobj/ELF/groups.test
index 4e165311ecfb..ac211893ffe2 100644
--- a/llvm/test/tools/llvm-readobj/ELF/groups.test
+++ b/llvm/test/tools/llvm-readobj/ELF/groups.test
@@ -61,7 +61,7 @@ Sections:
Info: bar
Members:
- SectionOrType: GRP_COMDAT
- - SectionOrType: .text.bar
+ - SectionOrType: [[TEXTBARNAME=.text.bar]]
- SectionOrType: .rela.text.bar
- Name: .text.foo
Type: SHT_PROGBITS
@@ -80,3 +80,47 @@ Symbols:
Section: .text.foo
- Name: bar
Section: .text.bar
+
+## Check that we report a warning and continue dumping when a section is included
+## in two group sections at the same time.
+
+# RUN: yaml2obj %s -DTEXTBARNAME=.text.foo -o %t.dup.o
+# RUN: llvm-readobj --elf-section-groups %t.dup.o 2>&1 | FileCheck %s -DFILE=%t.dup.o --check-prefix=DUP-LLVM
+# RUN: llvm-readelf --elf-section-groups %t.dup.o 2>&1 | FileCheck %s -DFILE=%t.dup.o --check-prefix=DUP-GNU
+
+# DUP-LLVM: Group {
+# DUP-LLVM-NEXT: Name: .group
+# DUP-LLVM-NEXT: Index: 1
+# DUP-LLVM-NEXT: Link: 7
+# DUP-LLVM-NEXT: Info: 1
+# DUP-LLVM-NEXT: Type: COMDAT
+# DUP-LLVM-NEXT: Signature: foo
+# DUP-LLVM-NEXT: Section(s) in group [
+# DUP-LLVM-NEXT: .text.foo (3)
+# DUP-LLVM-NEXT: .rela.text.foo (4)
+# DUP-LLVM-NEXT: ]
+# DUP-LLVM-NEXT: }
+# DUP-LLVM: Group {
+# DUP-LLVM-NEXT: Name: .group1
+# DUP-LLVM-NEXT: Index: 2
+# DUP-LLVM-NEXT: Link: 7
+# DUP-LLVM-NEXT: Info: 2
+# DUP-LLVM-NEXT: Type: COMDAT
+# DUP-LLVM-NEXT: Signature: bar
+# DUP-LLVM-NEXT: Section(s) in group [
+# DUP-LLVM-NEXT: warning: '[[FILE]]': section with index 3, included in the group section with index 1, was also found in the group section with index 2
+# DUP-LLVM-NEXT: .text.foo (3)
+# DUP-LLVM-NEXT: .rela.text.bar (6)
+# DUP-LLVM-NEXT: ]
+# DUP-LLVM-NEXT: }
+
+# DUP-GNU: COMDAT group section [ 1] `.group' [foo] contains 2 sections:
+# DUP-GNU-NEXT: [Index] Name
+# DUP-GNU-NEXT: [ 3] .text.foo
+# DUP-GNU-NEXT: [ 4] .rela.text.foo
+
+# DUP-GNU: COMDAT group section [ 2] `.group1' [bar] contains 2 sections:
+# DUP-GNU-NEXT: [Index] Name
+# DUP-GNU-NEXT: warning: '[[FILE]]': section with index 3, included in the group section with index 1, was also found in the group section with index 2
+# DUP-GNU-NEXT: [ 3] .text.foo
+# DUP-GNU-NEXT: [ 6] .rela.text.bar
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 5569b69f380e..104d1be751ab 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3605,15 +3605,13 @@ template <class ELFT> void GNUStyle<ELFT>::printGroupSections(const ELFO *Obj) {
<< " [Index] Name\n";
for (const GroupMember &GM : G.Members) {
const GroupSection *MainGroup = Map[GM.Index];
- if (MainGroup != &G) {
- OS.flush();
- errs() << "Error: section [" << format_decimal(GM.Index, 5)
- << "] in group section [" << format_decimal(G.Index, 5)
- << "] already in group section ["
- << format_decimal(MainGroup->Index, 5) << "]";
- errs().flush();
- continue;
- }
+ if (MainGroup != &G)
+ this->reportUniqueWarning(
+ createError("section with index " + Twine(GM.Index) +
+ ", included in the group section with index " +
+ Twine(MainGroup->Index) +
+ ", was also found in the group section with index " +
+ Twine(G.Index)));
OS << " [" << format_decimal(GM.Index, 5) << "] " << GM.Name << "\n";
}
}
@@ -6197,15 +6195,13 @@ void LLVMStyle<ELFT>::printGroupSections(const ELFO *Obj) {
ListScope L(W, "Section(s) in group");
for (const GroupMember &GM : G.Members) {
const GroupSection *MainGroup = Map[GM.Index];
- if (MainGroup != &G) {
- W.flush();
- errs() << "Error: " << GM.Name << " (" << GM.Index
- << ") in a group " + G.Name + " (" << G.Index
- << ") is already in a group " + MainGroup->Name + " ("
- << MainGroup->Index << ")\n";
- errs().flush();
- continue;
- }
+ if (MainGroup != &G)
+ this->reportUniqueWarning(
+ createError("section with index " + Twine(GM.Index) +
+ ", included in the group section with index " +
+ Twine(MainGroup->Index) +
+ ", was also found in the group section with index " +
+ Twine(G.Index)));
W.startLine() << GM.Name << " (" << GM.Index << ")\n";
}
}
More information about the llvm-commits
mailing list