public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFC/RFA: Improve definition of ASM_OUTPUT_MEASURED_SIZE
@ 2002-07-25 18:22 Zack Weinberg
  2002-07-25 19:56 ` Richard Henderson
  0 siblings, 1 reply; 9+ messages in thread
From: Zack Weinberg @ 2002-07-25 18:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

This patch makes some improvements to the definition of
ASM_OUTPUT_MEASURED_SIZE and to the code that uses it.  The motivation
is convoluted - please bear with me.

All but two of the current uses of ASM_OUTPUT_MEASURED_SIZE follow the
pattern

  { char label[256];
    static int labelno;
    ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno)
    ASM_OUTPUT_INTERNAL_LABEL (file, "Lfe", labelno)
    ASM_OUTPUT_MEASURED_SIZE (file, fname, label)
  }

which produces assembly output of the form

foo:
   /* ... */
.Lfe23:
   .size foo, .Lfe23-foo

The other two uses simply say

  ASM_OUTPUT_MEASURED_SIZE (file, fname, ".")

which produces

foo:
  /* ... */
  .size foo, .-foo

Or, it's supposed to do that.  ASM_OUTPUT_MEASURED_SIZE uses
assemble_name() to emit the dot, and on targets that prepend
underscores to user visible identifiers, we get

_foo:
  /* ... */
  .size _foo, _.-_foo

which the assembler naturally objects to.  So those targets are
broken by my change, and a fix is needed.

Now, note that ASM_OUTPUT_MEASURED_SIZE is never used other than to
calculate the difference between a symbol and the current address; we
just have two idioms for that operation.  One is substantially more
complicated than the other.  It seems to me that any assembler with a
.size directive ought to be modern enough to accept the expression
".-foo".  Therefore I propose to use that idiom universally, which
permits me to eliminate the third argument to ASM_OUTPUT_MEASURED_SIZE, 
and write out the dot with puts(), solving the problem currently
experienced by OpenBSD.  Eliminating a whole bunch of duplicate code
is a nice side effect.

I have built cross compilers as before, but it is impossible for me to
test it properly.  GAS from binutils CVS of course accepts ".-foo" -
the question is whether there exists a vendor assembler, or an old
version of GAS, that doesn't.  Reactions from the maintainers of the
affected targets would be appreciated.

Header			Tested with target
------			------------------
elfos.h			i386-linux
netbsd-aout.h		i386-netbsd
openbsd.h		i386-openbsd
arm/elf.h		arm-elf
avr/avr.h		avr-none
cris/aout.h		cris-aout
i386/freebsd-aout.h	i386-freebsd2
i386/sco5.h		i386-sco3.2v5
ip2k/ip2k.h		ip2k-elf (*)
m88k/m88k.h		m88k-aout
xtensa/elf.h		xtensa-elf
xtensa/linux.h		xtensa-linux

(*) This target does not build due to unrelated bugs.

A great many other targets are affected, since the change touches
shared headers such as elfos.h.

zw

	* defaults.h (ASM_OUTPUT_MEASURED_SIZE): Take only two
	arguments.  Always use ".-symbol" as expression argument.
	* doc/tm.texi: Update to match.  Document requirement for
	".size symbol, .-symbol" to be acceptable to assembler.

	* config/elfos.h, config/netbsd-aout.h, config/openbsd.h,
	config/arm/elf.h, config/avr/avr.h, config/cris/aout.h,
	config/i386/freebsd-aout.h, config/i386/sco5.h,
	config/ip2k/ip2k.h, config/m88k/m88k.h, config/xtensa/elf.h,
	config/xtensa/linux.h:  Update uses of ASM_OUTPUT_MEASURED_SIZE.

===================================================================
Index: defaults.h
--- defaults.h	25 Jul 2002 05:14:17 -0000	1.84
+++ defaults.h	25 Jul 2002 23:48:46 -0000
@@ -200,15 +200,13 @@ do { fputs (integer_asm_op (POINTER_SIZE
     }							\
   while (0)
 
-#define ASM_OUTPUT_MEASURED_SIZE(STREAM, BEG, END)	\
+#define ASM_OUTPUT_MEASURED_SIZE(STREAM, NAME)		\
   do							\
     {							\
       fputs (SIZE_ASM_OP, STREAM);			\
-      assemble_name (STREAM, BEG);			\
-      fputs (", ", STREAM);				\
-      assemble_name (STREAM, END);			\
-      putc ('-', STREAM);				\
-      assemble_name (STREAM, BEG);			\
+      assemble_name (STREAM, NAME);			\
+      fputs (", .-", STREAM);				\
+      assemble_name (STREAM, NAME);			\
       putc ('\n', STREAM);				\
     }							\
   while (0)
===================================================================
Index: config/elfos.h
--- config/elfos.h	25 Jul 2002 05:14:17 -0000	1.49
+++ config/elfos.h	25 Jul 2002 23:48:47 -0000
@@ -354,16 +354,7 @@ Boston, MA 02111-1307, USA.  */
   do								\
     {								\
       if (!flag_inhibit_size_directive)				\
-	{							\
-	  char label[256];					\
-	  static int labelno;					\
-	  							\
-	  labelno++;						\
-	  							\
-	  ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	  ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);	\
-	  ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);	\
-	}							\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
     }								\
   while (0)
 #endif
===================================================================
Index: config/netbsd-aout.h
--- config/netbsd-aout.h	25 Jul 2002 05:14:17 -0000	1.5
+++ config/netbsd-aout.h	25 Jul 2002 23:48:47 -0000
@@ -196,13 +196,6 @@ Boston, MA 02111-1307, USA.  */
   do									\
     {									\
       if (!flag_inhibit_size_directive)					\
-	{								\
-	  char label[256];						\
-	  static int labelno;						\
-	  labelno++;							\
-	  ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);		\
-	  ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);		\
-	  ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME, label);		\
-	}								\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);				\
     }									\
   while (0)
===================================================================
Index: config/openbsd.h
--- config/openbsd.h	25 Jul 2002 05:14:17 -0000	1.12
+++ config/openbsd.h	25 Jul 2002 23:48:47 -0000
@@ -212,10 +212,10 @@ Boston, MA 02111-1307, USA.  */
 #ifndef OBSD_HAS_DECLARE_FUNCTION_SIZE
 /* Declare the size of a function.  */
 #undef ASM_DECLARE_FUNCTION_SIZE
-#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
-  do {									\
-    if (!flag_inhibit_size_directive)					\
-      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME, ".");			\
+#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
+  do {								\
+    if (!flag_inhibit_size_directive)				\
+      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
   } while (0)
 #endif
 
===================================================================
Index: config/arm/elf.h
--- config/arm/elf.h	25 Jul 2002 05:14:18 -0000	1.35
+++ config/arm/elf.h	25 Jul 2002 23:48:47 -0000
@@ -79,14 +79,7 @@ Boston, MA 02111-1307, USA.  */
     {								\
       ARM_DECLARE_FUNCTION_SIZE (FILE, FNAME, DECL);		\
       if (!flag_inhibit_size_directive)				\
-        {							\
-          char label[256];					\
-	  static int labelno;					\
-	  labelno ++;						\
-	  ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	  ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);	\
-	  ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);	\
-        }							\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
     }								\
   while (0)
 
===================================================================
Index: config/avr/avr.h
--- config/avr/avr.h	25 Jul 2002 05:14:18 -0000	1.61
+++ config/avr/avr.h	25 Jul 2002 23:48:48 -0000
@@ -1969,14 +1969,7 @@ do {								\
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
   do {									\
     if (!flag_inhibit_size_directive)					\
-      {									\
-        char label[256];						\
-	static int labelno;						\
-	labelno++;							\
-	ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);		\
-	ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);		\
-	ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);		\
-      }									\
+      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);				\
   } while (0)
 /* A C statement (sans semicolon) to output to the stdio stream
    STREAM any text necessary for declaring the size of a function
===================================================================
Index: config/cris/aout.h
--- config/cris/aout.h	25 Jul 2002 05:14:18 -0000	1.3
+++ config/cris/aout.h	25 Jul 2002 23:48:48 -0000
@@ -339,16 +339,7 @@ Boston, MA 02111-1307, USA.  */
   do								\
     {								\
       if (!flag_inhibit_size_directive)				\
-	{							\
-	  char label[256];					\
-	  static int labelno;					\
-	  							\
-	  labelno++;						\
-	  							\
-	  ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	  ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);	\
-	  ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);	\
-	}							\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
     }								\
   while (0)
 
===================================================================
Index: config/i386/freebsd-aout.h
--- config/i386/freebsd-aout.h	25 Jul 2002 05:14:19 -0000	1.12
+++ config/i386/freebsd-aout.h	25 Jul 2002 23:48:48 -0000
@@ -207,14 +207,7 @@ do {                                    
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
   do {									\
     if (!flag_inhibit_size_directive)					\
-      {									\
-        char label[256];						\
-	static int labelno;						\
-	labelno++;							\
-	ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);		\
-	ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);		\
-	ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);		\
-      }									\
+      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);				\
   } while (0)
 
 #define ASM_SPEC   " %| %{fpic:-k} %{fPIC:-k}"
===================================================================
Index: config/i386/sco5.h
--- config/i386/sco5.h	25 Jul 2002 05:14:19 -0000	1.69
+++ config/i386/sco5.h	25 Jul 2002 23:48:49 -0000
@@ -150,7 +150,7 @@ do {									\
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
   do {									\
     if (TARGET_ELF && !flag_inhibit_size_directive)			\
-      ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), ".");			\
+      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);				\
   } while (0)
 
 #undef ASM_DECLARE_OBJECT_NAME
===================================================================
Index: config/ip2k/ip2k.h
--- config/ip2k/ip2k.h	25 Jul 2002 05:14:20 -0000	1.2
+++ config/ip2k/ip2k.h	25 Jul 2002 23:48:49 -0000
@@ -2139,14 +2139,7 @@ do {						\
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
   do {								\
     if (!flag_inhibit_size_directive)				\
-      {								\
-        char label[256];					\
-	static int labelno;					\
-	labelno++;						\
-	ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);	\
-	ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);	\
-      }								\
+      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
   } while (0)
 /* A C statement (sans semicolon) to output to the stdio stream
    STREAM any text necessary for declaring the size of a function
===================================================================
Index: config/m88k/m88k.h
--- config/m88k/m88k.h	25 Jul 2002 05:14:21 -0000	1.66
+++ config/m88k/m88k.h	25 Jul 2002 23:48:50 -0000
@@ -1866,18 +1866,8 @@ do {									 \
 #undef	ASM_DECLARE_FUNCTION_SIZE
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
   do {									\
-    if (DECLARE_ASM_NAME)						\
-      {									\
-	if (!flag_inhibit_size_directive)				\
-	  {								\
-	    char label[256];						\
-	    static int labelno = 0;					\
-	    labelno++;							\
-	    ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	    ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);		\
-	    ASM_OUTPUT_MEASURED_SIZE (FILE, (FNAME), label);		\
-	  }								\
-      }									\
+    if (DECLARE_ASM_NAME && !flag_inhibit_size_directive)		\
+      ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);				\
   } while (0)
 
 /* This is how to output the definition of a user-level label named NAME,
===================================================================
Index: config/xtensa/elf.h
--- config/xtensa/elf.h	25 Jul 2002 05:14:22 -0000	1.3
+++ config/xtensa/elf.h	25 Jul 2002 23:48:50 -0000
@@ -112,16 +112,7 @@ Software Foundation, 59 Temple Place - S
   do								\
     {								\
       if (!flag_inhibit_size_directive)				\
-	{							\
-	  char label[256];					\
-	  static int labelno;					\
-	  							\
-	  labelno++;						\
-	  							\
-	  ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	  ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);	\
-	  ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME, label);	\
-	}							\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
       XTENSA_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL);		\
     }								\
   while (0)
===================================================================
Index: config/xtensa/linux.h
--- config/xtensa/linux.h	25 Jul 2002 05:14:22 -0000	1.5
+++ config/xtensa/linux.h	25 Jul 2002 23:48:50 -0000
@@ -68,16 +68,7 @@ Software Foundation, 59 Temple Place - S
   do								\
     {								\
       if (!flag_inhibit_size_directive)				\
-	{							\
-	  char label[256];					\
-	  static int labelno;					\
-	  							\
-	  labelno++;						\
-	  							\
-	  ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);	\
-	  ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);	\
-	  ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME, label);	\
-	}							\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
       XTENSA_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL);		\
     }								\
   while (0)
===================================================================
Index: doc/tm.texi
--- doc/tm.texi	25 Jul 2002 05:14:23 -0000	1.150
+++ doc/tm.texi	25 Jul 2002 23:48:54 -0000
@@ -6421,12 +6421,18 @@ If you define @code{SIZE_ASM_OP}, a defa
 provided.
 
 @findex ASM_OUTPUT_MEASURED_SIZE
-@item ASM_OUTPUT_MEASURED_SIZE (@var{stream}, @var{beg}, @var{end})
+@item ASM_OUTPUT_MEASURED_SIZE (@var{stream}, @var{name})
 A C statement (sans semicolon) to output to the stdio stream
 @var{stream} a directive telling the assembler to calculate the size of
-the symbol @var{beg} by subtracting its address from that of the symbol
-@var{end}.  If you define @code{SIZE_ASM_OP}, a default definition of
-this macro is provided.
+the symbol @var{name} by subtracting its address from the current
+address.  
+
+If you define @code{SIZE_ASM_OP}, a default definition of this macro is
+provided.  The default assumes that the assembler recognizes a special
+@samp{.} symbol as referring to the current address, and can calculate
+the difference between this and another symbol.  If your assembler does
+not recognize @samp{.} or cannot do calculations with it, you will need
+to redefine @code{ASM_OUTPUT_MEASURED_SIZE} to use some other technique.
 
 @findex TYPE_ASM_OP
 @item TYPE_ASM_OP

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

end of thread, other threads:[~2002-07-29 16:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-25 18:22 RFC/RFA: Improve definition of ASM_OUTPUT_MEASURED_SIZE Zack Weinberg
2002-07-25 19:56 ` Richard Henderson
2002-07-25 23:54   ` Zack Weinberg
2002-07-26  4:20     ` Richard Sandiford
2002-07-26 11:21       ` Richard Henderson
2002-07-26 16:35         ` Zack Weinberg
2002-07-27 14:48           ` Richard Henderson
2002-07-29 10:02         ` Mark Mitchell
2002-07-26 10:48     ` Mark Mitchell

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).