This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] LD: PROVIDE_HIDDEN export class problem


On Thu, 2 May 2013, Alan Modra wrote:

> >  I hoped the test cases provided were clear enough an illustration, 
> > however in this case perhaps a C code piece will be better.  Given code 
> > produced from a definition like this:
> > 
> > int foo = 1234;
> > 
> > present in input and a linker script containing:
> > 
> > PROVIDE_HIDDEN (foo = bar);
> > 
> > I see no reason why foo should be assigned the hidden export class, as in 
> > this case "the linker will silently use the definition in the program."  
> > Likewise I'd expect the link not to fail even if there's been no bar 
> > definition anywhere.
> 
> Why would someone use PROVIDE_HIDDEN rather than plain PROVIDE if
> they don't want "foo" hidden?
> 
> >  Do you have a reference backing your claim that my interpretation is 
> > wrong?
> 
> Well, the current ld info doc says of PROVIDE_HIDDEN: "Similar to
> PROVIDE.  For ELF targeted ports, the symbol will be hidden and won't
> be exported."  Notice that it doesn't say "will be hidden .. if
> provided".  Hiding the symbol is unconditional according to the way I
> read this.
> 
> Furthermore, I think the current behaviour is not really surprising,
> given that not just a definition but even a reference (undefined
> symbol) with STV_HIDDEN in a relocatable object file results in the
> output symbol being hidden.

 I don't feel particularly convinced, although I do recognise the pros 
you've noted.  What I think the case is the current semantics wasn't 
really architected and just happened as a side effect of the original 
implementation of PROVIDE_HIDDEN support.  I don't feel compelled to argue 
to death either.

 But in any case I think at least the properties of this command should be 
properly covered in testing so as to avoid future surprises.  Here's the 
test script and cases I offered previously modified suitably to cover the 
current semantics.  No regressions across the usual 139 targets.

 OK to apply?

2013-05-02  Maciej W. Rozycki  <macro@codesourcery.com>

	ld/testsuite/
	* ld-elf/provide-hidden-s.nd: New test.
	* ld-elf/provide-hidden-abs.nd: New test.
	* ld-elf/provide-hidden-def.nd: New test.
	* ld-elf/provide-hidden-dyn.nd: New test.
	* ld-elf/provide-hidden-sec.nd: New test.
	* ld-elf/provide-hidden-dynabs.nd: New test.
	* ld-elf/provide-hidden-dynsec.nd: New test.
	* ld-elf/provide-hidden-s.ld: New test linker script.
	* ld-elf/provide-hidden-1.ld: New test linker script.
	* ld-elf/provide-hidden-2.ld: New test linker script.
	* ld-elf/provide-hidden-1.s: New test source.
	* ld-elf/provide-hidden-2.s: New test source.
	* ld-elf/provide-hidden-3.s: New test source.
	* ld-elf/provide-hidden-4.s: New test source.
	* ld-elf/provide-hidden.exp: New test script.

  Maciej

