https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119894

            Bug ID: 119894
           Summary: -fno-PIC -Os on loongarch creates code incompatible
                    with plts
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: phcoder at gmail dot com
  Target Milestone: ---

Created attachment 61170
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61170&action=edit
Test program

When compiling test program (attached) as loongarch64-linux-gnu-gcc  -Os -g
-shared -o misc.so misc.c  -nostdlib -fno-PIC. We get the following code:

 364:   57ff8fff        bl              -116    # 2f0 <grub_divmod64@plt>
/home/phcoder/grub-extras/misc.c:50
 368:   28c0206c        ld.d            $t0, $sp, 8
 36c:   02c005ef        addi.d          $t3, $t3, 1

So gcc relies on grub_divmod64@plt to preserve $t3. $t3 is preserved in
generated code of grub_divmod64 but insertion of PLT by the linker throws
things off as plt has following code:
 2f0:   1c00010f        pcaddu12i       $t3, 8
 2f4:   28f441ef        ld.d            $t3, $t3, -752
 2f8:   4c0001ed        jirl            $t1, $t3, 0

As per ABI specification $t3 is caller-preserved so gcc needs to take insertion
of PLTs into account when reusing the registers.

Reply via email to