[llvm-dev] [lld] linker script error while use "-=" on arm target

Fangrui Song via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 24 14:16:38 PDT 2021


On 2021-04-24, saito yutaka via llvm-dev wrote:
>Hello.
>
>I got link error when I try build code on arm target.
>It seems that It could'n use "-=" operation when using arm.
>The following is what we tried.
>
>$ cat sample.c
>void __init_array_start(void){};
>void __init_array_end(void){};
>int main()
>{
>     return 0;
>}
>
>$ cat sample.ld
>SECTIONS
>{
>    sample = 0;
>    sample += 1;
>    sample -= 1;
>    . = 0x08048000 + SIZEOF_HEADERS;
>    .text : {*(.text)}
>    .rodata : {*(.rodata)}
>    .data : {*(.data)}
>    .bss : {*(.bss)}
>}
>
># There is no error that build x86_64 target.
>$ clang -fPIE -target x86_64-unknown-none-elf -nodefaultlibs sample.c -T
>sample.ld
>
># But I get a error when build arm target.
>$ clang  -target arm-none-eabi -march=armv7-m -mcpu=cortex-m4
>-nodefaultlibs sample.c -T sample.ld
>ld.lld: error: sample.ld:5: malformed number: =
>>>>     sample -= 1;
>>>>             ^
>clang-12: error: ld.lld command failed with exit code 1 (use -v to see
>invocation)

-= is not supported. ld.lld only supports +=.
-= is probably too rare in the wild.

Actually changing the value of a symbol is hardly a good idea.
The evaluation order of expressions is not well defined.
Using -= or += may cause difficult-to-explain portability issues across
GNU ld and ld.lld.

># The version of clang I use using is 12.
>$ clang --version
>clang version 12.0.0 (https://github.com/llvm/llvm-project/
>b978a93635b584db380274d7c8963c73989944a1)
>Target: x86_64-unknown-linux-gnu
>Thread model: posix
>
>Is there some linker script difference depend on target?

No.


More information about the llvm-dev mailing list