public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] gas: add visibility support for XCOFF
@ 2022-01-03 13:21 CHIGOT, CLEMENT
  2022-01-11 14:18 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: CHIGOT, CLEMENT @ 2022-01-03 13:21 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1551 bytes --]

XCOFF assembly defines the visibility using an additional argument
on several pseudo-ops: .globl, .weak, .extern and .comm.
This implies that .globl and .weak syntax is different than the
usual GNU syntax. But we want to provide compatibility with AIX
assembler, especially because GCC is generating the visibility
using this XCOFF syntax.

PR 22085

bfd/ChangeLog:

        * coffcode.h (coff_write_object_contents): Change XCOFF header
        vstamp field to 2.
        * coffgen.c (coff_print_symbol): Increase the size for n_type.

gas/ChangeLog:

        * config/tc-ppc.c (ppc_xcoff_get_visibility): New function.
        (ppc_globl): New function.
        (ppc_weak): New function.
        (ppc_comm): Add visibility field support.
        (ppc_extern): Likewise.
        * testsuite/gas/all/cofftag.d: Adjust to new n_type size
        providing by objdump.
        * testsuite/gas/ppc/test1xcoff32.d: Likewise.
        * testsuite/gas/ppc/aix.exp: Add new tests.
        * testsuite/gas/ppc/xcoff-visibility-1-32.d: New test.
        * testsuite/gas/ppc/xcoff-visibility-1-64.d: New test.
        * testsuite/gas/ppc/xcoff-visibility-1.s: New test.

include/ChangeLog:

        * coff/internal.h (SYM_V_INTERNAL, SYM_V_HIDDEN,
        SYM_V_PROTECTED, SYM_V_EXPORTED, SYM_V_MASK): New defines.
        * coff/xcoff.h (struct xcoff_link_hash_entry): Add visibility
        field.

ld/ChangeLog:

        * testsuite/ld-pe/pr19803.d: Adjust to new n_type size
        providing by objdump.







[-- Attachment #2: 0001-gas-add-visibility-support-for-XCOFF.patch --]
[-- Type: application/octet-stream, Size: 24200 bytes --]

From d11b0871eedcd1e9fb887b11b4d4f6b10107c391 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <clement.chigot@atos.net>
Date: Tue, 16 Nov 2021 14:02:16 +0100
Subject: [PATCH 1/4] gas: add visibility support for XCOFF

XCOFF assembly defines the visibility using an additional argument
on several pseudo-ops: .globl, .weak, .extern and .comm.
This implies that .globl and .weak syntax is different than the
usual GNU syntax. But we want to provide compatibility with AIX
assembler, especially because GCC is generating the visibility
using this XCOFF syntax.

PR 22085

bfd/ChangeLog:

        * coffcode.h (coff_write_object_contents): Change XCOFF header
        vstamp field to 2.
        * coffgen.c (coff_print_symbol): Increase the size for n_type.

gas/ChangeLog:

        * config/tc-ppc.c (ppc_xcoff_get_visibility): New function.
        (ppc_globl): New function.
        (ppc_weak): New function.
        (ppc_comm): Add visibility field support.
        (ppc_extern): Likewise.
        * testsuite/gas/all/cofftag.d: Adjust to new n_type size
        providing by objdump.
        * testsuite/gas/ppc/test1xcoff32.d: Likewise.
        * testsuite/gas/ppc/aix.exp: Add new tests.
        * testsuite/gas/ppc/xcoff-visibility-1-32.d: New test.
        * testsuite/gas/ppc/xcoff-visibility-1-64.d: New test.
        * testsuite/gas/ppc/xcoff-visibility-1.s: New test.

include/ChangeLog:

        * coff/internal.h (SYM_V_INTERNAL, SYM_V_HIDDEN,
        SYM_V_PROTECTED, SYM_V_EXPORTED, SYM_V_MASK): New defines.
        * coff/xcoff.h (struct xcoff_link_hash_entry): Add visibility
        field.

ld/ChangeLog:

        * testsuite/ld-pe/pr19803.d: Adjust to new n_type size
        providing by objdump.
---
 bfd/coffcode.h                                |   7 +-
 bfd/coffgen.c                                 |   2 +-
 gas/config/tc-ppc.c                           | 156 +++++++++++++++++-
 gas/testsuite/gas/all/cofftag.d               |  24 +--
 gas/testsuite/gas/ppc/aix.exp                 |   3 +
 gas/testsuite/gas/ppc/test1xcoff32.d          |  40 ++---
 gas/testsuite/gas/ppc/xcoff-visibility-1-32.d |  70 ++++++++
 gas/testsuite/gas/ppc/xcoff-visibility-1-64.d |  70 ++++++++
 gas/testsuite/gas/ppc/xcoff-visibility-1.s    |  78 +++++++++
 include/coff/internal.h                       |   7 +
 include/coff/xcoff.h                          |   3 +
 ld/testsuite/ld-pe/pr19803.d                  |   2 +-
 12 files changed, 423 insertions(+), 39 deletions(-)
 create mode 100644 gas/testsuite/gas/ppc/xcoff-visibility-1-32.d
 create mode 100644 gas/testsuite/gas/ppc/xcoff-visibility-1-64.d
 create mode 100644 gas/testsuite/gas/ppc/xcoff-visibility-1.s

diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index d45b37d305c..31bd97542d0 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -3994,8 +3994,13 @@ coff_write_object_contents (bfd * abfd)
 #endif
   }
 
