Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

TypeCheck/misaligned.cpp FAILs on SPARC #45984

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR47015
Status NEW
Importance P normal
Reported by Rainer Orth (ro@gcc.gnu.org)
Reported on 2020-08-06 07:14:28 -0700
Last modified on 2020-08-07 01:03:45 -0700
Version unspecified
Hardware Sun Solaris
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The TypeCheck/misaligned.cpp test FAILs on SPARC:

  UBSan-Standalone-sparc :: TestCases/TypeCheck/misaligned.cpp
  UBSan-Standalone-sparcv9 :: TestCases/TypeCheck/misaligned.cpp

The failure only affects the s1 subtest:

$ ./misaligned.cpp.tmp s1
misaligned.cpp:55:5: runtime error: store to misaligned address 0xffbfee35 for
type 'int', which requires 4 byte alignment
0xffbfee35: note: pointer points here
 00 00 00 01 02 03 04  05 00 00 05 ff bf ee ac  00 00 00 02 00 00 00 00  00 00 00 02 ff bf ee ac  ff
             ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior misaligned.cpp:55:5 in
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==21427==ERROR: UndefinedBehaviorSanitizer: stack-overflow on address
0xffbfee35 (pc 0x0004fe20 bp 0xffbfee48 sp 0xffbfed30 T1)
    #0 0x4fe28 in main /var/llvm/local-sparcv9-A/misaligned.cpp:63:16
    #1 0x284f4 in _start (misaligned.cpp.tmp+0x284f4)

SUMMARY: UndefinedBehaviorSanitizer: stack-overflow /var/llvm/local-sparcv9-
A/misaligned.cpp:63:16 in main
==21427==ABORTING

and can be reproduced with the following minimal testcase:

$ cat ma.c
int main(void) {
  char c[] __attribute__((aligned(8))) = { 0, 0, 0, 0, 1, 2, 3, 4, 5 };

  int *p = (int*)&c[5];
  *p = 1;
}
$ clang -g3 -O0 -m32 -fsanitize=alignment -o ma ma.c

The test dies with SIGBUS as can be seen in truss output:

21443:      Incurred fault #5, FLTACCESS  %pc = 0x0004E128
21443:        siginfo: SIGBUS BUS_ADRALN addr=0xFFBFEE2D
21443:      Received signal #10, SIGBUS [caught]
21443:        siginfo: SIGBUS BUS_ADRALN addr=0xFFBFEE2D

Since SPARC is a strict-alignment target, the unaligned access is not only
undefefined behaviour, but actually incurs a fault.  It seems ubsan cannot
handle that.

I don't currently have access to Linux/sparc64 or other strict-alignment targets
to check if this is a Solaris issue or a generic sparc/strict-alignment one.
Quuxplusone commented 4 years ago
I've now managed a build on Linux/sparc64: the behaviour is exactly the same, so
this is not just a Solaris issue.