Really fix riscv shared library __global_pointer$ problem.
authorJim Wilson <jimw@sifive.com>
Tue, 5 Dec 2017 22:42:12 +0000 (14:42 -0800)
committerJim Wilson <jimw@sifive.com>
Tue, 5 Dec 2017 22:42:12 +0000 (14:42 -0800)
ld/
* emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Remove HIDDEN.
Don't define __global_pointer$ when CREATE_SHLIB.
* testsuite/ld-riscv-elf/gp-hidden-64.rd,
* testsuite/ld-riscv-elf/gp-hidden-lib.rd,
* testsuite/ld-riscv-elf/gp-hidden-lib.s,
* testsuite/ld-riscv-elf/gp-hidden-ver-64.rd,
* testsuite/ld-riscv-elf/gp-hidden-ver.rd,
* testsuite/ld-riscv-elf/gp-hidden-ver.s,
* testsuite/ld-riscv-elf/gp-hidden-ver.ver,
* testsuite/ld-riscv-elf/gp-hidden.rd,
* testsuite/ld-riscv-elf/gp-hidden.s,
* testsuite/ld-riscv-elf/gp-hidden.sd: Delete.
* testsuite/ld-riscv-elf/gp-test-lib.sd,
* testsuite/ld-riscv-elf/gp-test.s,
* testsuite/ld-riscv-elf/gp-test.sd: New.
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Rewrite gp tests.

