MC/Mach-O: Start emitting fixups/relocations for instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96095 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2010-02-13 09:29:02 +00:00
parent 2be2fd0730
commit f6346769b3
2 changed files with 20 additions and 2 deletions

View File

@ -23,6 +23,10 @@
#include "llvm/Support/MachO.h" #include "llvm/Support/MachO.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
// FIXME: Gross.
#include "../Target/X86/X86FixupKinds.h"
#include <vector> #include <vector>
using namespace llvm; using namespace llvm;
@ -50,8 +54,11 @@ static bool isVirtualSection(const MCSection &Section) {
static unsigned getFixupKindLog2Size(MCFixupKind Kind) { static unsigned getFixupKindLog2Size(MCFixupKind Kind) {
switch (Kind) { switch (Kind) {
default: llvm_unreachable("invalid fixup kind!"); default: llvm_unreachable("invalid fixup kind!");
case X86::reloc_pcrel_1byte:
case FK_Data_1: return 0; case FK_Data_1: return 0;
case FK_Data_2: return 1; case FK_Data_2: return 1;
case X86::reloc_pcrel_4byte:
case X86::reloc_riprel_4byte:
case FK_Data_4: return 2; case FK_Data_4: return 2;
case FK_Data_8: return 3; case FK_Data_8: return 3;
} }

View File

@ -382,12 +382,23 @@ void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
CurSectionData->setHasInstructions(true); CurSectionData->setHasInstructions(true);
// FIXME: Relocations!
SmallVector<MCFixup, 4> Fixups; SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code; SmallString<256> Code;
raw_svector_ostream VecOS(Code); raw_svector_ostream VecOS(Code);
Emitter->EncodeInstruction(Inst, VecOS, Fixups); Emitter->EncodeInstruction(Inst, VecOS, Fixups);
EmitBytes(VecOS.str(), 0); VecOS.flush();
// Add the fixups and data.
MCDataFragment *DF = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
if (!DF)
DF = new MCDataFragment(CurSectionData);
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
MCFixup &F = Fixups[i];
DF->getFixups().push_back(MCAsmFixup(DF->getContents().size()+F.getOffset(),
*F.getValue(),
F.getKind()));
}
DF->getContents().append(Code.begin(), Code.end());
} }
void MCMachOStreamer::Finish() { void MCMachOStreamer::Finish() {