[lld] r247960 - [ELF2] Fill up local symbols fields correctly.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 18:08:18 PDT 2015
Author: davide
Date: Thu Sep 17 20:08:17 2015
New Revision: 247960
URL: http://llvm.org/viewvc/llvm-project?rev=247960&view=rev
Log:
[ELF2] Fill up local symbols fields correctly.
Differential Revision: http://reviews.llvm.org/D12944
Modified:
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/local-dynamic.s
lld/trunk/test/elf2/local.s
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=247960&r1=247959&r2=247960&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Sep 17 20:08:17 2015
@@ -143,6 +143,9 @@ public:
Elf_Sym_Range getLocalSymbols();
+ const Elf_Shdr *getSymbolTable() { return this->Symtab; };
+ ArrayRef<Elf_Word> getSymbolTableShndx() { return SymtabSHNDX; };
+
private:
void initializeChunks();
void initializeSymbols();
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247960&r1=247959&r2=247960&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 17 20:08:17 2015
@@ -223,6 +223,7 @@ template <class ELFT> class Writer;
template <class ELFT>
class SymbolTableSection final : public OutputSectionBase<ELFT::Is64Bits> {
public:
+ typedef typename ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFFile<ELFT>::Elf_Sym_Range Elf_Sym_Range;
typedef typename OutputSectionBase<ELFT::Is64Bits>::uintX_t uintX_t;
@@ -733,6 +734,8 @@ static bool includeInSymtab(const Symbol
}
template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
+ const OutputSection<ELFT> *Out = nullptr;
+ const SectionChunk<ELFT> *Section = nullptr;
Buf += sizeof(Elf_Sym);
// All symbols with STB_LOCAL binding precede the weak and global symbols.
@@ -744,10 +747,22 @@ 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());
ESym->st_name = (SymName) ? StrTabSec.getFileOff(*SymName) : 0;
- ESym->st_value = Sym.st_value;
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<SectionChunk<ELFT> *> Chunks = File.getChunks();
+ Section = Chunks[SecIndex];
+ assert(Section != nullptr);
+ Out = Section->getOutputSection();
+ assert(Out != nullptr);
+ ESym->st_shndx = Out->getSectionIndex();
+ ESym->st_value =
+ Out->getVA() + Section->getOutputSectionOff() + Sym.st_value;
Buf += sizeof(Elf_Sym);
}
}
@@ -764,8 +779,8 @@ template <class ELFT> void SymbolTableSe
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
ESym->st_name = StrTabSec.getFileOff(Name);
- const SectionChunk<ELFT> *Section = nullptr;
- const OutputSection<ELFT> *Out = nullptr;
+ Out = nullptr;
+ Section = nullptr;
switch (Body->kind()) {
case SymbolBody::DefinedRegularKind:
Modified: lld/trunk/test/elf2/local-dynamic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/local-dynamic.s?rev=247960&r1=247959&r2=247960&view=diff
==============================================================================
--- lld/trunk/test/elf2/local-dynamic.s (original)
+++ lld/trunk/test/elf2/local-dynamic.s Thu Sep 17 20:08:17 2015
@@ -16,30 +16,30 @@
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: blah
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x1000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: foo
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x1000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: goo
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x1000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: _start
Modified: lld/trunk/test/elf2/local.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/local.s?rev=247960&r1=247959&r2=247960&view=diff
==============================================================================
--- lld/trunk/test/elf2/local.s (original)
+++ lld/trunk/test/elf2/local.s Thu Sep 17 20:08:17 2015
@@ -28,30 +28,30 @@
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: blah
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x11000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: foo
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x11000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: goo
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x11000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: _start
More information about the llvm-commits
mailing list