Skip to content

Commit a9cbe5c

Browse files
committed
[X86] Fix stack alignment on 32-bit Solaris/x86
On Solaris/x86, several hundred 32-bit tests `FAIL`, all in the same way: env ASAN_OPTIONS=halt_on_error=false ./halt_on_error_suppress_equal_pcs.cpp.tmp Segmentation Fault (core dumped) They segfault during startup: Thread 2 received signal SIGSEGV, Segmentation fault. [Switching to Thread 1 (LWP 1)] 0x080f21f0 in __sanitizer::internal_mmap(void*, unsigned long, int, int, int, unsigned long long) () at /vol/llvm/src/llvm-project/dist/compiler-rt/lib/sanitizer_common/sanitizer_solaris.cpp:65 65 int prot, int flags, int fd, OFF_T offset) { 1: x/i $pc => 0x80f21f0 <_ZN11__sanitizer13internal_mmapEPvmiiiy+16>: movaps 0x30(%esp),%xmm0 (gdb) p/x $esp $3 = 0xfeffd488 The problem is that `movaps` expects 16-byte alignment, while 32-bit Solaris/x86 only guarantees 4-byte alignment following the i386 psABI. This patch updates `X86Subtarget::initSubtargetFeatures` accordingly, handles Solaris/x86 in the corresponding testcase, and allows for some variation in address alignment in `compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp`. Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D87615
1 parent b03c2b8 commit a9cbe5c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int access_p(T *p, char type) {
162162
case 'm':
163163
// CHECK-MEMBER: vptr.cpp:[[@LINE+6]]:15: runtime error: member access within address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'
164164
// CHECK-MEMBER-NEXT: [[PTR]]: note: object is of type [[DYN_TYPE:'S'|'U']]
165-
// CHECK-MEMBER-NEXT: {{^ .. .. .. .. .. .. .. .. .. .. .. .. }}
165+
// CHECK-MEMBER-NEXT: {{^ ?.. .. .. .. ?.. .. .. .. ?.. .. .. .. ?}}
166166
// CHECK-MEMBER-NEXT: {{^ \^~~~~~~~~~~(~~~~~~~~~~~~)? *$}}
167167
// CHECK-MEMBER-NEXT: {{^ vptr for}} [[DYN_TYPE]]
168168
// CHECK-Linux-MEMBER: #0 {{.*}}access_p{{.*}}vptr.cpp:[[@LINE+1]]
@@ -178,7 +178,7 @@ int access_p(T *p, char type) {
178178
case 'f':
179179
// CHECK-MEMFUN: vptr.cpp:[[@LINE+6]]:15: runtime error: member call on address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'
180180
// CHECK-MEMFUN-NEXT: [[PTR]]: note: object is of type [[DYN_TYPE:'S'|'U']]
181-
// CHECK-MEMFUN-NEXT: {{^ .. .. .. .. .. .. .. .. .. .. .. .. }}
181+
// CHECK-MEMFUN-NEXT: {{^ ?.. .. .. .. ?.. .. .. .. ?.. .. .. .. ?}}
182182
// CHECK-MEMFUN-NEXT: {{^ \^~~~~~~~~~~(~~~~~~~~~~~~)? *$}}
183183
// CHECK-MEMFUN-NEXT: {{^ vptr for}} [[DYN_TYPE]]
184184
// TODO: Add check for stacktrace here.
@@ -196,7 +196,7 @@ int access_p(T *p, char type) {
196196
case 'c':
197197
// CHECK-DOWNCAST: vptr.cpp:[[@LINE+6]]:11: runtime error: downcast of address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'
198198
// CHECK-DOWNCAST-NEXT: [[PTR]]: note: object is of type [[DYN_TYPE:'S'|'U']]
199-
// CHECK-DOWNCAST-NEXT: {{^ .. .. .. .. .. .. .. .. .. .. .. .. }}
199+
// CHECK-DOWNCAST-NEXT: {{^ ?.. .. .. .. ?.. .. .. .. ?.. .. .. .. ?}}
200200
// CHECK-DOWNCAST-NEXT: {{^ \^~~~~~~~~~~(~~~~~~~~~~~~)? *$}}
201201
// CHECK-DOWNCAST-NEXT: {{^ vptr for}} [[DYN_TYPE]]
202202
// CHECK-Linux-DOWNCAST: #0 {{.*}}access_p{{.*}}vptr.cpp:[[@LINE+1]]

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,13 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
258258
report_fatal_error("64-bit code requested on a subtarget that doesn't "
259259
"support it!");
260260

261-
// Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both
262-
// 32 and 64 bit) and for all 64-bit targets.
261+
// Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and for all
262+
// 64-bit targets. On Solaris (32-bit), stack alignment is 4 bytes
263+
// following the i386 psABI, while on Illumos it is always 16 bytes.
263264
if (StackAlignOverride)
264265
stackAlignment = *StackAlignOverride;
265-
else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
266-
isTargetKFreeBSD() || In64BitMode)
266+
else if (isTargetDarwin() || isTargetLinux() || isTargetKFreeBSD() ||
267+
In64BitMode)
267268
stackAlignment = Align(16);
268269

269270
// Consume the vector width attribute or apply any target specific limit.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
; RUN: llc < %s -mcpu=generic -mtriple=i386-kfreebsd | FileCheck %s -check-prefix=KFREEBSD-I386
33
; RUN: llc < %s -mcpu=generic -mtriple=i386-netbsd | FileCheck %s -check-prefix=NETBSD-I386
44
; RUN: llc < %s -mcpu=generic -mtriple=i686-apple-darwin8 | FileCheck %s -check-prefix=DARWIN-I386
5+
; RUN: llc < %s -mcpu=generic -mtriple=i386-pc-solaris2.11 | FileCheck %s -check-prefix=SOLARIS-I386
56
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux | FileCheck %s -check-prefix=LINUX-X86_64
67
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-kfreebsd | FileCheck %s -check-prefix=KFREEBSD-X86_64
78
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-netbsd | FileCheck %s -check-prefix=NETBSD-X86_64
89
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-apple-darwin8 | FileCheck %s -check-prefix=DARWIN-X86_64
10+
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-pc-solaris2.11 | FileCheck %s -check-prefix=SOLARIS-X86_64
911

1012
define i32 @test() nounwind {
1113
entry:
@@ -15,14 +17,17 @@ entry:
1517
; LINUX-I386: subl $12, %esp
1618
; KFREEBSD-I386: subl $12, %esp
1719
; DARWIN-I386: subl $12, %esp
18-
; NETBSD-I386-NOT: subl {{.*}}, %esp
20+
; NETBSD-I386-NOT: subl {{.*}}, %esp
21+
; SOLARIS-I386-NOT: subl {{.*}}, %esp
1922

2023
; LINUX-X86_64: pushq %{{.*}}
2124
; LINUX-X86_64-NOT: subq {{.*}}, %rsp
2225
; DARWIN-X86_64: pushq %{{.*}}
2326
; DARWIN-X86_64-NOT: subq {{.*}}, %rsp
2427
; NETBSD-X86_64: pushq %{{.*}}
2528
; NETBSD-X86_64-NOT: subq {{.*}}, %rsp
29+
; SOLARIS-X86_64: pushq %{{.*}}
30+
; SOLARIS-X86_64-NOT: subq {{.*}}, %rsp
2631
; KFREEBSD-X86_64: pushq %{{.*}}
2732
; KFREEBSD-X86_64-NOT: subq {{.*}}, %rsp
2833
}

0 commit comments

Comments
 (0)