================
@@ -179,8 +179,16 @@ class CGObjCGNU : public CGObjCRuntime {
(R.getVersion() >= VersionTuple(major, minor));
}
- std::string ManglePublicSymbol(StringRef Name) {
- return (StringRef(CGM.getTriple().isOSBinFormatCOFF() ? "$_" : "._") +
Name).str();
+ const std::string ManglePublicSymbol(StringRef Name) {
+ StringRef prefix = "._";
+
+ // Exported symbols in Emscripten must be a valid Javascript identifier.
+ auto triple = CGM.getTriple();
+ if (triple.isOSBinFormatCOFF() || triple.isOSBinFormatWasm()) {
----------------
hmelder wrote:
> The restriction on valid JS identifiers is specific to Emscripten rather than
> wasm as a whole, so you might want to check for isOSEmscripten here rather
> than the bin format. But if you want to have a common ABI across Emscripten
> and WASI, then this would be OK with me too.
I think it does not _really_ matter whether we use `$` or `.` and I would
prefer to not add more complexity into the conditional.
> We should maybe fix emscripten to deal with these symbols instead of patching
> here?
> [...]
> So this change would just mean that symbol are that not valid JS symbol names
> would not be accessible via the first method... which is an odd difference
> but maybe better than "link failure" ?
We mangle the symbols so that they are not directly usable by the user in a C
program, or at least this was the original intend with `.` on ELF. AFAIK there
is an extension that allows `$` to be used in a C identifier which is why
Emscripten supports it in the first place.
You _can_ change this in Emscripten but it does not really matter for our use
case.
https://github.com/llvm/llvm-project/pull/169043
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits