aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ELFCodeEmitter.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2009-06-07 21:22:38 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2009-06-07 21:22:38 +0000
commita029a27fae25628fa7805aba6d7ae3216a4e026b (patch)
tree5f353df4c5e7e55748682c997d11b1e0e014f36c /lib/CodeGen/ELFCodeEmitter.cpp
parentfaeedf1254a4f79004cb94c3d2b738f138af450e (diff)
Simple ELF32/64 binary files can now be emitted for x86 and x86_64 without
relocation sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73038 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/ELFCodeEmitter.cpp')
-rw-r--r--lib/CodeGen/ELFCodeEmitter.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/CodeGen/ELFCodeEmitter.cpp b/lib/CodeGen/ELFCodeEmitter.cpp
index 9af276b4f9..c7bd8736bb 100644
--- a/lib/CodeGen/ELFCodeEmitter.cpp
+++ b/lib/CodeGen/ELFCodeEmitter.cpp
@@ -73,6 +73,9 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &MF) {
// Add a symbol to represent the function.
ELFSym FnSym(MF.getFunction());
+ // Update Section Size
+ ES->Size = CurBufferPtr - BufferBegin;
+
// Figure out the binding (linkage) of the symbol.
switch (MF.getFunction()->getLinkage()) {
default:
@@ -106,8 +109,29 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &MF) {
// Finally, add it to the symtab.
EW.SymbolTable.push_back(FnSym);
- // Update Section Size
- ES->Size = CurBufferPtr - BufferBegin;
+ // Relocations
+ // -----------
+ // If we have emitted any relocations to function-specific objects such as
+ // basic blocks, constant pools entries, or jump tables, record their
+ // addresses now so that we can rewrite them with the correct addresses
+ // later.
+ for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
+ MachineRelocation &MR = Relocations[i];
+ intptr_t Addr;
+
+ if (MR.isBasicBlock()) {
+ Addr = getMachineBasicBlockAddress(MR.getBasicBlock());
+ MR.setConstantVal(ES->SectionIdx);
+ MR.setResultPointer((void*)Addr);
+ } else if (MR.isGlobalValue()) {
+ EW.PendingGlobals.insert(MR.getGlobalValue());
+ } else {
+ assert(0 && "Unhandled relocation type");
+ }
+ ES->Relocations.push_back(MR);
+ }
+ Relocations.clear();
+
return false;
}