+#ifdef RS6000COFF_C
+  /* XCOFF 32bit needs this to have new behaviour for n_type field.  */
+  internal_a.vstamp = 2;
+#else
   /* FIXME: Does anybody ever set this to another value?  */
   internal_a.vstamp = 0;
+#endif
 
   /* Now should write relocs, strings, syms.  */
   obj_sym_filepos (abfd) = sym_base;
@@ -4070,7 +4075,7 @@ coff_write_object_contents (bfd * abfd)
       bfd_vma toc;
       asection *loader_sec;
 
-      internal_a.vstamp = 1;
+      internal_a.vstamp = 2;
 
       internal_a.o_snentry = xcoff_data (abfd)->snentry;
       if (internal_a.o_snentry == 0)
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 6087a958734..293fce2baf3 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -2185,7 +2185,7 @@ coff_print_symbol (bfd *abfd,
 		    - (bfd_hostptr_t) root)
 		   / sizeof (combined_entry_type));
 
-	  fprintf (file, "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x",
+	  fprintf (file, "(sec %2d)(fl 0x%02x)(ty %4x)(scl %3d) (nx %d) 0x",
 		   combined->u.syment.n_scnum,
 		   combined->u.syment.n_flags,
 		   combined->u.syment.n_type,
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index c7af7b76e08..1660ba5030b 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -110,6 +110,7 @@ static void ppc_change_csect (symbolS *, offsetT);
 static void ppc_file (int);
 static void ppc_function (int);
 static void ppc_extern (int);
+static void ppc_globl (int);
 static void ppc_lglobl (int);
 static void ppc_ref (int);
 static void ppc_section (int);
@@ -119,6 +120,7 @@ static void ppc_rename (int);
 static void ppc_toc (int);
 static void ppc_xcoff_cons (int);
 static void ppc_vbyte (int);
+static void ppc_weak (int);
 #endif
 
 #ifdef OBJ_ELF
@@ -230,6 +232,7 @@ const pseudo_typeS md_pseudo_table[] =
   { "extern",	ppc_extern,	0 },
   { "file",	ppc_file,	0 },
   { "function",	ppc_function,	0 },
+  { "globl",    ppc_globl,	0 },
   { "lglobl",	ppc_lglobl,	0 },
   { "ref",	ppc_ref,	0 },
   { "rename",	ppc_rename,	0 },
@@ -242,6 +245,7 @@ const pseudo_typeS md_pseudo_table[] =
   { "word",	ppc_xcoff_cons,	1 },
   { "short",	ppc_xcoff_cons,	1 },
   { "vbyte",    ppc_vbyte,	0 },
+  { "weak",     ppc_weak,	0 },
 #endif
 
 #ifdef OBJ_ELF
@@ -4285,6 +4289,39 @@ ppc_byte (int ignore ATTRIBUTE_UNUSED)
    to handle symbol suffixes for such symbols.  */
 static bool ppc_stab_symbol;
 
+/* Retrieve the visiblity input for pseudo-ops having ones.  */
+static unsigned short
+ppc_xcoff_get_visibility (void) {
+  SKIP_WHITESPACE();
+
+  if (startswith (input_line_pointer, "exported"))
+    {
+      input_line_pointer += 8;
+      return SYM_V_EXPORTED;
+    }
+
+  if (startswith (input_line_pointer, "hidden"))
+    {
+      input_line_pointer += 6;
+      return SYM_V_HIDDEN;
+    }
+
+  if (startswith (input_line_pointer, "internal"))
+    {
+      input_line_pointer += 8;
+      return SYM_V_INTERNAL;
+    }
+
+  if (startswith (input_line_pointer, "protected"))
+    {
+      input_line_pointer += 9;
+      return SYM_V_PROTECTED;
+    }
+
+  return 0;
+}
+
+
 /* The .comm and .lcomm pseudo-ops for XCOFF.  XCOFF puts common
    symbols in the .bss segment as though they were local common
    symbols, and uses a different smclas.  The native Aix 4.3.3 assembler
@@ -4305,6 +4342,7 @@ ppc_comm (int lcomm)
   symbolS *lcomm_sym = NULL;
   symbolS *sym;
   char *pfrag;
+  unsigned short visibility;
   struct ppc_xcoff_section *section;
 
   endc = get_symbol_name (&name);
@@ -4341,6 +4379,19 @@ ppc_comm (int lcomm)
 	      as_warn (_("ignoring bad alignment"));
 	      align = 2;
 	    }
+
+	  /* The fourth argument to .comm is the visibility.  */
+	  if (*input_line_pointer == ',')
+	    {
+	      input_line_pointer++;
+	      visibility = ppc_xcoff_get_visibility ();
+	      if (!visibility)
+		{
+		  as_bad (_("Unknown visibility field in .comm"));
+		  ignore_rest_of_line ();
+		  return;
+		}
+	    }
 	}
     }
   else
@@ -4463,6 +4514,14 @@ ppc_comm (int lcomm)
       symbol_get_frag (lcomm_sym)->fr_offset += size;
     }
 
+  if (!lcomm && visibility)
+    {
+      /* Add visibility to .comm symbol.  */
+      coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
+      coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
+      coffsym->native->u.syment.n_type |= visibility;
+    }
+
   subseg_set (current_seg, current_subseg);
 
   demand_empty_rest_of_line ();
@@ -4842,13 +4901,102 @@ static void
 ppc_extern (int ignore ATTRIBUTE_UNUSED)
 {
   char *name;
-  char endc;
+  symbolS *sym;
 
-  endc = get_symbol_name (&name);
+  if ((name = read_symbol_name ()) == NULL)
+    return;
 
-  (void) symbol_find_or_make (name);
+  sym = symbol_find_or_make (name);
 
-  (void) restore_line_pointer (endc);
+  if (*input_line_pointer == ',')
+    {
+      unsigned short visibility;
+      coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
+
+      input_line_pointer++;
+      visibility = ppc_xcoff_get_visibility ();
+      if (!visibility)
+	{
+	  as_bad (_("Unknown visibility field in .extern"));
+	  ignore_rest_of_line ();
+	  return;
+	}
+
+      coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
+      coffsym->native->u.syment.n_type |= visibility;
+    }
+
+  demand_empty_rest_of_line ();
+}
+
+/* XCOFF semantic for .globl says that the second parameter is
+   the symbol visibility.  */
+
+static void
+ppc_globl (int ignore ATTRIBUTE_UNUSED)
+{
+  char *name;
+  symbolS *sym;
+
+  if ((name = read_symbol_name ()) == NULL)
+    return;
+
+  sym = symbol_find_or_make (name);
+  S_SET_EXTERNAL (sym);
+
+  if (*input_line_pointer == ',')
+    {
+      unsigned short visibility;
+      coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
+
+      input_line_pointer++;
+      visibility = ppc_xcoff_get_visibility ();
+      if (!visibility)
+	{
+	  as_bad (_("Unknown visibility field in .globl"));
+	  ignore_rest_of_line ();
+	  return;
+	}
+
+      coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
+      coffsym->native->u.syment.n_type |= visibility;
+    }
+
+  demand_empty_rest_of_line ();
+}
+
+/* XCOFF semantic for .weak says that the second parameter is
+   the symbol visibility.  */
+
+static void
+ppc_weak (int ignore ATTRIBUTE_UNUSED)
+{
+  char *name;
+  symbolS *sym;
+
+  if ((name = read_symbol_name ()) == NULL)
+    return;
+
+  sym = symbol_find_or_make (name);
+  S_SET_WEAK (sym);
+
+  if (*input_line_pointer == ',')
+    {
+      unsigned short visibility;
+      coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
+
+      input_line_pointer++;
+      visibility = ppc_xcoff_get_visibility ();
+      if (!visibility)
+	{
+	  as_bad (_("Unknown visibility field in .weak"));
+	  ignore_rest_of_line ();
+	  return;
+	}
+
+      coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
+      coffsym->native->u.syment.n_type |= visibility;
+    }
 
   demand_empty_rest_of_line ();
 }
diff --git a/gas/testsuite/gas/all/cofftag.d b/gas/testsuite/gas/all/cofftag.d
index 88cf13c7d5f..2d2a4ccfdb8 100644
--- a/gas/testsuite/gas/all/cofftag.d
+++ b/gas/testsuite/gas/all/cofftag.d
@@ -4,22 +4,22 @@
 .*:     file format .*
 
 SYMBOL TABLE:
-\[  0\]\(sec -2\)\(fl 0x00\)\(ty   0\)\(scl 103\) \(nx 1\) 0x0+0000 foo.c
+\[  0\]\(sec -2\)\(fl 0x00\)\(ty    0\)\(scl 103\) \(nx 1\) 0x0+0000 foo.c
 File 
-\[  2\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl   6\) \(nx 0\) 0x0+0000 gcc2_compiled.
-\[  3\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl   6\) \(nx 0\) 0x0+0000 ___gnu_compiled_c
-\[  4\]\(sec -2\)\(fl 0x00\)\(ty   a\)\(scl  15\) \(nx 1\) 0x0+0000 _token
+\[  2\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl   6\) \(nx 0\) 0x0+0000 gcc2_compiled.
+\[  3\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl   6\) \(nx 0\) 0x0+0000 ___gnu_compiled_c
+\[  4\]\(sec -2\)\(fl 0x00\)\(ty    a\)\(scl  15\) \(nx 1\) 0x0+0000 _token
 AUX lnno 0 size 0x4 tagndx 0 endndx 10
-\[  6\]\(sec -(1|2)\)\(fl 0x00\)\(ty   b\)\(scl  16\) \(nx 0\) 0x0+0000 _operator
-\[  7\]\(sec -(1|2)\)\(fl 0x00\)\(ty   b\)\(scl  16\) \(nx 0\) 0x0+0001 _flags
-\[  8\]\(sec -(1|2)\)\(fl 0x00\)\(ty   0\)\(scl 102\) \(nx 1\) 0x0+0004 .eos
+\[  6\]\(sec -(1|2)\)\(fl 0x00\)\(ty    b\)\(scl  16\) \(nx 0\) 0x0+0000 _operator
+\[  7\]\(sec -(1|2)\)\(fl 0x00\)\(ty    b\)\(scl  16\) \(nx 0\) 0x0+0001 _flags
+\[  8\]\(sec -(1|2)\)\(fl 0x00\)\(ty    0\)\(scl 102\) \(nx 1\) 0x0+0004 .eos
 AUX lnno 0 size 0x4 tagndx 4
-\[ 10\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl   3\) \(nx 1\) 0x[0-9a-f]+ .text
+\[ 10\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl   3\) \(nx 1\) 0x[0-9a-f]+ .text
 AUX scnlen 0x[0-9a-f]+ nreloc 0 nlnno 0
-\[ 12\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl   3\) \(nx 1\) 0x[0-9a-f]+ .data
+\[ 12\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl   3\) \(nx 1\) 0x[0-9a-f]+ .data
 AUX scnlen 0x[0-9a-f]+ nreloc 0 nlnno 0
-\[ 14\]\(sec  3\)\(fl 0x00\)\(ty   0\)\(scl   3\) \(nx 1\) 0x[0-9a-f]+ .bss
+\[ 14\]\(sec  3\)\(fl 0x00\)\(ty    0\)\(scl   3\) \(nx 1\) 0x[0-9a-f]+ .bss
 AUX scnlen 0x[0-9a-f]+ nreloc 0 nlnno 0
-\[ 16\]\(sec  2\)\(fl 0x00\)\(ty   2\)\(scl   2\) \(nx 0\) 0x0+0000 _token
-\[ 17\]\(sec  2\)\(fl 0x00\)\(ty   a\)\(scl   2\) \(nx 1\) 0x[0-9a-f]+ _what
+\[ 16\]\(sec  2\)\(fl 0x00\)\(ty    2\)\(scl   2\) \(nx 0\) 0x0+0000 _token
+\[ 17\]\(sec  2\)\(fl 0x00\)\(ty    a\)\(scl   2\) \(nx 1\) 0x[0-9a-f]+ _what
 AUX lnno 0 size 0x4 tagndx 4
diff --git a/gas/testsuite/gas/ppc/aix.exp b/gas/testsuite/gas/ppc/aix.exp
index 85ed06e8a38..53806b3b4f2 100644
--- a/gas/testsuite/gas/ppc/aix.exp
+++ b/gas/testsuite/gas/ppc/aix.exp
@@ -87,4 +87,7 @@ if { [istarget "powerpc*-*-aix*"] || [istarget "rs6000-*-aix*"] } then {
 
     run_dump_test "xcoff-file-32"
     run_dump_test "xcoff-file-64"
+
+    run_dump_test "xcoff-visibility-1-32"
+    run_dump_test "xcoff-visibility-1-64"
 }
diff --git a/gas/testsuite/gas/ppc/test1xcoff32.d b/gas/testsuite/gas/ppc/test1xcoff32.d
index 2f8f502cfc7..a0e48dee5d0 100644
--- a/gas/testsuite/gas/ppc/test1xcoff32.d
+++ b/gas/testsuite/gas/ppc/test1xcoff32.d
@@ -17,45 +17,45 @@ Idx Name +Size +VMA +LMA +File off +Algn
   2 \.bss  +00000000  0+0090  0+0090  00000000  2\*\*3
  +ALLOC
 SYMBOL TABLE:
-\[  0\]\(sec -2\)\(fl 0x00\)\(ty   0\)\(scl 103\) \(nx 1\) 0x00000000 fake
+\[  0\]\(sec -2\)\(fl 0x00\)\(ty    0\)\(scl 103\) \(nx 1\) 0x00000000 fake
 File 
