Browse Source
When generating the shared object, the default visibility symbols may bind
externally, which means they will be exported to the dynamic symbol table,
and are preemptible by default. These symbols cannot be referenced by the
non-pic R_RISCV_JAL and R_RISCV_RVC_JUMP. However, consider that linker
may relax the R_RISCV_CALL relocations to R_RISCV_JAL or R_RISCV_RVC_JUMP,
if these relocations are relocated to the plt entries, then we won't report
error for them. Perhaps we also need the similar checks for the
R_RISCV_BRANCH and R_RISCV_RVC_BRANCH relocations.
After applying this patch, and revert the following glibc patch,
riscv: Fix incorrect jal with HIDDEN_JUMPTARGET
https://sourceware.org/git/?p=glibc.git;a=commit;h=68389203832ab39dd0dbaabbc4059e7fff51c29b
I get the expected errors as follows,
ld: relocation R_RISCV_RVC_JUMP against `__sigsetjmp' which may bind externally can not be used when making a shared object; recompile with -fPIC
ld: relocation R_RISCV_JAL against `exit' which may bind externally can not be used when making a shared object; recompile with -fPIC
Besides, we also have similar changes for libgcc,
RISC-V: jal cannot refer to a default visibility symbol for shared object
45116f3420
bfd/
pr 28509
* elfnn-riscv.c (riscv_elf_relocate_section): Report errors when
makeing a shard object, and the referenced symbols of R_RISCV_JAL
relocations are default visibility. Besides, we should handle most
of the cases here, so don't need the unresolvable check later for
R_RISCV_JAL and R_RISCV_RVC_JUMP.
ld/
pr 28509
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
* testsuite/ld-riscv-elf/lib-nopic-01a.s: Removed.
* testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise.
* testsuite/ld-riscv-elf/lib-nopic-01b.s: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-01.d: New testcase.
* testsuite/ld-riscv-elf/shared-lib-nopic-01.s: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-02.d: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-02.s: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-03.d: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-03.s: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-04.d: Likewise.
* testsuite/ld-riscv-elf/shared-lib-nopic-04.s: Likewise.
users/aburgess/try-mips-disasm-styling
13 changed files with 126 additions and 57 deletions
@ -1,9 +0,0 @@ |
|||
.option nopic |
|||
.text |
|||
.align 1 |
|||
.globl func1 |
|||
.type func1, @function |
|||
func1: |
|||
jal func2 |
|||
jr ra |
|||
.size func1, .-func1 |
|||
@ -1,5 +0,0 @@ |
|||
#name: link non-pic code into a shared library |
|||
#source: lib-nopic-01b.s |
|||
#as: |
|||
#ld: -shared tmpdir/lib-nopic-01a.so |
|||
#error: .*relocation R_RISCV_JAL against `func1' can not be used when making a shared object; recompile with -fPIC |
|||
@ -1,9 +0,0 @@ |
|||
.option nopic |
|||
.text |
|||
.align 1 |
|||
.globl func2 |
|||
.type func2, @function |
|||
func2: |
|||
jal func1 |
|||
jr ra |
|||
.size func2, .-func2 |
|||
@ -0,0 +1,4 @@ |
|||
#source: shared-lib-nopic-01.s |
|||
#as: |
|||
#ld: -shared |
|||
#error: .*relocation R_RISCV_JAL against `foo' which may bind externally can not be used when making a shared object; recompile with -fPIC |
|||
@ -0,0 +1,3 @@ |
|||
.option nopic |
|||
.text |
|||
jal foo # undefined |
|||
@ -0,0 +1,4 @@ |
|||
#source: shared-lib-nopic-02.s |
|||
#as: |
|||
#ld: -shared |
|||
#error: .*relocation R_RISCV_JAL against `foo_default' which may bind externally can not be used when making a shared object; recompile with -fPIC |
|||
@ -0,0 +1,12 @@ |
|||
.option nopic |
|||
.text |
|||
.align 1 |
|||
|
|||
jal foo_default |
|||
|
|||
.globl foo_default |
|||
.type foo_default, @function |
|||
foo_default: |
|||
nop |
|||
ret |
|||
.size foo_default, .-foo_default |
|||
@ -0,0 +1,14 @@ |
|||
#source: shared-lib-nopic-03.s |
|||
#as: |
|||
#ld: -shared |
|||
#objdump: -d |
|||
|
|||
.*:[ ]+file format .* |
|||
|
|||
Disassembly of section \.text: |
|||
|
|||
#... |
|||
.*:[ ]+[0-9a-f]+[ ]+jal[ ]+.* <foo_default> |
|||
|
|||
0+[0-9a-f]+ <foo_default>: |
|||
#... |
|||
@ -0,0 +1,13 @@ |
|||
.option nopic |
|||
.text |
|||
.align 1 |
|||
|
|||
jal foo_default |
|||
|
|||
.globl foo_default |
|||
.hidden foo_default |
|||
.type foo_default, @function |
|||
foo_default: |
|||
nop |
|||
ret |
|||
.size foo_default, .-foo_default |
|||
@ -0,0 +1,15 @@ |
|||
#source: shared-lib-nopic-04.s |
|||
#as: |
|||
#ld: -shared |
|||
#objdump: -d |
|||
|
|||
.*:[ ]+file format .* |
|||
|
|||
#... |
|||
Disassembly of section \.text: |
|||
#... |
|||
.*:[ ]+[0-9a-f]+[ ]+jal[ ]+.* <foo_default@plt> |
|||
.*:[ ]+[0-9a-f]+[ ]+jal[ ]+.* <foo_default@plt> |
|||
|
|||
0+[0-9a-f]+ <foo_default>: |
|||
#... |
|||
@ -0,0 +1,14 @@ |
|||
.option nopic |
|||
.text |
|||
.align 1 |
|||
|
|||
call foo_default |
|||
jal foo_default |
|||
|
|||
|
|||
.globl foo_default |
|||
.type foo_default, @function |
|||
foo_default: |
|||
nop |
|||
ret |
|||
.size foo_default, .-foo_default |
|||
Loading…
Reference in new issue