Fix .dwsect generation for XCOFF. Handle .function generated with DWARF on XCOFF.
authorCl?ment Chigot <clement.chigot@atos.net>
Fri, 7 May 2021 14:29:49 +0000 (15:29 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 7 May 2021 14:29:49 +0000 (15:29 +0100)
gas * config/tc-ppc.c (ppc_function): Update comment for
fifth argument.
(ppc_frob_symbol): Remove ppc_last_function check.
Make sure coff_last_function is reset.
Correctly set fsize when not provided in .function.
* testsuite/gas/ppc/aix.exp: New tests.
* testsuite/gas/ppc/xcoff-function-1-32.d: New test.
* testsuite/gas/ppc/xcoff-function-1-64.d: New test.
* testsuite/gas/ppc/xcoff-function-1.s: New test.

bfd * coff-rs6000.c (xcoff_dwsect_names): Add new DWARF
sections.
* coffgen.c (coff_pointerize_aux): Handle C_DWARF.
(coff_print_symbol): Likewise.
* libxcoff.h (XCOFF_DWSECT_NBR_NAMES): Update.

gas * config/obj-coff.c (coff_frob_symbol): Don't skip C_DWARF.
(coff_adjust_section_syms): Use corrext auxent for C_DWARF.
(coff_frob_section): Likewise.
* config/obj-coff.h (SA_GET_SECT_SCNLEN,
SA_GET_SECT_NRELOC, SA_SET_SECT_SCNLEN,
SA_SET_SECT_NRELOC) New defines.
(SET_SECTION_RELOCS): Adjust for C_DWARF.
* config/tc-ppc.c (ppc_frob_symbol): Don't skip C_DWARF.
(ppc_adjust_symtab): Reorder C_DWARF symbols.
* testsuite/gas/ppc/aix.exp: New tests.
* testsuite/gas/ppc/xcoff-dwsect-2-32.d: New test.
* testsuite/gas/ppc/xcoff-dwsect-2-64.d: New test.
* testsuite/gas/ppc/xcoff-dwsect-2.s: New test.

include * coff/internal.h (C_DWARF): New define.
* coff/xcoff.h (SSUBTYP_DWLOC, SSUBTYP_DWFRAME,
SSUBTYP_DWMAC): New defines.

18 files changed:
bfd/ChangeLog
bfd/coff-rs6000.c
bfd/coffgen.c
bfd/libxcoff.h
gas/ChangeLog
gas/config/obj-coff.c
gas/config/obj-coff.h
gas/config/tc-ppc.c
gas/testsuite/gas/ppc/aix.exp
gas/testsuite/gas/ppc/xcoff-dwsect-2-32.d [new file with mode: 0644]
gas/testsuite/gas/ppc/xcoff-dwsect-2-64.d [new file with mode: 0644]
gas/testsuite/gas/ppc/xcoff-dwsect-2.s [new file with mode: 0644]
gas/testsuite/gas/ppc/xcoff-function-1-32.d [new file with mode: 0644]
gas/testsuite/gas/ppc/xcoff-function-1-64.d [new file with mode: 0644]
gas/testsuite/gas/ppc/xcoff-function-1.s [new file with mode: 0644]
include/ChangeLog
include/coff/internal.h
include/coff/xcoff.h

index dd517a9d8104b5285aed69c62152a34b055b0f0a..e0a1e2348a0309d958233aa3b2f0bc44a48cda46 100644 (file)
@@ -1,3 +1,11 @@
+2021-05-07  Clément Chigot  <clement.chigot@atos.net>
+
+       * coff-rs6000.c (xcoff_dwsect_names): Add new DWARF
+       sections.
+       * coffgen.c (coff_pointerize_aux): Handle C_DWARF.
+       (coff_print_symbol): Likewise.
+       * libxcoff.h (XCOFF_DWSECT_NBR_NAMES): Update.
+
 2021-05-07  Jan Beulich  <jbeulich@suse.com>
 
        * elf64-x86-64.c (x86_64_elf_howto_table): Set src_mask fields
index 0745421cf11d5860a9a4540d8d079c35397b8434..45ba9b3cb0038fc8d6a8489679d836be920b4902 100644 (file)
@@ -4265,7 +4265,10 @@ const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
   { SSUBTYP_DWARNGE, ".dwarnge",  true },
   { SSUBTYP_DWABREV, ".dwabrev",  false },
   { SSUBTYP_DWSTR,   ".dwstr",    true },
-  { SSUBTYP_DWRNGES, ".dwrnges",  true }
+  { SSUBTYP_DWRNGES, ".dwrnges",  true },
+  { SSUBTYP_DWLOC,   ".dwloc",    true },
+  { SSUBTYP_DWFRAME, ".dwframe",  true },
+  { SSUBTYP_DWMAC,   ".dwmac",    true }
 };
 
 /* For generic entry points.  */
index 4e1424302025c54feb8c68605fb49b8f098c254f..b13e7732962bcdc52b6e66d1291b5da46d11a5e1 100644 (file)
@@ -1527,6 +1527,8 @@ coff_pointerize_aux (bfd *abfd,
     return;
   if (n_sclass == C_FILE)
     return;
+  if (n_sclass == C_DWARF)
+    return;
 
   BFD_ASSERT (! auxent->is_sym);
   /* Otherwise patch up.  */
@@ -2123,6 +2125,12 @@ coff_print_symbol (bfd *abfd,
                  fprintf (file, "File ");
                  break;
 
+               case C_DWARF:
+                 fprintf (file, "AUX scnlen 0x%lx nreloc %ld",
+                          (unsigned long) auxp->u.auxent.x_sect.x_scnlen,
+                          auxp->u.auxent.x_sect.x_nreloc);
+                 break;
+
                case C_STAT:
                  if (combined->u.syment.n_type == T_NULL)
                    /* Probably a section symbol ?  */
index cca9c21803347a9aaeeee8a40a8548edd46ea448..2eeb503d5488d88a8f3db1a0409715b5d13b0628 100644 (file)
@@ -252,7 +252,7 @@ struct xcoff_dwsect_name {
 
 /* Number of entries in the array.  The number is known and public so that user
    can 'extend' this array by index.  */
-#define XCOFF_DWSECT_NBR_NAMES 8
+#define XCOFF_DWSECT_NBR_NAMES 11
 
 /* The dwarf sections array.  */
 extern const struct xcoff_dwsect_name
index b04a764f2a8e346b43fb59f638d051849e76ab5f..b5c358d887acaea4232c64d974b194c7bf4881b7 100644 (file)
@@ -1,3 +1,29 @@
+2021-05-07  Clément Chigot  <clement.chigot@atos.net>
+
+       * config/obj-coff.c (coff_frob_symbol): Don't skip C_DWARF.
+       (coff_adjust_section_syms): Use corrext auxent for C_DWARF.
+       (coff_frob_section): Likewise.
+       * config/obj-coff.h (SA_GET_SECT_SCNLEN,
+       SA_GET_SECT_NRELOC, SA_SET_SECT_SCNLEN,
+       SA_SET_SECT_NRELOC) New defines.
+       (SET_SECTION_RELOCS): Adjust for C_DWARF.
+       * config/tc-ppc.c (ppc_frob_symbol): Don't skip C_DWARF.
+       (ppc_adjust_symtab): Reorder C_DWARF symbols.
+       * testsuite/gas/ppc/aix.exp: New tests.
+       * testsuite/gas/ppc/xcoff-dwsect-2-32.d: New test.
+       * testsuite/gas/ppc/xcoff-dwsect-2-64.d: New test.
+       * testsuite/gas/ppc/xcoff-dwsect-2.s: New test.
+
+       * config/tc-ppc.c (ppc_function): Update comment for
+       fifth argument.
+       (ppc_frob_symbol): Remove ppc_last_function check.
+       Make sure coff_last_function is reset.
+       Correctly set fsize when not provided in .function.
+       * testsuite/gas/ppc/aix.exp: New tests.
+       * testsuite/gas/ppc/xcoff-function-1-32.d: New test.
+       * testsuite/gas/ppc/xcoff-function-1-64.d: New test.
+       * testsuite/gas/ppc/xcoff-function-1.s: New test.
+
 2021-05-07  Jan Beulich  <jbeulich@suse.com>
 
        * testsuite/gas/i386/rela.s, testsuite/gas/i386/rela.d: New.
index f3cc3273a4bb7b0f678a9d603e371094ca4eeda9..f2703ff0457cff3165dd41b8954d6f0055d24def 100644 (file)
@@ -1379,6 +1379,7 @@ coff_frob_symbol (symbolS *symp, int *punt)
   /* This is pretty horrible, but we have to set *punt correctly in
      order to call SA_SET_SYM_ENDNDX correctly.  */
   if (! symbol_used_in_reloc_p (symp)
+      && S_GET_STORAGE_CLASS (symp) != C_DWARF
       && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0
          || (! (S_IS_EXTERNAL (symp) || S_IS_WEAK (symp))
              && ! symbol_get_tc (symp)->output
@@ -1483,8 +1484,18 @@ coff_adjust_section_syms (bfd *abfd ATTRIBUTE_UNUSED,
   secsym = section_symbol (sec);
   /* This is an estimate; we'll plug in the real value using
      SET_SECTION_RELOCS later */
+#ifdef OBJ_XCOFF
+  if (S_GET_STORAGE_CLASS (secsym) == C_DWARF)
+    SA_SET_SECT_NRELOC (secsym, nrelocs);
+  else
+    {
+      SA_SET_SCN_NRELOC (secsym, nrelocs);
+      SA_SET_SCN_NLINNO (secsym, nlnno);
+    }
+#else
   SA_SET_SCN_NRELOC (secsym, nrelocs);
   SA_SET_SCN_NLINNO (secsym, nlnno);
+#endif
 }
 
 void
@@ -1754,7 +1765,11 @@ coff_frob_section (segT sec)
       S_SET_STORAGE_CLASS (secsym, sclass);
       S_SET_NUMBER_AUXILIARY (secsym, 1);
       SF_SET_STATICS (secsym);
+#ifdef OBJ_XCOFF
+      SA_SET_SECT_SCNLEN (secsym, size);
+#else
       SA_SET_SCN_SCNLEN (secsym, size);
+#endif
     }
   /* FIXME: These should be in a "stabs.h" file, or maybe as.h.  */
 #ifndef STAB_SECTION_NAME
index 917b659e586f1572c28a6487245dfd797440c569..73c001e3edc76ebcfcd8ac8640318e3e40e0bef3 100644 (file)
 #define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc = (v))
 #define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno = (v))
 
+#ifdef OBJ_XCOFF
+#define SA_GET_SECT_SCNLEN(s)  (SYM_AUXENT (s)->x_sect.x_scnlen)
+#define SA_GET_SECT_NRELOC(s)  (SYM_AUXENT (s)->x_sect.x_nreloc)
+#define SA_SET_SECT_SCNLEN(s,v)        (SYM_AUXENT (s)->x_sect.x_scnlen = (v))
+#define SA_SET_SECT_NRELOC(s,v)        (SYM_AUXENT (s)->x_sect.x_nreloc = (v))
+#endif
+
 /* Internal use only definitions. SF_ stands for symbol flags.
 
    These values can be assigned to sy_symbol.ost_flags field of a symbolS.  */
@@ -294,8 +301,19 @@ extern const pseudo_typeS coff_pseudo_table[];
 #define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg)
 
 /* Store the number of relocations in the section aux entry.  */
+#ifdef OBJ_XCOFF
+#define SET_SECTION_RELOCS(sec, relocs, n)             \
+  do {                                                 \
+    symbolS * sectSym = section_symbol (sec);          \
+    if (S_GET_STORAGE_CLASS (sectSym) == C_DWARF)      \
+      SA_SET_SECT_NRELOC (sectSym, n);                 \
+    else                                               \
+      SA_SET_SCN_NRELOC (sectSym, n);                  \
+  } while (0)
+#else
 #define SET_SECTION_RELOCS(sec, relocs, n) \
   SA_SET_SCN_NRELOC (section_symbol (sec), n)
+#endif
 
 #define obj_app_file(name, app) c_dot_file_symbol (name, app)
 
index 7715fc53d0706f7312469805e82bf30ca022e63d..fce2b15f17afa224c631f47134377609b8966bb1 100644 (file)
@@ -5144,7 +5144,9 @@ ppc_function (int ignore ATTRIBUTE_UNUSED)
          expression (& exp);
          if (*input_line_pointer == ',')
            {
-             /* The fifth argument is the function size.  */
+             /* The fifth argument is the function size.
+                If it's omitted, the size will be the containing csect.
+                This will be donce during ppc_frob_symtab.  */
              ++input_line_pointer;
              symbol_get_tc (ext_sym)->u.size
                = symbol_new ("L0\001", absolute_section,
@@ -5864,6 +5866,7 @@ ppc_frob_symbol (symbolS *sym)
   /* Discard symbols that should not be included in the output symbol
      table.  */
   if (! symbol_used_in_reloc_p (sym)
+      && S_GET_STORAGE_CLASS (sym) != C_DWARF
       && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
          || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
              && ! symbol_get_tc (sym)->output
@@ -5903,8 +5906,9 @@ ppc_frob_symbol (symbolS *sym)
 
   if (SF_GET_FUNCTION (sym))
     {
-      if (ppc_last_function != (symbolS *) NULL)
-       as_bad (_("two .function pseudo-ops with no intervening .ef"));
+      /* Make sure coff_last_function is reset. Otherwise, we won't create
+         the auxent for the next function.  */
+      coff_last_function = 0;
       ppc_last_function = sym;
       if (symbol_get_tc (sym)->u.size != (symbolS *) NULL)
        {
@@ -5912,6 +5916,16 @@ ppc_frob_symbol (symbolS *sym)
          SA_SET_SYM_FSIZE (sym,
                            (long) S_GET_VALUE (symbol_get_tc (sym)->u.size));
        }
+      else
+       {
+         /* Size of containing csect.  */
+         symbolS* within = symbol_get_tc (sym)->within;
+         union internal_auxent *csectaux;
+         csectaux = &coffsymbol (symbol_get_bfdsym (within))
+           ->native[S_GET_NUMBER_AUXILIARY(within)].u.auxent;
+
+         SA_SET_SYM_FSIZE (sym, csectaux->x_csect.x_scnlen.l);
+       }
     }
   else if (S_GET_STORAGE_CLASS (sym) == C_FCN
           && strcmp (S_GET_NAME (sym), ".ef") == 0)
@@ -6126,13 +6140,43 @@ ppc_frob_symbol (symbolS *sym)
   return 0;
 }
 
-/* Adjust the symbol table.  This creates csect symbols for all
-   absolute symbols.  */
+/* Adjust the symbol table.  */
 
 void
 ppc_adjust_symtab (void)
 {
   symbolS *sym;
+  symbolS *anchorSym;
+
+  /* Make sure C_DWARF symbols come right after C_FILE.
+     As the C_FILE might not be defined yet and as C_DWARF
+     might already be ordered, we insert them before the
+     first symbol which isn't a C_FILE or a C_DWARF.  */
+  for (anchorSym = symbol_rootP; anchorSym != NULL;
+       anchorSym = symbol_next (anchorSym))
+    {
+      if (S_GET_STORAGE_CLASS (anchorSym) != C_FILE
+         && S_GET_STORAGE_CLASS (anchorSym) != C_DWARF)
+       break;
+    }
+
+  sym = anchorSym;
+  while (sym != NULL)
+    {
+      if (S_GET_STORAGE_CLASS (sym) != C_DWARF)
+       {
+         sym = symbol_next (sym);
+         continue;
+       }
+
+      symbolS* tsym = sym;
+      sym = symbol_next (sym);
+
+      symbol_remove (tsym, &symbol_rootP, &symbol_lastP);
+      symbol_insert (tsym, anchorSym, &symbol_rootP, &symbol_lastP);
+    }
+
+  /* Create csect symbols for all absolute symbols.  */
 
   if (! ppc_saw_abs)
     return;
index 8e7ac67f5ce24e7b48595b6f89e2298a5df82bd2..efe27e4edb03ab86db2c40b6835efd0e6de602fe 100644 (file)
@@ -73,4 +73,9 @@ if { [istarget "powerpc*-*-aix*"] || [istarget "rs6000-*-aix*"] } then {
 
     run_dump_test "xcoff-dwsect-1-32"
     run_dump_test "xcoff-dwsect-1-64"
+    run_dump_test "xcoff-dwsect-2-32"
+    run_dump_test "xcoff-dwsect-2-64"
+
+    run_dump_test "xcoff-function-1-32"
+    run_dump_test "xcoff-function-1-64"
 }
diff --git a/gas/testsuite/gas/ppc/xcoff-dwsect-2-32.d b/gas/testsuite/gas/ppc/xcoff-dwsect-2-32.d
new file mode 100644 (file)
index 0000000..cebc6d3
--- /dev/null
@@ -0,0 +1,18 @@
+#as: -a32
+#source: xcoff-dwsect-2.s
+#objdump: -t
+#name: XCOFF dwsect test 2 (32-bit)
+
+.*
+
+SYMBOL TABLE:
+.*\(scl 103\).*
+File .*
+.*\(scl 112\).* .dwinfo
+AUX .*
+.*\(scl 112\).* .dwloc
+AUX .*
+.*\(scl 112\).* .dwarnge
+AUX .*
+.*\(scl 107\).* .text
+.*
diff --git a/gas/testsuite/gas/ppc/xcoff-dwsect-2-64.d b/gas/testsuite/gas/ppc/xcoff-dwsect-2-64.d
new file mode 100644 (file)
index 0000000..445e707
--- /dev/null
@@ -0,0 +1,18 @@
+#as: -a64
+#source: xcoff-dwsect-2.s
+#objdump: -t
+#name: XCOFF dwsect test 2 (64-bit)
+
+.*
+
+SYMBOL TABLE:
+.*\(scl 103\).*
+File .*
+.*\(scl 112\).* .dwinfo
+AUX .*
+.*\(scl 112\).* .dwloc
+AUX .*
+.*\(scl 112\).* .dwarnge
+AUX .*
+.*\(scl 107\).* .text
+.*
diff --git a/gas/testsuite/gas/ppc/xcoff-dwsect-2.s b/gas/testsuite/gas/ppc/xcoff-dwsect-2.s
new file mode 100644 (file)
index 0000000..52a624f
--- /dev/null
@@ -0,0 +1,12 @@
+
+       .csect .text[PR]
+
+       .dwsect 0x10000,Ldwinfo_0
+       .short 2
+       .dwsect 0x90000
+Ldebug_loc:
+       .short 3
+       .dwsect 0x50000
+       .short 1
+       .short 4
+
diff --git a/gas/testsuite/gas/ppc/xcoff-function-1-32.d b/gas/testsuite/gas/ppc/xcoff-function-1-32.d
new file mode 100644 (file)
index 0000000..805a248
--- /dev/null
@@ -0,0 +1,20 @@
+#as: -a32
+#source: xcoff-function-1.s
+#objdump: -t
+#name: XCOFF function test 1 (32-bit)
+
+.*
+
+SYMBOL TABLE:
+.*
+.*
+\[  2\].* .text
+AUX val     8 .*
+\[  4\].* .foo
+AUX .* ttlsiz 0x8 .*
+AUX .* typ 2 .* clss 0 .*
+\[  7\].* .bar
+AUX .* ttlsiz 0x4 .*
+AUX .* typ 2 .* clss 0 .*
+
+
diff --git a/gas/testsuite/gas/ppc/xcoff-function-1-64.d b/gas/testsuite/gas/ppc/xcoff-function-1-64.d
new file mode 100644 (file)
index 0000000..431c61c
--- /dev/null
@@ -0,0 +1,20 @@
+#as: -a64
+#source: xcoff-function-1.s
+#objdump: -t
+#name: XCOFF function test 1 (64-bit)
+
+.*
+
+SYMBOL TABLE:
+.*
+.*
+\[  2\].* .text
+AUX val     8 .*
+\[  4\].* .foo
+AUX .* ttlsiz 0x8 .*
+AUX .* typ 2 .* clss 0 .*
+\[  7\].* .bar
+AUX .* ttlsiz 0x4 .*
+AUX .* typ 2 .* clss 0 .*
+
+
diff --git a/gas/testsuite/gas/ppc/xcoff-function-1.s b/gas/testsuite/gas/ppc/xcoff-function-1.s
new file mode 100644 (file)
index 0000000..8a63fe7
--- /dev/null
@@ -0,0 +1,16 @@
+  .csect .text[PR]
+
+  # .function without 5th argument means
+  # that the size is the size of the csect.
+  .globl .foo
+.foo:
+  .function .foo,.foo,2,0
+  blr
+
+  # .function without 5th argument means
+  # that the size is the size given.
+  .globl .bar
+.bar:
+  .function .bar,.bar,2,0, E..bar-.bar
+  blr
+E..bar:
index 621045e90d7b05cafe486d1c6313181ab2eb9c69..e22f3e85452ba1282ffaefccf520ddc3e7664452 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-07  Clément Chigot  <clement.chigot@atos.net>
+
+       * coff/internal.h (C_DWARF): New define.
+       * coff/xcoff.h (SSUBTYP_DWLOC, SSUBTYP_DWFRAME,
+       SSUBTYP_DWMAC): New defines.
+
 2021-05-06  Stafford Horne  <shorne@gmail.com>
 
        PR 21464
index e79bf560c6e73606f23ec41395b13e447f59d06c..8d757acb333ba6c1e36a0e9d7329412d62e37f0f 100644 (file)
@@ -348,6 +348,7 @@ struct internal_aouthdr
 #define C_BINCL         108    /* Marks beginning of include file */
 #define C_EINCL         109    /* Marks ending of include file */
 #define C_AIX_WEAKEXT   111    /* AIX definition of C_WEAKEXT.  */
+#define C_DWARF         112    /* DWARF symbol  */
 
 #define C_NULL_VALUE   0x00de1e00    /* Value for a C_NULL deleted entry.  */
 
index 3170542865b099151b74d3b5840e4ef710191ca6..2b61545d611760f0697d93b497417b9ac50daac2 100644 (file)
@@ -65,6 +65,9 @@
 #define SSUBTYP_DWABREV 0x60000
 #define SSUBTYP_DWSTR   0x70000
 #define SSUBTYP_DWRNGES 0x80000
+#define SSUBTYP_DWLOC   0x90000
+#define SSUBTYP_DWFRAME 0xA0000
+#define SSUBTYP_DWMAC   0xB0000
 
 /* XCOFF uses a special .loader section with type STYP_LOADER.  */
 #define STYP_LOADER 0x1000
This page took 0.050925 seconds and 4 git commands to generate.