a.out.h 头文件分析 \linux-1.0\linux\include\linux\a.out.h
生活随笔
收集整理的這篇文章主要介紹了
a.out.h 头文件分析 \linux-1.0\linux\include\linux\a.out.h
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#ifndef __A_OUT_GNU_H__
#define __A_OUT_GNU_H__#define __GNU_EXEC_MACROS__#ifndef __STRUCT_EXEC_OVERRIDE__//定義執行文件結構
struct exec
{unsigned long a_info; /* Use macros N_MAGIC, etc for access */unsigned a_text; /* length of text, in bytes */unsigned a_data; /* length of data, in bytes */unsigned a_bss; /* length of uninitialized data area for file, in bytes */unsigned a_syms; /* length of symbol table data in file, in bytes */unsigned a_entry; /* start address */unsigned a_trsize; /* length of relocation info for text, in bytes */unsigned a_drsize; /* length of relocation info for data, in bytes */
};#endif /* __STRUCT_EXEC_OVERRIDE__ *///機器類型設定
/* these go in the N_MACHTYPE field */
enum machine_type {
#if defined (M_OLDSUN2)M__OLDSUN2 = M_OLDSUN2,
#elseM_OLDSUN2 = 0,
#endif
#if defined (M_68010)M__68010 = M_68010,
#elseM_68010 = 1,
#endif
#if defined (M_68020)M__68020 = M_68020,
#elseM_68020 = 2,
#endif
#if defined (M_SPARC)M__SPARC = M_SPARC,
#elseM_SPARC = 3,
#endif/* skip a bunch so we don't run into any of sun's numbers */M_386 = 100,
};//定義MAGIC地址為32位的有效值。0-16位
#if !defined (N_MAGIC)
#define N_MAGIC(exec) ((exec).a_info & 0xffff)
#endif//獲取機器類型 16-23位
#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))//標記 24-31位
#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)//設定Magic,機器類型,標記
#define N_SET_INFO(exec, magic, type, flags) \((exec).a_info = ((magic) & 0xffff) \| (((int)(type) & 0xff) << 16) \| (((flags) & 0xff) << 24))//單獨設定Magic值
#define N_SET_MAGIC(exec, magic) \((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))//設定機器類型
#define N_SET_MACHTYPE(exec, machtype) \((exec).a_info = \((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))//設定機器標記
#define N_SET_FLAGS(exec, flags) \((exec).a_info = \((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))//不純凈的執行方式
/* Code indicating object file or impure executable. */
#define OMAGIC 0407//純凈的執行方式
/* Code indicating pure executable. */
#define NMAGIC 0410//需求頁執行方式
/* Code indicating demand-paged executable. */
#define ZMAGIC 0413//帶有頭文件的需求頁執行方式
/* This indicates a demand-paged executable with the header in the text. The first page is unmapped to help trap NULL pointer references */
#define QMAGIC 0314//核心文件執行方式
/* Code indicating core file. */
#define CMAGIC 0421//判斷是不是沒有定義的執行方式 1為該執行方式沒有定義 0為已經定義的執行方式
#if !defined (N_BADMAG)
#define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \&& N_MAGIC(x) != NMAGIC \&& N_MAGIC(x) != ZMAGIC \&& N_MAGIC(x) != QMAGIC)
#endif//獲取1024空間存放程序信息后的剩余的大小。
#define _N_HDROFF(x) (1024 - sizeof (struct exec))//獲取TEXT文本的偏移地址
//如果為按需求頁執行方式(ZMAGIC); 剩余文本空間為1024;
//如果為帶有頭文件的需求頁執行方式(QMAGIC); 剩余文本空間為0;
//如果2者都不是 剩余文本空間為執行程序空間的大小;
#if !defined (N_TXTOFF)
#define N_TXTOFF(x) \(N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \(N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
#endif//獲取DATA數據的偏移地址
#if !defined (N_DATOFF)
#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
#endif//獲取重新配置Text數據的偏移地址
#if !defined (N_TRELOFF)
#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
#endif//獲取重新配置dat啊數據的偏移地址
#if !defined (N_DRELOFF)
#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
#endif//獲取標志表數據的偏移地址
#if !defined (N_SYMOFF)
#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
#endif//獲取BSS數據的偏移地址
#if !defined (N_STROFF)
#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
#endif//TEXT地址 如果為 帶有頭文件的需求頁執行方式 地址為4096 不是為0
/* Address of text segment in memory after it is loaded. */
#if !defined (N_TXTADDR)
#define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
#endif//段的大小設定
/* Address of data segment in memory after it is loaded.Note that it is up to you to define SEGMENT_SIZEon machines not listed here. */
#if defined(vax) || defined(hp300) || defined(pyr)
#define SEGMENT_SIZE page_size
#endif
#ifdef sony
#define SEGMENT_SIZE 0x2000 //8192
#endif /* Sony. */
#ifdef is68k
#define SEGMENT_SIZE 0x20000 //131072
#endif
#if defined(m68k) && defined(PORTAR)
#define PAGE_SIZE 0x400 //1024
#define SEGMENT_SIZE PAGE_SIZE //4096
#endif//linux段的大小設定 1024
#ifdef linux
#include <linux/page.h>
#define SEGMENT_SIZE 1024
#endif//段的大小。需要段X×每個段的大小
#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))//執行程序Text文件的結束點。
#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)//獲取執行程序DATA數據的地址
//如果為不純凈的執行方式 在TEXT文件結束點;
//如果為非 地址為X的TEXT位置×每個段的大小
#ifndef N_DATADDR
#define N_DATADDR(x) \(N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \: (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
#endif/* Address of bss segment in memory after it is loaded. */
//獲取執行程序BSS數據的地址
#if !defined (N_BSSADDR)
#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
#endif//定義nList列表結構
#if !defined (N_NLIST_DECLARED)
struct nlist {union {char *n_name;struct nlist *n_next;long n_strx;} n_un; //統一4位的unionunsigned char n_type; //列表類型char n_other; //列表它項short n_desc; //減少值unsigned long n_value; //列表值
};
#endif /* no N_NLIST_DECLARED. *///定義必要的宏!
#if !defined (N_UNDF)
#define N_UNDF 0
#endif
#if !defined (N_ABS)
#define N_ABS 2
#endif
#if !defined (N_TEXT)
#define N_TEXT 4
#endif
#if !defined (N_DATA)
#define N_DATA 6
#endif
#if !defined (N_BSS)
#define N_BSS 8
#endif
#if !defined (N_FN)
#define N_FN 15
#endif#if !defined (N_EXT)
#define N_EXT 1
#endif
#if !defined (N_TYPE)
#define N_TYPE 036
#endif
#if !defined (N_STAB)
#define N_STAB 0340
#endif/* The following type indicates the definition of a symbol as beingan indirect reference to another symbol. The other symbolappears as an undefined reference, immediately following this symbol.Indirection is asymmetrical. The other symbol's value will be usedto satisfy requests for the indirect symbol, but not vice versa.If the other symbol does not have a definition, libraries willbe searched to find a definition. */
#define N_INDR 0xa/* The following symbols refer to set elements.All the N_SET[ATDB] symbols with the same name form one set.Space is allocated for the set in the text section, and each setelement's value is stored into one word of the space.The first word of the space is the length of the set (number of elements).The address of the set is made into an N_SETV symbolwhose name is the same as the name of the set.This symbol acts like a N_DATA global symbolin that it can satisfy undefined external references. *///元素標記
/* These appear as input to LD, in a .o file. */
#define N_SETA 0x14 /* Absolute set element symbol */
#define N_SETT 0x16 /* Text set element symbol */
#define N_SETD 0x18 /* Data set element symbol */
#define N_SETB 0x1A /* Bss set element symbol *//* This is output from LD. */
#define N_SETV 0x1C /* Pointer to set vector in data area. */#if !defined (N_RELOCATION_INFO_DECLARED)
/* This structure describes a single relocation to be performed.The text-relocation section of the file is a vector of these structures,all of which apply to the text section.Likewise, the data-relocation section applies to the data section. *///重新分配信息結構8位,2整數大小
struct relocation_info
{//重新分配地址/* Address (within segment) to be relocated. */int r_address;//標號數/* The meaning of r_symbolnum depends on r_extern. */unsigned int r_symbolnum:24;//pcrel偏移位/* Nonzero means value is a pc-relative offsetand it should be relocated for changes in its own addressas well as for changes in the symbol or section specified. */unsigned int r_pcrel:1;//分配域的長度/* Length (as exponent of 2) of the field to be relocated.Thus, a value of 2 indicates 1<<2 bytes. */unsigned int r_length:2;//擴展位/* 1 => relocate with value of symbol.r_symbolnum is the index of the symbolin file's the symbol table.0 => relocate with the address of a segment.r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS(the N_EXT bit may be set also, but signifies nothing). */ unsigned int r_extern:1;//pad值/* Four bits that aren't used, but when writing an object fileit is desirable to clear them. */
#ifdef NS32Kunsigned r_bsr:1;unsigned r_disp:1;unsigned r_pad:2;
#elseunsigned int r_pad:4;
#endif
};
#endif /* no N_RELOCATION_INFO_DECLARED. */#endif /* __A_OUT_GNU_H__ */
總結
以上是生活随笔為你收集整理的a.out.h 头文件分析 \linux-1.0\linux\include\linux\a.out.h的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《码出高效-JAVA开发手册》
- 下一篇: linux 其他常用命令