[PATCH 2/2] gas: properly check for ELF in LISTING_NODEBUG handling

Jan Beulich jbeulich@suse.com
Fri Aug 23 10:32:36 GMT 2024


While OBJ_MAYBE_ELF presently implies OBJ_ELF (due to obj-multi.h
including obj-elf.h for obscure reasons), there still need to be IS_ELF
checks to cover for the OBJ_MAYBE_ELF case. Note, however, that code
checking for ->debugging being true doesn't need such extra checks, as
the field can only ever be true when IS_ELF.

On the same basis reduce #ifdef-ary in debugging_pseudo().

Also move the field (into what on 64-bit architectures is a 32-bit gap)
and put it inside an OBJ_ELF conditional, too.

While there further switch int to bool in related code.

--- a/gas/listing.c
+++ b/gas/listing.c
@@ -176,13 +176,16 @@ struct list_info_struct
   /* Pointers to linked list of messages associated with this line.  */
   struct list_message *messages, *last_message;
 
-  enum edict_enum edict;
-  char *edict_arg;
-
+#ifdef OBJ_ELF
   /* Nonzero if this line is to be omitted because it contains
      debugging information.  This can become a flags field if we come
      up with more information to store here.  */
-  int debugging;
+  bool debugging;
+#endif
+
+  enum edict_enum edict;
+  char *edict_arg;
+
 };
 
 typedef struct list_info_struct list_info_type;
@@ -226,7 +229,6 @@ static unsigned int calc_hex (list_info_
 static void print_lines (list_info_type *, unsigned int, const char *,
 			 unsigned int);
 static void list_symbol_table (void);
-static int debugging_pseudo (list_info_type *, const char *);
 static void listing_listing (char *);
 
 static void
@@ -311,7 +313,8 @@ listing_newline (char *ps)
      considered to be debugging information.  This includes the
      statement which switches us into the debugging section, which we
      can only set after we are already in the debugging section.  */
-  if ((listing & LISTING_NODEBUG) != 0
+  if (IS_ELF
+      && (listing & LISTING_NODEBUG) != 0
       && listing_tail != NULL
       && ! listing_tail->debugging)
     {
@@ -320,7 +323,7 @@ listing_newline (char *ps)
       segname = segment_name (now_seg);
       if (startswith (segname, ".debug")
 	  || startswith (segname, ".line"))
-	listing_tail->debugging = 1;
+	listing_tail->debugging = true;
     }
 #endif
 
@@ -421,13 +424,13 @@ listing_newline (char *ps)
   new_i->edict = EDICT_NONE;
   new_i->hll_file = (file_info_type *) NULL;
   new_i->hll_line = 0;
-  new_i->debugging = 0;
 
   new_frag ();
 
 #ifdef OBJ_ELF
   /* In ELF, anything in a section beginning with .debug or .line is
      considered to be debugging information.  */
+  new_i->debugging = false;
   if ((listing & LISTING_NODEBUG) != 0)
     {
       const char *segname;
@@ -435,7 +438,7 @@ listing_newline (char *ps)
       segname = segment_name (now_seg);
       if (startswith (segname, ".debug")
 	  || startswith (segname, ".line"))
-	new_i->debugging = 1;
+	new_i->debugging = true;
     }
 #endif
 }
@@ -1120,24 +1123,20 @@ print_source (file_info_type *  current_
 /* Sometimes the user doesn't want to be bothered by the debugging
    records inserted by the compiler, see if the line is suspicious.  */
 
-static int
-debugging_pseudo (list_info_type *list, const char *line)
+static bool
+debugging_pseudo (list_info_type *list ATTRIBUTE_UNUSED, const char *line)
 {
 #ifdef OBJ_ELF
-  static int in_debug;
-  int was_debug;
-#endif
+  static bool in_debug;
+  bool was_debug;
 
   if (list->debugging)
     {
-#ifdef OBJ_ELF
-      in_debug = 1;
-#endif
-      return 1;
+      in_debug = true;
+      return true;
     }
-#ifdef OBJ_ELF
   was_debug = in_debug;
-  in_debug = 0;
+  in_debug = false;
 #endif
 
   while (ISSPACE (*line))
@@ -1156,42 +1155,42 @@ debugging_pseudo (list_info_type *list,
 	  && list->next != NULL
 	  && list->next->debugging)
 	{
-	  in_debug = 1;
-	  return 1;
+	  in_debug = true;
+	  return true;
 	}
 #endif
 
-      return 0;
+      return false;
     }
 
   line++;
 
   if (startswith (line, "def"))
-    return 1;
+    return true;
   if (startswith (line, "val"))
-    return 1;
+    return true;
   if (startswith (line, "scl"))
-    return 1;
+    return true;
   if (startswith (line, "line"))
-    return 1;
+    return true;
   if (startswith (line, "endef"))
-    return 1;
+    return true;
   if (startswith (line, "ln"))
-    return 1;
+    return true;
   if (startswith (line, "type"))
-    return 1;
+    return true;
   if (startswith (line, "size"))
-    return 1;
+    return true;
   if (startswith (line, "dim"))
-    return 1;
+    return true;
   if (startswith (line, "tag"))
-    return 1;
+    return true;
   if (startswith (line, "stabs"))
-    return 1;
+    return true;
   if (startswith (line, "stabn"))
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
 static void



More information about the Binutils mailing list