[llvm] fd0abcb - [yaml2obj] - Change NameIndex to StName for Symbol.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 6 01:04:48 PST 2020
Author: Georgii Rymar
Date: 2020-02-06T12:04:19+03:00
New Revision: fd0abcbfc18f9ed250ce3a95e1a979f0c01649ec
URL: https://github.com/llvm/llvm-project/commit/fd0abcbfc18f9ed250ce3a95e1a979f0c01649ec
DIFF: https://github.com/llvm/llvm-project/commit/fd0abcbfc18f9ed250ce3a95e1a979f0c01649ec.diff
LOG: [yaml2obj] - Change NameIndex to StName for Symbol.
It is consistent with the approach we use for Section struct.
Differential revision: https://reviews.llvm.org/D74034
Added:
Modified:
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/yaml2obj/ELF/symbol-name.yaml
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index f519c5195c91..0d808b660e15 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -102,7 +102,6 @@ struct ProgramHeader {
struct Symbol {
StringRef Name;
- Optional<uint32_t> NameIndex;
ELF_STT Type;
StringRef Section;
Optional<ELF_SHN> Index;
@@ -110,6 +109,8 @@ struct Symbol {
llvm::yaml::Hex64 Value;
llvm::yaml::Hex64 Size;
Optional<uint8_t> Other;
+
+ Optional<uint32_t> StName;
};
struct SectionOrType {
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 55d6ccb6c009..4d9d2fbe0020 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -543,8 +543,8 @@ ELFState<ELFT>::toELFSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
// If NameIndex, which contains the name offset, is explicitly specified, we
// use it. This is useful for preparing broken objects. Otherwise, we add
// the specified Name to the string table builder to get its offset.
- if (Sym.NameIndex)
- Symbol.st_name = *Sym.NameIndex;
+ if (Sym.StName)
+ Symbol.st_name = *Sym.StName;
else if (!Sym.Name.empty())
Symbol.st_name = Strtab.getOffset(ELFYAML::dropUniqueSuffix(Sym.Name));
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 2af348f67408..6a553a7a9854 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -984,7 +984,7 @@ struct NormalizedOther {
void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
IO.mapOptional("Name", Symbol.Name, StringRef());
- IO.mapOptional("NameIndex", Symbol.NameIndex);
+ IO.mapOptional("StName", Symbol.StName);
IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
IO.mapOptional("Section", Symbol.Section, StringRef());
IO.mapOptional("Index", Symbol.Index);
@@ -1006,8 +1006,6 @@ StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
ELFYAML::Symbol &Symbol) {
if (Symbol.Index && Symbol.Section.data())
return "Index and Section cannot both be specified for Symbol";
- if (Symbol.NameIndex && !Symbol.Name.empty())
- return "Name and NameIndex cannot both be specified for Symbol";
return StringRef();
}
diff --git a/llvm/test/tools/yaml2obj/ELF/symbol-name.yaml b/llvm/test/tools/yaml2obj/ELF/symbol-name.yaml
index eb07eaeaced7..599676fcf6ae 100644
--- a/llvm/test/tools/yaml2obj/ELF/symbol-name.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/symbol-name.yaml
@@ -16,22 +16,69 @@ FileHeader:
Type: ET_REL
Machine: EM_X86_64
Symbols:
- - Name: test
- - NameIndex: 1
- - NameIndex: 2
- - Name: 1
- - Name: 2
+ - Name: test
+ - StName: 1
+ - StName: 2
+ - Name: 1
+ - Name: 2
-## Check we do not allow specifying both Name and NameIndex at once.
-# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=ERR
-# ERR: error: Name and NameIndex cannot both be specified for Symbol
+## Check we allow specifying both Name and StName at once.
+## In this case StName has priority, but the symbol Name is still added
+## to the symbol string table.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj --symbols --sections --section-data -r --expand-relocs %t2 | FileCheck %s --check-prefix=BOTH
+
+# BOTH: Name: .strtab
+# BOTH: SectionData (
+# BOTH-NEXT: 0000: 00666F6F 00 |.foo.|
+# BOTH-NEXT: )
+
+# BOTH: Relocations [
+# BOTH-NEXT: Section (1) .rela.data {
+# BOTH-NEXT: Relocation {
+# BOTH-NEXT: Offset: 0x0
+# BOTH-NEXT: Type: R_X86_64_NONE (0)
+# BOTH-NEXT: Symbol: - (1)
+# BOTH-NEXT: Addend: 0x0
+# BOTH-NEXT: }
+# BOTH-NEXT: }
+# BOTH-NEXT: ]
+
+# BOTH: Symbols [
+# BOTH-NEXT: Symbol {
+# BOTH-NEXT: Name: (0)
+# BOTH-NEXT: Value: 0x0
+# BOTH-NEXT: Size: 0
+# BOTH-NEXT: Binding: Local (0x0)
+# BOTH-NEXT: Type: None (0x0)
+# BOTH-NEXT: Other: 0
+# BOTH-NEXT: Section: Undefined (0x0)
+# BOTH-NEXT: }
+# BOTH-NEXT: Symbol {
+# BOTH-NEXT: Name: (0)
+# BOTH-NEXT: Value: 0x0
+# BOTH-NEXT: Size: 0
+# BOTH-NEXT: Binding: Local (0x0)
+# BOTH-NEXT: Type: None (0x0)
+# BOTH-NEXT: Other: 0
+# BOTH-NEXT: Section: Undefined (0x0)
+# BOTH-NEXT: }
+# BOTH-NEXT: ]
--- !ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .rela.data
+ Type: SHT_RELA
+ Relocations:
+ - Offset: 0x0
+ Type: R_X86_64_NONE
+ Symbol: foo
Symbols:
- - Name: foo
- NameIndex: 0
+ - Name: foo
+ StName: 0
More information about the llvm-commits
mailing list