Skip to content

Commit

Permalink
[llvm-readelf/readobj] - Fix the behavior when a sections is included…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Georgii Rymar committed Jul 22, 2020
1 parent 36f9fe2 commit 066e209
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 99 deletions.
80 changes: 0 additions & 80 deletions llvm/test/tools/llvm-readobj/ELF/broken-group.test

This file was deleted.

46 changes: 45 additions & 1 deletion llvm/test/tools/llvm-readobj/ELF/groups.test
Expand Up @@ -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
Expand All @@ -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
32 changes: 14 additions & 18 deletions llvm/tools/llvm-readobj/ELFDumper.cpp
Expand Up @@ -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";
}
}
Expand Down Expand Up @@ -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";
}
}
Expand Down

0 comments on commit 066e209

Please sign in to comment.