Allow an otherwise unrepresentable read-only section that lies after .text

and before .data to be written into the output file and included in a_text.
This commit is contained in:
Nick Clifton 2002-12-10 16:15:27 +00:00
parent e06d9b4589
commit e6af3a53b1
3 changed files with 76 additions and 36 deletions

View file

@ -1,3 +1,13 @@
2002-12-10 Jason Thorpe <thorpej@wasabisystems.com>
* aoutx.h (set_section_contents): Allow an otherwise unrepresentable
read-only section that lies after .text and before .data to be
written into the output file and included in a_text.
(translate_to_native_sym_flags): If an otherwise unrepresentable
section was merged with .text, convert its symbols to N_TEXT
symbols.
* libaout.h (aout_section_merge_with_text_p): New macro.
2002-12-08 Alan Modra <amodra@bigpond.net.au>
* bfd-in.h: Comment typo fix. Formatting.

View file

@ -1287,11 +1287,17 @@ NAME(aout,set_section_contents) (abfd, section, location, offset, count)
if (section != obj_textsec (abfd)
&& section != obj_datasec (abfd))
{
(*_bfd_error_handler)
(_("%s: can not represent section `%s' in a.out object file format"),
bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
if (aout_section_merge_with_text_p (abfd, section))
section->filepos = obj_textsec (abfd)->filepos +
(section->vma - obj_textsec (abfd)->vma);
else
{
(*_bfd_error_handler)
(_("%s: can not represent section `%s' in a.out object file format"),
bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
}
}
if (count != 0)
@ -1703,11 +1709,16 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
sym_pointer->e_type[0] = N_UNDF | N_EXT;
else
{
(*_bfd_error_handler)
(_("%s: can not represent section `%s' in a.out object file format"),
bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
if (aout_section_merge_with_text_p (abfd, sec))
sym_pointer->e_type[0] |= N_TEXT;
else
{
(*_bfd_error_handler)
(_("%s: can not represent section `%s' in a.out object file format"),
bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
bfd_set_error (bfd_error_nonrepresentable_section);
return FALSE;
}
}
/* Turn the symbol from section relative to absolute again. */

View file

@ -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. */
#ifndef LIBAOUT_H
#define LIBAOUT_H
@ -282,10 +282,10 @@ enum machine_type {
M_68010 = 1,
M_68020 = 2,
M_SPARC = 3,
/* skip a bunch so we don't run into any of suns numbers */
/* make these up for the ns32k*/
M_NS32032 = (64), /* ns32032 running ? */
M_NS32532 = (64 + 5), /* ns32532 running mach */
/* Skip a bunch so we don't run into any of SUN's numbers. */
/* Make these up for the ns32k. */
M_NS32032 = (64), /* ns32032 running ? */
M_NS32532 = (64 + 5), /* ns32532 running mach */
M_386 = 100,
M_29K = 101, /* AMD 29000 */
@ -377,7 +377,7 @@ struct aoutdata {
struct internal_exec *hdr; /* exec file header */
aout_symbol_type *symbols; /* symtab for input bfd */
/* For ease, we do this */
/* For ease, we do this. */
asection *textsec;
asection *datasec;
asection *bsssec;
@ -387,16 +387,16 @@ struct aoutdata {
file_ptr sym_filepos;
file_ptr str_filepos;
/* Size of a relocation entry in external form */
/* Size of a relocation entry in external form. */
unsigned reloc_entry_size;
/* Size of a symbol table entry in external form */
/* Size of a symbol table entry in external form. */
unsigned symbol_entry_size;
/* Page size - needed for alignment of demand paged files. */
/* Page size - needed for alignment of demand paged files. */
unsigned long page_size;
/* Segment size - needed for alignment of demand paged files. */
/* Segment size - needed for alignment of demand paged files. */
unsigned long segment_size;
/* Zmagic disk block size - need to align the start of the text
@ -406,7 +406,7 @@ struct aoutdata {
unsigned exec_bytes_size;
unsigned vma_adjusted : 1;
/* used when a bfd supports several highly similar formats */
/* Used when a bfd supports several highly similar formats. */
enum
{
default_format = 0,
@ -471,7 +471,7 @@ struct aout_data_struct {
#define obj_aout_dynamic_info(bfd) (adata(bfd).dynamic_info)
/* We take the address of the first element of an asymbol to ensure that the
macro is only ever applied to an asymbol */
macro is only ever applied to an asymbol. */
#define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
/* Information we keep for each a.out section. This is currently only
@ -489,7 +489,7 @@ struct aout_section_data_struct
#define set_aout_section_data(s,v) \
((s)->used_by_bfd = (PTR)&(v)->relocs)
/* Prototype declarations for functions defined in aoutx.h */
/* Prototype declarations for functions defined in aoutx.h. */
extern bfd_boolean NAME(aout,squirt_out_relocs)
PARAMS ((bfd *, asection *));
@ -612,7 +612,7 @@ extern bfd_boolean NAME(aout,final_link)
extern bfd_boolean NAME(aout,bfd_free_cached_info)
PARAMS ((bfd *));
/* A.out uses the generic versions of these routines... */
/* A.out uses the generic versions of these routines... */
#define aout_16_get_section_contents _bfd_generic_get_section_contents
@ -648,7 +648,7 @@ extern bfd_boolean NAME(aout,bfd_free_cached_info)
|| bfd_bwrite ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, \
abfd) != EXEC_BYTES_SIZE) \
return FALSE; \
/* Now write out reloc info, followed by syms and strings */ \
/* Now write out reloc info, followed by syms and strings. */ \
\
if (bfd_get_outsymbols (abfd) != (asymbol **) NULL \
&& bfd_get_symcount (abfd) != 0) \
@ -672,4 +672,23 @@ extern bfd_boolean NAME(aout,bfd_free_cached_info)
}
#endif
/* Test if a read-only section can be merged with .text. This is
possible if:
1. Section has file contents and is read-only.
2. The VMA of the section is after the end of .text and before
the start of .data.
3. The image is demand-pageable (otherwise, a_text in the header
will not reflect the gap between .text and .data). */
#define aout_section_merge_with_text_p(abfd, sec) \
(((sec)->flags & (SEC_HAS_CONTENTS | SEC_READONLY)) == \
(SEC_HAS_CONTENTS | SEC_READONLY) \
&& obj_textsec (abfd) != NULL \
&& obj_datasec (abfd) != NULL \
&& (sec)->vma >= (obj_textsec (abfd)->vma + \
obj_textsec (abfd)->_cooked_size) \
&& ((sec)->vma + (sec)->_cooked_size) <= obj_datasec (abfd)->vma \
&& ((abfd)->flags & D_PAGED) != 0)
#endif /* ! defined (LIBAOUT_H) */