This is the mail archive of the binutils@sources.redhat.com 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: Linker script PROVIDE statements


Nathan Sidwell wrote:
I discovered PROVIDE was broken, fixed thusly.  I'm not smart enough to
figure out how to give the location of a conflicting definition, %D
doesn't appear to work.
Oops, it appears that patch had some issues. Here is one I've tested
on i686-pc-linux-gnu, and does not break the shared object linking.

shared objects have their own global definitions of things like _etext,
which get pulled into the linker's symbol table.  I suspect that is wrong,
but I don't know how to fix it. Presumably _etext should either not be in
the shared object's symbol table at all, or simply not exported from it.

ok?

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2004-02-19  Nathan Sidwell  <nathan@codesourcery.com>

	* ldexp.c (exp_fold_tree): Always create an assigned or provided
	symbol.
	* ldlang.c (lang_size_sections): Increment lang_statement_iteration.

	* ld-scripts/provide.exp: New.
	* ld-scripts/provide-{1,2}.{s,t,d}.exp: New.

Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.27
diff -c -3 -p -r1.27 ldexp.c
*** ld/ldexp.c	3 Jan 2004 12:39:07 -0000	1.27
--- ld/ldexp.c	20 Feb 2004 13:31:49 -0000
*************** exp_fold_tree (etree_type *tree,
*** 721,752 ****
  				  dot, dotp);
  	  if (result.valid_p)
  	    {
- 	      bfd_boolean create;
  	      struct bfd_link_hash_entry *h;
  
- 	      if (tree->type.node_class == etree_assign)
- 		create = TRUE;
- 	      else
- 		create = FALSE;
  	      h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
! 					create, FALSE, FALSE);
  	      if (h == NULL)
  		{
! 		  if (tree->type.node_class == etree_assign)
! 		    einfo (_("%P%F:%s: hash creation failed\n"),
  			   tree->assign.dst);
  		}
! 	      else if (tree->type.node_class == etree_provide
! 		       && h->type != bfd_link_hash_undefined
! 		       && h->type != bfd_link_hash_common)
! 		{
! 		  /* Do nothing.  The symbol was defined by some
! 		     object.  */
! 		}
  	      else
  		{
- 		  /* FIXME: Should we worry if the symbol is already
- 		     defined?  */
  		  lang_update_definedness (tree->assign.dst, h);
  		  h->type = bfd_link_hash_defined;
  		  h->u.def.value = result.value;
--- 721,772 ----
  				  dot, dotp);
  	  if (result.valid_p)
  	    {
  	      struct bfd_link_hash_entry *h;
+ 	      bfd_boolean update;
  
  	      h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
! 					TRUE, FALSE, FALSE);
  	      if (h == NULL)
+ 		einfo (_("%P%F:%s: hash creation failed\n"),
+ 		       tree->assign.dst);
+ 	      else if (h->type == bfd_link_hash_new
+ 		       || h->type == bfd_link_hash_undefined
+ 		       || h->type == bfd_link_hash_common)
+ 		update = TRUE;
+ 	      else if (h->type != bfd_link_hash_defined
+ 		       && h->type != bfd_link_hash_defweak)
+ 		update = FALSE;
+ 	      else if (!bfd_is_abs_section (h->u.def.section)
+ 		       && (bfd_is_abs_section
+ 			   (h->u.def.section->output_section)))
+ 		/* If it's already defined to a symbol with an
+ 		   absolute output section, it's not really a
+ 		   redefinition, because that is how we indicate
+ 		   sections that will be discarded.  */
+ 		update = TRUE;
+ 	      else if (tree->type.node_class == etree_assign)
  		{
! #if 0
! 		  /* This test breaks shared object linking, as those
! 		     have their own etext, __bss_start etc, which
! 		     conflicts.  The dynamic linking scripts should be
! 		     fixed.  */
! 		  if (lang_statement_iteration == 1
! 		      && (result.value != h->u.def.value
! 			  || result.section->bfd_section != h->u.def.section))
! 		    einfo (
! 	_("%F%P:%s: symbol defined in linker script and object file\n"),
  			   tree->assign.dst);
+ #endif
+ 		  update = TRUE;
  		}
