This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
linker tidy
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Thu, 3 Nov 2005 13:22:19 +1030
- Subject: linker tidy
Miscellaneous fixes for things I noticed when looking at bfd_link_order
and related linker structures.
- incorrect/vague comments
- misleading struct field names
- an unused field in lang_output_section_statement_type
- unnecessary work when sizing .tbss
include/
* bfdlink.h (struct bfd_link_order): Tweak comment.
bfd/
* elf.c (elf_fake_sections): When calculating tbss size, just use
the last link_order.
(assign_file_positions_for_segments): Likewise.
* elflink.c (bfd_elf_final_link): Likewise.
(elf_reloc_link_order): Correct comment.
ld/
* ldlang.h (lang_output_section_statement_type): Rearrange. Remove
memspec. Make "processed" a bitfield.
(lang_data_statement_type, lang_reloc_statement_type): Rename
output_vma to output_offset.
* ldlang.c (lang_output_section_statement_lookup_1): Init
all_input_readonly. Don't init memspec.
(init_os): Remove incorrect comment.
(print_data_statement, print_reloc_statement): Adjust for
lang_data_statement_type and lang_reloc_statement_type change.
(lang_size_sections_1, lang_add_reloc): Likewise.
* ldwrite.c (build_link_order): Likewise.
Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.57
diff -u -p -r1.57 bfdlink.h
--- include/bfdlink.h 18 Aug 2005 03:49:39 -0000 1.57
+++ include/bfdlink.h 3 Nov 2005 01:08:50 -0000
@@ -554,7 +554,7 @@ enum bfd_link_order_type
};
/* This is the link_order structure itself. These form a chain
- attached to the section whose contents they are describing. */
+ attached to the output section whose contents they are describing. */
struct bfd_link_order
{
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.317
diff -u -p -r1.317 elf.c
--- bfd/elf.c 25 Oct 2005 16:19:06 -0000 1.317
+++ bfd/elf.c 3 Nov 2005 01:08:34 -0000
@@ -2764,16 +2764,18 @@ elf_fake_sections (bfd *abfd, asection *
if ((asect->flags & SEC_THREAD_LOCAL) != 0)
{
this_hdr->sh_flags |= SHF_TLS;
- if (asect->size == 0 && (asect->flags & SEC_HAS_CONTENTS) == 0)
+ if (asect->size == 0
+ && (asect->flags & SEC_HAS_CONTENTS) == 0)
{
- struct bfd_link_order *o;
+ struct bfd_link_order *o = asect->map_tail.link_order;
this_hdr->sh_size = 0;
- for (o = asect->map_head.link_order; o != NULL; o = o->next)
- if (this_hdr->sh_size < o->offset + o->size)
+ if (o != NULL)
+ {
this_hdr->sh_size = o->offset + o->size;
- if (this_hdr->sh_size)
- this_hdr->sh_type = SHT_NOBITS;
+ if (this_hdr->sh_size != 0)
+ this_hdr->sh_type = SHT_NOBITS;
+ }
}
}
@@ -4396,14 +4398,9 @@ assign_file_positions_for_segments (bfd
&& sec->size == 0
&& (sec->flags & SEC_HAS_CONTENTS) == 0)
{
- struct bfd_link_order *o;
- bfd_vma tbss_size = 0;
-
- for (o = sec->map_head.link_order; o != NULL; o = o->next)
- if (tbss_size < o->offset + o->size)
- tbss_size = o->offset + o->size;
-
- p->p_memsz += tbss_size;
+ struct bfd_link_order *o = sec->map_tail.link_order;
+ if (o != NULL)
+ p->p_memsz += o->offset + o->size;
}
if (align > p->p_align
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.196
diff -u -p -r1.196 elflink.c
--- bfd/elflink.c 25 Oct 2005 16:19:07 -0000 1.196
+++ bfd/elflink.c 3 Nov 2005 01:08:40 -0000
@@ -7394,7 +7394,7 @@ elf_link_input_bfd (struct elf_final_lin
}
/* Generate a reloc when linking an ELF file. This is a reloc
- requested by the linker, and does come from any input file. This
+ requested by the linker, and does not come from any input file. This
is used to build constructor and destructor tables when linking
with -Ur. */
@@ -8129,15 +8129,14 @@ bfd_elf_final_link (bfd *abfd, struct bf
sec && (sec->flags & SEC_THREAD_LOCAL);
sec = sec->next)
{
- bfd_vma size = sec->size;
+ bfd_size_type size = sec->size;
- if (size == 0 && (sec->flags & SEC_HAS_CONTENTS) == 0)
+ if (size == 0
+ && (sec->flags & SEC_HAS_CONTENTS) == 0)
{
- struct bfd_link_order *o;
-
- for (o = sec->map_head.link_order; o != NULL; o = o->next)
- if (size < o->offset + o->size)
- size = o->offset + o->size;
+ struct bfd_link_order *o = sec->map_tail.link_order;
+ if (o != NULL)
+ size = o->offset + o->size;
}
end = sec->vma + size;
}
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.202
diff -u -p -r1.202 ldlang.c
--- ld/ldlang.c 24 Oct 2005 01:40:58 -0000 1.202
+++ ld/ldlang.c 3 Nov 2005 01:08:54 -0000
@@ -1087,12 +1087,12 @@ lang_output_section_statement_lookup_1 (
lookup->bfd_section = NULL;
lookup->processed = FALSE;
lookup->constraint = constraint;
+ lookup->all_input_readonly = FALSE;
lookup->ignored = FALSE;
lookup->sectype = normal_section;
lookup->addr_tree = NULL;
lang_list_init (&lookup->children);
- lookup->memspec = NULL;
lookup->flags = 0;
lookup->subsection_alignment = -1;
lookup->section_alignment = -1;
@@ -1691,9 +1691,6 @@ init_os (lang_output_section_statement_t
output_bfd->xvec->name, s->name);
}
s->bfd_section->output_section = s->bfd_section;
-
- /* We initialize an output sections output offset to minus its own
- vma to allow us to output a section through itself. */
s->bfd_section->output_offset = 0;
if (!command_line.reduce_memory_overheads)
{
@@ -3545,7 +3542,7 @@ print_data_statement (lang_data_statemen
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
print_space ();
- addr = data->output_vma;
+ addr = data->output_offset;
if (data->output_section != NULL)
addr += data->output_section->vma;
@@ -3612,7 +3609,7 @@ print_reloc_statement (lang_reloc_statem
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
print_space ();
- addr = reloc->output_vma;
+ addr = reloc->output_offset;
if (reloc->output_section != NULL)
addr += reloc->output_section->vma;
@@ -4292,7 +4289,7 @@ lang_size_sections_1
{
unsigned int size = 0;
- s->data_statement.output_vma =
+ s->data_statement.output_offset =
dot - output_section_statement->bfd_section->vma;
s->data_statement.output_section =
output_section_statement->bfd_section;
@@ -4330,7 +4327,7 @@ lang_size_sections_1
{
int size;
- s->reloc_statement.output_vma =
+ s->reloc_statement.output_offset =
dot - output_section_statement->bfd_section->vma;
s->reloc_statement.output_section =
output_section_statement->bfd_section;
@@ -5680,7 +5677,7 @@ lang_add_reloc (bfd_reloc_code_real_type
p->addend_value = 0;
p->output_section = NULL;
- p->output_vma = 0;
+ p->output_offset = 0;
}
lang_assignment_statement_type *
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.54
diff -u -p -r1.54 ldlang.h
--- ld/ldlang.h 13 Oct 2005 17:29:57 -0000 1.54
+++ ld/ldlang.h 3 Nov 2005 01:08:54 -0000
@@ -128,28 +128,14 @@ typedef struct lang_output_section_phdr_
typedef struct lang_output_section_statement_struct
{
lang_statement_header_type header;
- union etree_union *addr_tree;
lang_statement_list_type children;
- const char *memspec;
struct lang_output_section_statement_struct *next;
const char *name;
-
- bfd_boolean processed;
-
asection *bfd_section;
- flagword flags; /* Or together of all input sections. */
- enum section_type sectype;
lang_memory_region_type *region;
lang_memory_region_type *lma_region;
- size_t block_value;
fill_type *fill;
-
- int subsection_alignment; /* Alignment of components. */
- int section_alignment; /* Alignment of start of section. */
- int constraint;
- unsigned int all_input_readonly : 1;
- unsigned int ignored : 1;
-
+ union etree_union *addr_tree;
union etree_union *load_base;
/* If non-null, an expression to evaluate after setting the section's
@@ -159,6 +145,16 @@ typedef struct lang_output_section_state
union etree_union *update_dot_tree;
lang_output_section_phdr_list *phdrs;
+
+ unsigned int block_value;
+ int subsection_alignment; /* Alignment of components. */
+ int section_alignment; /* Alignment of start of section. */
+ int constraint;
+ flagword flags;
+ enum section_type sectype;
+ unsigned int processed : 1;
+ unsigned int all_input_readonly : 1;
+ unsigned int ignored : 1;
} lang_output_section_statement_type;
typedef struct
@@ -186,7 +182,7 @@ typedef struct
union etree_union *exp;
bfd_vma value;
asection *output_section;
- bfd_vma output_vma;
+ bfd_vma output_offset;
} lang_data_statement_type;
/* Generate a reloc in the output file. */
@@ -218,8 +214,8 @@ typedef struct
/* Output section where reloc should be performed. */
asection *output_section;
- /* VMA within output section. */
- bfd_vma output_vma;
+ /* Offset within output section. */
+ bfd_vma output_offset;
} lang_reloc_statement_type;
typedef struct lang_input_statement_struct
--
Alan Modra
IBM OzLabs - Linux Technology Centre