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]

[PATCH] GAS: Add ECOFF `.aent' pseudo-op support


Implement the ECOFF `.aent' pseudo-op for ECOFF-style `.mdebug' section 
support with ELF objects and, for consistency, also with ECOFF objects.  
This is so that the same MIPS source can be assembled without and with 
`.mdebug' section generation enabled.

Taking the `gas/testsuite/gas/mips/aent.s' test case source as an 
example and the `mips-linux' target we have:

$ as -o aent.o aent.s
$ as -mdebug -o aent.o aent.s
aent.s: Assembler messages:
aent.s:10: Error: unknown pseudo-op: `.aent'
$

because for the !ECOFF_DEBUGGING case (which is the default) the 
pseudo-op is already handled by the MIPS backend with `s_mips_ent', 
however no handler is present for the opposite case.

For the MIPS target this is a functional regression introduced with 
commit ecb4347adecd ("Last take: approval for MIPS_STABS_ELF killing"), 
<https://sourceware.org/ml/binutils/2002-06/msg00443.html>, where 
support for the `.mdebug' section was added along with its associated 
`-mdebug'/`-no-mdebug' command-line options, bringing an inconsistency 
between the assembly syntax supported for each of these options as far 
as the `.aent' pseudo-op is concerned.

Assembly language documentation available describes the pseudo-op 
respectively as follows[1]:

"
.aent name, symno Sets an alternate entry point for the current
                  procedure.  Use this information when you want
                  to generate information for the debugger.  It must
                  appear inside an .ent/.end pair."

and[2]:

"
.aent name [,symno]
     Sets an alternate entry point for the current procedure.  Use this
     information when you want to generate information for the debugger.
     This directive must appear between a pair of .ent and .end directives.
     (The optional symno is for compiler use only.  It refers to a dense
     number in a .T file (symbol table).)"

Copy the approach from `s_mips_ent' then and add `.aent' support to the 
`.ent' pseudo-op handler shared between the ELF and ECOFF object file 
format backends, by setting BSF_FUNCTION for the symbol requested.

References:

[1] "MIPSpro Assembly Language Programmer's Guide", Silicon Graphics,
    Inc., Document Number 007-2418-004, Section 8.1 "Op-Codes", p. 96
    <http://techpubs.sgi.com/library/manuals/2000/007-2418-004/pdf/007-2418-004.pdf>

[2] "Digital UNIX Assembly Language Programmer's Guide", Digital 
    Equipment Corporation, Order Number: AA-PS31D-TE, March 1996, 
    Chapter 5 "Assembler Directives", p. 5-2
    <http://h41361.www4.hpe.com/docs/base_doc/DOCUMENTATION/V40G_PDF/APS31DTE.PDF>

	gas/
	* ecoff.c (ecoff_directive_ent, add_procedure): Handle `.aent'.
	* config/obj-ecoff.c (obj_pseudo_table): Add "aent" entry.  
	* config/obj-elf.c (ecoff_debug_pseudo_table): Likewise.
	* testsuite/gas/mips/aent-2.d: New test.
	* testsuite/gas/mips/aent-mdebug.d: New test.
	* testsuite/gas/mips/aent-mdebug-2.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.
---
 This is covered by the test cases provided with MIPS targets only, but 
there should be no harm from adding the extra pseudo-op for other targets 
as users of those targets may simply ignore its presence if not needed.

 I haven't actually added an "aent" entry to the Alpha target's pseudo 
table, which is also why I haven't updated the documentation part.  Both 
can be easily done if needed, although a test case would also be good 
having.

 The MIPS target currently lacks documentation for its ECOFF-style 
pseudo-ops, so nothing to update here, although I do realise a new chapter 
would be desirable with their full description.

 I have examined other targets briefly and it appears some have copied and 
pasted `s_mips_ent' up to the point of quoting `.aent' in diagnostic 
messages, but without actually wiring the pseudo-op.  They might be worth 
cleaning up, but I'm going to leave them alone.

 No regressions across my usual targets.  OK to apply?

  Maciej

binutils-gas-ecoff-aent.diff
Index: binutils/gas/config/obj-ecoff.c
===================================================================
--- binutils.orig/gas/config/obj-ecoff.c	2017-02-15 13:49:50.756689887 +0000
+++ binutils/gas/config/obj-ecoff.c	2017-02-15 21:51:15.477969557 +0000
@@ -221,8 +221,8 @@ ecoff_separate_stab_sections (void)
    relating to debugging information are supported here.
 
    The following pseudo-ops from the Kane and Heinrich MIPS book
-   should be defined here, but are currently unsupported: .aent,
-   .bgnb, .endb, .verstamp, .vreg.
+   should be defined here, but are currently unsupported: .bgnb,
+   .endb, .verstamp, .vreg.
 
    The following pseudo-ops from the Kane and Heinrich MIPS book are
    MIPS CPU specific, and should be defined by tc-mips.c: .alias,
@@ -253,6 +253,7 @@ const pseudo_typeS obj_pseudo_table[] =
   { "val",	ecoff_directive_val,	0 },
 
   /* ECOFF specific debugging information.  */
+  { "aent",	ecoff_directive_ent,	1 },
   { "begin",	ecoff_directive_begin,	0 },
   { "bend",	ecoff_directive_bend,	0 },
   { "end",	ecoff_directive_end,	0 },
Index: binutils/gas/config/obj-elf.c
===================================================================
--- binutils.orig/gas/config/obj-elf.c	2017-02-15 13:49:50.766178279 +0000
+++ binutils/gas/config/obj-elf.c	2017-02-15 21:51:15.530377415 +0000
@@ -164,6 +164,7 @@ static const pseudo_typeS ecoff_debug_ps
   { "etype",	ecoff_directive_type,	0 },
 
   /* ECOFF specific debugging information.  */
+  { "aent",	ecoff_directive_ent,	1 },
   { "begin",	ecoff_directive_begin,	0 },
   { "bend",	ecoff_directive_bend,	0 },
   { "end",	ecoff_directive_end,	0 },
Index: binutils/gas/ecoff.c
===================================================================
--- binutils.orig/gas/ecoff.c	2017-02-15 13:49:50.791036459 +0000
+++ binutils/gas/ecoff.c	2017-02-15 21:51:15.575639506 +0000
@@ -1422,7 +1422,7 @@ static symint_t add_aux_sym_tir (type_in
 				 thash_t **hash_tbl);
 static tag_t *get_tag (const char *tag, localsym_t *sym, bt_t basic_type);
 static void add_unknown_tag (tag_t *ptag);
-static void add_procedure (char *func);
+static void add_procedure (char *func, int aent);
 static void add_file (const char *file_name, int indx, int fake);
 #ifdef ECOFF_DEBUG
 static char *sc_to_string (sc_t storage_class);
@@ -2109,10 +2109,11 @@ add_unknown_tag (tag_t *ptag /* pointer 
 }
 
 /* Add a procedure to the current file's list of procedures, and record
-   this is the current procedure.  */
+   this is the current procedure.  If AENT, then only set the requested
+   symbol's function type.  */
 
 static void
-add_procedure (char *func /* func name */)
+add_procedure (char *func /* func name */, int aent)
 {
   varray_t *vp;
   proc_t *new_proc_ptr;
@@ -2123,6 +2124,13 @@ add_procedure (char *func /* func name *
     fputc ('\n', stderr);
 #endif
 
+  /* Set the BSF_FUNCTION flag for the symbol.  */
+  sym = symbol_find_or_make (func);
+  symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
+
+  if (aent)
+    return;
+
   if (cur_file_ptr == (efdr_t *) NULL)
     as_fatal (_("no current file pointer"));
 
@@ -2143,10 +2151,6 @@ add_procedure (char *func /* func name *
   new_proc_ptr->pdr.lnLow = -1;
   new_proc_ptr->pdr.lnHigh = -1;
 
-  /* Set the BSF_FUNCTION flag for the symbol.  */
-  sym = symbol_find_or_make (func);
-  symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
-
   /* Push the start of the function.  */
   new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
 					sym, (bfd_vma) 0, (symint_t) 0,
@@ -3030,7 +3034,7 @@ ecoff_directive_end (int ignore ATTRIBUT
 /* Parse .ent directives.  */
 
 void
-ecoff_directive_ent (int ignore ATTRIBUTE_UNUSED)
+ecoff_directive_ent (int aent)
 {
   char *name;
   char name_end;
@@ -3038,7 +3042,7 @@ ecoff_directive_ent (int ignore ATTRIBUT
   if (cur_file_ptr == (efdr_t *) NULL)
     add_file ((const char *) NULL, 0, 1);
 
-  if (cur_proc_ptr != (proc_t *) NULL)
+  if (!aent && cur_proc_ptr != (proc_t *) NULL)
     {
       as_warn (_("second .ent directive found before .end directive"));
       demand_empty_rest_of_line ();
@@ -3049,13 +3053,13 @@ ecoff_directive_ent (int ignore ATTRIBUT
 
   if (name == input_line_pointer)
     {
-      as_warn (_(".ent directive has no name"));
+      as_warn (_("%s directive has no name"), aent ? ".aent" : ".ent");
       (void) restore_line_pointer (name_end);
       demand_empty_rest_of_line ();
       return;
     }
 
-  add_procedure (name);
+  add_procedure (name, aent);
 
   (void) restore_line_pointer (name_end);
 
Index: binutils/gas/testsuite/gas/mips/aent-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/aent-2.d	2017-02-15 21:51:22.977909838 +0000
@@ -0,0 +1,19 @@
+#PROG: readelf
+#readelf: -s
+#name: MIPS .aent directive 2
+#as: -32
+#source: aent.s
+
+# Verify that the .aent directive retains function symbol type annotation,
+# e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      8: 00000000    16 FUNC    GLOBAL DEFAULT    1 foo
+#      9: 00000008     0 FUNC    GLOBAL DEFAULT    1 bar
+# vs:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      8: 00000000    16 FUNC    GLOBAL DEFAULT    1 foo
+#      9: 00000008     0 OBJECT  GLOBAL DEFAULT    1 bar
+#...
+ *[0-9]+: +[0-9]+ +[0-9]+ +FUNC +GLOBAL +DEFAULT(?: +\[[^]]*\])? +[0-9]+ foo
+ *[0-9]+: +[0-9]+ +[0-9]+ +FUNC +GLOBAL +DEFAULT(?: +\[[^]]*\])? +[0-9]+ bar
+#pass
Index: binutils/gas/testsuite/gas/mips/aent-mdebug-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/aent-mdebug-2.d	2017-02-15 21:51:22.993108879 +0000
@@ -0,0 +1,16 @@
+#PROG: readelf
+#readelf: -s
+#name: MIPS .aent directive with ECOFF debug 2
+#as: -32 -mdebug
+#source: aent.s
+#dump: aent-2.d
+
+# Verify that the .aent directive retains function symbol type annotation,
+# e.g.:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      8: 00000000    16 FUNC    GLOBAL DEFAULT    1 foo
+#      9: 00000008     0 FUNC    GLOBAL DEFAULT    1 bar
+# vs:
+#    Num:    Value  Size Type    Bind   Vis      Ndx Name
+#      8: 00000000    16 FUNC    GLOBAL DEFAULT    1 foo
+#      9: 00000008     0 OBJECT  GLOBAL DEFAULT    1 bar
Index: binutils/gas/testsuite/gas/mips/aent-mdebug.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/aent-mdebug.d	2017-02-15 21:51:23.027435491 +0000
@@ -0,0 +1,7 @@
+#objdump: -dr --prefix-addresses
+#name: MIPS .aent directive with ECOFF debug
+#as: -32 -mdebug
+#source: aent.s
+#dump: aent.d
+
+# Test the .aent directive retains function symbol type annotation.
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp	2017-02-15 13:49:50.395152292 +0000
+++ binutils/gas/testsuite/gas/mips/mips.exp	2017-02-15 21:51:23.039574256 +0000
@@ -1191,7 +1191,11 @@ if { [istarget mips*-*-vxworks*] } {
 					    !micromips]
     }
 
-    run_dump_test_arches "aent"	[mips_arch_list_matching mips1]
+    run_dump_test_arches "aent"		[mips_arch_list_matching mips1]
+    run_dump_test_arches "aent-2"	[mips_arch_list_matching mips1]
+    run_dump_test_arches "aent-mdebug"	[mips_arch_list_matching mips1]
+    run_dump_test_arches "aent-mdebug-2" \
+					[mips_arch_list_matching mips1]
 
     run_dump_test_arches "loc-swap"	[mips_arch_list_all]
     run_dump_test_arches "loc-swap-dis"	[mips_arch_list_all]


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