Skip to content
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

regression in the llvm17 branch: C backend fails "align(N) on functions" behavior test #16845

Open
andrewrk opened this issue Aug 15, 2023 · 1 comment
Labels
backend-c The C backend (CBE) outputs C source code. bug Observed behavior contradicts documented or intended behavior regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Aug 15, 2023

zig version: 0.12.0-dev.116+4cc2544cd (llvm17 branch)

$ zig build test-behavior
run test behavior-native-Debug-libc-cbe: error: 'test.align(N) on functions' failed
run test behavior-native-Debug-libc-cbe: error: Illegal instruction at address 0x49d1b2
/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c:56772:2: 0x49d1b2 in behavior_cast_test_cast_20function_20with_20an_20opaque_20parameter__2424 (/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c)
 t7(t5);
 ^
/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c:25836:10: 0x4336d4 in test_runner_mainServer__158 (/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c)
    t6 = t43();
         ^
/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c:26014:9: 0x2a4beb in test_runner_main__157 (/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c)
  t17 = test_runner_mainServer__158();
        ^
/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c:23664:2: 0x2a3a07 in main (/home/andy/misc/zig/zig-cache/o/095b4cdbe22fa6116fcdfeb6662f9b6f/test.c)
 test_runner_main__157();
 ^
???:?:?: 0x7fc26b8de24d in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7fc26b8de24d` was not available, trace may be incomplete

???:?:?: 0x7ffcc8b29884 in ??? (???)

Some possible reasons this regressed with the llvm17 branch:

  • UBSAN in clang 17 is now catching a true positive
  • a regression in clang 17 when compiling the C code
  • changes in clang 17 that have a side-effect of uncovering a latent bug in zig's C backend output
  • a miscompilation in the compiler, which was compiled with the LLVM (17) backend

I suspect this has the same root cause for the failure of the behavior test "cast function with an opaque parameter" as well.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior backend-c The C backend (CBE) outputs C source code. regression It worked in a previous version of Zig, but stopped working. labels Aug 15, 2023
@andrewrk andrewrk added this to the 0.12.0 milestone Aug 15, 2023
andrewrk added a commit that referenced this issue Aug 16, 2023
@jacobly0
Copy link
Member

jacobly0 commented Aug 16, 2023

This regressed because llvm is inserting cfi information at the aligned function address requested and using an offset address for the function pointer.

To quote the LangRef

Prefix data is laid out as if it were an initializer for a global variable of the prefix data’s type. The function will be placed such that the beginning of the prefix data is aligned. This means that if the size of the prefix data is not a multiple of the alignment size, the function’s entrypoint will not be aligned. If alignment of the function’s entrypoint is desired, padding must be added to the prefix data.

andrewrk added a commit that referenced this issue Aug 20, 2023
andrewrk added a commit that referenced this issue Aug 24, 2023
andrewrk added a commit that referenced this issue Sep 19, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.13.0 Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-c The C backend (CBE) outputs C source code. bug Observed behavior contradicts documented or intended behavior regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

No branches or pull requests

2 participants