-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Constructor size is twice as large on Clang17.0.2 with MTE enabled #69939
Comments
Dear Mitch Phillips, I found that the issue mentioned in this issue was added between the following tags:
Also, I analyzed the MTE related activity for the commits between the mentioned tags and found that you are the author of them, for example:
Could you please analyze the current issue to see if it could be related to the changes you made? Thank you! |
G'day Victor, Yeah, this is almost certainly due to MTE globals instrumentation. We pad all global variables to be a multiple of 16 bytes, which includes your I'm guessing this breaks something in the dynamic loader as it's expecting the fnptrs in the I think explicitly declaring a constructor function with |
(misclick on the close-with-comment button) |
Dear Mitch, thank you very much for your quick reply!
Unfortunately yes. We have a few ideas to solve the problem, but your response was very helpful.
This really solved the problem:
Great advice!
UPD2.
However, in this case, function pointers should be accessed and called using ".init_array" section. P.S. |
I think you're doing something very niche by declaring a constructor using This breaks under all sanitizers that mess with global variables (asan, hwasan, mte). Given this is the first time I'm hearing about it, and the examples I could find in a quick search (android, chrome, incl. third party libraries, etc.) were in binutils/clang/lld and not in user code, I don't think it's a huge priority to fix. But it does look cheap, let me take a quick hack at it. |
Looks like there's code out there that, instead of using '__attribute__((constructor(x)))' to add constructor functions, they just declare a global function pointer and use '__attribute__((section('.ctors')))' instead. Problem is, with memtag-globals, we pad the global function pointer to be 16 bytes large. This of course means we have an 8-byte real function pointer, then 8 bytes of zero padding, and this trips up the loader when it processes this section. Fixes #69939
@llvm/issue-subscribers-backend-aarch64 Author: Victor Signaevskyi (P1119r1m)
### TL;DR
The bug is actually that Clang/ld.lld generates redundant executable code in the final binary.
This can be reproduced on (Clang > 17.0.0) when building C code for AARCH64 with the Memory Tagging Extension (MTE) compilation flags.
Example code simply stores function pointers in ".ctors" section.
Steps to reproduce the bugTo reproduce the problem 2 files should be created:
The output for the "source build.sh" run command is following:
In case of using "Clang17.0.0" from the "llvmorg-v17-init" tag:
|
TL;DR
The bug is actually that Clang/ld.lld generates redundant executable code in the final binary.
This can be reproduced on (Clang > 17.0.0) when building C code for AARCH64 with the Memory Tagging Extension (MTE) compilation flags.
Example code simply stores function pointers in ".ctors" section.
Steps to reproduce the bug
To reproduce the problem 2 files should be created:
main.c
build.sh
The output for the "source build.sh" run command is following:
In case of using "Clang17.0.0" from the "llvmorg-v17-init" tag:
The text was updated successfully, but these errors were encountered: