From b0cdc7bcb0239e52de59195f8b7e213c3f5ddc14 Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson Date: Sun, 17 Aug 2003 07:37:33 +0000 Subject: [PATCH] * 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. --- bfd/ChangeLog | 6 ++++++ bfd/simple.c | 38 ++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 3887f37..2ebddbf 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2003-08-17 Hans-Peter Nilsson + + * 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. + 2003-08-16 Alan Modra * elf64-ppc.c: Don't include elf/ppc.h. diff --git a/bfd/simple.c b/bfd/simple.c index 256fd91..c2a741c 100644 --- a/bfd/simple.c +++ b/bfd/simple.c @@ -140,6 +140,28 @@ bfd_simple_get_relocated_section_contents (bfd *abfd, 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)) { @@ -153,7 +175,7 @@ bfd_simple_get_relocated_section_contents (bfd *abfd, if (contents) bfd_get_section_contents (abfd, sec, contents, 0, size); - return contents; + RETURN (contents); } /* In order to use bfd_get_relocated_section_contents, we need @@ -183,7 +205,7 @@ bfd_simple_get_relocated_section_contents (bfd *abfd, { data = bfd_malloc (bfd_section_size (abfd, sec)); if (data == NULL) - return NULL; + RETURN (NULL); outbuf = data; } @@ -202,7 +224,7 @@ bfd_simple_get_relocated_section_contents (bfd *abfd, { if (data) free (data); - return NULL; + RETURN (NULL); } bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets); @@ -243,15 +265,7 @@ bfd_simple_get_relocated_section_contents (bfd *abfd, 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; + RETURN (contents); } -- 2.7.4