Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从对象文件中,有些是 根据其他信息合成*/ 旗语旗; #定义SEC_NO_标志0x000 /*告诉操作系统在加载时为此节分配空间。 对于包含调试信息的部分,这是明确的 只是*/ #定义SEC_ALLOC 0x001 /*告诉操作系统在加载时从文件加载节。 _C_Linux_Structure_Sections_Bfd - Fatal编程技术网

从对象文件中,有些是 根据其他信息合成*/ 旗语旗; #定义SEC_NO_标志0x000 /*告诉操作系统在加载时为此节分配空间。 对于包含调试信息的部分,这是明确的 只是*/ #定义SEC_ALLOC 0x001 /*告诉操作系统在加载时从文件加载节。

从对象文件中,有些是 根据其他信息合成*/ 旗语旗; #定义SEC_NO_标志0x000 /*告诉操作系统在加载时为此节分配空间。 对于包含调试信息的部分,这是明确的 只是*/ #定义SEC_ALLOC 0x001 /*告诉操作系统在加载时从文件加载节。 ,c,linux,structure,sections,bfd,C,Linux,Structure,Sections,Bfd,从对象文件中,有些是 根据其他信息合成*/ 旗语旗; #定义SEC_NO_标志0x000 /*告诉操作系统在加载时为此节分配空间。 对于包含调试信息的部分,这是明确的 只是*/ #定义SEC_ALLOC 0x001 /*告诉操作系统在加载时从文件加载节。 这对于.bss部分是明确的*/ #定义SEC_加载0x002 /*该部分包含仍要重新定位的数据,因此 还有一些搬迁信息*/ #定义SEC_RELOC 0x004 #如果0/*已过时*/ #定义SEC_BALIGN 0x008 #恩迪夫 /*向操

从对象文件中,有些是 根据其他信息合成*/ 旗语旗; #定义SEC_NO_标志0x000 /*告诉操作系统在加载时为此节分配空间。 对于包含调试信息的部分,这是明确的 只是*/ #定义SEC_ALLOC 0x001 /*告诉操作系统在加载时从文件加载节。 这对于.bss部分是明确的*/ #定义SEC_加载0x002 /*该部分包含仍要重新定位的数据,因此 还有一些搬迁信息*/ #定义SEC_RELOC 0x004 #如果0/*已过时*/ #定义SEC_BALIGN 0x008 #恩迪夫 /*向操作系统发送的一个信号,表示该节包含只读内容 数据*/ #定义SEC_只读0x010 /*该部分仅包含代码*/ #定义SEC_代码0x020 /*该部分仅包含数据*/ #定义SEC_数据0x040 /*该部分将驻留在ROM中*/ #定义SEC_ROM 0x080 /*该部分包含构造函数信息。本节 类型由链接器用于创建构造函数和 所使用的析构函数。当后端看到一个符号时 它将创建一个新的 名称类型(例如)的部分,附加 将符号添加到它,并构建重新定位。建立列表 对于构造函数,链接器所要做的就是将所有 调用节并重新定位数据 包含在-正是它将在其上形成的操作中 标准数据*/ #定义SEC_构造函数0x100 /*该部分是一个构件,应放置在 文本、数据或bss节(?)的结尾*/ #定义SEC_构造函数_文本0x1100 #定义SEC_构造函数_数据0x2100 #定义SEC_构造函数_BSS 0x3100 /*节具有内容-数据节可以是 | ; 可以创建调试部分 */ #定义SEC_的内容为0x200 /*指向链接器的不输出节的指令 即使它有通常会被写入的信息*/ #定义SEC_NEVER_LOAD 0x400 /*该节是COFF共享库节。这面旗是 仅适用于链接器。如果此类型的节出现在 对于输入文件,链接器必须将其复制到输出文件 无需更改vma或大小。菲克斯梅:尽管如此 本来是打算通用的,真的是COFF 特定的(并重命名该标志以指示此情况)。信息技术 可能更干净,有一些更一般的机制 允许后端控制链接器的操作 部分*/ #定义SEC_COFF_共享_库0x800 /*该部分为公共部分(可定义符号 多次,符号的值是 它需要的空间,最大的符号值是1 使用)。大多数目标正好有一个(我们 翻译成bfd_com_section_ptr),但ECOFF有两个*/ #定义SEC_为公共0x8000 /*该部分仅包含调试信息。对于 例如,这是为ELF.debug和.stab节设置的。 条带测试此标志,以查看是否可以删除某个节 丢弃*/ #定义SEC_调试0x10000 /*本节内容保存在指向的内存中 通过内容字段。这是由 bfd_获取_section_内容,并从中检索数据 记忆,如果合适的话*/ #在内存0x20000中定义秒 /*节结束标志*/ /*节的虚拟内存地址—它将位于的位置 在运行时。符号将根据此重新定位。这个 用户设置的vma标志由bfd维护;如果未设置,则 后端可以分配地址(例如,在中,其中 的默认地址取决于特定的 目标和各种标志)*/ bfd_vma vma; 布尔用户集; /*节的加载地址-它将位于 rom图像;实际上只用于编写节头 信息*/ bfd_vma lma; /*将要输出的节的大小(以字节为单位)。 包含一个值,即使该节没有内容(例如 的大小)。这将在搬迁后填写*/ bfd_尺寸(类型)(熟尺寸);; /*节在磁盘上的原始大小,以字节为单位。通常这个 值与大小相同,但如果有 如果完成,则该值将更大*/ bfd尺寸类型原始尺寸; /*如果要输出此部分,则此值为 输入中第一个字节的输出部分的偏移量 节。例如,如果这将从中的第100个字节开始 在输出部分,该值将为100*/ bfd_vma输出_偏移量; /*用于映射输出的输出部分*/ 结构部分*输出部分; /*截面的对齐要求,以2的指数表示- e、 例如,3与2^3(或8)对齐*/ 无符号整数幂; /*如果是一个输入段,则指向重定位向量的指针 本节中的数据记录*/ struct reloc_cache_条目*重定位; /*如果是输出节,则是指向指向的指针向量的指针 本节中数据的重新定位记录*/ struct reloc\u cache\u条目**orelocation; /*上述其中一项中的重新定位记录数*/ 无符号重新登录计数; /*下面的信息是特定于后端的,并不总是使用 或更新*/ /*节数据的文件位置*/ 文件\u ptr filepos; /*重新定位信息的文件位置*/ 文件\u ptr rel\u filepos; /*行数据的文件位置*/ 文件\u ptr行\u filepos; /*指向应用程序数据的指针*/ PTR用户数据; /*如果设置了SEC_IN_内存标志,则指向实际的 内容*/ 无符号字符*内容; /*中的附加行号
unsigned int number_of_sections(bfd *abfd)
{
  unsigned int numSections = 0;
  numSections =  bfd_count_sections(abfd);
  return numSections;
} 

int main (int argc, char *argv[])
{
  bfd *ibfd = NULL;
  char filename[80];
  char *fptr = &filename[0];
  unsigned int numSections = 0;

  if (argc < 2)
    {
      printf("Argc < 2\n");
      exit(EXIT_FAILURE);
    }
  else
    {
      bfd_init();
      printf("filename = %s\n", argv[1]);
      ibfd = bfd_openr(argv[1], NULL);
      numSections = number_of_sections(ibfd);
      printf("num sections = %d\n", numSections);
      bfd_close(ibfd);
    }
  return 1;
}
(gdb) print abfd
$1 = (bfd *) 0x85c010
(gdb) print *abfd
$2 = {filename = 0x0, xvec = 0x7fffffffe06f, iostream = 0x7fff20 <bfd_elf64_x86_64_vec> "\211\345X", cacheable = (unknown: 8773984), target_defaulted = false, lru_prev = 0x7f6d40 <cache_iovec>, lru_next = 0x85c010, where = 8765456, opened_once = false, mtime_set = false, mtime = 0, ifd = 0, format = bfd_unknown, direction = read_direction, flags = 0, origin = 0, output_has_begun = false, sections = 0x85d180, section_count = 4218960, start_address = 8769872, symcount = 251, outsymbols = 0x130, arch_info = 0x0, arelt_data = 0x0, my_archive = 0x0, next = 0x0, archive_head = 0x0, has_armap = false, link_next = 0x0, archive_pass = 8673856, tdata = {aout_data = 0x0, aout_ar_data = 0x0, oasys_obj_data = 0x0, oasys_ar_data = 0x0, coff_obj_data = 0x0, pe_obj_data = 0x0, xcoff_obj_data = 0x0, ecoff_obj_data = 0x0, ieee_data = 0x0, ieee_ar_data = 0x0, srec_data = 0x0, tekhex_data = 0x0, elf_obj_data = 0x0, nlm_obj_data = 0x0, bout_data = 0x0, sun_core_data = 0x0, trad_core_data = 0x0, som_data = 0x0, hpux_core_data = 0x0, hppabsd_core_data = 0x0, sgi_core_data = 0x0, lynx_core_data = 0x0, osf_core_data = 0x0, cisco_core_data = 0x0, versados_data = 0x0, any = 0x0}, usrdata = 0x0, memory = {chunk_size = 0, chunk = 0x0, object_base = 0x0, next_free = 0x0, chunk_limit = 0x0, temp = {tempint = 0, tempptr = 0x0}, alignment_mask = 0, chunkfun = 0x85c140, freefun = 0x7, extra_arg = 0x21, use_extra_arg = 0, maybe_empty_object = 0, alloc_failed = 0}}
(gdb) print *(abfd->sections)
$4 = {name = 0x0, index = 0, next = 0x0, flags = 0, vma = 0, user_set_vma = false, lma = 0, _cooked_size = 0, _raw_size = 0, output_offset = 0, output_section = 0x0, alignment_power = 0, relocation = 0x0, orelocation = 0x0, reloc_count = 0, filepos = 0, rel_filepos = 0, line_filepos = 0, userdata = 0x0, contents = 0x0, lineno = 0x0, lineno_count = 0, moving_line_filepos = 0, target_index = 0, used_by_bfd = 0x0, constructor_chain = 0x0, owner = 0x0, reloc_done = false, symbol = 0x0, symbol_ptr_ptr = 0x0, link_order_head = 0x0, link_order_tail = 0x0}
struct _bfd 
{
 /* The filename the application opened the BFD with.  */
CONST char *filename;                

