This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
SHT_GROUP support bugfixes
Bug fixes already. At the last moment before committing the last patch,
I changed elf.c:set_group_contents to use "sec->symbol" instead of
"elf_section_syms (abfd)[sec->index]", which turns out to be wrong. Also,
I've removed the hackish use of sec->lineno to pass a section pointer
around. It's much better to use elf_next_in_group (sec), and I suspect
using sec->lineno may even cause problems with elf targets that use ecoff
debugging info.
bfd/ChangeLog
* elf-bfd.h (struct bfd_elf_section_data): Rename "group" to
"group_name".
(elf_group_name): Define.
(elf_next_in_group): Define.
* elf.c: Make use of elf_group_name and elf_next_in_group throughout.
(setup_group): Don't use sec->lineno for SHT_GROUP section to store
first member section; Instead use elf_next_in_group.
(bfd_section_from_shdr): Likewise.
(set_group_contents): Likewise. Use elf_section_syms, not sec->symbol.
gas/ChangeLog
* config/obj-elf.c: Make use of elf_group_name and elf_next_in_group
throughout file.
(obj_elf_change_section): Rename "group" to "group_name".
(obj_elf_section): Likewise.
(elf_frob_file): Don't use sec->lineno for SHT_GROUP section to store
first member section; Instead use elf_next_in_group.
--
Alan Modra
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.51
diff -u -p -r1.51 elf-bfd.h
--- elf-bfd.h 2001/10/09 06:05:14 1.51
+++ elf-bfd.h 2001/10/09 12:34:27
@@ -816,7 +816,7 @@ struct bfd_elf_section_data
PTR merge_info;
/* Group name, if this section is part of a group. */
- const char *group;
+ const char *group_name;
/* A linked list of sections in the group. Circular when used by
the linker. */
@@ -830,6 +830,8 @@ struct bfd_elf_section_data
};
#define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd)
+#define elf_group_name(sec) (elf_section_data(sec)->group_name)
+#define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
#define get_elf_backend_data(abfd) \
((struct elf_backend_data *) (abfd)->xvec->backend_data)
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.98
diff -u -p -r1.98 elf.c
--- elf.c 2001/10/09 06:05:14 1.98
+++ elf.c 2001/10/09 12:34:32
@@ -475,20 +475,15 @@ setup_group (abfd, hdr, newsect)
n_elt = shdr->sh_size / 4;
while (--n_elt != 0)
if ((s = (++idx)->shdr->bfd_section) != NULL
- && elf_section_data (s)->next_in_group != NULL)
+ && elf_next_in_group (s) != NULL)
break;
if (n_elt != 0)
{
- const char *gname;
- asection *next;
-
/* Snarf the group name from other member, and
insert current section in circular list. */
- gname = elf_section_data (s)->group;
- elf_section_data (newsect)->group = gname;
- next = elf_section_data (s)->next_in_group;
- elf_section_data (newsect)->next_in_group = next;
- elf_section_data (s)->next_in_group = newsect;
+ elf_group_name (newsect) = elf_group_name (s);
+ elf_next_in_group (newsect) = elf_next_in_group (s);
+ elf_next_in_group (s) = newsect;
}
else
{
@@ -511,20 +506,20 @@ setup_group (abfd, hdr, newsect)
return false;
iname = H_GET_32 (abfd, ename);
gname = elf_string_from_elf_strtab (abfd, iname);
- elf_section_data (newsect)->group = gname;
+ elf_group_name (newsect) = gname;
/* Start a circular list with one element. */
- elf_section_data (newsect)->next_in_group = newsect;
+ elf_next_in_group (newsect) = newsect;
}
if (shdr->bfd_section != NULL)
- shdr->bfd_section->lineno = (alent *) newsect;
+ elf_next_in_group (shdr->bfd_section) = newsect;
i = num_group - 1;
break;
}
}
}
- if (elf_section_data (newsect)->group == NULL)
+ if (elf_group_name (newsect) == NULL)
{
(*_bfd_error_handler) (_("%s: no group info for section %s"),
bfd_archive_filename (abfd), newsect->name);
@@ -1718,9 +1713,9 @@ bfd_section_from_shdr (abfd, shindex)
while (--n_elt != 0)
if ((s = (++idx)->shdr->bfd_section) != NULL
- && elf_section_data (s)->next_in_group != NULL)
+ && elf_next_in_group (s) != NULL)
{
- hdr->bfd_section->lineno = (alent *) s;
+ elf_next_in_group (hdr->bfd_section) = s;
break;
}
}
@@ -2085,7 +2080,7 @@ elf_fake_sections (abfd, asect, failedpt
if ((asect->flags & SEC_STRINGS) != 0)
this_hdr->sh_flags |= SHF_STRINGS;
}
- if (elf_section_data (asect)->group != NULL)
+ if (elf_group_name (asect) != NULL)
this_hdr->sh_flags |= SHF_GROUP;
/* Check for processor-specific section types. */
@@ -2123,10 +2118,11 @@ set_group_contents (abfd, sec, failedptr
return;
/* If called from the assembler, swap_out_syms will have set up
- udata.i; If called for "ld -r", the symbols won't yet be mapped,
- so emulate elf_bfd_final_link. */
- symindx = sec->symbol->udata.i;
- if (symindx == 0)
+ elf_section_syms; If called for "ld -r", the symbols won't yet
+ be mapped, so emulate elf_bfd_final_link. */
+ if (elf_section_syms (abfd) != NULL)
+ symindx = elf_section_syms (abfd)[sec->index]->udata.i;
+ else
symindx = elf_section_data (sec)->this_idx;
elf_section_data (sec)->this_hdr.sh_info = symindx;
@@ -2145,7 +2141,7 @@ set_group_contents (abfd, sec, failedptr
/* Get the pointer to the first section in the group that we
squirreled away here. */
- elt = (asection *) sec->lineno;
+ elt = elf_next_in_group (sec);
/* First element is a flag word. Rest of section is elf section
indices for all the sections of the group. Write them backwards
@@ -2155,7 +2151,7 @@ set_group_contents (abfd, sec, failedptr
{
loc -= 4;
H_PUT_32 (abfd, elf_section_data (elt)->this_idx, loc);
- elt = elf_section_data (elt)->next_in_group;
+ elt = elf_next_in_group (elt);
}
/* If this is a relocatable link, then the above did nothing because
@@ -2163,16 +2159,16 @@ set_group_contents (abfd, sec, failedptr
instead. */
for (l = sec->link_order_head; l != NULL; l = l->next)
if (l->type == bfd_indirect_link_order
- && (elt = (asection *) l->u.indirect.section->lineno) != NULL)
+ && (elt = elf_next_in_group (l->u.indirect.section)) != NULL)
do
{
loc -= 4;
H_PUT_32 (abfd,
elf_section_data (elt->output_section)->this_idx, loc);
- elt = elf_section_data (elt)->next_in_group;
+ elt = elf_next_in_group (elt);
/* During a relocatable link, the lists are circular. */
}
- while (elt != (asection *) l->u.indirect.section->lineno);
+ while (elt != elf_next_in_group (l->u.indirect.section));
loc -= 4;
H_PUT_32 (abfd, 0, loc);
Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.42
diff -u -p -r1.42 obj-elf.c
--- obj-elf.c 2001/10/09 06:07:33 1.42
+++ obj-elf.c 2001/10/09 12:34:38
@@ -620,12 +620,12 @@ static struct special_section const spec
};
static void
-obj_elf_change_section (name, type, attr, entsize, group, push)
+obj_elf_change_section (name, type, attr, entsize, group_name, push)
const char *name;
int type;
int attr;
int entsize;
- const char *group;
+ const char *group_name;
int push;
{
asection *old_sec;
@@ -712,7 +712,7 @@ obj_elf_change_section (name, type, attr
bfd_set_section_flags (stdoutput, sec, flags);
if (flags & SEC_MERGE)
sec->entsize = entsize;
- elf_section_data (sec)->group = group;
+ elf_group_name (sec) = group_name;
/* Add a symbol for this section to the symbol table. */
secsym = symbol_find (name);
@@ -733,7 +733,7 @@ obj_elf_change_section (name, type, attr
else if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize)
as_warn (_("ignoring changed section entity size for %s"), name);
else if ((attr & SHF_GROUP) != 0
- && strcmp (elf_section_data (old_sec)->group, group) != 0)
+ && strcmp (elf_group_name (old_sec), group_name) != 0)
as_warn (_("ignoring new section group for %s"), name);
}
@@ -895,7 +895,7 @@ void
obj_elf_section (push)
int push;
{
- char *name, *group, *beg;
+ char *name, *group_name, *beg;
int type, attr, dummy;
int entsize;
@@ -926,7 +926,7 @@ obj_elf_section (push)
return;
type = SHT_NULL;
attr = 0;
- group = NULL;
+ group_name = NULL;
entsize = 0;
if (*input_line_pointer == ',')
@@ -998,8 +998,8 @@ obj_elf_section (push)
if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
{
++input_line_pointer;
- group = obj_elf_section_name ();
- if (group == NULL)
+ group_name = obj_elf_section_name ();
+ if (group_name == NULL)
attr &= ~SHF_GROUP;
}
else if ((attr & SHF_GROUP) != 0)
@@ -1036,7 +1036,7 @@ obj_elf_section (push)
demand_empty_rest_of_line ();
- obj_elf_change_section (name, type, attr, entsize, group, push);
+ obj_elf_change_section (name, type, attr, entsize, group_name, push);
}
/* Change to the .data section. */
@@ -1910,7 +1910,7 @@ build_group_lists (abfd, sec, inf)
PTR inf;
{
struct group_list *list = (struct group_list *) inf;
- const char *group_name = elf_section_data (sec)->group;
+ const char *group_name = elf_group_name (sec);
unsigned int i;
if (group_name == NULL)
@@ -1920,9 +1920,9 @@ build_group_lists (abfd, sec, inf)
the list. */
for (i = 0; i < list->num_group; i++)
{
- if (strcmp (group_name, elf_section_data (list->head[i])->group) == 0)
+ if (strcmp (group_name, elf_group_name (list->head[i])) == 0)
{
- elf_section_data (sec)->next_in_group = list->head[i];
+ elf_next_in_group (sec) = list->head[i];
list->head[i] = sec;
list->elt_count[i] += 1;
return;
@@ -1964,7 +1964,7 @@ elf_frob_file ()
the rest of the work. */
for (i = 0; i < list.num_group; i++)
{
- const char *group_name = elf_section_data (list.head[i])->group;
+ const char *group_name = elf_group_name (list.head[i]);
asection *s;
flagword flags;
@@ -1978,10 +1978,8 @@ elf_frob_file ()
bfd_errmsg (bfd_get_error ()));
}
- /* Pass a pointer to the first section in this group. This
- seems as good a field to use as any; It's not used otherwise
- by the ELF code. */
- s->lineno = (alent *) list.head[i];
+ /* Pass a pointer to the first section in this group. */
+ elf_next_in_group (s) = list.head[i];
s->_raw_size = 4 * (list.elt_count[i] + 1);
s->contents = frag_more (s->_raw_size);