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

saito yutaka via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 24 20:18:06 PDT 2021


Hi

Thanks for your reply.

> The evaluation order of expressions is not well defined.
> Using -= or += may cause difficult-to-explain portability issues across
> GNU ld and ld.lld.

I didn't know that.
Thank you for the information.

Saito Yutaka

2021年4月25日(日) 6:16 Fangrui Song <maskray at google.com>:

> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210425/e8f28df0/attachment.html>


More information about the llvm-dev mailing list