This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: 4.1/4.2 PATCH: PR middle-end/20218: Can't use __attribute__ ((visibility ("hidden"))) to hide a symbol
On Sun, Jan 14, 2007 at 06:35:15PM -0800, H. J. Lu wrote:
> On Mon, Jan 15, 2007 at 01:19:40AM +0000, Richard Sandiford wrote:
> > "H. J. Lu" <hjl@lucon.org> writes:
> > > I am enclosing backported 4.1/4.2 patches for PR middle-end/20218.
> >
> > If you're backporting a patch for elfos.h to a release branch, I think
> > you need to explain why you think it's safe for all elfos ports.
> > I realise you can't test them all, but you can at least (for example)
> > grep for definitions of ASM_OUTPUT_EXTERNAL.
> >
> > Your original mainline patch broke bootstrap on mips-linux-gnu (which
> > I know you know, because you commented on it). I think it would be
> > reasonable under the circumstances to expect you to include that fix
> > in your backport too. From a quick grep, I'm also dubious about pa/elf.h.
> > Does anything undefine your new elfos definition before pa/elf.h defines
> > the new one? What about config/score/score.h?
>
> I don't like to blindly undef ASM_OUTPUT_EXTERNAL to make an ELF
> backend to compile. It doesn't belong to my bug fix. I can provide
> a separate patch to undef ASM_OUTPUT_EXTERNAL for those ports which
> are affected. I only got one report on MIPS.
>
> Ideally, ASM_OUTPUT_EXTERNAL defined in each ELF backend should be
> double checked to see if it should be rewritten. Otherwise, that ELF
> backend may not include my bug fix, which is the case for MIPS in
> mainline. If someone wants to fix it, I can help.
>
>
Here is a patch for mips. Someone needs to verify/test it on all mips
platforms, including IRIX.
H.J.
----
2007-01-14 H.J. Lu <hongjiu.lu@intel.com>
* config/mips/iris.h (TARGET_ASM_EXTERNAL_LIBCALL): Removed.
* config/mips/mips.c (irix_output_external_libcall): Likewise.
(extern_list): Likewise.
(extern_head): Likewise.
(TARGET_ASM_FILE_END): Likewise.
(mips_file_end): Likewise.
(mips_output_external): Rewritten.
* config/mips/mips-protos.h (mips_output_external): Make it
return void.
--- gcc/config/mips/iris.h.global 2006-09-27 22:38:20.000000000 -0700
+++ gcc/config/mips/iris.h 2007-01-14 20:29:15.000000000 -0800
@@ -61,10 +61,6 @@ Boston, MA 02110-1301, USA. */
#undef ASM_FINISH_DECLARE_OBJECT
#define ASM_FINISH_DECLARE_OBJECT mips_finish_declare_object
-/* Also do this for libcalls. */
-#undef TARGET_ASM_EXTERNAL_LIBCALL
-#define TARGET_ASM_EXTERNAL_LIBCALL irix_output_external_libcall
-
/* The linker needs a space after "-o". */
#define SWITCHES_NEED_SPACES "o"
--- gcc/config/mips/mips-protos.h.global 2006-09-27 22:38:20.000000000 -0700
+++ gcc/config/mips/mips-protos.h 2007-01-14 21:39:17.000000000 -0800
@@ -197,7 +197,7 @@ extern HOST_WIDE_INT mips_debugger_offse
extern void print_operand (FILE *, rtx, int);
extern void print_operand_address (FILE *, rtx);
-extern int mips_output_external (FILE *, tree, const char *);
+extern void mips_output_external (FILE *, tree, const char *);
extern void mips_output_filename (FILE *, const char *);
extern void mips_output_ascii (FILE *, const char *, size_t, const char *);
extern void mips_output_aligned_bss (FILE *, tree, const char *,
--- gcc/config/mips/mips.c.global 2007-01-03 21:41:29.000000000 -0800
+++ gcc/config/mips/mips.c 2007-01-14 21:38:51.000000000 -0800
@@ -303,11 +303,10 @@ static void mips_set_tune (const struct
static bool mips_handle_option (size_t, const char *, int);
static struct machine_function *mips_init_machine_status (void);
static void print_operand_reloc (FILE *, rtx, const char **);
-#if TARGET_IRIX
-static void irix_output_external_libcall (rtx);
-#endif
static void mips_file_start (void);
+#ifndef USING_ELFOS_H
static void mips_file_end (void);
+#endif
static bool mips_rewrite_small_data_p (rtx);
static int mips_small_data_pattern_1 (rtx *, void *);
static int mips_rewrite_small_data_1 (rtx *, void *);
@@ -552,19 +551,6 @@ int sdb_label_count = 0;
/* Next label # for each statement for Silicon Graphics IRIS systems. */
int sym_lineno = 0;
-/* Linked list of all externals that are to be emitted when optimizing
- for the global pointer if they haven't been declared by the end of
- the program with an appropriate .comm or initialization. */
-
-struct extern_list GTY (())
-{
- struct extern_list *next; /* next external */
- const char *name; /* name of the external */
- int size; /* size in bytes */
-};
-
-static GTY (()) struct extern_list *extern_head = 0;
-
/* Name of the file containing the current function. */
const char *current_function_file = "";
@@ -1144,9 +1130,7 @@ static struct mips_rtx_cost_data const m
#define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
#undef TARGET_ASM_FILE_START
-#undef TARGET_ASM_FILE_END
#define TARGET_ASM_FILE_START mips_file_start
-#define TARGET_ASM_FILE_END mips_file_end
#undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
#define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
@@ -5786,48 +5770,42 @@ print_operand_address (FILE *file, rtx x
the -G limit but declared by the user to be in a section other
than .sbss or .sdata. */
-int
-mips_output_external (FILE *file ATTRIBUTE_UNUSED, tree decl, const char *name)
-{
- register struct extern_list *p;
-
- if (!TARGET_EXPLICIT_RELOCS && mips_in_small_data_p (decl))
- {
- p = (struct extern_list *) ggc_alloc (sizeof (struct extern_list));
- p->next = extern_head;
- p->name = name;
- p->size = int_size_in_bytes (TREE_TYPE (decl));
- extern_head = p;
- }
-
- if (TARGET_IRIX && mips_abi == ABI_32 && TREE_CODE (decl) == FUNCTION_DECL)
- {
- p = (struct extern_list *) ggc_alloc (sizeof (struct extern_list));
- p->next = extern_head;
- p->name = name;
- p->size = -1;
- extern_head = p;
- }
-
- return 0;
-}
-
-#if TARGET_IRIX
-static void
-irix_output_external_libcall (rtx fun)
+void
+mips_output_external (FILE *file ATTRIBUTE_UNUSED, tree decl,
+ const char *name)
{
- register struct extern_list *p;
+ /* We output the name if and only if TREE_SYMBOL_REFERENCED is
+ set in order to avoid putting out names that are never really
+ used. */
+ if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
+ {
+#ifdef USING_ELFOS_H
+ if (targetm.binds_local_p (decl))
+ maybe_assemble_visibility (decl);
+#endif
- if (mips_abi == ABI_32)
- {
- p = (struct extern_list *) ggc_alloc (sizeof (struct extern_list));
- p->next = extern_head;
- p->name = XSTR (fun, 0);
- p->size = -1;
- extern_head = p;
+ if (!TARGET_EXPLICIT_RELOCS && mips_in_small_data_p (decl))
+ {
+ fputs ("\t.extern\t", asm_out_file);
+ assemble_name (asm_out_file, name);
+ fprintf (asm_out_file, ", %ld\n",
+ int_size_in_bytes (TREE_TYPE (decl)));
+ }
+ else if (TARGET_IRIX
+ && mips_abi == ABI_32
+ && TREE_CODE (decl) == FUNCTION_DECL)
+ {
+ /* In IRIX 5 or IRIX 6 for the O32 ABI, we must output a
+ `.global name .text' directive for every used but
+ undefined function. If we don't, the linker may perform
+ an optimization (skipping over the insns that set $gp)
+ when it is unsafe. */
+ fputs ("\t.globl ", asm_out_file);
+ assemble_name (asm_out_file, name);
+ fputs (" .text\n", asm_out_file);
+ }
}
}
-#endif
/* Emit a new filename to a stream. If we are smuggling stabs, try to
put out a MIPS ECOFF file and a stab. */
@@ -5989,50 +5967,6 @@ mips_output_aligned_bss (FILE *stream, t
}
#endif
-/* Implement TARGET_ASM_FILE_END. When using assembler macros, emit
- .externs for any small-data variables that turned out to be external. */
-
-static void
-mips_file_end (void)
-{
- tree name_tree;
- struct extern_list *p;
-
- if (extern_head)
- {
- fputs ("\n", asm_out_file);
-
- for (p = extern_head; p != 0; p = p->next)
- {
- name_tree = get_identifier (p->name);
-
- /* Positively ensure only one .extern for any given symbol. */
- if (!TREE_ASM_WRITTEN (name_tree)
- && TREE_SYMBOL_REFERENCED (name_tree))
- {
- TREE_ASM_WRITTEN (name_tree) = 1;
- /* In IRIX 5 or IRIX 6 for the O32 ABI, we must output a
- `.global name .text' directive for every used but
- undefined function. If we don't, the linker may perform
- an optimization (skipping over the insns that set $gp)
- when it is unsafe. */
- if (TARGET_IRIX && mips_abi == ABI_32 && p->size == -1)
- {
- fputs ("\t.globl ", asm_out_file);
- assemble_name (asm_out_file, p->name);
- fputs (" .text\n", asm_out_file);
- }
- else
- {
- fputs ("\t.extern\t", asm_out_file);
- assemble_name (asm_out_file, p->name);
- fprintf (asm_out_file, ", %d\n", p->size);
- }
- }
- }
- }
-}
-
/* Implement ASM_OUTPUT_ALIGNED_DECL_COMMON. This is usually the same as the
elfos.h version, but we also need to handle -muninit-const-in-rodata. */