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]

Linker script PROVIDE statements


Hi,
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.

tested on mips-unknown-elf, 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.  Detect erroneous redefinition.

	* 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	19 Feb 2004 17:42:56 -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,747 ----
  				  dot, dotp);
  	  if (result.valid_p)
  	    {
  	      struct bfd_link_hash_entry *h;
  
  	      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
+ 		       || ((h->type == bfd_link_hash_defined
+ 			    || h->type == bfd_link_hash_defweak)
+ 			   && (lang_statement_iteration > 1
+ 			       /* 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.  */
+ 			       || (!bfd_is_abs_section (h->u.def.section)
+ 				   && (bfd_is_abs_section
+ 				       (h->u.def.section->output_section))))))
  		{
  		  lang_update_definedness (tree->assign.dst, h);
  		  h->type = bfd_link_hash_defined;
  		  h->u.def.value = result.value;
*************** exp_fold_tree (etree_type *tree,
*** 754,759 ****
--- 749,759 ----
  		  if (tree->type.node_class == etree_provide)
  		    tree->type.node_class = etree_provided;
  		}
+ 	      else if (tree->type.node_class == etree_assign
+ 		       && (h->u.def.value != result.value
+ 			   || h->u.def.section != result.section->bfd_section))
+ 		einfo (_("%F%P:%s: symbol defined in linker script and object file\n"),
+ 		       tree->assign.dst);
  	    }
  	}
        break;
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	19 Feb 2004 17:42:56 -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	19 Feb 2004 17:42:56 -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	19 Feb 2004 17:42:56 -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	19 Feb 2004 17:42:56 -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	19 Feb 2004 17:42:56 -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	19 Feb 2004 17:42:56 -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	19 Feb 2004 17:42:56 -0000
***************
*** 0 ****
--- 1,23 ----
+ # 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
+ 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]