@@ -1178,14 +1178,23 @@ void AsmPrinter::EmitJumpTableInfo() {
1178
1178
// the appropriate section.
1179
1179
const Function *F = MF->getFunction ();
1180
1180
const TargetLoweringObjectFile &TLOF = getObjFileLowering ();
1181
- bool JTInDiffSection = !TLOF.shouldPutJumpTableInFunctionSection (
1182
- MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32,
1183
- *F);
1184
- if (JTInDiffSection) {
1181
+ bool JTInDiffSection = false ;
1182
+ if (// In PIC mode, we need to emit the jump table to the same section as the
1183
+ // function body itself, otherwise the label differences won't make sense.
1184
+ // FIXME: Need a better predicate for this: what about custom entries?
1185
+ MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
1186
+ // We should also do if the section name is NULL or function is declared
1187
+ // in discardable section
1188
+ // FIXME: this isn't the right predicate, should be based on the MCSection
1189
+ // for the function.
1190
+ F->isWeakForLinker ()) {
1191
+ OutStreamer.SwitchSection (TLOF.SectionForGlobal (F, *Mang, TM));
1192
+ } else {
1185
1193
// Otherwise, drop it in the readonly section.
1186
1194
const MCSection *ReadOnlySection =
1187
1195
TLOF.getSectionForJumpTable (*F, *Mang, TM);
1188
1196
OutStreamer.SwitchSection (ReadOnlySection);
1197
+ JTInDiffSection = true ;
1189
1198
}
1190
1199
1191
1200
EmitAlignment (Log2_32 (
0 commit comments