diff options
author | Chris Lattner <sabre@nondot.org> | 2005-07-11 06:17:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-07-11 06:17:35 +0000 |
commit | 5bacb00452782584e6690dce4cdc8b4a1e9fb3bf (patch) | |
tree | 5ad5a245dde31305716a0a327800f58b4c3ccf9f /llvm/lib/CodeGen/ELFWriter.cpp | |
parent | c1b8551e3a9d6420a6d00f3dfdeed3fea6ecbec8 (diff) | |
download | bcm5719-llvm-5bacb00452782584e6690dce4cdc8b4a1e9fb3bf.tar.gz bcm5719-llvm-5bacb00452782584e6690dce4cdc8b4a1e9fb3bf.zip |
Emit a symbol table entry for each function we output to the ELF file. This
allows objdump to know which function we are emitting to:
00000000 <foo>: <----
0: b8 01 00 00 00 mov $0x1,%eax
5: 03 44 24 04 add 0x4(%esp,1),%eax
9: c3 ret
... and allows .o files to be useful for linking :)
llvm-svn: 22378
Diffstat (limited to 'llvm/lib/CodeGen/ELFWriter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/ELFWriter.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/ELFWriter.cpp b/llvm/lib/CodeGen/ELFWriter.cpp index 96668e29ecb..2f2eec0ec20 100644 --- a/llvm/lib/CodeGen/ELFWriter.cpp +++ b/llvm/lib/CodeGen/ELFWriter.cpp @@ -67,7 +67,37 @@ namespace llvm { FnStart = OutputBuffer.size(); } - void finishFunction(MachineFunction &F) {} + void finishFunction(MachineFunction &F) { + // We now know the size of the function, add a symbol to represent it. + ELFWriter::ELFSym FnSym(F.getFunction()); + + // Figure out the binding (linkage) of the symbol. + switch (F.getFunction()->getLinkage()) { + default: + // appending linkage is illegal for functions. + assert(0 && "Unknown linkage type!"); + case GlobalValue::ExternalLinkage: + FnSym.SetBind(ELFWriter::ELFSym::STB_GLOBAL); + break; + case GlobalValue::LinkOnceLinkage: + case GlobalValue::WeakLinkage: + FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK); + break; + case GlobalValue::InternalLinkage: + FnSym.SetBind(ELFWriter::ELFSym::STB_LOCAL); + break; + } + + FnSym.SetType(ELFWriter::ELFSym::STT_FUNC); + FnSym.SectionIdx = EW.SectionList.size()-1; // .text section. + // Value = Offset from start of .text + FnSym.Value = FnStart - EW.SectionList.back().Offset; + FnSym.Size = OutputBuffer.size()-FnStart; + + // Finally, add it to the symtab. + EW.SymbolTable.push_back(FnSym); + } + void emitConstantPool(MachineConstantPool *MCP) { if (MCP->isEmpty()) return; assert(0 && "unimp"); |