[Openmp-commits] [llvm] [openmp] [openmp][wasm] Allow compiling OpenMP to WebAssembly (PR #71297)

via Openmp-commits openmp-commits at lists.llvm.org
Tue Jun 11 13:29:34 PDT 2024


================
@@ -4982,10 +4982,13 @@ OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
     // variable for possibly changing that to internal or private, or maybe
     // create different versions of the function for different OMP internal
     // variables.
-    auto *GV = new GlobalVariable(
-        M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
-        Constant::getNullValue(Ty), Elem.first(),
-        /*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
+    auto Linkage = this->M.getTargetTriple().rfind("wasm32") == 0
+                       ? GlobalValue::ExternalLinkage
+                       : GlobalValue::CommonLinkage;
----------------
arsnyder16 wrote:

@abrown Hey Andrew, this seems to break linking under wasm.

Previously when it externally linked it was required to define these variables through assembly, hence you updates to z_Linux_asm.S specially `.global .gomp_critical_user_.reduction.var` are actually no longer required. 

But now that they are common linkage they suffer from duplicate symbol problem.

For critical sections this can avoided if you manually add a name to the critical section that does not conflict 
`omp critical(UniqueValue)`

but for reduction allowing them to be named is not an option, so if multiple compilation units use reduction you will introduce a duplicate symbols

```
wasm-ld: error: duplicate symbol: .gomp_critical_user_.reduction.var
>>> defined in lib/libTest.a(a.cpp.o)
>>> defined in lib/libTest.a(b.cpp.o)
```

I am wonder if something like `InternalLinkage` is more appropriate

https://github.com/llvm/llvm-project/pull/71297


More information about the Openmp-commits mailing list