From 4bd5a3935bde2bfc8b1b569e915a35da3e4daa94 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 4 Jul 2002 14:41:01 +0000 Subject: [PATCH] * ldlang.c: (strip_excluded_output_sections): New function. (lang_process): Call it. (lang_size_sections_1): Revert 2002-06-10 change. --- ld/ChangeLog | 6 ++++++ ld/ldlang.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 44765dba101..a3371710c0e 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2002-07-04 Alan Modra + + * ldlang.c: (strip_excluded_output_sections): New function. + (lang_process): Call it. + (lang_size_sections_1): Revert 2002-06-10 change. + 2002-07-03 Alan Modra * Makefile.am (check-DEJAGNU): Revert 2002-06-25 change. diff --git a/ld/ldlang.c b/ld/ldlang.c index f621e00dd32..e775c088532 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -97,6 +97,7 @@ static void lang_place_undefineds PARAMS ((void)); static void map_input_to_output_sections PARAMS ((lang_statement_union_type *, const char *, lang_output_section_statement_type *)); +static void strip_excluded_output_sections PARAMS ((void)); static void print_output_section_statement PARAMS ((lang_output_section_statement_type *)); static void print_assignment @@ -2161,6 +2162,41 @@ map_input_to_output_sections (s, target, output_section_statement) } } +/* An output section might have been removed after its statement was + added. For example, ldemul_before_allocation can remove dynamic + sections if they turn out to be not needed. Clean them up here. */ + +static void +strip_excluded_output_sections () +{ + lang_statement_union_type *u; + + for (u = lang_output_section_statement.head; + u != NULL; + u = u->output_section_statement.next) + { + lang_output_section_statement_type *os; + asection *s; + + os = &u->output_section_statement; + s = os->bfd_section; + if (s != NULL && (s->flags & SEC_EXCLUDE) != 0) + { + asection **p; + + os->bfd_section = NULL; + + for (p = &output_bfd->sections; *p; p = &(*p)->next) + if (*p == s) + { + bfd_section_list_remove (output_bfd, p); + output_bfd->section_count--; + break; + } + } + } +} + static void print_output_section_statement (output_section_statement) lang_output_section_statement_type *output_section_statement; @@ -2903,14 +2939,6 @@ lang_size_sections_1 (s, output_section_statement, prev, fill, dot, relax) /* This section was never actually created. */ break; - /* The section might have been removed after its statement was - added. For example, ldemul_before_allocation can remove - dynamic sections if they turn out not to be needed. */ - if (!link_info.relocateable - && (bfd_get_section_flags (output_bfd, os->bfd_section) - & SEC_EXCLUDE) != 0) - break; - /* If this is a COFF shared library section, use the size and address from the input section. FIXME: This is COFF specific; it would be cleaner if there were some other way @@ -4252,6 +4280,9 @@ lang_process () and other back-ends size dynamic sections. */ ldemul_before_allocation (); + if (!link_info.relocateable) + strip_excluded_output_sections (); + /* We must record the program headers before we try to fix the section positions, since they will affect SIZEOF_HEADERS. */ lang_record_phdrs (); -- 2.30.2