?? section.c
字號:
asection *DEFUN(bfd_get_section_by_name,(abfd, name), bfd *abfd AND CONST char *name){ asection *sect; for (sect = abfd->sections; sect != NULL; sect = sect->next) if (!strcmp (sect->name, name)) return sect; return NULL;}/*FUNCTION bfd_make_section_old_waySYNOPSIS asection *bfd_make_section_old_way(bfd *, CONST char *name);DESCRIPTION This function creates a new empty section called @var{name} and attaches it to the end of the chain of sections for the BFD supplied. 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 is was rewritten... Possible errors are: o invalid_operation - If output has already started for this BFD. o no_memory - If obstack alloc fails.*/asection *DEFUN(bfd_make_section_old_way,(abfd, name), bfd *abfd AND CONST char * name){ asection *sec = bfd_get_section_by_name(abfd, name); if (sec == (asection *)NULL) { sec = bfd_make_section(abfd, name); } return sec;}/*FUNCTION bfd_make_sectionSYNOPSIS asection * bfd_make_section(bfd *, CONST char *name);DESCRIPTION This function creates a new empty section called @var{name} and attaches it to the end of the chain of sections for the BFD supplied. An attempt to create a section with a name which is already in use, returns NULL without changing the section chain. Possible errors are: o invalid_operation - If output has already started for this BFD. o no_memory - If obstack alloc fails.*/sec_ptrDEFUN(bfd_make_section,(abfd, name), bfd *abfd AND CONST char * name){ asection *newsect; asection ** prev = &abfd->sections; asection * sect = abfd->sections; if (abfd->output_has_begun) { bfd_error = invalid_operation; return NULL; } if (strcmp(name, BFD_ABS_SECTION_NAME) == 0) { return &bfd_abs_section; } if (strcmp(name, BFD_COM_SECTION_NAME) == 0) { return &bfd_com_section; } if (strcmp(name, BFD_UND_SECTION_NAME) == 0) { return &bfd_und_section; } while (sect) { if (!strcmp(sect->name, name)) return NULL; prev = §->next; sect = sect->next; } newsect = (asection *) bfd_zalloc(abfd, sizeof (asection)); if (newsect == NULL) { bfd_error = no_memory; return NULL; } newsect->name = name; newsect->index = abfd->section_count++; newsect->flags = SEC_NO_FLAGS; newsect->userdata = 0; newsect->next = (asection *)NULL; newsect->relocation = (arelent *)NULL; newsect->reloc_count = 0; newsect->line_filepos =0; newsect->owner = abfd; /* Create a symbol whos only job is to point to this section. This is useful for things like relocs which are relative to the base of a section. */ newsect->symbol = bfd_make_empty_symbol(abfd); newsect->symbol->name = name; newsect->symbol->value = 0; 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)) != true) { free (newsect); return NULL; } *prev = newsect; return newsect;}/*FUNCTION bfd_set_section_flagsSYNOPSIS boolean bfd_set_section_flags(bfd *, asection *, flagword);DESCRIPTION Attempts to set the attributes of the section named in the BFD supplied to the value. Returns true on success, false on error. Possible error returns are: o invalid operation - The section cannot have one or more of the attributes requested. For example, a .bss section in <<a.out>> may not have the <<SEC_HAS_CONTENTS>> field set.*/booleanDEFUN(bfd_set_section_flags,(abfd, section, flags), bfd *abfd AND sec_ptr section AND flagword flags){#if 0 /* If you try to copy a text section from an input file (where it has the SEC_CODE flag set) to an output file, this loses big if the bfd_applicable_section_flags (abfd) doesn't have the SEC_CODE set - which it doesn't, at least not for a.out. FIXME */ if ((flags & bfd_applicable_section_flags (abfd)) != flags) { bfd_error = invalid_operation; return false; }#endif section->flags = flags; return true;}/*FUNCTION bfd_map_over_sectionsSYNOPSIS void bfd_map_over_sections(bfd *abfd, void (*func)(bfd *abfd, asection *sect, PTR obj), PTR obj);DESCRIPTION Calls the provided function @var{func} for each section attached to the BFD @var{abfd}, passing @var{obj} as an argument. The function will be called as if by | func(abfd, the_section, obj); This is the prefered method for iterating over sections, an alternative would be to use a loop:| section *p;| for (p = abfd->sections; p != NULL; p = p->next)| func(abfd, p, ...)*//*VARARGS2*/voidDEFUN(bfd_map_over_sections,(abfd, operation, user_storage), bfd *abfd AND void EXFUN((*operation), (bfd *abfd, asection *sect, PTR obj)) AND PTR user_storage){ asection *sect; 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_sizeSYNOPSIS boolean bfd_set_section_size(bfd *, asection *, bfd_size_type val);DESCRIPTION Sets @var{section} to the size @var{val}. If the operation is ok, then <<true>> is returned, else <<false>>. Possible error returns: o invalid_operation - Writing has started to the BFD, so setting the size is invalid*/booleanDEFUN(bfd_set_section_size,(abfd, ptr, val), bfd *abfd AND sec_ptr ptr AND bfd_size_type val){ /* Once you've started writing to any section you cannot create or change the size of any others. */ if (abfd->output_has_begun) { bfd_error = invalid_operation; return false; } ptr->_cooked_size = val; ptr->_raw_size = val; return true;}/*FUNCTION bfd_set_section_contentsSYNOPSIS boolean bfd_set_section_contents (bfd *abfd, asection *section, PTR data, file_ptr offset, bfd_size_type count);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 @var{offset} for @var{count} bytes. Normally <<true>> is returned, else <<false>>. Possible error returns are: o no_contents - The output section does not have the <<SEC_HAS_CONTENTS>> attribute, so nothing can be written to it. o and some more too This routine is front end to the back end function <<_bfd_set_section_contents>>.*/#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))booleanDEFUN(bfd_set_section_contents,(abfd, section, location, offset, count), bfd *abfd AND sec_ptr section AND PTR location AND file_ptr offset AND bfd_size_type count){ bfd_size_type sz; if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS)) { bfd_error = no_contents; return(false); } if (offset < 0 || count < 0) { bad_val: bfd_error = bad_value; return false; } sz = bfd_get_section_size_now (abfd, section); if (offset > sz || count > sz || offset + count > sz) goto bad_val; if (BFD_SEND (abfd, _bfd_set_section_contents, (abfd, section, location, offset, count))) { abfd->output_has_begun = true; return true; } return false;}/*FUNCTION bfd_get_section_contentsSYNOPSIS boolean bfd_get_section_contents (bfd *abfd, asection *section, PTR location, file_ptr offset, bfd_size_type count);DESCRIPTION This function reads 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 constuctor with the <<SEC_CONSTUCTOR>> flag set are requested, then the @var{location} is filled with zeroes. If no errors occur, <<true>> is returned, else <<false>>.*/booleanDEFUN(bfd_get_section_contents,(abfd, section, location, offset, count), bfd *abfd AND sec_ptr section AND PTR location AND file_ptr offset AND bfd_size_type count){ bfd_size_type sz; if (section->flags & SEC_CONSTRUCTOR) { memset(location, 0, (unsigned)count); return true; } if (offset < 0 || count < 0) { bad_val: bfd_error = bad_value; return false; } sz = bfd_get_section_size_now (abfd, section); if (offset > sz || count > sz || offset + count > sz) goto bad_val; if (count == 0) /* Don't bother. */ return true; return BFD_SEND (abfd, _bfd_get_section_contents, (abfd, section, location, offset, count));}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -