From da02107a39f3eff5e0b6d6321da4e88f9564350a Mon Sep 17 00:00:00 2001 From: Jim Wilson Date: Mon, 4 Dec 2017 17:37:55 -0800 Subject: [PATCH] Riscv shared libraries should not export __global_pointer$. ld/ * emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Mark __global_pointer$ as HIDDEN. * testsuite/ld-riscv-elf/gp-hidden-64.rd: New. * testsuite/ld-riscv-elf/gp-hidden-lib.rd: New. * testsuite/ld-riscv-elf/gp-hidden-lib.s: New. * testsuite/ld-riscv-elf/gp-hidden-ver-64.rd: New. * testsuite/ld-riscv-elf/gp-hidden-ver.rd: New. * testsuite/ld-riscv-elf/gp-hidden-ver.s: New. * testsuite/ld-riscv-elf/gp-hidder-ver.ver: New. * testsuite/ld-riscv-elf/gp-hidden.rd: New. * testsuite/ld-riscv-elf/gp-hidden.s: New. * testsuite/ld-riscv-elf/gp-hidden.sd: New. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Change riscv to riscv*. Run the new tests with run_ld_link_tests. --- ld/ChangeLog | 17 ++++++++++++++ ld/emulparams/elf32lriscv-defs.sh | 2 +- ld/testsuite/ld-riscv-elf/gp-hidden-64.rd | 4 ++++ ld/testsuite/ld-riscv-elf/gp-hidden-lib.rd | 5 ++++ ld/testsuite/ld-riscv-elf/gp-hidden-lib.s | 6 +++++ ld/testsuite/ld-riscv-elf/gp-hidden-ver-64.rd | 6 +++++ ld/testsuite/ld-riscv-elf/gp-hidden-ver.rd | 6 +++++ ld/testsuite/ld-riscv-elf/gp-hidden-ver.s | 7 ++++++ ld/testsuite/ld-riscv-elf/gp-hidden-ver.ver | 1 + ld/testsuite/ld-riscv-elf/gp-hidden.rd | 4 ++++ ld/testsuite/ld-riscv-elf/gp-hidden.s | 7 ++++++ ld/testsuite/ld-riscv-elf/gp-hidden.sd | 9 +++++++ ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 34 ++++++++++++++++++++++++++- 13 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-64.rd create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-lib.rd create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-lib.s create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-ver-64.rd create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-ver.rd create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-ver.s create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden-ver.ver create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden.rd create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden.s create mode 100644 ld/testsuite/ld-riscv-elf/gp-hidden.sd diff --git a/ld/ChangeLog b/ld/ChangeLog index 6b0e026..69384d8 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,20 @@ +2017-12-04 Jim Wilson + + * emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Mark + __global_pointer$ as HIDDEN. + * testsuite/ld-riscv-elf/gp-hidden-64.rd: New. + * testsuite/ld-riscv-elf/gp-hidden-lib.rd: New. + * testsuite/ld-riscv-elf/gp-hidden-lib.s: New. + * testsuite/ld-riscv-elf/gp-hidden-ver-64.rd: New. + * testsuite/ld-riscv-elf/gp-hidden-ver.rd: New. + * testsuite/ld-riscv-elf/gp-hidden-ver.s: New. + * testsuite/ld-riscv-elf/gp-hidder-ver.ver: New. + * testsuite/ld-riscv-elf/gp-hidden.rd: New. + * testsuite/ld-riscv-elf/gp-hidden.s: New. + * testsuite/ld-riscv-elf/gp-hidden.sd: New. + * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Change riscv to riscv*. + Run the new tests with run_ld_link_tests. + 2017-12-04 Alan Modra * testsuite/ld-i386/pr17935-1.d: Adjust expected error. diff --git a/ld/emulparams/elf32lriscv-defs.sh b/ld/emulparams/elf32lriscv-defs.sh index ab80333..5b41d5c 100644 --- a/ld/emulparams/elf32lriscv-defs.sh +++ b/ld/emulparams/elf32lriscv-defs.sh @@ -23,7 +23,7 @@ TEXT_START_ADDR=0x10000 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)" COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)" -SDATA_START_SYMBOLS="__global_pointer$ = . + 0x800; +SDATA_START_SYMBOLS="HIDDEN (__global_pointer$ = . + 0x800); *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*)" INITIAL_READONLY_SECTIONS=".interp : { *(.interp) } ${CREATE_PIE-${INITIAL_READONLY_SECTIONS}}" diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-64.rd b/ld/testsuite/ld-riscv-elf/gp-hidden-64.rd new file mode 100644 index 0000000..aaaec93 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-64.rd @@ -0,0 +1,4 @@ + +Relocation section '\.rela\.dyn' at offset .* contains 1 entry: + *Offset * Info * Type * Sym\. *Value * Sym\. *Name \+ Addend +[0-9a-f]+ * [0-9a-f]+02 * R_RISCV_64 * [0-9a-f]+ * foo \+ 0 diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-lib.rd b/ld/testsuite/ld-riscv-elf/gp-hidden-lib.rd new file mode 100644 index 0000000..59b4442 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-lib.rd @@ -0,0 +1,5 @@ + +Relocation section '\.rela\.dyn' at offset .* contains 1 entry: + *Offset * Info * Type * Sym\. *Value * Sym\. *Name \+ Addend +# This must be an absolute relocation, there must not be a _gp reference. +[0-9a-f]+ * 0+03 * R_RISCV_RELATIVE * [0-9a-f]+ diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-lib.s b/ld/testsuite/ld-riscv-elf/gp-hidden-lib.s new file mode 100644 index 0000000..04f0655 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-lib.s @@ -0,0 +1,6 @@ + .data + .globl bar + .type bar, @object +bar: + .dc.a __global_pointer$ + .size bar, . - bar diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-ver-64.rd b/ld/testsuite/ld-riscv-elf/gp-hidden-ver-64.rd new file mode 100644 index 0000000..57cb13f --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-ver-64.rd @@ -0,0 +1,6 @@ + +Relocation section '\.rela\.dyn' at offset .* contains 2 entries: + *Offset * Info * Type * Sym\. *Value * Sym\. *Name \+ Addend +# This must be an absolute relocation, there must not be a _gp reference. +[0-9a-f]+ * 0+03 * R_RISCV_RELATIVE * [0-9a-f]+ +[0-9a-f]+ * [0-9a-f]+02 * R_RISCV_64 * [0-9a-f]+ * bar \+ 0 diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-ver.rd b/ld/testsuite/ld-riscv-elf/gp-hidden-ver.rd new file mode 100644 index 0000000..dbed24f --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-ver.rd @@ -0,0 +1,6 @@ + +Relocation section '\.rela\.dyn' at offset .* contains 2 entries: + *Offset * Info * Type * Sym\. *Value * Sym\. *Name \+ Addend +# This must be an absolute relocation, there must not be a _gp reference. +[0-9a-f]+ * 0+03 * R_RISCV_RELATIVE * [0-9a-f]+ +[0-9a-f]+ * [0-9a-f]+01 * R_RISCV_32 * [0-9a-f]+ * bar \+ 0 diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-ver.s b/ld/testsuite/ld-riscv-elf/gp-hidden-ver.s new file mode 100644 index 0000000..a197bac --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-ver.s @@ -0,0 +1,7 @@ + .data + .globl foo + .type foo, @object +foo: + .dc.a bar + .dc.a __global_pointer$ + .size foo, . - foo diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden-ver.ver b/ld/testsuite/ld-riscv-elf/gp-hidden-ver.ver new file mode 100644 index 0000000..b6b2365 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden-ver.ver @@ -0,0 +1 @@ +{ global: foo; local: *; }; diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden.rd b/ld/testsuite/ld-riscv-elf/gp-hidden.rd new file mode 100644 index 0000000..dc29f7d --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden.rd @@ -0,0 +1,4 @@ + +Relocation section '\.rela\.dyn' at offset .* contains 1 entry: + *Offset * Info * Type * Sym\. *Value * Sym\. *Name \+ Addend +[0-9a-f]+ * [0-9a-f]+01 * R_RISCV_32 * [0-9a-f]+ * foo \+ 0 diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden.s b/ld/testsuite/ld-riscv-elf/gp-hidden.s new file mode 100644 index 0000000..18d3ca3 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden.s @@ -0,0 +1,7 @@ + .data + .globl blah + .type blah, @object +blah: + .dc.a foo + .dc.a __global_pointer$ + .size blah, . - blah diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden.sd b/ld/testsuite/ld-riscv-elf/gp-hidden.sd new file mode 100644 index 0000000..f4321c2 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/gp-hidden.sd @@ -0,0 +1,9 @@ + +Symbol table '.dynsym' contains [0-9]+ entries: + * Num: * Value * Size * Type * Bind * Vis * Ndx * Name +#... +Symbol table '.symtab' contains [0-9]+ entries: + * Num: * Value * Size * Type * Bind * Vis * Ndx * Name +#... + * [0-9a-f]+: * [0-9a-f]+ * 0 * NOTYPE * LOCAL * DEFAULT .* __global_pointer\$ +#pass diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp index c219b18..9f5959c 100644 --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp @@ -19,6 +19,38 @@ # MA 02110-1301, USA. # -if [istarget "riscv-*-*"] { +if [istarget "riscv*-*-*"] { run_dump_test "c-lui" + + set abis { rv32gc ilp32 elf32lriscv rv64gc lp64 elf64lriscv } + foreach { arch abi emul } $abis { + # This checks whether our linker scripts get the scope of + # __global_pointer$ right, and thus must therefore use default scripts. + set suff64 [string map {ilp32 "" lp64 -64} $abi] + run_ld_link_tests [list \ + [list "gp scope test ($abi shared library)" \ + "-m$emul -shared" "" \ + "-march=$arch -mabi=$abi -fpic" \ + { gp-hidden-lib.s } \ + [list \ + "readelf --relocs gp-hidden-lib.rd" \ + "readelf --syms gp-hidden.sd"] \ + "gp-hidden-lib-${abi}.so"] \ + [list "gp scope test ($abi versioned lib)" \ + "-m$emul -shared -version-script gp-hidden-ver.ver tmpdir/gp-hidden-lib-${abi}.so" "" \ + "-march=$arch -mabi=$abi -fpic" \ + { gp-hidden-ver.s } \ + [list \ + "readelf --relocs gp-hidden-ver${suff64}.rd" \ + "readelf --syms gp-hidden.sd"] \ + "gp-hidden-ver-${abi}.so"] \ + [list "gp scope test ($abi executable)" \ + "-m$emul -e 0 -rpath-link . tmpdir/gp-hidden-ver-${abi}.so" "" \ + "-march=$arch -mabi=$abi" \ + {gp-hidden.s} \ + [list \ + "readelf --relocs gp-hidden${suff64}.rd" \ + "readelf --syms gp-hidden.sd"]\ + "gp-hidden-${abi}"]] + } } -- 2.7.4