Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp |
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp |
index 8a327134f273677e7d94343eaec4fb21e14f6da3..719acd50b8503b03ad4d43aa8936bd3d0a160a6b 100644 |
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp |
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp |
@@ -760,9 +760,14 @@ void AsmPrinter::EmitFunctionBody() { |
break; |
case TargetOpcode::EH_LABEL: |
- case TargetOpcode::GC_LABEL: |
+ case TargetOpcode::GC_LABEL: { |
+ // @LOCALMOD-START |
+ if (unsigned LabelAlign = GetTargetLabelAlign(&MI)) |
+ EmitAlignment(LabelAlign); |
+ // @LOCALMOD-END |
OutStreamer.EmitLabel(MI.getOperand(0).getMCSymbol()); |
break; |
+ } |
case TargetOpcode::INLINEASM: |
EmitInlineAsm(&MI); |
break; |
@@ -1127,19 +1132,34 @@ void AsmPrinter::EmitJumpTableInfo() { |
if (// In PIC mode, we need to emit the jump table to the same section as the |
// function body itself, otherwise the label differences won't make sense. |
// FIXME: Need a better predicate for this: what about custom entries? |
- MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 || |
+ (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 || |
// We should also do if the section name is NULL or function is declared |
// in discardable section |
// FIXME: this isn't the right predicate, should be based on the MCSection |
// for the function. |
- F->isWeakForLinker()) { |
+ // @LOCALMOD-START |
+ // the original code is a hack |
+ // jumptables usually end up in .rodata |
+ // but for functions with weak linkage there is a chance that the are |
+ // not needed. So in order to be discard the function AND the jumptable |
+ // they keep them both in .text. This fix only works if we never discard |
+ // weak functions. This is guaranteed because the bitcode linker already |
+ // throws out unused ones. |
+ // TODO: Investigate the other case of concern -- PIC code. |
+ // Concern is about jumptables being in a different section: can the |
+ // rodata and text be too far apart for a RIP-relative offset? |
+ F->isWeakForLinker()) |
+ && !UseReadOnlyJumpTables()) { |
OutStreamer.SwitchSection( |
getObjFileLowering().SectionForGlobal(F, *Mang, TM)); |
} else { |
// Otherwise, drop it in the readonly section. |
+ // (localmod: pick a readonly section based on the properties of F, which |
+ // means a unique readonly section if F gets a unique text section) |
const MCSection *ReadOnlySection = |
- getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly(), |
- /*C=*/nullptr); |
+ getObjFileLowering().SectionForGlobal( |
+ F, SectionKind::getReadOnly(), *Mang, TM); |
+ // @LOCALMOD-END |
OutStreamer.SwitchSection(ReadOnlySection); |
JTInDiffSection = true; |
} |
@@ -1161,7 +1181,8 @@ void AsmPrinter::EmitJumpTableInfo() { |
// For the EK_LabelDifference32 entry, if using .set avoids a relocation, |
/// emit a .set directive for each unique entry. |
if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 && |
- MAI->doesSetDirectiveSuppressesReloc()) { |
+ MAI->doesSetDirectiveSuppressesReloc() && |
+ !UseReadOnlyJumpTables()) { // @LOCALMOD |
SmallPtrSet<const MachineBasicBlock*, 16> EmittedSets; |
const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering(); |
const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext); |
@@ -1242,7 +1263,8 @@ void AsmPrinter::EmitJumpTableEntry(const MachineJumpTableInfo *MJTI, |
// If the .set directive avoids relocations, this is emitted as: |
// .set L4_5_set_123, LBB123 - LJTI1_2 |
// .word L4_5_set_123 |
- if (MAI->doesSetDirectiveSuppressesReloc()) { |
+ if (MAI->doesSetDirectiveSuppressesReloc() && |
+ !UseReadOnlyJumpTables()) { // @LOCALMOD |
Value = MCSymbolRefExpr::Create(GetJTSetSymbol(UID, MBB->getNumber()), |
OutContext); |
break; |