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

Compilation fails when Address Sanitizer enabled #1990

Closed
davidrothera opened this issue Jul 19, 2022 · 9 comments · Fixed by #1996
Closed

Compilation fails when Address Sanitizer enabled #1990

davidrothera opened this issue Jul 19, 2022 · 9 comments · Fixed by #1996

Comments

@davidrothera
Copy link

davidrothera commented Jul 19, 2022

Platform

iOS

Installed

Swift Package Manager

Version

7.21.0

Steps to Reproduce

  • Enable Address Sanitizer on build
  • Try to build
  • Observe compilation fails with:
ld: Assertion failed: (index < orderedInitOffsetAtoms.size()), function doPass, file inits.cpp, line 131.

Simple repro at https://github.com/davidrothera/CrashTest with ASAN enabled

Expected Result

Compilation works

Actual Result

Compilation fails

@davidrothera
Copy link
Author

Confirmed that rolling back to 7.2.0 fixes the issue.

@bruno-garcia
Copy link
Member

bruno-garcia commented Jul 19, 2022

Does it work on the latest? 7.21.0?

@davidrothera
Copy link
Author

Sorry I got the versions wrong:

  • Working: 7.20.0
  • Broken: 7.21.0

@philipphofmann
Copy link
Member

Thanks for reporting this, @davidrothera. I can reproduce this with your sample project and have to look into what's causing this. I'm surprised that our CI didn't catch this.

@davidrothera
Copy link
Author

It took me a while to catch it myself as it's not super clear what causes it and I wasn't seeing it in all projects or in all build modes and it wasn't until I went over them with a magnifying glass that I remembered I had ASAN enabled the one which was failing.

I'm guessing most of your CI projects don't have ASAN enabled.

@bruno-garcia
Copy link
Member

bruno-garcia commented Jul 20, 2022

I'm guessing most of your CI projects don't have ASAN enabled.

If we enable it in one of our samples, would that do the job @philipphofmann @brustolin ?

@davidrothera
Copy link
Author

If we enable it in one of our samples, would that do the job @philipphofmann @brustolin ?

It should do, enabling ASAN usually should have no impact other than to surface issues and then even this is abnormal for ASAN but I'm guessing it could be related to the C++ module init functions which were added?

@philipphofmann
Copy link
Member

Yep, it's related to

/**
* Module initialization functions. The C++ compiler places static constructors here. For more info
* visit:
* https://github.com/aidansteele/osx-abi-macho-file-format-reference#table-2-the-sections-of-a__datasegment
*/
__attribute__((section("__DATA,__mod_init_func"))) typeof(sentryModuleInitializationHook) *__init
= sentryModuleInitializationHook;

I just removed this code, and it compiles again. I wonder why that is.

We have ASAN enabled in CI for the Sentry project, but not for the samples. Enabling it for our sample projects doesn't fail the build.

Maybe we can use

__used __attribute__((constructor)) static void recordProcessStartTime() {
    moduleInitializationTimestamp = [NSDate date];
}

Instead of the __mod_init_func.

@philipphofmann
Copy link
Member

philipphofmann commented Jul 20, 2022

The detailed error is

Assertion failed: (index < orderedInitOffsetAtoms.size()), function doPass, file inits.cpp, line 131.
0  0x10a2ee0ee  __assert_rtn + 127
1  0x10a2ac2ef  ld::passes::inits::doPass(Options&, ld::Internal&) + 1169
2  0x10a1a2325  main + 419

The assertion error is coming from here assert(index < orderedInitOffsetAtoms.size());.

Here is the linker snapshot. It's bigger than 25MB, so I couldn't upload it here.

philipphofmann added a commit that referenced this issue Jul 22, 2022
philipphofmann added a commit that referenced this issue Jul 28, 2022
Fix address sanitizer compilation error by using the constructor attribute instead of
__DATA,__mod_init_func.


Fixes GH-1990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants