Dealing with multiple gas versions

Alan Modra amodra@gmail.com
Wed Oct 12 02:57:00 GMT 2011


On Tue, Oct 11, 2011 at 03:28:20PM -0400, Ryan Mansfield wrote:
> Has there been any discussion of introducing a mechanism that allows
> users to write code that is for specific version(s) of gas?  Not
> frequently but occasionally there are changes between versions where
> it would be handy to write conditional code that could be assembled
> by multiple versions of gas.

Good idea.  A little messy to use, since older assemblers won't have
the "mechanism" whatever that is.  I reckon the only thing that would
work is a predefined symbol, since symbols can be tested with
.ifdef/.ifndef.

 .ifndef __GAS_VERSION__
	.byte 4			# before 2.22 (assuming this goes
				# on the branch)
 .elseif __GAS_VERSION__ < 22300
	.byte 5			# 2.22
 .else
	.byte 6			# 2.23 and later
 .endif

	* symbols.c (local_symbol_make): Make global.
	* symbols.h (local_symbol_make): Declare.
	* as.c (main): Define __GAS_VERSION__.

Index: gas/as.c
===================================================================
RCS file: /cvs/src/src/gas/as.c,v
retrieving revision 1.97
diff -u -p -r1.97 as.c
--- gas/as.c	2 Jun 2011 13:43:19 -0000	1.97
+++ gas/as.c	12 Oct 2011 02:10:29 -0000
@@ -1206,6 +1206,9 @@ main (int argc, char ** argv)
 
   dwarf2_init ();
 
+  local_symbol_make ("__GAS_VERSION__", absolute_section,
+		     BFD_VERSION / 10000UL, &zero_address_frag);
+
   /* Now that we have fully initialized, and have created the output
      file, define any symbols requested by --defsym command line
      arguments.  */
Index: gas/symbols.c
===================================================================
RCS file: /cvs/src/src/gas/symbols.c,v
retrieving revision 1.111
diff -u -p -r1.111 symbols.c
--- gas/symbols.c	24 Jul 2011 14:20:08 -0000	1.111
+++ gas/symbols.c	12 Oct 2011 02:10:30 -0000
@@ -23,11 +23,9 @@
 /* #define DEBUG_SYMS / * to debug symbol list maintenance.  */
 
 #include "as.h"
-
 #include "safe-ctype.h"
 #include "obstack.h"		/* For "symbols.h" */
 #include "subsegs.h"
-
 #include "struc-symbol.h"
 
 /* This is non-zero if symbols are case sensitive, which is the
@@ -191,7 +189,7 @@ static unsigned long local_symbol_conver
 
 /* Create a local symbol and insert it into the local hash table.  */
 
-static struct local_symbol *
+struct local_symbol *
 local_symbol_make (const char *name, segT section, valueT val, fragS *frag)
 {
   char *name_copy;
Index: gas/symbols.h
===================================================================
RCS file: /cvs/src/src/gas/symbols.h,v
retrieving revision 1.33
diff -u -p -r1.33 symbols.h
--- gas/symbols.h	1 Dec 2010 21:34:10 -0000	1.33
+++ gas/symbols.h	12 Oct 2011 02:10:30 -0000
@@ -50,6 +50,8 @@ symbolS *symbol_new (const char *name, s
 		     fragS * frag);
 symbolS *symbol_create (const char *name, segT segment, valueT value,
 			fragS * frag);
+struct local_symbol *local_symbol_make (const char *name, segT section,
+					valueT val, fragS *frag);
 symbolS *symbol_clone (symbolS *, int);
 #undef symbol_clone_if_forward_ref
 symbolS *symbol_clone_if_forward_ref (symbolS *, int);


-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list