#include "llvm/Support/Mangler.h"
#include "llvm/System/Path.h"
#include "llvm/Target/TargetAsmInfo.h"
-#include "llvm/Target/MRegisterInfo.h"
+#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Target/TargetInstrInfo.h"
const TargetData *TD;
/// RI - Register Information.
- const MRegisterInfo *RI;
+ const TargetRegisterInfo *RI;
/// M - Current module.
///
// Add variable address.
MachineLocation Location;
- RI->getLocation(*MF, DV->getFrameIndex(), Location);
+ Location.set(RI->getFrameRegister(*MF),
+ RI->getFrameIndexOffset(*MF, DV->getFrameIndex()));
AddAddress(VariableDie, DW_AT_location, Location);
return VariableDie;
// Assumes in correct section after the entry point.
EmitLabel("func_begin", ++SubprogramCount);
+
+ // Emit label for the implicitly defined dbg.stoppoint at the start of
+ // the function.
+ const SourceLineInfo &LineInfo = MMI->getSourceLines()[0];
+ Asm->printLabel(LineInfo.getLabelID());
}
/// EndFunction - Gather and emit post-function debug information.
bool hasCalls;
bool hasLandingPads;
std::vector<MachineMove> Moves;
- Function::LinkageTypes linkage;
+ const Function * function;
FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P,
bool hC, bool hL,
const std::vector<MachineMove> &M,
- Function::LinkageTypes l):
+ const Function *f):
FnName(FN), Number(Num), PersonalityIndex(P),
- hasCalls(hC), hasLandingPads(hL), Moves(M),
- linkage(l) { }
+ hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { }
};
std::vector<FunctionEHFrameInfo> EHFrames;
Asm->EOL("Personality (pcrel sdata4 indirect)");
- PrintRelDirective();
+ PrintRelDirective(TAI->getShortenEHDataOn64Bit());
O << TAI->getPersonalityPrefix();
Asm->EmitExternalGlobal((const GlobalVariable *)(Personality));
O << TAI->getPersonalitySuffix();
- O << "-" << TAI->getPCSymbol();
+ if (!TAI->getShortenEHDataOn64Bit()) {
+ O << "-" << TAI->getPCSymbol();
+ }
Asm->EOL("Personality");
Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
/// EmitEHFrame - Emit function exception frame information.
///
void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo) {
+ Function::LinkageTypes linkage = EHFrameInfo.function->getLinkage();
+
Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
// Externally visible entry into the functions eh frame info.
// If the corresponding function is static, this should not be
// externally visible.
- if (EHFrameInfo.linkage != Function::InternalLinkage) {
+ if (linkage != Function::InternalLinkage) {
if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
}
- // If there are no calls then you can't unwind.
- if (!EHFrameInfo.hasCalls) {
+ // If corresponding function is weak definition, this should be too.
+ if ((linkage == Function::WeakLinkage ||
+ linkage == Function::LinkOnceLinkage) &&
+ TAI->getWeakDefDirective())
+ O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
+
+ // If there are no calls then you can't unwind. This may mean we can
+ // omit the EH Frame, but some environments do not handle weak absolute
+ // symbols.
+ if (!EHFrameInfo.hasCalls &&
+ ((linkage != Function::WeakLinkage &&
+ linkage != Function::LinkOnceLinkage) ||
+ !TAI->getWeakDefDirective() ||
+ TAI->getSupportsWeakOmittedEHFrame()))
+ {
O << EHFrameInfo.FnName << " = 0\n";
+ // This name has no connection to the function, so it might get
+ // dead-stripped when the function is not, erroneously. Prohibit
+ // dead-stripping unconditionally.
+ if (const char *UsedDirective = TAI->getUsedDirective())
+ O << UsedDirective << EHFrameInfo.FnName << "\n\n";
} else {
O << EHFrameInfo.FnName << ":\n";
- // If corresponding function is weak definition, this should be too.
- if ((EHFrameInfo.linkage == Function::WeakLinkage ||
- EHFrameInfo.linkage == Function::LinkOnceLinkage) &&
- TAI->getWeakDefDirective())
- O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
-
// EH frame header.
EmitDifference("eh_frame_end", EHFrameInfo.Number,
"eh_frame_begin", EHFrameInfo.Number, true);
// If there is a personality and landing pads then point to the language
// specific data area in the exception table.
if (EHFrameInfo.PersonalityIndex) {
- Asm->EmitULEB128Bytes(4);
+ Asm->EmitULEB128Bytes(TAI->getShortenEHDataOn64Bit() ? 8 : 4);
Asm->EOL("Augmentation size");
if (EHFrameInfo.hasLandingPads) {
Asm->EmitAlignment(2);
EmitLabel("eh_frame_end", EHFrameInfo.Number);
- }
- if (const char *UsedDirective = TAI->getUsedDirective())
- O << UsedDirective << EHFrameInfo.FnName << "\n\n";
+ // If the function is marked used, this table should be also. We cannot
+ // make the mark unconditional in this case, since retaining the table
+ // also retains the function in this case, and there is code around
+ // that depends on unused functions (calling undefined externals) being
+ // dead-stripped to link correctly. Yes, there really is.
+ if (MMI->getUsedFunctions().count(EHFrameInfo.function))
+ if (const char *UsedDirective = TAI->getUsedDirective())
+ O << UsedDirective << EHFrameInfo.FnName << "\n\n";
+ }
}
/// EmitExceptionTable - Emit landing pads and actions.
}
EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount,
- false, true);
+ TAI->getShortenEHDataOn64Bit(), true);
Asm->EOL("Region start");
if (!S.EndLabel) {
- EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber);
+ EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber,
+ TAI->getShortenEHDataOn64Bit());
} else {
- EmitDifference("label", S.EndLabel, BeginTag, BeginNumber);
+ EmitDifference("label", S.EndLabel, BeginTag, BeginNumber,
+ TAI->getShortenEHDataOn64Bit());
}
Asm->EOL("Region length");
if (!S.PadLabel) {
- if (TD->getPointerSize() == sizeof(int32_t))
+ if (TD->getPointerSize() == sizeof(int32_t) || TAI->getShortenEHDataOn64Bit())
Asm->EmitInt32(0);
else
Asm->EmitInt64(0);
} else {
EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount,
- false, true);
+ TAI->getShortenEHDataOn64Bit(), true);
}
Asm->EOL("Landing pad");
MF->getFrameInfo()->hasCalls(),
!MMI->getLandingPads().empty(),
MMI->getFrameMoves(),
- MF->getFunction()->getLinkage()));
+ MF->getFunction()));
}
};