re PR middle-end/46674 (Weak alias is mistakenly optimized away)

gcc/ChangeLog:

	PR middle-end/46674
	PR lto/43157
	* target.def (mangle_assembler_name): New target asm_out hook.
	* targhooks.c (default_mangle_assembler_name): Add default hook
	implementation.
	* targhooks.h (default_mangle_assembler_name): Add prototype.
	* lto-symtab.c (lto_symtab_register_decl): Use new hook when
	processing DECL_ASSEMBLER_NAMEs for lto symtabs.
	(lto_symtab_get_resolution): Likewise.
	(lto_cgraph_replace_node): Likewise.
	(lto_symtab_prevailing_decl): Likewise.
	* lto-streamer-out.c (write_symbol): Likewise.
	* doc/tm.texi.in (TARGET_MANGLE_ASSEMBLER_NAME): Add @hook directive.
	* doc/tm.texi: Regenerate.
	* config/i386/cygming.h (TARGET_MANGLE_ASSEMBLER_NAME): Define to
	point at i386_pe_mangle_assembler_name.
	* config/i386/winnt.c (i386_pe_mangle_assembler_name): New function.
	* config/i386/i386-protos.h (i386_pe_mangle_assembler_name): Add
	prototype.

lto-plugin/ChangeLog:

	PR middle-end/46674
	PR lto/43157
	* configure.ac (SYM_STYLE): Don't AC_DEFINE.
	* lto-plugin.c (sym_style): Don't use it; default to ss_none.
	* configure: Regenerate.
	* config.h.in: Likewise.

gcc/testsuite/ChangeLog:

	PR middle-end/46674
	PR lto/43157
	* gcc.dg/pr43157.c: New file.

From-SVN: r167688
This commit is contained in:
Dave Korn 2010-12-10 14:28:58 +00:00 committed by Dave Korn
parent 4816c5938d
commit 77754180a9
18 changed files with 120 additions and 45 deletions

View File

@ -1,3 +1,25 @@
2010-12-10 Dave Korn <dave.korn.cygwin@gmail.com>
PR middle-end/46674
PR lto/43157
* target.def (mangle_assembler_name): New target asm_out hook.
* targhooks.c (default_mangle_assembler_name): Add default hook
implementation.
* targhooks.h (default_mangle_assembler_name): Add prototype.
* lto-symtab.c (lto_symtab_register_decl): Use new hook when
processing DECL_ASSEMBLER_NAMEs for lto symtabs.
(lto_symtab_get_resolution): Likewise.
(lto_cgraph_replace_node): Likewise.
(lto_symtab_prevailing_decl): Likewise.
* lto-streamer-out.c (write_symbol): Likewise.
* doc/tm.texi.in (TARGET_MANGLE_ASSEMBLER_NAME): Add @hook directive.
* doc/tm.texi: Regenerate.
* config/i386/cygming.h (TARGET_MANGLE_ASSEMBLER_NAME): Define to
point at i386_pe_mangle_assembler_name.
* config/i386/winnt.c (i386_pe_mangle_assembler_name): New function.
* config/i386/i386-protos.h (i386_pe_mangle_assembler_name): Add
prototype.
2010-12-10 Nathan Froyd <froydnj@codesourcery.com>
* c-typeck.c (readonly_error): Delete.

View File

@ -252,6 +252,10 @@ do { \
fputs ((NAME), (STREAM)); \
} while (0)
/* This does much the same in memory rather than to a stream. */
#undef TARGET_MANGLE_ASSEMBLER_NAME
#define TARGET_MANGLE_ASSEMBLER_NAME i386_pe_mangle_assembler_name
/* Emit code to check the stack when allocating more than 4000
bytes in one go. */

View File

@ -226,6 +226,7 @@ extern void i386_pe_file_end (void);
extern void i386_pe_start_function (FILE *, const char *, tree);
extern void i386_pe_end_function (FILE *, const char *, tree);
extern tree i386_pe_mangle_decl_assembler_name (tree, tree);
extern tree i386_pe_mangle_assembler_name (const char *);
extern void i386_pe_seh_init (FILE *);
extern void i386_pe_seh_end_prologue (FILE *);

View File

@ -244,6 +244,20 @@ i386_pe_mangle_decl_assembler_name (tree decl, tree id)
return (new_id ? new_id : id);
}
/* This hook behaves the same as varasm.c/assemble_name(), but
generates the name into memory rather than outputting it to
a file stream. */
tree
i386_pe_mangle_assembler_name (const char *name ATTRIBUTE_UNUSED)
{
const char *skipped = name + (*name == '*' ? 1 : 0);
const char *stripped = targetm.strip_name_encoding (skipped);
if (*name != '*' && *user_label_prefix && *stripped != FASTCALL_PREFIX)
stripped = ACONCAT ((user_label_prefix, stripped, NULL));
return get_identifier (stripped);
}
void
i386_pe_encode_section_info (tree decl, rtx rtl, int first)
{

View File

@ -8041,6 +8041,10 @@ is customary on your operating system, as it is in most Berkeley Unix
systems. This macro is used in @code{assemble_name}.
@end defmac
@deftypefn {Target Hook} tree TARGET_MANGLE_ASSEMBLER_NAME (const char *@var{name})
Given a symbol @var{name}, perform same mangling as @code{varasm.c}'s @code{assemble_name}, but in memory rather than to a file stream, returning result as an @code{IDENTIFIER_NODE}. Required for correct LTO symtabs. The default implementation calls the @code{TARGET_STRIP_NAME_ENCODING} hook and then prepends the @code{USER_LABEL_PREFIX}, if any.
@end deftypefn
@defmac ASM_OUTPUT_SYMBOL_REF (@var{stream}, @var{sym})
A C statement (sans semicolon) to output a reference to
@code{SYMBOL_REF} @var{sym}. If not defined, @code{assemble_name}

View File

@ -8013,6 +8013,8 @@ is customary on your operating system, as it is in most Berkeley Unix
systems. This macro is used in @code{assemble_name}.
@end defmac
@hook TARGET_MANGLE_ASSEMBLER_NAME
@defmac ASM_OUTPUT_SYMBOL_REF (@var{stream}, @var{sym})
A C statement (sans semicolon) to output a reference to
@code{SYMBOL_REF} @var{sym}. If not defined, @code{assemble_name}

View File

@ -2368,16 +2368,14 @@ write_symbol (struct lto_streamer_cache_d *cache,
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
/* This behaves like assemble_name_raw in varasm.c, performing the
same name manipulations that ASM_OUTPUT_LABELREF does. */
name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
if (pointer_set_contains (seen, name))
return;
pointer_set_insert (seen, name);
/* FIXME lto: this is from assemble_name_raw in varasm.c. For some
architectures we might have to do the same name manipulations that
ASM_OUTPUT_LABELREF does. */
if (name[0] == '*')
name = &name[1];
lto_streamer_cache_lookup (cache, t, &slot_num);
gcc_assert (slot_num >= 0);

View File

@ -155,7 +155,8 @@ lto_symtab_register_decl (tree decl,
gcc_assert (!DECL_ABSTRACT (decl));
new_entry = ggc_alloc_cleared_lto_symtab_entry_def ();
new_entry->id = DECL_ASSEMBLER_NAME (decl);
new_entry->id = (*targetm.asm_out.mangle_assembler_name)
(IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
new_entry->decl = decl;
new_entry->resolution = resolution;
new_entry->file_data = file_data;
@ -190,7 +191,8 @@ lto_symtab_get_resolution (tree decl)
gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
e = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
e = lto_symtab_get ((*targetm.asm_out.mangle_assembler_name)
(IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
while (e && e->decl != decl)
e = e->next;
if (!e)
@ -218,7 +220,8 @@ lto_cgraph_replace_node (struct cgraph_node *node,
cgraph_node_name (node), node->uid,
cgraph_node_name (prevailing_node),
prevailing_node->uid,
IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name)
(IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)))));
}
if (prevailing_node->same_body_alias)
@ -836,7 +839,8 @@ lto_symtab_prevailing_decl (tree decl)
gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
/* Walk through the list of candidates and return the one we merged to. */
ret = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
ret = lto_symtab_get ((*targetm.asm_out.mangle_assembler_name)
(IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
if (!ret)
return NULL_TREE;

View File

@ -524,6 +524,18 @@ DEFHOOK_UNDOC
bool ,(unsigned char code),
default_print_operand_punct_valid_p)
/* Given a symbol name, perform same mangling as assemble_name and
ASM_OUTPUT_LABELREF, returning result as an IDENTIFIER_NODE. */
DEFHOOK
(mangle_assembler_name,
"Given a symbol @var{name}, perform same mangling as @code{varasm.c}'s\
@code{assemble_name}, but in memory rather than to a file stream, returning\
result as an @code{IDENTIFIER_NODE}. Required for correct LTO symtabs. The\
default implementation calls the @code{TARGET_STRIP_NAME_ENCODING} hook and\
then prepends the @code{USER_LABEL_PREFIX}, if any.",
tree, (const char *name),
default_mangle_assembler_name)
HOOK_VECTOR_END (asm_out)
/* Functions relating to instruction scheduling. All of these

View File

@ -358,6 +358,17 @@ default_print_operand_punct_valid_p (unsigned char code ATTRIBUTE_UNUSED)
#endif
}
/* The default implementation of TARGET_MANGLE_ASSEMBLER_NAME. */
tree
default_mangle_assembler_name (const char *name ATTRIBUTE_UNUSED)
{
const char *skipped = name + (*name == '*' ? 1 : 0);
const char *stripped = targetm.strip_name_encoding (skipped);
if (*name != '*' && user_label_prefix[0])
stripped = ACONCAT ((user_label_prefix, stripped, NULL));
return get_identifier (stripped);
}
/* The default implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */
bool

View File

@ -65,6 +65,8 @@ extern bool hook_callee_copies_named
extern void default_print_operand (FILE *, rtx, int);
extern void default_print_operand_address (FILE *, rtx);
extern bool default_print_operand_punct_valid_p (unsigned char);
extern tree default_mangle_assembler_name (const char *);
extern bool default_asm_output_addr_const_extra (FILE *, rtx);
extern bool default_scalar_mode_supported_p (enum machine_mode);

View File

@ -1,3 +1,9 @@
2010-12-10 Dave Korn <dave.korn.cygwin@gmail.com>
PR middle-end/46674
PR lto/43157
* gcc.dg/pr43157.c: New file.
2010-12-10 Nathan Froyd <froydnj@codesourcery.com>
* gcc.dg/dfp/struct-union.c: Adjust.

View File

@ -0,0 +1,19 @@
/* { dg-do link } */
/* { dg-require-effective-target lto } */
/* { dg-options "-O1 -flto -fuse-linker-plugin" } */
#define LABEL3(pfx, x) # pfx x
#define LABEL2(pfx, x) LABEL3(pfx, x)
#define LABEL(x) LABEL2(__USER_LABEL_PREFIX__, x)
unsigned int factorial_ (unsigned int) __asm__ (LABEL ("factorial"));
unsigned int factorial (unsigned int i)
{
return i > 1 ? i * factorial_ (i - 1) : 1;
}
int main (void)
{
return factorial (5);
}

View File

@ -1,3 +1,12 @@
2010-12-10 Dave Korn <dave.korn.cygwin@gmail.com>
PR middle-end/46674
PR lto/43157
* configure.ac (SYM_STYLE): Don't AC_DEFINE.
* lto-plugin.c (sym_style): Don't use it; default to ss_none.
* configure: Regenerate.
* config.h.in: Likewise.
2010-12-06 Dave Korn <dave.korn.cygwin@gmail.com>
PR target/40125

View File

@ -61,9 +61,6 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Default symbol style */
#undef SYM_STYLE
/* Version number of package */
#undef VERSION

18
lto-plugin/configure vendored
View File

@ -10872,24 +10872,6 @@ esac
# Trying to get this information from gcc's config is tricky.
case $target in
x86_64*-mingw*)
$as_echo "#define SYM_STYLE ss_none" >>confdefs.h
;;
*-cygwin* | i?86*-mingw* )
$as_echo "#define SYM_STYLE ss_win32" >>confdefs.h
;;
*)
$as_echo "#define SYM_STYLE ss_none" >>confdefs.h
;;
esac
ac_fn_c_find_intX_t "$LINENO" "64" "ac_cv_c_int64_t"
case $ac_cv_c_int64_t in #(
no|yes) ;; #(

View File

@ -9,18 +9,6 @@ AC_SYS_LARGEFILE
AM_PROG_LIBTOOL
ACX_LT_HOST_FLAGS
AC_SUBST(target_noncanonical)
# Trying to get this information from gcc's config is tricky.
case $target in
x86_64*-mingw*)
AC_DEFINE([SYM_STYLE], [ss_none], [Default symbol style])
;;
*-cygwin* | i?86*-mingw* )
AC_DEFINE([SYM_STYLE], [ss_win32], [Default symbol style])
;;
*)
AC_DEFINE([SYM_STYLE], [ss_none], [Default symbol style])
;;
esac
AC_TYPE_INT64_T
AC_TYPE_UINT64_T
AC_HEADER_SYS_WAIT

View File

@ -152,10 +152,10 @@ static char debug;
static char nop;
static char *resolution_file = NULL;
/* Set by default from configure.ac, but can be overridden at runtime
/* Not used by default, but can be overridden at runtime
by using -plugin-opt=-sym-style={none,win32,underscore|uscore}
(in fact, only first letter of style arg is checked.) */
static enum symbol_style sym_style = SYM_STYLE;
static enum symbol_style sym_style = ss_none;
static void
check_1 (int gate, enum ld_plugin_level level, const char *text)