(original) (raw)

Hi Rui, Peter,

You know I’m enabling the “clang-cl + lld-link” toolchain for Uefi firmware. I meet a problem that the lld-link fails to link 32bits assembly functions, but can link 64bits assembly functions successfully. I need your suggestion.

Below is an example to show my problem in linux. The example has two only source files: main.c and foo.nasm.

$ cat main.c

void Foo (void);

int main()

{

Foo();

return 0;

}

$ cat foo.nasm

SECTION .text

global Foo

Foo:

Ret

64bits compiling and linking is successful:

$ nasm foo.nasm -Ox -f win64 \-g -o foo.obj

$ \~/llvm/releaseinstall/bin/clang-cl main.c /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2s /EHs-c- /GR- /GF /Gy /Zi /Gw -m64

$ \~/llvm/releaseinstall/bin/lld-link main.obj foo.obj /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /DLL /ENTRY:main /SUBSYSTEM:EFI\_BOOT\_SERVICE\_DRIVER /SAFESEH:NO /BASE:0 /DRIVER: /DEBUG:GHASH /Machine:X64

But 32bits linking fails with error of Foo assembly function is a undefined symbol:

$ nasm foo.nasm -Ox -f win32 \-g -o foo.obj

$ \~/llvm/releaseinstall/bin/clang-cl main.c /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1b2 /EHs-c- /GR- /GF /Gy /Zi /Gw -m32

$ \~/llvm/releaseinstall/bin/lld-link main.obj foo.obj /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /DLL /ENTRY:main /SUBSYSTEM:EFI\_BOOT\_SERVICE\_DRIVER /SAFESEH:NO /BASE:0 /DRIVER: /DEBUG:GHASH /MACHINE:X86

lld-link: error: undefined symbol: \_Foo

>>> referenced by /home/jshi19/llvm/wrongcode/lld-link/main.c:4

>>> main.obj:(\_main)

BTW, I find the lld-link does not suppor the /MAP option to generate mapfile. If I hope to output the linking mapfile info, what option should I use?

Thanks

Steven