Browse Source
The non-preemptible SHN_ABS symbol with a pc-relative relocation should be
disallowed when generating shared object (pic and pie). Generally, the
following cases, which refer to pr25749, will cause a symbol be
non-preemptible,
* -pie, or -shared with -symbolic
* STV_HIDDEN, STV_INTERNAL, STV_PROTECTED
* Have dynamic symbol table, but without the symbol
* VER_NDX_LOCAL
However, PCREL_HI20/LO12 relocs are always bind locally when generating
shared object, so not only the non-preemptible absolute symbol need to
be disallowed, all absolute symbol references need but except that they
are defined in linker script. If we also disallow the absolute symbol
in linker script, then the glibc-linux toolchain build failed, so regard
them as pc-relative symbols, just like what x86 did.
Maybe we should add this check for all pc-relative relocations, rather
than just handle in R_RISCV_PCREL relocs. Ideally, since the value of
SHN_ABS symbol is a constant, only S - A relocations should be allowed
in the shared object, so only BFD_RELOC_8/16/32/64 are allowed, which
means R_RISCV_32/R_RISCV_64.
bfd/
PR 28789
* elfnn-riscv.c (riscv_elf_check_relocs): The absolute symbol cannot be
referneced with pc-relative relocation when generating shared object.
ld/
PR 28789
* ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
* ld/testsuite/ld-riscv-elf/pcrel-reloc*: New testcases.
users/aburgess/try-core-file-pid0
committed by
Nelson Chu
9 changed files with 111 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||
#source: pcrel-reloc.s |
|||
#source: pcrel-reloc-abs.s |
|||
#as: -march=rv64i -mabi=lp64 |
|||
#ld: -melf64lriscv --no-pie --no-relax |
|||
#objdump: -d |
|||
|
|||
.*:[ ]+file format .* |
|||
|
|||
Disassembly of section \.text: |
|||
|
|||
[0-9a-f]+ <_start>: |
|||
.*auipc.* |
|||
.*lw.*# [0-9a-f]* <sym> |
|||
#pass |
|||
@ -0,0 +1,5 @@ |
|||
#source: pcrel-reloc.s |
|||
#source: pcrel-reloc-abs.s |
|||
#as: -march=rv64i -mabi=lp64 |
|||
#ld: -melf64lriscv --pie --no-relax |
|||
#error: .*relocation R_RISCV_PCREL_HI20 against absolute symbol `sym' can not be used when making a shared objec.*t |
|||
@ -0,0 +1,2 @@ |
|||
.global sym |
|||
.set sym,0x8000 |
|||
@ -0,0 +1,14 @@ |
|||
#source: pcrel-reloc.s |
|||
#source: pcrel-reloc-rel.s |
|||
#as: -march=rv64i -mabi=lp64 |
|||
#ld: -melf64lriscv --no-pie --no-relax |
|||
#objdump: -d |
|||
|
|||
.*:[ ]+file format .* |
|||
|
|||
Disassembly of section \.text: |
|||
|
|||
[0-9a-f]+ <_start>: |
|||
.*auipc.* |
|||
.*lw.*# [0-9a-f]* <sym> |
|||
#pass |
|||
@ -0,0 +1,14 @@ |
|||
#source: pcrel-reloc.s |
|||
#source: pcrel-reloc-rel.s |
|||
#as: -march=rv64i -mabi=lp64 |
|||
#ld: -melf64lriscv --pie --no-relax |
|||
#objdump: -d |
|||
|
|||
.*:[ ]+file format .* |
|||
|
|||
Disassembly of section \.text: |
|||
|
|||
[0-9a-f]+ <_start>: |
|||
.*auipc.* |
|||
.*lw.*# [0-9a-f]* <sym> |
|||
#pass |
|||
@ -0,0 +1,9 @@ |
|||
.data |
|||
# Makes sure "sym" doesn't end up at the beginning of ".data", as that makes it |
|||
# tough to then later detect it from scripts. |
|||
.global buf |
|||
buf: |
|||
.fill 8192, 4, 1 |
|||
.global sym |
|||
sym: |
|||
.fill 8192, 4, 2 |
|||
@ -0,0 +1,5 @@ |
|||
.text |
|||
.global _start |
|||
_start: |
|||
auipc t0, %pcrel_hi(sym) |
|||
lw t0, %pcrel_lo(_start)(t0) |
|||
Loading…
Reference in new issue