aix: Redesign section encoding and selection

AIX symbol references can refer to either the symbol (a label) or a
symbol with a qualifier (the storage mapping class).  The storage mapping
class provide information about the underlying COFF section into which the
symbol will be placed, e.g. [RO] for read-only in the text section,
[RW] for read-writer in the data section, or [BS] for the BSS section.
A label is distinct from a qualname in the assembler language, e.g.,
foo and foo[RW] are different, but the symbol table of an object file strips
the storage mapping class from the name, so that it no longer is relevant
when referring to symbols across object files and libraries.

	.csect .data[RW]
i:

is a label "i" in the .data CSECT, which has storage mapping class [RW]
so that it is placed in the read-write COFF section.

	.csect i[RW]

is a CSECT "i[RW]".  BSS does not allow interior labels.

The AIX port of GCC had been emitting the storage mapping class where
appropriate but not consistently using the storage mapping class on
the DECL or SYM name.  This patch updates the section encoding to properly
place storage mapping class on symbol names and remove the decorations
placed when emitting the symbol.

The mapping classes correspond to sections and the encoding choices must
exactly match the section choices made by get_section, so the logic for
the computation of reloc in get_variable_section is split into its own
function that XCOFF encode section info can call.

gcc/ChangeLog:

	* varasm.c (compute_reloc_for_var): Split out from...
	(get_variable_section): Use it.
	* output.h (compute_reloc_for_var): Declare.
	* config/rs6000/rs6000-protos.h
	(rs6000_xcoff_asm_output_aligned_decl_common): Change alignment to
	unsigned int.
	* config/rs6000/rs6000.c (rs6000_legitimize_tls_address_aix):
	Don't append storage mapping class to symbol.
	(rs6000_xcoff_asm_named_section): Add BS and UL mapping classes.
	Don't convert TLS BSS to common.
	(rs6000_xcoff_unique_section): Don't fall back to select_secton.
	(rs6000_xcoff_section_type_flags): Add SECTION_BSS if DECL is
	bss_initializer.
	(rs6000_xcoff_asm_globalize_decl_name): Don't strip storage
	mapping class.
	(rs6000_xcoff_asm_output_aligned_decl_common): Align is unsigned int.
	If align is 0 from TLS class, use the same rules as varasm.c
	If not common, switch to BSS section manually.
	If common, emit appropriate comm or lcomm directive.
	(rs6000_xcoff_encode_section_info): Add logic to append all
	storage mapping classes.
	(rs6000_asm_weaken_decl): Adjust for qualname symbols.
	* config/rs6000/xcoff.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL): Use
	rs6000_xcoff_asm_output_aligned_decl_common.
	(ASM_OUTPUT_ALIGNED_DECL_LOCAL): Use
	rs6000_xcoff_asm_output_aligned_decl_common.
	(ASM_OUTPUT_TLS_COMMON): Use
	rs6000_xcoff_asm_output_aligned_decl_common.

gcc/testsuite/ChangeLog:
	* g++.dg/ext/visibility/fvisibility-inlines-hidden-4.C: Expect [BS]
	mapping class on AIX.
	* gcc.c-torture/compile/pr61159.c: XFAIL on AIX.
	* gcc.c-torture/execute/alias-2.c: Same.
	* gcc.dg/alias-7.c: Same.
This commit is contained in:
David Edelsohn 2021-04-06 11:41:49 -04:00
parent a13a50047e
commit 92f59e47f5
9 changed files with 133 additions and 110 deletions

View file

@ -243,7 +243,7 @@ extern void rs6000_xcoff_declare_object_name (FILE *, const char *, tree);
extern void rs6000_xcoff_asm_output_aligned_decl_common (FILE *, tree,
const char *,
unsigned HOST_WIDE_INT,
unsigned HOST_WIDE_INT);
unsigned int);
extern void rs6000_elf_declare_function_name (FILE *, const char *, tree);
extern bool rs6000_elf_in_small_data_p (const_tree);

View file

