[PATCH] D61180: [yaml2obj] - Treat integer symbol names as explicit st_name value.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 26 03:49:14 PDT 2019
grimar created this revision.
grimar added a reviewer: jhenderson.
Herald added a subscriber: jakehehrlich.
In some cases it is useful to explicitly set symbol's st_name value.
For example, I am using it in a patch for LLD to remove the broken
binary from a test case and replace it with a YAML test.
https://reviews.llvm.org/D61180
Files:
test/tools/yaml2obj/symbol-name.yaml
tools/yaml2obj/yaml2elf.cpp
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;
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61180.196829.patch
Type: text/x-patch
Size: 1524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190426/8d3aa083/attachment-0001.bin>
More information about the llvm-commits
mailing list