This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
More ld SEC_EXCLUDE tweaks
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Fri, 28 May 2004 15:11:59 +0930
- Subject: More ld SEC_EXCLUDE tweaks
This further cleans up the SEC_EXCLUDE handling. It's better to adjust
flags in one place, and the lang_gc_sections script traversal happens at
the right time. Also, doing things this way means the emul place_orphan
functions don't need to worry about SEC_EXCLUDE.
* ldlang.c (lang_add_section): Don't twidlle SEC_EXCLUDE here.
(output_section_callback): Nor SEC_KEEP here.
(gc_section_callback): Twiddle SEC_EXCLUDE here.
(lang_gc_wild): Delete. Fold into..
(lang_gc_sections_1): ..here. Only call bfd_gc_sections when garbage
collecting.
(lang_process): Always call lang_gc_sections.
(lang_place_orphans): Handle SEC_EXCLUDE sections.
* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Remove
SEC_EXCLUDE code.
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.150
diff -u -p -r1.150 ldlang.c
--- ld/ldlang.c 27 May 2004 05:53:36 -0000 1.150
+++ ld/ldlang.c 28 May 2004 05:37:00 -0000
@@ -1089,23 +1089,9 @@ lang_add_section (lang_statement_list_ty
lang_output_section_statement_type *output,
lang_input_statement_type *file)
{
- flagword flags;
+ flagword flags = section->flags;
bfd_boolean discard;
- flags = bfd_get_section_flags (section->owner, section);
-
- /* SEC_EXCLUDE is ignored when doing a relocatable link, except in
- the special case of debug info. (See bfd/stabs.c) */
- if (link_info.relocatable && (flags & SEC_DEBUGGING) == 0)
- {
- flags &= ~SEC_EXCLUDE;
-
- /* Write the modified flag back, to simplify later linker
- code. */
- if (section->owner != NULL)
- bfd_set_section_flags (section->owner, section, flags);
- }
-
/* Discard sections marked with SEC_EXCLUDE. */
discard = (flags & SEC_EXCLUDE) != 0;
@@ -1349,11 +1335,6 @@ output_section_callback (lang_wild_state
if (unique_section_p (section))
return;
- /* If the wild pattern was marked KEEP, the member sections
- should be as well. */
- if (ptr->keep_sections)
- section->flags |= SEC_KEEP;
-
before = wild_sort (ptr, sec, file, section);
/* Here BEFORE points to the lang_input_section which
@@ -4029,9 +4010,10 @@ lang_place_orphans (void)
around for a sensible place for it to go. */
if (file->just_syms_flag)
- {
- abort ();
- }
+ abort ();
+
+ if ((s->flags & SEC_EXCLUDE) != 0)
+ s->output_section = bfd_abs_section_ptr;
else if (strcmp (s->name, "COMMON") == 0)
{
/* This is a lonely common section which must have
@@ -4271,8 +4253,7 @@ lang_reset_memory_regions (void)
o->_raw_size = 0;
}
-/* If the wild pattern was marked KEEP, the member sections
- should be as well. */
+/* Worker for lang_gc_sections_1. */
static void
gc_section_callback (lang_wild_statement_type *ptr,
@@ -4281,18 +4262,18 @@ gc_section_callback (lang_wild_statement
lang_input_statement_type *file ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED)
{
+ /* SEC_EXCLUDE is ignored when doing a relocatable link, except in
+ the special case of debug info. (See bfd/stabs.c)
+ Twiddle the flag here, to simplify later linker code. */
+ if (link_info.relocatable && (section->flags & SEC_DEBUGGING) == 0)
+ section->flags &= ~SEC_EXCLUDE;
+
+ /* If the wild pattern was marked KEEP, the member sections
+ should be as well. */
if (ptr->keep_sections)
section->flags |= SEC_KEEP;
}
-/* Handle a wild statement, marking it against GC. */
-
-static void
-lang_gc_wild (lang_wild_statement_type *s)
-{
- walk_wild (s, gc_section_callback, NULL);
-}
-
/* Iterate over sections marking them against GC. */
static void
@@ -4303,7 +4284,7 @@ lang_gc_sections_1 (lang_statement_union
switch (s->header.type)
{
case lang_wild_statement_enum:
- lang_gc_wild (&s->wild_statement);
+ walk_wild (&s->wild_statement, gc_section_callback, NULL);
break;
case lang_constructors_statement_enum:
lang_gc_sections_1 (constructor_list.head);
@@ -4347,7 +4328,8 @@ lang_gc_sections (void)
}
}
- bfd_gc_sections (output_bfd, &link_info);
+ if (command_line.gc_sections)
+ bfd_gc_sections (output_bfd, &link_info);
}
void
@@ -4395,8 +4377,7 @@ lang_process (void)
ldctor_build_sets ();
/* Remove unreferenced sections if asked to. */
- if (command_line.gc_sections)
- lang_gc_sections ();
+ lang_gc_sections ();
/* Size up the common data. */
lang_common ();
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.116
diff -u -p -r1.116 elf32.em
--- ld/emultempl/elf32.em 27 May 2004 05:53:36 -0000 1.116
+++ ld/emultempl/elf32.em 28 May 2004 05:37:01 -0000
@@ -1182,16 +1182,6 @@ gld${EMULATION_NAME}_place_orphan (lang_
#define HAVE_SECTION(hold, name) \
(hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL)
- if (link_info.relocatable && (s->flags & SEC_DEBUGGING) == 0)
- s->flags &= ~SEC_EXCLUDE;
-
- if ((s->flags & SEC_EXCLUDE) != 0)
- {
- if (s->output_section == NULL)
- s->output_section = bfd_abs_section_ptr;
- return TRUE;
- }
-
place = NULL;
if ((s->flags & SEC_ALLOC) == 0)
;
--
Alan Modra
IBM OzLabs - Linux Technology Centre