yaml2obj/obj2yaml does not support the symbols with STB_GNU_UNIQUE yet.
Currently, obj2yaml fails with llvm_unreachable when met such a symbol.
I faced it when investigated the https://bugs.llvm.org/show_bug.cgi?id=41196.
Differential revision: https://reviews.llvm.org/D59875
llvm-svn: 357158
uint8_t Other;
};
-struct LocalGlobalWeakSymbols {
+struct SymbolsDef {
std::vector<Symbol> Local;
std::vector<Symbol> Global;
std::vector<Symbol> Weak;
+ std::vector<Symbol> GNUUnique;
};
struct SectionOrType {
// 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
static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
};
-template <>
-struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
- static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
+template <> struct MappingTraits<ELFYAML::SymbolsDef> {
+ static void mapping(IO &IO, ELFYAML::SymbolsDef &Symbols);
};
template <> struct MappingTraits<ELFYAML::DynamicEntry> {
return StringRef();
}
-void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
- IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
+void MappingTraits<ELFYAML::SymbolsDef>::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) {
--- /dev/null
+# 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
--- /dev/null
+# 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
ArrayRef<Elf_Word> 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);
}
template <class ELFT>
-std::error_code
-ELFDumper<ELFT>::dumpSymbols(const Elf_Shdr *Symtab,
- ELFYAML::LocalGlobalWeakSymbols &Symbols) {
+std::error_code ELFDumper<ELFT>::dumpSymbols(const Elf_Shdr *Symtab,
+ ELFYAML::SymbolsDef &Symbols) {
if (!Symtab)
return std::error_code();
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");
}
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<Elf_Phdr> &PHeaders);
bool initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
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),
}
template <class ELFT>
-bool ELFState<ELFT>::buildSymbolIndex(
- const ELFYAML::LocalGlobalWeakSymbols &Symbols) {
+bool ELFState<ELFT>::buildSymbolIndex(const ELFYAML::SymbolsDef &Symbols) {
std::size_t I = 0;
for (const std::vector<ELFYAML::Symbol> &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())
template <class ELFT> void ELFState<ELFT>::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.
}
template <class ELFT> bool ELFState<ELFT>::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 <class ELFT>