This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
another tweak to ld padding
- To: binutils at sourceware dot cygnus dot com
- Subject: another tweak to ld padding
- From: Alan Modra <amodra at bigpond dot net dot au>
- Date: Mon, 20 Aug 2001 10:49:56 +0930
As per rth's suggestion, use offsetof in insert_pad. In this patch,
there's also a small change to the handling of padding statements in
lang_size_sections. Since padding statements are only ever created
inside lang_size_sections, and we don't want to act upon any stale
pad from previous iterations of lang_size_sections, we can simply
nullify any pad we see regardless of the "relax" param. This allows
us to prune some code in hppaelf.em.
ld/ChangeLog
* ldlang.c (insert_pad): Use offsetof macro.
(lang_size_sections): Always neuter padding statements.
* emultempl/hppaelf.em (hppaelf_delete_padding_statements): Delete.
--
Alan Modra
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.58
diff -u -p -r1.58 ldlang.c
--- ldlang.c 2001/08/18 14:54:26 1.58
+++ ldlang.c 2001/08/20 00:45:52
@@ -2635,15 +2635,11 @@ insert_pad (ptr, fill, alignment_needed,
bfd_vma dot;
{
lang_statement_union_type *pad;
- size_t ptr_off;
- /* ptr_off is zero, but let's not be too fast and loose with
- pointers. */
- ptr_off = ((char *) &((lang_statement_union_type *) 0)->header.next
- - (char *) 0);
+ pad = ((lang_statement_union_type *)
+ ((char *) ptr - offsetof (lang_statement_union_type *, header.next)));
if (ptr != &statement_list.head
- && ((pad = (lang_statement_union_type *) ((char *) ptr - ptr_off))
- ->header.type == lang_padding_statement_enum)
+ && pad->header.type == lang_padding_statement_enum)
&& pad->padding_statement.output_section == output_section)
{
/* Use the existing pad statement. The above test on output
@@ -3163,18 +3159,12 @@ lang_size_sections (s, output_section_st
break;
case lang_padding_statement_enum:
- if (relax)
- {
- /* If we are relaxing, and this is not the first pass,
- we need to allow padding to shrink. If padding is
- needed on this pass, it will be added back in. */
- s->padding_statement.size = 0;
- break;
- }
-
- dot += s->padding_statement.size / opb;
- output_section_statement->bfd_section->_raw_size +=
- s->padding_statement.size;
+ /* If this is the first time lang_size_sections is called,
+ we won't have any padding statements. If this is the
+ second or later passes when relaxing, we should allow
+ padding to shrink. If padding is needed on this pass, it
+ will be added back in. */
+ s->padding_statement.size = 0;
break;
case lang_group_statement_enum:
@@ -3187,9 +3177,8 @@ lang_size_sections (s, output_section_st
default:
FAIL ();
break;
-
- /* This can only get here when relaxing is turned on. */
+ /* We can only get here when relaxing is turned on. */
case lang_address_statement_enum:
break;
}
Index: ld/emultempl/hppaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/hppaelf.em,v
retrieving revision 1.13
diff -u -p -r1.13 hppaelf.em
--- hppaelf.em 2001/08/14 02:01:31 1.13
+++ hppaelf.em 2001/08/20 00:45:52
@@ -29,8 +29,6 @@ cat >>e${EMULATION_NAME}.c <<EOF
static void hppaelf_after_parse PARAMS((void));
static void hppaelf_create_output_section_statements PARAMS ((void));
-static void hppaelf_delete_padding_statements
- PARAMS ((lang_statement_list_type *));
static asection *hppaelf_add_stub_section
PARAMS ((const char *, asection *));
static void hppaelf_layaout_sections_again PARAMS ((void));
@@ -88,64 +86,7 @@ hppaelf_create_output_section_statements
ldlang_add_file (stub_file);
}
-/* Walk all the lang statements splicing out any padding statements from
- the list. */
-static void
-hppaelf_delete_padding_statements (list)
- lang_statement_list_type *list;
-{
- lang_statement_union_type *s;
- lang_statement_union_type **ps;
- for (ps = &list->head; (s = *ps) != NULL; ps = &s->next)
- {
- switch (s->header.type)
- {
-
- /* We want to recursively walk these sections. */
- case lang_constructors_statement_enum:
- hppaelf_delete_padding_statements (&constructor_list);
- break;
-
- case lang_output_section_statement_enum:
- hppaelf_delete_padding_statements (&s->output_section_statement.children);
- break;
-
- case lang_group_statement_enum:
- hppaelf_delete_padding_statements (&s->group_statement.children);
- break;
-
- case lang_wild_statement_enum:
- hppaelf_delete_padding_statements (&s->wild_statement.children);
- break;
-
- /* Here's what we are really looking for. Splice these out of
- the list. */
- case lang_padding_statement_enum:
- *ps = s->next;
- if (*ps == NULL)
- list->tail = ps;
- break;
-
- /* We don't care about these cases. */
- case lang_data_statement_enum:
- case lang_object_symbols_statement_enum:
- case lang_output_statement_enum:
- case lang_target_statement_enum:
- case lang_input_section_enum:
- case lang_input_statement_enum:
- case lang_assignment_statement_enum:
- case lang_address_statement_enum:
- break;
-
- default:
- abort ();
- break;
- }
- }
-}
-
-
struct hook_stub_info
{
lang_statement_list_type add;
@@ -280,9 +221,6 @@ hppaelf_layaout_sections_again ()
/* If we have changed sizes of the stub sections, then we need
to recalculate all the section offsets. This may mean we need to
add even more stubs. */
-
- /* Delete all the padding statements, they're no longer valid. */
- hppaelf_delete_padding_statements (stat_ptr);
/* Resize the sections. */
lang_size_sections (stat_ptr->head, abs_output_section,