public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* A comment-finding hack for hppa I found useful
@ 2000-07-11  1:03 Alan Modra
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Modra @ 2000-07-11  1:03 UTC (permalink / raw)
  To: binutils

Hello all,
   I found the following hack useful when debugging glibc sources for
hppa.  The comment in the first hunk below indicates why it's useful, but
I'm ambivalent as to whether this belongs in the official sources.
However if the general consensus (this ain't a democracy - some people 
have weightier votes than others!) is to put this in, I'll do so.  In any
case, posting it here means those who find the hack useful can use it.

Regards, Alan Modra
-- 
Linuxcare.  Support for the Revolution.

PS. Question for the language experts.  "#if MACRO" or "#ifdef MACRO",
which is preferred?  Given MACRO is either undefined or evaluates to 1,
there is no difference really (except I believe some really old compilers
don't even supprt #ifdef)


gas/ChangeLog
	* as.h (warn_comment, found_comment, found_comment_file): Declare.
	* app.c (do_scrub_chars): Record where first comment found.
	* read.c (read_a_source_file): Init found_comment on entry, and
	notify whether comments found on exit.
	* config/tc-hppa.c (md_shortopts): Add "c".
	(md_longopts): Add warn-comment.
	(md_parse_option): Handle it.
	* config/te-linux.h (FIND_HPPA_COMMENTS): Define to TC_HPPA.
	* config/te-hppalinux64.h (FIND_HPPA_COMMENTS): Likewise.

Index: as.h
===================================================================
RCS file: /cvs/src/src/gas/as.h,v
retrieving revision 1.13
diff -u -p -r1.13 as.h
--- as.h	2000/05/08 10:24:05	1.13
+++ as.h	2000/07/11 06:58:42
@@ -640,6 +640,17 @@ COMMON int flag_m68k_mri;
 #define flag_m68k_mri 0
 #endif
 
+#if FIND_HPPA_COMMENTS
+/* Define to compile in an extra assembler option, -c, which enables a
+   warning (once per file) when a comment is encountered.
+   The hppa comment char is a `;' which tends to occur in random C asm
+   statements.  A semicolon is a line separator for most assemblers.
+   It's hard to find these lurking semicolons.  Thus...  */
+COMMON int warn_comment;
+COMMON unsigned int found_comment;
+COMMON char *found_comment_file;
+#endif
+
 #ifndef NUMBERS_WITH_SUFFIX
 #define NUMBERS_WITH_SUFFIX 0
 #endif
Index: app.c
===================================================================
RCS file: /cvs/src/src/gas/app.c,v
retrieving revision 1.10
diff -u -p -r1.10 app.c
--- app.c	2000/06/09 00:00:02	1.10
+++ app.c	2000/07/11 06:58:40
@@ -1171,6 +1171,10 @@ do_scrub_chars (get, tostart, tolen)
 	  if ((symver_state != NULL) && (*symver_state == 0))
 	    goto de_fault;
 #endif
+#if FIND_HPPA_COMMENTS
+	  if (!found_comment)
+	    as_where (&found_comment_file, &found_comment);
+#endif
 	  do
 	    {
 	      ch = GET ();
Index: read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.24
diff -u -p -r1.24 read.c
--- read.c	2000/06/09 00:00:02	1.24
+++ read.c	2000/07/11 06:58:54
@@ -526,6 +526,10 @@ read_a_source_file (name)
   register int temp;
   pseudo_typeS *pop;
 
+#if FIND_HPPA_COMMENTS
+  found_comment = 0;
+#endif
+
   buffer = input_scrub_new_file (name);
 
   listing_file (name);
@@ -1098,6 +1102,13 @@ read_a_source_file (name)
   md_cleanup();
 #endif
   input_scrub_close ();		/* Close the input file */
+#if FIND_HPPA_COMMENTS
+  {
+    if (warn_comment && found_comment)
+      as_warn_where (found_comment_file, found_comment,
+		     "first comment found here");
+  }
+#endif
 }
 
 /* For most MRI pseudo-ops, the line actually ends at the first
Index: config/tc-hppa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.c,v
retrieving revision 1.59
diff -u -p -r1.59 tc-hppa.c
--- tc-hppa.c	2000/07/10 15:15:01	1.59
+++ tc-hppa.c	2000/07/11 06:59:10
@@ -4345,12 +4345,23 @@ md_estimate_size_before_relax (fragP, se
 }
 \f
 #ifdef OBJ_ELF
+# if FIND_HPPA_COMMENTS
+const char *md_shortopts = "Vc";
+# else
 const char *md_shortopts = "V";
+# endif
 #else
+# if FIND_HPPA_COMMENTS
+const char *md_shortopts = "c";
+# else
 const char *md_shortopts = "";
+# endif
 #endif
 
 struct option md_longopts[] = {
+#if FIND_HPPA_COMMENTS
+  {"warn-comment", no_argument, NULL, 'c'},
+#endif
   {NULL, no_argument, NULL, 0}
 };
 size_t md_longopts_size = sizeof(md_longopts);
@@ -4370,6 +4381,11 @@ md_parse_option (c, arg)
       print_version_id ();
       break;
 #endif
+#if FIND_HPPA_COMMENTS
+    case 'c':
+      warn_comment = 1;
+      break;
+#endif
     }
 
   return 1;
@@ -4431,7 +4447,7 @@ md_apply_fix (fixP, valp)
     }
 #endif
 
-  insn = bfd_get_32 (stdoutput, (unsigned char *)buf);
+  insn = bfd_get_32 (stdoutput, (unsigned char *) buf);
   /* There should have been an HPPA specific fixup associated
      with the GAS fixup.  */
   if (hppa_fixP)
Index: config/te-hppalinux64.h
===================================================================
RCS file: /cvs/src/src/gas/config/te-hppalinux64.h,v
retrieving revision 1.1
diff -u -p -r1.1 te-hppalinux64.h
--- te-hppalinux64.h	2000/07/09 08:16:21	1.1
+++ te-hppalinux64.h	2000/07/11 06:59:12
@@ -1,5 +1,13 @@
 #define TE_LINUX
 #define TARGET_ARCH_SIZE 64
 #define LOCAL_LABELS_FB 1
+#if 1
+/* Define to compile in an extra assembler option, -c, which enables a
+   warning (once per file) when a comment is encountered.
+   The hppa comment char is a `;' which tends to occur in random C asm
+   statements.  A semicolon is a line separator for most assemblers.
+   It's hard to find these lurking semicolons.  Thus...  */
+#define FIND_HPPA_COMMENTS TC_HPPA
+#endif
 
 #include "obj-format.h"
Index: config/te-linux.h
===================================================================
RCS file: /cvs/src/src/gas/config/te-linux.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 te-linux.h
--- te-linux.h	1999/05/03 07:28:44	1.1.1.1
+++ te-linux.h	2000/07/11 06:59:12
@@ -1,4 +1,12 @@
 #define TE_LINUX
 #define LOCAL_LABELS_FB 1
+#if 1
+/* Define to compile in an extra assembler option, -c, which enables a
+   warning (once per file) when a comment is encountered.
+   The hppa comment char is a `;' which tends to occur in random C asm
+   statements.  A semicolon is a line separator for most assemblers.
+   It's hard to find these lurking semicolons.  Thus...  */
+#define FIND_HPPA_COMMENTS TC_HPPA
+#endif
 
 #include "obj-format.h"

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

* Re: A comment-finding hack for hppa I found useful
  2000-07-11 12:10 Nick Clifton
                   ` (2 preceding siblings ...)
  2000-07-12 15:37 ` Michael Meissner
@ 2000-07-27 22:03 ` Alan Modra
  3 siblings, 0 replies; 8+ messages in thread
From: Alan Modra @ 2000-07-27 22:03 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

Hi Nick,
  I've cleaned up this patch a little, taking into account the preference
stated here for using #ifdef rather than #if, and commited it.

Regards, Alan
-- 
Linuxcare.  Support for the Revolution.


gas/ChangeLog
	* as.h (warn_comment, found_comment, found_comment_file): Declare.
	* app.c (do_scrub_chars): Record where first comment found.
	* read.c (read_a_source_file): Init found_comment on entry, and
	notify whether comments found on exit.
	* config/tc-hppa.c (md_shortopts): Add "c".
	(md_longopts): Add warn-comment.
	(md_parse_option): Handle it.
	(md_show_usage): Show available options.
	* config/tc-hppa.h (WARN_COMMENTS): Define if TE_LINUX

Index: app.c
===================================================================
RCS file: /cvs/src/src/gas/app.c,v
retrieving revision 1.10
diff -u -p -r1.10 app.c
--- app.c	2000/06/09 00:00:02	1.10
+++ app.c	2000/07/28 03:20:44
@@ -1171,6 +1171,10 @@ do_scrub_chars (get, tostart, tolen)
 	  if ((symver_state != NULL) && (*symver_state == 0))
 	    goto de_fault;
 #endif
+#ifdef WARN_COMMENTS
+	  if (!found_comment)
+	    as_where (&found_comment_file, &found_comment);
+#endif
 	  do
 	    {
 	      ch = GET ();
Index: as.h
===================================================================
RCS file: /cvs/src/src/gas/as.h,v
retrieving revision 1.13
diff -u -p -r1.13 as.h
--- as.h	2000/05/08 10:24:05	1.13
+++ as.h	2000/07/28 03:20:46
@@ -640,6 +640,12 @@ COMMON int flag_m68k_mri;
 #define flag_m68k_mri 0
 #endif
 
+#ifdef WARN_COMMENTS
+COMMON int warn_comment;
+COMMON unsigned int found_comment;
+COMMON char *found_comment_file;
+#endif
+
 #ifndef NUMBERS_WITH_SUFFIX
 #define NUMBERS_WITH_SUFFIX 0
 #endif
Index: read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.25
diff -u -p -r1.25 read.c
--- read.c	2000/07/20 17:12:25	1.25
+++ read.c	2000/07/28 03:20:58
@@ -521,6 +521,10 @@ read_a_source_file (name)
   register int temp;
   pseudo_typeS *pop;
 
+#ifdef WARN_COMMENTS
+  found_comment = 0;
+#endif
+
   buffer = input_scrub_new_file (name);
 
   listing_file (name);
@@ -1082,6 +1086,13 @@ read_a_source_file (name)
 #endif
   /* Close the input file.  */
   input_scrub_close ();
+#ifdef WARN_COMMENTS
+  {
+    if (warn_comment && found_comment)
+      as_warn_where (found_comment_file, found_comment,
+		     "first comment found here");
+  }
+#endif
 }
 
 /* For most MRI pseudo-ops, the line actually ends at the first
Index: config/tc-hppa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.c,v
retrieving revision 1.61
diff -u -p -r1.61 tc-hppa.c
--- tc-hppa.c	2000/07/19 06:30:49	1.61
+++ tc-hppa.c	2000/07/28 03:21:15
@@ -4345,12 +4345,23 @@ md_estimate_size_before_relax (fragP, se
 }
 \f
 #ifdef OBJ_ELF
+# ifdef WARN_COMMENTS
+const char *md_shortopts = "Vc";
+# else
 const char *md_shortopts = "V";
+# endif
 #else
+# ifdef WARN_COMMENTS
+const char *md_shortopts = "c";
+# else
 const char *md_shortopts = "";
+# endif
 #endif
 
 struct option md_longopts[] = {
+#ifdef WARN_COMMENTS
+  {"warn-comment", no_argument, NULL, 'c'},
+#endif
   {NULL, no_argument, NULL, 0}
 };
 size_t md_longopts_size = sizeof(md_longopts);
@@ -4370,6 +4381,11 @@ md_parse_option (c, arg)
       print_version_id ();
       break;
 #endif
+#ifdef WARN_COMMENTS
+    case 'c':
+      warn_comment = 1;
+      break;
+#endif
     }
 
   return 1;
@@ -4379,6 +4395,14 @@ void
 md_show_usage (stream)
      FILE *stream ATTRIBUTE_UNUSED;
 {
+#ifdef OBJ_ELF
+  fprintf (stream, _("\
+  -Q                      ignored\n"));
+#endif
+#ifdef WARN_COMMENTS
+  fprintf (stream, _("\
+  -c                      print a warning if a comment is found\n"));
+#endif
 }
 \f
 /* We have no need to default values of symbols.  */
Index: config/tc-hppa.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.h,v
retrieving revision 1.8
diff -u -p -r1.8 tc-hppa.h
--- tc-hppa.h	2000/07/09 08:16:21	1.8
+++ tc-hppa.h	2000/07/28 03:21:15
@@ -61,6 +61,15 @@
 #define TARGET_FORMAT "som"
 #endif
 
+#ifdef TE_LINUX
+/* Define to compile in an extra assembler option, -c, which enables a
+   warning (once per file) when a comment is encountered.
+   The hppa comment char is a `;' which tends to occur in random C asm
+   statements.  A semicolon is a line separator for most assemblers.
+   It's hard to find these lurking semicolons.  Thus...  */
+#define WARN_COMMENTS 1
+#endif
+
 /* FIXME.  Why oh why aren't these defined somewhere globally?  */
 #ifndef FALSE
 #define FALSE   (0)

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

* Re: A comment-finding hack for hppa I found useful
  2000-07-12 15:37 ` Michael Meissner
  2000-07-12 15:48   ` Ulrich Drepper
@ 2000-07-12 18:11   ` Alan Modra
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Modra @ 2000-07-12 18:11 UTC (permalink / raw)
  To: Michael Meissner; +Cc: binutils

On Wed, 12 Jul 2000, Michael Meissner wrote:

> > : PS. Question for the language experts.  "#if MACRO" or "#ifdef MACRO",
> > : which is preferred?  Given MACRO is either undefined or evaluates to 1,
> > : there is no difference really (except I believe some really old compilers
> > : don't even supprt #ifdef)
> 
> At the time of the original C standard was being produced (1984 or 1985 being
> the first meeting), there were no known compilers still in use that did not
> support #ifdef (K&R-1 mentions both #ifdef and #if).  I do recall having
> #ifdef's and a preprocessor when I was working on a UNIX V6 system in 1979
> (though you had to make sure the first byte of the file was '#' or else the
> preprocessor was not run, and it had the original wacky structure rules).  The
> default compiler on SunOS does support #if name and #if defined(name).

My faulty memory playing tricks again.  It's not #ifdef that is missing in
some compilers, it's "#if defined (name)".  I even remembered where I saw
this first: nethack include/config.h :-)

-- 
Linuxcare.  Support for the Revolution.

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

* Re: A comment-finding hack for hppa I found useful
  2000-07-12 15:37 ` Michael Meissner
@ 2000-07-12 15:48   ` Ulrich Drepper
  2000-07-12 18:11   ` Alan Modra
  1 sibling, 0 replies; 8+ messages in thread
From: Ulrich Drepper @ 2000-07-12 15:48 UTC (permalink / raw)
  To: Michael Meissner; +Cc: Nick Clifton, binutils

Michael Meissner <meissner@cygnus.com> writes:

> At the time of the original C standard was being produced (1984 or 1985 being
> the first meeting), there were no known compilers still in use that did not
> support #ifdef (K&R-1 mentions both #ifdef and #if).  I do recall having
> #ifdef's and a preprocessor when I was working on a UNIX V6 system in 1979

I don't know about a compiler with this problem either.  But the
opposite is the case: there are compilers without #if.  The Plan 9
compiler has (had?) no #if.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

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

* Re: A comment-finding hack for hppa I found useful
  2000-07-11 12:10 Nick Clifton
  2000-07-11 13:24 ` Jeffrey A Law
  2000-07-11 19:51 ` Alan Modra
@ 2000-07-12 15:37 ` Michael Meissner
  2000-07-12 15:48   ` Ulrich Drepper
  2000-07-12 18:11   ` Alan Modra
  2000-07-27 22:03 ` Alan Modra
  3 siblings, 2 replies; 8+ messages in thread
From: Michael Meissner @ 2000-07-12 15:37 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Tue, Jul 11, 2000 at 12:10:52PM -0700, Nick Clifton wrote:
> Hi Alan,
> 
> :    I found the following hack useful when debugging glibc sources
> : for hppa.  The comment in the first hunk below indicates why it's
> : useful, but I'm ambivalent as to whether this belongs in the
> : official sources.
> 
> So basically the problem is that (for the hppa) the comment chracater,
> (';') is the same as the line seperator character for lots of other
> assemblers, and that tihs leads to confusion, especially when writing
> C asm statements ?
> 
> I guess I have no objections to adding the feature, although I think
> that it will only very occaisionally be useful.  perhaps it could be
> part of the output with the -D switch ?
> 
> : PS. Question for the language experts.  "#if MACRO" or "#ifdef MACRO",
> : which is preferred?  Given MACRO is either undefined or evaluates to 1,
> : there is no difference really (except I believe some really old compilers
> : don't even supprt #ifdef)

At the time of the original C standard was being produced (1984 or 1985 being
the first meeting), there were no known compilers still in use that did not
support #ifdef (K&R-1 mentions both #ifdef and #if).  I do recall having
#ifdef's and a preprocessor when I was working on a UNIX V6 system in 1979
(though you had to make sure the first byte of the file was '#' or else the
preprocessor was not run, and it had the original wacky structure rules).  The
default compiler on SunOS does support #if name and #if defined(name).

> I had not heard about old compilers not supporting #ifdef, but I think
> from a very strict point of view, I would prefer '#ifdef MACRO" over
> "#if MACRO" since this makes clear that all that is being tested is
> the fact that MACRO is defined, not what value it might happen to
> have.

I agree with Nick.

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

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

* Re: A comment-finding hack for hppa I found useful
  2000-07-11 12:10 Nick Clifton
  2000-07-11 13:24 ` Jeffrey A Law
@ 2000-07-11 19:51 ` Alan Modra
  2000-07-12 15:37 ` Michael Meissner
  2000-07-27 22:03 ` Alan Modra
  3 siblings, 0 replies; 8+ messages in thread
From: Alan Modra @ 2000-07-11 19:51 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Tue, 11 Jul 2000, Nick Clifton wrote:

> :    I found the following hack useful when debugging glibc sources
> : for hppa.  The comment in the first hunk below indicates why it's
> : useful, but I'm ambivalent as to whether this belongs in the
> : official sources.
> 
> So basically the problem is that (for the hppa) the comment chracater,
> (';') is the same as the line seperator character for lots of other
> assemblers, and that tihs leads to confusion, especially when writing
> C asm statements ?

Yup.  Taking an example from current glibc sources: include/libc-symbols.h

#   define __make_section_unallocated(section_string)   \
  asm(".section " section_string "; .previous");

Here, the ".previous" is treated as a comment by hppa gas.  I sent a patch
to Ulrich Drepper for this a long time ago, but it hasn't gone in (and in
case Ulrich is reading this, there's no pressing need for it to go in yet
as hppa-linux glibc needs quite a bit of work) 

> I guess I have no objections to adding the feature, although I think
> that it will only very occaisionally be useful.  perhaps it could be
> part of the output with the -D switch ?

Yes, that would be reasonable.  I just picked `-c' as an unused letter.

-- 
Linuxcare.  Support for the Revolution.

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

* Re: A comment-finding hack for hppa I found useful
  2000-07-11 12:10 Nick Clifton
@ 2000-07-11 13:24 ` Jeffrey A Law
  2000-07-11 19:51 ` Alan Modra
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Jeffrey A Law @ 2000-07-11 13:24 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

  In message < 200007111910.MAA17553@elmo.cygnus.com >you write:
  > So basically the problem is that (for the hppa) the comment chracater,
  > (';') is the same as the line seperator character for lots of other
  > assemblers, and that tihs leads to confusion, especially when writing
  > C asm statements ?
Yup.  What's just as fun is the line separator is a comment in some
other assemblers, a binary operation, and a completer for certain
instructions :-)

Let's just say PA assembly isn't fun.


  > I guess I have no objections to adding the feature, although I think
  > that it will only very occaisionally be useful.  perhaps it could be
  > part of the output with the -D switch ?
Possibly.


  > : PS. Question for the language experts.  "#if MACRO" or "#ifdef MACRO",
  > : which is preferred?  Given MACRO is either undefined or evaluates to 1,
  > : there is no difference really (except I believe some really old compilers
  > : don't even supprt #ifdef)
  > 
  > I had not heard about old compilers not supporting #ifdef, but I think
  > from a very strict point of view, I would prefer '#ifdef MACRO" over
  > "#if MACRO" since this makes clear that all that is being tested is
  > the fact that MACRO is defined, not what value it might happen to
  > have.
Agreed.
jeff

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

* Re: A comment-finding hack for hppa I found useful
@ 2000-07-11 12:10 Nick Clifton
  2000-07-11 13:24 ` Jeffrey A Law
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Nick Clifton @ 2000-07-11 12:10 UTC (permalink / raw)
  To: binutils

Hi Alan,

:    I found the following hack useful when debugging glibc sources
: for hppa.  The comment in the first hunk below indicates why it's
: useful, but I'm ambivalent as to whether this belongs in the
: official sources.

So basically the problem is that (for the hppa) the comment chracater,
(';') is the same as the line seperator character for lots of other
assemblers, and that tihs leads to confusion, especially when writing
C asm statements ?

I guess I have no objections to adding the feature, although I think
that it will only very occaisionally be useful.  perhaps it could be
part of the output with the -D switch ?

: PS. Question for the language experts.  "#if MACRO" or "#ifdef MACRO",
: which is preferred?  Given MACRO is either undefined or evaluates to 1,
: there is no difference really (except I believe some really old compilers
: don't even supprt #ifdef)

I had not heard about old compilers not supporting #ifdef, but I think
from a very strict point of view, I would prefer '#ifdef MACRO" over
"#if MACRO" since this makes clear that all that is being tested is
the fact that MACRO is defined, not what value it might happen to
have.

Cheers
	Nick

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

end of thread, other threads:[~2000-07-27 22:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-11  1:03 A comment-finding hack for hppa I found useful Alan Modra
2000-07-11 12:10 Nick Clifton
2000-07-11 13:24 ` Jeffrey A Law
2000-07-11 19:51 ` Alan Modra
2000-07-12 15:37 ` Michael Meissner
2000-07-12 15:48   ` Ulrich Drepper
2000-07-12 18:11   ` Alan Modra
2000-07-27 22:03 ` 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).