 /* A pointer to the target jump table.             */
const struct bfd_target *xvec;

 /* To avoid dragging too many header files into every file that
   includes `<<bfd.h>>', IOSTREAM has been declared as a "char
   *", and MTIME as a "long".  Their correct types, to which they
   are cast when used, are "FILE *" and "time_t".    The iostream
   is the result of an fopen on the filename. */
char *iostream;

 /* Is the file descriptor being cached?  That is, can it be closed as
   needed, and re-opened when accessed later?  */

boolean cacheable;

 /* Marks whether there was a default target specified when the
   BFD was opened. This is used to select which matching algorithm
   to use to choose the back end. */

boolean target_defaulted;

 /* The caching routines use these to maintain a
   least-recently-used list of BFDs */

struct _bfd *lru_prev, *lru_next;

 /* When a file is closed by the caching routines, BFD retains
   state information on the file here: */

file_ptr where;              

 /* and here: (``once'' means at least once) */

boolean opened_once;

 /* Set if we have a locally maintained mtime value, rather than
   getting it from the file each time: */

boolean mtime_set;

 /* File modified time, if mtime_set is true: */

long mtime;          

 /* Reserved for an unimplemented file locking extension.*/

int ifd;

 /* The format which belongs to the BFD. (object, core, etc.) */

bfd_format format;

 /* The direction the BFD was opened with*/

enum bfd_direction {no_direction = 0,
                    read_direction = 1,
                    write_direction = 2,
                    both_direction = 3} direction;

 /* Format_specific flags*/

flagword flags;              

 /* Currently my_archive is tested before adding origin to
   anything. I believe that this can become always an add of
   origin, with origin set to 0 for non archive files.   */

file_ptr origin;             

 /* Remember when output has begun, to stop strange things
   from happening. */
boolean output_has_begun;

 /* Pointer to linked list of sections*/
struct sec  *sections;

 /* The number of sections */
unsigned int section_count;

 /* Stuff only useful for object files: 
   The start address. */
bfd_vma start_address;

 /* Used for input and output*/
unsigned int symcount;

 /* Symbol table for output BFD (with symcount entries) */
struct symbol_cache_entry  **outsymbols;             

 /* Pointer to structure which contains architecture information*/
const struct bfd_arch_info *arch_info;

 /* Stuff only useful for archives:*/
PTR arelt_data;              
struct _bfd *my_archive;      /* The containing archive BFD.  */
struct _bfd *next;            /* The next BFD in the archive.  */
struct _bfd *archive_head;    /* The first BFD in the archive.  */
boolean has_armap;           

 /* A chain of BFD structures involved in a link.  */
struct _bfd *link_next;

 /* A field used by _bfd_generic_link_add_archive_symbols.  This will
   be used only for archive elements.  */
int archive_pass;

 /* Used by the back end to hold private data. */

union 
  {
  struct aout_data_struct *aout_data;
  struct artdata *aout_ar_data;
  struct _oasys_data *oasys_obj_data;
  struct _oasys_ar_data *oasys_ar_data;
  struct coff_tdata *coff_obj_data;
  struct pe_tdata *pe_obj_data;
  struct xcoff_tdata *xcoff_obj_data;
  struct ecoff_tdata *ecoff_obj_data;
  struct ieee_data_struct *ieee_data;
  struct ieee_ar_data_struct *ieee_ar_data;
  struct srec_data_struct *srec_data;
  struct tekhex_data_struct *tekhex_data;
  struct elf_obj_tdata *elf_obj_data;
  struct nlm_obj_tdata *nlm_obj_data;
  struct bout_data_struct *bout_data;
  struct sun_core_struct *sun_core_data;
  struct trad_core_struct *trad_core_data;
  struct som_data_struct *som_data;
  struct hpux_core_struct *hpux_core_data;
  struct hppabsd_core_struct *hppabsd_core_data;
  struct sgi_core_struct *sgi_core_data;
  struct lynx_core_struct *lynx_core_data;
  struct osf_core_struct *osf_core_data;
  struct cisco_core_struct *cisco_core_data;
  struct versados_data_struct *versados_data;
  PTR any;
  } tdata;

