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

__builtin_debugtrap detection is wrong #24

Open
jwakely opened this issue Jan 4, 2022 · 3 comments
Open

__builtin_debugtrap detection is wrong #24

jwakely opened this issue Jan 4, 2022 · 3 comments

Comments

@jwakely
Copy link

jwakely commented Jan 4, 2022

You use defined(__APPLE__) to decide whether to use __builtin_debugtrap but that's wrong, because only Clang supports that built-in, but GCC defines __APPLE__ too.

The minimal fix would be to just check defined(__clang__) instead of defined(__APPLE__).

I don't see any reason to restrict the use of __builtin_debugtrap() to aarch64 on macOS, you could use it on all platforms when compiling with Clang. For x86 it expands to int 3 which is what your own code does. For ARM it expands to .inst 0xe7f001f0 which is the same as your code again.

To use __builtin_debugtrap() whenever the compiler supports it, you can do something like:

#ifdef __has_builtin
# if __has_builtin(__builtin_debugtrap)
#  define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BUILTIN_DEBUGTRAP
# endif
#endif

#ifndef DEBUG_BREAK_IMPL
// ... existing code ...
#endif
@ericoporto
Copy link

@jwakely do you have a fork with these fixes?

@jwakely
Copy link
Author

jwakely commented May 2, 2023

No, maybe I'll create one tomorrow though

@dbabokin
Copy link

I got the same problem, when trying to use gcc on Apple ARM64 platform.

Checking defined(__clang__) instead or after defined(__APPLE__) would do the job.

The one can argue that using gcc on macOS is very strange use case. While tris is true, it has it's niche for building software in "Linux compatible mode" and it has its value for developers.

For the reference, I'm installing gcc through home brew: brew install gcc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants