public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch] PPC small data symbols.
@ 2005-06-29  1:22 Paul Brook
  2005-06-29  6:47 ` Alan Modra
  2005-07-12 11:25 ` Alan Modra
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Brook @ 2005-06-29  1:22 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

VxWorks executables are relocatable. One side-effect of this is that the 
linker provided small data base symbols must be section relative, not 
absolute.

The attached patch fixes this by passing an option section argument to 
_bfd_elf_provide_symbol.

Tested --enable-targets=all on ppc-linux and ppc-vxworks.
Ok?

Paul

2005-06-29  Paul Brook  <paul@codesourcery.com>

	* bfd-in.h (_bfd_elf_provide_symbol): Update prototype.
	* bfd-in2.h: Regenerate.
	* elf32-ppc.c (ppc_elf_set_sdata_syms): Make sdata symbols section
	relative.
	* elflink.c (bfd_elf_set_symbol): Add section argument.
	(_bfd_elf_provide_symbol): Ditto.
	(_bfd_elf_provide_section_bound_symbols): Pass NULL section argument.

[-- Attachment #2: patch.sda_rel --]
[-- Type: text/x-diff, Size: 4951 bytes --]

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.102
diff -u -p -r1.102 bfd-in.h
--- bfd/bfd-in.h	4 May 2005 15:53:00 -0000	1.102
+++ bfd/bfd-in.h	29 Jun 2005 00:37:57 -0000
@@ -698,7 +698,7 @@ extern struct bfd_section *_bfd_elf_tls_
   (bfd *, struct bfd_link_info *);
 
 extern void _bfd_elf_provide_symbol
-  (struct bfd_link_info *, const char *, bfd_vma);
+  (struct bfd_link_info *, const char *, bfd_vma, struct bfd_section *);
 
 extern void _bfd_elf_provide_section_bound_symbols
   (struct bfd_link_info *, struct bfd_section *sec, const char *, const char *);
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.346
diff -u -p -r1.346 bfd-in2.h
--- bfd/bfd-in2.h	17 Jun 2005 08:03:46 -0000	1.346
+++ bfd/bfd-in2.h	29 Jun 2005 00:37:57 -0000
@@ -705,7 +705,7 @@ extern struct bfd_section *_bfd_elf_tls_
   (bfd *, struct bfd_link_info *);
 
 extern void _bfd_elf_provide_symbol
-  (struct bfd_link_info *, const char *, bfd_vma);
+  (struct bfd_link_info *, const char *, bfd_vma, struct bfd_section *);
 
 extern void _bfd_elf_provide_section_bound_symbols
   (struct bfd_link_info *, struct bfd_section *sec, const char *, const char *);
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.164
diff -u -p -r1.164 elf32-ppc.c
--- bfd/elf32-ppc.c	20 Jun 2005 18:12:07 -0000	1.164
+++ bfd/elf32-ppc.c	29 Jun 2005 00:37:57 -0000
@@ -5108,24 +5108,38 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
       if (s == NULL)
 	s = bfd_get_section_by_name (obfd, lsect->bss_name);
 
-      val = 0;
-      if (s != NULL)
-	val = s->vma + 32768;
-      lsect->sym_val = val;
+      if (s)
+	{
+	  /* VxWorks executables are relocatable, so the sdata base symbols
+	     must be section-relative.  If the section is zero sized leave
+	     them as absolute symbols to avoid creationg an unused
+	     output section.  */
+	  val = 32768;
+	  lsect->sym_val = val + s->vma;
+	  if (s->size == 0)
+	    {
+	      val += s->vma;
+	      s = NULL;
+	    }
+	}
+      else
+	{
+	  val = 0;
+	  lsect->sym_val = 0;
+	}
 
-      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val, s);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
-  val = 0;
+  _bfd_elf_provide_symbol (info, "__sbss_start", 0, NULL);
+  _bfd_elf_provide_symbol (info, "___sbss_start", 0, NULL);
   if (s != NULL)
-    val = s->vma;
-  _bfd_elf_provide_symbol (info, "__sbss_start", val);
-  _bfd_elf_provide_symbol (info, "___sbss_start", val);
-  if (s != NULL)
-    val += s->size;
-  _bfd_elf_provide_symbol (info, "__sbss_end", val);
-  _bfd_elf_provide_symbol (info, "___sbss_end", val);
+    val = s->size;
+  else
+    val = 0;
+  _bfd_elf_provide_symbol (info, "__sbss_end", val, s);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val, s);
   return TRUE;
 }
 \f
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.168
diff -u -p -r1.168 elflink.c
--- bfd/elflink.c	14 Jun 2005 19:25:45 -0000	1.168
+++ bfd/elflink.c	29 Jun 2005 00:37:58 -0000
@@ -9792,10 +9792,11 @@ _bfd_elf_section_already_linked (bfd *ab
 }
 
 static void
