b.out(5) UNIX Programmmer's Manual b.out(5) _N_A_M_E _b_._o_u_t -- executable file format _D_E_S_C_R_I_P_T_I_O_N The assembler (_a_6_8) and linker (_l_d_6_8) produce executable files in this format. The system call _e_x_e_c expects files of this format. _b_._o_u_t has six sections: 1. header 2. program text 3. data text 4. symbol table 5. text relocation commands 6. data relocation commands These sections are always in the above order. The header always contains the following 8 longwords. 1 magic number (default is 407) 2 the size of the program text segment 3 the size of the initialized portion of the data segment 4 the size of the uninitialized (bss) portion of the data segment 5 the size of the symbol table 6 the size of the text relocation commands 7 the size of the data relocation commands 8 the entry location for program execution The sizes of all _b_._o_u_t segments are in bytes. The sizes of the text, data, and bss segments are rounded multiples of 4, adjusting to the next longword boundary. Starting points for all other segments depend upon the size of the preceeding segments. Listed below are the abbreviations used, for clarity, in discussing the starting points for _b_._o_u_t segments. st size of the text segment sd size of the data segment ss size of the symbol table str size of the text relocation segment The starting positions, in bytes, for _b_._o_u_t segments are: text segment 32 data segment 32 + st symbol table 32 + st + sd text relocation 32 + st + sd + ss data relocation 32 + st + sd + ss + str Three logical segments are set up when a file produced by _l_d_6_8 or _a_6_8 is loaded into core for execution. 7th Edition March 20, 1981 1 b.out(5) UNIX Programmmer's Manual b.out(5) 1. text segment - loaded starting at 0x400. 2. data segment - divided into _d_a_t_a and _b_s_s. The _d_a_t_a part contains initialized data. The _b_s_s contains uninitialized data which starts off as all 0 upon execution. The data segment may be extended by using the _b_r_k system call. 3. stack - occupies the highest possible location in the core image. The stack grows down from 0x80000. The symbol table consists of variable length entries. The first byte contains the symbol type, the next four bytes comprize a longword which contains the value of the symbol, and the remaining bytes contain the symbol name (zero-padded). The possible symbol types are: 00 undefined symbol 01 absolute symbol 02 text segment symbol 03 data segment symbol 04 bss segment symbol 06 register symbol 040 undefined external (.globl) symbol 041 absolute external symbol 042 text segment external symbol 043 data segment external symbol 044 bss segment external symbol _N_O_T_E_: _0_4_0 _i_s _O_R_e_d (40|n) _t_o _s_y_m_b_o_l _t_y_p_e_s _0_0 _- _0_4 _t_o _i_d_e_n_t_i_f_y _c_o_r_r_e_s_p_o_n_d_i_n_g _e_x_t_e_r_n_a_l _s_y_m_b_o_l_s_. _l_d_6_8 _i_n_t_e_r_p_r_e_t_s _t_y_p_e _4_0 _(_u_n_d_e_f_i_n_e_d _e_x_t_e_r_n_a_l_) _s_y_m_b_o_l_s _w_i_t_h _n_o_n_-_z_e_r_o _v_a_l_u_e_s _a_s _c_o_m_m_o_n _r_e_g_i_o_n_s _w_i_t_h _a _s_i_z_e _e_q_u_a_l _t_o _t_h_e _s_y_m_b_o_l _v_a_l_u_e_. The loader, _l_d_6_8, defines information which is undefined prior to the load, and adjusts data after linking several files together. Information from the loader is required when a word is to be relocated, or when a relocation command refers to an undefined external symbol. When files are linked, all undefined external symbols are defined, and the values of the symbols are added into the correct words in the output. Words which are to be relocated, but do not involve external references, contain the value which should be present if the file is executed without linking. If linking modifies the word, it should be adjusted by adding the new address of the beginning of the region in which it was relocated. Relocation information consists of a sequence of commands which specify how to fix up bytes in the text and data portion of the file. Relocation information comes in two parts: commands for the text segment, and commands for the data segment. Each command has four parts (_N_O_T_E_: _B_i_t _0 _i_s _t_h_e _r_i_g_h_t_m_o_s_t _b_i_t _i_n _t_h_e _b_y_t_e): 1. Bits 1-0 of the first byte specify which segment this relocation command refers to: 00 add the address of the start of the text segment 01 add the address of the start of initialized data 7th Edition March 20, 1981 2 b.out(5) UNIX Programmmer's Manual b.out(5) 02 add the address of the start of bss (uninitialized data) 03 the value of the external symbol is put into the word 2. Bits 3-2 of the first byte indicate the number of bytes to be relocated: 00 byte 01 word 02 long 3. The second word in the relocation command is used for undefined external symbols. All undefined external symbols are read into a symbol array. A C-style index is used. The value of the word is the index into the symbol array. 4. A longword is given which indicates the position of the data to be modified. This position is relative to the start of the segment, _n_o_t _t_o _t_h_e _s_t_a_r_t _o_f _t_h_e _f_i_l_e. Thus, a command to relocate the first byte of the data segment would have a position of zero. The following is the C structure for the relocation information. struct reloc { unsigned rsegment:2; /* RTEXT, RDATA, RBSS, or REXTERN */ unsigned rsize:2; /* RBYTE, RWORD, or RLONG */ unsigned rdisp:1; /* 1 => a displacement */ short rsymbol; /* id of the symbol of external relocations */ long rpos; /* position of relocation in segment */ }; _S_E_E _A_L_S_O a68(1), ld68(1), exec(2), brk(2), nlist(3) 7th Edition March 20, 1981 3