Skip to content

Commit 1cb9f37

Browse files
adalavanemanjai
authored andcommitted
[FreeBSD] Do not mark __stack_chk_guard as dso_local
This symbol is defined in libc.so so it is definitely not DSO-Local. Marking it as such causes problems on some platforms (such as PowerPC). Differential revision: https://reviews.llvm.org/D109090
1 parent 13a442c commit 1cb9f37

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,11 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
19871987
auto *GV = new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false,
19881988
GlobalVariable::ExternalLinkage, nullptr,
19891989
"__stack_chk_guard");
1990+
1991+
// FreeBSD has "__stack_chk_guard" defined externally on libc.so
19901992
if (TM.getRelocationModel() == Reloc::Static &&
1991-
!TM.getTargetTriple().isWindowsGNUEnvironment())
1993+
!TM.getTargetTriple().isWindowsGNUEnvironment() &&
1994+
!TM.getTargetTriple().isOSFreeBSD())
19921995
GV->setDSOLocal(true);
19931996
}
19941997
}

llvm/test/CodeGen/PowerPC/stack-protector.ll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux < %s | FileCheck -check-prefix=LINUX64 %s
44
; RUN: llc -verify-machineinstrs -mtriple=powerpc-ibm-aix-xcoff < %s | FileCheck -check-prefix=AIX32 %s
55
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s | FileCheck -check-prefix=AIX64 %s
6+
; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-freebsd13 < %s | FileCheck -check-prefix=FREEBSD32 %s
7+
; RUN: llc -verify-machineinstrs -mtriple=powerpcle-unknown-freebsd13 < %s | FileCheck -check-prefix=FREEBSD32 %s
8+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd13 < %s | FileCheck -check-prefix=FREEBSD64 %s
9+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-freebsd13 < %s | FileCheck -check-prefix=FREEBSD64 %s
610

7-
; LINUX32: lwz {{[0-9]+}}, -28680(2)
8-
; LINUX64: ld {{[0-9]+}}, -28688(13)
11+
; LINUX32: lwz [[#]], -28680(2)
12+
; LINUX64: ld [[#]], -28688(13)
913
; AIX32: lwz {{.*}}__ssp_canary_word
1014
; AIX64: ld {{.*}}__ssp_canary_word
15+
; FREEBSD32: lwz [[#]], __stack_chk_guard@l([[#]])
16+
; FREEBSD64: ld [[#]], .LC0@toc@l([[#]])
1117

1218
; LINUX32: __stack_chk_fail
1319
; LINUX64: __stack_chk_fail
1420
; AIX32: __stack_chk_fail
1521
; AIX64: __stack_chk_fail
22+
; FREEBSD32: bl __stack_chk_fail
23+
; FREEBSD64: bl __stack_chk_fail
1624

1725
@"\01LC" = internal constant [11 x i8] c"buf == %s\0A\00" ; <[11 x i8]*> [#uses=1]
1826

0 commit comments

Comments
 (0)