MichalStrehovsky / zerosharp

Demo of the potential of C# for systems programming with the .NET native ahead-of-time compilation technology.
2k stars 103 forks source link

Issues with Linking NativeAOT (ILC) Compiled Object File for EFI Application on macOS (.NET8 RC1) #48

Open ZeroLP opened 1 year ago

ZeroLP commented 1 year ago

Hello,

I am encountering issues while trying to build and link a NativeAOT compiled object file for an EFI application on macOS. Below are the details of the problem and the steps I have taken so far:

Problem Description: I am working on a project where I need to compile C# code using ILC and link the resulting object file to create an EFI application. The development environment is macOS M1, and I am targeting the x86_64 architecture on .NET8 RC1.

Steps Taken: Compilation with ILC: I used the following command to compile the C# code using .NET Native:

csc /nologo /debug:embedded /noconfig /nostdlib /runtimemetadataversion:v4.0.30319 <source_files> /out:EFINet8Test /langversion:latest /unsafe
ilc EFINet8Test -o EFINet8Test.obj --systemmodule EFINet8Test--map EFINet8Test.map -O

Project-Level Compilation with dotnet build: I also tried defining the csc arguments at the project level in the .csproj file properties and then built the project using dotnet build to ensure that the correct C# version and .NET 8 SDK were being used. However, this did not resolve the issue.

Linking with Clang: I attempted to link the compiled object file using clang with the following command: clang -o BOOTX64.EFI -target x86_64-unknown-windows -ffreestanding -nostdlib -e EfiMain EFINet8Test.obj -fuse-ld=/usr/local/opt/llvm/bin/lld-link

However, this resulted in an "unknown file type" error, indicating that lld-link does not recognise the format of the .obj file produced by ILC.

Exploration of Alternatives:

Questions:

Any guidance, suggestions, or insights into this problem would be greatly appreciated. Thank you in advance for your help!