00001 /* 00002 * Copyright 2003, 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* Object file "section" support for the BFD library. 00006 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 00007 2000, 2001, 2002, 2003, 2004, 2005 00008 Free Software Foundation, Inc. 00009 Written by Cygnus Support. 00010 00011 This file is part of BFD, the Binary File Descriptor library. 00012 00013 This program is free software; you can redistribute it and/or modify 00014 it under the terms of the GNU General Public License as published by 00015 the Free Software Foundation; either version 2 of the License, or 00016 (at your option) any later version. 00017 00018 This program is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 along with this program; if not, write to the Free Software 00025 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00026 00027 /* 00028 SECTION 00029 Sections 00030 00031 The raw data contained within a BFD is maintained through the 00032 section abstraction. A single BFD may have any number of 00033 sections. It keeps hold of them by pointing to the first; 00034 each one points to the next in the list. 00035 00036 Sections are supported in BFD in <<section.c>>. 00037 00038 @menu 00039 @* Section Input:: 00040 @* Section Output:: 00041 @* typedef asection:: 00042 @* section prototypes:: 00043 @end menu 00044 00045 INODE 00046 Section Input, Section Output, Sections, Sections 00047 SUBSECTION 00048 Section input 00049 00050 When a BFD is opened for reading, the section structures are 00051 created and attached to the BFD. 00052 00053 Each section has a name which describes the section in the 00054 outside world---for example, <<a.out>> would contain at least 00055 three sections, called <<.text>>, <<.data>> and <<.bss>>. 00056 00057 Names need not be unique; for example a COFF file may have several 00058 sections named <<.data>>. 00059 00060 Sometimes a BFD will contain more than the ``natural'' number of 00061 sections. A back end may attach other sections containing 00062 constructor data, or an application may add a section (using 00063 <<bfd_make_section>>) to the sections attached to an already open 00064 BFD. For example, the linker creates an extra section 00065 <<COMMON>> for each input file's BFD to hold information about 00066 common storage. 00067 00068 The raw data is not necessarily read in when 00069 the section descriptor is created. Some targets may leave the 00070 data in place until a <<bfd_get_section_contents>> call is 00071 made. Other back ends may read in all the data at once. For 00072 example, an S-record file has to be read once to determine the 00073 size of the data. An IEEE-695 file doesn't contain raw data in 00074 sections, but data and relocation expressions intermixed, so 00075 the data area has to be parsed to get out the data and 00076 relocations. 00077 00078 INODE 00079 Section Output, typedef asection, Section Input, Sections 00080 00081 SUBSECTION 00082 Section output 00083 00084 To write a new object style BFD, the various sections to be 00085 written have to be created. They are attached to the BFD in 00086 the same way as input sections; data is written to the 00087 sections using <<bfd_set_section_contents>>. 00088 00089 Any program that creates or combines sections (e.g., the assembler 00090 and linker) must use the <<asection>> fields <<output_section>> and 00091 <<output_offset>> to indicate the file sections to which each 00092 section must be written. (If the section is being created from 00093 scratch, <<output_section>> should probably point to the section 00094 itself and <<output_offset>> should probably be zero.) 00095 00096 The data to be written comes from input sections attached 00097 (via <<output_section>> pointers) to 00098 the output sections. The output section structure can be 00099 considered a filter for the input section: the output section 00100 determines the vma of the output data and the name, but the 00101 input section determines the offset into the output section of 00102 the data to be written. 00103 00104 E.g., to create a section "O", starting at 0x100, 0x123 long, 00105 containing two subsections, "A" at offset 0x0 (i.e., at vma 00106 0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the <<asection>> 00107 structures would look like: 00108 00109 | section name "A" 00110 | output_offset 0x00 00111 | size 0x20 00112 | output_section -----------> section name "O" 00113 | | vma 0x100 00114 | section name "B" | size 0x123 00115 | output_offset 0x20 | 00116 | size 0x103 | 00117 | output_section --------| 00118 00119 SUBSECTION 00120 Link orders 00121 00122 The data within a section is stored in a @dfn{link_order}. 00123 These are much like the fixups in <<gas>>. The link_order 00124 abstraction allows a section to grow and shrink within itself. 00125 00126 A link_order knows how big it is, and which is the next 00127 link_order and where the raw data for it is; it also points to 00128 a list of relocations which apply to it. 00129 00130 The link_order is used by the linker to perform relaxing on 00131 final code. The compiler creates code which is as big as 00132 necessary to make it work without relaxing, and the user can 00133 select whether to relax. Sometimes relaxing takes a lot of 00134 time. The linker runs around the relocations to see if any 00135 are attached to data which can be shrunk, if so it does it on 00136 a link_order by link_order basis. 00137 00138 */ 00139 00140 #include "bfd.h" 00141 #include "sysdep.h" 00142 #include "libbfd.h" 00143 #include "bfdlink.h" 00144 00145 /* 00146 DOCDD 00147 INODE 00148 typedef asection, section prototypes, Section Output, Sections 00149 SUBSECTION 00150 typedef asection 00151 00152 Here is the section structure: 00153 00154 CODE_FRAGMENT 00155 . 00156 .typedef struct bfd_section 00157 .{ 00158 . {* The name of the section; the name isn't a copy, the pointer is 00159 . the same as that passed to bfd_make_section. *} 00160 . const char *name; 00161 . 00162 . {* A unique sequence number. *} 00163 . int id; 00164 . 00165 . {* Which section in the bfd; 0..n-1 as sections are created in a bfd. *} 00166 . int index; 00167 . 00168 . {* The next section in the list belonging to the BFD, or NULL. *} 00169 . struct bfd_section *next; 00170 . 00171 . {* The field flags contains attributes of the section. Some 00172 . flags are read in from the object file, and some are 00173 . synthesized from other information. *} 00174 . flagword flags; 00175 . 00176 .#define SEC_NO_FLAGS 0x000 00177 . 00178 . {* Tells the OS to allocate space for this section when loading. 00179 . This is clear for a section containing debug information only. *} 00180 .#define SEC_ALLOC 0x001 00181 . 00182 . {* Tells the OS to load the section from the file when loading. 00183 . This is clear for a .bss section. *} 00184 .#define SEC_LOAD 0x002 00185 . 00186 . {* The section contains data still to be relocated, so there is 00187 . some relocation information too. *} 00188 .#define SEC_RELOC 0x004 00189 . 00190 . {* A signal to the OS that the section contains read only data. *} 00191 .#define SEC_READONLY 0x008 00192 . 00193 . {* The section contains code only. *} 00194 .#define SEC_CODE 0x010 00195 . 00196 . {* The section contains data only. *} 00197 .#define SEC_DATA 0x020 00198 . 00199 . {* The section will reside in ROM. *} 00200 .#define SEC_ROM 0x040 00201 . 00202 . {* The section contains constructor information. This section 00203 . type is used by the linker to create lists of constructors and 00204 . destructors used by <<g++>>. When a back end sees a symbol 00205 . which should be used in a constructor list, it creates a new 00206 . section for the type of name (e.g., <<__CTOR_LIST__>>), attaches 00207 . the symbol to it, and builds a relocation. To build the lists 00208 . of constructors, all the linker has to do is catenate all the 00209 . sections called <<__CTOR_LIST__>> and relocate the data 00210 . contained within - exactly the operations it would peform on 00211 . standard data. *} 00212 .#define SEC_CONSTRUCTOR 0x080 00213 . 00214 . {* The section has contents - a data section could be 00215 . <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be 00216 . <<SEC_HAS_CONTENTS>> *} 00217 .#define SEC_HAS_CONTENTS 0x100 00218 . 00219 . {* An instruction to the linker to not output the section 00220 . even if it has information which would normally be written. *} 00221 .#define SEC_NEVER_LOAD 0x200 00222 . 00223 . {* The section contains thread local data. *} 00224 .#define SEC_THREAD_LOCAL 0x400 00225 . 00226 . {* The section has GOT references. This flag is only for the 00227 . linker, and is currently only used by the elf32-hppa back end. 00228 . It will be set if global offset table references were detected 00229 . in this section, which indicate to the linker that the section 00230 . contains PIC code, and must be handled specially when doing a 00231 . static link. *} 00232 .#define SEC_HAS_GOT_REF 0x800 00233 . 00234 . {* The section contains common symbols (symbols may be defined 00235 . multiple times, the value of a symbol is the amount of 00236 . space it requires, and the largest symbol value is the one 00237 . used). Most targets have exactly one of these (which we 00238 . translate to bfd_com_section_ptr), but ECOFF has two. *} 00239 .#define SEC_IS_COMMON 0x1000 00240 . 00241 . {* The section contains only debugging information. For 00242 . example, this is set for ELF .debug and .stab sections. 00243 . strip tests this flag to see if a section can be 00244 . discarded. *} 00245 .#define SEC_DEBUGGING 0x2000 00246 . 00247 . {* The contents of this section are held in memory pointed to 00248 . by the contents field. This is checked by bfd_get_section_contents, 00249 . and the data is retrieved from memory if appropriate. *} 00250 .#define SEC_IN_MEMORY 0x4000 00251 . 00252 . {* The contents of this section are to be excluded by the 00253 . linker for executable and shared objects unless those 00254 . objects are to be further relocated. *} 00255 .#define SEC_EXCLUDE 0x8000 00256 . 00257 . {* The contents of this section are to be sorted based on the sum of 00258 . the symbol and addend values specified by the associated relocation 00259 . entries. Entries without associated relocation entries will be 00260 . appended to the end of the section in an unspecified order. *} 00261 .#define SEC_SORT_ENTRIES 0x10000 00262 . 00263 . {* When linking, duplicate sections of the same name should be 00264 . discarded, rather than being combined into a single section as 00265 . is usually done. This is similar to how common symbols are 00266 . handled. See SEC_LINK_DUPLICATES below. *} 00267 .#define SEC_LINK_ONCE 0x20000 00268 . 00269 . {* If SEC_LINK_ONCE is set, this bitfield describes how the linker 00270 . should handle duplicate sections. *} 00271 .#define SEC_LINK_DUPLICATES 0x40000 00272 . 00273 . {* This value for SEC_LINK_DUPLICATES means that duplicate 00274 . sections with the same name should simply be discarded. *} 00275 .#define SEC_LINK_DUPLICATES_DISCARD 0x0 00276 . 00277 . {* This value for SEC_LINK_DUPLICATES means that the linker 00278 . should warn if there are any duplicate sections, although 00279 . it should still only link one copy. *} 00280 .#define SEC_LINK_DUPLICATES_ONE_ONLY 0x80000 00281 . 00282 . {* This value for SEC_LINK_DUPLICATES means that the linker 00283 . should warn if any duplicate sections are a different size. *} 00284 .#define SEC_LINK_DUPLICATES_SAME_SIZE 0x100000 00285 . 00286 . {* This value for SEC_LINK_DUPLICATES means that the linker 00287 . should warn if any duplicate sections contain different 00288 . contents. *} 00289 .#define SEC_LINK_DUPLICATES_SAME_CONTENTS \ 00290 . (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE) 00291 . 00292 . {* This section was created by the linker as part of dynamic 00293 . relocation or other arcane processing. It is skipped when 00294 . going through the first-pass output, trusting that someone 00295 . else up the line will take care of it later. *} 00296 .#define SEC_LINKER_CREATED 0x200000 00297 . 00298 . {* This section should not be subject to garbage collection. *} 00299 .#define SEC_KEEP 0x400000 00300 . 00301 . {* This section contains "short" data, and should be placed 00302 . "near" the GP. *} 00303 .#define SEC_SMALL_DATA 0x800000 00304 . 00305 . {* Attempt to merge identical entities in the section. 00306 . Entity size is given in the entsize field. *} 00307 .#define SEC_MERGE 0x1000000 00308 . 00309 . {* If given with SEC_MERGE, entities to merge are zero terminated 00310 . strings where entsize specifies character size instead of fixed 00311 . size entries. *} 00312 .#define SEC_STRINGS 0x2000000 00313 . 00314 . {* This section contains data about section groups. *} 00315 .#define SEC_GROUP 0x4000000 00316 . 00317 . {* The section is a COFF shared library section. This flag is 00318 . only for the linker. If this type of section appears in 00319 . the input file, the linker must copy it to the output file 00320 . without changing the vma or size. FIXME: Although this 00321 . was originally intended to be general, it really is COFF 00322 . specific (and the flag was renamed to indicate this). It 00323 . might be cleaner to have some more general mechanism to 00324 . allow the back end to control what the linker does with 00325 . sections. *} 00326 .#define SEC_COFF_SHARED_LIBRARY 0x10000000 00327 . 00328 . {* This section contains data which may be shared with other 00329 . executables or shared objects. This is for COFF only. *} 00330 .#define SEC_COFF_SHARED 0x20000000 00331 . 00332 . {* When a section with this flag is being linked, then if the size of 00333 . the input section is less than a page, it should not cross a page 00334 . boundary. If the size of the input section is one page or more, 00335 . it should be aligned on a page boundary. This is for TI 00336 . TMS320C54X only. *} 00337 .#define SEC_TIC54X_BLOCK 0x40000000 00338 . 00339 . {* Conditionally link this section; do not link if there are no 00340 . references found to any symbol in the section. This is for TI 00341 . TMS320C54X only. *} 00342 .#define SEC_TIC54X_CLINK 0x80000000 00343 . 00344 . {* End of section flags. *} 00345 . 00346 . {* Some internal packed boolean fields. *} 00347 . 00348 . {* See the vma field. *} 00349 . unsigned int user_set_vma : 1; 00350 . 00351 . {* A mark flag used by some of the linker backends. *} 00352 . unsigned int linker_mark : 1; 00353 . 00354 . {* Another mark flag used by some of the linker backends. Set for 00355 . output sections that have an input section. *} 00356 . unsigned int linker_has_input : 1; 00357 . 00358 . {* A mark flag used by some linker backends for garbage collection. *} 00359 . unsigned int gc_mark : 1; 00360 . 00361 . {* The following flags are used by the ELF linker. *} 00362 . 00363 . {* Mark sections which have been allocated to segments. *} 00364 . unsigned int segment_mark : 1; 00365 . 00366 . {* Type of sec_info information. *} 00367 . unsigned int sec_info_type:3; 00368 .#define ELF_INFO_TYPE_NONE 0 00369 .#define ELF_INFO_TYPE_STABS 1 00370 .#define ELF_INFO_TYPE_MERGE 2 00371 .#define ELF_INFO_TYPE_EH_FRAME 3 00372 .#define ELF_INFO_TYPE_JUST_SYMS 4 00373 . 00374 . {* Nonzero if this section uses RELA relocations, rather than REL. *} 00375 . unsigned int use_rela_p:1; 00376 . 00377 . {* Bits used by various backends. The generic code doesn't touch 00378 . these fields. *} 00379 . 00380 . {* Nonzero if this section has TLS related relocations. *} 00381 . unsigned int has_tls_reloc:1; 00382 . 00383 . {* Nonzero if this section has a gp reloc. *} 00384 . unsigned int has_gp_reloc:1; 00385 . 00386 . {* Nonzero if this section needs the relax finalize pass. *} 00387 . unsigned int need_finalize_relax:1; 00388 . 00389 . {* Whether relocations have been processed. *} 00390 . unsigned int reloc_done : 1; 00391 . 00392 . {* End of internal packed boolean fields. *} 00393 . 00394 . {* The virtual memory address of the section - where it will be 00395 . at run time. The symbols are relocated against this. The 00396 . user_set_vma flag is maintained by bfd; if it's not set, the 00397 . backend can assign addresses (for example, in <<a.out>>, where 00398 . the default address for <<.data>> is dependent on the specific 00399 . target and various flags). *} 00400 . bfd_vma vma; 00401 . 00402 . {* The load address of the section - where it would be in a 00403 . rom image; really only used for writing section header 00404 . information. *} 00405 . bfd_vma lma; 00406 . 00407 . {* The size of the section in octets, as it will be output. 00408 . Contains a value even if the section has no contents (e.g., the 00409 . size of <<.bss>>). *} 00410 . bfd_size_type size; 00411 . 00412 . {* For input sections, the original size on disk of the section, in 00413 . octets. This field is used by the linker relaxation code. It is 00414 . currently only set for sections where the linker relaxation scheme 00415 . doesn't cache altered section and reloc contents (stabs, eh_frame, 00416 . SEC_MERGE, some coff relaxing targets), and thus the original size 00417 . needs to be kept to read the section multiple times. 00418 . For output sections, rawsize holds the section size calculated on 00419 . a previous linker relaxation pass. *} 00420 . bfd_size_type rawsize; 00421 . 00422 . {* If this section is going to be output, then this value is the 00423 . offset in *bytes* into the output section of the first byte in the 00424 . input section (byte ==> smallest addressable unit on the 00425 . target). In most cases, if this was going to start at the 00426 . 100th octet (8-bit quantity) in the output section, this value 00427 . would be 100. However, if the target byte size is 16 bits 00428 . (bfd_octets_per_byte is "2"), this value would be 50. *} 00429 . bfd_vma output_offset; 00430 . 00431 . {* The output section through which to map on output. *} 00432 . struct bfd_section *output_section; 00433 . 00434 . {* The alignment requirement of the section, as an exponent of 2 - 00435 . e.g., 3 aligns to 2^3 (or 8). *} 00436 . unsigned int alignment_power; 00437 . 00438 . {* If an input section, a pointer to a vector of relocation 00439 . records for the data in this section. *} 00440 . struct reloc_cache_entry *relocation; 00441 . 00442 . {* If an output section, a pointer to a vector of pointers to 00443 . relocation records for the data in this section. *} 00444 . struct reloc_cache_entry **orelocation; 00445 . 00446 . {* The number of relocation records in one of the above. *} 00447 . unsigned reloc_count; 00448 . 00449 . {* Information below is back end specific - and not always used 00450 . or updated. *} 00451 . 00452 . {* File position of section data. *} 00453 . file_ptr filepos; 00454 . 00455 . {* File position of relocation info. *} 00456 . file_ptr rel_filepos; 00457 . 00458 . {* File position of line data. *} 00459 . file_ptr line_filepos; 00460 . 00461 . {* Pointer to data for applications. *} 00462 . void *userdata; 00463 . 00464 . {* If the SEC_IN_MEMORY flag is set, this points to the actual 00465 . contents. *} 00466 . unsigned char *contents; 00467 . 00468 . {* Attached line number information. *} 00469 . alent *lineno; 00470 . 00471 . {* Number of line number records. *} 00472 . unsigned int lineno_count; 00473 . 00474 . {* Entity size for merging purposes. *} 00475 . unsigned int entsize; 00476 . 00477 . {* Points to the kept section if this section is a link-once section, 00478 . and is discarded. *} 00479 . struct bfd_section *kept_section; 00480 . 00481 . {* When a section is being output, this value changes as more 00482 . linenumbers are written out. *} 00483 . file_ptr moving_line_filepos; 00484 . 00485 . {* What the section number is in the target world. *} 00486 . int target_index; 00487 . 00488 . void *used_by_bfd; 00489 . 00490 . {* If this is a constructor section then here is a list of the 00491 . relocations created to relocate items within it. *} 00492 . struct relent_chain *constructor_chain; 00493 . 00494 . {* The BFD which owns the section. *} 00495 . bfd *owner; 00496 . 00497 . {* A symbol which points at this section only. *} 00498 . struct bfd_symbol *symbol; 00499 . struct bfd_symbol **symbol_ptr_ptr; 00500 . 00501 . struct bfd_link_order *link_order_head; 00502 . struct bfd_link_order *link_order_tail; 00503 .} asection; 00504 . 00505 .{* These sections are global, and are managed by BFD. The application 00506 . and target back end are not permitted to change the values in 00507 . these sections. New code should use the section_ptr macros rather 00508 . than referring directly to the const sections. The const sections 00509 . may eventually vanish. *} 00510 .#define BFD_ABS_SECTION_NAME "*ABS*" 00511 .#define BFD_UND_SECTION_NAME "*UND*" 00512 .#define BFD_COM_SECTION_NAME "*COM*" 00513 .#define BFD_IND_SECTION_NAME "*IND*" 00514 . 00515 .{* The absolute section. *} 00516 .extern asection bfd_abs_section; 00517 .#define bfd_abs_section_ptr ((asection *) &bfd_abs_section) 00518 .#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr) 00519 .{* Pointer to the undefined section. *} 00520 .extern asection bfd_und_section; 00521 .#define bfd_und_section_ptr ((asection *) &bfd_und_section) 00522 .#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr) 00523 .{* Pointer to the common section. *} 00524 .extern asection bfd_com_section; 00525 .#define bfd_com_section_ptr ((asection *) &bfd_com_section) 00526 .{* Pointer to the indirect section. *} 00527 .extern asection bfd_ind_section; 00528 .#define bfd_ind_section_ptr ((asection *) &bfd_ind_section) 00529 .#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr) 00530 . 00531 .#define bfd_is_const_section(SEC) \ 00532 . ( ((SEC) == bfd_abs_section_ptr) \ 00533 . || ((SEC) == bfd_und_section_ptr) \ 00534 . || ((SEC) == bfd_com_section_ptr) \ 00535 . || ((SEC) == bfd_ind_section_ptr)) 00536 . 00537 .extern const struct bfd_symbol * const bfd_abs_symbol; 00538 .extern const struct bfd_symbol * const bfd_com_symbol; 00539 .extern const struct bfd_symbol * const bfd_und_symbol; 00540 .extern const struct bfd_symbol * const bfd_ind_symbol; 00541 . 00542 .{* Macros to handle insertion and deletion of a bfd's sections. These 00543 . only handle the list pointers, ie. do not adjust section_count, 00544 . target_index etc. *} 00545 .#define bfd_section_list_remove(ABFD, PS) \ 00546 . do \ 00547 . { \ 00548 . asection **_ps = PS; \ 00549 . asection *_s = *_ps; \ 00550 . *_ps = _s->next; \ 00551 . if (_s->next == NULL) \ 00552 . (ABFD)->section_tail = _ps; \ 00553 . } \ 00554 . while (0) 00555 .#define bfd_section_list_insert(ABFD, PS, S) \ 00556 . do \ 00557 . { \ 00558 . asection **_ps = PS; \ 00559 . asection *_s = S; \ 00560 . _s->next = *_ps; \ 00561 . *_ps = _s; \ 00562 . if (_s->next == NULL) \ 00563 . (ABFD)->section_tail = &_s->next; \ 00564 . } \ 00565 . while (0) 00566 . 00567 */ 00568 00569 /* We use a macro to initialize the static asymbol structures because 00570 traditional C does not permit us to initialize a union member while 00571 gcc warns if we don't initialize it. */ 00572 /* the_bfd, name, value, attr, section [, udata] */ 00573 #ifdef __STDC__ 00574 #define GLOBAL_SYM_INIT(NAME, SECTION) \ 00575 { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION, { 0 }} 00576 #else 00577 #define GLOBAL_SYM_INIT(NAME, SECTION) \ 00578 { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION } 00579 #endif 00580 00581 /* These symbols are global, not specific to any BFD. Therefore, anything 00582 that tries to change them is broken, and should be repaired. */ 00583 00584 static const asymbol global_syms[] = 00585 { 00586 GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, &bfd_com_section), 00587 GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, &bfd_und_section), 00588 GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, &bfd_abs_section), 00589 GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, &bfd_ind_section), 00590 #ifdef IPA_LINK 00591 GLOBAL_SYM_INIT (BFD_WHD_SECTION_NAME, &bfd_whirl_data_section), 00592 GLOBAL_SYM_INIT (BFD_WHT_SECTION_NAME, &bfd_whirl_text_section), 00593 #endif 00594 }; 00595 00596 #define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX) \ 00597 const asymbol * const SYM = (asymbol *) &global_syms[IDX]; \ 00598 asection SEC = \ 00599 /* name, id, index, next, flags, user_set_vma, */ \ 00600 { NAME, IDX, 0, NULL, FLAGS, 0, \ 00601 \ 00602 /* linker_mark, linker_has_input, gc_mark, segment_mark, */ \ 00603 0, 0, 1, 0, \ 00604 \ 00605 /* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc, */ \ 00606 0, 0, 0, 0, \ 00607 \ 00608 /* need_finalize_relax, reloc_done, */ \ 00609 0, 0, \ 00610 \ 00611 /* vma, lma, size, rawsize */ \ 00612 0, 0, 0, 0, \ 00613 \ 00614 /* output_offset, output_section, alignment_power, */ \ 00615 0, (struct bfd_section *) &SEC, 0, \ 00616 \ 00617 /* relocation, orelocation, reloc_count, filepos, rel_filepos, */ \ 00618 NULL, NULL, 0, 0, 0, \ 00619 \ 00620 /* line_filepos, userdata, contents, lineno, lineno_count, */ \ 00621 0, NULL, NULL, NULL, 0, \ 00622 \ 00623 /* entsize, kept_section, moving_line_filepos, */ \ 00624 0, NULL, 0, \ 00625 \ 00626 /* target_index, used_by_bfd, constructor_chain, owner, */ \ 00627 0, NULL, NULL, NULL, \ 00628 \ 00629 /* symbol, */ \ 00630 (struct bfd_symbol *) &global_syms[IDX], \ 00631 \ 00632 /* symbol_ptr_ptr, */ \ 00633 (struct bfd_symbol **) &SYM, \ 00634 \ 00635 /* link_order_head, link_order_tail */ \ 00636 NULL, NULL \ 00637 } 00638 00639 STD_SECTION (bfd_com_section, SEC_IS_COMMON, bfd_com_symbol, 00640 BFD_COM_SECTION_NAME, 0); 00641 STD_SECTION (bfd_und_section, 0, bfd_und_symbol, BFD_UND_SECTION_NAME, 1); 00642 STD_SECTION (bfd_abs_section, 0, bfd_abs_symbol, BFD_ABS_SECTION_NAME, 2); 00643 STD_SECTION (bfd_ind_section, 0, bfd_ind_symbol, BFD_IND_SECTION_NAME, 3); 00644 #ifdef IPA_LINK 00645 STD_SECTION (bfd_whirl_data_section, 0, bfd_whirl_data_symbol, 00646 BFD_WHD_SECTION_NAME, 4); 00647 STD_SECTION (bfd_whirl_text_section, 0, bfd_whirl_text_symbol, 00648 BFD_WHT_SECTION_NAME, 5); 00649 #endif 00650 #undef STD_SECTION 00651 00652 struct section_hash_entry 00653 { 00654 struct bfd_hash_entry root; 00655 asection section; 00656 }; 00657 00658 /* Initialize an entry in the section hash table. */ 00659 00660 struct bfd_hash_entry * 00661 bfd_section_hash_newfunc (struct bfd_hash_entry *entry, 00662 struct bfd_hash_table *table, 00663 const char *string) 00664 { 00665 /* Allocate the structure if it has not already been allocated by a 00666 subclass. */ 00667 if (entry == NULL) 00668 { 00669 entry = (struct bfd_hash_entry *) 00670 bfd_hash_allocate (table, sizeof (struct section_hash_entry)); 00671 if (entry == NULL) 00672 return entry; 00673 } 00674 00675 /* Call the allocation method of the superclass. */ 00676 entry = bfd_hash_newfunc (entry, table, string); 00677 if (entry != NULL) 00678 memset (&((struct section_hash_entry *) entry)->section, 0, 00679 sizeof (asection)); 00680 00681 return entry; 00682 } 00683 00684 #define section_hash_lookup(table, string, create, copy) \ 00685 ((struct section_hash_entry *) \ 00686 bfd_hash_lookup ((table), (string), (create), (copy))) 00687 00688 /* Initializes a new section. NEWSECT->NAME is already set. */ 00689 00690 static asection * 00691 bfd_section_init (bfd *abfd, asection *newsect) 00692 { 00693 static int section_id = 0x10; /* id 0 to 3 used by STD_SECTION. */ 00694 00695 newsect->id = section_id; 00696 newsect->index = abfd->section_count; 00697 newsect->owner = abfd; 00698 00699 /* Create a symbol whose only job is to point to this section. This 00700 is useful for things like relocs which are relative to the base 00701 of a section. */ 00702 newsect->symbol = bfd_make_empty_symbol (abfd); 00703 if (newsect->symbol == NULL) 00704 return NULL; 00705 00706 newsect->symbol->name = newsect->name; 00707 newsect->symbol->value = 0; 00708 newsect->symbol->section = newsect; 00709 newsect->symbol->flags = BSF_SECTION_SYM; 00710 00711 newsect->symbol_ptr_ptr = &newsect->symbol; 00712 00713 if (! BFD_SEND (abfd, _new_section_hook, (abfd, newsect))) 00714 return NULL; 00715 00716 section_id++; 00717 abfd->section_count++; 00718 *abfd->section_tail = newsect; 00719 abfd->section_tail = &newsect->next; 00720 return newsect; 00721 } 00722 00723 /* 00724 DOCDD 00725 INODE 00726 section prototypes, , typedef asection, Sections 00727 SUBSECTION 00728 Section prototypes 00729 00730 These are the functions exported by the section handling part of BFD. 00731 */ 00732 00733 /* 00734 FUNCTION 00735 bfd_section_list_clear 00736 00737 SYNOPSIS 00738 void bfd_section_list_clear (bfd *); 00739 00740 DESCRIPTION 00741 Clears the section list, and also resets the section count and 00742 hash table entries. 00743 */ 00744 00745 void 00746 bfd_section_list_clear (bfd *abfd) 00747 { 00748 abfd->sections = NULL; 00749 abfd->section_tail = &abfd->sections; 00750 abfd->section_count = 0; 00751 memset (abfd->section_htab.table, 0, 00752 abfd->section_htab.size * sizeof (struct bfd_hash_entry *)); 00753 } 00754 00755 /* 00756 FUNCTION 00757 bfd_get_section_by_name 00758 00759 SYNOPSIS 00760 asection *bfd_get_section_by_name (bfd *abfd, const char *name); 00761 00762 DESCRIPTION 00763 Run through @var{abfd} and return the one of the 00764 <<asection>>s whose name matches @var{name}, otherwise <<NULL>>. 00765 @xref{Sections}, for more information. 00766 00767 This should only be used in special cases; the normal way to process 00768 all sections of a given name is to use <<bfd_map_over_sections>> and 00769 <<strcmp>> on the name (or better yet, base it on the section flags 00770 or something else) for each section. 00771 */ 00772 00773 asection * 00774 bfd_get_section_by_name (bfd *abfd, const char *name) 00775 { 00776 struct section_hash_entry *sh; 00777 00778 sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE); 00779 if (sh != NULL) 00780 return &sh->section; 00781 00782 return NULL; 00783 } 00784 00785 /* 00786 FUNCTION 00787 bfd_get_section_by_name_if 00788 00789 SYNOPSIS 00790 asection *bfd_get_section_by_name_if 00791 (bfd *abfd, 00792 const char *name, 00793 bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj), 00794 void *obj); 00795 00796 DESCRIPTION 00797 Call the provided function @var{func} for each section 00798 attached to the BFD @var{abfd} whose name matches @var{name}, 00799 passing @var{obj} as an argument. The function will be called 00800 as if by 00801 00802 | func (abfd, the_section, obj); 00803 00804 It returns the first section for which @var{func} returns true, 00805 otherwise <<NULL>>. 00806 00807 */ 00808 00809 asection * 00810 bfd_get_section_by_name_if (bfd *abfd, const char *name, 00811 bfd_boolean (*operation) (bfd *, 00812 asection *, 00813 void *), 00814 void *user_storage) 00815 { 00816 struct section_hash_entry *sh; 00817 unsigned long hash; 00818 00819 sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE); 00820 if (sh == NULL) 00821 return NULL; 00822 00823 hash = sh->root.hash; 00824 do 00825 { 00826 if ((*operation) (abfd, &sh->section, user_storage)) 00827 return &sh->section; 00828 sh = (struct section_hash_entry *) sh->root.next; 00829 } 00830 while (sh != NULL && sh->root.hash == hash 00831 && strcmp (sh->root.string, name) == 0); 00832 00833 return NULL; 00834 } 00835 00836 /* 00837 FUNCTION 00838 bfd_get_unique_section_name 00839 00840 SYNOPSIS 00841 char *bfd_get_unique_section_name 00842 (bfd *abfd, const char *templat, int *count); 00843 00844 DESCRIPTION 00845 Invent a section name that is unique in @var{abfd} by tacking 00846 a dot and a digit suffix onto the original @var{templat}. If 00847 @var{count} is non-NULL, then it specifies the first number 00848 tried as a suffix to generate a unique name. The value 00849 pointed to by @var{count} will be incremented in this case. 00850 */ 00851 00852 char * 00853 bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count) 00854 { 00855 int num; 00856 unsigned int len; 00857 char *sname; 00858 00859 len = strlen (templat); 00860 sname = bfd_malloc (len + 8); 00861 if (sname == NULL) 00862 return NULL; 00863 memcpy (sname, templat, len); 00864 num = 1; 00865 if (count != NULL) 00866 num = *count; 00867 00868 do 00869 { 00870 /* If we have a million sections, something is badly wrong. */ 00871 if (num > 999999) 00872 abort (); 00873 sprintf (sname + len, ".%d", num++); 00874 } 00875 while (section_hash_lookup (&abfd->section_htab, sname, FALSE, FALSE)); 00876 00877 if (count != NULL) 00878 *count = num; 00879 return sname; 00880 } 00881 00882 /* 00883 FUNCTION 00884 bfd_make_section_old_way 00885 00886 SYNOPSIS 00887 asection *bfd_make_section_old_way (bfd *abfd, const char *name); 00888 00889 DESCRIPTION 00890 Create a new empty section called @var{name} 00891 and attach it to the end of the chain of sections for the 00892 BFD @var{abfd}. An attempt to create a section with a name which 00893 is already in use returns its pointer without changing the 00894 section chain. 00895 00896 It has the funny name since this is the way it used to be 00897 before it was rewritten.... 00898 00899 Possible errors are: 00900 o <<bfd_error_invalid_operation>> - 00901 If output has already started for this BFD. 00902 o <<bfd_error_no_memory>> - 00903 If memory allocation fails. 00904 00905 */ 00906 00907 asection * 00908 bfd_make_section_old_way (bfd *abfd, const char *name) 00909 { 00910 struct section_hash_entry *sh; 00911 asection *newsect; 00912 00913 if (abfd->output_has_begun) 00914 { 00915 bfd_set_error (bfd_error_invalid_operation); 00916 return NULL; 00917 } 00918 00919 if (strcmp (name, BFD_ABS_SECTION_NAME) == 0) 00920 return bfd_abs_section_ptr; 00921 00922 if (strcmp (name, BFD_COM_SECTION_NAME) == 0) 00923 return bfd_com_section_ptr; 00924 00925 if (strcmp (name, BFD_UND_SECTION_NAME) == 0) 00926 return bfd_und_section_ptr; 00927 00928 if (strcmp (name, BFD_IND_SECTION_NAME) == 0) 00929 return bfd_ind_section_ptr; 00930 00931 #ifdef IPA_LINK 00932 if (strcmp (name, BFD_WHD_SECTION_NAME) == 0) 00933 return bfd_whirl_data_section_ptr; 00934 00935 if (strcmp (name, BFD_WHT_SECTION_NAME) == 0) 00936 return bfd_whirl_text_section_ptr; 00937 #endif 00938 00939 sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE); 00940 if (sh == NULL) 00941 return NULL; 00942 00943 newsect = &sh->section; 00944 if (newsect->name != NULL) 00945 { 00946 /* Section already exists. */ 00947 return newsect; 00948 } 00949 00950 newsect->name = name; 00951 return bfd_section_init (abfd, newsect); 00952 } 00953 00954 /* 00955 FUNCTION 00956 bfd_make_section_anyway 00957 00958 SYNOPSIS 00959 asection *bfd_make_section_anyway (bfd *abfd, const char *name); 00960 00961 DESCRIPTION 00962 Create a new empty section called @var{name} and attach it to the end of 00963 the chain of sections for @var{abfd}. Create a new section even if there 00964 is already a section with that name. 00965 00966 Return <<NULL>> and set <<bfd_error>> on error; possible errors are: 00967 o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}. 00968 o <<bfd_error_no_memory>> - If memory allocation fails. 00969 */ 00970 00971 sec_ptr 00972 bfd_make_section_anyway (bfd *abfd, const char *name) 00973 { 00974 struct section_hash_entry *sh; 00975 asection *newsect; 00976 00977 if (abfd->output_has_begun) 00978 { 00979 bfd_set_error (bfd_error_invalid_operation); 00980 return NULL; 00981 } 00982 00983 sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE); 00984 if (sh == NULL) 00985 return NULL; 00986 00987 newsect = &sh->section; 00988 if (newsect->name != NULL) 00989 { 00990 /* We are making a section of the same name. Put it in the 00991 section hash table. Even though we can't find it directly by a 00992 hash lookup, we'll be able to find the section by traversing 00993 sh->root.next quicker than looking at all the bfd sections. */ 00994 struct section_hash_entry *new_sh; 00995 new_sh = (struct section_hash_entry *) 00996 bfd_section_hash_newfunc (NULL, &abfd->section_htab, name); 00997 if (new_sh == NULL) 00998 return NULL; 00999 01000 new_sh->root = sh->root; 01001 sh->root.next = &new_sh->root; 01002 newsect = &new_sh->section; 01003 } 01004 01005 newsect->name = name; 01006 return bfd_section_init (abfd, newsect); 01007 } 01008 01009 /* 01010 FUNCTION 01011 bfd_make_section 01012 01013 SYNOPSIS 01014 asection *bfd_make_section (bfd *, const char *name); 01015 01016 DESCRIPTION 01017 Like <<bfd_make_section_anyway>>, but return <<NULL>> (without calling 01018 bfd_set_error ()) without changing the section chain if there is already a 01019 section named @var{name}. If there is an error, return <<NULL>> and set 01020 <<bfd_error>>. 01021 */ 01022 01023 asection * 01024 bfd_make_section (bfd *abfd, const char *name) 01025 { 01026 struct section_hash_entry *sh; 01027 asection *newsect; 01028 01029 if (abfd->output_has_begun) 01030 { 01031 bfd_set_error (bfd_error_invalid_operation); 01032 return NULL; 01033 } 01034 01035 if (strcmp (name, BFD_ABS_SECTION_NAME) == 0 01036 || strcmp (name, BFD_COM_SECTION_NAME) == 0 01037 || strcmp (name, BFD_UND_SECTION_NAME) == 0 01038 || strcmp (name, BFD_IND_SECTION_NAME) == 0) 01039 return NULL; 01040 01041 sh = section_hash_lookup (&abfd->section_htab, name, TRUE, FALSE); 01042 if (sh == NULL) 01043 return NULL; 01044 01045 newsect = &sh->section; 01046 if (newsect->name != NULL) 01047 { 01048 /* Section already exists. */ 01049 return NULL; 01050 } 01051 01052 newsect->name = name; 01053 return bfd_section_init (abfd, newsect); 01054 } 01055 01056 /* 01057 FUNCTION 01058 bfd_set_section_flags 01059 01060 SYNOPSIS 01061 bfd_boolean bfd_set_section_flags 01062 (bfd *abfd, asection *sec, flagword flags); 01063 01064 DESCRIPTION 01065 Set the attributes of the section @var{sec} in the BFD 01066 @var{abfd} to the value @var{flags}. Return <<TRUE>> on success, 01067 <<FALSE>> on error. Possible error returns are: 01068 01069 o <<bfd_error_invalid_operation>> - 01070 The section cannot have one or more of the attributes 01071 requested. For example, a .bss section in <<a.out>> may not 01072 have the <<SEC_HAS_CONTENTS>> field set. 01073 01074 */ 01075 01076 bfd_boolean 01077 bfd_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED, 01078 sec_ptr section, 01079 flagword flags) 01080 { 01081 section->flags = flags; 01082 return TRUE; 01083 } 01084 01085 /* 01086 FUNCTION 01087 bfd_map_over_sections 01088 01089 SYNOPSIS 01090 void bfd_map_over_sections 01091 (bfd *abfd, 01092 void (*func) (bfd *abfd, asection *sect, void *obj), 01093 void *obj); 01094 01095 DESCRIPTION 01096 Call the provided function @var{func} for each section 01097 attached to the BFD @var{abfd}, passing @var{obj} as an 01098 argument. The function will be called as if by 01099 01100 | func (abfd, the_section, obj); 01101 01102 This is the preferred method for iterating over sections; an 01103 alternative would be to use a loop: 01104 01105 | section *p; 01106 | for (p = abfd->sections; p != NULL; p = p->next) 01107 | func (abfd, p, ...) 01108 01109 */ 01110 01111 void 01112 bfd_map_over_sections (bfd *abfd, 01113 void (*operation) (bfd *, asection *, void *), 01114 void *user_storage) 01115 { 01116 asection *sect; 01117 unsigned int i = 0; 01118 01119 for (sect = abfd->sections; sect != NULL; i++, sect = sect->next) 01120 (*operation) (abfd, sect, user_storage); 01121 01122 if (i != abfd->section_count) /* Debugging */ 01123 abort (); 01124 } 01125 01126 /* 01127 FUNCTION 01128 bfd_sections_find_if 01129 01130 SYNOPSIS 01131 asection *bfd_sections_find_if 01132 (bfd *abfd, 01133 bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj), 01134 void *obj); 01135 01136 DESCRIPTION 01137 Call the provided function @var{operation} for each section 01138 attached to the BFD @var{abfd}, passing @var{obj} as an 01139 argument. The function will be called as if by 01140 01141 | operation (abfd, the_section, obj); 01142 01143 It returns the first section for which @var{operation} returns true. 01144 01145 */ 01146 01147 asection * 01148 bfd_sections_find_if (bfd *abfd, 01149 bfd_boolean (*operation) (bfd *, asection *, void *), 01150 void *user_storage) 01151 { 01152 asection *sect; 01153 01154 for (sect = abfd->sections; sect != NULL; sect = sect->next) 01155 if ((*operation) (abfd, sect, user_storage)) 01156 break; 01157 01158 return sect; 01159 } 01160 01161 /* 01162 FUNCTION 01163 bfd_set_section_size 01164 01165 SYNOPSIS 01166 bfd_boolean bfd_set_section_size 01167 (bfd *abfd, asection *sec, bfd_size_type val); 01168 01169 DESCRIPTION 01170 Set @var{sec} to the size @var{val}. If the operation is 01171 ok, then <<TRUE>> is returned, else <<FALSE>>. 01172 01173 Possible error returns: 01174 o <<bfd_error_invalid_operation>> - 01175 Writing has started to the BFD, so setting the size is invalid. 01176 01177 */ 01178 01179 bfd_boolean 01180 bfd_set_section_size (bfd *abfd, sec_ptr ptr, bfd_size_type val) 01181 { 01182 /* Once you've started writing to any section you cannot create or change 01183 the size of any others. */ 01184 01185 if (abfd->output_has_begun) 01186 { 01187 bfd_set_error (bfd_error_invalid_operation); 01188 return FALSE; 01189 } 01190 01191 ptr->size = val; 01192 return TRUE; 01193 } 01194 01195 /* 01196 FUNCTION 01197 bfd_set_section_contents 01198 01199 SYNOPSIS 01200 bfd_boolean bfd_set_section_contents 01201 (bfd *abfd, asection *section, const void *data, 01202 file_ptr offset, bfd_size_type count); 01203 01204 DESCRIPTION 01205 Sets the contents of the section @var{section} in BFD 01206 @var{abfd} to the data starting in memory at @var{data}. The 01207 data is written to the output section starting at offset 01208 @var{offset} for @var{count} octets. 01209 01210 Normally <<TRUE>> is returned, else <<FALSE>>. Possible error 01211 returns are: 01212 o <<bfd_error_no_contents>> - 01213 The output section does not have the <<SEC_HAS_CONTENTS>> 01214 attribute, so nothing can be written to it. 01215 o and some more too 01216 01217 This routine is front end to the back end function 01218 <<_bfd_set_section_contents>>. 01219 01220 */ 01221 01222 bfd_boolean 01223 bfd_set_section_contents (bfd *abfd, 01224 sec_ptr section, 01225 const void *location, 01226 file_ptr offset, 01227 bfd_size_type count) 01228 { 01229 bfd_size_type sz; 01230 01231 if (!(bfd_get_section_flags (abfd, section) & SEC_HAS_CONTENTS)) 01232 { 01233 bfd_set_error (bfd_error_no_contents); 01234 return FALSE; 01235 } 01236 01237 sz = section->size; 01238 if ((bfd_size_type) offset > sz 01239 || count > sz 01240 || offset + count > sz 01241 || count != (size_t) count) 01242 { 01243 bfd_set_error (bfd_error_bad_value); 01244 return FALSE; 01245 } 01246 01247 switch (abfd->direction) 01248 { 01249 case read_direction: 01250 case no_direction: 01251 bfd_set_error (bfd_error_invalid_operation); 01252 return FALSE; 01253 01254 case write_direction: 01255 break; 01256 01257 case both_direction: 01258 /* File is opened for update. `output_has_begun' some time ago when 01259 the file was created. Do not recompute sections sizes or alignments 01260 in _bfd_set_section_content. */ 01261 abfd->output_has_begun = TRUE; 01262 break; 01263 } 01264 01265 /* Record a copy of the data in memory if desired. */ 01266 if (section->contents 01267 && location != section->contents + offset) 01268 memcpy (section->contents + offset, location, (size_t) count); 01269 01270 if (BFD_SEND (abfd, _bfd_set_section_contents, 01271 (abfd, section, location, offset, count))) 01272 { 01273 abfd->output_has_begun = TRUE; 01274 return TRUE; 01275 } 01276 01277 return FALSE; 01278 } 01279 01280 /* 01281 FUNCTION 01282 bfd_get_section_contents 01283 01284 SYNOPSIS 01285 bfd_boolean bfd_get_section_contents 01286 (bfd *abfd, asection *section, void *location, file_ptr offset, 01287 bfd_size_type count); 01288 01289 DESCRIPTION 01290 Read data from @var{section} in BFD @var{abfd} 01291 into memory starting at @var{location}. The data is read at an 01292 offset of @var{offset} from the start of the input section, 01293 and is read for @var{count} bytes. 01294 01295 If the contents of a constructor with the <<SEC_CONSTRUCTOR>> 01296 flag set are requested or if the section does not have the 01297 <<SEC_HAS_CONTENTS>> flag set, then the @var{location} is filled 01298 with zeroes. If no errors occur, <<TRUE>> is returned, else 01299 <<FALSE>>. 01300 01301 */ 01302 bfd_boolean 01303 bfd_get_section_contents (bfd *abfd, 01304 sec_ptr section, 01305 void *location, 01306 file_ptr offset, 01307 bfd_size_type count) 01308 { 01309 bfd_size_type sz; 01310 01311 if (section->flags & SEC_CONSTRUCTOR) 01312 { 01313 memset (location, 0, (size_t) count); 01314 return TRUE; 01315 } 01316 01317 sz = section->rawsize ? section->rawsize : section->size; 01318 if ((bfd_size_type) offset > sz 01319 || count > sz 01320 || offset + count > sz 01321 || count != (size_t) count) 01322 { 01323 bfd_set_error (bfd_error_bad_value); 01324 return FALSE; 01325 } 01326 01327 if (count == 0) 01328 /* Don't bother. */ 01329 return TRUE; 01330 01331 if ((section->flags & SEC_HAS_CONTENTS) == 0) 01332 { 01333 memset (location, 0, (size_t) count); 01334 return TRUE; 01335 } 01336 01337 if ((section->flags & SEC_IN_MEMORY) != 0) 01338 { 01339 memcpy (location, section->contents + offset, (size_t) count); 01340 return TRUE; 01341 } 01342 01343 return BFD_SEND (abfd, _bfd_get_section_contents, 01344 (abfd, section, location, offset, count)); 01345 } 01346 01347 /* 01348 FUNCTION 01349 bfd_malloc_and_get_section 01350 01351 SYNOPSIS 01352 bfd_boolean bfd_malloc_and_get_section 01353 (bfd *abfd, asection *section, bfd_byte **buf); 01354 01355 DESCRIPTION 01356 Read all data from @var{section} in BFD @var{abfd} 01357 into a buffer, *@var{buf}, malloc'd by this function. 01358 */ 01359 01360 bfd_boolean 01361 bfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf) 01362 { 01363 bfd_size_type sz = sec->rawsize ? sec->rawsize : sec->size; 01364 bfd_byte *p = NULL; 01365 01366 *buf = p; 01367 if (sz == 0) 01368 return TRUE; 01369 01370 p = bfd_malloc (sec->rawsize > sec->size ? sec->rawsize : sec->size); 01371 if (p == NULL) 01372 return FALSE; 01373 *buf = p; 01374 01375 return bfd_get_section_contents (abfd, sec, p, 0, sz); 01376 } 01377 /* 01378 FUNCTION 01379 bfd_copy_private_section_data 01380 01381 SYNOPSIS 01382 bfd_boolean bfd_copy_private_section_data 01383 (bfd *ibfd, asection *isec, bfd *obfd, asection *osec); 01384 01385 DESCRIPTION 01386 Copy private section information from @var{isec} in the BFD 01387 @var{ibfd} to the section @var{osec} in the BFD @var{obfd}. 01388 Return <<TRUE>> on success, <<FALSE>> on error. Possible error 01389 returns are: 01390 01391 o <<bfd_error_no_memory>> - 01392 Not enough memory exists to create private data for @var{osec}. 01393 01394 .#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ 01395 . BFD_SEND (obfd, _bfd_copy_private_section_data, \ 01396 . (ibfd, isection, obfd, osection)) 01397 */ 01398 01399 /* 01400 FUNCTION 01401 _bfd_strip_section_from_output 01402 01403 SYNOPSIS 01404 void _bfd_strip_section_from_output 01405 (struct bfd_link_info *info, asection *section); 01406 01407 DESCRIPTION 01408 Remove @var{section} from the output. If the output section 01409 becomes empty, remove it from the output bfd. 01410 01411 This function won't actually do anything except twiddle flags 01412 if called too late in the linking process, when it's not safe 01413 to remove sections. 01414 */ 01415 void 01416 _bfd_strip_section_from_output (struct bfd_link_info *info, asection *s) 01417 { 01418 asection *os; 01419 asection *is; 01420 bfd *abfd; 01421 01422 s->flags |= SEC_EXCLUDE; 01423 01424 /* If the section wasn't assigned to an output section, or the 01425 section has been discarded by the linker script, there's nothing 01426 more to do. */ 01427 os = s->output_section; 01428 if (os == NULL || os->owner == NULL) 01429 return; 01430 01431 /* If the output section has other (non-excluded) input sections, we 01432 can't remove it. */ 01433 for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next) 01434 for (is = abfd->sections; is != NULL; is = is->next) 01435 if (is->output_section == os && (is->flags & SEC_EXCLUDE) == 0) 01436 return; 01437 01438 /* If the output section is empty, flag it for removal too. 01439 See ldlang.c:strip_excluded_output_sections for the action. */ 01440 os->flags |= SEC_EXCLUDE; 01441 } 01442 01443 /* 01444 FUNCTION 01445 bfd_generic_is_group_section 01446 01447 SYNOPSIS 01448 bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec); 01449 01450 DESCRIPTION 01451 Returns TRUE if @var{sec} is a member of a group. 01452 */ 01453 01454 bfd_boolean 01455 bfd_generic_is_group_section (bfd *abfd ATTRIBUTE_UNUSED, 01456 const asection *sec ATTRIBUTE_UNUSED) 01457 { 01458 return FALSE; 01459 } 01460 01461 /* 01462 FUNCTION 01463 bfd_generic_discard_group 01464 01465 SYNOPSIS 01466 bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group); 01467 01468 DESCRIPTION 01469 Remove all members of @var{group} from the output. 01470 */ 01471 01472 bfd_boolean 01473 bfd_generic_discard_group (bfd *abfd ATTRIBUTE_UNUSED, 01474 asection *group ATTRIBUTE_UNUSED) 01475 { 01476 return TRUE; 01477 }
1.5.6