! 	      else if (tree->type.node_class == etree_provided)
! 		update = TRUE;
  	      else
+ 		update = FALSE;
+ 	      
+ 	      if (update)
  		{
  		  lang_update_definedness (tree->assign.dst, h);
  		  h->type = bfd_link_hash_defined;
  		  h->u.def.value = result.value;
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.137
diff -c -3 -p -r1.137 ldlang.c
*** ld/ldlang.c	19 Feb 2004 14:08:31 -0000	1.137
--- ld/ldlang.c	20 Feb 2004 13:31:58 -0000
*************** lang_size_sections
*** 3294,3299 ****
--- 3294,3300 ----
  	  && first + last <= exp_data_seg.pagesize)
  	{
  	  exp_data_seg.phase = exp_dataseg_adjust;
+ 	  lang_statement_iteration++;
  	  result = lang_size_sections_1 (s, output_section_statement, prev,
  					 fill, dot, relax, check_regions);
  	}
Index: ld/testsuite/ld-scripts/provide-1.d
===================================================================
RCS file: ld/testsuite/ld-scripts/provide-1.d
diff -N ld/testsuite/ld-scripts/provide-1.d
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide-1.d	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,8 ----
+ #source: provide-1.s
+ #ld: -T provide-1.t
+ #objdump: -s -j .data
+ 
+ .*:     file format .*
+ 
+ Contents of section .data:
+  0000 (08)?000000(08)? (0c)?000000(0c)? 00000000           ............    
Index: ld/testsuite/ld-scripts/provide-1.s
===================================================================
RCS file: ld/testsuite/ld-scripts/provide-1.s
diff -N ld/testsuite/ld-scripts/provide-1.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide-1.s	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,3 ----
+ 	.data
+ 	.globl foo
+ foo:	.long 0
Index: ld/testsuite/ld-scripts/provide-1.t
===================================================================
RCS file: ld/testsuite/ld-scripts/provide-1.t
diff -N ld/testsuite/ld-scripts/provide-1.t
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide-1.t	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,11 ----
+ SECTIONS 
+ {
+   .data :
+   {
+     LONG (foo)
+     LONG (bar)
+     *(.data)
+   }
+   PROVIDE (foo = .);
+   PROVIDE (bar = .);
+ }
Index: ld/testsuite/ld-scripts/provide-2.d
===================================================================
RCS file: ld/testsuite/ld-scripts/provide-2.d
diff -N ld/testsuite/ld-scripts/provide-2.d
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide-2.d	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,3 ----
+ #source: provide-2.s
+ #ld: -T provide-2.t
+ #error: symbol defined in linker script and object file
Index: ld/testsuite/ld-scripts/provide-2.s
===================================================================
RCS file: ld/testsuite/ld-scripts/provide-2.s
diff -N ld/testsuite/ld-scripts/provide-2.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide-2.s	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,3 ----
+ 	.data
+ 	.globl foo
+ foo:	.long 0
Index: ld/testsuite/ld-scripts/provide-2.t
===================================================================
RCS file: ld/testsuite/ld-scripts/provide-2.t
diff -N ld/testsuite/ld-scripts/provide-2.t
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide-2.t	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,11 ----
+ SECTIONS 
+ {
+   .data :
+   {
+     LONG (foo)
+     LONG (bar)
+     *(.data)
+   }
+   foo = .;
+   bar = .;
+ }
Index: ld/testsuite/ld-scripts/provide.exp
===================================================================
RCS file: ld/testsuite/ld-scripts/provide.exp
diff -N ld/testsuite/ld-scripts/provide.exp
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/provide.exp	20 Feb 2004 13:31:58 -0000
***************
*** 0 ****
--- 1,24 ----
+ # Test PROVIDE in a linker script.
+ # By Nathan Sidwell, CodeSourcery LLC
+ #   Copyright 2004
+ #   Free Software Foundation, Inc.
+ #
+ # This file 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ 
+ set testname "provide"
+ 
+ run_dump_test provide-1
+ setup_xfail *-*-*
+ run_dump_test provide-2

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