SPARC64's crt1.o is wrongly compiled with -fPIC

Bug #1990335 reported by Rui Ueyama
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cross-toolchain-base-ports (Ubuntu)
New
Undecided
Unassigned

Bug Description

Ubuntu 22's libc6-dev-sparc64-cross package (version 2.35-0ubuntu3cross4) seems to contain a mis-configured crt1.o file. It looks like the file was wrongly compiled with -fPIC option. As a result, you can only cross-build position-independent executables for SPARC64.

  $ sparc64-linux-gnu-gcc-12 -o hello hello.c -fPIC -pie
  $ qemu-sparc64 -L /usr/sparc64-linux-gnu ./hello
  Hello world

  $ sparc64-linux-gnu-gcc-12 -o hello hello.c -fno-PIC -no-pie
  $ qemu-sparc64 -L /usr/sparc64-linux-gnu ./hello
  Illegal instruction (core dumped)

Here is the content of the correct crt1.o file (taken from Debian):

  $ sparc64-linux-gnu-objdump -dr /usr/sparc64-linux-gnu/lib/crt1.o
  /usr/sparc64-linux-gnu/lib/crt1.o: file format elf64-sparc
  Disassembly of section .text:

  0000000000000000 <_start>:
     0: bc 10 00 00 mov %g0, %fp
     4: 9c 23 a0 30 sub %sp, 0x30, %sp
     8: d2 5b a8 af ldx [ %sp + 0x8af ], %o1
     c: 94 03 a8 b7 add %sp, 0x8b7, %o2
    10: 11 00 00 00 sethi %hi(0), %o0
                          10: R_SPARC_HI22 main
    14: 17 00 00 00 sethi %hi(0), %o3
                          14: R_SPARC_HI22 __libc_csu_init
    18: 19 00 00 00 sethi %hi(0), %o4
                          18: R_SPARC_HI22 __libc_csu_fini
    1c: 90 12 20 00 mov %o0, %o0
                          1c: R_SPARC_LO10 main
    20: 96 12 e0 00 mov %o3, %o3
                          20: R_SPARC_LO10 __libc_csu_init
    24: 98 13 20 00 mov %o4, %o4
                          24: R_SPARC_LO10 __libc_csu_fini
    28: 9a 10 00 01 mov %g1, %o5
    2c: 40 00 00 00 call 2c <_start+0x2c>
                          2c: R_SPARC_WDISP30 __libc_start_main
    30: 01 00 00 00 nop
    34: 00 00 00 00 illtrap 0

This is a dump of Ubuntu's bad crt1.o file.

  $ sparc64-linux-gnu-objdump -dr /usr/sparc64-linux-gnu/lib/crt1.o
  /usr/sparc64-linux-gnu/lib/crt1.o: file format elf64-sparc
  Disassembly of section .text:

  0000000000000000 <_start>:
     0: 2f 00 00 00 sethi %hi(0), %l7
                          0: R_SPARC_HI22 _GLOBAL_OFFSET_TABLE_-0x4
     4: 40 00 00 00 call 4 <_start+0x4>
                          4: R_SPARC_WDISP30 __sparc_get_pc_thunk.l7
     8: ae 15 e0 00 mov %l7, %l7 ! 0 <_start>
                          8: R_SPARC_LO10 _GLOBAL_OFFSET_TABLE_+0x4
     c: bc 10 00 00 mov %g0, %fp
    10: 9c 23 a0 30 sub %sp, 0x30, %sp
    14: d2 5b a8 af ldx [ %sp + 0x8af ], %o1
    18: 94 03 a8 b7 add %sp, 0x8b7, %o2
    1c: 11 00 00 00 sethi %hi(0), %o0
                          1c: R_SPARC_GOTDATA_OP_HIX22 main
    20: 90 1a 20 00 xor %o0, 0, %o0
                          20: R_SPARC_GOTDATA_OP_LOX10 main
    24: d0 5d c0 08 ldx [ %l7 + %o0 ], %o0
                          24: R_SPARC_GOTDATA_OP main
    28: 96 10 20 00 clr %o3
    2c: 98 10 20 00 clr %o4
    30: 9a 10 00 01 mov %g1, %o5
    34: 40 00 00 00 call 34 <_start+0x34>
                          34: R_SPARC_WDISP30 __libc_start_main
    38: 01 00 00 00 nop
    3c: 00 00 00 00 illtrap 0

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.