This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] [builtins] Fix building atomic.c with GCC
Needs ReviewPublic

Authored by mgorny on Feb 15 2017, 11:14 PM.

Details

Summary

Make the use of #pragma redefine_extname and appropriate renames of
builtins conditional to using clang. GCC used not to support it outside
Solaris and currently seems to be very restrictive on applying it.
In other words, it does not work for me with GCC 5.4.0 and the built
libraries use the 'internal' names.

On the other hand, GCC does not have any restrictions on redefining
builtins. So instead of trying to figure out how to make the #pragma
work, it is simpler to make the rename conditional to clang.

Diff Detail

Event Timeline

mgorny created this revision.Feb 15 2017, 11:14 PM
theraven edited edge metadata.Feb 16 2017, 2:19 AM

This code is working around something that's probably a clang bug. It would be better to fix the clang bug than add more complex workarounds.

This code is working around something that's probably a clang bug. It would be better to fix the clang bug than add more complex workarounds.

Well, clang explicitly rejects those functions as errors, so I would guess it does that by design.

No, it's a bug in clang. Clang does not reject other functions that are used to implement builtins (if it did, compiler-rt would be a lot more difficult to build).

joerg added a subscriber: joerg.Feb 16 2017, 6:22 AM

Note that the normal compiler-rt functions have a different name than the builtins they provide, at least from the C frontend view.

mgorny added a subscriber: doug.gregor.

If I read the git correctly, the change that forbid defining builtins was initially made in rL64639. @doug.gregor, any chance you could help us over here? Is clang supposed to unconditionally reject those definitions, and are we supposed to always work-around it in compiler-rt, or should we consider adding some additional switch to allow them in clang?