OSDN Git Service

[yaml2elf] - Simplify code, add a test. NFC.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 16 Aug 2018 12:23:22 +0000 (12:23 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 16 Aug 2018 12:23:22 +0000 (12:23 +0000)
This simplifies the code allowing to set the sh_info
for relocations sections. And adds a missing test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339870 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/yaml2obj/reloc-sec-info.yaml [new file with mode: 0644]
tools/yaml2obj/yaml2elf.cpp

diff --git a/test/tools/yaml2obj/reloc-sec-info.yaml b/test/tools/yaml2obj/reloc-sec-info.yaml
new file mode 100644 (file)
index 0000000..8810bd7
--- /dev/null
@@ -0,0 +1,25 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+# CHECK: Name: .rela.text
+# CHECK: Type: SHT_RELA
+# CHECK: Flags [
+# CHECK: ]
+# CHECK: Address:
+# CHECK: Offset:
+# CHECK: Size:
+# CHECK: Link:
+# CHECK: Info: 12345
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .rela.text
+    Type:            SHT_RELA
+    Link:            .symtab
+    Info:            12345
+    Relocations:
index ec8cec1..99f55d1 100644 (file)
@@ -261,12 +261,10 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
         SHeader.sh_link = getDotSymTabSecNo();
 
       unsigned Index;
-      if (SN2I.lookup(S->Info, Index)) {
-        if (S->Info.getAsInteger(0, Index)) {
-          WithColor::error() << "Unknown section referenced: '" << S->Info
-                             << "' at YAML section '" << S->Name << "'.\n";
-          return false;
-        }
+      if (SN2I.lookup(S->Info, Index) && !to_integer(S->Info, Index)) {
+        WithColor::error() << "Unknown section referenced: '" << S->Info
+                           << "' at YAML section '" << S->Name << "'.\n";
+        return false;
       }
       SHeader.sh_info = Index;