Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit b820135

Browse files
committed
Add segmented stack support for DragonFlyBSD.
Patch by Michael Neumann. http://llvm.org/viewvc/llvm-project?view=revision&revision=224936 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224936 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ec1fdb3 commit b820135

File tree

4 files changed

+122
-3
lines changed

4 files changed

+122
-3
lines changed

include/llvm/ADT/Triple.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ class Triple {
368368
return getOS() == Triple::FreeBSD;
369369
}
370370

371+
bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
372+
371373
bool isWindowsMSVCEnvironment() const {
372374
return getOS() == Triple::Win32 &&
373375
(getEnvironment() == Triple::UnknownEnvironment ||

lib/Target/X86/X86FrameLowering.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,9 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
13691369

13701370
if (MF.getFunction()->isVarArg())
13711371
report_fatal_error("Segmented stacks do not support vararg functions.");
1372-
if (!STI.isTargetLinux() && !STI.isTargetDarwin() &&
1373-
!STI.isTargetWin32() && !STI.isTargetWin64() && !STI.isTargetFreeBSD())
1372+
if (!STI.isTargetLinux() && !STI.isTargetDarwin() && !STI.isTargetWin32() &&
1373+
!STI.isTargetWin64() && !STI.isTargetFreeBSD() &&
1374+
!STI.isTargetDragonFly())
13741375
report_fatal_error("Segmented stacks not supported on this platform.");
13751376

13761377
// Eventually StackSize will be calculated by a link-time pass; which will
@@ -1424,6 +1425,9 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
14241425
} else if (STI.isTargetFreeBSD()) {
14251426
TlsReg = X86::FS;
14261427
TlsOffset = 0x18;
1428+
} else if (STI.isTargetDragonFly()) {
1429+
TlsReg = X86::FS;
1430+
TlsOffset = 0x20; // use tls_tcb.tcb_segstack
14271431
} else {
14281432
report_fatal_error("Segmented stacks not supported on this platform.");
14291433
}
@@ -1446,6 +1450,9 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
14461450
} else if (STI.isTargetWin32()) {
14471451
TlsReg = X86::FS;
14481452
TlsOffset = 0x14; // pvArbitrary, reserved for application use
1453+
} else if (STI.isTargetDragonFly()) {
1454+
TlsReg = X86::FS;
1455+
TlsOffset = 0x10; // use tls_tcb.tcb_segstack
14491456
} else if (STI.isTargetFreeBSD()) {
14501457
report_fatal_error("Segmented stacks not supported on FreeBSD i386.");
14511458
} else {
@@ -1458,7 +1465,8 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
14581465
BuildMI(checkMBB, DL, TII.get(X86::LEA32r), ScratchReg).addReg(X86::ESP)
14591466
.addImm(1).addReg(0).addImm(-StackSize).addReg(0);
14601467

1461-
if (STI.isTargetLinux() || STI.isTargetWin32() || STI.isTargetWin64()) {
1468+
if (STI.isTargetLinux() || STI.isTargetWin32() || STI.isTargetWin64() ||
1469+
STI.isTargetDragonFly()) {
14621470
BuildMI(checkMBB, DL, TII.get(X86::CMP32rm)).addReg(ScratchReg)
14631471
.addReg(0).addImm(0).addReg(0).addImm(TlsOffset).addReg(TlsReg);
14641472
} else if (STI.isTargetDarwin()) {

lib/Target/X86/X86Subtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ class X86Subtarget final : public X86GenSubtargetInfo {
385385
bool isTargetFreeBSD() const {
386386
return TargetTriple.getOS() == Triple::FreeBSD;
387387
}
388+
bool isTargetDragonFly() const { return TargetTriple.isOSDragonFly(); }
388389
bool isTargetSolaris() const {
389390
return TargetTriple.getOS() == Triple::Solaris;
390391
}

test/CodeGen/X86/segmented-stacks.ll

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-darwin -verify-machineinstrs | FileCheck %s -check-prefix=X64-Darwin
66
; RUN: llc < %s -mcpu=generic -mtriple=i686-mingw32 -verify-machineinstrs | FileCheck %s -check-prefix=X32-MinGW
77
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-freebsd -verify-machineinstrs | FileCheck %s -check-prefix=X64-FreeBSD
8+
; RUN: llc < %s -mcpu=generic -mtriple=i686-dragonfly -verify-machineinstrs | FileCheck %s -check-prefix=X32-DFlyBSD
9+
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-dragonfly -verify-machineinstrs | FileCheck %s -check-prefix=X64-DFlyBSD
810
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-mingw32 -verify-machineinstrs | FileCheck %s -check-prefix=X64-MinGW
911

1012
; We used to crash with filetype=obj
@@ -15,6 +17,8 @@
1517
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-darwin -filetype=obj
1618
; RUN: llc < %s -mcpu=generic -mtriple=i686-mingw32 -filetype=obj
1719
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-freebsd -filetype=obj
20+
; RUN: llc < %s -mcpu=generic -mtriple=i686-dragonfly -filetype=obj
21+
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-dragonfly -filetype=obj
1822
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-mingw32 -filetype=obj
1923

2024
; RUN: not llc < %s -mcpu=generic -mtriple=x86_64-solaris 2> %t.log
@@ -114,6 +118,26 @@ define void @test_basic() #0 {
114118
; X64-FreeBSD-NEXT: callq __morestack
115119
; X64-FreeBSD-NEXT: ret
116120

121+
; X32-DFlyBSD-LABEL: test_basic:
122+
123+
; X32-DFlyBSD: cmpl %fs:16, %esp
124+
; X32-DFlyBSD-NEXT: ja .LBB0_2
125+
126+
; X32-DFlyBSD: pushl $0
127+
; X32-DFlyBSD-NEXT: pushl $48
128+
; X32-DFlyBSD-NEXT: calll __morestack
129+
; X32-DFlyBSD-NEXT: ret
130+
131+
; X64-DFlyBSD-LABEL: test_basic:
132+
133+
; X64-DFlyBSD: cmpq %fs:32, %rsp
134+
; X64-DFlyBSD-NEXT: ja .LBB0_2
135+
136+
; X64-DFlyBSD: movabsq $40, %r10
137+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
138+
; X64-DFlyBSD-NEXT: callq __morestack
139+
; X64-DFlyBSD-NEXT: ret
140+
117141
}
118142

119143
define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
@@ -199,6 +223,24 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
199223
; X64-FreeBSD-NEXT: ret
200224
; X64-FreeBSD-NEXT: movq %rax, %r10
201225

226+
; X32-DFlyBSD: cmpl %fs:16, %esp
227+
; X32-DFlyBSD-NEXT: ja .LBB1_2
228+
229+
; X32-DFlyBSD: pushl $4
230+
; X32-DFlyBSD-NEXT: pushl $52
231+
; X32-DFlyBSD-NEXT: calll __morestack
232+
; X32-DFlyBSD-NEXT: ret
233+
234+
; X64-DFlyBSD: cmpq %fs:32, %rsp
235+
; X64-DFlyBSD-NEXT: ja .LBB1_2
236+
237+
; X64-DFlyBSD: movq %r10, %rax
238+
; X64-DFlyBSD-NEXT: movabsq $56, %r10
239+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
240+
; X64-DFlyBSD-NEXT: callq __morestack
241+
; X64-DFlyBSD-NEXT: ret
242+
; X64-DFlyBSD-NEXT: movq %rax, %r10
243+
202244
}
203245

204246
define void @test_large() #0 {
@@ -280,6 +322,24 @@ define void @test_large() #0 {
280322
; X64-FreeBSD-NEXT: callq __morestack
281323
; X64-FreeBSD-NEXT: ret
282324

325+
; X32-DFlyBSD: leal -40008(%esp), %ecx
326+
; X32-DFlyBSD-NEXT: cmpl %fs:16, %ecx
327+
; X32-DFlyBSD-NEXT: ja .LBB2_2
328+
329+
; X32-DFlyBSD: pushl $0
330+
; X32-DFlyBSD-NEXT: pushl $40008
331+
; X32-DFlyBSD-NEXT: calll __morestack
332+
; X32-DFlyBSD-NEXT: ret
333+
334+
; X64-DFlyBSD: leaq -40008(%rsp), %r11
335+
; X64-DFlyBSD-NEXT: cmpq %fs:32, %r11
336+
; X64-DFlyBSD-NEXT: ja .LBB2_2
337+
338+
; X64-DFlyBSD: movabsq $40008, %r10
339+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
340+
; X64-DFlyBSD-NEXT: callq __morestack
341+
; X64-DFlyBSD-NEXT: ret
342+
283343
}
284344

285345
define fastcc void @test_fastcc() #0 {
@@ -368,6 +428,26 @@ define fastcc void @test_fastcc() #0 {
368428
; X64-FreeBSD-NEXT: callq __morestack
369429
; X64-FreeBSD-NEXT: ret
370430

431+
; X32-DFlyBSD-LABEL: test_fastcc:
432+
433+
; X32-DFlyBSD: cmpl %fs:16, %esp
434+
; X32-DFlyBSD-NEXT: ja .LBB3_2
435+
436+
; X32-DFlyBSD: pushl $0
437+
; X32-DFlyBSD-NEXT: pushl $48
438+
; X32-DFlyBSD-NEXT: calll __morestack
439+
; X32-DFlyBSD-NEXT: ret
440+
441+
; X64-DFlyBSD-LABEL: test_fastcc:
442+
443+
; X64-DFlyBSD: cmpq %fs:32, %rsp
444+
; X64-DFlyBSD-NEXT: ja .LBB3_2
445+
446+
; X64-DFlyBSD: movabsq $40, %r10
447+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
448+
; X64-DFlyBSD-NEXT: callq __morestack
449+
; X64-DFlyBSD-NEXT: ret
450+
371451
}
372452

