Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,8 @@ void CodeGenModule::Release() {
if (LangOpts.HLSL)
getHLSLRuntime().finishCodeGen();

if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
uint32_t PLevel = Context.getLangOpts().PICLevel;
if (PLevel) {
assert(PLevel < 3 && "Invalid PIC Level");
getModule().setPICLevel(static_cast<llvm::PICLevel::Level>(PLevel));
if (Context.getLangOpts().PIE)
Expand All @@ -1152,7 +1153,7 @@ void CodeGenModule::Release() {
getModule().setRtLibUseGOT();
if (getTriple().isOSBinFormatELF() &&
CodeGenOpts.DirectAccessExternalData !=
getModule().getDirectAccessExternalData()) {
getModule().getDirectAccessExternalData(PLevel == 0)) {
getModule().setDirectAccessExternalData(
CodeGenOpts.DirectAccessExternalData);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {

/// Get/set whether referencing global variables can use direct access
/// relocations on ELF targets.
bool getDirectAccessExternalData() const;
bool getDirectAccessExternalData(bool IsStaticRelocModel) const;
void setDirectAccessExternalData(bool Value);

/// Get/set whether synthesized functions should get the uwtable attribute.
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,8 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
"__stack_chk_guard");

// FreeBSD has "__stack_chk_guard" defined externally on libc.so
if (M.getDirectAccessExternalData() &&
if (M.getDirectAccessExternalData(TM.getRelocationModel() ==
Reloc::Static) &&
!TM.getTargetTriple().isWindowsGNUEnvironment() &&
!TM.getTargetTriple().isOSFreeBSD() &&
!TM.getTargetTriple().isOSDarwin())
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,12 @@ void Module::setRtLibUseGOT() {
addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
}

bool Module::getDirectAccessExternalData() const {
bool Module::getDirectAccessExternalData(bool IsStaticRelocModel) const {
auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag("direct-access-external-data"));
if (Val)
return cast<ConstantInt>(Val->getValue())->getZExtValue() > 0;
return getPICLevel() == PICLevel::NotPIC;
return getPICLevel() == PICLevel::NotPIC || IsStaticRelocModel;
}

void Module::setDirectAccessExternalData(bool Value) {
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/X86ISelLoweringCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,8 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {
nullptr, GuardSymb, nullptr,
GlobalValue::NotThreadLocal, AddressSpace);
if (!Subtarget.isTargetDarwin())
GV->setDSOLocal(M->getDirectAccessExternalData());
GV->setDSOLocal(M->getDirectAccessExternalData(
getTargetMachine().getRelocationModel() == Reloc::Static));
}
return GV;
}
Expand Down
8 changes: 3 additions & 5 deletions llvm/test/LTO/ARM/ssp-static-reloc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
; RUN: llvm-lto -O0 -relocation-model=static -o %t.o %t.bc
; RUN: llvm-objdump -d -r %t.o | FileCheck %s

; Confirm that we do generate one too many indirections accessing the stack guard
; variable, when the relocation model is static and the PIC level is not 0..
; This is preparation for the fix.
; Confirm that we do not generate one too many indirections accessing the stack guard
; variable, when the relocation model is static and the PIC level is not 0.
;
target triple = "armv4t-unknown-unknown"

Expand All @@ -20,8 +19,7 @@ entry:
; CHECK: <foo>:
; CHECK: [[#%x,CURPC:]]:{{.*}} ldr r[[REG1:[0-9]+]], [pc, #0x[[#%x,OFFSET:]]]
; CHECK-NEXT: ldr r[[REG2:[0-9]+]], [r[[REG1]]]
; CHECK-NEXT: ldr r[[REG3:[0-9]+]], [r[[REG2]]]
; CHECK-NEXT: str r[[REG3]],
; CHECK-NEXT: str r[[REG2]],
; CHECK: [[#CURPC + OFFSET + 8]]:{{.*}}.word
; CHECK-NEXT: R_ARM_ABS32 __stack_chk_guard

Expand Down