This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: RFC: Speeding up libstdc++.so with --dynamic-list-data
On Tue, Jan 09, 2007 at 02:01:53PM +0000, Andrew Haley wrote:
> H. J. Lu writes:
> > On Tue, Jan 09, 2007 at 01:51:00PM +0000, Andrew Haley wrote:
> > > H. J. Lu writes:
> > > > On Tue, Jan 09, 2007 at 01:38:00PM +0000, Andrew Haley wrote:
> > > > > H. J. Lu writes:
> > > > > > I am enclosing a patch to implement a new linker swicth,
> > > > > > --dynamic-list-data. It is -Bsymbolic for function symbols only.
> > > > > > I tried it with C, C++, Java and Fortran on Linux/ia32, Linux/x86-64
> > > > > > and Linux/ia64. There are only a few regressions. The function calls
> > > > > > within the new resulting DSOs will bind locally. It speeds up
> > > > > > the enclosed C++ testcase by
> > > > > >
> > > > > > 1. 23% on ia64.
> > > > > > 2. 6% on ia32.
> > > > > > 3. 3% on x86-64.
> > > > > >
> > > > > > Should we consider such optimization?
> > > > >
> > > > > That's a terrible name for the option. What does it mean?
> > > >
> > > > It is an extension of the current command line options:
> > > >
> > > > --dynamic-list-cpp-typeinfo Use C++ typeinfo dynamic list
> > > > --dynamic-list FILE Read dynamic list
> > >
> > > But you said it was like -Bsymbolic for function symbols only. What
> > > is the connection between C++ typeinfo and that? (Hint: Java doesn't
> > > use C++ typeinfo, but -Bsymbolic for function symbols only would be
> > > very useful.)
> >
> > --dynamic-list is a generic linker feature. Users have to provide a
> > list of symbols, which will be bound dynamically and everything else
> > is bound locally. --dynamic-list-cpp-typeinfo includes a prefined
> > list for C++ typeinfo. --dynamic-list-data puts data symbols on
> > the dynamic list.
>
> OK, so in the case of --dynamic-list-data, there is no user-supplied
> list. Instead, there's (conceptually) an automatically-generated
> list, which contains every symbol that doesn't point to a function.
> Can't you just call the new option -Bsymbolic-functions? At least
> then people like me might have an outside chance of remembering it.
Here is the updated patch to use -Bsymbolic-functions instead.
H.J.
---
bfd/
2007-01-05 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3831
* elf-bfd.h (bfd_elf_link_mark_dynamic_symbol): Add an
argument, Elf_Internal_Sym *.
* elflink.c (bfd_elf_link_mark_dynamic_symbol): Mark a data
symbol dynamic if info->symbolic_functions is TRUE.
(bfd_elf_record_link_assignment): Updated call to
bfd_elf_record_link_assignment.
(_bfd_elf_merge_symbol): Likewise. Always call
bfd_elf_link_mark_dynamic_symbol.
include/
2007-01-05 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3831
* bfdlink.h (bfd_link_info): Rename dynamic to dynamic_list.
Add dynamic and symbolic_functions.
ld/
2007-01-05 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3831
* ldlang.c (lang_process): Change link_info.dynamic to
link_info.dynamic_list.
(lang_append_dynamic_list): Likewise.
* ldmain.c (main): Likewise. Initialize link_info.dynamic and
link_info.symbolic_functions to FALSE.
* lexsup.c (option_values): Add OPTION_SYMBOLIC_FUNCTIONS.
(ld_options): Add -Bsymbolic-functions.
(parse_args): Change link_info.dynamic to link_info.dynamic_list.
Set link_info.symbolic_functions to TRUE for -Bsymbolic-functions.
Set link_info.dynamic to TRUE for --dynamic-list and
--dynamic-list-cpp-typeinfo.
--- binutils/bfd/elf-bfd.h.data 2007-01-09 05:49:14.000000000 -0800
+++ binutils/bfd/elf-bfd.h 2007-01-09 06:15:11.000000000 -0800
@@ -1858,7 +1858,8 @@ extern int bfd_elf_link_record_local_dyn
(struct bfd_link_info *, bfd *, long);
extern void bfd_elf_link_mark_dynamic_symbol
- (struct bfd_link_info *, struct elf_link_hash_entry *);
+ (struct bfd_link_info *, struct elf_link_hash_entry *,
+ Elf_Internal_Sym *);
extern bfd_boolean _bfd_elf_close_and_cleanup
(bfd *);
--- binutils/bfd/elflink.c.data 2007-01-09 05:49:14.000000000 -0800
+++ binutils/bfd/elflink.c 2007-01-09 06:15:11.000000000 -0800
@@ -454,14 +454,22 @@ bfd_elf_link_record_dynamic_symbol (stru
void
bfd_elf_link_mark_dynamic_symbol (struct bfd_link_info *info,
- struct elf_link_hash_entry *h)
+ struct elf_link_hash_entry *h,
+ Elf_Internal_Sym *sym)
{
- struct bfd_elf_dynamic_list *d = info->dynamic;
+ struct bfd_elf_dynamic_list *d = info->dynamic_list;
- if (d == NULL || info->relocatable)
+ /* It may be called more than once on the same H. */
+ if(h->dynamic || info->relocatable)
return;
- if ((*d->match) (&d->head, NULL, h->root.root.string))
+ if ((info->symbolic_functions
+ && (h->type == STT_OBJECT
+ || (sym != NULL
+ && ELF_ST_TYPE (sym->st_info) == STT_OBJECT)))
+ || (d != NULL
+ && h->root.type == bfd_link_hash_new
+ && (*d->match) (&d->head, NULL, h->root.root.string)))
h->dynamic = 1;
}
@@ -499,7 +507,7 @@ bfd_elf_record_link_assignment (bfd *out
if (h->root.type == bfd_link_hash_new)
{
- bfd_elf_link_mark_dynamic_symbol (info, h);
+ bfd_elf_link_mark_dynamic_symbol (info, h, NULL);
h->non_elf = 0;
}
@@ -906,13 +914,17 @@ _bfd_elf_merge_symbol (bfd *abfd,
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ /* We have to check it for every instance since the first few may be
+ refereences and not all compilers emit symbol type for undefined
+ symbols. */
+ bfd_elf_link_mark_dynamic_symbol (info, h, sym);
+
/* If we just created the symbol, mark it as being an ELF symbol.
Other than that, there is nothing to do--there is no merge issue
with a newly defined symbol--so we just return. */
if (h->root.type == bfd_link_hash_new)
{
- bfd_elf_link_mark_dynamic_symbol (info, h);
h->non_elf = 0;
return TRUE;
}
--- binutils/include/bfdlink.h.data 2006-10-30 15:29:39.000000000 -0800
+++ binutils/include/bfdlink.h 2007-01-09 06:15:37.000000000 -0800
@@ -246,6 +246,9 @@ struct bfd_link_info
/* TRUE if BFD should pre-bind symbols in a shared object. */
unsigned int symbolic: 1;
+ /* TRUE if BFD should pre-bind function symbols in a shared object. */
+ unsigned int symbolic_functions: 1;
+
/* TRUE if BFD should export all symbols in the dynamic symbol table
of an executable, rather than only those used. */
unsigned int export_dynamic: 1;
@@ -340,6 +343,10 @@ struct bfd_link_info
caching ELF symbol buffer. */
unsigned int reduce_memory_overheads: 1;
+ /* TRUE if some symbols have to be dynamic, controlled by
+ --dynamic-list command line options. */
+ unsigned int dynamic: 1;
+
/* What to do with unresolved symbols in an object file.
When producing executables the default is GENERATE_ERROR.
When producing shared libraries the default is IGNORE. The
@@ -440,7 +447,7 @@ struct bfd_link_info
bfd_vma relro_start, relro_end;
/* List of symbols should be dynamic. */
- struct bfd_elf_dynamic_list *dynamic;
+ struct bfd_elf_dynamic_list *dynamic_list;
};
/* This structures holds a set of callback functions. These are
--- binutils/ld/ldlang.c.data 2007-01-09 05:49:14.000000000 -0800
+++ binutils/ld/ldlang.c 2007-01-09 06:15:11.000000000 -0800
@@ -5732,8 +5732,8 @@ void
lang_process (void)
{
/* Finalize dynamic list. */
- if (link_info.dynamic)
- lang_finalize_version_expr_head (&link_info.dynamic->head);
+ if (link_info.dynamic_list)
+ lang_finalize_version_expr_head (&link_info.dynamic_list->head);
current_target = default_target;
@@ -7047,13 +7047,13 @@ lang_add_unique (const char *name)
void
lang_append_dynamic_list (struct bfd_elf_version_expr *dynamic)
{
- if (link_info.dynamic)
+ if (link_info.dynamic_list)
{
struct bfd_elf_version_expr *tail;
for (tail = dynamic; tail->next != NULL; tail = tail->next)
;
- tail->next = link_info.dynamic->head.list;
- link_info.dynamic->head.list = dynamic;
+ tail->next = link_info.dynamic_list->head.list;
+ link_info.dynamic_list->head.list = dynamic;
}
else
{
@@ -7062,7 +7062,7 @@ lang_append_dynamic_list (struct bfd_elf
d = xcalloc (1, sizeof *d);
d->head.list = dynamic;
d->match = lang_vers_match;
- link_info.dynamic = d;
+ link_info.dynamic_list = d;
}
}
--- binutils/ld/ldmain.c.data 2006-10-30 15:29:40.000000000 -0800
+++ binutils/ld/ldmain.c 2007-01-09 06:15:11.000000000 -0800
@@ -318,7 +318,9 @@ main (int argc, char **argv)
link_info.warn_shared_textrel = FALSE;
link_info.gc_sections = FALSE;
link_info.print_gc_sections = FALSE;
- link_info.dynamic = NULL;
+ link_info.dynamic = FALSE;
+ link_info.dynamic_list = NULL;
+ link_info.symbolic_functions = FALSE;
link_info.reduce_memory_overheads = FALSE;
config.maxpagesize = 0;
--- binutils/ld/lexsup.c.data 2006-10-30 15:29:40.000000000 -0800
+++ binutils/ld/lexsup.c 2007-01-09 06:15:11.000000000 -0800
@@ -97,6 +97,7 @@ enum option_values
OPTION_SORT_SECTION,
OPTION_STATS,
OPTION_SYMBOLIC,
+ OPTION_SYMBOLIC_FUNCTIONS,
OPTION_TASK_LINK,
OPTION_TBSS,
OPTION_TDATA,
@@ -346,6 +347,8 @@ static const struct ld_option ld_options
'\0', NULL, NULL, ONE_DASH },
{ {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
'\0', NULL, N_("Bind global references locally"), ONE_DASH },
+ { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
+ '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
{ {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
'\0', NULL, N_("Check section addresses for overlaps (default)"),
TWO_DASHES },
@@ -1133,6 +1136,10 @@ parse_args (unsigned argc, char **argv)
case OPTION_SYMBOLIC:
link_info.symbolic = TRUE;
break;
+ case OPTION_SYMBOLIC_FUNCTIONS:
+ link_info.symbolic_functions = TRUE;
+ link_info.dynamic = TRUE;
+ break;
case 't':
trace_files = TRUE;
break;
@@ -1246,6 +1253,7 @@ parse_args (unsigned argc, char **argv)
break;
case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
lang_append_dynamic_list_cpp_typeinfo ();
+ link_info.dynamic = TRUE;
break;
case OPTION_DYNAMIC_LIST:
/* This option indicates a small script that only specifies
@@ -1260,6 +1268,7 @@ parse_args (unsigned argc, char **argv)
parser_input = input_dynamic_list;
yyparse ();
}
+ link_info.dynamic = TRUE;
break;
case OPTION_WARN_COMMON:
config.warn_common = TRUE;