373453
define fastcc void @test_fastcc_large() #0 {
@@ -464,6 +544,28 @@ define fastcc void @test_fastcc_large() #0 {
464544
; X64-FreeBSD-NEXT: callq __morestack
465545
; X64-FreeBSD-NEXT: ret
466546

547+
; X32-DFlyBSD-LABEL: test_fastcc_large:
548+
549+
; X32-DFlyBSD: leal -40008(%esp), %eax
550+
; X32-DFlyBSD-NEXT: cmpl %fs:16, %eax
551+
; X32-DFlyBSD-NEXT: ja .LBB4_2
552+
553+
; X32-DFlyBSD: pushl $0
554+
; X32-DFlyBSD-NEXT: pushl $40008
555+
; X32-DFlyBSD-NEXT: calll __morestack
556+
; X32-DFlyBSD-NEXT: ret
557+
558+
; X64-DFlyBSD-LABEL: test_fastcc_large:
559+
560+
; X64-DFlyBSD: leaq -40008(%rsp), %r11
561+
; X64-DFlyBSD-NEXT: cmpq %fs:32, %r11
562+
; X64-DFlyBSD-NEXT: ja .LBB4_2
563+
564+
; X64-DFlyBSD: movabsq $40008, %r10
565+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
566+
; X64-DFlyBSD-NEXT: callq __morestack
567+
; X64-DFlyBSD-NEXT: ret
568+
467569
}
468570

469571
define fastcc void @test_fastcc_large_with_ecx_arg(i32 %a) #0 {
@@ -515,6 +617,12 @@ define void @test_nostack() #0 {
515617

516618
; X64-FreeBSD-LABEL: test_nostack:
517619
; X64-FreeBSD-NOT: callq __morestack
620+
621+
; X32-DFlyBSD-LABEL: test_nostack:
622+
; X32-DFlyBSD-NOT: calll __morestack
623+
624+
; X64-DFlyBSD-LABEL: test_nostack:
625+
; X64-DFlyBSD-NOT: callq __morestack
518626
}
519627

520628
attributes #0 = { "split-stack" }

0 commit comments

Comments
 (0)