1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Revert 43f031d3126 "Enable IBT(Indirect Branch Tracking) in JIT with CET(Control-flow Enforcement Technology)"

ExecutionEngine/MCJIT/cet-code-model-lager.ll is failing on 32-bit
windows, see llvm-commits thread for fef2dab.

This reverts commit 43f031d31264d20cfb8f1ebd606c66e57c231d4d
and the follow-ups fef2dab100dfc7c49ccf0ce2bacea409324b54ba and
6a800f6f622a7ade275fa6cb1ef07803460d8bb3.
This commit is contained in:
Hans Wennborg 2020-04-06 15:05:08 +02:00
parent 27f0eced3b
commit 8ffdfd4312
5 changed files with 8 additions and 91 deletions

View File

@ -18,7 +18,6 @@
#include "X86.h"
#include "X86InstrInfo.h"
#include "X86Subtarget.h"
#include "X86TargetMachine.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
@ -103,16 +102,7 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
// Check that the cf-protection-branch is enabled.
Metadata *isCFProtectionSupported =
MF.getMMI().getModule()->getModuleFlag("cf-protection-branch");
// NB: We need to enable IBT in jitted code if JIT compiler is CET
// enabled.
const X86TargetMachine *TM =
static_cast<const X86TargetMachine *>(&MF.getTarget());
#ifdef __CET__
bool isJITwithCET = TM->isJIT();
#else
bool isJITwithCET = false;
#endif
if (!isCFProtectionSupported && !IndirectBranchTracking && !isJITwithCET)
if (!isCFProtectionSupported && !IndirectBranchTracking)
return false;
// True if the current MF was changed and false otherwise.
@ -121,11 +111,10 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
TII = SubTarget.getInstrInfo();
EndbrOpcode = SubTarget.is64Bit() ? X86::ENDBR64 : X86::ENDBR32;
// Large code model, non-internal function or function whose address
// was taken, can be accessed through indirect calls. Mark the first
// BB with ENDBR instruction unless nocf_check attribute is used.
if ((TM->getCodeModel() == CodeModel::Large ||
MF.getFunction().hasAddressTaken() ||
// Non-internal function or function whose address was taken, can be
// accessed through indirect calls. Mark the first BB with ENDBR instruction
// unless nocf_check attribute is used.
if ((MF.getFunction().hasAddressTaken() ||
!MF.getFunction().hasLocalLinkage()) &&
!MF.getFunction().doesNoCfCheck()) {
auto MBB = MF.begin();
@ -147,8 +136,8 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
Changed |= addENDBR(MBB, std::next(I));
if (EHPadIBTNeeded && I->isEHLabel()) {
Changed |= addENDBR(MBB, std::next(I));
EHPadIBTNeeded = false;
Changed |= addENDBR(MBB, std::next(I));
EHPadIBTNeeded = false;
}
}
}

View File

@ -215,7 +215,7 @@ X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT,
getEffectiveRelocModel(TT, JIT, RM),
getEffectiveX86CodeModel(CM, JIT, TT.getArch() == Triple::x86_64),
OL),
TLOF(createTLOF(getTargetTriple())), IsJIT(JIT) {
TLOF(createTLOF(getTargetTriple())) {
// On PS4, the "return address" of a 'noreturn' call must still be within
// the calling function, and TrapUnreachable is an easy way to get that.
if (TT.isPS4() || TT.isOSBinFormatMachO()) {

View File

@ -30,8 +30,6 @@ class TargetTransformInfo;
class X86TargetMachine final : public LLVMTargetMachine {
std::unique_ptr<TargetLoweringObjectFile> TLOF;
mutable StringMap<std::unique_ptr<X86Subtarget>> SubtargetMap;
// True if this is used in JIT.
bool IsJIT;
public:
X86TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
@ -54,8 +52,6 @@ public:
TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
}
bool isJIT() const { return IsJIT; }
};
} // end namespace llvm

View File

@ -1,36 +0,0 @@
; RUN: llc -mtriple=x86_64-unknown-unknown -code-model=large < %s | FileCheck %s
; In large code model indirect branches are needed when branching to addresses
; whose offset from the current instruction pointer is unknown.
;CHECK-COUNT-3: endbr
@a = dso_local local_unnamed_addr global i32 1, align 4
; Function Attrs: nofree noinline norecurse nounwind uwtable writeonly
define dso_local void @ext() local_unnamed_addr #0 {
entry:
store i32 0, i32* @a, align 4
ret void
}
; Function Attrs: nofree norecurse nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #1 {
entry:
tail call fastcc void @foo()
%0 = load i32, i32* @a, align 4
ret i32 %0
}
; Function Attrs: nofree noinline norecurse nounwind uwtable writeonly
define internal fastcc void @foo() unnamed_addr #0 {
entry:
tail call void @ext()
ret void
}
!llvm.module.flags = !{!0, !1, !2, !3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 4, !"cf-protection-return", i32 1}
!2 = !{i32 4, !"cf-protection-branch", i32 1}
!3 = !{i32 1, !"Code Model", i32 4}

View File

@ -1,32 +0,0 @@
; RUN: %lli -mtriple=x86_64-unknown-unknown -code-model=large %s > /dev/null
@a = dso_local local_unnamed_addr global i32 1, align 4
; Function Attrs: nofree noinline norecurse nounwind uwtable writeonly
define dso_local void @ext() local_unnamed_addr #0 {
entry:
store i32 0, i32* @a, align 4
ret void
}
; Function Attrs: nofree norecurse nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #1 {
entry:
tail call fastcc void @foo()
%0 = load i32, i32* @a, align 4
ret i32 %0
}
; Function Attrs: nofree noinline norecurse nounwind uwtable writeonly
define internal fastcc void @foo() unnamed_addr #0 {
entry:
tail call void @ext()
ret void
}
!llvm.module.flags = !{!0, !1, !2, !3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 4, !"cf-protection-return", i32 1}
!2 = !{i32 4, !"cf-protection-branch", i32 1}
!3 = !{i32 1, !"Code Model", i32 4}