[yaml2obj][ELF] Allow expressing undefined symbols.
authorSean Silva <silvas@purdue.edu>
Fri, 21 Jun 2013 01:11:48 +0000 (01:11 +0000)
committerSean Silva <silvas@purdue.edu>
Fri, 21 Jun 2013 01:11:48 +0000 (01:11 +0000)
Previously we unconditionally enforced that section references in
symbols in the YAML had a name that was a section name present in the
object, and linked the references to that section. Now, permit empty
section names (already the default, if the `Section` key is not
provided) to indicate SHN_UNDEF.

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

test/Object/yaml2obj-elf-symbol-basic.yaml
tools/yaml2obj/yaml2elf.cpp

index 238348b9b0e198ca4ec1aacee4c28f7b4755ccb7..f19db424509376238c29b82733a2f67539b94906 100644 (file)
@@ -26,6 +26,7 @@ Sections:
           Section: .text
           Value: 0x1
           Size: 2
+        - Name: undefined_symbol
 
 # CHECK:      Symbols [
 # CHECK-NEXT:   Symbol {
@@ -37,6 +38,9 @@ Sections:
 # CHECK:          Binding: Global
 # CHECK-NEXT:     Type: Function
 # CHECK:          Section: .text
+# CHECK:        Symbol {
+# CHECK:          Name: undefined_symbol
+# CHECK:          Section:  (0x0)
 
 # DISASSEMBLY:      Disassembly of section .text:
 # DISASSEMBLY-NEXT: main:
index f9bc566f7362173a33020b723aaa63c1dcc956a8..ac6b330e667ba228be4dc2c195277e483c793af7 100644 (file)
@@ -184,13 +184,15 @@ addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, ELFState<ELFT> &State,
     if (!Sym.Name.empty())
       Symbol.st_name = State.getStringTable().addString(Sym.Name);
     Symbol.setBindingAndType(SymbolBinding, Sym.Type);
-    unsigned Index;
-    if (State.getSN2I().lookupSection(Sym.Section, Index)) {
-      errs() << "error: Unknown section referenced: '" << Sym.Section
-             << "' by YAML symbol " << Sym.Name << ".\n";
-      exit(1);
-    }
-    Symbol.st_shndx = Index;
+    if (!Sym.Section.empty()) {
+      unsigned Index;
+      if (State.getSN2I().lookupSection(Sym.Section, Index)) {
+        errs() << "error: Unknown section referenced: '" << Sym.Section
+               << "' by YAML symbol " << Sym.Name << ".\n";
+        exit(1);
+      }
+      Symbol.st_shndx = Index;
+    } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
     Symbol.st_value = Sym.Value;
     Symbol.st_size = Sym.Size;
     Syms.push_back(Symbol);