 /* Used by the application to hold private data*/
PTR usrdata;

 /* Where all the allocated stuff under this BFD goes */
struct obstack memory;
};
typedef struct sec
{
     /* 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;

     /* Which section is it; 0..nth.      */

    int index;

     /* The next section in the list belonging to the BFD, or NULL. */

    struct sec *next;

     /* 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;

#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. */
#define SEC_ALLOC      0x001

     /* Tells the OS to load the section from the file when loading.
       This is clear for a .bss section. */
#define SEC_LOAD       0x002

     /* The section contains data still to be relocated, so there is
       some relocation information too. */
#define SEC_RELOC      0x004

#if 0    /* Obsolete ? */
#define SEC_BALIGN     0x008
#endif

     /* A signal to the OS that the section contains read only
      data. */
#define SEC_READONLY   0x010

     /* The section contains code only. */
#define SEC_CODE       0x020

     /* The section contains data only. */
#define SEC_DATA       0x040

     /* The section will reside in ROM. */
#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. */
#define SEC_CONSTRUCTOR 0x100

     /* The section is a constuctor, and should be placed at the
      end of the text, data, or bss section(?). */
#define SEC_CONSTRUCTOR_TEXT 0x1100
#define SEC_CONSTRUCTOR_DATA 0x2100
#define SEC_CONSTRUCTOR_BSS  0x3100

     /* The section has contents - a data section could be
       <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
       <<SEC_HAS_CONTENTS>> */ 
#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. */
#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. */
#define SEC_COFF_SHARED_LIBRARY 0x800

     /* The section is a common section (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. */
#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. */
#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.  */
#define SEC_IN_MEMORY 0x20000

 /*  End of section flags.  */

    /*  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;
   boolean user_set_vma;

    /*  The load address of the section - where it would be in a
       rom image; really only used for writing section header
    information. */

   bfd_vma lma;

     /* The size of the section in bytes, 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;

     /* The original size on disk of the section, in bytes.  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;

     /* If this section is going to be output, then this value is the
       offset into the output section of the first byte in the input
       section. E.g., if this was going to start at the 100th byte in
       the output section, this value would be 100. */

   bfd_vma output_offset;

     /* The output section through which to map on output. */

   struct sec *output_section;

     /* The alignment requirement of the section, as an exponent of 2 -
       e.g., 3 aligns to 2^3 (or 8). */

   unsigned int alignment_power;

     /* If an input section, a pointer to a vector of relocation
       records for the data in this section. */

   struct reloc_cache_entry *relocation;

     /* 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;

     /* The number of relocation records in one of the above  */

   unsigned reloc_count;

     /* Information below is back end specific - and not always used
       or updated.  */

     /* File position of section data    */

   file_ptr filepos;

     /* File position of relocation info */

   file_ptr rel_filepos;

     /* File position of line data       */

   file_ptr line_filepos;

     /* Pointer to data for applications */

   PTR userdata;

     /* If the SEC_IN_MEMORY flag is set, this points to the actual
       contents.  */
   unsigned char *contents;

     /* Attached line number information */

   alent *lineno;

     /* Number of line number records   */

   unsigned int lineno_count;

     /* When a section is being output, this value changes as more
       linenumbers are written out */

   file_ptr moving_line_filepos;

     /* What the section number is in the target world  */

   int target_index;

   PTR used_by_bfd;

     /* 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;

     /* The BFD which owns the section. */

   bfd *owner;

   boolean reloc_done;
  /* A symbol which points at this section only */
   struct symbol_cache_entry *symbol;
   struct symbol_cache_entry **symbol_ptr_ptr;

   struct bfd_link_order *link_order_head;
   struct bfd_link_order *link_order_tail;
} asection ;
fd = open (argv[1], O_RDONLY | O_CLOEXEC, 0);
if (fd == -1)
  die ("open");

abfd = bfd_fopen (argv[1], NULL, "r", fd);

if (!bfd_check_format (abfd, bfd_object))
  {
    bfd_close (abfd);
    die ("bfd_check_format");
  }