summaryrefslogtreecommitdiff
path: root/lib/CodeGen/ELFWriter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-07-12 06:57:52 +0000
committerChris Lattner <sabre@nondot.org>2005-07-12 06:57:52 +0000
commit46c53054d0af0a99edf98309ff11affe92a17f19 (patch)
treeb26698a90048ece994b7979573ee328e413f5c2c /lib/CodeGen/ELFWriter.cpp
parent39429617e05721c7cee22b745311d60d6741c8fc (diff)
downloadllvm-46c53054d0af0a99edf98309ff11affe92a17f19.tar.gz
llvm-46c53054d0af0a99edf98309ff11affe92a17f19.tar.bz2
llvm-46c53054d0af0a99edf98309ff11affe92a17f19.tar.xz
Add support for 64-bit elf files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22400 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/ELFWriter.cpp')
-rw-r--r--lib/CodeGen/ELFWriter.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp
index 198e9cca5e..cc8895df09 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -197,11 +197,10 @@ bool ELFWriter::doInitialization(Module &M) {
outaddr(0); // e_shoff
outword(e_flags); // e_flags = whatever the target wants
- assert(!is64Bit && "These sizes need to be adjusted for 64-bit!");
- outhalf(52); // e_ehsize = ELF header size
+ outhalf(is64Bit ? 64 : 52); // e_ehsize = ELF header size
outhalf(0); // e_phentsize = prog header entry size
outhalf(0); // e_phnum = # prog header entries = 0
- outhalf(40); // e_shentsize = sect header entry size
+ outhalf(is64Bit ? 64 : 40); // e_shentsize = sect header entry size
ELFHeader_e_shnum_Offset = OutputBuffer.size();
@@ -409,27 +408,36 @@ void ELFWriter::EmitSymbolTable() {
// Now that we have emitted the string table and know the offset into the
// string table of each symbol, emit the symbol table itself.
- assert(!is64Bit && "Should this be 8 byte aligned for 64-bit?"
- " (check .Align below also)");
- align(4);
+ align(is64Bit ? 8 : 4);
SectionList.push_back(ELFSection(".symtab", OutputBuffer.size()));
ELFSection &SymTab = SectionList.back();
SymTab.Type = ELFSection::SHT_SYMTAB;
- SymTab.Align = 4; // FIXME: check for ELF64
+ SymTab.Align = is64Bit ? 8 : 4;
SymTab.Link = SectionList.size()-2; // Section Index of .strtab.
SymTab.Info = FirstNonLocalSymbol; // First non-STB_LOCAL symbol.
SymTab.EntSize = 16; // Size of each symtab entry. FIXME: wrong for ELF64
- assert(!is64Bit && "check this!");
- for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
- ELFSym &Sym = SymbolTable[i];
- outword(Sym.NameIdx);
- outaddr(Sym.Value);
- outword(Sym.Size);
- outbyte(Sym.Info);
- outbyte(Sym.Other);
- outhalf(Sym.SectionIdx);
+ if (!is64Bit) { // 32-bit and 64-bit formats are shuffled a bit.
+ for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
+ ELFSym &Sym = SymbolTable[i];
+ outword(Sym.NameIdx);
+ outaddr32(Sym.Value);
+ outword(Sym.Size);
+ outbyte(Sym.Info);
+ outbyte(Sym.Other);
+ outhalf(Sym.SectionIdx);
+ }
+ } else {
+ for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) {
+ ELFSym &Sym = SymbolTable[i];
+ outword(Sym.NameIdx);
+ outbyte(Sym.Info);
+ outbyte(Sym.Other);
+ outhalf(Sym.SectionIdx);
+ outaddr64(Sym.Value);
+ outxword(Sym.Size);
+ }
}
SymTab.Size = OutputBuffer.size()-SymTab.Offset;