old-cross-binutils/bfd/section.c

1369 lines
41 KiB
C
Raw Normal View History

1999-05-03 07:29:11 +00:00
/* Object file "section" support for the BFD library.
2001-03-08 21:04:02 +00:00
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
bfd * elf-bfd.h (enum elf_link_info_type): Remove. (struct bfd_elf_section_data): Move sec_info_type, use_rela_p fields to struct sec. Remove linkonce_p field. (elf_linkonce_p): Delete. (elf_discarded_section): Update for sec_info_type change. * section.c (struct sec): Add sec_info_type, use_rela_p, has_tls_reloc, flag11, flag12, flag13, flag14, flag15, flag16, flag20, flag24. (ELF_INFO_TYPE_NONE): Define. (ELF_INFO_TYPE_STABS): Define. (ELF_INFO_TYPE_MERGE): Define. (ELF_INFO_TYPE_EH_FRAME): Define. (ELF_INFO_TYPE_JUST_SYMS): Define. (STD_SECTION): Update struct sec initializer. * ecoff.c (bfd_debug_section): Likewise. * elf.c: Likewise. Update occurrences of sec_info_type and use_rela_p. * elflink.h: Likewise. * elf-eh-frame.c: Likewise. * elf64-alpha.c: Likewise. * elfxx-ia64.c: Likewise. * elfxx-mips.c: Likewise. * bfd-in2.h: Regenerate. * elf32-sparc.c (sec_do_relax): Use elf_section_data macro rather than referring to used_by_bfd. * elf64-sparc.c (sec_do_relax): Likewise. * elf64-mmix.c (mmix_elf_section_data): Likewise. * elfxx-mips.c (mips_elf_section_data): Likewise. * ieee.c (ieee_slurp_section_data): Use ieee_per_section macro. (ieee_get_section_contents): Likewise. (ieee_new_section_hook): Formatting. (ieee_canonicalize_reloc): Remove commented out code. * mmo.c (mmo_section_data): Define. Use throughout file. * oasys.c (oasys_get_section_contents): Use oasys_per_section macro. gas * config/obj-elf.c (obj_elf_change_section): Set SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD directly rather than using elf_linkonce_p.
2003-02-04 12:34:08 +00:00
2000, 2001, 2002, 2003
1999-05-03 07:29:11 +00:00
Free Software Foundation, Inc.
Written by Cygnus Support.
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 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. */
/*
SECTION
Sections
The raw data contained within a BFD is maintained through the
section abstraction. A single BFD may have any number of
sections. It keeps hold of them by pointing to the first;
each one points to the next in the list.
Sections are supported in BFD in <<section.c>>.
@menu
@* Section Input::
@* Section Output::
@* typedef asection::
@* section prototypes::
@end menu
INODE
Section Input, Section Output, Sections, Sections
SUBSECTION
Section input
When a BFD is opened for reading, the section structures are
created and attached to the BFD.
Each section has a name which describes the section in the
outside world---for example, <<a.out>> would contain at least
three sections, called <<.text>>, <<.data>> and <<.bss>>.
Names need not be unique; for example a COFF file may have several
sections named <<.data>>.
Sometimes a BFD will contain more than the ``natural'' number of
sections. A back end may attach other sections containing
constructor data, or an application may add a section (using
<<bfd_make_section>>) to the sections attached to an already open
BFD. For example, the linker creates an extra section
<<COMMON>> for each input file's BFD to hold information about
common storage.
The raw data is not necessarily read in when
the section descriptor is created. Some targets may leave the
data in place until a <<bfd_get_section_contents>> call is
made. Other back ends may read in all the data at once. For
example, an S-record file has to be read once to determine the
size of the data. An IEEE-695 file doesn't contain raw data in
sections, but data and relocation expressions intermixed, so
the data area has to be parsed to get out the data and
relocations.
INODE
Section Output, typedef asection, Section Input, Sections
SUBSECTION
Section output
To write a new object style BFD, the various sections to be
written have to be created. They are attached to the BFD in
the same way as input sections; data is written to the
sections using <<bfd_set_section_contents>>.
Any program that creates or combines sections (e.g., the assembler
and linker) must use the <<asection>> 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
(via <<output_section>> pointers) to
the output sections. The output section structure can be
considered a filter for the input section: the output section
determines the vma of the output data and the name, but the
input section determines the offset into the output section of
the data to be written.
E.g., to create a section "O", starting at 0x100, 0x123 long,
containing two subsections, "A" at offset 0x0 (i.e., at vma
0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the <<asection>>
structures would look like:
| section name "A"
| output_offset 0x00
| size 0x20
| output_section -----------> section name "O"
| | vma 0x100
| section name "B" | size 0x123
| output_offset 0x20 |
| size 0x103 |
| output_section --------|
SUBSECTION
Link orders
The data within a section is stored in a @dfn{link_order}.
These are much like the fixups in <<gas>>. The link_order
abstraction allows a section to grow and shrink within itself.
A link_order knows how big it is, and which is the next
link_order and where the raw data for it is; it also points to
a list of relocations which apply to it.
The link_order is used by the linker to perform relaxing on
final code. The compiler creates code which is as big as
necessary to make it work without relaxing, and the user can
select whether to relax. Sometimes relaxing takes a lot of
time. The linker runs around the relocations to see if any
are attached to data which can be shrunk, if so it does it on
a link_order by link_order basis.
*/
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "bfdlink.h"
/*
DOCDD
INODE
typedef asection, section prototypes, Section Output, Sections
SUBSECTION
typedef asection
Here is the section structure:
CODE_FRAGMENT
.
.{* This structure is used for a comdat section, as in PE. A comdat
. section is associated with a particular symbol. When the linker
. sees a comdat section, it keeps only one of the sections with a
. given name and associated with a given symbol. *}
.
.struct bfd_comdat_info
.{
. {* The name of the symbol associated with a comdat section. *}
. const char *name;
.
. {* The local symbol table index of the symbol associated with a
. comdat section. This is only meaningful to the object file format
. specific code; it is not an index into the list returned by
. bfd_canonicalize_symtab. *}
. long symbol;
.};
.
.typedef struct bfd_section
1999-05-03 07:29:11 +00:00
.{
. {* The name of the section; the name isn't a copy, the pointer is
. the same as that passed to bfd_make_section. *}
. const char *name;
.
. {* A unique sequence number. *}
. int id;
1999-05-03 07:29:11 +00:00
.
. {* Which section in the bfd; 0..n-1 as sections are created in a bfd. *}
. int index;
1999-05-03 07:29:11 +00:00
.
. {* The next section in the list belonging to the BFD, or NULL. *}
. struct bfd_section *next;
1999-05-03 07:29:11 +00:00
.
. {* The field flags contains attributes of the section. Some
. flags are read in from the object file, and some are
. synthesized from other information. *}
. flagword flags;
1999-05-03 07:29:11 +00:00
.
.#define SEC_NO_FLAGS 0x000
.
. {* Tells the OS to allocate space for this section when loading.
. This is clear for a section containing debug information only. *}
1999-05-03 07:29:11 +00:00
.#define SEC_ALLOC 0x001
.
. {* Tells the OS to load the section from the file when loading.
. This is clear for a .bss section. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LOAD 0x002
.
. {* The section contains data still to be relocated, so there is
. some relocation information too. *}
1999-05-03 07:29:11 +00:00
.#define SEC_RELOC 0x004
.
. {* ELF reserves 4 processor specific bits and 8 operating system
. specific bits in sh_flags; at present we can get away with just
. one in communicating between the assembler and BFD, but this
. isn't a good long-term solution. *}
.#define SEC_ARCH_BIT_0 0x008
1999-05-03 07:29:11 +00:00
.
. {* A signal to the OS that the section contains read only data. *}
1999-05-03 07:29:11 +00:00
.#define SEC_READONLY 0x010
.
. {* The section contains code only. *}
1999-05-03 07:29:11 +00:00
.#define SEC_CODE 0x020
.
. {* The section contains data only. *}
1999-05-03 07:29:11 +00:00
.#define SEC_DATA 0x040
.
. {* The section will reside in ROM. *}
1999-05-03 07:29:11 +00:00
.#define SEC_ROM 0x080
.
. {* The section contains constructor information. This section
. type is used by the linker to create lists of constructors and
. destructors used by <<g++>>. When a back end sees a symbol
. which should be used in a constructor list, it creates a new
. section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
. the symbol to it, and builds a relocation. To build the lists
. of constructors, all the linker has to do is catenate all the
. sections called <<__CTOR_LIST__>> and relocate the data
. contained within - exactly the operations it would peform on
. standard data. *}
1999-05-03 07:29:11 +00:00
.#define SEC_CONSTRUCTOR 0x100
.
. {* The section has contents - a data section could be
. <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
. <<SEC_HAS_CONTENTS>> *}
1999-05-03 07:29:11 +00:00
.#define SEC_HAS_CONTENTS 0x200
.
. {* An instruction to the linker to not output the section
. even if it has information which would normally be written. *}
1999-05-03 07:29:11 +00:00
.#define SEC_NEVER_LOAD 0x400
.
. {* The section is a COFF shared library section. This flag is
. only for the linker. If this type of section appears in
. the input file, the linker must copy it to the output file
. without changing the vma or size. FIXME: Although this
. was originally intended to be general, it really is COFF
. specific (and the flag was renamed to indicate this). It
. might be cleaner to have some more general mechanism to
. allow the back end to control what the linker does with
. sections. *}
1999-05-03 07:29:11 +00:00
.#define SEC_COFF_SHARED_LIBRARY 0x800
.
* elf.c (_bfd_elf_make_section_from_shdr): Set SEC_THREAD_LOCAL for symbols from SHF_TLS section. (_bfd_elf_print_private_bfd_data): Add PT_TLS. (elf_fake_sections): Set SHF_TLS for SEC_THREAD_LOCAL sections. (map_sections_to_segments): Build PT_TLS segment if necessary. (assign_file_positions_for_segments): Likewise. (get_program_header_size): Account for PT_TLS segment. (swap_out_syms): Set type of BSF_THREAD_LOCAL symbols and symbols from SEC_THREAD_LOCAL sections to STT_TLS. * reloc.c: Add 386 and IA-64 TLS relocs. * section.c (SEC_THREAD_LOCAL): Define. (SEC_CONSTRUCTOR_TEXT, SEC_CONSTRUCTOR_DATA, SEC_CONSTRUCTOR_BSS): Remove. * elflink.h (elf_link_add_object_symbols): Support .tcommon. (size_dynamic_sections): If DF_STATIC_TLS, set DF_FLAGS unconditionally. (struct elf_final_link_info): Add first_tls_sec. (elf_bfd_final_link): Set first_tls_sec. Compute elf_hash_table (info)->tls_segment. (elf_link_output_extsym): Handle STT_TLS symbols. (elf_link_input_bfd): Likewise. * syms.c (BSF_THREAD_LOCAL): Define. * bfd-in2.h: Rebuilt. * libbfd.h: Rebuilt. * elf32-i386.c (elf_i386_tls_transition, dtpoff_base, tpoff, elf_i386_mkobject, elf_i386_object_p): New functions. (elf_howto_table): Add TLS relocs. (elf_i386_reloc_type_lookup): Support TLS relocs. (elf_i386_info_to_howto_rel): Likewise. (struct elf_i386_link_hash_entry): Add tls_type. (struct elf_i386_obj_tdata): New. (elf_i386_hash_entry, elf_i386_tdata, elf_i386_local_got_tls_type): New macros. (struct elf_i386_link_hash_table): Add tls_ldm_got. (link_hash_newfunc): Clear tls_type. (elf_i386_check_relocs): Support TLS relocs. (elf_i386_gc_sweep_hook): Likewise. (allocate_dynrelocs): Likewise. (elf_i386_size_dynamic_sections): Likewise. (elf_i386_relocate_section): Likewise. (elf_i386_finish_dynamic_symbol): Likewise. (bfd_elf32_mkobject, elf_backend_object_p): Define. * elfxx-ia64.c (struct elfNN_ia64_dyn_sym_info): Add tprel_offset, dtpmod_offset, dtprel_offset, tprel_done, dtpmod_done, dtprel_done, want_tprel, want_dtpmod, want_dtprel. (elfNN_ia64_tprel_base, elfNN_ia64_dtprel_base): New functions. (ia64_howto_table): Add TLS relocs, rename R_IA64_LTOFF_TP22 to R_IA64_LTOFF_TPREL22. (elf_code_to_howto_index): Add TLS relocs. (elfNN_ia64_check_relocs): Support TLS relocs. (allocate_global_data_got): Account for TLS .got data. (allocate_dynrel_entries): Account for TLS dynamic relocations. (elfNN_ia64_install_value): Supprt TLS relocs. (set_got_entry): Support TLS relocs. (elfNN_ia64_relocate_section): Likewise. * config/obj-elf.c (elf_common): Renamed from obj_elf_common. (obj_elf_common): Call elf_common. (obj_elf_tls_common): New function. (elf_pseudo_tab): Support .tls_common. (special_sections): Add .tdata and .tbss. (obj_elf_change_section): Set SEC_THREAD_LOCAL for SHF_TLS sections. (obj_elf_parse_section_letters): Support T in section flags (SHF_TLS). (obj_elf_parse_section_letters): Include T in error message. * config/tc-ppc.c (ppc_section_letter): Likewise. * config/tc-alpha.c (alpha_elf_section_letter): Likewise. (tc_gen_reloc): Handle SEC_THREAD_LOCAL the same way as SEC_MERGE. * config/tc-sparc.c (md_apply_fix3): Likewise. * config/tc-i386.c (tc_i386_fix_adjustable): Add TLS relocs. Define them if not BFD_ASSEMBLER. (lex_got): Support @TLSGD, @TLSLDM, @GOTTPOFF, @TPOFF, @DTPOFF and @NTPOFF. (md_apply_fix3): Add TLS relocs. * config/tc-ia64.c (enum reloc_func): Add FUNC_DTP_MODULE, FUNC_DTP_RELATIVE, FUNC_TP_RELATIVE, FUNC_LT_DTP_MODULE, FUNC_LT_DTP_RELATIVE, FUNC_LT_TP_RELATIVE. (pseudo_func): Support @dtpmod(), @dtprel() and @tprel(). (ia64_elf_section_letter): Include T in error message. (md_begin): Support TLS operators. (md_operand): Likewise. (ia64_gen_real_reloc_type): Support TLS relocs. * testsuite/gas/i386/tlspic.s: New file. * testsuite/gas/i386/tlsd.s: New file. * testsuite/gas/i386/tlsnopic.s: New file. * testsuite/gas/i386/tlsd.d: New file. * testsuite/gas/i386/tlsnopic.d: New file. * testsuite/gas/i386/tlspic.d: New file. * testsuite/gas/i386/i386.exp: Add tlsd, tlsnopic and tlspic tests. * testsuite/gas/ia64/tls.s: New file. * testsuite/gas/ia64/tls.d: New file. * testsuite/gas/ia64/ia64.exp: Add tls test. * write.c (adjust_reloc_syms): Don't change symbols in SEC_THREAD_LOCAL sections to STT_SECTION + addend. * elf/common.h (PT_TLS, SHF_TLS, STT_TLS, DF_STATIC_TLS): Define. * elf/ia64.h (R_IA64_LTOFF_TPREL22): Renamed from R_IA64_LTOFF_TP22. * elf/i386.h: Add TLS relocs. * scripttempl/elf.sc: Add .rel{,a}.t{bss,data}, .tdata and .tbss. * ldlang.c (lang_add_section): Set SEC_THREAD_LOCAL for output section if necessary. Handle .tbss. (lang_size_sections): Clear _raw_size for .tbss section (it allocates space in PT_TLS segment only). * ldwrite.c (build_link_order): Build link order for .tbss too. * readelf.c (get_segment_type): Add PT_TLS. (get_elf_section_flags): Add SHF_TLS. (get_dynamic_flags): Optimize. Add DF_STATIC_TLS. (process_dynamic_segment): Use puts instead of printf. (get_symbol_type): Support STT_TLS. * objdump.c (dump_section_header): Remove SEC_CONSTRUCTOR_TEXT, SEC_CONSTRUCTOR_DATA, SEC_CONSTRUCTOR_BSS. Add SEC_THREAD_LOCAL.
2002-05-23 13:12:53 +00:00
. {* The section contains thread local data. *}
.#define SEC_THREAD_LOCAL 0x1000
.
. {* The section has GOT references. This flag is only for the
. linker, and is currently only used by the elf32-hppa back end.
. It will be set if global offset table references were detected
. in this section, which indicate to the linker that the section
. contains PIC code, and must be handled specially when doing a
. static link. *}
.#define SEC_HAS_GOT_REF 0x4000
.
. {* The section contains common symbols (symbols may be defined
. multiple times, the value of a symbol is the amount of
. space it requires, and the largest symbol value is the one
. used). Most targets have exactly one of these (which we
. translate to bfd_com_section_ptr), but ECOFF has two. *}
1999-05-03 07:29:11 +00:00
.#define SEC_IS_COMMON 0x8000
.
. {* The section contains only debugging information. For
. example, this is set for ELF .debug and .stab sections.
. strip tests this flag to see if a section can be
. discarded. *}
1999-05-03 07:29:11 +00:00
.#define SEC_DEBUGGING 0x10000
.
. {* The contents of this section are held in memory pointed to
. by the contents field. This is checked by bfd_get_section_contents,
. and the data is retrieved from memory if appropriate. *}
1999-05-03 07:29:11 +00:00
.#define SEC_IN_MEMORY 0x20000
.
. {* The contents of this section are to be excluded by the
. linker for executable and shared objects unless those
. objects are to be further relocated. *}
1999-05-03 07:29:11 +00:00
.#define SEC_EXCLUDE 0x40000
.
. {* The contents of this section are to be sorted based on the sum of
. the symbol and addend values specified by the associated relocation
. entries. Entries without associated relocation entries will be
. appended to the end of the section in an unspecified order. *}
1999-05-03 07:29:11 +00:00
.#define SEC_SORT_ENTRIES 0x80000
.
. {* When linking, duplicate sections of the same name should be
. discarded, rather than being combined into a single section as
. is usually done. This is similar to how common symbols are
. handled. See SEC_LINK_DUPLICATES below. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINK_ONCE 0x100000
.
. {* If SEC_LINK_ONCE is set, this bitfield describes how the linker
. should handle duplicate sections. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINK_DUPLICATES 0x600000
.
. {* This value for SEC_LINK_DUPLICATES means that duplicate
. sections with the same name should simply be discarded. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINK_DUPLICATES_DISCARD 0x0
.
. {* This value for SEC_LINK_DUPLICATES means that the linker
. should warn if there are any duplicate sections, although
. it should still only link one copy. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINK_DUPLICATES_ONE_ONLY 0x200000
.
. {* This value for SEC_LINK_DUPLICATES means that the linker
. should warn if any duplicate sections are a different size. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINK_DUPLICATES_SAME_SIZE 0x400000
.
. {* This value for SEC_LINK_DUPLICATES means that the linker
. should warn if any duplicate sections contain different
. contents. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINK_DUPLICATES_SAME_CONTENTS 0x600000
.
. {* This section was created by the linker as part of dynamic
. relocation or other arcane processing. It is skipped when
. going through the first-pass output, trusting that someone
. else up the line will take care of it later. *}
1999-05-03 07:29:11 +00:00
.#define SEC_LINKER_CREATED 0x800000
.
. {* This section should not be subject to garbage collection. *}
1999-05-03 07:29:11 +00:00
.#define SEC_KEEP 0x1000000
.
. {* This section contains "short" data, and should be placed
. "near" the GP. *}
.#define SEC_SMALL_DATA 0x2000000
.
. {* This section contains data which may be shared with other
. executables or shared objects. *}
.#define SEC_SHARED 0x4000000
.
. {* When a section with this flag is being linked, then if the size of
. the input section is less than a page, it should not cross a page
. boundary. If the size of the input section is one page or more, it
. should be aligned on a page boundary. *}
.#define SEC_BLOCK 0x8000000
.
. {* Conditionally link this section; do not link if there are no
. references found to any symbol in the section. *}
.#define SEC_CLINK 0x10000000
.
. {* Attempt to merge identical entities in the section.
. Entity size is given in the entsize field. *}
.#define SEC_MERGE 0x20000000
.
. {* If given with SEC_MERGE, entities to merge are zero terminated
. strings where entsize specifies character size instead of fixed
. size entries. *}
.#define SEC_STRINGS 0x40000000
.
. {* This section contains data about section groups. *}
.#define SEC_GROUP 0x80000000
.
. {* End of section flags. *}
1999-05-03 07:29:11 +00:00
.
. {* Some internal packed boolean fields. *}
1999-05-03 07:29:11 +00:00
.
. {* See the vma field. *}
. unsigned int user_set_vma : 1;
1999-05-03 07:29:11 +00:00
.
. {* Whether relocations have been processed. *}
. unsigned int reloc_done : 1;
1999-05-03 07:29:11 +00:00
.
. {* A mark flag used by some of the linker backends. *}
. unsigned int linker_mark : 1;
1999-05-03 07:29:11 +00:00
.
. {* Another mark flag used by some of the linker backends. Set for
. output sections that have an input section. *}
. unsigned int linker_has_input : 1;
.
. {* A mark flag used by some linker backends for garbage collection. *}
. unsigned int gc_mark : 1;
1999-05-03 07:29:11 +00:00
.
bfd * elf-bfd.h (enum elf_link_info_type): Remove. (struct bfd_elf_section_data): Move sec_info_type, use_rela_p fields to struct sec. Remove linkonce_p field. (elf_linkonce_p): Delete. (elf_discarded_section): Update for sec_info_type change. * section.c (struct sec): Add sec_info_type, use_rela_p, has_tls_reloc, flag11, flag12, flag13, flag14, flag15, flag16, flag20, flag24. (ELF_INFO_TYPE_NONE): Define. (ELF_INFO_TYPE_STABS): Define. (ELF_INFO_TYPE_MERGE): Define. (ELF_INFO_TYPE_EH_FRAME): Define. (ELF_INFO_TYPE_JUST_SYMS): Define. (STD_SECTION): Update struct sec initializer. * ecoff.c (bfd_debug_section): Likewise. * elf.c: Likewise. Update occurrences of sec_info_type and use_rela_p. * elflink.h: Likewise. * elf-eh-frame.c: Likewise. * elf64-alpha.c: Likewise. * elfxx-ia64.c: Likewise. * elfxx-mips.c: Likewise. * bfd-in2.h: Regenerate. * elf32-sparc.c (sec_do_relax): Use elf_section_data macro rather than referring to used_by_bfd. * elf64-sparc.c (sec_do_relax): Likewise. * elf64-mmix.c (mmix_elf_section_data): Likewise. * elfxx-mips.c (mips_elf_section_data): Likewise. * ieee.c (ieee_slurp_section_data): Use ieee_per_section macro. (ieee_get_section_contents): Likewise. (ieee_new_section_hook): Formatting. (ieee_canonicalize_reloc): Remove commented out code. * mmo.c (mmo_section_data): Define. Use throughout file. * oasys.c (oasys_get_section_contents): Use oasys_per_section macro. gas * config/obj-elf.c (obj_elf_change_section): Set SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD directly rather than using elf_linkonce_p.
2003-02-04 12:34:08 +00:00
. {* The following flags are used by the ELF linker. *}
.
. {* Mark sections which have been allocated to segments. *}
. unsigned int segment_mark : 1;
.
bfd * elf-bfd.h (enum elf_link_info_type): Remove. (struct bfd_elf_section_data): Move sec_info_type, use_rela_p fields to struct sec. Remove linkonce_p field. (elf_linkonce_p): Delete. (elf_discarded_section): Update for sec_info_type change. * section.c (struct sec): Add sec_info_type, use_rela_p, has_tls_reloc, flag11, flag12, flag13, flag14, flag15, flag16, flag20, flag24. (ELF_INFO_TYPE_NONE): Define. (ELF_INFO_TYPE_STABS): Define. (ELF_INFO_TYPE_MERGE): Define. (ELF_INFO_TYPE_EH_FRAME): Define. (ELF_INFO_TYPE_JUST_SYMS): Define. (STD_SECTION): Update struct sec initializer. * ecoff.c (bfd_debug_section): Likewise. * elf.c: Likewise. Update occurrences of sec_info_type and use_rela_p. * elflink.h: Likewise. * elf-eh-frame.c: Likewise. * elf64-alpha.c: Likewise. * elfxx-ia64.c: Likewise. * elfxx-mips.c: Likewise. * bfd-in2.h: Regenerate. * elf32-sparc.c (sec_do_relax): Use elf_section_data macro rather than referring to used_by_bfd. * elf64-sparc.c (sec_do_relax): Likewise. * elf64-mmix.c (mmix_elf_section_data): Likewise. * elfxx-mips.c (mips_elf_section_data): Likewise. * ieee.c (ieee_slurp_section_data): Use ieee_per_section macro. (ieee_get_section_contents): Likewise. (ieee_new_section_hook): Formatting. (ieee_canonicalize_reloc): Remove commented out code. * mmo.c (mmo_section_data): Define. Use throughout file. * oasys.c (oasys_get_section_contents): Use oasys_per_section macro. gas * config/obj-elf.c (obj_elf_change_section): Set SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD directly rather than using elf_linkonce_p.
2003-02-04 12:34:08 +00:00
. {* Type of sec_info information. *}
. unsigned int sec_info_type:3;
.#define ELF_INFO_TYPE_NONE 0
.#define ELF_INFO_TYPE_STABS 1
.#define ELF_INFO_TYPE_MERGE 2
.#define ELF_INFO_TYPE_EH_FRAME 3
.#define ELF_INFO_TYPE_JUST_SYMS 4
.
. {* Nonzero if this section uses RELA relocations, rather than REL. *}
. unsigned int use_rela_p:1;
.
. {* Bits used by various backends. *}
. unsigned int has_tls_reloc:1;
.
. {* Nonzero if this section needs the relax finalize pass. *}
. unsigned int need_finalize_relax:1;
.
* elf64-ppc.c: Move TARGET_LITTLE_SYM and other macros used by elfxx-target.h so that we can use elf_backend_got_header_size. (ELF_MACHINE_ALT1, ELF_MACHINE_ALT2): Delete. (GLINK_CALL_STUB_SIZE): Modify. Define new glink call stub and associated macros. (ppc64_elf_howto_raw <GOT_TPREL16_DS, GOT_TPREL16_LO_DS>): Correct dst_mask. (enum ppc_stub_type): Add ppc_stub_long_branch_r2off and ppc_stub_plt_branch_r2off. (struct ppc_stub_hash_entry): Reorganize. (struct ppc_link_hash_table): Add no_multi_toc, multi_toc_needed, toc_curr, toc_off and emit_stub_syms. (ppc64_elf_link_hash_table_create): Init them. (ppc_stub_name): Correct string size. (ppc64_elf_check_relocs): Set has_gp_reloc on GOT and TOC relocs. (ppc64_elf_size_dynamic_sections): Set no_multi_toc if GOT entries used. (ppc_type_of_stub): Tweak root.type test. (build_plt_stub): Remove glink code. Adjust for insn macro changes. (ppc_size_one_stub): Handle ppc_stub_long_branch_r2off and ppc_stub_plt_branch_r2off. (ppc_build_one_stub): Likewise. Fix var shadowing. Correct addis,addi range test. Use toc_off to calculte r2 values. Handle emit_stub_syms. (ppc64_elf_setup_section_lists): Remove htab creator flavour test. Initialize elf_gp and toc_curr. (ppc64_elf_next_toc_section, ppc64_elf_reinit_toc): New functions. (ppc64_elf_next_input_section): Set toc_off. (group_sections): Ensure groups have the same TOC. (ppc64_elf_size_stubs): Check whether we need a TOC adjusting stub. (ppc64_elf_build_stubs): Add emit_stub_syms param, and stash in htab. Build new glink stub. (ppc64_elf_relocate_section): Handle multiple TOCs. Fix comments. (ppc64_elf_finish_dynamic_sections): Adjust DT_PPC64_GLINK. * elf64-ppc.h (ppc64_elf_build_stubs): Update prototype. (ppc64_elf_next_toc_section, ppc64_elf_reinit_toc): Declare. * section.c (struct sec): Rename flag12 to has_gp_reloc. (STD_SECTION): Update. * ecoff.c (bfd_debug_section): Update comment. * bfd-in2.h: Regenerate.
2003-06-08 14:06:38 +00:00
. {* Nonzero if this section has a gp reloc. *}
. unsigned int has_gp_reloc:1;
.
. {* Unused bits. *}
bfd * elf-bfd.h (enum elf_link_info_type): Remove. (struct bfd_elf_section_data): Move sec_info_type, use_rela_p fields to struct sec. Remove linkonce_p field. (elf_linkonce_p): Delete. (elf_discarded_section): Update for sec_info_type change. * section.c (struct sec): Add sec_info_type, use_rela_p, has_tls_reloc, flag11, flag12, flag13, flag14, flag15, flag16, flag20, flag24. (ELF_INFO_TYPE_NONE): Define. (ELF_INFO_TYPE_STABS): Define. (ELF_INFO_TYPE_MERGE): Define. (ELF_INFO_TYPE_EH_FRAME): Define. (ELF_INFO_TYPE_JUST_SYMS): Define. (STD_SECTION): Update struct sec initializer. * ecoff.c (bfd_debug_section): Likewise. * elf.c: Likewise. Update occurrences of sec_info_type and use_rela_p. * elflink.h: Likewise. * elf-eh-frame.c: Likewise. * elf64-alpha.c: Likewise. * elfxx-ia64.c: Likewise. * elfxx-mips.c: Likewise. * bfd-in2.h: Regenerate. * elf32-sparc.c (sec_do_relax): Use elf_section_data macro rather than referring to used_by_bfd. * elf64-sparc.c (sec_do_relax): Likewise. * elf64-mmix.c (mmix_elf_section_data): Likewise. * elfxx-mips.c (mips_elf_section_data): Likewise. * ieee.c (ieee_slurp_section_data): Use ieee_per_section macro. (ieee_get_section_contents): Likewise. (ieee_new_section_hook): Formatting. (ieee_canonicalize_reloc): Remove commented out code. * mmo.c (mmo_section_data): Define. Use throughout file. * oasys.c (oasys_get_section_contents): Use oasys_per_section macro. gas * config/obj-elf.c (obj_elf_change_section): Set SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD directly rather than using elf_linkonce_p.
2003-02-04 12:34:08 +00:00
. unsigned int flag13:1;
. unsigned int flag14:1;
. unsigned int flag15:1;
. unsigned int flag16:4;
. unsigned int flag20:4;
. unsigned int flag24:8;
.
. {* End of internal packed boolean fields. *}
1999-05-03 07:29:11 +00:00
.
. {* The virtual memory address of the section - where it will be
. at run time. The symbols are relocated against this. The
. user_set_vma flag is maintained by bfd; if it's not set, the
. backend can assign addresses (for example, in <<a.out>>, where
. the default address for <<.data>> is dependent on the specific
. target and various flags). *}
. bfd_vma vma;
1999-05-03 07:29:11 +00:00
.
. {* The load address of the section - where it would be in a
. rom image; really only used for writing section header
2002-01-30 18:12:17 +00:00
. information. *}
. bfd_vma lma;
1999-05-03 07:29:11 +00:00
.
. {* The size of the section in octets, as it will be output.
. Contains a value even if the section has no contents (e.g., the
. size of <<.bss>>). This will be filled in after relocation. *}
. bfd_size_type _cooked_size;
1999-05-03 07:29:11 +00:00
.
. {* The original size on disk of the section, in octets. Normally this
. value is the same as the size, but if some relaxing has
. been done, then this value will be bigger. *}
. bfd_size_type _raw_size;
1999-05-03 07:29:11 +00:00
.
. {* If this section is going to be output, then this value is the
. offset in *bytes* into the output section of the first byte in the
. input section (byte ==> smallest addressable unit on the
. target). In most cases, if this was going to start at the
. 100th octet (8-bit quantity) in the output section, this value
. would be 100. However, if the target byte size is 16 bits
. (bfd_octets_per_byte is "2"), this value would be 50. *}
. bfd_vma output_offset;
1999-05-03 07:29:11 +00:00
.
. {* The output section through which to map on output. *}
. struct bfd_section *output_section;
1999-05-03 07:29:11 +00:00
.
. {* The alignment requirement of the section, as an exponent of 2 -
. e.g., 3 aligns to 2^3 (or 8). *}
. unsigned int alignment_power;
1999-05-03 07:29:11 +00:00
.
. {* If an input section, a pointer to a vector of relocation
. records for the data in this section. *}
. struct reloc_cache_entry *relocation;
1999-05-03 07:29:11 +00:00
.
. {* If an output section, a pointer to a vector of pointers to
. relocation records for the data in this section. *}
. struct reloc_cache_entry **orelocation;
1999-05-03 07:29:11 +00:00
.
2002-01-30 18:12:17 +00:00
. {* The number of relocation records in one of the above. *}
. unsigned reloc_count;
1999-05-03 07:29:11 +00:00
.
. {* Information below is back end specific - and not always used
. or updated. *}
1999-05-03 07:29:11 +00:00
.
. {* File position of section data. *}
. file_ptr filepos;
1999-05-03 07:29:11 +00:00
.
. {* File position of relocation info. *}
. file_ptr rel_filepos;
1999-05-03 07:29:11 +00:00
.
. {* File position of line data. *}
. file_ptr line_filepos;
1999-05-03 07:29:11 +00:00
.
. {* Pointer to data for applications. *}
2003-06-29 10:06:40 +00:00
. void *userdata;
1999-05-03 07:29:11 +00:00
.
. {* If the SEC_IN_MEMORY flag is set, this points to the actual
. contents. *}
. unsigned char *contents;
1999-05-03 07:29:11 +00:00
.
. {* Attached line number information. *}
. alent *lineno;
1999-05-03 07:29:11 +00:00
.
. {* Number of line number records. *}
. unsigned int lineno_count;
1999-05-03 07:29:11 +00:00
.
. {* Entity size for merging purposes. *}
. unsigned int entsize;
.
. {* Optional information about a COMDAT entry; NULL if not COMDAT. *}
. struct bfd_comdat_info *comdat;
.
. {* Points to the kept section if this section is a link-once section,
. and is discarded. *}
. struct bfd_section *kept_section;
.
. {* When a section is being output, this value changes as more
. linenumbers are written out. *}
. file_ptr moving_line_filepos;
1999-05-03 07:29:11 +00:00
.
. {* What the section number is in the target world. *}
. int target_index;
1999-05-03 07:29:11 +00:00
.
2003-06-29 10:06:40 +00:00
. void *used_by_bfd;
1999-05-03 07:29:11 +00:00
.
. {* If this is a constructor section then here is a list of the
. relocations created to relocate items within it. *}
. struct relent_chain *constructor_chain;
1999-05-03 07:29:11 +00:00
.
. {* The BFD which owns the section. *}
. bfd *owner;
1999-05-03 07:29:11 +00:00
.
2002-01-30 18:12:17 +00:00
. {* A symbol which points at this section only. *}
. struct bfd_symbol *symbol;
. struct bfd_symbol **symbol_ptr_ptr;
1999-05-03 07:29:11 +00:00
.
. struct bfd_link_order *link_order_head;
. struct bfd_link_order *link_order_tail;
2002-01-30 18:12:17 +00:00
.} asection;
1999-05-03 07:29:11 +00:00
.
.{* These sections are global, and are managed by BFD. The application
. and target back end are not permitted to change the values in
. these sections. New code should use the section_ptr macros rather
. than referring directly to the const sections. The const sections
. may eventually vanish. *}
1999-05-03 07:29:11 +00:00
.#define BFD_ABS_SECTION_NAME "*ABS*"
.#define BFD_UND_SECTION_NAME "*UND*"
.#define BFD_COM_SECTION_NAME "*COM*"
.#define BFD_IND_SECTION_NAME "*IND*"
.
2002-01-30 18:12:17 +00:00
.{* The absolute section. *}
bfd/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * elf-bfd.h (bfd_elf_special_section): New. (elf_backend_data): Add special_sections, a pointer to bfd_elf_special_section. (elf_section_type). New. (elf_section_flags): New. (_bfd_elf_get_sec_type_attr): New. * elf.c (_bfd_elf_make_section_from_shdr): Always use the real section type/flags. (special_sections): New. (get_special_section): New. (_bfd_elf_get_sec_type_attr): New. (_bfd_elf_new_section_hook): Check special_section to set elf_section_type and elf_section_flags. (elf_fake_sections): Don't use section name to set ELF section data. * elf32-m32r.c (m32r_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-m68hc11.c (elf32_m68hc11_special_sections): New. (elf_backend_special_sections): Defined. * elf32-mcore.c (mcore_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-ppc.c (ppc_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-sh64.c (sh64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-v850.c (v850_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-xtensa.c (elf_xtensa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-alpha.c (elf64_alpha_special_sections): New. (elf_backend_special_sections): Defined. * elf64-hppa.c (elf64_hppa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-ppc.c (ppc64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf64-sh64.c (sh64_elf64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-ia64.c (elfNN_ia64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-mips.c (_bfd_mips_elf_special_sections): New. * elfxx-mips.h (_bfd_mips_elf_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-target.h (elf_backend_special_sections): New. Default to NULL. (elfNN_bed): Initialize special_sections. * section.c (bfd_abs_section): Remove const. (bfd_und_section): Likewise. (bfd_com_section): Likewise. (bfd_ind_section): Likewise. gas/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * config/obj-elf.c (special_sections): Removed. (obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set elf_section_type and elf_section_flags. (elf_frob_file): Set SHT_GROUP. * config/obj-elf.h (obj_sec_set_private_data): New. * config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed. * config/tc-ia64.h: Likewise. * config/tc-m32r.h: Likewise. * config/tc-m68hc11.h: Likewise. * config/tc-mcore.h: Likewise. * config/tc-mips.h: Likewise. * config/tc-ppc.h: Likewise. * config/tc-sh64.h: Likewise. * config/tc-v850.h: Likewise. * config/tc-xtensa.h: Likewise. * config/tc-v850.h (SHF_V850_GPREL): Removed. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise. * subsegs.c (subseg_get): Call obj_sec_set_private_data if it is defined. include/elf/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * v850.h (SHF_V850_GPREL): New. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise.
2003-07-25 14:35:56 +00:00
.extern asection bfd_abs_section;
1999-05-03 07:29:11 +00:00
.#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
.#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
2002-01-30 18:12:17 +00:00
.{* Pointer to the undefined section. *}
bfd/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * elf-bfd.h (bfd_elf_special_section): New. (elf_backend_data): Add special_sections, a pointer to bfd_elf_special_section. (elf_section_type). New. (elf_section_flags): New. (_bfd_elf_get_sec_type_attr): New. * elf.c (_bfd_elf_make_section_from_shdr): Always use the real section type/flags. (special_sections): New. (get_special_section): New. (_bfd_elf_get_sec_type_attr): New. (_bfd_elf_new_section_hook): Check special_section to set elf_section_type and elf_section_flags. (elf_fake_sections): Don't use section name to set ELF section data. * elf32-m32r.c (m32r_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-m68hc11.c (elf32_m68hc11_special_sections): New. (elf_backend_special_sections): Defined. * elf32-mcore.c (mcore_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-ppc.c (ppc_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-sh64.c (sh64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-v850.c (v850_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-xtensa.c (elf_xtensa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-alpha.c (elf64_alpha_special_sections): New. (elf_backend_special_sections): Defined. * elf64-hppa.c (elf64_hppa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-ppc.c (ppc64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf64-sh64.c (sh64_elf64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-ia64.c (elfNN_ia64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-mips.c (_bfd_mips_elf_special_sections): New. * elfxx-mips.h (_bfd_mips_elf_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-target.h (elf_backend_special_sections): New. Default to NULL. (elfNN_bed): Initialize special_sections. * section.c (bfd_abs_section): Remove const. (bfd_und_section): Likewise. (bfd_com_section): Likewise. (bfd_ind_section): Likewise. gas/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * config/obj-elf.c (special_sections): Removed. (obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set elf_section_type and elf_section_flags. (elf_frob_file): Set SHT_GROUP. * config/obj-elf.h (obj_sec_set_private_data): New. * config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed. * config/tc-ia64.h: Likewise. * config/tc-m32r.h: Likewise. * config/tc-m68hc11.h: Likewise. * config/tc-mcore.h: Likewise. * config/tc-mips.h: Likewise. * config/tc-ppc.h: Likewise. * config/tc-sh64.h: Likewise. * config/tc-v850.h: Likewise. * config/tc-xtensa.h: Likewise. * config/tc-v850.h (SHF_V850_GPREL): Removed. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise. * subsegs.c (subseg_get): Call obj_sec_set_private_data if it is defined. include/elf/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * v850.h (SHF_V850_GPREL): New. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise.
2003-07-25 14:35:56 +00:00
.extern asection bfd_und_section;
1999-05-03 07:29:11 +00:00
.#define bfd_und_section_ptr ((asection *) &bfd_und_section)
.#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
2002-01-30 18:12:17 +00:00
.{* Pointer to the common section. *}
bfd/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * elf-bfd.h (bfd_elf_special_section): New. (elf_backend_data): Add special_sections, a pointer to bfd_elf_special_section. (elf_section_type). New. (elf_section_flags): New. (_bfd_elf_get_sec_type_attr): New. * elf.c (_bfd_elf_make_section_from_shdr): Always use the real section type/flags. (special_sections): New. (get_special_section): New. (_bfd_elf_get_sec_type_attr): New. (_bfd_elf_new_section_hook): Check special_section to set elf_section_type and elf_section_flags. (elf_fake_sections): Don't use section name to set ELF section data. * elf32-m32r.c (m32r_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-m68hc11.c (elf32_m68hc11_special_sections): New. (elf_backend_special_sections): Defined. * elf32-mcore.c (mcore_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-ppc.c (ppc_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-sh64.c (sh64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-v850.c (v850_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-xtensa.c (elf_xtensa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-alpha.c (elf64_alpha_special_sections): New. (elf_backend_special_sections): Defined. * elf64-hppa.c (elf64_hppa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-ppc.c (ppc64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf64-sh64.c (sh64_elf64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-ia64.c (elfNN_ia64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-mips.c (_bfd_mips_elf_special_sections): New. * elfxx-mips.h (_bfd_mips_elf_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-target.h (elf_backend_special_sections): New. Default to NULL. (elfNN_bed): Initialize special_sections. * section.c (bfd_abs_section): Remove const. (bfd_und_section): Likewise. (bfd_com_section): Likewise. (bfd_ind_section): Likewise. gas/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * config/obj-elf.c (special_sections): Removed. (obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set elf_section_type and elf_section_flags. (elf_frob_file): Set SHT_GROUP. * config/obj-elf.h (obj_sec_set_private_data): New. * config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed. * config/tc-ia64.h: Likewise. * config/tc-m32r.h: Likewise. * config/tc-m68hc11.h: Likewise. * config/tc-mcore.h: Likewise. * config/tc-mips.h: Likewise. * config/tc-ppc.h: Likewise. * config/tc-sh64.h: Likewise. * config/tc-v850.h: Likewise. * config/tc-xtensa.h: Likewise. * config/tc-v850.h (SHF_V850_GPREL): Removed. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise. * subsegs.c (subseg_get): Call obj_sec_set_private_data if it is defined. include/elf/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * v850.h (SHF_V850_GPREL): New. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise.
2003-07-25 14:35:56 +00:00
.extern asection bfd_com_section;
1999-05-03 07:29:11 +00:00
.#define bfd_com_section_ptr ((asection *) &bfd_com_section)
2002-01-30 18:12:17 +00:00
.{* Pointer to the indirect section. *}
bfd/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * elf-bfd.h (bfd_elf_special_section): New. (elf_backend_data): Add special_sections, a pointer to bfd_elf_special_section. (elf_section_type). New. (elf_section_flags): New. (_bfd_elf_get_sec_type_attr): New. * elf.c (_bfd_elf_make_section_from_shdr): Always use the real section type/flags. (special_sections): New. (get_special_section): New. (_bfd_elf_get_sec_type_attr): New. (_bfd_elf_new_section_hook): Check special_section to set elf_section_type and elf_section_flags. (elf_fake_sections): Don't use section name to set ELF section data. * elf32-m32r.c (m32r_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-m68hc11.c (elf32_m68hc11_special_sections): New. (elf_backend_special_sections): Defined. * elf32-mcore.c (mcore_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-ppc.c (ppc_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-sh64.c (sh64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-v850.c (v850_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-xtensa.c (elf_xtensa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-alpha.c (elf64_alpha_special_sections): New. (elf_backend_special_sections): Defined. * elf64-hppa.c (elf64_hppa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-ppc.c (ppc64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf64-sh64.c (sh64_elf64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-ia64.c (elfNN_ia64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-mips.c (_bfd_mips_elf_special_sections): New. * elfxx-mips.h (_bfd_mips_elf_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-target.h (elf_backend_special_sections): New. Default to NULL. (elfNN_bed): Initialize special_sections. * section.c (bfd_abs_section): Remove const. (bfd_und_section): Likewise. (bfd_com_section): Likewise. (bfd_ind_section): Likewise. gas/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * config/obj-elf.c (special_sections): Removed. (obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set elf_section_type and elf_section_flags. (elf_frob_file): Set SHT_GROUP. * config/obj-elf.h (obj_sec_set_private_data): New. * config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed. * config/tc-ia64.h: Likewise. * config/tc-m32r.h: Likewise. * config/tc-m68hc11.h: Likewise. * config/tc-mcore.h: Likewise. * config/tc-mips.h: Likewise. * config/tc-ppc.h: Likewise. * config/tc-sh64.h: Likewise. * config/tc-v850.h: Likewise. * config/tc-xtensa.h: Likewise. * config/tc-v850.h (SHF_V850_GPREL): Removed. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise. * subsegs.c (subseg_get): Call obj_sec_set_private_data if it is defined. include/elf/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * v850.h (SHF_V850_GPREL): New. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise.
2003-07-25 14:35:56 +00:00
.extern asection bfd_ind_section;
1999-05-03 07:29:11 +00:00
.#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
.#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
.
2001-11-19 15:35:38 +00:00
.#define bfd_is_const_section(SEC) \
. ( ((SEC) == bfd_abs_section_ptr) \
. || ((SEC) == bfd_und_section_ptr) \
. || ((SEC) == bfd_com_section_ptr) \
. || ((SEC) == bfd_ind_section_ptr))
.
.extern const struct bfd_symbol * const bfd_abs_symbol;
.extern const struct bfd_symbol * const bfd_com_symbol;
.extern const struct bfd_symbol * const bfd_und_symbol;
.extern const struct bfd_symbol * const bfd_ind_symbol;
1999-05-03 07:29:11 +00:00
.#define bfd_get_section_size_before_reloc(section) \
. ((section)->_raw_size)
1999-05-03 07:29:11 +00:00
.#define bfd_get_section_size_after_reloc(section) \
. ((section)->reloc_done ? (section)->_cooked_size \
. : (abort (), (bfd_size_type) 1))
.
.{* Macros to handle insertion and deletion of a bfd's sections. These
. only handle the list pointers, ie. do not adjust section_count,
. target_index etc. *}
.#define bfd_section_list_remove(ABFD, PS) \
. do \
. { \
. asection **_ps = PS; \
. asection *_s = *_ps; \
. *_ps = _s->next; \
. if (_s->next == NULL) \
. (ABFD)->section_tail = _ps; \
. } \
. while (0)
.#define bfd_section_list_insert(ABFD, PS, S) \
. do \
. { \
. asection **_ps = PS; \
. asection *_s = S; \
. _s->next = *_ps; \
. *_ps = _s; \
. if (_s->next == NULL) \
. (ABFD)->section_tail = &_s->next; \
. } \
. while (0)
.
1999-05-03 07:29:11 +00:00
*/
/* We use a macro to initialize the static asymbol structures because
traditional C does not permit us to initialize a union member while
gcc warns if we don't initialize it. */
/* the_bfd, name, value, attr, section [, udata] */
#ifdef __STDC__
#define GLOBAL_SYM_INIT(NAME, SECTION) \
{ 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION, { 0 }}
#else
#define GLOBAL_SYM_INIT(NAME, SECTION) \
{ 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION }
#endif
1999-05-03 07:29:11 +00:00
/* These symbols are global, not specific to any BFD. Therefore, anything
that tries to change them is broken, and should be repaired. */
1999-05-03 07:29:11 +00:00
static const asymbol global_syms[] =
{
GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, &bfd_com_section),
GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, &bfd_und_section),
GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, &bfd_abs_section),
GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, &bfd_ind_section)
1999-05-03 07:29:11 +00:00
};
#define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX) \
const asymbol * const SYM = (asymbol *) &global_syms[IDX]; \
bfd/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * elf-bfd.h (bfd_elf_special_section): New. (elf_backend_data): Add special_sections, a pointer to bfd_elf_special_section. (elf_section_type). New. (elf_section_flags): New. (_bfd_elf_get_sec_type_attr): New. * elf.c (_bfd_elf_make_section_from_shdr): Always use the real section type/flags. (special_sections): New. (get_special_section): New. (_bfd_elf_get_sec_type_attr): New. (_bfd_elf_new_section_hook): Check special_section to set elf_section_type and elf_section_flags. (elf_fake_sections): Don't use section name to set ELF section data. * elf32-m32r.c (m32r_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-m68hc11.c (elf32_m68hc11_special_sections): New. (elf_backend_special_sections): Defined. * elf32-mcore.c (mcore_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-ppc.c (ppc_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-sh64.c (sh64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-v850.c (v850_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf32-xtensa.c (elf_xtensa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-alpha.c (elf64_alpha_special_sections): New. (elf_backend_special_sections): Defined. * elf64-hppa.c (elf64_hppa_special_sections): New. (elf_backend_special_sections): Defined. * elf64-ppc.c (ppc64_elf_special_sections): New. (elf_backend_special_sections): Defined. * elf64-sh64.c (sh64_elf64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-ia64.c (elfNN_ia64_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-mips.c (_bfd_mips_elf_special_sections): New. * elfxx-mips.h (_bfd_mips_elf_special_sections): New. (elf_backend_special_sections): Defined. * elfxx-target.h (elf_backend_special_sections): New. Default to NULL. (elfNN_bed): Initialize special_sections. * section.c (bfd_abs_section): Remove const. (bfd_und_section): Likewise. (bfd_com_section): Likewise. (bfd_ind_section): Likewise. gas/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * config/obj-elf.c (special_sections): Removed. (obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set elf_section_type and elf_section_flags. (elf_frob_file): Set SHT_GROUP. * config/obj-elf.h (obj_sec_set_private_data): New. * config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed. * config/tc-ia64.h: Likewise. * config/tc-m32r.h: Likewise. * config/tc-m68hc11.h: Likewise. * config/tc-mcore.h: Likewise. * config/tc-mips.h: Likewise. * config/tc-ppc.h: Likewise. * config/tc-sh64.h: Likewise. * config/tc-v850.h: Likewise. * config/tc-xtensa.h: Likewise. * config/tc-v850.h (SHF_V850_GPREL): Removed. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise. * subsegs.c (subseg_get): Call obj_sec_set_private_data if it is defined. include/elf/ 2003-07-25 H.J. Lu <hongjiu.lu@intel.com> * v850.h (SHF_V850_GPREL): New. (SHF_V850_EPREL): Likewise. (SHF_V850_R0REL): Likewise.
2003-07-25 14:35:56 +00:00
asection SEC = \
2000-07-10 02:05:40 +00:00
/* name, id, index, next, flags, user_set_vma, reloc_done, */ \
{ NAME, IDX, 0, NULL, FLAGS, 0, 0, \
\
/* linker_mark, linker_has_input, gc_mark, segment_mark, */ \
0, 0, 1, 0, \
\
* elf64-ppc.c: Move TARGET_LITTLE_SYM and other macros used by elfxx-target.h so that we can use elf_backend_got_header_size. (ELF_MACHINE_ALT1, ELF_MACHINE_ALT2): Delete. (GLINK_CALL_STUB_SIZE): Modify. Define new glink call stub and associated macros. (ppc64_elf_howto_raw <GOT_TPREL16_DS, GOT_TPREL16_LO_DS>): Correct dst_mask. (enum ppc_stub_type): Add ppc_stub_long_branch_r2off and ppc_stub_plt_branch_r2off. (struct ppc_stub_hash_entry): Reorganize. (struct ppc_link_hash_table): Add no_multi_toc, multi_toc_needed, toc_curr, toc_off and emit_stub_syms. (ppc64_elf_link_hash_table_create): Init them. (ppc_stub_name): Correct string size. (ppc64_elf_check_relocs): Set has_gp_reloc on GOT and TOC relocs. (ppc64_elf_size_dynamic_sections): Set no_multi_toc if GOT entries used. (ppc_type_of_stub): Tweak root.type test. (build_plt_stub): Remove glink code. Adjust for insn macro changes. (ppc_size_one_stub): Handle ppc_stub_long_branch_r2off and ppc_stub_plt_branch_r2off. (ppc_build_one_stub): Likewise. Fix var shadowing. Correct addis,addi range test. Use toc_off to calculte r2 values. Handle emit_stub_syms. (ppc64_elf_setup_section_lists): Remove htab creator flavour test. Initialize elf_gp and toc_curr. (ppc64_elf_next_toc_section, ppc64_elf_reinit_toc): New functions. (ppc64_elf_next_input_section): Set toc_off. (group_sections): Ensure groups have the same TOC. (ppc64_elf_size_stubs): Check whether we need a TOC adjusting stub. (ppc64_elf_build_stubs): Add emit_stub_syms param, and stash in htab. Build new glink stub. (ppc64_elf_relocate_section): Handle multiple TOCs. Fix comments. (ppc64_elf_finish_dynamic_sections): Adjust DT_PPC64_GLINK. * elf64-ppc.h (ppc64_elf_build_stubs): Update prototype. (ppc64_elf_next_toc_section, ppc64_elf_reinit_toc): Declare. * section.c (struct sec): Rename flag12 to has_gp_reloc. (STD_SECTION): Update. * ecoff.c (bfd_debug_section): Update comment. * bfd-in2.h: Regenerate.
2003-06-08 14:06:38 +00:00
/* sec_info_type, use_rela_p, has_tls_reloc, */ \
0, 0, 0, \
\
/* need_finalize_relax, has_gp_reloc, */ \
0, 0, \
bfd * elf-bfd.h (enum elf_link_info_type): Remove. (struct bfd_elf_section_data): Move sec_info_type, use_rela_p fields to struct sec. Remove linkonce_p field. (elf_linkonce_p): Delete. (elf_discarded_section): Update for sec_info_type change. * section.c (struct sec): Add sec_info_type, use_rela_p, has_tls_reloc, flag11, flag12, flag13, flag14, flag15, flag16, flag20, flag24. (ELF_INFO_TYPE_NONE): Define. (ELF_INFO_TYPE_STABS): Define. (ELF_INFO_TYPE_MERGE): Define. (ELF_INFO_TYPE_EH_FRAME): Define. (ELF_INFO_TYPE_JUST_SYMS): Define. (STD_SECTION): Update struct sec initializer. * ecoff.c (bfd_debug_section): Likewise. * elf.c: Likewise. Update occurrences of sec_info_type and use_rela_p. * elflink.h: Likewise. * elf-eh-frame.c: Likewise. * elf64-alpha.c: Likewise. * elfxx-ia64.c: Likewise. * elfxx-mips.c: Likewise. * bfd-in2.h: Regenerate. * elf32-sparc.c (sec_do_relax): Use elf_section_data macro rather than referring to used_by_bfd. * elf64-sparc.c (sec_do_relax): Likewise. * elf64-mmix.c (mmix_elf_section_data): Likewise. * elfxx-mips.c (mips_elf_section_data): Likewise. * ieee.c (ieee_slurp_section_data): Use ieee_per_section macro. (ieee_get_section_contents): Likewise. (ieee_new_section_hook): Formatting. (ieee_canonicalize_reloc): Remove commented out code. * mmo.c (mmo_section_data): Define. Use throughout file. * oasys.c (oasys_get_section_contents): Use oasys_per_section macro. gas * config/obj-elf.c (obj_elf_change_section): Set SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD directly rather than using elf_linkonce_p.
2003-02-04 12:34:08 +00:00
\
/* flag13, flag14, flag15, flag16, flag20, flag24, */ \
0, 0, 0, 0, 0, 0, \
\
/* vma, lma, _cooked_size, _raw_size, */ \
0, 0, 0, 0, \
\
/* output_offset, output_section, alignment_power, */ \
0, (struct bfd_section *) &SEC, 0, \
\
/* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \
NULL, NULL, 0, 0, 0, \
\
/* line_filepos, userdata, contents, lineno, lineno_count, */ \
0, NULL, NULL, NULL, 0, \
\
/* entsize, comdat, kept_section, moving_line_filepos, */ \
0, NULL, NULL, 0, \
\
/* target_index, used_by_bfd, constructor_chain, owner, */ \
0, NULL, NULL, NULL, \
\
/* symbol, */ \
(struct bfd_symbol *) &global_syms[IDX], \
\
/* symbol_ptr_ptr, */ \
(struct bfd_symbol **) &SYM, \
\
/* link_order_head, link_order_tail */ \
NULL, NULL \
}
1999-05-03 07:29:11 +00:00
STD_SECTION (bfd_com_section, SEC_IS_COMMON, bfd_com_symbol,
BFD_COM_SECTION_NAME, 0);
STD_SECTION (bfd_und_section, 0, bfd_und_symbol, BFD_UND_SECTION_NAME, 1);
STD_SECTION (bfd_abs_section, 0, bfd_abs_symbol, BFD_ABS_SECTION_NAME, 2);
STD_SECTION (bfd_ind_section, 0, bfd_ind_symbol, BFD_IND_SECTION_NAME, 3);
#undef STD_SECTION
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
struct section_hash_entry
{
struct bfd_hash_entry root;
asection section;
};
/* Initialize an entry in the section hash table. */
struct bfd_hash_entry *
2003-06-29 10:06:40 +00:00
bfd_section_hash_newfunc (struct bfd_hash_entry *entry,
struct bfd_hash_table *table,
const char *string)
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
{
/* Allocate the structure if it has not already been allocated by a
subclass. */
if (entry == NULL)
{
* aoutx.h (NAME(aout,swap_ext_reloc_in)): Cast bytes->r_index to unsigned int. Cast RELOC_BASE10, RELOC_BASE13 and RELOC_BASE22 to unsigned int. (NAME(aout,final_link)): Cast enum used in assignment. (aout_link_write_symbols): Cast enums in comparisons, int values to boolean, enums in assignments to int. (aout_link_input_section_std): Cast rel->r_index to unsigned int. (aout_link_input_section_ext): Likewise. Cast enums used in comparisons with unsigned ints. (aout_link_reloc_link_order): Cast enum to int in assignment. * archive.c (_bfd_generic_read_ar_hdr_mag): Cast result of memchr calls to char *. * bfd-in.h (bfd_set_section_vma): Cast enum true to unsigned int in assignment. * bfd-in2.h (bfd_set_section_vma): Likewise. * bfd.c (bfd_record_phdr): Cast enums in assignments. * binary.c (bfd_alloc): Cast enum to long. * coffgen.c (_bfd_coff_is_local_label_name): Cast return to boolean. * dwarf2.c (read_abbrevs): Add casts to enum types. (read_attribute_value): Likewise. (arange_add): Cast result of bfd_zalloc call. (comp_unit_contains_address): Return true and false. (comp_unit_find_nearest_line): Cast return to boolean. * format.c (bfd_check_format_matches, bfd_set_format): Likewise. * gen-aout.c: define macro '_' if not defined. * libbfd.c (bfd_realloc): Cast malloc and realloc to PTR. (bfd_bwrite): Cast bfd_realloc to bfd_byte *. (bfd_write_bigendian_4byte_int): Cast return to boolean. (bfd_seek): Cast bfd_realloc to bfd_byte *. (bfd_generic_is_local_label_name): Cast return to boolean. * libcoff.h (_bfd_coff_adjust_symndx): Remove extraneous '\'. * linker.c (_bfd_link_hash_newfunc): Cast bfd_hash_allocate result to struct bfd_hash_entry *. (_bfd_generic_link_hash_newfunc): likewise. (_bfd_generic_final_link): Cast enum to unsigned int. * merge.c (sec_merge_emit): Cast return to boolean. (merge_strings): Add casts to const unsigned char *. * reloc.c (bfd_get_reloc_code_name): Cast enums in comparison to int. (bfd_generic_get_relocated_section_content): Cast enum to unsigned int. * section.c (bfd_section_hash_newfunc): Cast bfd_hash_allocate result to struct bfd_hash_entry *. (bfd_set_section_content): Add cast to PTR in comparison. * simple.c (simple_dummy_warning, simple_dummy_undefined_symbol, simple_dummy_reloc_overflow, simple_dummy_reloc_dangerous, simple_dummy_unattached_reloc, bfd_simple_get_relocated_section_contents): Add K&R declarations and function definitions. * srec.c (S3Forced): Initialize to false. (srec_get_symtab): Cast return value from bfd_alloc to asymbol *. * stabs.c (_bfd_link_section_stabs): Cast enum to int in comparisons. (_bfd_discard_section_stabs): Likewise. Also cast return to boolean. * syms.c (bfd_is_undefined_symclass): Cast return to boolean. (_bfd_stab_section_find_nearest_line): Cast enum to bfd_byte in comparisons.
2002-10-25 02:45:54 +00:00
entry = (struct bfd_hash_entry *)
bfd_hash_allocate (table, sizeof (struct section_hash_entry));
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (entry == NULL)
return entry;
}
/* Call the allocation method of the superclass. */
entry = bfd_hash_newfunc (entry, table, string);
if (entry != NULL)
2003-06-29 10:06:40 +00:00
memset (&((struct section_hash_entry *) entry)->section, 0,
sizeof (asection));
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
return entry;
}
#define section_hash_lookup(table, string, create, copy) \
((struct section_hash_entry *) \
bfd_hash_lookup ((table), (string), (create), (copy)))
/* Initializes a new section. NEWSECT->NAME is already set. */
static asection *
2003-06-29 10:06:40 +00:00
bfd_section_init (bfd *abfd, asection *newsect)
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
{
static int section_id = 0x10; /* id 0 to 3 used by STD_SECTION. */
newsect->id = section_id;
newsect->index = abfd->section_count;
newsect->owner = abfd;
/* Create a symbol whose 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);
if (newsect->symbol == NULL)
return NULL;
newsect->symbol->name = newsect->name;
newsect->symbol->value = 0;
newsect->symbol->section = newsect;
newsect->symbol->flags = BSF_SECTION_SYM;
newsect->symbol_ptr_ptr = &newsect->symbol;
if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect)))
return NULL;
section_id++;
abfd->section_count++;
*abfd->section_tail = newsect;
abfd->section_tail = &newsect->next;
return newsect;
}
1999-05-03 07:29:11 +00:00
/*
DOCDD
INODE
section prototypes, , typedef asection, Sections
SUBSECTION
Section prototypes
These are the functions exported by the section handling part of BFD.
*/
/*
FUNCTION
bfd_section_list_clear
SYNOPSIS
void bfd_section_list_clear (bfd *);
DESCRIPTION
Clears the section list, and also resets the section count and
hash table entries.
*/
void
2003-06-29 10:06:40 +00:00
bfd_section_list_clear (bfd *abfd)
{
abfd->sections = NULL;
abfd->section_tail = &abfd->sections;
abfd->section_count = 0;
2003-06-29 10:06:40 +00:00
memset (abfd->section_htab.table, 0,
abfd->section_htab.size * sizeof (struct bfd_hash_entry *));
}
1999-05-03 07:29:11 +00:00
/*
FUNCTION
bfd_get_section_by_name
SYNOPSIS
2003-06-29 10:06:40 +00:00
asection *bfd_get_section_by_name (bfd *abfd, const char *name);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Run through @var{abfd} and return the one of the
<<asection>>s whose name matches @var{name}, otherwise <<NULL>>.
@xref{Sections}, for more information.
This should only be used in special cases; the normal way to process
all sections of a given name is to use <<bfd_map_over_sections>> and
<<strcmp>> on the name (or better yet, base it on the section flags
or something else) for each section.
*/
asection *
2003-06-29 10:06:40 +00:00
bfd_get_section_by_name (bfd *abfd, const char *name)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
struct section_hash_entry *sh;
sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (sh != NULL)
return &sh->section;
1999-05-03 07:29:11 +00:00
return NULL;
}
/*
FUNCTION
bfd_get_unique_section_name
SYNOPSIS
2003-06-29 10:06:40 +00:00
char *bfd_get_unique_section_name
(bfd *abfd, const char *templat, int *count);
DESCRIPTION
Invent a section name that is unique in @var{abfd} by tacking
a dot and a digit suffix onto the original @var{templat}. If
@var{count} is non-NULL, then it specifies the first number
tried as a suffix to generate a unique name. The value
pointed to by @var{count} will be incremented in this case.
*/
char *
2003-06-29 10:06:40 +00:00
bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count)
{
int num;
unsigned int len;
char *sname;
len = strlen (templat);
2003-06-29 10:06:40 +00:00
sname = bfd_malloc (len + 8);
2000-09-20 04:20:26 +00:00
if (sname == NULL)
return NULL;
2002-06-25 09:40:45 +00:00
memcpy (sname, templat, len);
num = 1;
if (count != NULL)
num = *count;
do
{
/* If we have a million sections, something is badly wrong. */
if (num > 999999)
abort ();
sprintf (sname + len, ".%d", num++);
}
while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE));
if (count != NULL)
*count = num;
return sname;
}
1999-05-03 07:29:11 +00:00
/*
FUNCTION
bfd_make_section_old_way
SYNOPSIS
2003-06-29 10:06:40 +00:00
asection *bfd_make_section_old_way (bfd *abfd, const char *name);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Create a new empty section called @var{name}
and attach it to the end of the chain of sections for the
BFD @var{abfd}. An attempt to create a section with a name which
is already in use returns its pointer without changing the
section chain.
It has the funny name since this is the way it used to be
before it was rewritten....
Possible errors are:
o <<bfd_error_invalid_operation>> -
If output has already started for this BFD.
o <<bfd_error_no_memory>> -
If memory allocation fails.
*/
asection *
2003-06-29 10:06:40 +00:00
bfd_make_section_old_way (bfd *abfd, const char *name)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
struct section_hash_entry *sh;
asection *newsect;
if (abfd->output_has_begun)
{
bfd_set_error (bfd_error_invalid_operation);
return NULL;
}
if (strcmp (name, BFD_ABS_SECTION_NAME) == 0)
return bfd_abs_section_ptr;
if (strcmp (name, BFD_COM_SECTION_NAME) == 0)
return bfd_com_section_ptr;
if (strcmp (name, BFD_UND_SECTION_NAME) == 0)
return bfd_und_section_ptr;
if (strcmp (name, BFD_IND_SECTION_NAME) == 0)
return bfd_ind_section_ptr;
sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (sh == NULL)
return NULL;
newsect = &sh->section;
if (newsect->name != NULL)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
/* Section already exists. */
return newsect;
1999-05-03 07:29:11 +00:00
}
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
newsect->name = name;
return bfd_section_init (abfd, newsect);
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
bfd_make_section_anyway
SYNOPSIS
2003-06-29 10:06:40 +00:00
asection *bfd_make_section_anyway (bfd *abfd, const char *name);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Create a new empty section called @var{name} and attach it to the end of
the chain of sections for @var{abfd}. Create a new section even if there
is already a section with that name.
Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
o <<bfd_error_no_memory>> - If memory allocation fails.
*/
sec_ptr
2003-06-29 10:06:40 +00:00
bfd_make_section_anyway (bfd *abfd, const char *name)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
struct section_hash_entry *sh;
1999-05-03 07:29:11 +00:00
asection *newsect;
if (abfd->output_has_begun)
{
bfd_set_error (bfd_error_invalid_operation);
return NULL;
}
sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (sh == NULL)
1999-05-03 07:29:11 +00:00
return NULL;
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
newsect = &sh->section;
if (newsect->name != NULL)
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
/* We are making a section of the same name. It can't go in
section_htab without generating a unique section name and
that would be pointless; We don't need to traverse the
hash table. */
2003-06-29 10:06:40 +00:00
newsect = bfd_zalloc (abfd, sizeof (asection));
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (newsect == NULL)
return NULL;
1999-05-03 07:29:11 +00:00
}
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
newsect->name = name;
return bfd_section_init (abfd, newsect);
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
bfd_make_section
SYNOPSIS
2003-06-29 10:06:40 +00:00
asection *bfd_make_section (bfd *, const char *name);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling
bfd_set_error ()) without changing the section chain if there is already a
section named @var{name}. If there is an error, return <<NULL>> and set
<<bfd_error>>.
*/
asection *
2003-06-29 10:06:40 +00:00
bfd_make_section (bfd *abfd, const char *name)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
struct section_hash_entry *sh;
asection *newsect;
1999-05-03 07:29:11 +00:00
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (abfd->output_has_begun)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
bfd_set_error (bfd_error_invalid_operation);
return NULL;
1999-05-03 07:29:11 +00:00
}
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (strcmp (name, BFD_ABS_SECTION_NAME) == 0
|| strcmp (name, BFD_COM_SECTION_NAME) == 0
|| strcmp (name, BFD_UND_SECTION_NAME) == 0
|| strcmp (name, BFD_IND_SECTION_NAME) == 0)
return NULL;
1999-05-03 07:29:11 +00:00
sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE);
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
if (sh == NULL)
return NULL;
newsect = &sh->section;
if (newsect->name != NULL)
1999-05-03 07:29:11 +00:00
{
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
/* Section already exists. */
return NULL;
1999-05-03 07:29:11 +00:00
}
hash bfd sections for fast lookup and create. bfd/ChangeLog * bfd.c (struct _bfd): Add section_htab, section_tail. * libbfd-in.h (_bfd_delete_bfd): Declare. (bfd_section_hash_newfunc): Declare. * opncls.c (_bfd_new_bfd): Free memory on failure. Init section_htab and section_tail. (_bfd_delete_bfd): New function. (bfd_openr): Use it. (bfd_fdopenr): Likewise. (bfd_openstreamr): Likewise. (bfd_openw): Likewise. (bfd_close): Likewise. (bfd_close_all_done): Likewise. (bfd_release): Comment. * section.c (struct section_hash_entry): New. (bfd_section_hash_newfunc): New function. (section_hash_lookup): Define. (bfd_section_init): New function, split out from bfd_make_section_anyway. (bfd_get_section_by_name): Lookup via hash table. (bfd_get_unique_section_name): Likewise. (bfd_make_section_old_way): Rewrite to use hash table. (bfd_make_section_anyway): Likewise. (bfd_make_section): Likewise. Return NULL for attempts to make BFD_{ABS,COM,UND,IND}_SECTION_NAME. (_bfd_strip_section_from_output): Adjust section_tail if needed. * configure.in: Bump bfd version. * configure: Regenerate. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. ld/ChangeLog * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Adjust section_tail when fiddling with section list. (gld${EMULATION_NAME}_list_options): Ensure sentences aren't broken into separate strings to make translation easier. * emultempl/mmo.em (mmo_place_orphan): Adjust section_tail when fiddling with section list. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
2001-12-17 00:40:53 +00:00
newsect->name = name;
return bfd_section_init (abfd, newsect);
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
bfd_set_section_flags
SYNOPSIS
2003-06-29 10:06:40 +00:00
bfd_boolean bfd_set_section_flags
(bfd *abfd, asection *sec, flagword flags);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Set the attributes of the section @var{sec} in the BFD
@var{abfd} to the value @var{flags}. Return <<TRUE>> on success,
<<FALSE>> on error. Possible error returns are:
1999-05-03 07:29:11 +00:00
o <<bfd_error_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.
*/
bfd_boolean
2003-06-29 10:06:40 +00:00
bfd_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
sec_ptr section,
flagword flags)
1999-05-03 07:29:11 +00:00
{
#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_set_error (bfd_error_invalid_operation);
return FALSE;
1999-05-03 07:29:11 +00:00
}
#endif
section->flags = flags;
return TRUE;
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
bfd_map_over_sections
SYNOPSIS
2003-06-29 10:06:40 +00:00
void bfd_map_over_sections
(bfd *abfd,
void (*func) (bfd *abfd, asection *sect, void *obj),
void *obj);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Call the provided function @var{func} for each section
attached to the BFD @var{abfd}, passing @var{obj} as an
argument. The function will be called as if by
2003-06-29 10:06:40 +00:00
| func (abfd, the_section, obj);
1999-05-03 07:29:11 +00:00
This is the preferred method for iterating over sections; an
1999-05-03 07:29:11 +00:00
alternative would be to use a loop:
| section *p;
| for (p = abfd->sections; p != NULL; p = p->next)
2003-06-29 10:06:40 +00:00
| func (abfd, p, ...)
1999-05-03 07:29:11 +00:00
*/
void
2003-06-29 10:06:40 +00:00
bfd_map_over_sections (bfd *abfd,
void (*operation) (bfd *, asection *, void *),
void *user_storage)
1999-05-03 07:29:11 +00:00
{
asection *sect;
unsigned int i = 0;
for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
(*operation) (abfd, sect, user_storage);
if (i != abfd->section_count) /* Debugging */
abort ();
}
/*
FUNCTION
bfd_set_section_size
SYNOPSIS
2003-06-29 10:06:40 +00:00
bfd_boolean bfd_set_section_size
(bfd *abfd, asection *sec, bfd_size_type val);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Set @var{sec} to the size @var{val}. If the operation is
ok, then <<TRUE>> is returned, else <<FALSE>>.
1999-05-03 07:29:11 +00:00
Possible error returns:
o <<bfd_error_invalid_operation>> -
Writing has started to the BFD, so setting the size is invalid.
*/
bfd_boolean
2003-06-29 10:06:40 +00:00
bfd_set_section_size (bfd *abfd, sec_ptr ptr, bfd_size_type val)
1999-05-03 07:29:11 +00:00
{
/* Once you've started writing to any section you cannot create or change
the size of any others. */
1999-05-03 07:29:11 +00:00
if (abfd->output_has_begun)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
1999-05-03 07:29:11 +00:00
}
ptr->_cooked_size = val;
ptr->_raw_size = val;
return TRUE;
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
bfd_set_section_contents
SYNOPSIS
2003-06-29 10:06:40 +00:00
bfd_boolean bfd_set_section_contents
(bfd *abfd, asection *section, const void *data,
file_ptr offset, bfd_size_type count);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Sets the contents of the section @var{section} in BFD
@var{abfd} to the data starting in memory at @var{data}. The
data is written to the output section starting at offset
2000-01-13 22:10:36 +00:00
@var{offset} for @var{count} octets.
1999-05-03 07:29:11 +00:00
Normally <<TRUE>> is returned, else <<FALSE>>. Possible error
1999-05-03 07:29:11 +00:00
returns are:
o <<bfd_error_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
This routine is front end to the back end function
<<_bfd_set_section_contents>>.
*/
2003-06-29 10:06:40 +00:00
#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))
1999-05-03 07:29:11 +00:00
bfd_boolean
2003-06-29 10:06:40 +00:00
bfd_set_section_contents (bfd *abfd,
sec_ptr section,
const void *location,
2003-06-29 10:06:40 +00:00
file_ptr offset,
bfd_size_type count)
1999-05-03 07:29:11 +00:00
{
bfd_size_type sz;
if (!(bfd_get_section_flags (abfd, section) & SEC_HAS_CONTENTS))
{
bfd_set_error (bfd_error_no_contents);
return FALSE;
1999-05-03 07:29:11 +00:00
}
sz = bfd_get_section_size_now (abfd, section);
if ((bfd_size_type) offset > sz
|| count > sz
|| offset + count > sz
|| count != (size_t) count)
1999-05-03 07:29:11 +00:00
{
bfd_set_error (bfd_error_bad_value);
return FALSE;
1999-05-03 07:29:11 +00:00
}
switch (abfd->direction)
{
case read_direction:
case no_direction:
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
1999-05-03 07:29:11 +00:00
case write_direction:
break;
case both_direction:
/* File is opened for update. `output_has_begun' some time ago when
the file was created. Do not recompute sections sizes or alignments
in _bfd_set_section_content. */
abfd->output_has_begun = TRUE;
1999-05-03 07:29:11 +00:00
break;
}
/* Record a copy of the data in memory if desired. */
if (section->contents
2003-06-29 10:06:40 +00:00
&& location != section->contents + offset)
memcpy (section->contents + offset, location, (size_t) count);
1999-05-03 07:29:11 +00:00
if (BFD_SEND (abfd, _bfd_set_section_contents,
(abfd, section, location, offset, count)))
{
abfd->output_has_begun = TRUE;
return TRUE;
1999-05-03 07:29:11 +00:00
}
return FALSE;
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
bfd_get_section_contents
SYNOPSIS
2003-06-29 10:06:40 +00:00
bfd_boolean bfd_get_section_contents
(bfd *abfd, asection *section, void *location, file_ptr offset,
bfd_size_type count);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Read data from @var{section} in BFD @var{abfd}
into memory starting at @var{location}. The data is read at an
offset of @var{offset} from the start of the input section,
and is read for @var{count} bytes.
If the contents of a constructor with the <<SEC_CONSTRUCTOR>>
flag set are requested or if the section does not have the
<<SEC_HAS_CONTENTS>> flag set, then the @var{location} is filled
with zeroes. If no errors occur, <<TRUE>> is returned, else
<<FALSE>>.
1999-05-03 07:29:11 +00:00
*/
bfd_boolean
2003-06-29 10:06:40 +00:00
bfd_get_section_contents (bfd *abfd,
sec_ptr section,
void *location,
file_ptr offset,
bfd_size_type count)
1999-05-03 07:29:11 +00:00
{
bfd_size_type sz;
if (section->flags & SEC_CONSTRUCTOR)
{
memset (location, 0, (size_t) count);
return TRUE;
1999-05-03 07:29:11 +00:00
}
/* Even if reloc_done is TRUE, this function reads unrelocated
contents, so we want the raw size. */
sz = section->_raw_size;
if ((bfd_size_type) offset > sz
|| count > sz
|| offset + count > sz
|| count != (size_t) count)
1999-05-03 07:29:11 +00:00
{
bfd_set_error (bfd_error_bad_value);
return FALSE;
1999-05-03 07:29:11 +00:00
}
if (count == 0)
/* Don't bother. */
return TRUE;
1999-05-03 07:29:11 +00:00
if ((section->flags & SEC_HAS_CONTENTS) == 0)
{
memset (location, 0, (size_t) count);
return TRUE;
1999-05-03 07:29:11 +00:00
}
if ((section->flags & SEC_IN_MEMORY) != 0)
{
memcpy (location, section->contents + offset, (size_t) count);
return TRUE;
1999-05-03 07:29:11 +00:00
}
return BFD_SEND (abfd, _bfd_get_section_contents,
(abfd, section, location, offset, count));
}
/*
FUNCTION
bfd_copy_private_section_data
SYNOPSIS
2003-06-29 10:06:40 +00:00
bfd_boolean bfd_copy_private_section_data
(bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Copy private section information from @var{isec} in the BFD
@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
Return <<TRUE>> on success, <<FALSE>> on error. Possible error
1999-05-03 07:29:11 +00:00
returns are:
o <<bfd_error_no_memory>> -
Not enough memory exists to create private data for @var{osec}.
.#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
. BFD_SEND (obfd, _bfd_copy_private_section_data, \
. (ibfd, isection, obfd, osection))
*/
/*
FUNCTION
_bfd_strip_section_from_output
SYNOPSIS
void _bfd_strip_section_from_output
2003-06-29 10:06:40 +00:00
(struct bfd_link_info *info, asection *section);
1999-05-03 07:29:11 +00:00
DESCRIPTION
Remove @var{section} from the output. If the output section
becomes empty, remove it from the output bfd.
This function won't actually do anything except twiddle flags
if called too late in the linking process, when it's not safe
to remove sections.
1999-05-03 07:29:11 +00:00
*/
void
2003-06-29 10:06:40 +00:00
_bfd_strip_section_from_output (struct bfd_link_info *info, asection *s)
1999-05-03 07:29:11 +00:00
{
asection *os;
asection *is;
bfd *abfd;
1999-05-03 07:29:11 +00:00
s->flags |= SEC_EXCLUDE;
/* If the section wasn't assigned to an output section, or the
section has been discarded by the linker script, there's nothing
more to do. */
1999-05-03 07:29:11 +00:00
os = s->output_section;
if (os == NULL || os->owner == NULL)
return;
/* If the output section has other (non-excluded) input sections, we
can't remove it. */
for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next)
for (is = abfd->sections; is != NULL; is = is->next)
if (is->output_section == os && (is->flags & SEC_EXCLUDE) == 0)
return;
/* If the output section is empty, flag it for removal too.
See ldlang.c:strip_excluded_output_sections for the action. */
os->flags |= SEC_EXCLUDE;
1999-05-03 07:29:11 +00:00
}
/*
FUNCTION
* bfd-in.h: Remove "taken from the source" comment. * libbfd-in.h: Likewise. * libcoff-in.h: Likewise. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * libcoff.h: Regenerate. * elf.c (bfd_elf_discard_group): Return true. * elf-bfd.h (bfd_elf_discard_group): Declare. * bfd-in.h (bfd_elf_discard_group): Don't declare here. * section.c (bfd_discard_group): Rename to bfd_generic_discard_group. * bfd.c (bfd_discard_group): Define. * targets.c (struct bfd_target): Add _bfd_discard_group. (BFD_JUMP_TABLE_LINK): Here too. * libbfd-in.h (_bfd_nolink_bfd_discard_group): Define. * aout-adobe.c (aout_32_bfd_discard_group): Define. * aout-target.h (MY_bfd_discard_group): Define. * aout-tic30.c (MY_bfd_discard_group): Define. * binary.c (binary_bfd_discard_group): Define. * bout.c (b_out_bfd_discard_group): Define. * coff-alpha.c (_bfd_ecoff_bfd_discard_group): Define. * coffcode.h (coff_bfd_discard_group): Define. * coff-mips.c (_bfd_ecoff_bfd_discard_group): Define. * elfxx-target.h (bfd_elfNN_bfd_discard_group): Define. * i386msdos.c (msdos_bfd_discard_group): Define. * i386os9k.c (os9k_bfd_discard_group): Define. * ieee.c (ieee_bfd_discard_group): Define. * ihex.c (ihex_bfd_discard_group): Define. * mmo.c (mmo_bfd_discard_group): Define. * nlm-target.h (nlm_bfd_discard_group): Define. * oasys.c (oasys_bfd_discard_group): Define. * ppcboot.c (ppcboot_bfd_discard_group): Define. * som.c (som_bfd_discard_group): Define. * srec.c (srec_bfd_discard_group): Define. * tekhex.c (tekhex_bfd_discard_group): Define. * versados.c (versados_bfd_discard_group): Define. * vms.c (vms_bfd_discard_group): Define. * xcoff-target.h (_bfd_xcoff_bfd_discard_group): Define. * coff64-rs6000.c (rs6000coff64_vec): Update initialiser. (aix5coff64_vec): Likewise. * coff-rs6000.c (rs6000coff_vec, pmac_xcoff_vec): Likewise.
2002-06-05 03:43:11 +00:00
bfd_generic_discard_group
SYNOPSIS
bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
DESCRIPTION
Remove all members of @var{group} from the output.
*/
bfd_boolean
2003-06-29 10:06:40 +00:00
bfd_generic_discard_group (bfd *abfd ATTRIBUTE_UNUSED,
asection *group ATTRIBUTE_UNUSED)
{
return TRUE;
}