[lld] r248726 - Add support for local absolute symbols.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 11:29:47 PDT 2015
Author: rafael
Date: Mon Sep 28 13:29:47 2015
New Revision: 248726
URL: http://llvm.org/viewvc/llvm-project?rev=248726&view=rev
Log:
Add support for local absolute symbols.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/test/elf2/local.s
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=248726&r1=248725&r2=248726&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Sep 28 13:29:47 2015
@@ -403,24 +403,27 @@ template <class ELFT> void SymbolTableSe
Elf_Sym_Range Syms = File.getLocalSymbols();
for (const Elf_Sym &Sym : Syms) {
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
- uint32_t SecIndex = Sym.st_shndx;
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
if (SymName && !shouldKeepInSymtab(*SymName))
continue;
ESym->st_name = (SymName) ? StrTabSec.getFileOff(*SymName) : 0;
ESym->st_size = Sym.st_size;
ESym->setBindingAndType(Sym.getBinding(), Sym.getType());
- if (SecIndex == SHN_XINDEX)
- SecIndex = File.getObj().getExtendedSymbolTableIndex(
- &Sym, File.getSymbolTable(), File.getSymbolTableShndx());
- ArrayRef<InputSection<ELFT> *> Sections = File.getSections();
- const InputSection<ELFT> *Section = Sections[SecIndex];
- assert(Section != nullptr);
- const OutputSection<ELFT> *Out = Section->getOutputSection();
- assert(Out != nullptr);
- ESym->st_shndx = Out->getSectionIndex();
- ESym->st_value =
- Out->getVA() + Section->getOutputSectionOff() + Sym.st_value;
+ uint32_t SecIndex = Sym.st_shndx;
+ uintX_t VA = Sym.st_value;
+ if (SecIndex == SHN_ABS) {
+ ESym->st_shndx = SHN_ABS;
+ } else {
+ if (SecIndex == SHN_XINDEX)
+ SecIndex = File.getObj().getExtendedSymbolTableIndex(
+ &Sym, File.getSymbolTable(), File.getSymbolTableShndx());
+ ArrayRef<InputSection<ELFT> *> Sections = File.getSections();
+ const InputSection<ELFT> *Section = Sections[SecIndex];
+ const OutputSection<ELFT> *Out = Section->getOutputSection();
+ ESym->st_shndx = Out->getSectionIndex();
+ VA += Out->getVA() + Section->getOutputSectionOff();
+ }
+ ESym->st_value = VA;
Buf += sizeof(Elf_Sym);
}
}
Modified: lld/trunk/test/elf2/local.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/local.s?rev=248726&r1=248725&r2=248726&view=diff
==============================================================================
--- lld/trunk/test/elf2/local.s (original)
+++ lld/trunk/test/elf2/local.s Mon Sep 28 13:29:47 2015
@@ -14,7 +14,7 @@
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size:
// CHECK-NEXT: Link:
-// CHECK-NEXT: Info: 4
+// CHECK-NEXT: Info: 5
// CHECK: Symbols [
// CHECK-NEXT: Symbol {
@@ -27,6 +27,15 @@
// CHECK-NEXT: Section: Undefined
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: abs
+// CHECK-NEXT: Value: 0x2A
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local
+// CHECK-NEXT: Type: None
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: Absolute
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: blah
// CHECK-NEXT: Value: 0x11000
// CHECK-NEXT: Size: 0
@@ -70,3 +79,4 @@ _start:
blah:
foo:
goo:
+abs = 42
More information about the llvm-commits
mailing list