-bfd_elf_set_symbol (struct elf_link_hash_entry *h, bfd_vma val)
+bfd_elf_set_symbol (struct elf_link_hash_entry *h, bfd_vma val,
+		    struct bfd_section *s)
 {
   h->root.type = bfd_link_hash_defined;
-  h->root.u.def.section = bfd_abs_section_ptr;
+  h->root.u.def.section = s ? s : bfd_abs_section_ptr;
   h->root.u.def.value = val;
   h->def_regular = 1;
   h->type = STT_OBJECT;
@@ -9803,11 +9804,12 @@ bfd_elf_set_symbol (struct elf_link_hash
   h->forced_local = 1;
 }
 
-/* Set NAME to VAL if the symbol exists and is undefined.  */
+/* Set NAME to VAL if the symbol exists and is undefined.  If val is NULL
+   it is an absolute symbol, otherwise it is relative to that section.  */
 
 void
 _bfd_elf_provide_symbol (struct bfd_link_info *info, const char *name,
-			 bfd_vma val)
+			 bfd_vma val, struct bfd_section *s)
 {
   struct elf_link_hash_entry *h;
 
@@ -9815,7 +9817,7 @@ _bfd_elf_provide_symbol (struct bfd_link
 			    FALSE);
   if (h != NULL && (h->root.type == bfd_link_hash_undefined
 		    || h->root.type == bfd_link_hash_undefweak))
-    bfd_elf_set_symbol (h, val);
+    bfd_elf_set_symbol (h, val, s);
 }
 
 /* Set START and END to boundaries of SEC if they exist and are
@@ -9868,8 +9870,8 @@ _bfd_elf_provide_section_bound_symbols (
     }
 
   if (do_start)
-    bfd_elf_set_symbol (hs, start_val);
+    bfd_elf_set_symbol (hs, start_val, NULL);
 
   if (do_end)
-    bfd_elf_set_symbol (he, end_val);
+    bfd_elf_set_symbol (he, end_val, NULL);
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] PPC small data symbols.
  2005-06-29  1:22 [patch] PPC small data symbols Paul Brook
@ 2005-06-29  6:47 ` Alan Modra
  2005-07-12 11:25 ` Alan Modra
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Modra @ 2005-06-29  6:47 UTC (permalink / raw)
  To: Paul Brook; +Cc: binutils

On Wed, Jun 29, 2005 at 02:22:40AM +0100, Paul Brook wrote:
> 	* bfd-in.h (_bfd_elf_provide_symbol): Update prototype.
> 	* bfd-in2.h: Regenerate.
> 	* elf32-ppc.c (ppc_elf_set_sdata_syms): Make sdata symbols section
> 	relative.
> 	* elflink.c (bfd_elf_set_symbol): Add section argument.
> 	(_bfd_elf_provide_symbol): Ditto.
> 	(_bfd_elf_provide_section_bound_symbols): Pass NULL section argument.

OK.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] PPC small data symbols.
  2005-06-29  1:22 [patch] PPC small data symbols Paul Brook
  2005-06-29  6:47 ` Alan Modra
@ 2005-07-12 11:25 ` Alan Modra
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Modra @ 2005-07-12 11:25 UTC (permalink / raw)
  To: binutils

On Wed, Jun 29, 2005 at 02:22:40AM +0100, Paul Brook wrote:
> 	* elf32-ppc.c (ppc_elf_set_sdata_syms): Make sdata symbols section
> 	relative.

This slipped past my review.

	* elf32-ppc.c (ppc_elf_set_sdata_syms): Correct __sbss_start value.

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.171
diff -u -p -r1.171 elf32-ppc.c
--- bfd/elf32-ppc.c	8 Jul 2005 06:19:59 -0000	1.171
+++ bfd/elf32-ppc.c	12 Jul 2005 09:40:43 -0000
@@ -5307,12 +5311,11 @@ ppc_elf_set_sdata_syms (bfd *obfd, struc
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
-  _bfd_elf_provide_symbol (info, "__sbss_start", 0, NULL);
-  _bfd_elf_provide_symbol (info, "___sbss_start", 0, NULL);
+  val = 0;
+  _bfd_elf_provide_symbol (info, "__sbss_start", val, s);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val, s);
   if (s != NULL)
     val = s->size;
-  else
-    val = 0;
   _bfd_elf_provide_symbol (info, "__sbss_end", val, s);
   _bfd_elf_provide_symbol (info, "___sbss_end", val, s);
   return TRUE;

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-12 11:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-29  1:22 [patch] PPC small data symbols Paul Brook
2005-06-29  6:47 ` Alan Modra
2005-07-12 11:25 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).