-
Notifications
You must be signed in to change notification settings - Fork 257
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
Segmentation fault with clang-x86 #635
Comments
When the C++ initializer runs, the stack is aligned to 4 mod 16. There's an SSE movaps instruction that accesses a misaligned stack location, which causes the segfault. The stack should be 16-byte aligned in the Linux x86 ABI. There's a platform bug here that seems to exist in (at least) 19 through 23. API 25 seems to be OK, or maybe I'm getting lucky. Reduced test case: #include <stdio.h>
struct Aligned16 {
char buf[16];
} __attribute__((aligned(16)));
static bool init() {
Aligned16 a16;
printf("&a16 = %p\n", &a16);
return true;
}
static bool dummy = init();
int main() {
return 0;
} Broken output (23):
Good output (25):
See https://issuetracker.google.com/37116296 and https://issuetracker.google.com/37119345. Our fix for this issue is to compile with The standalone toolchain doesn't pass the flag. Presumably it also should? Aside: I'm looking at the output of
Edit: Remove "The flag is ignored for x86_64". It looks like the flag does affect x86_64. |
Thanks, |
The standalone toolchain targeting 32-bit x86 passes |
Test: ./checkbuild.py && ./run_tests.py Bug: android/ndk#635 Change-Id: I68e724453baf5b07a4e28ca5078e8fcb0c5ddcc3 (cherry picked from commit c87bf19428313bc21c3e0aeee4f773ad4e523129)
@rprichard Ryan, a clarification. You mention:
Is the platform bug that the stack is sometimes not aligned to 16 bytes or is it something different? |
Yes, the bug here was that ESP was misaligned on dynamic linker startup, and also misaligned when the dynamic linker called constructors while loading the executable. I had commented that the bug seemed fixed as of API 25. AFAIK, the NDK could omit I fixed the root cause of this misalignment for P (API 28) in https://android-review.googlesource.com/c/platform/bionic/+/615665/. I believe the issue was fixed in previous platform versions by two changes:
The combination of those changes masked the misalignment fixed by my Gerrit CL above. Edit: It looks like API 24 is also fine. |
Description
Found code with static initialization that causes segmentation fault when build with clang for x86.
clang-arm works well.
Testcase with buildscript can be found here:
https://github.com/vok1980/segfault-android-clang-x86
Environment Details
The text was updated successfully, but these errors were encountered: