RFC: Add bfd_get_section_ident
H. J. Lu
hjl@lucon.org
Sun May 30 08:08:00 GMT 2004
On Sat, May 29, 2004 at 03:14:47PM +0930, Alan Modra wrote:
> On Fri, May 28, 2004 at 05:59:12PM -0400, Ian Lance Taylor wrote:
> > Now, that said, do we really need two new fields in asection? That
> > can be pretty costly in the linker, with regard to memory space.
>
> I don't think so. Diagnostics can build these ident strings as needed.
>
Here is the updated patch.
H.J.
-------------- next part --------------
2004-05-28 H.J. Lu <hongjiu.lu@intel.com>
* elf-bfd.h (_bfd_elf_setup_group_pointers): New prototype.
* elf.c (_bfd_elf_setup_group_pointers): New function.
* elfcode.h (elf_object_p): Call _bfd_elf_setup_group_pointers.
* elflink.c (elf_link_read_relocs_from_section): Call
bfd_get_section_ident to identify the section when reporting
error.
(_bfd_elf_link_output_relocs): Likewise.
(elf_link_output_extsym): Likewise.
(elf_link_input_bfd): Likewise.
(bfd_elf_gc_record_vtinherit): Likewise.
* section.c (bfd_section): Add ident, a pointer to section
identifier and group, a pointer to section group.
(bfd_get_section_ident): New.
* section (STD_SECTION): Initialize ident and group to NULL.
* ecoff.c (bfd_debug_section): Likewise.
* bfd-in2.h: Regenerated.
--- bfd/ecoff.c.ident 2004-04-26 21:11:29.000000000 -0700
+++ bfd/ecoff.c 2004-05-29 00:44:47.428008945 -0700
@@ -77,8 +77,8 @@ static unsigned int ecoff_armap_hash
static asection bfd_debug_section =
{
- /* name, id, index, next, flags, user_set_vma, reloc_done, */
- "*DEBUG*", 0, 0, NULL, 0, 0, 0,
+ /* name, ident, id, index, next, flags, user_set_vma, reloc_done, */
+ "*DEBUG*", NULL, 0, 0, NULL, 0, 0, 0,
/* linker_mark, linker_has_input, gc_mark, segment_mark, */
0, 0, 0, 0,
/* sec_info_type, use_rela_p, has_tls_reloc, */
@@ -95,8 +95,8 @@ static asection bfd_debug_section =
NULL, NULL, 0, 0, 0,
/* line_filepos, userdata, contents, lineno, lineno_count, */
0, NULL, NULL, NULL, 0,
- /* entsize, comdat, kept_section, moving_line_filepos, */
- 0, NULL, NULL, 0,
+ /* entsize, comdat, group, kept_section, moving_line_filepos, */
+ 0, NULL, NULL, NULL, 0,
/* target_index, used_by_bfd, constructor_chain, owner, */
0, NULL, NULL, NULL,
/* symbol, */
--- bfd/elf-bfd.h.ident 2004-05-17 21:22:55.000000000 -0700
+++ bfd/elf-bfd.h 2004-05-29 00:47:23.171791653 -0700
@@ -1556,6 +1556,9 @@ extern bfd_boolean _bfd_elf_dynamic_symb
extern bfd_boolean _bfd_elf_symbol_refs_local_p
(struct elf_link_hash_entry *, struct bfd_link_info *, bfd_boolean);
+extern void _bfd_elf_setup_group_pointers
+ (bfd *);
+
extern const bfd_target *bfd_elf32_object_p
(bfd *);
extern const bfd_target *bfd_elf32_core_file_p
--- bfd/elf.c.ident 2004-05-26 23:08:37.000000000 -0700
+++ bfd/elf.c 2004-05-29 00:47:23.176791004 -0700
@@ -612,6 +612,26 @@ setup_group (bfd *abfd, Elf_Internal_Shd
return TRUE;
}
+void
+_bfd_elf_setup_group_pointers (bfd *abfd)
+{
+ unsigned int i;
+ unsigned int num_group = elf_tdata (abfd)->num_group;
+
+ if (num_group == (unsigned) -1)
+ return;
+
+ for (i = 0; i < num_group; i++)
+ {
+ Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
+ Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents;
+ unsigned int n_elt = shdr->sh_size / 4;
+
+ while (--n_elt != 0)
+ (++idx)->shdr->bfd_section->group = shdr->bfd_section;
+ }
+}
+
bfd_boolean
bfd_elf_is_group_section (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec)
{
--- bfd/elfcode.h.ident 2004-04-22 08:20:00.000000000 -0700
+++ bfd/elfcode.h 2004-05-29 00:44:47.439007517 -0700
@@ -742,6 +742,9 @@ elf_object_p (bfd *abfd)
if (shindex == SHN_LORESERVE - 1)
shindex += SHN_HIRESERVE + 1 - SHN_LORESERVE;
}
+
+ /* Set up group pointers. */
+ _bfd_elf_setup_group_pointers (abfd);
}
/* Let the backend double check the format and override global
--- bfd/elflink.c.ident 2004-05-25 22:34:17.000000000 -0700
+++ bfd/elflink.c 2004-05-29 00:44:47.446006608 -0700
@@ -1850,7 +1850,8 @@ elf_link_read_relocs_from_section (bfd *
(*_bfd_error_handler)
(_("%s: bad reloc symbol index (0x%lx >= 0x%lx) for offset 0x%lx in section `%s'"),
bfd_archive_filename (abfd), (unsigned long) r_symndx,
- (unsigned long) nsyms, irela->r_offset, sec->name);
+ (unsigned long) nsyms, irela->r_offset,
+ bfd_get_section_ident (sec));
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
@@ -2040,7 +2041,7 @@ _bfd_elf_link_output_relocs (bfd *output
(_("%s: relocation size mismatch in %s section %s"),
bfd_get_filename (output_bfd),
bfd_archive_filename (input_section->owner),
- input_section->name);
+ bfd_get_section_ident (input_section));
bfd_set_error (bfd_error_wrong_object_format);
return FALSE;
}
@@ -6068,8 +6069,8 @@ elf_link_output_extsym (struct elf_link_
(*_bfd_error_handler)
(_("%s: could not find output section %s for input section %s"),
bfd_get_filename (finfo->output_bfd),
- input_sec->output_section->name,
- input_sec->name);
+ bfd_get_section_ident (input_sec->output_section),
+ bfd_get_section_ident (input_sec));
eoinfo->failed = TRUE;
return FALSE;
}
@@ -6587,7 +6588,7 @@ elf_link_input_bfd (struct elf_final_lin
_("%T: discarded in section `%s' from %s\n"),
h->root.root.string,
h->root.root.string,
- h->root.u.def.section->name,
+ bfd_get_section_ident (h->root.u.def.section),
bfd_archive_filename (h->root.u.def.section->owner));
}
}
@@ -6626,7 +6627,7 @@ elf_link_input_bfd (struct elf_final_lin
finfo->info->callbacks->error_handler
(LD_DEFINITION_IN_DISCARDED_SECTION,
_("%T: discarded in section `%s' from %s\n"),
- buf, buf, sec->name,
+ buf, buf, bfd_get_section_ident (sec),
bfd_archive_filename (input_bfd));
if (ok != -1)
free (buf);
@@ -8566,7 +8567,8 @@ bfd_elf_gc_record_vtinherit (bfd *abfd,
}
(*_bfd_error_handler) ("%s: %s+%lu: No symbol found for INHERIT",
- bfd_archive_filename (abfd), sec->name,
+ bfd_archive_filename (abfd),
+ bfd_get_section_ident (sec),
(unsigned long) offset);
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
--- bfd/section.c.ident 2004-05-17 07:37:17.000000000 -0700
+++ bfd/section.c 2004-05-29 00:51:02.265356626 -0700
@@ -172,6 +172,10 @@ CODE_FRAGMENT
. the same as that passed to bfd_make_section. *}
. const char *name;
.
+. {* The identifier of the section; the identifier is unique within
+. the file. *}
+. const char *ident;
+.
. {* A unique sequence number. *}
. int id;
.
@@ -493,6 +497,10 @@ CODE_FRAGMENT
. {* Optional information about a COMDAT entry; NULL if not COMDAT. *}
. struct bfd_comdat_info *comdat;
.
+. {* Optional information about section group; NULL if it doesn't
+. belongs to any section group. *}
+. struct bfd_section *group;
+.
. {* Points to the kept section if this section is a link-once section,
. and is discarded. *}
. struct bfd_section *kept_section;
@@ -616,8 +624,8 @@ static const asymbol global_syms[] =
#define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX) \
const asymbol * const SYM = (asymbol *) &global_syms[IDX]; \
asection SEC = \
- /* name, id, index, next, flags, user_set_vma, reloc_done, */ \
- { NAME, IDX, 0, NULL, FLAGS, 0, 0, \
+ /* name, ident, id, index, next, flags, user_set_vma, reloc_done, */\
+ { NAME, NULL, IDX, 0, NULL, FLAGS, 0, 0, \
\
/* linker_mark, linker_has_input, gc_mark, segment_mark, */ \
0, 0, 1, 0, \
@@ -643,8 +651,8 @@ static const asymbol global_syms[] =
/* line_filepos, userdata, contents, lineno, lineno_count, */ \
0, NULL, NULL, NULL, 0, \
\
- /* entsize, comdat, kept_section, moving_line_filepos, */ \
- 0, NULL, NULL, 0, \
+ /* entsize, comdat, group, kept_section, moving_line_filepos, */ \
+ 0, NULL, NULL, NULL, 0, \
\
/* target_index, used_by_bfd, constructor_chain, owner, */ \
0, NULL, NULL, NULL, \
@@ -1476,3 +1484,41 @@ bfd_generic_discard_group (bfd *abfd ATT
{
return TRUE;
}
+
+/*
+FUNCTION
+ bfd_get_section_ident
+
+SYNOPSIS
+ const char *bfd_get_section_ident (asection *sec);
+
+DESCRIPTION
+ Return the section identifier of @var{sec}.
+*/
+
+const char *
+bfd_get_section_ident (asection *sec)
+{
+ if (sec->ident == NULL)
+ {
+ if (sec->group == NULL)
+ sec->ident = sec->name;
+ else if (sec->owner != NULL)
+ {
+ bfd_size_type nlen = strlen (sec->name);
+ bfd_size_type glen = strlen (sec->group->name);
+ char *buf = bfd_alloc (sec->owner, nlen + glen + 2 + 1);
+ if (buf != NULL)
+ {
+ strcpy (buf, sec->name);
+ buf [nlen] = '[';
+ strcpy (&buf [nlen + 1], sec->group->name);
+ buf [nlen + 1 + glen] = ']';
+ buf [nlen + 1 + glen + 1] = '\0';
+ sec->ident = buf;
+ }
+ }
+ }
+
+ return sec->ident;
+}
More information about the Binutils
mailing list