How to use LLVM intrinsics on a UEFI x64 target?

KytoDragon kytodragon at
Mon Aug 10 08:30:52 UTC 2020

I am currently writing an UEFI application and ran into the 
problem that using the llvm_cos and llvm_sin intrinsics results 
in an undefined symbol during linking as they are just replaced 
with call to C's cosf and sinf.

Reduced test:

import ldc.intrinsics;

extern(C) export __gshared int _fltused = 0;

extern(Windows) void efi_main() {
     float a = llvm_cos(0.5f);
     double b = llvm_sin(0.5);

compiled with

-mtriple=x86_64-windows-coff -defaultlib= -debuglib= 
-code-model=large -betterC
-L/entry:efi_main -L/dll -L/subsystem:EFI_APPLICATION 

results in

lld-link: error: undefined symbol: cosf
  referenced by D_Test\source\app.d:5

lld-link: error: undefined symbol: sin
  referenced by D_Test\source\app.d:6
Error: linking with LLD failed
ldc2 failed with exit code 1.

How can i tell LDC that my target does not have a C standard 
library? I tried to use the target triple x86_64-none-coff but 
that is not accepted by LLVM:

LLVM ERROR: Cannot initialize MC for non-Windows COFF object 
ldc2 failed with exit code 1.

Interestingly sqrt works fine.

More information about the digitalmars-d-ldc mailing list