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: Dealing with multiple gas versions


On Wed, Oct 12, 2011 at 10:40:17AM +0100, Jan Beulich wrote:
> or .gasversion.

I quite like this suggestion.

> > Jan, do you remember why you chose to make local
> > symbols error on redefining?
> 
> Because it's plain wrong

Yeah, OK.  After I posted my email, I came to the same conclusion
myself when looking at where local symbols are currently used.

So, predefined symbols like .gasversion.
a) must pass .ifdef
b) should not cause any existing assembly to fail, even if it sets
   .gasversion. via .equiv, which normally fails if the symbol is
   already defined.
c) should not appear in the output symbol table, unless the symbol
   is redefined.

a) excludes using tricks like md_parse_name
b) and (c) together are a pain.

Here's a solution.

	* as.c (main): Define .gasversion. rather than __GAS_VERSION__.
	* frags.h (bss_address_frag): Delete
	(predefined_address_frag): New.
	* frags.c (frag_init): Init predefined_address_frag.  Delete ref
	to bss_addres_frag.
	* symbols.c (S_CAN_BE_REDEFINED): New function.
	* symbols.h (S_CAN_BE_REDEFINED): Declare.
	* read.c (assign_symbol): Use S_CAN_BE_REDEFINED.

Index: gas/as.c
===================================================================
RCS file: /cvs/src/src/gas/as.c,v
retrieving revision 1.98
diff -u -p -r1.98 as.c
--- gas/as.c	12 Oct 2011 02:57:07 -0000	1.98
+++ gas/as.c	12 Oct 2011 14:00:20 -0000
@@ -1206,8 +1206,8 @@ main (int argc, char ** argv)
 
   dwarf2_init ();
 
-  local_symbol_make ("__GAS_VERSION__", absolute_section,
-		     BFD_VERSION / 10000UL, &zero_address_frag);
+  local_symbol_make (".gasversion.", absolute_section,
+		     BFD_VERSION / 10000UL, &predefined_address_frag);
 
   /* Now that we have fully initialized, and have created the output
      file, define any symbols requested by --defsym command line
Index: gas/frags.c
===================================================================
RCS file: /cvs/src/src/gas/frags.c,v
retrieving revision 1.30
diff -u -p -r1.30 frags.c
--- gas/frags.c	1 Aug 2011 08:05:49 -0000	1.30
+++ gas/frags.c	12 Oct 2011 14:00:20 -0000
@@ -25,7 +25,7 @@
 #include "obstack.h"
 
 extern fragS zero_address_frag;
-extern fragS bss_address_frag;
+extern fragS predefined_address_frag;
 
 /* Initialization for frag routines.  */
 
@@ -33,7 +33,7 @@ void
 frag_init (void)
 {
   zero_address_frag.fr_type = rs_fill;
-  bss_address_frag.fr_type = rs_fill;
+  predefined_address_frag.fr_type = rs_fill;
 }
 
 /* Check that we're not trying to assemble into a section that can't
Index: gas/frags.h
===================================================================
RCS file: /cvs/src/src/gas/frags.h,v
retrieving revision 1.24
diff -u -p -r1.24 frags.h
--- gas/frags.h	19 Oct 2010 11:59:18 -0000	1.24
+++ gas/frags.h	12 Oct 2011 14:00:20 -0000
@@ -118,8 +118,7 @@ extern addressT frag_now_fix_octets (voi
 
 /* For foreign-segment symbol fixups.  */
 COMMON fragS zero_address_frag;
-/* For local common (N_BSS segment) fixups.  */
-COMMON fragS bss_address_frag;
+COMMON fragS predefined_address_frag;
 
 extern void frag_append_1_char (int);
 #define FRAG_APPEND_1_CHAR(X) frag_append_1_char (X)
Index: gas/read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.173
diff -u -p -r1.173 read.c
--- gas/read.c	2 Jun 2011 13:43:19 -0000	1.173
+++ gas/read.c	12 Oct 2011 14:00:22 -0000
@@ -3091,9 +3091,8 @@ assign_symbol (char *name, int mode)
 
   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
     {
-      /* Permit register names to be redefined.  */
       if ((mode != 0 || !S_IS_VOLATILE (symbolP))
-	  && S_GET_SEGMENT (symbolP) != reg_section)
+	  && !S_CAN_BE_REDEFINED (symbolP))
 	{
 	  as_bad (_("symbol `%s' is already defined"), name);
 	  symbolP = symbol_clone (symbolP, 0);
Index: gas/symbols.c
===================================================================
RCS file: /cvs/src/src/gas/symbols.c,v
retrieving revision 1.112
diff -u -p -r1.112 symbols.c
--- gas/symbols.c	12 Oct 2011 02:57:07 -0000	1.112
+++ gas/symbols.c	12 Oct 2011 14:00:24 -0000
@@ -2137,6 +2137,16 @@ S_IS_STABD (symbolS *s)
 }
 
 int
+S_CAN_BE_REDEFINED (const symbolS *s)
+{
+  if (LOCAL_SYMBOL_CHECK (s))
+    return (local_symbol_get_frag ((struct local_symbol *) s)
+	    == &predefined_address_frag);
+  /* Permit register names to be redefined.  */
+  return s->bsym->section == reg_section;
+}
+
+int
 S_IS_VOLATILE (const symbolS *s)
 {
   if (LOCAL_SYMBOL_CHECK (s))
Index: gas/symbols.h
===================================================================
RCS file: /cvs/src/src/gas/symbols.h,v
retrieving revision 1.34
diff -u -p -r1.34 symbols.h
--- gas/symbols.h	12 Oct 2011 02:57:07 -0000	1.34
+++ gas/symbols.h	12 Oct 2011 14:00:24 -0000
@@ -100,6 +100,7 @@ extern int S_FORCE_RELOC (symbolS *, int
 extern int S_IS_DEBUG (symbolS *);
 extern int S_IS_LOCAL (symbolS *);
 extern int S_IS_STABD (symbolS *);
+extern int S_CAN_BE_REDEFINED (const symbolS *);
 extern int S_IS_VOLATILE (const symbolS *);
 extern int S_IS_FORWARD_REF (const symbolS *);
 extern const char *S_GET_NAME (symbolS *);

-- 
Alan Modra
Australia Development Lab, IBM


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