Index: llvm/include/llvm/ObjectYAML/ELFYAML.h =================================================================== --- llvm/include/llvm/ObjectYAML/ELFYAML.h +++ llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -102,7 +102,6 @@ struct Symbol { StringRef Name; - Optional NameIndex; ELF_STT Type; StringRef Section; Optional Index; @@ -110,6 +109,8 @@ llvm::yaml::Hex64 Value; llvm::yaml::Hex64 Size; Optional Other; + + Optional StName; }; struct SectionOrType { Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -543,8 +543,8 @@ // 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)); Index: llvm/lib/ObjectYAML/ELFYAML.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFYAML.cpp +++ llvm/lib/ObjectYAML/ELFYAML.cpp @@ -984,7 +984,7 @@ void MappingTraits::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 @@ 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(); } Index: llvm/test/tools/yaml2obj/ELF/symbol-name.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/symbol-name.yaml +++ llvm/test/tools/yaml2obj/ELF/symbol-name.yaml @@ -16,22 +16,69 @@ 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 a priority, but symbol Name is still added +## to the string symbol 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