/* And more follows */
-void EXFUN(bfd_check_init, (void));
-PTR EXFUN(bfd_xmalloc, ( bfd_size_type size));
-void EXFUN(bfd_write_bigendian_4byte_int, (bfd *abfd, int i));
-bfd_vma EXFUN(bfd_log2, (bfd_vma x));
-void EXFUN(bfd_check_init, (void));
-PTR EXFUN(bfd_xmalloc, ( bfd_size_type size));
-void EXFUN(bfd_write_bigendian_4byte_int, (bfd *abfd, int i));
-bfd_vma EXFUN(bfd_log2, (bfd_vma x));
+void
+bfd_check_init PARAMS ((void));
+
+PTR
+bfd_xmalloc PARAMS (( bfd_size_type size));
+
+void
+bfd_write_bigendian_4byte_int PARAMS ((bfd *abfd, int i));
+
+bfd_vma
+bfd_log2 PARAMS ((bfd_vma x));
+
+void
+bfd_check_init PARAMS ((void));
+
+PTR
+bfd_xmalloc PARAMS (( bfd_size_type size));
+
+void
+bfd_write_bigendian_4byte_int PARAMS ((bfd *abfd, int i));
+
+bfd_vma
+bfd_log2 PARAMS ((bfd_vma x));
+
#define BFD_CACHE_MAX_OPEN 10
extern bfd *bfd_last_cache;
((x)==bfd_last_cache? \
(FILE*)(bfd_last_cache->iostream): \
bfd_cache_lookup_worker(x))
-void EXFUN(bfd_cache_init , (bfd *));
-boolean EXFUN(bfd_cache_close , (bfd *));
-FILE* EXFUN(bfd_open_file, (bfd *));
-FILE *EXFUN(bfd_cache_lookup_worker, (bfd *));
-void EXFUN(bfd_constructor_entry, (bfd *abfd,
+void
+bfd_cache_init PARAMS ((bfd *));
+
+boolean
+bfd_cache_close PARAMS ((bfd *));
+
+FILE*
+bfd_open_file PARAMS ((bfd *));
+
+FILE *
+bfd_cache_lookup_worker PARAMS ((bfd *));
+
+void
+bfd_constructor_entry PARAMS ((bfd *abfd,
asymbol **symbol_ptr_ptr,
CONST char*type));
-CONST struct reloc_howto_struct *EXFUN(bfd_default_reloc_type_lookup
- , (CONST struct bfd_arch_info *,
+
+CONST struct reloc_howto_struct *
+bfd_default_reloc_type_lookup
+ PARAMS ((CONST struct bfd_arch_info *,
bfd_reloc_code_real_type code));
-boolean EXFUN(bfd_generic_relax_section
- , (bfd *abfd,
+
+boolean
+bfd_generic_relax_section
+ PARAMS ((bfd *abfd,
asection *section,
asymbol **symbols));
+
bfd_byte *
-EXFUN(bfd_generic_get_relocated_section_contents, (bfd *abfd,
+
+bfd_generic_get_relocated_section_contents PARAMS ((bfd *abfd,
struct bfd_seclet_struct *seclet,
bfd_byte *data)
);
+
extern bfd_arch_info_type bfd_default_arch_struct;
-boolean EXFUN(bfd_default_set_arch_mach, (bfd *abfd,
+boolean
+bfd_default_set_arch_mach PARAMS ((bfd *abfd,
enum bfd_architecture arch,
unsigned long mach));
-void EXFUN(bfd_arch_init, (void));
-void EXFUN(bfd_arch_linkin, (bfd_arch_info_type *));
-CONST bfd_arch_info_type *EXFUN(bfd_default_compatible
- , (CONST bfd_arch_info_type *a,
+
+void
+bfd_arch_init PARAMS ((void));
+
+void
+bfd_arch_linkin PARAMS ((bfd_arch_info_type *));
+
+CONST bfd_arch_info_type *
+bfd_default_compatible
+ PARAMS ((CONST bfd_arch_info_type *a,
CONST bfd_arch_info_type *b));
-boolean EXFUN(bfd_default_scan, (CONST struct bfd_arch_info *, CONST char *));
-struct elf_internal_shdr *EXFUN(bfd_elf_find_section , (bfd *abfd, char *name));
+
+boolean
+bfd_default_scan PARAMS ((CONST struct bfd_arch_info *, CONST char *));
+
+struct elf_internal_shdr *
+bfd_elf_find_section PARAMS ((bfd *abfd, char *name));
+
@* section prototypes::
@end menu
-@node Section Input, Section Output, Sections, Sections
+INODE
+Section Input, Section Output, Sections, Sections
SUBSECTION
Section Input
the data area has to be parsed to get out the data and
relocations.
-@node Section Output, typedef asection, Section Input, Sections
+INODE
+Section Output, typedef asection, Section Input, Sections
SUBSECTION
Section Output
the same way as input sections, data is written to the
sections using <<bfd_set_section_contents>>.
- The linker uses the fields <<output_section>> and
- <<output_offset>> to create an output file.
+ Any program that creates or combines sections (e.g., the assembler
+ and linker) must use the fields <<output_section>> and
+ <<output_offset>> to indicate the file sections to which each
+ section must be written. (If the section is being created from
+ scratch, <<output_section>> should probably point to the section
+ itself, and <<output_offset>> should probably be zero.)
The data to be written comes from input sections attached to
the output sections. The output section structure can be
input section determines the offset into the output section of
the data to be written.
- Eg to create a section "O", starting at 0x100, 0x123 long,
+ E.g., to create a section "O", starting at 0x100, 0x123 long,
containing two subsections, "A" at offset 0x0 (ie at vma
0x100) and "B" at offset 0x20 (ie at vma 0x120) the structures
would look like:
#include "libbfd.h"
-/*doc*
-@node typedef asection, section prototypes, Section Output, Sections
+/*
+DOCDD
+INODE
+typedef asection, section prototypes, Section Output, Sections
SUBSECTION
typedef asection
.
.
. bfd_vma vma;
+. boolean user_set_vma;
.
. {* The size of the section in bytes, as it will be output.
. contains a value even if the section has no contents (eg, the
. ((section->reloc_done) ? (section)->_cooked_size: (abort(),1))
*/
-
-
-asection bfd_com_section = { BFD_COM_SECTION_NAME ,0 };
-asection bfd_und_section = { BFD_UND_SECTION_NAME ,0 };
-asection bfd_abs_section = { BFD_ABS_SECTION_NAME ,0 };
-
-struct symbol_cache_entry *bfd_abs_symbol;
-struct symbol_cache_entry *bfd_com_symbol;
-struct symbol_cache_entry *bfd_und_symbol;
+/* These symbols are global, not specific to any BFD. Therefore, anything
+ that tries to change them is broken, and should be repaired. */
+static CONST asymbol global_syms[] = {
+ /* bfd, name, value, attr, section [, udata] */
+ { 0, BFD_COM_SECTION_NAME, 0, BSF_SECTION_SYM, &bfd_com_section },
+ { 0, BFD_UND_SECTION_NAME, 0, BSF_SECTION_SYM, &bfd_und_section },
+ { 0, BFD_ABS_SECTION_NAME, 0, BSF_SECTION_SYM, &bfd_abs_section },
+};
+
+#define STD_SECTION(SEC,SYM,NAME, IDX) \
+ asymbol *SYM = (asymbol *) &global_syms[IDX]; \
+ asection SEC = { NAME, 0, 0, 0, 0, (boolean) 0, 0, 0, 0, &SEC,\
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (boolean) 0, \
+ (asymbol *) &global_syms[IDX], &SYM, }
+
+STD_SECTION (bfd_com_section, bfd_com_symbol, BFD_COM_SECTION_NAME, 0);
+STD_SECTION (bfd_und_section, bfd_und_symbol, BFD_UND_SECTION_NAME, 1);
+STD_SECTION (bfd_abs_section, bfd_abs_symbol, BFD_ABS_SECTION_NAME, 2);
+#undef STD_SECTION
/*
-@node section prototypes, , typedef asection, Sections
+DOCDD
+INODE
+section prototypes, , typedef asection, Sections
SUBSECTION
section prototypes
before is was rewritten...
Possible errors are:
- o invalid_operation
+ o invalid_operation -
If output has already started for this BFD.
- o no_memory
+ o no_memory -
If obstack alloc fails.
*/
newsect->line_filepos =0;
newsect->owner = abfd;
-/* Create a symbol whos only job is to point to this section. This is
- usfull for things like relocs which are relative to the base of a
- section
- */
+ /* Create a symbol whos only job is to point to this section. This is
+ useful for things like relocs which are relative to the base of a
+ section. */
newsect->symbol = bfd_make_empty_symbol(abfd);
newsect->symbol->name = name;
newsect->symbol->value = 0;
supplied to the value. Returns true on success, false on
error. Possible error returns are:
- o invalid operation
+ o invalid operation -
The section cannot have one or more of the attributes
requested. For example, a .bss section in <<a.out>> may not
have the <<SEC_HAS_CONTENTS>> field set.
sec_ptr section AND
flagword flags)
{
+#if 0
+ /* If you try to copy a text section from an input file (where it
+ has the SEC_CODE flag set) to an output file, this loses big if
+ the bfd_applicable_section_flags (abfd) doesn't have the SEC_CODE
+ set - which it doesn't, at least not for a.out. FIXME */
+
if ((flags & bfd_applicable_section_flags (abfd)) != flags) {
bfd_error = invalid_operation;
return false;
}
+#endif
section->flags = flags;
return true;
bfd_map_over_sections
SYNOPSIS
- void bfd_map_over_sections(bfd *abfd, void (*func)(), PTR obj);
+ void bfd_map_over_sections(bfd *abfd,
+ void (*func)(bfd *abfd,
+ asection *sect,
+ PTR obj),
+ PTR obj);
DESCRIPTION
Calls the provided function @var{func} for each section
void
DEFUN(bfd_map_over_sections,(abfd, operation, user_storage),
bfd *abfd AND
- void (*operation)() AND
+ void (*operation) PARAMS ((bfd *abfd, asection *sect, PTR obj)) AND
PTR user_storage)
{
asection *sect;
ok, then <<true>> is returned, else <<false>>.
Possible error returns:
- o invalid_operation
+ o invalid_operation -
Writing has started to the BFD, so setting the size is invalid
*/
Normally <<true>> is returned, else <<false>>. Possible error
returns are:
- o no_contents
+ o no_contents -
The output section does not have the <<SEC_HAS_CONTENTS>>
attribute, so nothing can be written to it.
o and some more too
*/
+#define bfd_get_section_size_now(abfd,sec) \
+(sec->reloc_done \
+ ? bfd_get_section_size_after_reloc (sec) \
+ : bfd_get_section_size_before_reloc (sec))
+
boolean
DEFUN(bfd_set_section_contents,(abfd, section, location, offset, count),
bfd *abfd AND
file_ptr offset AND
bfd_size_type count)
{
+ bfd_size_type sz;
+
if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS))
{
bfd_error = no_contents;
return(false);
- }
+ }
+
+ if (offset < 0 || count < 0)
+ {
+ bad_val:
+ bfd_error = bad_value;
+ return false;
+ }
+ sz = bfd_get_section_size_now (abfd, section);
+ if (offset > sz
+ || count > sz
+ || offset + count > sz)
+ goto bad_val;
if (BFD_SEND (abfd, _bfd_set_section_contents,
(abfd, section, location, offset, count)))
file_ptr offset AND
bfd_size_type count)
{
- if (section->flags & SEC_CONSTRUCTOR)
- {
- memset(location, 0, (unsigned)count);
- return true;
- }
- else
- {
- return (BFD_SEND (abfd, _bfd_get_section_contents,
- (abfd, section, location, offset, count)));
- }
-}
-
-
-/* Initialize the internal data structures */
-DEFUN_VOID(bfd_section_init)
-{
-
- bfd_com_symbol = (asymbol *)zalloc(sizeof(asymbol));
- bfd_com_symbol->name = BFD_COM_SECTION_NAME;
- bfd_com_symbol->flags = BSF_SECTION_SYM;
- bfd_com_symbol->section = &bfd_com_section;
- bfd_com_section.symbol = bfd_com_symbol;
- bfd_com_section.symbol_ptr_ptr = &bfd_com_symbol;
- bfd_com_section.output_section = &bfd_com_section;
-
-
-
- bfd_und_symbol = (asymbol *)zalloc(sizeof(asymbol));
- bfd_und_symbol->name = BFD_UND_SECTION_NAME;
- bfd_und_symbol->flags = BSF_SECTION_SYM;
- bfd_und_symbol->section = &bfd_und_section;
- bfd_und_section.symbol = bfd_und_symbol;
- bfd_und_section.symbol_ptr_ptr = &bfd_und_symbol;
- bfd_und_section.output_section = &bfd_und_section;
-
- bfd_abs_symbol = (asymbol *)zalloc(sizeof(asymbol));
- bfd_abs_symbol->name = BFD_ABS_SECTION_NAME;
- bfd_abs_symbol->flags = BSF_SECTION_SYM;
- bfd_abs_symbol->section = &bfd_abs_section;
- bfd_abs_section.symbol = bfd_abs_symbol;
- bfd_abs_section.symbol_ptr_ptr = &bfd_abs_symbol;
- bfd_abs_section.output_section = &bfd_abs_section;
-
-
-
+ bfd_size_type sz;
+ if (section->flags & SEC_CONSTRUCTOR)
+ {
+ memset(location, 0, (unsigned)count);
+ return true;
+ }
+ if (offset < 0 || count < 0)
+ {
+ bad_val:
+ bfd_error = bad_value;
+ return false;
+ }
+ sz = bfd_get_section_size_now (abfd, section);
+ if (offset > sz
+ || count > sz
+ || offset + count > sz)
+ goto bad_val;
+
+ if (count == 0)
+ /* Don't bother. */
+ return true;
+
+ return BFD_SEND (abfd, _bfd_get_section_contents,
+ (abfd, section, location, offset, count));
}