dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.44k stars 201 forks source link

[NativeAOT-LLVM] Symbol clashes are not very difficult to encounter #2817

Open yowl opened 2 days ago

yowl commented 2 days ago

If you want to link to some c code with a name that is already used, e.g.

int CloseHandle (
    void* hObject)
{
    return pFuncs->pCloseHandle(hObject);
};

You hit

wasm-ld: error: duplicate symbol: CloseHandle
>>> defined in C:/git/CMSDevA/src/packages/runtime.browser-wasm.microsoft.dotnet.ilcompiler.llvm/10.0.0-dev/sdk/libPortableRuntime.a(PalRedhawkUnix.cpp.o)
>>> defined in C:\\git\\CMSDevA\\lib\\Xpf\\Others\\Others\\AvaloniaUI.Xpf.WinApiShim.Native.o

(from Discord https://discord.com/channels/143867839282020352/1141126727028985877/1312127937109299412)

jkotas commented 1 day ago

This is not Wasm-specific issue. It applies to linking custom code native AOT on all non-Windows architectures. E.g. if somebody creates a Windows API shims for Linux and tries to link them into Native AOT app, they are going to hit the same collision.

NAOT runtime tries to avoid these sort of name collisions by using Rh or Pal prefix, but this pattern is not followed everywhere. CloseHandle should not really exist in non-Windows NAOT runtime at all.