-\[  2\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000000 \.crazy_table
+\[  2\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000000 \.crazy_table
 AUX val     8 prmhsh 0 snhsh 0 typ 1 algn 2 clss 1 stb 0 snstb 0
-\[  4\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000008 
+\[  4\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000008 
 AUX val    96 prmhsh 0 snhsh 0 typ 1 algn 2 clss 0 stb 0 snstb 0
-\[  6\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000008 reference_csect_relative_symbols
+\[  6\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000008 reference_csect_relative_symbols
 AUX indx    4 prmhsh 0 snhsh 0 typ 2 algn 0 clss 0 stb 0 snstb 0
-\[  8\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000018 dubious_references_to_default_RW_csect
+\[  8\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000018 dubious_references_to_default_RW_csect
 AUX indx    4 prmhsh 0 snhsh 0 typ 2 algn 0 clss 0 stb 0 snstb 0
-\[ 10\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000028 reference_via_toc
+\[ 10\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000028 reference_via_toc
 AUX indx    4 prmhsh 0 snhsh 0 typ 2 algn 0 clss 0 stb 0 snstb 0
-\[ 12\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000040 subtract_symbols
+\[ 12\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000040 subtract_symbols
 AUX indx    4 prmhsh 0 snhsh 0 typ 2 algn 0 clss 0 stb 0 snstb 0
-\[ 14\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x0000005c load_addresses
+\[ 14\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x0000005c load_addresses
 AUX indx    4 prmhsh 0 snhsh 0 typ 2 algn 0 clss 0 stb 0 snstb 0
-\[ 16\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000068 
+\[ 16\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000068 
 AUX val    12 prmhsh 0 snhsh 0 typ 1 algn 2 clss 5 stb 0 snstb 0
-\[ 18\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000074 TOC
+\[ 18\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000074 TOC
 AUX val     0 prmhsh 0 snhsh 0 typ 1 algn 2 clss 15 stb 0 snstb 0
-\[ 20\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000074 ignored0
+\[ 20\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000074 ignored0
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 22\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000078 ignored1
+\[ 22\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000078 ignored1
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 24\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x0000007c ignored2
+\[ 24\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x0000007c ignored2
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 26\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000080 ignored3
+\[ 26\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000080 ignored3
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 28\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000084 ignored4
+\[ 28\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000084 ignored4
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 30\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x00000088 ignored5
+\[ 30\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x00000088 ignored5
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 32\]\(sec  2\)\(fl 0x00\)\(ty   0\)\(scl 107\) \(nx 1\) 0x0000008c ignored6
+\[ 32\]\(sec  2\)\(fl 0x00\)\(ty    0\)\(scl 107\) \(nx 1\) 0x0000008c ignored6
 AUX val     4 prmhsh 0 snhsh 0 typ 1 algn 2 clss 3 stb 0 snstb 0
-\[ 34\]\(sec  0\)\(fl 0x00\)\(ty   0\)\(scl   2\) \(nx 1\) 0x00000000 esym0
+\[ 34\]\(sec  0\)\(fl 0x00\)\(ty    0\)\(scl   2\) \(nx 1\) 0x00000000 esym0
 AUX val     0 prmhsh 0 snhsh 0 typ 0 algn 0 clss 0 stb 0 snstb 0
-\[ 36\]\(sec  0\)\(fl 0x00\)\(ty   0\)\(scl   2\) \(nx 1\) 0x00000000 esym1
+\[ 36\]\(sec  0\)\(fl 0x00\)\(ty    0\)\(scl   2\) \(nx 1\) 0x00000000 esym1
 AUX val     0 prmhsh 0 snhsh 0 typ 0 algn 0 clss 0 stb 0 snstb 0
-\[ 38\]\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl   3\) \(nx 1\) 0x00000000 \.text
+\[ 38\]\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl   3\) \(nx 1\) 0x00000000 \.text
 AUX scnlen 0x68 nreloc 7 nlnno 0
 
 
diff --git a/gas/testsuite/gas/ppc/xcoff-visibility-1-32.d b/gas/testsuite/gas/ppc/xcoff-visibility-1-32.d
new file mode 100644
index 00000000000..f3d00eb6f24
--- /dev/null
+++ b/gas/testsuite/gas/ppc/xcoff-visibility-1-32.d
@@ -0,0 +1,70 @@
+#as: -a32
+#source: xcoff-visibility-1.s
+#objdump: -t
+#name: XCOFF Visibility 1 (32 bit)
+
+.*
+
+SYMBOL TABLE:
+.*
+.*
+.*
+.*
+\[  4\].*\(ty    0\).*l_novisibility
+.*
+\[  6\].*\(ty 1000\).*l_internal
+.*
+\[  8\].*\(ty 2000\).*l_hidden
+.*
+\[ 10\].*\(ty 3000\).*l_protected
+.*
+\[ 12\].*\(ty 4000\).*l_exported
+.*
+\[ 14\].*\(ty 1000\).*l_dual
+.*
+\[ 16\].*\(ty    0\).*globl_novisibility
+.*
+\[ 18\].*\(ty 1000\).*globl_internal
+.*
+\[ 20\].*\(ty 2000\).*globl_hidden
+.*
+\[ 22\].*\(ty 3000\).*globl_protected
+.*
+\[ 24\].*\(ty 4000\).*globl_exported
+.*
+\[ 26\].*\(ty 1000\).*globl_dual
+.*
+\[ 28\].*\(ty    0\).*weak_novisibility
+.*
+\[ 30\].*\(ty 1000\).*weak_internal
+.*
+\[ 32\].*\(ty 2000\).*weak_hidden
+.*
+\[ 34\].*\(ty 3000\).*weak_protected
+.*
+\[ 36\].*\(ty 4000\).*weak_exported
+.*
+\[ 38\].*\(ty 1000\).*weak_dual
+.*
+\[ 40\].*\(ty    0\).*comm_novisibility
+.*
+\[ 42\].*\(ty 1000\).*comm_internal
+.*
+\[ 44\].*\(ty 2000\).*comm_hidden
+.*
+\[ 46\].*\(ty 3000\).*comm_protected
+.*
+\[ 48\].*\(ty 4000\).*comm_exported
+.*
+\[ 50\].*\(ty    0\).*extern_novisibility
+.*
+\[ 52\].*\(ty 1000\).*extern_internal
+.*
+\[ 54\].*\(ty 2000\).*extern_hidden
+.*
+\[ 56\].*\(ty 3000\).*extern_protected
+.*
+\[ 58\].*\(ty 4000\).*extern_exported
+.*
+\[ 60\].*\(ty 1000\).*extern_dual
+.*
diff --git a/gas/testsuite/gas/ppc/xcoff-visibility-1-64.d b/gas/testsuite/gas/ppc/xcoff-visibility-1-64.d
new file mode 100644
index 00000000000..fd686e10d93
--- /dev/null
+++ b/gas/testsuite/gas/ppc/xcoff-visibility-1-64.d
@@ -0,0 +1,70 @@
+#as: -a64
+#source: xcoff-visibility-1.s
+#objdump: -t
+#name: XCOFF Visibility 1 (64 bit)
+
+.*
+
+SYMBOL TABLE:
+.*
+.*
+.*
+.*
+\[  4\].*\(ty    0\).*l_novisibility
+.*
+\[  6\].*\(ty 1000\).*l_internal
+.*
+\[  8\].*\(ty 2000\).*l_hidden
+.*
+\[ 10\].*\(ty 3000\).*l_protected
+.*
+\[ 12\].*\(ty 4000\).*l_exported
+.*
+\[ 14\].*\(ty 1000\).*l_dual
+.*
+\[ 16\].*\(ty    0\).*globl_novisibility
+.*
+\[ 18\].*\(ty 1000\).*globl_internal
+.*
+\[ 20\].*\(ty 2000\).*globl_hidden
+.*
+\[ 22\].*\(ty 3000\).*globl_protected
+.*
+\[ 24\].*\(ty 4000\).*globl_exported
+.*
+\[ 26\].*\(ty 1000\).*globl_dual
+.*
+\[ 28\].*\(ty    0\).*weak_novisibility
+.*
+\[ 30\].*\(ty 1000\).*weak_internal
+.*
+\[ 32\].*\(ty 2000\).*weak_hidden
+.*
+\[ 34\].*\(ty 3000\).*weak_protected
+.*
+\[ 36\].*\(ty 4000\).*weak_exported
+.*
+\[ 38\].*\(ty 1000\).*weak_dual
+.*
+\[ 40\].*\(ty    0\).*comm_novisibility
+.*
+\[ 42\].*\(ty 1000\).*comm_internal
+.*
+\[ 44\].*\(ty 2000\).*comm_hidden
+.*
+\[ 46\].*\(ty 3000\).*comm_protected
+.*
+\[ 48\].*\(ty 4000\).*comm_exported
+.*
+\[ 50\].*\(ty    0\).*extern_novisibility
+.*
+\[ 52\].*\(ty 1000\).*extern_internal
+.*
+\[ 54\].*\(ty 2000\).*extern_hidden
+.*
+\[ 56\].*\(ty 3000\).*extern_protected
+.*
+\[ 58\].*\(ty 4000\).*extern_exported
+.*
+\[ 60\].*\(ty 1000\).*extern_dual
+.*
diff --git a/gas/testsuite/gas/ppc/xcoff-visibility-1.s b/gas/testsuite/gas/ppc/xcoff-visibility-1.s
new file mode 100644
index 00000000000..995c5e51f3f
--- /dev/null
+++ b/gas/testsuite/gas/ppc/xcoff-visibility-1.s
@@ -0,0 +1,78 @@
+# Tests every possible visibility using XCOFF format.
+# Ensure that the visibility field is left empty if no
+# visibility is provided.
+# Ensure that only the last visibility is taken into
+# account when several are provided.
+
+# Csect visibility
+  .globl globl_novisibility[RW]
+  .csect globl_novisibility[RW]
+  .globl globl_internal[RW], internal
+  .csect globl_internal[RW]
+  .globl globl_hidden[RW], hidden
+  .csect globl_hidden[RW]
+  .globl globl_protected[RW], protected
+  .csect globl_protected[RW]
+  .globl globl_exported[RW], exported
+  .csect globl_exported[RW]
+  .globl globl_dual[RW], exported
+  .globl globl_dual[RW], internal
+  .csect globl_dual[RW]
+
+# Weak csect visibility
+  .weak weak_novisibility[RW]
+  .csect weak_novisibility[RW]
+  .weak weak_internal[RW], internal
+  .csect weak_internal[RW]
+  .weak weak_hidden[RW], hidden
+  .csect weak_hidden[RW]
+  .weak weak_protected[RW], protected
+  .csect weak_protected[RW]
+  .weak weak_exported[RW], exported
+  .csect weak_exported[RW]
+  .weak weak_dual[RW], exported
+  .weak weak_dual[RW], internal
+  .csect weak_dual[RW]
+
+# Comm visibility
+  .comm comm_novisibility[RW], 8, 4
+  .comm comm_internal[RW], 8, 4, internal
+  .comm comm_hidden[RW], 8, 4, hidden
+  .comm comm_protected[RW], 8, 4, protected
+  .comm comm_exported[RW], 8, 4, exported
+
+# Extern visibility
+  .extern extern_novisibility[RW]
+  .extern extern_internal[RW], internal
+  .extern extern_hidden[RW], hidden
+  .extern extern_protected[RW], protected
+  .extern extern_exported[RW], exported
+  .extern extern_dual[RW], exported
+  .extern extern_dual[RW], internal
+
+# Label visibility
+  .csect .text[PR]
+  .globl l_novisibility
+l_novisibility:
+  blr
+
+  .globl l_internal, internal
+l_internal:
+  blr
+
+  .globl l_hidden, hidden
+l_hidden:
+  blr
+
+  .globl l_protected, protected
+l_protected:
+  blr
+
+  .globl l_exported, exported
+l_exported:
+  blr
+
+  .globl l_dual, exported
+  .globl l_dual, internal
+l_dual:
+  blr
diff --git a/include/coff/internal.h b/include/coff/internal.h
index 69eb0a4a582..f12908b0f65 100644
--- a/include/coff/internal.h
+++ b/include/coff/internal.h
@@ -536,6 +536,13 @@ struct internal_syment
 #define DECREF(x) \
   ((((x) >> N_TSHIFT) & ~ N_BTMASK) | ((x) & N_BTMASK))
 
+/* Visibility flag, in XCOFF n_type.  */
+#define SYM_V_INTERNAL		0x1000
+#define SYM_V_HIDDEN		0x2000
+#define SYM_V_PROTECTED 	0x3000
+#define SYM_V_EXPORTED		0x4000
+#define SYM_V_MASK		0xF000
+
 union internal_auxent
 {
   struct
diff --git a/include/coff/xcoff.h b/include/coff/xcoff.h
index bf53ecd4700..acadf54d4a1 100644
--- a/include/coff/xcoff.h
+++ b/include/coff/xcoff.h
@@ -349,6 +349,9 @@ struct xcoff_link_hash_entry
   /* Some linker flags.  */
   unsigned long flags;
 
+  /* Symbol visibility, using the same define than n_type.  */
+  unsigned short visibility;
+
   /* The storage mapping class.  */
   unsigned char smclas;
 };
diff --git a/ld/testsuite/ld-pe/pr19803.d b/ld/testsuite/ld-pe/pr19803.d
index 238194bc1d9..1bd7958cf24 100644
--- a/ld/testsuite/ld-pe/pr19803.d
+++ b/ld/testsuite/ld-pe/pr19803.d
@@ -9,5 +9,5 @@
 # collection.
 
 #...
-.*\(sec  1\)\(fl 0x00\)\(ty   0\)\(scl   2\) \(nx 0\) 0x0+000 .*Startup.*
+.*\(sec  1\)\(fl 0x00\)\(ty    0\)\(scl   2\) \(nx 0\) 0x0+000 .*Startup.*
 #pass
-- 
2.25.1


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

* Re: [PATCH 1/4] gas: add visibility support for XCOFF
  2022-01-03 13:21 [PATCH 1/4] gas: add visibility support for XCOFF CHIGOT, CLEMENT
@ 2022-01-11 14:18 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2022-01-11 14:18 UTC (permalink / raw)
  To: CHIGOT, CLEMENT, binutils

Hi Clement,

> XCOFF assembly defines the visibility using an additional argument
> on several pseudo-ops: .globl, .weak, .extern and .comm.
> This implies that .globl and .weak syntax is different than the
> usual GNU syntax. But we want to provide compatibility with AIX
> assembler, especially because GCC is generating the visibility
> using this XCOFF syntax.
> 
> PR 22085
> 
> bfd/ChangeLog:
> 
>          * coffcode.h (coff_write_object_contents): Change XCOFF header
>          vstamp field to 2.
>          * coffgen.c (coff_print_symbol): Increase the size for n_type.
> 
> gas/ChangeLog:
> 
>          * config/tc-ppc.c (ppc_xcoff_get_visibility): New function.
>          (ppc_globl): New function.
>          (ppc_weak): New function.
>          (ppc_comm): Add visibility field support.
>          (ppc_extern): Likewise.
>          * testsuite/gas/all/cofftag.d: Adjust to new n_type size
>          providing by objdump.
>          * testsuite/gas/ppc/test1xcoff32.d: Likewise.
>          * testsuite/gas/ppc/aix.exp: Add new tests.
>          * testsuite/gas/ppc/xcoff-visibility-1-32.d: New test.
>          * testsuite/gas/ppc/xcoff-visibility-1-64.d: New test.
>          * testsuite/gas/ppc/xcoff-visibility-1.s: New test.
> 
> include/ChangeLog:
> 
>          * coff/internal.h (SYM_V_INTERNAL, SYM_V_HIDDEN,
>          SYM_V_PROTECTED, SYM_V_EXPORTED, SYM_V_MASK): New defines.
>          * coff/xcoff.h (struct xcoff_link_hash_entry): Add visibility
>          field.
> 
> ld/ChangeLog:
> 
>          * testsuite/ld-pe/pr19803.d: Adjust to new n_type size
>          providing by objdump.

Approved - please apply.

Cheers
   Nick



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

end of thread, other threads:[~2022-01-11 14:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-03 13:21 [PATCH 1/4] gas: add visibility support for XCOFF CHIGOT, CLEMENT
2022-01-11 14:18 ` Nick Clifton

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