[llvm-dev] lld-link fails to link 32bits assembly functions but 64bits pass

Martin Storsjö via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 18 01:07:28 PST 2019


On Mon, 18 Feb 2019, Shi, Steven wrote:

> Hi Martin,
> Thank you for the hint.
>
>> For 32 bit windows, functions with cdecl calling convention (the default
>> in C) are decorated with an underscore prefix. So you'd need to update
>> your nasm source file to define the symbol _Foo instead of Foo. (Most
>> assembly files use some sort of macro for wrapping this detail.)
> Yes, my assembly files do use prefix macro (ASM_PFX) for wrapping the 
> underscore. We use the __USER_LABEL_PREFIX__ to control the prefix macro 
> expand to be "_" as below. I find the __USER_LABEL_PREFIX__ has been 
> predefined by clang-cl, but it is defined as nothing. That is why my 
> prefix macro expands to be nothing. Do you know why the clang-cl 
> predefines the __USER_LABEL_PREFIX__ as nothing?

It looks to me like __USER_LABEL_PREFIX__ is properly defined to an 
underscore when preprocessing with clang-cl:

$ cat userprefix.c
__USER_LABEL_PREFIX__
$ bin/clang-cl -E userprefix.c -m32
# 1 "userprefix.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 331 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "userprefix.c" 2
_
$ bin/clang-cl -E userprefix.c
# 1 "userprefix.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 334 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "userprefix.c" 2

$

So as long as I specify a x86 32 bit target, __USER_LABEL_PREFIX__ expands 
correctly to an underscore. Where do you observe differing behaviour? If 
you use (clang-)cl to preprocess your assembler files, you need make sure 
you run that preprocessor with the right target.

// Martin



More information about the llvm-dev mailing list