This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [RFA:] bfd/simple.c: fix NOCROSSREFS for not-pure-ELF targets.
- From: Hans-Peter Nilsson <hp at bitrange dot com>
- To: Alan Modra <amodra at bigpond dot net dot au>
- Cc: binutils at sources dot redhat dot com
- Date: Sat, 16 Aug 2003 11:11:11 -0400 (EDT)
- Subject: Re: [RFA:] bfd/simple.c: fix NOCROSSREFS for not-pure-ELF targets.
On Sat, 16 Aug 2003, Alan Modra wrote:
> On Sat, Aug 16, 2003 at 07:24:18AM -0400, Hans-Peter Nilsson wrote:
> > best fix seems to be to move the existing kludge to before the
> > first bfd_section_size call.
>
> Err, isn't the kludge there to undo setting of reloc_done by
> bfd_generic_get_relocated_section_contents?
Uhh, yes?
(The function bfd_generic_get_relocated_section_contents is
called before bfd_simple_get_relocated_section_contents, causing
the abort in bfd_section_size calls there.)
Oh, you mean for any users *after the call to
bfd_simple_get_relocated_section_contents*?
Who are they (ah, somewhere in gdb) and why don't they contain
that undoing kludge themselves? Should a function named
bfd_simple_get_relocated_section_contents really undo any marks
that the section is relocated?
Anyway, I guess bfd_simple_get_relocated_section_contents is
just misnamed (as in causing semantics to be confused with those
of bfd_generic_get_relocated_section_contents). And I think it
should *save*, not *clear* the reloc_done flag.
So, is this ok? (tested mmix-knuth-mmixware, NOCROSSREFS 1 with
-melf64mmix too.)
* simple.c (bfd_simple_get_relocated_section_contents): Move
reloc_done hack to before first bfd_section_size call. Change all
returns to use new wrapper macro RETURN, restoring sec->reloc_done.
Index: simple.c
===================================================================
RCS file: /cvs/src/src/bfd/simple.c,v
retrieving revision 1.10
diff -p -c -r1.10 simple.c
*** simple.c 29 Jun 2003 10:06:39 -0000 1.10
--- simple.c 16 Aug 2003 15:05:44 -0000
*************** bfd_simple_get_relocated_section_content
*** 140,145 ****
--- 140,167 ----
bfd_byte *contents, *data;
int storage_needed;
void *saved_offsets;
+ bfd_boolean saved_reloc_done = sec->reloc_done;
+
+ #undef RETURN
+ #define RETURN(x) \
+ do \
+ { \
+ sec->reloc_done = saved_reloc_done; \
+ return (x); \
+ } \
+ while (0)
+
+ /* Foul hack to prevent bfd_section_size aborts. The reloc_done flag
+ only controls that macro (and the related size macros), selecting
+ between _raw_size and _cooked_size. We may be called with relocation
+ done or not, so we need to save the done-flag and mark the section as
+ not relocated.
+
+ Debug sections won't change size while we're only relocating. There
+ may be trouble here someday if it tries to run relaxation
+ unexpectedly, so make sure. */
+ BFD_ASSERT (sec->_raw_size == sec->_cooked_size);
+ sec->reloc_done = 0;
if (! (sec->flags & SEC_RELOC))
{
*************** bfd_simple_get_relocated_section_content
*** 153,159 ****
if (contents)
bfd_get_section_contents (abfd, sec, contents, 0, size);
! return contents;
}
/* In order to use bfd_get_relocated_section_contents, we need
--- 175,181 ----
if (contents)
bfd_get_section_contents (abfd, sec, contents, 0, size);
! RETURN (contents);
}
/* In order to use bfd_get_relocated_section_contents, we need
*************** bfd_simple_get_relocated_section_content
*** 183,189 ****
{
data = bfd_malloc (bfd_section_size (abfd, sec));
if (data == NULL)
! return NULL;
outbuf = data;
}
--- 205,211 ----
{
data = bfd_malloc (bfd_section_size (abfd, sec));
if (data == NULL)
! RETURN (NULL);
outbuf = data;
}
*************** bfd_simple_get_relocated_section_content
*** 202,208 ****
{
if (data)
free (data);
! return NULL;
}
bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets);
--- 224,230 ----
{
if (data)
free (data);
! RETURN (NULL);
}
bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets);
*************** bfd_simple_get_relocated_section_content
*** 243,257 ****
bfd_map_over_sections (abfd, simple_restore_output_info, saved_offsets);
free (saved_offsets);
- /* Foul hack to prevent bfd_section_size aborts. This flag only controls
- that macro (and the related size macros), selecting between _raw_size
- and _cooked_size. Debug sections won't change size while we're only
- relocating. There may be trouble here someday if it tries to run
- relaxation unexpectedly, so make sure. */
- BFD_ASSERT (sec->_raw_size == sec->_cooked_size);
- sec->reloc_done = 0;
-
bfd_link_hash_table_free (abfd, link_info.hash);
! return contents;
}
--- 265,271 ----
bfd_map_over_sections (abfd, simple_restore_output_info, saved_offsets);
free (saved_offsets);
bfd_link_hash_table_free (abfd, link_info.hash);
! RETURN (contents);
}
brgds, H-P