bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/25694] New: R_RISCV_TPREL_HI20 relocations cause riscv64 to add


From: slyfox at inbox dot ru
Subject: [Bug ld/25694] New: R_RISCV_TPREL_HI20 relocations cause riscv64 to add TEXTREL bit on executables
Date: Wed, 18 Mar 2020 22:28:27 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=25694

            Bug ID: 25694
           Summary: R_RISCV_TPREL_HI20 relocations cause riscv64 to add
                    TEXTREL bit on executables
           Product: binutils
           Version: 2.34
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: slyfox at inbox dot ru
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: riscv64-unknown-linux-gnu
             Build: x86_64-pc-linux-gnu

Initial bug is reported as a https://bugs.gentoo.org/713082 where gdb-9.1 was
observed to be complied with TEXTRELs. Here is the minimal reproducer:

// $ cat a.cc
static int a () { return 1; }

static thread_local int (*tlf) () = &a;

int main(void) { return tlf(); }
[sf] /tmp/z:cat a.cc
static int a () { return 1; }

static thread_local int (*tlf) () = &a;

int main(void) { return tlf(); }

$ riscv64-unknown-linux-gnu-g++ a.cc -o a -Wl,-z,text -pie -fPIE
/usr/libexec/gcc/riscv64-unknown-linux-gnu/ld: read-only segment has dynamic
relocations
collect2: error: ld returned 1 exit status

$ riscv64-unknown-linux-gnu-g++ -S a.cc -o a.S -Wl,-z,text -pie -fPIE
$ cat a.S
...
main:
...
        lui     a5,%tprel_hi(_ZL3tlf)
        add     a5,a5,tp,%tprel_add(_ZL3tlf)
        ld      a5,%tprel_lo(_ZL3tlf)(a5)
        jalr    a5
...


I assume it's a binutils deficiency as I see no relocations in read-only
sections:

$ riscv64-unknown-linux-gnu-g++ a.cc -o a -pie -fPIE
/usr/libexec/gcc/riscv64-unknown-linux-gnu/ld: warning: creating a DT_TEXTREL
in object
$ LANG=C objdump -D -R a | egrep 'R_RISC|section ' | egrep -A2 'section '
Disassembly of section .interp:
Disassembly of section .note.ABI-tag:
Disassembly of section .gnu.hash:
Disassembly of section .dynsym:
Disassembly of section .dynstr:
Disassembly of section .gnu.version:
Disassembly of section .gnu.version_r:
Disassembly of section .rela.dyn:
Disassembly of section .rela.plt:
Disassembly of section .plt:
Disassembly of section .text:
Disassembly of section .rodata:
Disassembly of section .eh_frame_hdr:
Disassembly of section .eh_frame:
Disassembly of section .tdata:
                        1da0: R_RISCV_RELATIVE  *ABS*+0x72a
Disassembly of section .preinit_array:
                        1da8: R_RISCV_RELATIVE  *ABS*+0x68e
Disassembly of section .init_array:
                        1db0: R_RISCV_RELATIVE  *ABS*+0x728
Disassembly of section .fini_array:
                        1db8: R_RISCV_RELATIVE  *ABS*+0x6ee
Disassembly of section .dynamic:
Disassembly of section .data:
                        2000: R_RISCV_RELATIVE  *ABS*+0x2000
Disassembly of section .got:
                        2018: R_RISCV_JUMP_SLOT __libc_start_main@GLIBC_2.27
                        2020: R_RISCV_JUMP_SLOT __stack_chk_fail@GLIBC_2.27
--
Disassembly of section .bss:
Disassembly of section .comment:
                        0: R_RISCV_NONE *ABS*


riscv_elf_check_relocs() is probably too conservative at attributing
thread_local relocations in PIEs as TEXTRELs.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]