Bug 23892 - ld.gold fails partial linking on sparc64 for global registers: only registers %g[2367] can be declared using STT_REGISTER
Summary: ld.gold fails partial linking on sparc64 for global registers: only registers...
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-17 14:20 UTC by Sergei Trofimovich
Modified: 2018-11-17 18:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
bug.tar.gz (847 bytes, application/gzip)
2018-11-17 14:21 UTC, Sergei Trofimovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2018-11-17 14:20:14 UTC
Initially observed as a build failure of linux kernel:
    make defconfig
    make LD=sparc64-unknown-linux-gnu-ld.gold
    ...
    sparc64-unknown-linux-gnu-ld.gold: error: drivers/char/hw_random/core.o: only registers %g[2367] can be declared using STT_REGISTER

Here is the minimal reproducer:

    $ cat bug.c
    register long a asm("g6");

    $ sparc64-unknown-linux-gnu-gcc -Wall -c -o bug0.o bug.c
    $ sparc64-unknown-linux-gnu-ld.gold -m elf64_sparc -r -o bug1-gold.o bug0.o
    $ sparc64-unknown-linux-gnu-ld.gold -m elf64_sparc -r -o bug2-gold.o bug1-gold.o
    $ sparc64-unknown-linux-gnu-ld.gold: error: bug1-gold.o: only registers %g[2367] can be declared using STT_REGISTER

Note, partial linking is very simple here as it uses single input source.
Second partial linking step should be a no-op (it is a no-op on bfd).

Attached source and emitted binaries.
Tool versions:
  binutils: 2.31.1
  gcc: 8.2.0
  target: sparc64-unknown-linux-gnu

Thanks!
Comment 1 Sergei Trofimovich 2018-11-17 14:21:17 UTC
Created attachment 11400 [details]
bug.tar.gz
Comment 2 Sergei Trofimovich 2018-11-17 18:10:03 UTC
Diffing 'objdump -x bug1-bfd.o' and 'objdump -x bug1-gold.o' shows that register number is changed:

bfd:  REG_G6           g     R *UND*  0000000000000000 a
gold: REG_G4           g     R *UND*  0000000000000000 a