summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Silva <silvas@purdue.edu>2013-06-21 01:11:48 +0000
committerSean Silva <silvas@purdue.edu>2013-06-21 01:11:48 +0000
commit326c193e0aa221c7836adfa16a3ec85857d7d8b7 (patch)
tree37850acc56eaa7426c17c9fc2264c7e3e89b6c49
parent552d7cd31a0f6eb0e1434981196f477ae741a184 (diff)
downloadllvm-326c193e0aa221c7836adfa16a3ec85857d7d8b7.tar.gz
llvm-326c193e0aa221c7836adfa16a3ec85857d7d8b7.tar.bz2
llvm-326c193e0aa221c7836adfa16a3ec85857d7d8b7.tar.xz
[yaml2obj][ELF] Allow expressing undefined symbols.
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
-rw-r--r--test/Object/yaml2obj-elf-symbol-basic.yaml4
-rw-r--r--tools/yaml2obj/yaml2elf.cpp16
2 files changed, 13 insertions, 7 deletions
diff --git a/test/Object/yaml2obj-elf-symbol-basic.yaml b/test/Object/yaml2obj-elf-symbol-basic.yaml
index 238348b9b0..f19db42450 100644
--- a/test/Object/yaml2obj-elf-symbol-basic.yaml
+++ b/test/Object/yaml2obj-elf-symbol-basic.yaml
@@ -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:
diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp
index f9bc566f73..ac6b330e66 100644
--- a/tools/yaml2obj/yaml2elf.cpp
+++ b/tools/yaml2obj/yaml2elf.cpp
@@ -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);