Skip to content

Commit 33cc107

Browse files
committed
Revert "On ELF, put PIC jump tables in a non executable section."
This reverts commit r228939. The commit broke something in the output of exception handling tables on darwin x86-64. llvm-svn: 229203
1 parent 2c79ad9 commit 33cc107

File tree

6 files changed

+13
-41
lines changed

6 files changed

+13
-41
lines changed

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
6060
getSectionForJumpTable(const Function &F, Mangler &Mang,
6161
const TargetMachine &TM) const override;
6262

63-
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
64-
const Function &F) const override;
65-
6663
/// Return an MCExpr to use for a reference to the specified type info global
6764
/// variable from exception handling information.
6865
const MCExpr *

llvm/include/llvm/Target/TargetLoweringObjectFile.h

-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
9898
getSectionForJumpTable(const Function &F, Mangler &Mang,
9999
const TargetMachine &TM) const;
100100

101-
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
102-
const Function &F) const;
103-
104101
/// Targets should implement this method to assign a section to globals with
105102
/// an explicit section specfied. The implementation of this method can
106103
/// assume that GV->hasSection() is true.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -1178,14 +1178,23 @@ void AsmPrinter::EmitJumpTableInfo() {
11781178
// the appropriate section.
11791179
const Function *F = MF->getFunction();
11801180
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 {
11851193
// Otherwise, drop it in the readonly section.
11861194
const MCSection *ReadOnlySection =
11871195
TLOF.getSectionForJumpTable(*F, *Mang, TM);
11881196
OutStreamer.SwitchSection(ReadOnlySection);
1197+
JTInDiffSection = true;
11891198
}
11901199

11911200
EmitAlignment(Log2_32(

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,6 @@ const MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
356356
return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, Group);
357357
}
358358

359-
bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
360-
bool UsesLabelDifference, const Function &F) const {
361-
// We can always create relative relocations, so use another section
362-
// that can be marked non-executable.
363-
return false;
364-
}
365-
366359
/// getSectionForConstant - Given a mergeable constant with the
367360
/// specified size and relocation information, return a section that it
368361
/// should be placed in.

llvm/lib/Target/TargetLoweringObjectFile.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,6 @@ const MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
275275
return getSectionForConstant(SectionKind::getReadOnly(), /*C=*/nullptr);
276276
}
277277

278-
bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
279-
bool UsesLabelDifference, const Function &F) const {
280-
// In PIC mode, we need to emit the jump table to the same section as the
281-
// function body itself, otherwise the label differences won't make sense.
282-
// FIXME: Need a better predicate for this: what about custom entries?
283-
if (UsesLabelDifference)
284-
return true;
285-
286-
// We should also do if the section name is NULL or function is declared
287-
// in discardable section
288-
// FIXME: this isn't the right predicate, should be based on the MCSection
289-
// for the function.
290-
if (F.isWeakForLinker())
291-
return true;
292-
293-
return false;
294-
}
295-
296278
/// getSectionForConstant - Given a mergable constant with the
297279
/// specified size and relocation information, return a section that it
298280
/// should be placed in.

llvm/test/CodeGen/X86/global-sections.ll

-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
; RUN: llc < %s -mtriple=i386-apple-darwin10 -relocation-model=static | FileCheck %s -check-prefix=DARWIN-STATIC
44
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 | FileCheck %s -check-prefix=DARWIN64
55
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -data-sections -function-sections | FileCheck %s -check-prefix=LINUX-SECTIONS
6-
; RUN: llc < %s -mtriple=x86_64-pc-linux -data-sections -function-sections -relocation-model=pic | FileCheck %s -check-prefix=LINUX-SECTIONS-PIC
76
; RUN: llc < %s -mtriple=i686-pc-win32 -data-sections -function-sections | FileCheck %s -check-prefix=WIN32-SECTIONS
87

98
define void @F1() {
@@ -42,11 +41,6 @@ bb5:
4241
; LINUX-SECTIONS-NEXT: .cfi_endproc
4342
; LINUX-SECTIONS-NEXT: .section .rodata.F2,"a",@progbits
4443

45-
; LINUX-SECTIONS-PIC: .section .text.F2,"ax",@progbits
46-
; LINUX-SECTIONS-PIC: .size F2,
47-
; LINUX-SECTIONS-PIC-NEXT: .cfi_endproc
48-
; LINUX-SECTIONS-PIC-NEXT: .section .rodata.F2,"a",@progbits
49-
5044
; int G1;
5145
@G1 = common global i32 0
5246

0 commit comments

Comments
 (0)