@ -9311,29 +9311,12 @@ rs6000_got_sym (void)
static rtx
rs6000_legitimize_tls_address_aix (rtx addr, enum tls_model model)
{
rtx sym, mem, tocref, tlsreg, tmpreg, dest, tlsaddr;
rtx sym, mem, tocref, tlsreg, tmpreg, dest;
const char *name;
char *tlsname;
name = XSTR (addr, 0);
/* Append TLS CSECT qualifier, unless the symbol already is qualified
or the symbol will be in TLS private data section. */
if (name[strlen (name) - 1] != ']'
&& (TREE_PUBLIC (SYMBOL_REF_DECL (addr))
|| bss_initializer_p (SYMBOL_REF_DECL (addr))))
{
tlsname = XALLOCAVEC (char, strlen (name) + 4);
strcpy (tlsname, name);
strcat (tlsname,
bss_initializer_p (SYMBOL_REF_DECL (addr)) ? "[UL]" : "[TL]");
tlsaddr = copy_rtx (addr);
XSTR (tlsaddr, 0) = ggc_strdup (tlsname);
}
else
tlsaddr = addr;
/* Place addr into TOC constant pool. */
sym = force_const_mem (GET_MODE (tlsaddr), tlsaddr);
sym = force_const_mem (GET_MODE (addr), addr);
/* Output the TOC entry and create the MEM referencing the value. */
if (constant_pool_expr_p (XEXP (sym, 0))
@ -21238,10 +21221,11 @@ rs6000_xcoff_asm_named_section (const char *name, unsigned int flags,
tree decl ATTRIBUTE_UNUSED)
{
int smclass;
static const char * const suffix[5] = { "PR", "RO", "RW", "TL", "XO" };
static const char * const suffix[7]
= { "PR", "RO", "RW", "BS", "TL", "UL", "XO" };
if (flags & SECTION_EXCLUDE)
smclass = 4;
smclass = 6;
else if (flags & SECTION_DEBUG)
{
fprintf (asm_out_file, "\t.dwsect %s\n", name);
@ -21250,9 +21234,19 @@ rs6000_xcoff_asm_named_section (const char *name, unsigned int flags,
else if (flags & SECTION_CODE)
smclass = 0;
else if (flags & SECTION_TLS)
smclass = 3;
{
if (flags & SECTION_BSS)
smclass = 5;
else
smclass = 4;
}
else if (flags & SECTION_WRITE)
smclass = 2;
{
if (flags & SECTION_BSS)
smclass = 3;
else
smclass = 2;
}
else
smclass = 1;
@ -21291,11 +21285,7 @@ rs6000_xcoff_select_section (tree decl, int reloc,
if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
{
if (bss_initializer_p (decl))
{
/* Convert to COMMON to emit in BSS. */
DECL_COMMON (decl) = 1;
return tls_comm_section;
}
return tls_comm_section;
else if (TREE_PUBLIC (decl))
return tls_data_section;
else
@ -21315,17 +21305,6 @@ rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
{
const char *name;
/* Use select_section for private data and uninitialized data with
alignment <= BIGGEST_ALIGNMENT. */
if (!TREE_PUBLIC (decl)
|| DECL_COMMON (decl)
|| (DECL_INITIAL (decl) == NULL_TREE
&& DECL_ALIGN (decl) <= BIGGEST_ALIGNMENT)
|| DECL_INITIAL (decl) == error_mark_node
|| (flag_zero_initialized_in_bss
&& initializer_zerop (DECL_INITIAL (decl))))
return;
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
name = (*targetm.strip_name_encoding) (name);
set_decl_section_name (decl, name);
@ -21370,6 +21349,9 @@ rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
unsigned int align;
unsigned int flags = default_section_type_flags (decl, name, reloc);
if (decl && DECL_P (decl) && VAR_P (decl) && bss_initializer_p (decl))
flags |= SECTION_BSS;
/* Align to at least UNIT size. */
if ((flags & SECTION_CODE) != 0 || !decl || !DECL_P (decl))
align = MIN_UNITS_PER_WORD;
@ -21632,7 +21614,7 @@ rs6000_xcoff_asm_globalize_decl_name (FILE *stream, tree decl)
{
const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
fputs (GLOBAL_ASM_OP, stream);
RS6000_OUTPUT_BASENAME (stream, name);
assemble_name (stream, name);
#ifdef HAVE_GAS_HIDDEN
fputs (rs6000_xcoff_visibility (decl), stream);
#endif
@ -21647,27 +21629,50 @@ rs6000_xcoff_asm_output_aligned_decl_common (FILE *stream,
tree decl ATTRIBUTE_UNUSED,
const char *name,
unsigned HOST_WIDE_INT size,
unsigned HOST_WIDE_INT align)
unsigned int align)
{
unsigned HOST_WIDE_INT align2 = 2;
unsigned int align2 = 2;
if (align == 0)
align = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), DECL_ALIGN (decl));
if (align > 32)
align2 = floor_log2 (align / BITS_PER_UNIT);
else if (size > 4)
align2 = 3;
fputs (COMMON_ASM_OP, stream);
RS6000_OUTPUT_BASENAME (stream, name);
if (! DECL_COMMON (decl))
{
/* Forget section. */
in_section = NULL;
fprintf (stream,
"," HOST_WIDE_INT_PRINT_UNSIGNED "," HOST_WIDE_INT_PRINT_UNSIGNED,
size, align2);
/* Globalize TLS BSS. */
if (TREE_PUBLIC (decl) && DECL_THREAD_LOCAL_P (decl))
fprintf (stream, "\t.globl %s\n", name);
/* Switch to section and skip space. */
fprintf (stream, "\t.csect %s,%u\n", name, align2);
ASM_DECLARE_OBJECT_NAME (stream, name, decl);
ASM_OUTPUT_SKIP (stream, size ? size : 1);
return;
}
if (TREE_PUBLIC (decl))
{
fprintf (stream,
"\t.comm %s," HOST_WIDE_INT_PRINT_UNSIGNED ",%u" ,
name, size, align2);
#ifdef HAVE_GAS_HIDDEN
if (decl != NULL)
fputs (rs6000_xcoff_visibility (decl), stream);
if (decl != NULL)
fputs (rs6000_xcoff_visibility (decl), stream);
#endif
putc ('\n', stream);
putc ('\n', stream);
}
else
fprintf (stream,
"\t.lcomm %s," HOST_WIDE_INT_PRINT_UNSIGNED ",%s,%u\n",
(*targetm.strip_name_encoding) (name), size, name, align2);
}
/* This macro produces the initial definition of a object (variable) name.
@ -21733,19 +21738,50 @@ rs6000_xcoff_encode_section_info (tree decl, rtx rtl, int first)
SYMBOL_REF_FLAGS (symbol) = flags;
/* Append mapping class to extern decls. */
symname = XSTR (symbol, 0);
if (decl /* sync condition with assemble_external () */
&& DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)
&& ((TREE_CODE (decl) == VAR_DECL && !DECL_THREAD_LOCAL_P (decl))
|| TREE_CODE (decl) == FUNCTION_DECL)
/* Append CSECT mapping class, unless the symbol already is qualified. */
if (decl
&& DECL_P (decl)
&& VAR_OR_FUNCTION_DECL_P (decl)
&& lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) == NULL_TREE
&& symname[strlen (symname) - 1] != ']')
{
char *newname = (char *) alloca (strlen (symname) + 5);
strcpy (newname, symname);
strcat (newname, (TREE_CODE (decl) == FUNCTION_DECL
? "[DS]" : "[UA]"));
XSTR (symbol, 0) = ggc_strdup (newname);
const char *smclass = NULL;
if (TREE_CODE (decl) == FUNCTION_DECL)
{
if (DECL_EXTERNAL (decl))
smclass = "[DS]";
}
else if (DECL_THREAD_LOCAL_P (decl))
{
if (bss_initializer_p (decl))
smclass = "[UL]";
else if (flag_data_sections)
smclass = "[TL]";
}
else if (DECL_EXTERNAL (decl))
smclass = "[UA]";
else if (bss_initializer_p (decl))
smclass = "[BS]";
else if (flag_data_sections)
{
/* This must exactly match the logic of select section. */
if (decl_readonly_section (decl, compute_reloc_for_var (decl)))
smclass = "[RO]";
else
smclass = "[RW]";
}
if (smclass != NULL)
{
char *newname = XALLOCAVEC (char, strlen (symname) + 5);
strcpy (newname, symname);
strcat (newname, smclass);
XSTR (symbol, 0) = ggc_strdup (newname);
}
}
}
#endif /* HAVE_AS_TLS */
@ -21756,11 +21792,11 @@ rs6000_asm_weaken_decl (FILE *stream, tree decl,
const char *name, const char *val)
{
fputs ("\t.weak\t", stream);
RS6000_OUTPUT_BASENAME (stream, name);
assemble_name (stream, name);
if (decl && TREE_CODE (decl) == FUNCTION_DECL
&& DEFAULT_ABI == ABI_AIX && DOT_SYMBOLS)
{
if (TARGET_XCOFF)
if (TARGET_XCOFF && name[strlen (name) - 1] != ']')
fputs ("[DS]", stream);
#if TARGET_XCOFF && HAVE_GAS_HIDDEN
if (TARGET_XCOFF)

View file

@ -104,6 +104,8 @@
#define TARGET_ENCODE_SECTION_INFO rs6000_xcoff_encode_section_info
#endif
#define ASM_OUTPUT_ALIGNED_DECL_COMMON rs6000_xcoff_asm_output_aligned_decl_common
#define ASM_OUTPUT_ALIGNED_DECL_LOCAL rs6000_xcoff_asm_output_aligned_decl_common
#define ASM_OUTPUT_ALIGNED_BSS rs6000_xcoff_asm_output_aligned_decl_common
/* FP save and restore routines. */
#define SAVE_FP_PREFIX "._savef"
@ -218,48 +220,12 @@
to define a global common symbol. */
#define COMMON_ASM_OP "\t.comm "
/* This says how to output an assembler line
to define a local common symbol.
The assembler in AIX 6.1 and later supports an alignment argument.
For earlier releases of AIX, we try to maintain
alignment after preceding TOC section if it was aligned
for 64-bit mode. */
#define LOCAL_COMMON_ASM_OP "\t.lcomm "
#if TARGET_AIX_VERSION >= 61
#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
do { fputs (LOCAL_COMMON_ASM_OP, (FILE)); \
RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
if ((ALIGN) > 32) \
fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED",%s%u_,%u\n", \
(SIZE), xcoff_bss_section_name, \
floor_log2 ((ALIGN) / BITS_PER_UNIT), \
floor_log2 ((ALIGN) / BITS_PER_UNIT)); \
else if ((SIZE) > 4) \
fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED",%s3_,3\n", \
(SIZE), xcoff_bss_section_name); \
else \
fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED",%s,2\n", \
(SIZE), xcoff_bss_section_name); \
} while (0)
#endif
#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
do { fputs (LOCAL_COMMON_ASM_OP, (FILE)); \
RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED",%s\n", \
(TARGET_32BIT ? (SIZE) : (ROUNDED)), \
xcoff_bss_section_name); \
} while (0)
#ifdef HAVE_AS_TLS
#define ASM_OUTPUT_TLS_COMMON(FILE, DECL, NAME, SIZE) \
do { fputs (COMMON_ASM_OP, (FILE)); \
RS6000_OUTPUT_BASENAME ((FILE), (NAME)); \
fprintf ((FILE), "[UL]," HOST_WIDE_INT_PRINT_UNSIGNED"\n", \
(SIZE)); \
#define ASM_OUTPUT_TLS_COMMON(FILE, DECL, NAME, SIZE) \
do { \
rs6000_xcoff_asm_output_aligned_decl_common ((FILE), (DECL), (NAME), (SIZE), 0); \
} while (0)
#endif

View file

@ -349,6 +349,9 @@ extern bool decl_readonly_section (const_tree, int);
given a constant expression. */
extern int compute_reloc_for_constant (tree);
/* This can be used to compute RELOC for get_variable_section. */
extern int compute_reloc_for_var (tree);
/* User label prefix in effect for this compilation. */
extern const char *user_label_prefix;

View file

@ -6,7 +6,7 @@
/* { dg-final { scan-not-hidden "_ZZ3barvE1n" } } */
/* { dg-final { scan-not-hidden "_Z3fooIiEvv" } } */
/* { dg-final { scan-hidden "_Z3fooIvEvv" } } */
/* { dg-final { scan-hidden "_ZZN1A5innerEvE1n" } } */
/* { dg-final { scan-hidden "_ZZN1A5innerEvE1n(\\\[BS\\\])?" } } */
inline int * bar()
{

View file

@ -1,5 +1,6 @@
/* { dg-require-alias "" } */
/* { dg-require-weak "" } */
/* { dg-xfail-if "weak alias" { powerpc-ibm-aix* } } */
static int dummy = 0;
extern int foo __attribute__((__weak__, __alias__("dummy")));

View file

@ -1,4 +1,5 @@
/* { dg-require-alias "" } */
/* { dg-skip-if "BSS alias" { powerpc-ibm-aix* } } */
int a[10]={};
extern int b[10] __attribute__ ((alias("a")));
int off;

View file

@ -1,6 +1,7 @@
/* { dg-do run } */
/* { dg-require-alias "" } */
/* { dg-options "-O2" } */
/* { dg-skip-if "weak alias" { powerpc-ibm-aix* } } */
extern void abort (void);

View file

@ -1202,6 +1202,25 @@ get_variable_align (tree decl)
return align;
}
/* Compute reloc for get_variable_section. The return value
is a mask for which bit 1 indicates a global relocation, and bit 0
indicates a local relocation. */
int
compute_reloc_for_var (tree decl)
{
int reloc;
if (DECL_INITIAL (decl) == error_mark_node)
reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
else if (DECL_INITIAL (decl))
reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
else
reloc = 0;
return reloc;
}
/* Return the section into which the given VAR_DECL or CONST_DECL
should be placed. PREFER_NOSWITCH_P is true if a noswitch
section should be used wherever possible. */
@ -1239,12 +1258,7 @@ get_variable_section (tree decl, bool prefer_noswitch_p)
return comm_section;
}
if (DECL_INITIAL (decl) == error_mark_node)
reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
else if (DECL_INITIAL (decl))
reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
else
reloc = 0;
reloc = compute_reloc_for_var (decl);
resolve_unique_section (decl, reloc, flag_data_sections);
if (IN_NAMED_SECTION (decl))
@ -7252,7 +7266,8 @@ compute_reloc_for_rtx_1 (const_rtx x)
/* Like compute_reloc_for_constant, except for an RTX. The return value
is a mask for which bit 1 indicates a global relocation, and bit 0
indicates a local relocation. */
indicates a local relocation. Used by default_select_rtx_section
and default_elf_select_rtx_section. */
static int
compute_reloc_for_rtx (const_rtx x)