Index: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h =================================================================== --- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h +++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h @@ -102,10 +102,11 @@ uint8_t Other; }; -struct LocalGlobalWeakSymbols { +struct SymbolsDef { std::vector Local; std::vector Global; std::vector Weak; + std::vector GNUUnique; }; struct SectionOrType { @@ -288,8 +289,8 @@ // cleaner and nicer if we read them from the YAML as a separate // top-level key, which automatically ensures that invariants like there // being a single SHT_SYMTAB section are upheld. - LocalGlobalWeakSymbols Symbols; - LocalGlobalWeakSymbols DynamicSymbols; + SymbolsDef Symbols; + SymbolsDef DynamicSymbols; }; } // end namespace ELFYAML @@ -436,9 +437,8 @@ static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol); }; -template <> -struct MappingTraits { - static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols); +template <> struct MappingTraits { + static void mapping(IO &IO, ELFYAML::SymbolsDef &Symbols); }; template <> struct MappingTraits { Index: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp +++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp @@ -864,11 +864,12 @@ return StringRef(); } -void MappingTraits::mapping( - IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) { +void MappingTraits::mapping(IO &IO, + ELFYAML::SymbolsDef &Symbols) { IO.mapOptional("Local", Symbols.Local); IO.mapOptional("Global", Symbols.Global); IO.mapOptional("Weak", Symbols.Weak); + IO.mapOptional("GNUUnique", Symbols.GNUUnique); } static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) { Index: llvm/trunk/test/tools/obj2yaml/elf-gnu-unique-symbols.yaml =================================================================== --- llvm/trunk/test/tools/obj2yaml/elf-gnu-unique-symbols.yaml +++ llvm/trunk/test/tools/obj2yaml/elf-gnu-unique-symbols.yaml @@ -0,0 +1,30 @@ +# RUN: yaml2obj %s -o %t +# RUN: obj2yaml %t | FileCheck %s + +## Check obj2yaml is able to dump the STB_GNU_UNIQUE symbol. + +# CHECK: --- !ELF +# CHECK-NEXT: FileHeader: +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: OSABI: ELFOSABI_GNU +# CHECK-NEXT: Type: ET_REL +# CHECK-NEXT: Machine: EM_X86_64 +# CHECK-NEXT: Symbols: +# CHECK-NEXT: GNUUnique: +# CHECK-NEXT: - Name: foo +# CHECK-NEXT: Type: STT_OBJECT +# CHECK-NEXT: DynamicSymbols: {} +# CHECK-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Symbols: + GNUUnique: + - Name: foo + Type: STT_OBJECT Index: llvm/trunk/test/tools/yaml2obj/elf-gnu-unique-symbols.yaml =================================================================== --- llvm/trunk/test/tools/yaml2obj/elf-gnu-unique-symbols.yaml +++ llvm/trunk/test/tools/yaml2obj/elf-gnu-unique-symbols.yaml @@ -0,0 +1,21 @@ +# RUN: yaml2obj %s -o %t +# RUN: llvm-readobj -symbols %t | FileCheck %s + +## Check yaml2obj is able to create the STB_GNU_UNIQUE symbol. + +# CHECK: Name: foo +# CHECK-NEXT: Value: +# CHECK-NEXT: Size: +# CHECK-NEXT: Binding: Unique + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_X86_64 +Symbols: + GNUUnique: + - Name: foo + Type: STT_OBJECT Index: llvm/trunk/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/trunk/tools/obj2yaml/elf2yaml.cpp +++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp @@ -42,7 +42,7 @@ ArrayRef ShndxTable; std::error_code dumpSymbols(const Elf_Shdr *Symtab, - ELFYAML::LocalGlobalWeakSymbols &Symbols); + ELFYAML::SymbolsDef &Symbols); std::error_code dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab, StringRef StrTable, ELFYAML::Symbol &S); std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); @@ -226,9 +226,8 @@ } template -std::error_code -ELFDumper::dumpSymbols(const Elf_Shdr *Symtab, - ELFYAML::LocalGlobalWeakSymbols &Symbols) { +std::error_code ELFDumper::dumpSymbols(const Elf_Shdr *Symtab, + ELFYAML::SymbolsDef &Symbols) { if (!Symtab) return std::error_code(); @@ -262,6 +261,9 @@ case ELF::STB_WEAK: Symbols.Weak.push_back(S); break; + case ELF::STB_GNU_UNIQUE: + Symbols.GNUUnique.push_back(S); + break; default: llvm_unreachable("Unknown ELF symbol binding"); } Index: llvm/trunk/tools/yaml2obj/yaml2elf.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2elf.cpp +++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp @@ -133,7 +133,7 @@ const ELFYAML::Object &Doc; bool buildSectionIndex(); - bool buildSymbolIndex(const ELFYAML::LocalGlobalWeakSymbols &); + bool buildSymbolIndex(const ELFYAML::SymbolsDef &); void initELFHeader(Elf_Ehdr &Header); void initProgramHeaders(std::vector &PHeaders); bool initSectionHeaders(std::vector &SHeaders, @@ -362,6 +362,7 @@ addSymbols(Symbols.Local, Syms, ELF::STB_LOCAL, Strtab); addSymbols(Symbols.Global, Syms, ELF::STB_GLOBAL, Strtab); addSymbols(Symbols.Weak, Syms, ELF::STB_WEAK, Strtab); + addSymbols(Symbols.GNUUnique, Syms, ELF::STB_GNU_UNIQUE, Strtab); writeArrayData( CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign), @@ -795,11 +796,10 @@ } template -bool ELFState::buildSymbolIndex( - const ELFYAML::LocalGlobalWeakSymbols &Symbols) { +bool ELFState::buildSymbolIndex(const ELFYAML::SymbolsDef &Symbols) { std::size_t I = 0; for (const std::vector &V : - {Symbols.Local, Symbols.Global, Symbols.Weak}) { + {Symbols.Local, Symbols.Global, Symbols.Weak, Symbols.GNUUnique}) { for (const auto &Sym : V) { ++I; if (Sym.Name.empty()) @@ -815,13 +815,15 @@ template void ELFState::finalizeStrings() { auto AddSymbols = [](StringTableBuilder &StrTab, - const ELFYAML::LocalGlobalWeakSymbols &Symbols) { + const ELFYAML::SymbolsDef &Symbols) { for (const auto &Sym : Symbols.Local) StrTab.add(Sym.Name); for (const auto &Sym : Symbols.Global) StrTab.add(Sym.Name); for (const auto &Sym : Symbols.Weak) StrTab.add(Sym.Name); + for (const auto &Sym : Symbols.GNUUnique) + StrTab.add(Sym.Name); }; // Add the regular symbol names to .strtab section. @@ -919,9 +921,10 @@ } template bool ELFState::hasDynamicSymbols() const { - return Doc.DynamicSymbols.Global.size() > 0 || - Doc.DynamicSymbols.Weak.size() > 0 || - Doc.DynamicSymbols.Local.size() > 0; + return !Doc.DynamicSymbols.Global.empty() || + !Doc.DynamicSymbols.Weak.empty() || + !Doc.DynamicSymbols.Local.empty() || + !Doc.DynamicSymbols.GNUUnique.empty(); } template