Skip to content

[JITLink][i386] Avoid 'i386' name clashing with built-in macro #137063

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

Closed
wants to merge 1 commit into from

Conversation

DimitryAndric
Copy link
Collaborator

When compiling llvm on an actual i386 platform, both clang and gcc define a built-in macro i386 to the value 1. This clashes with the llvm::jitlink::i386 namespace:

In file included from llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp:18:
llvm/include/llvm/ExecutionEngine/JITLink/i386.h:19:24: error: expected '{'
   19 | namespace llvm::jitlink::i386 {
      |                        ^
llvm/include/llvm/ExecutionEngine/JITLink/i386.h:19:26: error: expected unqualified-id
   19 | namespace llvm::jitlink::i386 {
      |                          ^

The macro name 'i386' is obviously a historical bad choice, but since it existed long before llvm, llvm should either rename its namespace, or actively undefine the macro in i386.h (similar to e.g. https://github.com/google/swiftshader/blob/master/third_party/llvm-16.0/Android.bp#L1510).

This particular pull request implements the rename, but is meant to gauge opinions on how to solve this issue.

When compiling llvm on an actual i386 platform, both clang and gcc
define a built-in macro `i386` to the value 1. This clashes with the
`llvm::jitlink::i386` namespace:

```
In file included from llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp:18:
llvm/include/llvm/ExecutionEngine/JITLink/i386.h:19:24: error: expected '{'
   19 | namespace llvm::jitlink::i386 {
      |                        ^
llvm/include/llvm/ExecutionEngine/JITLink/i386.h:19:26: error: expected unqualified-id
   19 | namespace llvm::jitlink::i386 {
      |                          ^
```

The macro name 'i386' is obviously a historical bad choice, but since it
existed long before llvm, llvm should either rename its namespace, or
actively undefine the macro in `i386.h` (similar to e.g.
https://github.com/google/swiftshader/blob/master/third_party/llvm-16.0/Android.bp#L1510).

This particular pull request implements the rename, but is meant to
gauge opinions on how to solve this issue.
@jrtc27
Copy link
Collaborator

jrtc27 commented Apr 23, 2025

When compiling llvm on an actual i386 platform, both clang and gcc define a built-in macro i386 to the value 1.

* As GNU C/C++. This of course also extends to any third-party code compiled as such that includes this header.

@DimitryAndric
Copy link
Collaborator Author

Since the llvm build system itself explicitly compiles this with -std=c++17, not -std=gnu++17, I think the problem we've encountered in FreeBSD is self-inflicted. :) Then again, for other projects it might be nicer to avoid this identifier, or at the least #undef it if it exists.

@lhames
Copy link
Contributor

lhames commented Apr 24, 2025

I’d be fine renaming this backed to x86 (or x86_32) to avoid the clash. I doubt that there are any explicit references to jitlink::i386 outside llvm-project so I’d expect the fallout to be minimal (beyond a bunch of renames in LLVM itself).

I’m travelling with limited internet access for the next week and a bit, but can check in on this when I get back to my desk.

lhames added a commit that referenced this pull request May 8, 2025
When building on i386, both clang and gcc define a builtin 'i386' macro (see
discussion in #137063). This causes
build errors in the JITLink/i386 backend when attempting to build LLVM on i386.

This commit renames the 'i386' backend (namespaces, APIs and files) to 'x86' to
avoid this issue.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 8, 2025
When building on i386, both clang and gcc define a builtin 'i386' macro (see
discussion in llvm/llvm-project#137063). This causes
build errors in the JITLink/i386 backend when attempting to build LLVM on i386.

This commit renames the 'i386' backend (namespaces, APIs and files) to 'x86' to
avoid this issue.
petrhosek pushed a commit to petrhosek/llvm-project that referenced this pull request May 8, 2025
When building on i386, both clang and gcc define a builtin 'i386' macro (see
discussion in llvm#137063). This causes
build errors in the JITLink/i386 backend when attempting to build LLVM on i386.

This commit renames the 'i386' backend (namespaces, APIs and files) to 'x86' to
avoid this issue.
@lhames
Copy link
Contributor

lhames commented May 8, 2025

This should be fixed by b972164 and prior commits.

@lhames lhames closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants