aboutsummaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2002-07-04 14:41:01 +0000
committerAlan Modra <amodra@gmail.com>2002-07-04 14:41:01 +0000
commit4bd5a3935bde2bfc8b1b569e915a35da3e4daa94 (patch)
tree85714aa926364bc19e2e79e65db3e1bac53e84c7 /ld/ldlang.c
parentbc0ba53708a7da5955ae96f988165ffd15b8c3f5 (diff)
downloadgdb-4bd5a3935bde2bfc8b1b569e915a35da3e4daa94.zip
gdb-4bd5a3935bde2bfc8b1b569e915a35da3e4daa94.tar.gz
gdb-4bd5a3935bde2bfc8b1b569e915a35da3e4daa94.tar.bz2
* ldlang.c: (strip_excluded_output_sections): New function.
(lang_process): Call it. (lang_size_sections_1): Revert 2002-06-10 change.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index f621e00..e775c08 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 ();