Skip to content

Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds #131578

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

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

anutosh491
Copy link
Member

@anutosh491 anutosh491 commented Mar 17, 2025

While building llvm (clang, lld) against emscripten we see this error

 │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9:
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI'
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       | ^
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       |                   ^

Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see llvm/Support/Compiler.h, the condition only checked for the platform WASM . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI.

The successful build after using this patch can be seen here

@anutosh491 anutosh491 marked this pull request as ready for review March 17, 2025 07:56
@llvmbot llvmbot added clang Clang issues not falling into any other category llvm:support labels Mar 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 17, 2025

@llvm/pr-subscribers-clang

Author: Anutosh Bhat (anutosh491)

Changes

While building llvm (clang, lld) against emscripten we see this error

 │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9:
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI'
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       | ^
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       |                   ^

Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see llvm/Support/Compiler.h, the condition only checked for the platform WASM . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI.


Full diff: https://github.com/llvm/llvm-project/pull/131578.diff

2 Files Affected:

  • (modified) clang/include/clang/Support/Compiler.h (+1-1)
  • (modified) llvm/include/llvm/Support/Compiler.h (+1-1)
diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h
index 13582b899dc2a..5a74f8e3b6723 100644
--- a/clang/include/clang/Support/Compiler.h
+++ b/clang/include/clang/Support/Compiler.h
@@ -54,7 +54,7 @@
 #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_EXPORT_TEMPLATE
-#elif defined(__MACH__) || defined(__WASM__)
+#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
 #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_TEMPLATE_ABI
 #define CLANG_EXPORT_TEMPLATE
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index f9c57b89f1f03..dc8b5389069eb 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -203,7 +203,7 @@
 #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_EXPORT_TEMPLATE
 #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
-#elif defined(__MACH__) || defined(__WASM__)
+#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE

@llvmbot
Copy link
Member

llvmbot commented Mar 17, 2025

@llvm/pr-subscribers-llvm-support

Author: Anutosh Bhat (anutosh491)

Changes

While building llvm (clang, lld) against emscripten we see this error

 │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9:
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI'
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       | ^
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       |                   ^

Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see llvm/Support/Compiler.h, the condition only checked for the platform WASM . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI.


Full diff: https://github.com/llvm/llvm-project/pull/131578.diff

2 Files Affected:

  • (modified) clang/include/clang/Support/Compiler.h (+1-1)
  • (modified) llvm/include/llvm/Support/Compiler.h (+1-1)
diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h
index 13582b899dc2a..5a74f8e3b6723 100644
--- a/clang/include/clang/Support/Compiler.h
+++ b/clang/include/clang/Support/Compiler.h
@@ -54,7 +54,7 @@
 #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_EXPORT_TEMPLATE
-#elif defined(__MACH__) || defined(__WASM__)
+#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
 #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_TEMPLATE_ABI
 #define CLANG_EXPORT_TEMPLATE
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index f9c57b89f1f03..dc8b5389069eb 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -203,7 +203,7 @@
 #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_EXPORT_TEMPLATE
 #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
-#elif defined(__MACH__) || defined(__WASM__)
+#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE

@anutosh491
Copy link
Member Author

cc @serge-sans-paille for review.

@serge-sans-paille serge-sans-paille self-requested a review March 17, 2025 08:28
@serge-sans-paille
Copy link
Collaborator

LGTM, waiting for CI to complete though

@anutosh491
Copy link
Member Author

Hey,

Thanks for the review. The CI is green now !

@serge-sans-paille serge-sans-paille merged commit e57cd10 into llvm:main Mar 17, 2025
16 checks passed
@anutosh491 anutosh491 deleted the emscripten_llvm_abi branch March 17, 2025 11:17
@anutosh491
Copy link
Member Author

Hey @serge-sans-paille

One final request here would be if you could add the milestone (LLVM 20.X Release I think)

So that this is picked up in the next release (20.0.2) and we wouldn't need to use the patch then !

@anutosh491
Copy link
Member Author

/cherry-pick e57cd10

@llvmbot
Copy link
Member

llvmbot commented Mar 17, 2025

/cherry-pick e57cd10

Error: Command failed due to missing milestone.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 17, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building clang,llvm at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/9230

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: 1200 seconds without output running [b'ninja', b'-j 4', b'check-openmp'], attempting to kill
...
PASS: ompd-test :: openmp_examples/example_2.c (442 of 452)
PASS: ompd-test :: openmp_examples/example_4.c (443 of 452)
PASS: ompd-test :: openmp_examples/example_5.c (444 of 452)
PASS: ompd-test :: openmp_examples/example_task.c (445 of 452)
UNSUPPORTED: ompd-test :: openmp_examples/ompd_bt.c (446 of 452)
PASS: ompd-test :: openmp_examples/fibonacci.c (447 of 452)
UNSUPPORTED: ompd-test :: openmp_examples/ompd_parallel.c (448 of 452)
PASS: ompd-test :: openmp_examples/parallel.c (449 of 452)
PASS: ompd-test :: openmp_examples/nested.c (450 of 452)
PASS: ompd-test :: openmp_examples/ompd_icvs.c (451 of 452)
command timed out: 1200 seconds without output running [b'ninja', b'-j 4', b'check-openmp'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1315.180381

@tstellar
Copy link
Collaborator

tstellar commented Apr 1, 2025

/cherry-pick e57cd10

@llvmbot
Copy link
Member

llvmbot commented Apr 1, 2025

/pull-request #133996

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Apr 1, 2025
swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Apr 1, 2025
While building llvm (clang, lld) against emscripten we see this
[error](https://github.com/emscripten-forge/recipes/actions/runs/13803029307/job/38608794602#step:9:1715)

```
 │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9:
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI'
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       | ^
 │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator
 │ │   192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str);
 │ │       |                   ^
 ```

Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see [llvm/Support/Compiler.h](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L206-L210), the condition only checked for the platform __WASM__ . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI.

The successful build after using this patch can be seen [here](https://github.com/emscripten-forge/recipes/actions/runs/13805214092/job/38614585621)

(cherry picked from commit e57cd10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category llvm:support
Projects
Development

Successfully merging this pull request may close these issues.

6 participants