binutils-provide-hidden-test.diff
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-1.ld
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-1.ld	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,15 @@
+SECTIONS
+{
+  . = 0x12300000;
+  .data :
+    {
+      PROVIDE_HIDDEN (foo = . + 0x11100000);
+      *(.data)
+    }
+  .got : { *(.got) }
+  .interp : { *(.interp) }
+  .dynsym : { *(.dynsym) }
+  .dynstr : { *(.dynstr) }
+  .dynamic : { *(.dynamic) }
+  .hash : { *(.hash) }
+}
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-1.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-1.s	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,4 @@
+	.data
+	.globl	foo
+foo:
+	.dc.a	foo
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-2.ld
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-2.ld	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,12 @@
+SECTIONS
+{
+  . = 0x12300000;
+  PROVIDE_HIDDEN (foo = . + 0x11100000);
+  .data : { *(.data) }
+  .got : { *(.got) }
+  .interp : { *(.interp) }
+  .dynsym : { *(.dynsym) }
+  .dynstr : { *(.dynstr) }
+  .dynamic : { *(.dynamic) }
+  .hash : { *(.hash) }
+}
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-2.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-2.s	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,5 @@
+	.data
+	.globl	foo
+	.internal foo
+foo:
+	.dc.a	foo
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-3.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-3.s	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,4 @@
+	.data
+	.globl	bar
+bar:
+	.dc.a	foo
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-4.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-4.s	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,5 @@
+	.data
+	.globl	bar
+	.internal foo
+bar:
+	.dc.a	foo
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-abs.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-abs.nd	2013-05-02 15:42:59.052764874 +0100
@@ -0,0 +1,5 @@
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +ABS foo
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-def.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-def.nd	2013-05-02 14:42:21.583869464 +0100
@@ -0,0 +1,5 @@
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*12300000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +[0-9]+ foo
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-dyn.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-dyn.nd	2013-05-02 17:56:59.082900096 +0100
@@ -0,0 +1,7 @@
+#failif
+Symbol table '\.dynsym' contains [0-9]+ entries:
+#...
+.* foo
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-dynabs.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-dynabs.nd	2013-05-02 20:36:07.312653925 +0100
@@ -0,0 +1,8 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +ABS foo
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +ABS foo
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-dynsec.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-dynsec.nd	2013-05-02 20:12:53.633868977 +0100
@@ -0,0 +1,8 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +[0-9]+ foo
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +[0-9]+ foo
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-s.ld
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-s.ld	2013-05-02 15:50:02.603231709 +0100
@@ -0,0 +1,11 @@
+SECTIONS
+{
+  . = 0x12300000;
+  .data : { *(.data) }
+  .got : { *(.got) }
+  .interp : { *(.interp) }
+  .dynsym : { *(.dynsym) }
+  .dynstr : { *(.dynstr) }
+  .dynamic : { *(.dynamic) }
+  .hash : { *(.hash) }
+}
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-s.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-s.nd	2013-05-02 15:48:41.592760597 +0100
@@ -0,0 +1,8 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*12300000 +0 (?:NOTYPE|OBJECT) +GLOBAL +DEFAULT +[0-9]+ foo
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*12300000 +0 (?:NOTYPE|OBJECT) +GLOBAL +DEFAULT +[0-9]+ foo
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-sec.nd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden-sec.nd	2013-05-02 15:42:54.552761072 +0100
@@ -0,0 +1,5 @@
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+#...
+ *[0-9]+: 0*23400000 +0 (?:NOTYPE|OBJECT) +LOCAL +DEFAULT +[0-9]+ foo
+#pass
Index: binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/ld/testsuite/ld-elf/provide-hidden.exp	2013-05-02 20:36:37.812655868 +0100
@@ -0,0 +1,154 @@
+# Expect script for the PROVIDE_HIDDEN linker script command.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+#
+# Written by Maciej W. Rozycki <macro@codesourcery.com>
+#
+
+# Export classes only make sense for ELF shared-library targets.
+if { ![is_elf_format] || ![check_shared_lib_support] } {
+    return
+}
+
+# This target requires extra GAS options when building code for shared
+# libraries.
+set AFLAGS_PIC ""
+if [istarget "tic6x-*-*"] {
+    append AFLAGS_PIC " -mpic -mpid=near"
+}
+
+set testname "PROVIDE_HIDDEN test"
+
+run_ld_link_tests [list \
+    [list \
+	"$testname (auxiliary shared object)" \
+	"-shared -T provide-hidden-s.ld" "" \
+	"$AFLAGS_PIC" \
+	[list provide-hidden-1.s ] \
+	[list "readelf -s provide-hidden-s.nd"] \
+	"provide-hidden-s.so"]]
+
+run_ld_link_tests [list \
+    [list \
+	"$testname 1" \
+	"-T provide-hidden-1.ld" "" \
+	"" \
+	[list provide-hidden-1.s] \
+	[list \
+	    [list readelf -s provide-hidden-def.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-1"] \
+    [list \
+	"$testname 2" \
+	"-T provide-hidden-1.ld" "" \
+	"" \
+	[list provide-hidden-2.s] \
+	[list \
+	    [list readelf -s provide-hidden-def.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-2"] \
+    [list \
+	"$testname 3" \
+	"-T provide-hidden-1.ld" "" \
+	"" \
+	[list provide-hidden-3.s] \
+	[list \
+	    [list readelf -s provide-hidden-sec.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-3"] \
+    [list \
+	"$testname 4" \
+	"-T provide-hidden-1.ld" "tmpdir/provide-hidden-s.so" \
+	"" \
+	[list provide-hidden-3.s] \
+	[list "readelf -s provide-hidden-dynsec.nd"] \
+	"provide-hidden-4"] \
+    [list \
+	"$testname 5" \
+	"-T provide-hidden-1.ld" "" \
+	"" \
+	[list provide-hidden-4.s] \
+	[list \
+	    [list readelf -s provide-hidden-sec.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-5"] \
+    [list \
+	"$testname 6" \
+	"-T provide-hidden-1.ld" "tmpdir/provide-hidden-s.so" \
+	"" \
+	[list provide-hidden-4.s] \
+	[list \
+	    [list readelf -s provide-hidden-sec.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-6"] \
+    [list \
+	"$testname 7" \
+	"-T provide-hidden-2.ld" "" \
+	"" \
+	[list provide-hidden-1.s] \
+	[list \
+	    [list readelf -s provide-hidden-def.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-7"] \
+    [list \
+	"$testname 8" \
+	"-T provide-hidden-2.ld" "" \
+	"" \
+	[list provide-hidden-2.s] \
+	[list \
+	    [list readelf -s provide-hidden-def.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-8"] \
+    [list \
+	"$testname 9" \
+	"-T provide-hidden-2.ld" "" \
+	"" \
+	[list provide-hidden-3.s] \
+	[list \
+	    [list readelf -s provide-hidden-abs.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-9"] \
+    [list \
+	"$testname 10" \
+	"-T provide-hidden-2.ld" "tmpdir/provide-hidden-s.so" \
+	"" \
+	[list provide-hidden-3.s] \
+	[list "readelf -s provide-hidden-dynabs.nd"] \
+	"provide-hidden-10"] \
+    [list \
+	"$testname 11" \
+	"-T provide-hidden-2.ld" "" \
+	"" \
+	[list provide-hidden-4.s] \
+	[list \
+	    [list readelf -s provide-hidden-abs.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-11"] \
+    [list \
+	"$testname 12" \
+	"-T provide-hidden-2.ld" "tmpdir/provide-hidden-s.so" \
+	"" \
+	[list provide-hidden-4.s] \
+	[list \
+	    [list readelf -s provide-hidden-abs.nd] \
+	    [list readelf -s provide-hidden-dyn.nd]] \
+	"provide-hidden-12"]]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]