This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gold lto patch] Add plugin support for LDPR_PREVAILING_DEF_IRONLY_EXP


> This patch adds LDPT_GET_SYMBOLS_V2 to the gold plugin API, which will
> return the new LDPR_PREVAILING_DEF_IRONLY_EXP resolution code for
> symbols that are referenced only from IR code, but are exported. For
> more details, see GCC PR lto/47247:
> 
>    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47247
> 
> Tested on x86_64. OK to commit?
> 
> -cary
> 
> PS: Is this the right way to put GCC PR tags in a binutils ChangeLog?
> 
> PPS: Sorry, Honza, for taking so long. I had the implementation done
> at the London conference, but never found the time to update the test
> suite.

Hi,
thanks and I am attaching what should be support on GCC side.  However I run into problem
that when bulding i.e. tramp3d:
/abuild/jh/trunk-install/bin/g++ -O2 -flto=24 tramp3d-v43.o -fpermissive -fdump-ipa-cgraph -fno-fat-lto-objects  --save-temps -fuse-linker-plugin
I get no PREVAILING_DEF_INRONLY relocations.  Since I now output all comdats into
symbol table there should be plenty of them.

Any ideas?

Honza

Index: lto-plugin/lto-plugin.c
===================================================================
*** lto-plugin/lto-plugin.c	(revision 179274)
--- lto-plugin/lto-plugin.c	(working copy)
*************** enum symbol_style
*** 129,135 ****
  static char *arguments_file_name;
  static ld_plugin_register_claim_file register_claim_file;
  static ld_plugin_register_all_symbols_read register_all_symbols_read;
! static ld_plugin_get_symbols get_symbols;
  static ld_plugin_register_cleanup register_cleanup;
  static ld_plugin_add_input_file add_input_file;
  static ld_plugin_add_input_library add_input_library;
--- 129,135 ----
  static char *arguments_file_name;
  static ld_plugin_register_claim_file register_claim_file;
  static ld_plugin_register_all_symbols_read register_all_symbols_read;
! static ld_plugin_get_symbols get_symbols, get_symbols_v2;
  static ld_plugin_register_cleanup register_cleanup;
  static ld_plugin_add_input_file add_input_file;
  static ld_plugin_add_input_library add_input_library;
*************** write_resolution (void)
*** 441,447 ****
        struct plugin_symtab *symtab = &info->symtab;
        struct ld_plugin_symbol *syms = symtab->syms;
  
!       get_symbols (info->handle, symtab->nsyms, syms);
  
        finish_conflict_resolution (symtab, &info->conflicts);
  
--- 441,451 ----
        struct plugin_symtab *symtab = &info->symtab;
        struct ld_plugin_symbol *syms = symtab->syms;
  
!       /* Version 2 of API supports IRONLY_EXP resolution.  */
!       if (get_symbols_v2)
!         get_symbols_v2 (info->handle, symtab->nsyms, syms);
!       else
!         get_symbols (info->handle, symtab->nsyms, syms);
  
        finish_conflict_resolution (symtab, &info->conflicts);
  
*************** onload (struct ld_plugin_tv *tv)
*** 986,991 ****
--- 990,998 ----
  	case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK:
  	  register_all_symbols_read = p->tv_u.tv_register_all_symbols_read;
  	  break;
+ 	case LDPT_GET_SYMBOLS_V2:
+ 	  get_symbols_v2 = p->tv_u.tv_get_symbols;
+ 	  break;
  	case LDPT_GET_SYMBOLS:
  	  get_symbols = p->tv_u.tv_get_symbols;
  	  break;
Index: gcc/lto-symtab.c
===================================================================
*** gcc/lto-symtab.c	(revision 179274)
--- gcc/lto-symtab.c	(working copy)
*************** lto_symtab_merge_decls_1 (void **slot, v
*** 586,591 ****
--- 589,595 ----
    for (prevailing = (lto_symtab_entry_t) *slot;
         prevailing
         && prevailing->resolution != LDPR_PREVAILING_DEF_IRONLY
+        && prevailing->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP
         && prevailing->resolution != LDPR_PREVAILING_DEF;
         prevailing = prevailing->next)
      ;
*************** lto_symtab_merge_decls_1 (void **slot, v
*** 595,600 ****
--- 599,605 ----
      for (e = prevailing->next; e; e = e->next)
        {
  	if (e->resolution == LDPR_PREVAILING_DEF_IRONLY
+ 	    || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
  	    || e->resolution == LDPR_PREVAILING_DEF)
  	  fatal_error ("multiple prevailing defs for %qE",
  		       DECL_NAME (prevailing->decl));
*************** lto_symtab_merge_decls_1 (void **slot, v
*** 685,693 ****
       to handle UNKNOWN relocation well.
  
       The problem with storing guessed decision is whether to use
!      PREVAILING_DEF or PREVAILING_DEF_IRONLY.  First one would disable
!      some whole program optimizations, while ther second would imply
!      to many whole program assumptions.  */
    if (prevailing->node && !flag_ltrans && !prevailing->guessed)
      prevailing->node->resolution = prevailing->resolution;
    else if (prevailing->vnode && !flag_ltrans && !prevailing->guessed)
--- 690,698 ----
       to handle UNKNOWN relocation well.
  
       The problem with storing guessed decision is whether to use
!      PREVAILING_DEF, PREVAILING_DEF_IRONLY, PREVAILING_DEF_IRONLY_EXP.
!      First one would disable some whole program optimizations, while
!      ther second would imply to many whole program assumptions.  */
    if (prevailing->node && !flag_ltrans && !prevailing->guessed)
      prevailing->node->resolution = prevailing->resolution;
    else if (prevailing->vnode && !flag_ltrans && !prevailing->guessed)
Index: gcc/cgraph.c
===================================================================
*** gcc/cgraph.c	(revision 179274)
--- gcc/cgraph.c	(working copy)
*************** const char * const ld_plugin_symbol_reso
*** 110,116 ****
    "preempted_ir",
    "resolved_ir",
    "resolved_exec",
!   "resolved_dyn"
  };
  
  static void cgraph_node_remove_callers (struct cgraph_node *node);
--- 110,117 ----
    "preempted_ir",
    "resolved_ir",
    "resolved_exec",
!   "resolved_dyn",
!   "prevailing_def_ironly_exp"
  };
  
  static void cgraph_node_remove_callers (struct cgraph_node *node);
*************** resolution_used_from_other_file_p (enum
*** 2975,2980 ****
--- 2976,2982 ----
    return (resolution == LDPR_PREVAILING_DEF
            || resolution == LDPR_PREEMPTED_REG
            || resolution == LDPR_RESOLVED_EXEC
+           || resolution == LDPR_UNDEF
            || resolution == LDPR_RESOLVED_DYN);
  }
  
Index: gcc/lto-cgraph.c
===================================================================
*** gcc/lto-cgraph.c	(revision 179274)
--- gcc/lto-cgraph.c	(working copy)
*************** static void output_cgraph_opt_summary (c
*** 52,58 ****
  static void input_cgraph_opt_summary (VEC (cgraph_node_ptr, heap) * nodes);
  
  /* Number of LDPR values known to GCC.  */
! #define LDPR_NUM_KNOWN (LDPR_RESOLVED_DYN + 1)
  
  /* Cgraph streaming is organized as set of record whose type
     is indicated by a tag.  */
--- 52,58 ----
  static void input_cgraph_opt_summary (VEC (cgraph_node_ptr, heap) * nodes);
  
  /* Number of LDPR values known to GCC.  */
! #define LDPR_NUM_KNOWN (LDPR_PREVAILING_DEF_IRONLY_EXP + 1)
  
  /* Cgraph streaming is organized as set of record whose type
     is indicated by a tag.  */
Index: gcc/lto-streamer-out.c
===================================================================
*** gcc/lto-streamer-out.c	(revision 179274)
--- gcc/lto-streamer-out.c	(working copy)
*************** produce_symtab (struct output_block *ob,
*** 1340,1346 ****
        node = lto_cgraph_encoder_deref (encoder, i);
        if (DECL_EXTERNAL (node->decl))
  	continue;
!       if (DECL_COMDAT (node->decl)
  	  && cgraph_comdat_can_be_unshared_p (node))
  	continue;
        if ((node->alias && !node->thunk.alias) || node->global.inlined_to)
--- 1340,1346 ----
        node = lto_cgraph_encoder_deref (encoder, i);
        if (DECL_EXTERNAL (node->decl))
  	continue;
!       if (DECL_COMDAT (node->decl) && 0
  	  && cgraph_comdat_can_be_unshared_p (node))
  	continue;
        if ((node->alias && !node->thunk.alias) || node->global.inlined_to)
*************** produce_symtab (struct output_block *ob,
*** 1352,1358 ****
        node = lto_cgraph_encoder_deref (encoder, i);
        if (!DECL_EXTERNAL (node->decl))
  	continue;
!       if (DECL_COMDAT (node->decl)
  	  && cgraph_comdat_can_be_unshared_p (node))
  	continue;
        if ((node->alias && !node->thunk.alias) || node->global.inlined_to)
--- 1352,1358 ----
        node = lto_cgraph_encoder_deref (encoder, i);
        if (!DECL_EXTERNAL (node->decl))
  	continue;
!       if (DECL_COMDAT (node->decl) && 0
  	  && cgraph_comdat_can_be_unshared_p (node))
  	continue;
        if ((node->alias && !node->thunk.alias) || node->global.inlined_to)
*************** produce_symtab (struct output_block *ob,
*** 1369,1375 ****
        /* COMDAT virtual tables can be unshared.  Do not declare them
  	 in the LTO symbol table to prevent linker from forcing them
  	 into the output. */
!       if (DECL_COMDAT (vnode->decl)
  	  && !vnode->force_output
  	  && vnode->finalized 
  	  && DECL_VIRTUAL_P (vnode->decl))
--- 1369,1375 ----
        /* COMDAT virtual tables can be unshared.  Do not declare them
  	 in the LTO symbol table to prevent linker from forcing them
  	 into the output. */
!       if (DECL_COMDAT (vnode->decl) && 0
  	  && !vnode->force_output
  	  && vnode->finalized 
  	  && DECL_VIRTUAL_P (vnode->decl))
*************** produce_symtab (struct output_block *ob,
*** 1383,1389 ****
        vnode = lto_varpool_encoder_deref (varpool_encoder, i);
        if (!DECL_EXTERNAL (vnode->decl))
  	continue;
!       if (DECL_COMDAT (vnode->decl)
  	  && !vnode->force_output
  	  && vnode->finalized 
  	  && DECL_VIRTUAL_P (vnode->decl))
--- 1383,1389 ----
        vnode = lto_varpool_encoder_deref (varpool_encoder, i);
        if (!DECL_EXTERNAL (vnode->decl))
  	continue;
!       if (DECL_COMDAT (vnode->decl) && 0
  	  && !vnode->force_output
  	  && vnode->finalized 
  	  && DECL_VIRTUAL_P (vnode->decl))
Index: gcc/ipa.c
===================================================================
*** gcc/ipa.c	(revision 179274)
--- gcc/ipa.c	(working copy)
*************** cgraph_externally_visible_p (struct cgra
*** 628,634 ****
       This improves code quality and we know we will duplicate them at most twice
       (in the case that we are not using plugin and link with object file
        implementing same COMDAT)  */
!   if ((in_lto_p || whole_program)
        && DECL_COMDAT (node->decl)
        && cgraph_comdat_can_be_unshared_p (node))
      return false;
--- 631,638 ----
       This improves code quality and we know we will duplicate them at most twice
       (in the case that we are not using plugin and link with object file
        implementing same COMDAT)  */
!   if ((in_lto_p || whole_program
!        || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
        && DECL_COMDAT (node->decl)
        && cgraph_comdat_can_be_unshared_p (node))
      return false;
*************** varpool_externally_visible_p (struct var
*** 691,697 ****
       so this does not enable more optimization, but referring static var
       is faster for dynamic linking.  Also this match logic hidding vtables
       from LTO symbol tables.  */
!   if ((in_lto_p || flag_whole_program)
        && !vnode->force_output
        && DECL_COMDAT (vnode->decl) && DECL_VIRTUAL_P (vnode->decl))
      return false;
--- 695,702 ----
       so this does not enable more optimization, but referring static var
       is faster for dynamic linking.  Also this match logic hidding vtables
       from LTO symbol tables.  */
!   if ((in_lto_p || flag_whole_program
!        || vnode->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
        && !vnode->force_output
        && DECL_COMDAT (vnode->decl) && DECL_VIRTUAL_P (vnode->decl))
      return false;
Index: gcc/lto/common.c
===================================================================
*** gcc/lto/common.c	(revision 179274)
--- gcc/lto/common.c	(working copy)
*************** const char *lto_visibility_str[4] __attr
*** 31,37 ****
   "INTERNAL", "HIDDEN"
  };
  
! const char *lto_resolution_str[9] __attribute__ ((visibility ("hidden"))) =
  {
    "UNKNOWN",
    "UNDEF",
--- 31,37 ----
   "INTERNAL", "HIDDEN"
  };
  
! const char *lto_resolution_str[10] __attribute__ ((visibility ("hidden"))) =
  {
    "UNKNOWN",
    "UNDEF",
*************** const char *lto_resolution_str[9] __attr
*** 41,46 ****
    "PREEMPTED_IR",
    "RESOLVED_IR",
    "RESOLVED_EXEC",
!   "RESOLVED_DYN"
  };
  
--- 41,47 ----
    "PREEMPTED_IR",
    "RESOLVED_IR",
    "RESOLVED_EXEC",
!   "RESOLVED_DYN",
!   "PREVAILING_DEF_IRONLY_EXP",
  };
  
Index: gcc/lto/common.h
===================================================================
*** gcc/lto/common.h	(revision 179274)
--- gcc/lto/common.h	(working copy)
*************** along with GCC; see the file COPYING3.
*** 20,26 ****
  
  
  
! static const char *lto_resolution_str[9] =
  {
    "UNKNOWN",
    "UNDEF",
--- 20,26 ----
  
  
  
! static const char *lto_resolution_str[10] =
  {
    "UNKNOWN",
    "UNDEF",
*************** static const char *lto_resolution_str[9]
*** 30,34 ****
    "PREEMPTED_IR",
    "RESOLVED_IR",
    "RESOLVED_EXEC",
!   "RESOLVED_DYN"
  };
--- 30,35 ----
    "PREEMPTED_IR",
    "RESOLVED_IR",
    "RESOLVED_EXEC",
!   "RESOLVED_DYN",
!   "PREVAILING_DEF_IRONLY_EXP",
  };
Index: gcc/varasm.c
===================================================================
*** gcc/varasm.c	(revision 179274)
--- gcc/varasm.c	(working copy)
*************** static bool
*** 6681,6686 ****
--- 6681,6687 ----
  resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution)
  {
    return (resolution == LDPR_PREVAILING_DEF
+ 	  || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
  	  || resolution == LDPR_PREVAILING_DEF_IRONLY);
  }
  
*************** resolution_local_p (enum ld_plugin_symbo
*** 6692,6697 ****
--- 6693,6699 ----
  {
    return (resolution == LDPR_PREVAILING_DEF
  	  || resolution == LDPR_PREVAILING_DEF_IRONLY
+ 	  || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
  	  || resolution == LDPR_PREEMPTED_REG
  	  || resolution == LDPR_PREEMPTED_IR
  	  || resolution == LDPR_RESOLVED_IR


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]