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

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 (ASMPFX) for wrapping the underscore. We use the USERLABELPREFIX to control the prefix macro expand to be "" as below. I find the USERLABELPREFIX 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 USERLABELPREFIX 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 "" 1

1 "" 3

331 "" 3

1 "" 1

1 "" 2

1 "userprefix.c" 2

_ $ bin/clang-cl -E userprefix.c

1 "userprefix.c"

1 "" 1

1 "" 3

334 "" 3

1 "" 1

1 "" 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