14 files changed:
ld/ChangeLog
ld/emulparams/elf32lriscv-defs.sh
ld/testsuite/ld-riscv-elf/gp-hidden-64.rd [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden-lib.rd [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden-lib.s [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden-ver-64.rd [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden-ver.rd [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden-ver.s [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden-ver.ver [deleted file]
ld/testsuite/ld-riscv-elf/gp-hidden.rd [deleted file]
ld/testsuite/ld-riscv-elf/gp-test-lib.sd [moved from ld/testsuite/ld-riscv-elf/gp-hidden.sd with 70% similarity]
ld/testsuite/ld-riscv-elf/gp-test.s [moved from ld/testsuite/ld-riscv-elf/gp-hidden.s with 65% similarity]
ld/testsuite/ld-riscv-elf/gp-test.sd [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp

index 69384d8..179d229 100644 (file)
@@ -1,3 +1,23 @@
+2017-12-05  Jim Wilson  <jimw@sifive.com>
+           Andrew Waterman  <andrew@sifive.com>
+
+       * emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Remove HIDDEN.
+       Don't define __global_pointer$ when CREATE_SHLIB.
+       * testsuite/ld-riscv-elf/gp-hidden-64.rd,
+       * testsuite/ld-riscv-elf/gp-hidden-lib.rd,
+       * testsuite/ld-riscv-elf/gp-hidden-lib.s,
+       * testsuite/ld-riscv-elf/gp-hidden-ver-64.rd,
+       * testsuite/ld-riscv-elf/gp-hidden-ver.rd,
+       * testsuite/ld-riscv-elf/gp-hidden-ver.s,
+       * testsuite/ld-riscv-elf/gp-hidden-ver.ver,
+       * testsuite/ld-riscv-elf/gp-hidden.rd,
+       * testsuite/ld-riscv-elf/gp-hidden.s,
+       * testsuite/ld-riscv-elf/gp-hidden.sd: Delete.
+       * testsuite/ld-riscv-elf/gp-test-lib.sd,
+       * testsuite/ld-riscv-elf/gp-test.s,
+       * testsuite/ld-riscv-elf/gp-test.sd: New.
+       * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Rewrite gp tests.
+
 2017-12-04  Jim Wilson  <jimw@sifive.com>
 
        * emulparams/elf32lriscv-defs.sh (SDATA_START_SYMBOLS): Mark
index 5b41d5c..29ed6d8 100644 (file)
@@ -23,7 +23,8 @@ TEXT_START_ADDR=0x10000
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
 
-SDATA_START_SYMBOLS="HIDDEN (__global_pointer$ = . + 0x800);
+SDATA_START_SYMBOLS="__global_pointer$ = . + 0x800;"
+SDATA_START_SYMBOLS="${CREATE_SHLIB-${SDATA_START_SYMBOLS}}
     *(.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
deleted file mode 100644 (file)
index aaaec93..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-
-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
deleted file mode 100644 (file)
index 59b4442..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-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
deleted file mode 100644 (file)
index 04f0655..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-       .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
deleted file mode 100644 (file)
index 57cb13f..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-
-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
deleted file mode 100644 (file)
index dbed24f..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-
-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
deleted file mode 100644 (file)
index a197bac..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-       .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
deleted file mode 100644 (file)
index b6b2365..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{ global: foo; local: *; };
diff --git a/ld/testsuite/ld-riscv-elf/gp-hidden.rd b/ld/testsuite/ld-riscv-elf/gp-hidden.rd
deleted file mode 100644 (file)
index dc29f7d..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-
-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
similarity index 70%
rename from ld/testsuite/ld-riscv-elf/gp-hidden.sd
rename to ld/testsuite/ld-riscv-elf/gp-test-lib.sd
index f4321c2..c590e6c 100644 (file)
@@ -1,9 +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
+#failif
+#...
+ * [0-9a-f]+: * [0-9a-f]+ * 0 * NOTYPE * GLOBAL * DEFAULT .* __global_pointer\$
 #...
- * [0-9a-f]+: * [0-9a-f]+ * 0 * NOTYPE * LOCAL * DEFAULT .* __global_pointer\$
-#pass
similarity index 65%
rename from ld/testsuite/ld-riscv-elf/gp-hidden.s
rename to ld/testsuite/ld-riscv-elf/gp-test.s
index 18d3ca3..a92c75e 100644 (file)
@@ -2,6 +2,5 @@
        .globl  blah
        .type   blah, @object
 blah:
-       .dc.a   foo
-       .dc.a   __global_pointer$
+       .dc.a   0
        .size   blah, . - blah
diff --git a/ld/testsuite/ld-riscv-elf/gp-test.sd b/ld/testsuite/ld-riscv-elf/gp-test.sd
new file mode 100644 (file)
index 0000000..30c1482
--- /dev/null
@@ -0,0 +1,5 @@
+Symbol table '.symtab' contains [0-9]+ entries:
+ * Num: * Value * Size * Type * Bind * Vis * Ndx * Name
+#...
+ * [0-9a-f]+: * [0-9a-f]+ * 0 * NOTYPE * GLOBAL * DEFAULT .* __global_pointer\$
+#pass
index 9f5959c..ea09a16 100644 (file)
@@ -24,33 +24,22 @@ if [istarget "riscv*-*-*"] {
 
     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.
+       # This checks whether our linker scripts handle __global_pointer$
+       # correctly.  It should be defined in executables and PIE, but not
+       # in shared libraries.
        set suff64 [string map {ilp32 "" lp64 -64} $abi]
        run_ld_link_tests [list \
-                              [list "gp scope test ($abi shared library)" \
+                              [list "gp 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" "" \
+                                   { gp-test.s } \
+                                   [list "readelf --syms gp-test-lib.sd"] \
+                                   "gp-test-lib-${abi}.so"] \
+                              [list "gp test ($abi executable)" \
+                                   "-m$emul" "" \
                                    "-march=$arch -mabi=$abi" \
-                                   {gp-hidden.s} \
-                                   [list \
-                                        "readelf --relocs gp-hidden${suff64}.rd" \
-                                        "readelf --syms gp-hidden.sd"]\
-                                   "gp-hidden-${abi}"]]
+                                   { gp-test.s } \
+                                   [list "readelf --syms gp-test.sd"] \
+                                   "gp-test-${abi}"]]
     }
 }