From 849bab54f0aa7823170b9aaa048e5df10d97d651 Mon Sep 17 00:00:00 2001 From: nickc Date: Thu, 7 Nov 2002 14:36:31 +0000 Subject: [PATCH] Use bfd_simple_get_relocated_section_contents() instead of bfd_get_section_contents(). --- bfd/ChangeLog | 11 +++++++++++ bfd/dwarf2.c | 16 ++++++++-------- bfd/reloc.c | 27 ++++++++++++++------------- bfd/simple.c | 15 +++++++++++++++ 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 941da8a28d..5acc0c619d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,14 @@ +2002-11-07 Michal Ludvig + + * dwarf2.c (read_indirect_string, read_abbrevs, decode_line_info, + _bfd_dwarf2_find_nearest_line): Use + bfd_simple_get_relocated_section_contents() instead of + bfd_get_section_contents(). + * reloc.c (bfd_perform_relocation): Add sanity check. + * simple.c (simple_get_relocated_section_contents): If the section + does not have any relocs associated with it, just return the + unadjusted contents. + 2002-11-07 Hans-Peter Nilsson * elf32-cris.c (cris_elf_relocate_section) dwarf_abbrev_buffer) return NULL; - if (! bfd_get_section_contents (abfd, msec, stash->dwarf_str_buffer, - (bfd_vma) 0, msec->_raw_size)) + if (! bfd_simple_get_relocated_section_contents + (abfd, msec, stash->dwarf_str_buffer)) return NULL; } @@ -550,8 +550,8 @@ read_abbrevs (abfd, offset, stash) if (! stash->dwarf_abbrev_buffer) return 0; - if (! bfd_get_section_contents (abfd, msec, stash->dwarf_abbrev_buffer, - (bfd_vma) 0, msec->_raw_size)) + if (! bfd_simple_get_relocated_section_contents + (abfd, msec, stash->dwarf_abbrev_buffer)) return 0; } @@ -1023,8 +1023,8 @@ decode_line_info (unit, stash) if (! stash->dwarf_line_buffer) return 0; - if (! bfd_get_section_contents (abfd, msec, stash->dwarf_line_buffer, - (bfd_vma) 0, msec->_raw_size)) + if (! bfd_simple_get_relocated_section_contents + (abfd, msec, stash->dwarf_line_buffer)) return 0; /* FIXME: We ought to apply the relocs against this section before @@ -1939,8 +1939,8 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, start = stash->info_ptr_end - stash->info_ptr; - if (! bfd_get_section_contents (abfd, msec, stash->info_ptr + start, - (bfd_vma) 0, size)) + if (! bfd_simple_get_relocated_section_contents + (abfd, msec, stash->info_ptr + start)) continue; stash->info_ptr_end = stash->info_ptr + start + size; diff --git a/bfd/reloc.c b/bfd/reloc.c index b13f6722c1..0885e03232 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -4,21 +4,21 @@ Free Software Foundation, Inc. Written by Cygnus Support. -This file is part of BFD, the Binary File Descriptor library. + This file is part of BFD, the Binary File Descriptor library. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* SECTION @@ -645,7 +645,8 @@ bfd_perform_relocation (abfd, reloc_entry, data, input_section, output_bfd, reloc_target_output_section = symbol->section->output_section; /* Convert input-section-relative symbol value to absolute. */ - if (output_bfd && ! howto->partial_inplace) + if ((output_bfd && ! howto->partial_inplace) + || reloc_target_output_section == NULL) output_base = 0; else output_base = reloc_target_output_section->vma; diff --git a/bfd/simple.c b/bfd/simple.c index 10178a40ad..f0f5ee6412 100644 --- a/bfd/simple.c +++ b/bfd/simple.c @@ -138,6 +138,21 @@ bfd_simple_get_relocated_section_contents (abfd, sec, outbuf) int storage_needed, number_of_symbols; asymbol **symbol_table; + if (! (sec->flags & SEC_RELOC)) + { + bfd_size_type size = bfd_section_size (abfd, sec); + + if (outbuf == NULL) + contents = bfd_malloc (size); + else + contents = outbuf; + + if (contents) + bfd_get_section_contents (abfd, sec, contents, 0, size); + + return contents; + } + /* In order to use bfd_get_relocated_section_contents, we need to forge some data structures that it expects. */ -- 2.11.0