[ELF2] Fill up local symbols fields correctly.

Differential Revision:	http://reviews.llvm.org/D12944

llvm-svn: 247960
This commit is contained in:
Davide Italiano 2015-09-18 01:08:17 +00:00
parent 097ce205b0
commit b5b47b432b
4 changed files with 33 additions and 15 deletions

View File

@ -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();

View File

@ -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 SymbolBody &B) {
}
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 SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
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 SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
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:

View File

@ -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

View File

@ -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