From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 54486 invoked by alias); 5 Dec 2017 01:38:52 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 54475 invoked by uid 89); 5 Dec 2017 01:38:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPAM_SUBJECT1,SPF_PASS autolearn=ham version=3.3.2 spammy=LOCAL, HIDDEN, ndx, Ndx X-HELO: mail-pg0-f68.google.com Received: from mail-pg0-f68.google.com (HELO mail-pg0-f68.google.com) (74.125.83.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Dec 2017 01:38:50 +0000 Received: by mail-pg0-f68.google.com with SMTP id b18so9555455pgv.10 for ; Mon, 04 Dec 2017 17:38:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=b/9WhY5ytknrLVnOiDf6dKNbnMM+nexjS477rDisjQ0=; b=JGj9EtwPY+3s074boAemwY8EGoOXXX6jFfFVkJBOPBk/azCc4tU52w4fLRIBR1ht7D barZ1o1Wd/UTech9fyM5KZRYXclPLe3QCeYG2yt8YBlBIniIlOwfjwAK7yM/Fu9MW5sb 4w2Yv/ST7RB/L3HKwO6fdMHZIqAy0fB9ScfTBBOAnlipcko3llJ6psdDehuv6VwzIOUQ G8WSnbfJyL/ipXwa2jOaCcVUt6VneQFWq3gq/7huXaZkA5bVAAYSM2p7vqkZHinsjSQA AjdkIcZFEdIed2wo5HlGweoFJe+YkVAN3Jns63LEFSerVBK6WXU9rJ/klsD/Ixj61ZfE IqEw== X-Gm-Message-State: AJaThX5rdu0xtQRM0HDNbaNj0+swFWC2v7NtBC8fJ6wZqXGl3LnUFVIB MWQv+dmVwQQOrM+vNnrCRWAjT/D92gE= X-Google-Smtp-Source: AGs4zMYt14isd/EtQCpJhfeUI3nPtLf48NDTt/SiYbfK0XPy3yfI1S8Do0tn55z8UD5117n/1Ywmow== X-Received: by 10.99.107.197 with SMTP id g188mr15587619pgc.295.1512437928082; Mon, 04 Dec 2017 17:38:48 -0800 (PST) Received: from rohan.internal.sifive.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id f79sm26077254pfd.45.2017.12.04.17.38.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Dec 2017 17:38:47 -0800 (PST) From: Jim Wilson To: binutils@sourceware.org Cc: Jim Wilson Subject: [PATCH] Riscv shared libraries should not export __global_pointer$. Date: Tue, 05 Dec 2017 01:38:00 -0000 Message-Id: <20171205013845.17778-1-jimw@sifive.com> X-SW-Source: 2017-12/txt/msg00041.txt.bz2 This fixes issue #108 in the riscv-binutils-gdb project on github. https://github.com/riscv/riscv-binutils-gdb/issues/108 The problem here is that the riscv linker is exporting __global_pointer$ which is wrong. This symbol serves the same function as the mips _gp. It is set by the linker script in every executable/shared library and should not be exported. Exporting it can lead to linker errors as reported in #108. The fix is use HIDDEN for __global_pointer$, same as the mips port uses HIDDEN for _gp. The mips port has some nice testcases for this, so I borrowed them to use for the riscv target. I also noticed that the riscv specific linker tests weren't being run because of a typo in the target check. This is fixed by this patch also. This was tested with check-binutils/check-gas/check-ld on riscv32 and riscv64. There were no regressions. Committed. 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/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 ++++++++++++++++++++++++++- 12 files changed, 89 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/emulparams/elf32lriscv-defs.sh b/ld/emulparams/elf32lriscv-defs.sh index ab80333289..5b41d5cd02 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 0000000000..aaaec93d8e --- /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 0000000000..59b4442190 --- /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 0000000000..04f0655857 --- /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 0000000000..57cb13fc4a --- /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 0000000000..dbed24f81e --- /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 0000000000..a197bacd9b --- /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 0000000000..b6b2365188 --- /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 0000000000..dc29f7d058 --- /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 0000000000..18d3ca3d98 --- /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 0000000000..f4321c2b1f --- /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 c219b18159..9f5959cc3b 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.14.1