Skip to content

Commit 26464f2

Browse files
authored
[FreeBSD] Mark __stack_chk_guard dso_local except for PPC64 (#86665)
Adjust logic of 1cb9f37 to match freebsd/freebsd-src@9a4d48a645a7a. D113443 is the original attempt to bring this FreeBSD patch to llvm-project, but it never landed. This change is required to build FreeBSD kernel modules with -fstack-protector using a standard LLVM toolchain. The FreeBSD kernel loader does not handle R_X86_64_REX_GOTPCRELX relocations. Fixes #50932.
1 parent 4f9aab2 commit 26464f2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,8 @@ void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
20732073
// FreeBSD has "__stack_chk_guard" defined externally on libc.so
20742074
if (M.getDirectAccessExternalData() &&
20752075
!TM.getTargetTriple().isWindowsGNUEnvironment() &&
2076-
!TM.getTargetTriple().isOSFreeBSD() &&
2076+
!(TM.getTargetTriple().isPPC64() &&
2077+
TM.getTargetTriple().isOSFreeBSD()) &&
20772078
(!TM.getTargetTriple().isOSDarwin() ||
20782079
TM.getRelocationModel() == Reloc::Static))
20792080
GV->setDSOLocal(true);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; RUN: llc -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck --check-prefix=LINUX-I386 %s
22
; RUN: llc -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck --check-prefix=LINUX-X64 %s
33
; RUN: llc -code-model=kernel -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck --check-prefix=LINUX-KERNEL-X64 %s
4+
; RUN: llc -code-model=kernel -mtriple=x86_64-unknown-freebsd < %s -o - | FileCheck --check-prefix=FREEBSD-KERNEL-X64 %s
45
; RUN: llc -mtriple=x86_64-apple-darwin < %s -o - | FileCheck --check-prefix=DARWIN-X64 %s
56
; RUN: llc -mtriple=amd64-pc-openbsd < %s -o - | FileCheck --check-prefix=OPENBSD-AMD64 %s
67
; RUN: llc -mtriple=i386-pc-windows-msvc < %s -o - | FileCheck -check-prefix=MSVC-I386 %s
@@ -75,6 +76,10 @@ entry:
7576
; LINUX-X64: mov{{l|q}} %fs:
7677
; LINUX-X64: callq __stack_chk_fail
7778

79+
; FREEBSD-KERNEL-X64-LABEL: test1b:
80+
; FREEBSD-KERNEL-X64-NOT: mov{{l|q}} __stack_chk_guard@GOTPCREL
81+
; FREEBSD-KERNEL-X64: callq __stack_chk_fail
82+
7883
; LINUX-KERNEL-X64-LABEL: test1b:
7984
; LINUX-KERNEL-X64: mov{{l|q}} %gs:
8085
; LINUX-KERNEL-X64: callq __stack_chk_fail
@@ -118,6 +123,10 @@ entry:
118123
; LINUX-X64: mov{{l|q}} %fs:
119124
; LINUX-X64: callq __stack_chk_fail
120125

126+
; FREEBSD-KERNEL-X64-LABEL: test1c:
127+
; FREEBSD-KERNEL-X64: mov{{l|q}} __stack_chk_guard(%rip)
128+
; FREEBSD-KERNEL-X64: callq __stack_chk_fail
129+
121130
; LINUX-KERNEL-X64-LABEL: test1c:
122131
; LINUX-KERNEL-X64: mov{{l|q}} %gs:
123132
; LINUX-KERNEL-X64: callq __stack_chk_fail

0 commit comments

Comments
 (0)