[PATCH] D58498: [obj2yaml] - Do not miss section index for SHN_ABS and SHN_COMMON symbols.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 21 03:31:14 PST 2019
grimar created this revision.
grimar added a reviewer: jhenderson.
Herald added a subscriber: arphaman.
This fixes https://bugs.llvm.org/show_bug.cgi?id=40786
("obj2yaml symbol output missing section index for SHN_ABS and SHN_COMMON symbols")
Since SHN_ABS and SHN_COMMON symbols are special, we should preserve
the st_shndx for them. The patch does this.
https://reviews.llvm.org/D58498
Files:
test/tools/yaml2obj/abs-common-symbols.yaml
tools/obj2yaml/elf2yaml.cpp
Index: tools/obj2yaml/elf2yaml.cpp
===================================================================
--- tools/obj2yaml/elf2yaml.cpp
+++ tools/obj2yaml/elf2yaml.cpp
@@ -276,6 +276,11 @@
return errorToErrorCode(SymbolNameOrErr.takeError());
S.Name = SymbolNameOrErr.get();
+ if (Sym->st_shndx == ELF::SHN_ABS || Sym->st_shndx == ELF::SHN_COMMON) {
+ S.Index = (ELFYAML::ELF_SHN)Sym->st_shndx;
+ return obj2yaml_error::success;
+ }
+
auto ShdrOrErr = Obj.getSection(Sym, SymTab, ShndxTable);
if (!ShdrOrErr)
return errorToErrorCode(ShdrOrErr.takeError());
Index: test/tools/yaml2obj/abs-common-symbols.yaml
===================================================================
--- /dev/null
+++ test/tools/yaml2obj/abs-common-symbols.yaml
@@ -0,0 +1,41 @@
+# RUN: yaml2obj %s > %t
+# RUN: obj2yaml %t | FileCheck %s
+
+# CHECK: Symbols:
+# CHECK-NEXT: Global:
+# CHECK-NEXT: - Name: absolute1
+# CHECK-NEXT: Index: SHN_ABS
+# CHECK-NEXT: Value: 0x0000000000001234
+# CHECK-NEXT: - Name: absolute2
+# CHECK-NEXT: Index: SHN_ABS
+# CHECK-NEXT: Value: 0x0000000000004321
+# CHECK-NEXT: - Name: common1
+# CHECK-NEXT: Index: SHN_COMMON
+# CHECK-NEXT: - Name: common2
+# CHECK-NEXT: Index: SHN_COMMON
+# CHECK-NEXT: - Name: valid_index
+# CHECK-NEXT: Section: .text
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+Symbols:
+ Global:
+ - Name: absolute1
+ Index: SHN_ABS
+ Value: 0x1234
+ - Name: absolute2
+ Index: 0xfff1
+ Value: 0x4321
+ - Name: common1
+ Index: SHN_COMMON
+ - Name: common2
+ Index: 0xfff2
+ - Name: valid_index
+ Index: 0x1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58498.187759.patch
Type: text/x-patch
Size: 1902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190221/869d8563/attachment.bin>
More information about the llvm-commits
mailing list