Index: test/tools/yaml2obj/symbol-name.yaml =================================================================== --- /dev/null +++ test/tools/yaml2obj/symbol-name.yaml @@ -0,0 +1,20 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-readobj --symbols %t | FileCheck %s + +# Check we are able to use integers for symbol names and +# yaml2obj use them as explicit st_name value for symbols. + +# CHECK: Name: test (1) +# CHECK: Name: test (1) +# CHECK: Name: est (2) + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Symbols: + - Name: test + - Name: 1 + - Name: 2 Index: tools/yaml2obj/yaml2elf.cpp =================================================================== --- tools/yaml2obj/yaml2elf.cpp +++ tools/yaml2obj/yaml2elf.cpp @@ -480,8 +480,18 @@ for (const auto &Sym : Symbols) { Elf_Sym Symbol; zero(Symbol); - if (!Sym.Name.empty()) - Symbol.st_name = Strtab.getOffset(Sym.Name); + + // If name described in YAML as an integer, we assume it is an offset and + // use it. It is useful for preparing broken objects. Otherwise, we treat it + // as a string name and add to the string table builder. + if (!Sym.Name.empty()) { + unsigned SymName = 0; + if (!to_integer(Sym.Name, SymName)) + Symbol.st_name = Strtab.getOffset(Sym.Name); + else + Symbol.st_name = SymName; + } + Symbol.setBindingAndType(Sym.Binding, Sym.Type); if (!Sym.Section.empty()) { unsigned Index;