[llvm] 60f161e - [yaml2obj][obj2yaml] - Simplify format of the SHT_LLVM_ADDRSIG section.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 01:33:43 PST 2020
Author: Georgii Rymar
Date: 2020-02-05T12:33:14+03:00
New Revision: 60f161eb62d0a6b30a54885711d5e63f7f572bb6
URL: https://github.com/llvm/llvm-project/commit/60f161eb62d0a6b30a54885711d5e63f7f572bb6
DIFF: https://github.com/llvm/llvm-project/commit/60f161eb62d0a6b30a54885711d5e63f7f572bb6.diff
LOG: [yaml2obj][obj2yaml] - Simplify format of the SHT_LLVM_ADDRSIG section.
Previously the description allowed to describe symbols with use of
`Name` and `Index` keys. This patch removes them and now it is still
possible to use either names or symbol indexes, but the code is simpler
and the format is slightly different.
Such a change will be useful for another patches, e.g:
https://reviews.llvm.org/D73788#inline-671077
Differential revision: https://reviews.llvm.org/D73888
Added:
Modified:
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/llvm-readobj/ELF/addrsig.test
llvm/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml
llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index 19b6de8763c7..f519c5195c91 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -340,19 +340,10 @@ struct VerneedSection : Section {
}
};
-struct AddrsigSymbol {
- AddrsigSymbol(StringRef N) : Name(N), Index(None) {}
- AddrsigSymbol(llvm::yaml::Hex32 Ndx) : Name(None), Index(Ndx) {}
- AddrsigSymbol() : Name(None), Index(None) {}
-
- Optional<StringRef> Name;
- Optional<llvm::yaml::Hex32> Index;
-};
-
struct AddrsigSection : Section {
Optional<yaml::BinaryRef> Content;
Optional<llvm::yaml::Hex64> Size;
- Optional<std::vector<AddrsigSymbol>> Symbols;
+ Optional<std::vector<YAMLFlowString>> Symbols;
AddrsigSection() : Section(ChunkKind::Addrsig) {}
@@ -532,7 +523,6 @@ struct Object {
} // end namespace ELFYAML
} // end namespace llvm
-LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::AddrsigSymbol)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::StackSizeEntry)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::LinkerOption)
@@ -700,10 +690,6 @@ template <> struct MappingTraits<ELFYAML::VernauxEntry> {
static void mapping(IO &IO, ELFYAML::VernauxEntry &E);
};
-template <> struct MappingTraits<ELFYAML::AddrsigSymbol> {
- static void mapping(IO &IO, ELFYAML::AddrsigSymbol &Sym);
-};
-
template <> struct MappingTraits<ELFYAML::LinkerOption> {
static void mapping(IO &IO, ELFYAML::LinkerOption &Sym);
};
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 76c2ff6fa978..55d6ccb6c009 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1230,12 +1230,9 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
return;
}
- for (const ELFYAML::AddrsigSymbol &Sym : *Section.Symbols) {
- uint64_t Val =
- Sym.Name ? toSymbolIndex(*Sym.Name, Section.Name, /*IsDynamic=*/false)
- : (uint32_t)*Sym.Index;
- SHeader.sh_size += encodeULEB128(Val, OS);
- }
+ for (StringRef Sym : *Section.Symbols)
+ SHeader.sh_size += encodeULEB128(
+ toSymbolIndex(Sym, Section.Name, /*IsDynamic=*/false), OS);
}
template <class ELFT>
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 4b21490a2754..2af348f67408 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1383,11 +1383,6 @@ StringRef MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
if (!Sec->Symbols)
return {};
-
- for (const ELFYAML::AddrsigSymbol &AS : *Sec->Symbols)
- if (AS.Index && AS.Name)
- return "\"Index\" and \"Name\" cannot be used together when defining a "
- "symbol";
return {};
}
@@ -1604,12 +1599,6 @@ void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
IO.setContext(nullptr);
}
-void MappingTraits<ELFYAML::AddrsigSymbol>::mapping(IO &IO, ELFYAML::AddrsigSymbol &Sym) {
- assert(IO.getContext() && "The IO context is not initialized");
- IO.mapOptional("Name", Sym.Name);
- IO.mapOptional("Index", Sym.Index);
-}
-
void MappingTraits<ELFYAML::LinkerOption>::mapping(IO &IO,
ELFYAML::LinkerOption &Opt) {
assert(IO.getContext() && "The IO context is not initialized");
diff --git a/llvm/test/tools/llvm-readobj/ELF/addrsig.test b/llvm/test/tools/llvm-readobj/ELF/addrsig.test
index ac2d69a410f7..1234a42a839a 100644
--- a/llvm/test/tools/llvm-readobj/ELF/addrsig.test
+++ b/llvm/test/tools/llvm-readobj/ELF/addrsig.test
@@ -20,9 +20,7 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Name: foo
- - Name: bar
+ Symbols: [ foo, bar ]
Symbols:
- Name: foo
- Name: bar
@@ -74,10 +72,7 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Index: 1
- - Index: 255
- - Index: 2
+ Symbols: [ 1, 255, 2 ]
Symbols:
- Name: foo
- Name: bar
diff --git a/llvm/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml b/llvm/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml
index 9519d1f05ba9..06430b771186 100644
--- a/llvm/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml
+++ b/llvm/test/tools/obj2yaml/elf-llvm-addrsig-section.yaml
@@ -7,21 +7,13 @@
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=NAME
-# NAME: - Name: .llvm_addrsig
-# NAME-NEXT: Type: SHT_LLVM_ADDRSIG
-# NAME-NEXT: Link: .symtab
-# NAME-NEXT: Symbols:
-# NAME-NEXT: - Name: foo
-# NAME-NEXT: - Name: bar
-# NAME-NEXT: - Index: 0x00000003
-# NAME-NEXT: - Index: 0xFFFFFFFF
+# NAME: - Name: .llvm_addrsig
+# NAME-NEXT: Type: SHT_LLVM_ADDRSIG
+# NAME-NEXT: Link: .symtab
+# NAME-NEXT: Symbols: [ foo, bar, '3', '4294967295' ]
# NAME: - Name: .llvm_addrsig_unlinked
# NAME-NEXT: Type: SHT_LLVM_ADDRSIG
-# NAME-NEXT: Symbols:
-# NAME-NEXT: - Index: 0x00000001
-# NAME-NEXT: - Index: 0x00000002
-# NAME-NEXT: - Index: 0x00000003
-# NAME-NEXT: - Index: 0xFFFFFFFF
+# NAME-NEXT: Symbols: [ '1', '2', '3', '4294967295' ]
--- !ELF
FileHeader:
@@ -32,19 +24,11 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Index: 1
- - Index: 2
- - Index: 3
- - Index: 0xFFFFFFFF
+ Symbols: [ 1, 2, 3, 0xFFFFFFFF ]
- Name: .llvm_addrsig_unlinked
Type: SHT_LLVM_ADDRSIG
Link: 0
- Symbols:
- - Index: 1
- - Index: 2
- - Index: 3
- - Index: 0xFFFFFFFF
+ Symbols: [ 1, 2, 3, 0xFFFFFFFF ]
Symbols:
- Name: foo
Type: STT_FUNC
@@ -82,7 +66,7 @@ Sections:
# EMPTY: - Name: .llvm_addrsig
# EMPTY-NEXT: Type: SHT_LLVM_ADDRSIG
-# EMPTY-NEXT: Symbols: []
+# EMPTY-NEXT: Symbols: [ ]
--- !ELF
FileHeader:
diff --git a/llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml b/llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml
index 1433d6dbc13e..6e235e93a6e4 100644
--- a/llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/llvm-addrsig-section.yaml
@@ -33,11 +33,7 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Name: foo
- - Name: bar
- - Index: 1
- - Index: 2
+ Symbols: [ foo, bar, 1, 2 ]
Symbols:
- Name: foo
Type: STT_FUNC
@@ -46,33 +42,10 @@ Symbols:
Type: STT_FUNC
Binding: STB_GLOBAL
-## We can't specify both "Index" and "Name" when defining a symbol.
-
-# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INDEX-NAME
-
-# INDEX-NAME: error: "Index" and "Name" cannot be used together when defining a symbol
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .llvm_addrsig
- Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Name: foo
- Index: 1
-Symbols:
- - Name: foo
- Type: STT_FUNC
- Binding: STB_GLOBAL
-
## Check we report an error if an unknown symbol is referenced in the
## SHT_LLVM_ADDRSIG section description.
-# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=SYMBOL-UNKNOWN
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=SYMBOL-UNKNOWN
# SYMBOL-UNKNOWN: error: unknown symbol referenced: 'foo' by YAML section '.llvm_addrsig'
# SYMBOL-UNKNOWN: error: unknown symbol referenced: 'bar' by YAML section '.llvm_addrsig'
@@ -86,14 +59,12 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Name: foo
- - Name: bar
+ Symbols: [ foo, bar ]
## Check we can specify any arbitrary symbol indices.
-# RUN: yaml2obj --docnum=4 %s -o %t4
-# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=SYMBOL-INDEX
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=SYMBOL-INDEX
# SYMBOL-INDEX: Type: SHT_LLVM_ADDRSIG
# SYMBOL-INDEX: SectionData (
@@ -109,18 +80,14 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Index: 0
- - Index: 255
- - Index: 0x11223344
## 0xFFFFFFFF is a maximum allowed index value.
- - Index: 0xFFFFFFFF
+ Symbols: [ 0, 255, 0x11223344, 0xFFFFFFFF ]
## Check that the maximum symbol index size is 32 bits.
-# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=SYMBOL-INDEX-OVERFLOW
+# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=SYMBOL-INDEX-OVERFLOW
-# SYMBOL-INDEX-OVERFLOW: error: out of range hex32 number
+# SYMBOL-INDEX-OVERFLOW: error: unknown symbol referenced: '0x1122334455' by YAML section '.llvm_addrsig'
--- !ELF
FileHeader:
@@ -131,13 +98,12 @@ FileHeader:
Sections:
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
- Symbols:
- - Index: 0x1122334455
+ Symbols: [ 0x1122334455 ]
## Check we can use the "Content" tag to specify any data for SHT_LLVM_ADDRSIG sections.
-# RUN: yaml2obj --docnum=6 %s -o %t6
-# RUN: llvm-readobj --sections --section-data %t6 | FileCheck %s --check-prefix=CONTENT
+# RUN: yaml2obj --docnum=5 %s -o %t5
+# RUN: llvm-readobj --sections --section-data %t5 | FileCheck %s --check-prefix=CONTENT
# CONTENT: Type: SHT_LLVM_ADDRSIG
# CONTENT: Size:
@@ -159,7 +125,7 @@ Sections:
## Either "Content" or "Symbols" must be specifed for SHT_LLVM_ADDRSIG sections.
-# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=NO-TAGS
+# RUN: not yaml2obj --docnum=6 %s 2>&1 | FileCheck %s --check-prefix=NO-TAGS
# NO-TAGS: error: one of "Content", "Size" or "Symbols" must be specified
@@ -175,7 +141,7 @@ Sections:
## "Content" and "Symbols" cannot be used together to describe the SHT_LLVM_ADDRSIG section.
-# RUN: not yaml2obj --docnum=8 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS
+# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS
# CONTENT-SYMBOLS: "Symbols" cannot be used with "Content" or "Size"
@@ -193,8 +159,8 @@ Sections:
## Check we can set an arbitrary sh_link value for SHT_LLVM_ADDRSIG sections.
-# RUN: yaml2obj --docnum=9 %s -o %t9
-# RUN: llvm-readobj --sections %t9 | FileCheck %s --check-prefix=LINK
+# RUN: yaml2obj --docnum=8 %s -o %t8
+# RUN: llvm-readobj --sections %t8 | FileCheck %s --check-prefix=LINK
# LINK: Name: .llvm_addrsig
# LINK: Link:
@@ -214,8 +180,8 @@ Sections:
## Check we can use only "Size" to create a SHT_LLVM_ADDRSIG section.
-# RUN: yaml2obj --docnum=10 %s -o %t10
-# RUN: llvm-readobj --sections --section-data %t10 | FileCheck %s --check-prefix=SIZE
+# RUN: yaml2obj --docnum=9 %s -o %t9
+# RUN: llvm-readobj --sections --section-data %t9 | FileCheck %s --check-prefix=SIZE
# SIZE: Name: .llvm_addrsig
# SIZE: Size:
@@ -238,8 +204,8 @@ Sections:
## Check we can use "Size" and "Content" together to create a SHT_LLVM_ADDRSIG section.
-# RUN: yaml2obj --docnum=11 %s -o %t11
-# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=SIZE-CONTENT
+# RUN: yaml2obj --docnum=10 %s -o %t10
+# RUN: llvm-readobj --sections --section-data %t10 | FileCheck %s --check-prefix=SIZE-CONTENT
# SIZE-CONTENT: Name: .llvm_addrsig_sizegr
# SIZE-CONTENT: Size:
@@ -274,7 +240,7 @@ Sections:
## Check that when "Size" and "Content" are used together, the size
## must be greater than or equal to the content size.
-# RUN: not yaml2obj --docnum=12 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR
+# RUN: not yaml2obj --docnum=11 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR
# SIZE-CONTENT-ERR: error: "Size" must be greater than or equal to the content size
@@ -292,7 +258,7 @@ Sections:
## Check we can't use "Size" and "Symbols" tags together.
-# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS
+# RUN: not yaml2obj --docnum=12 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-SYMBOLS
--- !ELF
FileHeader:
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 43e340bdb8be..d399b95c1cfb 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -40,6 +40,8 @@ class ELFDumper {
DenseMap<StringRef, uint32_t> UsedSymbolNames;
std::vector<std::string> SymbolNames;
+ BumpPtrAllocator StringAllocator;
+
Expected<StringRef> getUniquedSectionName(const Elf_Shdr *Sec);
Expected<StringRef> getUniquedSymbolName(const Elf_Sym *Sym,
StringRef StrTable,
@@ -603,7 +605,7 @@ ELFDumper<ELFT>::dumpAddrsigSection(const Elf_Shdr *Shdr) {
ArrayRef<uint8_t> Content = *ContentOrErr;
DataExtractor::Cursor Cur(0);
DataExtractor Data(Content, Obj.isLE(), /*AddressSize=*/0);
- std::vector<ELFYAML::AddrsigSymbol> Symbols;
+ std::vector<ELFYAML::YAMLFlowString> Symbols;
while (Cur && Cur.tell() < Content.size()) {
uint64_t SymNdx = Data.getULEB128(Cur);
if (!Cur)
@@ -612,7 +614,8 @@ ELFDumper<ELFT>::dumpAddrsigSection(const Elf_Shdr *Shdr) {
Expected<StringRef> SymbolName = getSymbolName(Shdr->sh_link, SymNdx);
if (!SymbolName || SymbolName->empty()) {
consumeError(SymbolName.takeError());
- Symbols.emplace_back(SymNdx);
+ Symbols.emplace_back(
+ StringRef(std::to_string(SymNdx)).copy(StringAllocator));
continue;
}
More information about the llvm-commits
mailing list