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?
H.J.
bfd/
2007-01-05 H.J. Lu <[EMAIL PROTECTED]>
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->dynamic_data 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 <[EMAIL PROTECTED]>
PR ld/3831
* bfdlink.h (bfd_link_info): Rename dynamic to dynamic_list.
Add dynamic and dynamic_data.
ld/
2007-01-05 H.J. Lu <[EMAIL PROTECTED]>
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.dynamic_data to FALSE.
* lexsup.c (option_values): Add OPTION_DYNAMIC_LIST_DATA.
(ld_options): --dynamic-list-data.
(parse_args): Change link_info.dynamic to
link_info.dynamic_list. Set link_info.dynamic_data to TRUE for
--dynamic-list-data. Set link_info.dynamic to TRUE for
--dynamuc-list*.
--- binutils/bfd/elf-bfd.h.data 2007-01-08 10:05:49.000000000 -0800
+++ binutils/bfd/elf-bfd.h 2007-01-08 10:05:49.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-08 10:05:49.000000000 -0800
+++ binutils/bfd/elflink.c 2007-01-08 17:42:35.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->dynamic_data
+ && (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:25:51.000000000 -0800
+++ binutils/include/bfdlink.h 2007-01-08 10:05:49.000000000 -0800
@@ -340,6 +340,13 @@ struct bfd_link_info
caching ELF symbol buffer. */
unsigned int reduce_memory_overheads: 1;
+ /* TRUE if all data symbols should be dynamic. */
+ unsigned int dynamic_data: 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-08 10:05:49.000000000 -0800
+++ binutils/ld/ldlang.c 2007-01-08 10:05:49.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:25:51.000000000 -0800
+++ binutils/ld/ldmain.c 2007-01-08 10:05:49.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.dynamic_data = FALSE;
link_info.reduce_memory_overheads = FALSE;
config.maxpagesize = 0;
--- binutils/ld/lexsup.c.data 2006-10-30 15:25:51.000000000 -0800
+++ binutils/ld/lexsup.c 2007-01-08 10:05:49.000000000 -0800
@@ -109,6 +109,7 @@ enum option_values
OPTION_VERSION_EXPORTS_SECTION,
OPTION_DYNAMIC_LIST,
OPTION_DYNAMIC_LIST_CPP_TYPEINFO,
+ OPTION_DYNAMIC_LIST_DATA,
OPTION_WARN_COMMON,
OPTION_WARN_CONSTRUCTORS,
OPTION_WARN_FATAL,
@@ -507,6 +508,8 @@ static const struct ld_option ld_options
'\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
{ {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
'\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
+ { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
+ '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
{ {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
'\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
{ {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
@@ -1244,8 +1247,13 @@ parse_args (unsigned argc, char **argv)
.exports sections. */
command_line.version_exports_section = optarg;
break;
+ case OPTION_DYNAMIC_LIST_DATA:
+ link_info.dynamic_data = TRUE;
+ link_info.dynamic = TRUE;
+ 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;
#include <set>
#include <cstdio>
#include <cstdlib>
using namespace std;
int
main(int argc, char **argv)
{
int n = argc == 2 ? atoi(argv[1]) : 10000;
set<int> s;
for(int i = 0; i < n; i++)
s.insert(rand());
for(int i = 0; i < 10000; i++){
for(set<int>::iterator it = s.begin(); it != s.end(); ++it){
if(*it < 0) return 1;
}
}
// printf("set size: %d\n", (int)s.size());
}