-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
llvm.eh.sjlj.setjmp needs returns_twice (to make nested __builtin_setjmp work on PowerPC) #49578
Comments
FWIW, it seems that the workaround code in the repro does not work any more with Clang/LLVM version 12.0.1 or 13.0.0-rc1. With 12.0.1, $ /usr/lib/llvm/12/bin/clang --target=powerpc64le-unknown-linux-musl -O3 ppc_bsjlj.c -DWORKAROUND=1 results in the hexdump'ed output 00000000 76 61 6c 75 65 20 3d 20 32 37 34 38 37 38 31 30 |value = 27487810| and with 13.0.0-rc1, $ /usr/lib/llvm/13/bin/clang --target=powerpc64le-unknown-linux-musl -O3 ppc_bsjlj.c -DWORKAROUND=1 results in 00000000 76 61 6c 75 65 20 3d 20 32 37 34 38 37 38 31 30 |value = 27487810| I have no idea whether this is a separate issue or not. Note that this time musl is used as a target, and so the generated executable becomes a PIE, which I am not sure is relevant. |
Disassembly of main (compiled with -O1) 10b10: 50 80 83 e8 ld 4, -32688(3) # value of n loaded 10ba8: c0 80 83 38 addi 4, 3, -32576 # addr of jb2 10b78: 70 00 61 e8 ld 3, 112(1) # addr of format string reloaded The value of n is saved at 120(1), but afterwards it is overwritten by the address of jb2. Similarly, the funny output with -DWORKAROUND=1 shown in the previous comment seems due to the saved address of format string being corrupted afterwards (note that print_ulong is inlined). I have no idea how to fix this for now. |
It seems that __builtin_setjmp needs attribute returns_twice. Proposed change: https://reviews.llvm.org/D109248 |
mentioned in issue llvm/llvm-bugzilla-archive#51729 |
Extended Description
The attached C program (named ppc_bsjlj.c) behaves incorrectly when compiled with optimization level -O1 or higher for PPC targets.
For 32-bit PPC
$ clang --target=powerpc-unknown-linux-gnu -O3 -c ppc_bsjlj.c
results in the output
value = 268566576
value = 268566596
where the two lines should be identical.
Similarly, for ppc64le
$ clang --target=powerpc64le-unknown-linux-gnu -O3 -c ppc_bsjlj.c
results in
value = 268566608
value = 268566648
Note that in the program the value of the local variable
n
is not changed between__builtin_setjmp
and the corresponding__builtin_longjmp
. Indeed it is const-qualified.The text was updated successfully, but these errors were encountered: