From 4a43e768f18f325a0e52de37fe69d4a6a764d668 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 18 Mar 2004 12:50:20 +0000 Subject: bfd/ * elf-bfd.h (struct elf_obj_tdata): Delete dt_soname field. Add dyn_lib_class field. Rearrange for better packing. (elf_dt_soname): Delete. (elf_dyn_lib_class): Define. * elf.c (bfd_elf_set_dt_needed_name): Update comment. (bfd_elf_set_dt_needed_soname): Delete. (bfd_elf_set_dyn_lib_class): New function. * elflink.h (add_dt_needed_tag): New function. Split out from.. (elf_link_add_object_symbols): ..here. Rename "name" to "soname". Use elf_dyn_lib_class to set dt_needed and add_needed. Move fallback initialization of soname. (elf_link_check_versioned_symbol): Test elf_dyn_lib_class instead of elf_dt_soname. * bfd-in.h (enum dynamic_lib_link_class): New. (bfd_elf_set_dt_needed_soname): Delete. (bfd_elf_set_dyn_lib_class): Declare. * bfd-in2.h: Regenerate. ld/ * ld.texinfo: Add --as-needed doco. * ldmain.c (as_needed): New global var. * ldmain.h (as_needed): Declare. * lexsup.c (option_values): Add OPTION_AS_NEEDED and OPTION_NO_AS_NEEDED. (ld_options): Likewise. (parse_args): Handle them. * ldlang.h (lang_input_statement_type): Add as_needed field. * ldlang.c (new_afile): Set p->as_needed. * emultempl/elf32.em (gld${EMULATION_NAME}_load_symbols): New function. (gld${EMULATION_NAME}_try_needed): Use bfd_elf_set_dyn_lib_class. (ld_${EMULATION_NAME}_emulation): Set LDEMUL_RECOGNIZED_FILE entry. * ldlang.c (open_input_bfds): Remove useless cast. (lang_do_assignments_1): Likewise. (lang_for_each_input_section): Delete. --- ld/ChangeLog | 19 +++++++++++++++++++ ld/emultempl/elf32.em | 37 +++++++++++++++++++++++++++++-------- ld/ld.texinfo | 12 ++++++++++++ ld/ldlang.c | 24 +++--------------------- ld/ldlang.h | 4 ++++ ld/ldmain.c | 6 +++++- ld/ldmain.h | 3 ++- ld/lexsup.c | 14 +++++++++++++- 8 files changed, 87 insertions(+), 32 deletions(-) (limited to 'ld') diff --git a/ld/ChangeLog b/ld/ChangeLog index 0b3407f..3c4940c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,22 @@ +2004-03-18 Alan Modra + + * ld.texinfo: Add --as-needed doco. + * ldmain.c (as_needed): New global var. + * ldmain.h (as_needed): Declare. + * lexsup.c (option_values): Add OPTION_AS_NEEDED and + OPTION_NO_AS_NEEDED. + (ld_options): Likewise. + (parse_args): Handle them. + * ldlang.h (lang_input_statement_type): Add as_needed field. + * ldlang.c (new_afile): Set p->as_needed. + * emultempl/elf32.em (gld${EMULATION_NAME}_load_symbols): New function. + (gld${EMULATION_NAME}_try_needed): Use bfd_elf_set_dyn_lib_class. + (ld_${EMULATION_NAME}_emulation): Set LDEMUL_RECOGNIZED_FILE entry. + + * ldlang.c (open_input_bfds): Remove useless cast. + (lang_do_assignments_1): Likewise. + (lang_for_each_input_section): Delete. + 2004-03-17 Ralf Corsepius * configure.tgt: Switch sh-*-rtems* to ELF. Add sh-*-rtemscoff*. diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index 45749e7..e95b3a9 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -89,6 +89,28 @@ gld${EMULATION_NAME}_before_parse (void) EOF fi +if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then +cat >>e${EMULATION_NAME}.c <as_needed + || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0) + return FALSE; + + /* Tell the ELF linker that we don't want the output file to have a + DT_NEEDED entry for this file, unless it is used to resolve + references in a regular object. */ + bfd_elf_set_dyn_lib_class (entry->the_bfd, DYN_AS_NEEDED); + + /* Continue on with normal load_symbols processing. */ + return FALSE; +} +EOF +fi + cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <next = NULL; p->symbol_count = 0; p->dynamic = config.dynamic_link; + p->as_needed = as_needed; p->whole_archive = whole_archive; p->loaded = FALSE; lang_statement_append (&input_file_chain, @@ -1842,7 +1843,7 @@ open_input_bfds (lang_statement_union_type *s, bfd_boolean force) /* Maybe we should load the file's symbols. */ if (s->wild_statement.filename && ! wildcardp (s->wild_statement.filename)) - (void) lookup_name (s->wild_statement.filename); + lookup_name (s->wild_statement.filename); open_input_bfds (s->wild_statement.children.head, force); break; case lang_group_statement_enum: @@ -3348,8 +3349,7 @@ lang_do_assignments_1 if (os->bfd_section != NULL) { dot = os->bfd_section->vma; - (void) lang_do_assignments_1 (os->children.head, os, - os->fill, dot); + lang_do_assignments_1 (os->children.head, os, os->fill, dot); dot = (os->bfd_section->vma + TO_ADDR (os->bfd_section->_raw_size)); @@ -3938,24 +3938,6 @@ lang_for_each_file (void (*func) (lang_input_statement_type *)) } } -#if 0 - -/* Not used. */ - -void -lang_for_each_input_section (void (*func) (bfd *ab, asection *as)) -{ - LANG_FOR_EACH_INPUT_STATEMENT (f) - { - asection *s; - - for (s = f->the_bfd->sections; s != NULL; s = s->next) - func (f->the_bfd, s); - } -} - -#endif - void ldlang_add_file (lang_input_statement_type *entry) { diff --git a/ld/ldlang.h b/ld/ldlang.h index d518398..649fea1 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -264,6 +264,10 @@ typedef struct lang_input_statement_struct /* Whether to search for this entry as a dynamic archive. */ bfd_boolean dynamic; + /* Whether this entry should cause a DT_NEEDED tag only when + satisfying references from regular files, or always. */ + bfd_boolean as_needed; + /* Whether to include the entire contents of an archive. */ bfd_boolean whole_archive; diff --git a/ld/ldmain.c b/ld/ldmain.c index 88b5c75..d0e0b12 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -1,6 +1,6 @@ /* Main program of GNU linker. Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003 + 2002, 2003, 2004 Free Software Foundation, Inc. Written by Steve Chamberlain steve@cygnus.com @@ -93,6 +93,10 @@ bfd_boolean version_printed; /* Nonzero means link in every member of an archive. */ bfd_boolean whole_archive; +/* Nonzero means create DT_NEEDED entries only if a dynamic library + actually satisfies some reference in a regular object. */ +bfd_boolean as_needed; + /* TRUE if we should demangle symbol names. */ bfd_boolean demangling; diff --git a/ld/ldmain.h b/ld/ldmain.h index 10169dd..8cab5fe 100644 --- a/ld/ldmain.h +++ b/ld/ldmain.h @@ -1,5 +1,5 @@ /* ldmain.h - - Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2002, 2003 + Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GLD, the Gnu Linker. @@ -32,6 +32,7 @@ extern bfd_boolean trace_files; extern bfd_boolean trace_file_tries; extern bfd_boolean version_printed; extern bfd_boolean whole_archive; +extern bfd_boolean as_needed; extern bfd_boolean demangling; extern int g_switch_value; extern const char *output_filename; diff --git a/ld/lexsup.c b/ld/lexsup.c index e43e15e..d3b3d8d 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -1,6 +1,6 @@ /* Parse options for the GNU linker. Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003 + 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GLD, the Gnu Linker. @@ -112,6 +112,8 @@ enum option_values OPTION_SPLIT_BY_RELOC, OPTION_SPLIT_BY_FILE , OPTION_WHOLE_ARCHIVE, + OPTION_AS_NEEDED, + OPTION_NO_AS_NEEDED, OPTION_WRAP, OPTION_FORCE_EXE_SUFFIX, OPTION_GC_SECTIONS, @@ -438,6 +440,10 @@ static const struct ld_option ld_options[] = TWO_DASHES }, { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES }, + { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED}, + '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), TWO_DASHES }, + { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED}, + '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"), TWO_DASHES }, { {"wrap", required_argument, NULL, OPTION_WRAP}, '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES } }; @@ -1156,6 +1162,12 @@ parse_args (unsigned argc, char **argv) case OPTION_WHOLE_ARCHIVE: whole_archive = TRUE; break; + case OPTION_AS_NEEDED: + as_needed = TRUE; + break; + case OPTION_NO_AS_NEEDED: + as_needed = FALSE; + break; case OPTION_WRAP: add_wrap (optarg); break; -- cgit v1.1