2009-09-20 07:41:30 +00:00
|
|
|
//===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-25 22:55:53 +00:00
|
|
|
//
|
2009-09-20 07:41:30 +00:00
|
|
|
// This file contains a printer that converts from our internal representation
|
2010-01-28 01:02:27 +00:00
|
|
|
// of machine-dependent LLVM code to X86 machine code.
|
2002-10-25 22:55:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
#include "X86AsmPrinter.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "InstPrinter/X86ATTInstPrinter.h"
|
2009-09-20 07:41:30 +00:00
|
|
|
#include "X86.h"
|
|
|
|
#include "X86COFFMachineModuleInfo.h"
|
|
|
|
#include "X86MachineFunctionInfo.h"
|
|
|
|
#include "X86TargetMachine.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Assembly/Writer.h"
|
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2012-06-28 00:05:13 +00:00
|
|
|
#include "llvm/DebugInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2010-03-09 00:40:17 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-09-20 07:41:30 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-02-03 06:42:38 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2009-09-20 07:41:30 +00:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-07-14 18:14:33 +00:00
|
|
|
#include "llvm/Support/COFF.h"
|
2010-08-04 18:06:05 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-09-20 07:41:30 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/Mangler.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2009-09-20 07:41:30 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Primitive Helper Functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-28 01:02:27 +00:00
|
|
|
/// runOnMachineFunction - Emit the function body.
|
2009-09-20 07:41:30 +00:00
|
|
|
///
|
|
|
|
bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
SetupMachineFunction(MF);
|
|
|
|
|
2011-02-01 01:14:13 +00:00
|
|
|
if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) {
|
2010-05-08 19:54:22 +00:00
|
|
|
bool Intrn = MF.getFunction()->hasInternalLinkage();
|
|
|
|
OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
|
2010-09-15 01:01:45 +00:00
|
|
|
OutStreamer.EmitCOFFSymbolStorageClass(Intrn ? COFF::IMAGE_SYM_CLASS_STATIC
|
2010-07-14 18:14:33 +00:00
|
|
|
: COFF::IMAGE_SYM_CLASS_EXTERNAL);
|
|
|
|
OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION
|
|
|
|
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
|
2010-05-08 19:54:22 +00:00
|
|
|
OutStreamer.EndCOFFSymbolDef();
|
2010-01-26 23:18:44 +00:00
|
|
|
}
|
2010-02-12 15:28:40 +00:00
|
|
|
|
2010-01-26 23:18:44 +00:00
|
|
|
// Have common code print out the function header with linkage info etc.
|
|
|
|
EmitFunctionHeader();
|
2010-02-12 15:28:40 +00:00
|
|
|
|
2010-01-28 01:02:27 +00:00
|
|
|
// Emit the rest of the function body.
|
|
|
|
EmitFunctionBody();
|
2009-09-20 07:41:30 +00:00
|
|
|
|
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// printSymbolOperand - Print a raw symbol reference operand. This handles
|
|
|
|
/// jump tables, constant pools, global address and external symbols, all of
|
|
|
|
/// which print to a label with various suffixes for relocation types etc.
|
2010-04-04 05:19:20 +00:00
|
|
|
void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO,
|
|
|
|
raw_ostream &O) {
|
2009-09-20 07:41:30 +00:00
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("unknown symbol type!");
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
2010-01-23 05:26:25 +00:00
|
|
|
O << *GetJTISymbol(MO.getIndex());
|
2009-09-20 07:41:30 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2010-01-23 05:26:25 +00:00
|
|
|
O << *GetCPISymbol(MO.getIndex());
|
2010-04-03 22:28:33 +00:00
|
|
|
printOffset(MO.getOffset(), O);
|
2009-09-20 07:41:30 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
|
|
|
const GlobalValue *GV = MO.getGlobal();
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2010-01-18 00:59:24 +00:00
|
|
|
MCSymbol *GVSym;
|
2009-09-20 07:41:30 +00:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
2010-01-16 18:37:32 +00:00
|
|
|
GVSym = GetSymbolWithGlobalValueBase(GV, "$stub");
|
2009-09-20 07:41:30 +00:00
|
|
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
2010-01-16 18:37:32 +00:00
|
|
|
GVSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-01-16 00:51:39 +00:00
|
|
|
else
|
2013-10-29 17:07:16 +00:00
|
|
|
GVSym = getSymbol(GV);
|
2010-01-16 00:51:39 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
// Handle dllimport linkage.
|
|
|
|
if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
|
2010-01-16 00:51:39 +00:00
|
|
|
GVSym = OutContext.GetOrCreateSymbol(Twine("__imp_") + GVSym->getName());
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
|
2010-01-16 18:37:32 +00:00
|
|
|
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-09-15 01:01:45 +00:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2009-09-20 07:41:30 +00:00
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
|
2010-03-10 22:34:10 +00:00
|
|
|
if (StubSym.getPointer() == 0)
|
|
|
|
StubSym = MachineModuleInfoImpl::
|
2013-10-29 17:07:16 +00:00
|
|
|
StubValueTy(getSymbol(GV), !GV->hasInternalLinkage());
|
2009-09-20 07:41:30 +00:00
|
|
|
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){
|
2010-01-16 18:37:32 +00:00
|
|
|
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-03-10 22:34:10 +00:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2009-09-20 07:41:30 +00:00
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym);
|
2010-03-10 22:34:10 +00:00
|
|
|
if (StubSym.getPointer() == 0)
|
|
|
|
StubSym = MachineModuleInfoImpl::
|
2013-10-29 17:07:16 +00:00
|
|
|
StubValueTy(getSymbol(GV), !GV->hasInternalLinkage());
|
2009-09-20 07:41:30 +00:00
|
|
|
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
|
2010-01-16 18:37:32 +00:00
|
|
|
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
|
2010-03-10 22:34:10 +00:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2009-09-20 07:41:30 +00:00
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
|
2010-03-10 22:34:10 +00:00
|
|
|
if (StubSym.getPointer() == 0)
|
|
|
|
StubSym = MachineModuleInfoImpl::
|
2013-10-29 17:07:16 +00:00
|
|
|
StubValueTy(getSymbol(GV), !GV->hasInternalLinkage());
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
// If the name begins with a dollar-sign, enclose it in parens. We do this
|
|
|
|
// to avoid having it look like an integer immediate to the assembler.
|
2010-01-16 00:51:39 +00:00
|
|
|
if (GVSym->getName()[0] != '$')
|
2010-01-17 21:43:43 +00:00
|
|
|
O << *GVSym;
|
|
|
|
else
|
|
|
|
O << '(' << *GVSym << ')';
|
2010-04-03 22:28:33 +00:00
|
|
|
printOffset(MO.getOffset(), O);
|
2009-09-20 07:41:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
2010-01-13 07:56:59 +00:00
|
|
|
const MCSymbol *SymToPrint;
|
2009-09-20 07:41:30 +00:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
|
2010-01-16 01:00:27 +00:00
|
|
|
SmallString<128> TempNameStr;
|
|
|
|
TempNameStr += StringRef(MO.getSymbolName());
|
|
|
|
TempNameStr += StringRef("$stub");
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2010-02-03 06:18:30 +00:00
|
|
|
MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
|
2010-03-10 22:34:10 +00:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2009-09-20 07:41:30 +00:00
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
|
2010-03-10 22:34:10 +00:00
|
|
|
if (StubSym.getPointer() == 0) {
|
2010-01-13 06:38:18 +00:00
|
|
|
TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end());
|
2010-03-10 22:34:10 +00:00
|
|
|
StubSym = MachineModuleInfoImpl::
|
|
|
|
StubValueTy(OutContext.GetOrCreateSymbol(TempNameStr.str()),
|
|
|
|
true);
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
2010-03-10 22:34:10 +00:00
|
|
|
SymToPrint = StubSym.getPointer();
|
2010-01-13 07:56:59 +00:00
|
|
|
} else {
|
2010-01-16 01:00:27 +00:00
|
|
|
SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName());
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
// If the name begins with a dollar-sign, enclose it in parens. We do this
|
|
|
|
// to avoid having it look like an integer immediate to the assembler.
|
2010-09-15 01:01:45 +00:00
|
|
|
if (SymToPrint->getName()[0] != '$')
|
2010-01-17 21:43:43 +00:00
|
|
|
O << *SymToPrint;
|
|
|
|
else
|
|
|
|
O << '(' << *SymToPrint << '(';
|
2009-09-20 07:41:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
switch (MO.getTargetFlags()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown target flag on GV operand");
|
|
|
|
case X86II::MO_NO_FLAG: // No flag.
|
|
|
|
break;
|
|
|
|
case X86II::MO_DARWIN_NONLAZY:
|
|
|
|
case X86II::MO_DLLIMPORT:
|
|
|
|
case X86II::MO_DARWIN_STUB:
|
|
|
|
// These affect the name of the symbol, not any suffix.
|
|
|
|
break;
|
|
|
|
case X86II::MO_GOT_ABSOLUTE_ADDRESS:
|
2010-11-14 22:48:15 +00:00
|
|
|
O << " + [.-" << *MF->getPICBaseSymbol() << ']';
|
2010-09-15 01:01:45 +00:00
|
|
|
break;
|
2009-09-20 07:41:30 +00:00
|
|
|
case X86II::MO_PIC_BASE_OFFSET:
|
|
|
|
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
|
|
|
|
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
|
2010-11-14 22:48:15 +00:00
|
|
|
O << '-' << *MF->getPICBaseSymbol();
|
2009-09-20 07:41:30 +00:00
|
|
|
break;
|
|
|
|
case X86II::MO_TLSGD: O << "@TLSGD"; break;
|
2012-06-01 16:27:21 +00:00
|
|
|
case X86II::MO_TLSLD: O << "@TLSLD"; break;
|
|
|
|
case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
|
2009-09-20 07:41:30 +00:00
|
|
|
case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
|
|
|
|
case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
|
|
|
|
case X86II::MO_TPOFF: O << "@TPOFF"; break;
|
2012-06-01 16:27:21 +00:00
|
|
|
case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
|
2009-09-20 07:41:30 +00:00
|
|
|
case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
|
2012-05-11 10:11:01 +00:00
|
|
|
case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
|
2009-09-20 07:41:30 +00:00
|
|
|
case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
|
|
|
|
case X86II::MO_GOT: O << "@GOT"; break;
|
|
|
|
case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
|
|
|
|
case X86II::MO_PLT: O << "@PLT"; break;
|
2010-06-03 04:07:48 +00:00
|
|
|
case X86II::MO_TLVP: O << "@TLVP"; break;
|
|
|
|
case X86II::MO_TLVP_PIC_BASE:
|
2010-11-14 22:48:15 +00:00
|
|
|
O << "@TLVP" << '-' << *MF->getPICBaseSymbol();
|
2010-06-03 04:07:48 +00:00
|
|
|
break;
|
2013-03-30 16:21:50 +00:00
|
|
|
case X86II::MO_SECREL: O << "@SECREL32"; break;
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 22:50:57 +00:00
|
|
|
/// printPCRelImm - This is used to print an immediate value that ends up
|
2009-09-20 07:41:30 +00:00
|
|
|
/// being encoded as a pc-relative value. These print slightly differently, for
|
|
|
|
/// example, a $ is not emitted.
|
2012-09-10 22:50:57 +00:00
|
|
|
void X86AsmPrinter::printPCRelImm(const MachineInstr *MI, unsigned OpNo,
|
2010-04-04 05:19:20 +00:00
|
|
|
raw_ostream &O) {
|
2009-09-20 07:41:30 +00:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("Unknown pcrel immediate operand");
|
2010-07-16 18:35:46 +00:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
// pc-relativeness was handled when computing the value in the reg.
|
|
|
|
printOperand(MI, OpNo, O);
|
|
|
|
return;
|
2009-09-20 07:41:30 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2010-04-04 05:19:20 +00:00
|
|
|
printSymbolOperand(MO, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void X86AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
2012-09-10 21:10:49 +00:00
|
|
|
raw_ostream &O, const char *Modifier,
|
|
|
|
unsigned AsmVariant) {
|
2009-09-20 07:41:30 +00:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("unknown operand type!");
|
|
|
|
case MachineOperand::MO_Register: {
|
2012-09-10 21:10:49 +00:00
|
|
|
// FIXME: Enumerating AsmVariant, so we can remove magic number.
|
|
|
|
if (AsmVariant == 0) O << '%';
|
2009-09-20 07:41:30 +00:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
|
2012-09-30 19:49:56 +00:00
|
|
|
MVT::SimpleValueType VT = (strcmp(Modifier+6,"64") == 0) ?
|
2009-09-20 07:41:30 +00:00
|
|
|
MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
|
|
|
|
((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
|
|
|
|
Reg = getX86SubSuperRegister(Reg, VT);
|
|
|
|
}
|
|
|
|
O << X86ATTInstPrinter::getRegisterName(Reg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MachineOperand::MO_Immediate:
|
2013-02-13 21:33:44 +00:00
|
|
|
if (AsmVariant == 0) O << '$';
|
|
|
|
O << MO.getImm();
|
2009-09-20 07:41:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2010-09-15 01:01:45 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2009-09-20 07:41:30 +00:00
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
2013-02-13 21:33:44 +00:00
|
|
|
if (AsmVariant == 0) O << '$';
|
2010-04-04 05:19:20 +00:00
|
|
|
printSymbolOperand(MO, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86AsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
|
2010-04-04 05:19:20 +00:00
|
|
|
raw_ostream &O, const char *Modifier) {
|
2009-09-20 07:41:30 +00:00
|
|
|
const MachineOperand &BaseReg = MI->getOperand(Op);
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(Op+2);
|
|
|
|
const MachineOperand &DispSpec = MI->getOperand(Op+3);
|
|
|
|
|
|
|
|
// If we really don't want to print out (rip), don't.
|
|
|
|
bool HasBaseReg = BaseReg.getReg() != 0;
|
|
|
|
if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
|
|
|
|
BaseReg.getReg() == X86::RIP)
|
|
|
|
HasBaseReg = false;
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
// HasParenPart - True if we will print out the () part of the mem ref.
|
|
|
|
bool HasParenPart = IndexReg.getReg() || HasBaseReg;
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
if (DispSpec.isImm()) {
|
|
|
|
int DispVal = DispSpec.getImm();
|
|
|
|
if (DispVal || !HasParenPart)
|
|
|
|
O << DispVal;
|
|
|
|
} else {
|
|
|
|
assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
|
|
|
|
DispSpec.isJTI() || DispSpec.isSymbol());
|
2010-04-04 05:19:20 +00:00
|
|
|
printSymbolOperand(MI->getOperand(Op+3), O);
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2011-01-01 20:58:46 +00:00
|
|
|
if (Modifier && strcmp(Modifier, "H") == 0)
|
|
|
|
O << "+8";
|
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
if (HasParenPart) {
|
|
|
|
assert(IndexReg.getReg() != X86::ESP &&
|
|
|
|
"X86 doesn't allow scaling by ESP");
|
|
|
|
|
|
|
|
O << '(';
|
|
|
|
if (HasBaseReg)
|
2010-04-04 05:19:20 +00:00
|
|
|
printOperand(MI, Op, O, Modifier);
|
2009-09-20 07:41:30 +00:00
|
|
|
|
|
|
|
if (IndexReg.getReg()) {
|
|
|
|
O << ',';
|
2010-04-04 05:19:20 +00:00
|
|
|
printOperand(MI, Op+2, O, Modifier);
|
2009-09-20 07:41:30 +00:00
|
|
|
unsigned ScaleVal = MI->getOperand(Op+1).getImm();
|
|
|
|
if (ScaleVal != 1)
|
|
|
|
O << ',' << ScaleVal;
|
|
|
|
}
|
|
|
|
O << ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86AsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
|
2010-04-04 05:19:20 +00:00
|
|
|
raw_ostream &O, const char *Modifier) {
|
2009-09-20 07:41:30 +00:00
|
|
|
assert(isMem(MI, Op) && "Invalid memory reference!");
|
|
|
|
const MachineOperand &Segment = MI->getOperand(Op+4);
|
|
|
|
if (Segment.getReg()) {
|
2010-04-04 05:19:20 +00:00
|
|
|
printOperand(MI, Op+4, O, Modifier);
|
2009-09-20 07:41:30 +00:00
|
|
|
O << ':';
|
|
|
|
}
|
2010-04-04 05:19:20 +00:00
|
|
|
printLeaMemReference(MI, Op, O, Modifier);
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:06:44 +00:00
|
|
|
void X86AsmPrinter::printIntelMemReference(const MachineInstr *MI, unsigned Op,
|
|
|
|
raw_ostream &O, const char *Modifier,
|
|
|
|
unsigned AsmVariant){
|
|
|
|
const MachineOperand &BaseReg = MI->getOperand(Op);
|
|
|
|
unsigned ScaleVal = MI->getOperand(Op+1).getImm();
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(Op+2);
|
|
|
|
const MachineOperand &DispSpec = MI->getOperand(Op+3);
|
|
|
|
const MachineOperand &SegReg = MI->getOperand(Op+4);
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2012-10-03 22:06:44 +00:00
|
|
|
// If this has a segment register, print it.
|
|
|
|
if (SegReg.getReg()) {
|
|
|
|
printOperand(MI, Op+4, O, Modifier, AsmVariant);
|
|
|
|
O << ':';
|
|
|
|
}
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2012-10-03 22:06:44 +00:00
|
|
|
O << '[';
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2012-10-03 22:06:44 +00:00
|
|
|
bool NeedPlus = false;
|
|
|
|
if (BaseReg.getReg()) {
|
|
|
|
printOperand(MI, Op, O, Modifier, AsmVariant);
|
|
|
|
NeedPlus = true;
|
|
|
|
}
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2012-10-03 22:06:44 +00:00
|
|
|
if (IndexReg.getReg()) {
|
|
|
|
if (NeedPlus) O << " + ";
|
|
|
|
if (ScaleVal != 1)
|
|
|
|
O << ScaleVal << '*';
|
|
|
|
printOperand(MI, Op+2, O, Modifier, AsmVariant);
|
|
|
|
NeedPlus = true;
|
|
|
|
}
|
|
|
|
|
2013-02-13 21:33:44 +00:00
|
|
|
if (!DispSpec.isImm()) {
|
|
|
|
if (NeedPlus) O << " + ";
|
|
|
|
printOperand(MI, Op+3, O, Modifier, AsmVariant);
|
|
|
|
} else {
|
|
|
|
int64_t DispVal = DispSpec.getImm();
|
|
|
|
if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
|
|
|
|
if (NeedPlus) {
|
|
|
|
if (DispVal > 0)
|
|
|
|
O << " + ";
|
|
|
|
else {
|
|
|
|
O << " - ";
|
|
|
|
DispVal = -DispVal;
|
|
|
|
}
|
2012-10-03 22:06:44 +00:00
|
|
|
}
|
2013-02-13 21:33:44 +00:00
|
|
|
O << DispVal;
|
2012-10-03 22:06:44 +00:00
|
|
|
}
|
2013-02-13 21:33:44 +00:00
|
|
|
}
|
2012-10-03 22:06:44 +00:00
|
|
|
O << ']';
|
|
|
|
}
|
|
|
|
|
2010-04-04 05:19:20 +00:00
|
|
|
bool X86AsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode,
|
|
|
|
raw_ostream &O) {
|
2009-09-20 07:41:30 +00:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
switch (Mode) {
|
|
|
|
default: return true; // Unknown mode.
|
|
|
|
case 'b': // Print QImode register
|
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i8);
|
|
|
|
break;
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
|
|
|
|
break;
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i16);
|
|
|
|
break;
|
|
|
|
case 'k': // Print SImode register
|
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i32);
|
|
|
|
break;
|
|
|
|
case 'q': // Print DImode register
|
2013-11-12 21:47:44 +00:00
|
|
|
// FIXME: gcc will actually print e instead of r for 32-bit.
|
2009-09-20 07:41:30 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i64);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
O << '%' << X86ATTInstPrinter::getRegisterName(Reg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
2010-04-04 05:29:35 +00:00
|
|
|
const char *ExtraCode, raw_ostream &O) {
|
2009-09-20 07:41:30 +00:00
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
|
|
|
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
switch (ExtraCode[0]) {
|
2012-06-26 13:49:27 +00:00
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
case 'a': // This is an address. Currently only 'i' and 'r' are expected.
|
|
|
|
if (MO.isImm()) {
|
|
|
|
O << MO.getImm();
|
|
|
|
return false;
|
2010-09-15 01:01:45 +00:00
|
|
|
}
|
2009-09-20 07:41:30 +00:00
|
|
|
if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) {
|
2010-04-04 05:19:20 +00:00
|
|
|
printSymbolOperand(MO, O);
|
2010-07-06 23:27:00 +00:00
|
|
|
if (Subtarget->isPICStyleRIPRel())
|
|
|
|
O << "(%rip)";
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (MO.isReg()) {
|
|
|
|
O << '(';
|
2010-04-04 05:19:20 +00:00
|
|
|
printOperand(MI, OpNo, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
O << ')';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 'c': // Don't print "$" before a global var name or constant.
|
|
|
|
if (MO.isImm())
|
|
|
|
O << MO.getImm();
|
|
|
|
else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol())
|
2010-04-04 05:19:20 +00:00
|
|
|
printSymbolOperand(MO, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
else
|
2010-04-04 05:19:20 +00:00
|
|
|
printOperand(MI, OpNo, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'A': // Print '*' before a register (it must be a register)
|
|
|
|
if (MO.isReg()) {
|
|
|
|
O << '*';
|
2010-04-04 05:19:20 +00:00
|
|
|
printOperand(MI, OpNo, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 'b': // Print QImode register
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
case 'k': // Print SImode register
|
|
|
|
case 'q': // Print DImode register
|
|
|
|
if (MO.isReg())
|
2010-04-04 05:19:20 +00:00
|
|
|
return printAsmMRegister(MO, ExtraCode[0], O);
|
|
|
|
printOperand(MI, OpNo, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'P': // This is the operand of a call, treat specially.
|
2012-09-10 22:50:57 +00:00
|
|
|
printPCRelImm(MI, OpNo, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'n': // Negate the immediate or print a '-' before the operand.
|
|
|
|
// Note: this is a temporary solution. It should be handled target
|
|
|
|
// independently as part of the 'MC' work.
|
|
|
|
if (MO.isImm()) {
|
|
|
|
O << -MO.getImm();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
O << '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:10:49 +00:00
|
|
|
printOperand(MI, OpNo, O, /*Modifier*/ 0, AsmVariant);
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo, unsigned AsmVariant,
|
2010-04-04 05:29:35 +00:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
2012-10-03 22:06:44 +00:00
|
|
|
if (AsmVariant) {
|
|
|
|
printIntelMemReference(MI, OpNo, O);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
|
|
|
|
|
|
|
switch (ExtraCode[0]) {
|
|
|
|
default: return true; // Unknown modifier.
|
|
|
|
case 'b': // Print QImode register
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
case 'k': // Print SImode register
|
|
|
|
case 'q': // Print SImode register
|
|
|
|
// These only apply to registers, ignore on mem.
|
|
|
|
break;
|
2011-01-01 20:58:46 +00:00
|
|
|
case 'H':
|
|
|
|
printMemReference(MI, OpNo, O, "H");
|
|
|
|
return false;
|
2009-09-20 07:41:30 +00:00
|
|
|
case 'P': // Don't print @PLT, but do print as memory.
|
2010-04-04 05:19:20 +00:00
|
|
|
printMemReference(MI, OpNo, O, "no-rip");
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-04-04 05:19:20 +00:00
|
|
|
printMemReference(MI, OpNo, O);
|
2009-09-20 07:41:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-13 02:10:00 +00:00
|
|
|
void X86AsmPrinter::EmitStartOfAsmFile(Module &M) {
|
2011-02-01 01:14:13 +00:00
|
|
|
if (Subtarget->isTargetEnvMacho())
|
2010-03-13 02:10:00 +00:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
|
2013-09-17 23:18:05 +00:00
|
|
|
|
2013-10-18 02:14:40 +00:00
|
|
|
if (Subtarget->isTargetCOFF()) {
|
2013-09-17 23:18:05 +00:00
|
|
|
// Emit an absolute @feat.00 symbol. This appears to be some kind of
|
|
|
|
// compiler features bitfield read by link.exe.
|
|
|
|
if (!Subtarget->is64Bit()) {
|
|
|
|
MCSymbol *S = MMI->getContext().GetOrCreateSymbol(StringRef("@feat.00"));
|
|
|
|
OutStreamer.BeginCOFFSymbolDef(S);
|
|
|
|
OutStreamer.EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
|
|
|
|
OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
|
|
|
|
OutStreamer.EndCOFFSymbolDef();
|
|
|
|
// According to the PE-COFF spec, the LSB of this value marks the object
|
|
|
|
// for "registered SEH". This means that all SEH handler entry points
|
|
|
|
// must be registered in .sxdata. Use of any unregistered handlers will
|
|
|
|
// cause the process to terminate immediately. LLVM does not know how to
|
|
|
|
// register any SEH handlers, so its object files should be safe.
|
|
|
|
S->setAbsolute();
|
2013-11-18 23:08:12 +00:00
|
|
|
OutStreamer.EmitSymbolAttribute(S, MCSA_Global);
|
2013-09-17 23:18:05 +00:00
|
|
|
OutStreamer.EmitAssignment(
|
|
|
|
S, MCConstantExpr::Create(int64_t(1), MMI->getContext()));
|
|
|
|
}
|
|
|
|
}
|
2010-03-13 02:10:00 +00:00
|
|
|
}
|
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
|
|
|
|
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
|
2011-02-01 01:14:13 +00:00
|
|
|
if (Subtarget->isTargetEnvMacho()) {
|
2009-09-20 07:41:30 +00:00
|
|
|
// All darwin targets use mach-o.
|
|
|
|
MachineModuleInfoMachO &MMIMacho =
|
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
// Output stubs for dynamically-linked functions.
|
|
|
|
MachineModuleInfoMachO::SymbolListTy Stubs;
|
|
|
|
|
|
|
|
Stubs = MMIMacho.GetFnStubList();
|
|
|
|
if (!Stubs.empty()) {
|
2010-09-15 01:01:45 +00:00
|
|
|
const MCSection *TheSection =
|
2010-04-08 20:40:11 +00:00
|
|
|
OutContext.getMachOSection("__IMPORT", "__jump_table",
|
|
|
|
MCSectionMachO::S_SYMBOL_STUBS |
|
|
|
|
MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE |
|
|
|
|
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
|
|
|
|
5, SectionKind::getMetadata());
|
2009-09-20 07:41:30 +00:00
|
|
|
OutStreamer.SwitchSection(TheSection);
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
|
2010-02-03 06:42:38 +00:00
|
|
|
// L_foo$stub:
|
|
|
|
OutStreamer.EmitLabel(Stubs[i].first);
|
|
|
|
// .indirect_symbol _foo
|
2010-03-10 22:34:10 +00:00
|
|
|
OutStreamer.EmitSymbolAttribute(Stubs[i].second.getPointer(),
|
|
|
|
MCSA_IndirectSymbol);
|
2011-08-30 20:53:29 +00:00
|
|
|
// hlt; hlt; hlt; hlt; hlt hlt = 0xf4.
|
|
|
|
const char HltInsts[] = "\xf4\xf4\xf4\xf4\xf4";
|
2013-01-09 01:57:54 +00:00
|
|
|
OutStreamer.EmitBytes(StringRef(HltInsts, 5));
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
2010-09-15 01:01:45 +00:00
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
Stubs.clear();
|
2010-02-03 06:42:38 +00:00
|
|
|
OutStreamer.AddBlankLine();
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output stubs for external and common global variables.
|
|
|
|
Stubs = MMIMacho.GetGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
2010-09-15 01:01:45 +00:00
|
|
|
const MCSection *TheSection =
|
2010-04-08 20:40:11 +00:00
|
|
|
OutContext.getMachOSection("__IMPORT", "__pointers",
|
|
|
|
MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
|
|
|
|
SectionKind::getMetadata());
|
2009-09-20 07:41:30 +00:00
|
|
|
OutStreamer.SwitchSection(TheSection);
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
|
2010-02-03 06:42:38 +00:00
|
|
|
// L_foo$non_lazy_ptr:
|
|
|
|
OutStreamer.EmitLabel(Stubs[i].first);
|
|
|
|
// .indirect_symbol _foo
|
2010-03-12 19:20:40 +00:00
|
|
|
MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second;
|
|
|
|
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),
|
2010-03-10 22:34:10 +00:00
|
|
|
MCSA_IndirectSymbol);
|
2010-02-03 06:42:38 +00:00
|
|
|
// .long 0
|
2010-03-12 19:20:40 +00:00
|
|
|
if (MCSym.getInt())
|
|
|
|
// External to current translation unit.
|
2013-01-09 01:57:54 +00:00
|
|
|
OutStreamer.EmitIntValue(0, 4/*size*/);
|
2010-03-12 19:20:40 +00:00
|
|
|
else
|
|
|
|
// Internal to current translation unit.
|
2010-03-31 18:48:58 +00:00
|
|
|
//
|
|
|
|
// When we place the LSDA into the TEXT section, the type info
|
|
|
|
// pointers need to be indirect and pc-rel. We accomplish this by
|
|
|
|
// using NLPs. However, sometimes the types are local to the file. So
|
|
|
|
// we need to fill in the value for the NLP in those cases.
|
2010-03-12 19:20:40 +00:00
|
|
|
OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(),
|
2013-01-09 01:57:54 +00:00
|
|
|
OutContext), 4/*size*/);
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
Stubs.clear();
|
2010-02-03 06:42:38 +00:00
|
|
|
OutStreamer.AddBlankLine();
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Stubs = MMIMacho.GetHiddenGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
|
|
|
|
EmitAlignment(2);
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
|
2010-02-03 06:42:38 +00:00
|
|
|
// L_foo$non_lazy_ptr:
|
|
|
|
OutStreamer.EmitLabel(Stubs[i].first);
|
|
|
|
// .long _foo
|
2010-03-10 22:34:10 +00:00
|
|
|
OutStreamer.EmitValue(MCSymbolRefExpr::
|
|
|
|
Create(Stubs[i].second.getPointer(),
|
2013-01-09 01:57:54 +00:00
|
|
|
OutContext), 4/*size*/);
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
Stubs.clear();
|
2010-02-03 06:42:38 +00:00
|
|
|
OutStreamer.AddBlankLine();
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 22:11:56 +00:00
|
|
|
SM.serializeToStackMapSection();
|
|
|
|
|
2009-09-20 07:41:30 +00:00
|
|
|
// Funny Darwin hack: This flag tells the linker that no global symbols
|
|
|
|
// contain code that falls through to other global symbols (e.g. the obvious
|
|
|
|
// implementation of multiple entry points). If this doesn't occur, the
|
|
|
|
// linker can safely perform dead code stripping. Since LLVM never
|
|
|
|
// generates code that does this, it is always safe to set.
|
2010-01-23 06:39:22 +00:00
|
|
|
OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
|
2009-10-15 22:36:18 +00:00
|
|
|
}
|
2009-09-20 07:41:30 +00:00
|
|
|
|
2010-11-12 17:24:29 +00:00
|
|
|
if (Subtarget->isTargetWindows() && !Subtarget->isTargetCygMing() &&
|
2012-02-22 19:06:13 +00:00
|
|
|
MMI->usesVAFloatArgument()) {
|
2010-10-23 09:06:59 +00:00
|
|
|
StringRef SymbolName = Subtarget->is64Bit() ? "_fltused" : "__fltused";
|
|
|
|
MCSymbol *S = MMI->getContext().GetOrCreateSymbol(SymbolName);
|
2010-10-16 08:25:41 +00:00
|
|
|
OutStreamer.EmitSymbolAttribute(S, MCSA_Global);
|
|
|
|
}
|
|
|
|
|
2011-02-01 01:14:13 +00:00
|
|
|
if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) {
|
2009-10-15 22:36:18 +00:00
|
|
|
X86COFFMachineModuleInfo &COFFMMI =
|
2009-09-20 07:41:30 +00:00
|
|
|
MMI->getObjFileInfo<X86COFFMachineModuleInfo>();
|
|
|
|
|
2009-10-15 22:36:18 +00:00
|
|
|
// Emit type information for external functions
|
2010-05-08 19:54:22 +00:00
|
|
|
typedef X86COFFMachineModuleInfo::externals_iterator externals_iterator;
|
|
|
|
for (externals_iterator I = COFFMMI.externals_begin(),
|
|
|
|
E = COFFMMI.externals_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
|
2010-07-14 18:14:33 +00:00
|
|
|
OutStreamer.EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_EXTERNAL);
|
|
|
|
OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION
|
|
|
|
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
|
2010-05-08 19:54:22 +00:00
|
|
|
OutStreamer.EndCOFFSymbolDef();
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
2009-10-15 22:36:18 +00:00
|
|
|
|
2010-05-09 05:52:28 +00:00
|
|
|
// Necessary for dllexport support
|
|
|
|
std::vector<const MCSymbol*> DLLExportedFns, DLLExportedGlobals;
|
|
|
|
|
|
|
|
const TargetLoweringObjectFileCOFF &TLOFCOFF =
|
|
|
|
static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
|
|
|
|
|
|
|
|
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
|
|
|
|
if (I->hasDLLExportLinkage())
|
2013-10-29 17:07:16 +00:00
|
|
|
DLLExportedFns.push_back(getSymbol(I));
|
2010-05-09 05:52:28 +00:00
|
|
|
|
|
|
|
for (Module::const_global_iterator I = M.global_begin(),
|
|
|
|
E = M.global_end(); I != E; ++I)
|
|
|
|
if (I->hasDLLExportLinkage())
|
2013-10-29 17:07:16 +00:00
|
|
|
DLLExportedGlobals.push_back(getSymbol(I));
|
2010-05-09 05:52:28 +00:00
|
|
|
|
|
|
|
// Output linker support code for dllexported globals on windows.
|
|
|
|
if (!DLLExportedGlobals.empty() || !DLLExportedFns.empty()) {
|
|
|
|
OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection());
|
2010-05-09 08:40:06 +00:00
|
|
|
SmallString<128> name;
|
|
|
|
for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) {
|
|
|
|
if (Subtarget->isTargetWindows())
|
|
|
|
name = " /EXPORT:";
|
|
|
|
else
|
|
|
|
name = " -export:";
|
|
|
|
name += DLLExportedGlobals[i]->getName();
|
|
|
|
if (Subtarget->isTargetWindows())
|
|
|
|
name += ",DATA";
|
|
|
|
else
|
|
|
|
name += ",data";
|
2013-01-09 01:57:54 +00:00
|
|
|
OutStreamer.EmitBytes(name);
|
2010-05-09 08:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = DLLExportedFns.size(); i != e; ++i) {
|
|
|
|
if (Subtarget->isTargetWindows())
|
|
|
|
name = " /EXPORT:";
|
|
|
|
else
|
|
|
|
name = " -export:";
|
|
|
|
name += DLLExportedFns[i]->getName();
|
2013-01-09 01:57:54 +00:00
|
|
|
OutStreamer.EmitBytes(name);
|
2010-05-09 08:40:06 +00:00
|
|
|
}
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-15 22:35:59 +00:00
|
|
|
|
|
|
|
if (Subtarget->isTargetELF()) {
|
2010-04-17 16:44:48 +00:00
|
|
|
const TargetLoweringObjectFileELF &TLOFELF =
|
|
|
|
static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
|
2010-02-15 22:35:59 +00:00
|
|
|
|
|
|
|
MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>();
|
|
|
|
|
|
|
|
// Output stubs for external and common global variables.
|
|
|
|
MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
|
|
|
OutStreamer.SwitchSection(TLOFELF.getDataRelSection());
|
2012-10-08 16:38:25 +00:00
|
|
|
const DataLayout *TD = TM.getDataLayout();
|
2010-02-15 22:35:59 +00:00
|
|
|
|
2010-04-04 05:35:04 +00:00
|
|
|
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
|
|
|
|
OutStreamer.EmitLabel(Stubs[i].first);
|
|
|
|
OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(),
|
2013-01-09 01:57:54 +00:00
|
|
|
TD->getPointerSize());
|
2010-04-04 05:35:04 +00:00
|
|
|
}
|
2010-02-15 22:35:59 +00:00
|
|
|
Stubs.clear();
|
|
|
|
}
|
|
|
|
}
|
2009-09-20 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Registry Stuff
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Force static initialization.
|
2010-09-15 01:01:45 +00:00
|
|
|
extern "C" void LLVMInitializeX86AsmPrinter() {
|
2009-09-20 07:41:30 +00:00
|
|
|
RegisterAsmPrinter<X86AsmPrinter> X(TheX86_32Target);
|
|
|
|
RegisterAsmPrinter<X86AsmPrinter> Y(TheX86_64Target);
|
|
|
|
}
|