Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 #ifndef em_elf_INCLUDED 00037 #define em_elf_INCLUDED 00038 00039 /* ==================================================================== 00040 * ==================================================================== 00041 * 00042 * 00043 * Description: 00044 * 00045 * External interface to write out an elf object file. 00046 * 00047 * ==================================================================== 00048 * ==================================================================== 00049 */ 00050 00051 #include <stdio.h> /* for FILE */ 00052 #include <elf.h> /* Open64 version */ 00053 00054 00055 #ifdef __cplusplus 00056 extern "C" { 00057 #endif 00058 00059 /* the default gp value for gprel and reginfo */ 00060 extern INT GP_DISP; 00061 00062 #define Roundup(_value,_align) ((_value+(_align-1)) & (~(_align-1))) 00063 00064 typedef struct section_info SCNINFO, *pSCNINFO; 00065 00066 extern pSCNINFO Symtab_Info; 00067 extern BOOL Sixtyfour_Bit; 00068 extern pSCNINFO Options_Scn; 00069 00070 /* Given a file name 'ofilename', this procedure opens the file. If the 00071 flag 'update' is true, it opens the already existing elf file for 00072 updating. Otherwise it creates a new file. The 'elf64' argument 00073 is true if a 64bit object file is to be created. If the 'elf_trace' 00074 argument is true, some tracing output is generated. 00075 00076 It returns the file descriptor for the object file opened. 00077 */ 00078 extern INT 00079 Em_Begin_File ( 00080 char *ofilename, 00081 BOOL update, 00082 BOOL elf64, 00083 BOOL old_abi, 00084 INT isa, 00085 BOOL big_endian, 00086 BOOL pic, 00087 BOOL cpic, 00088 BOOL xgot, 00089 BOOL gp_groups, 00090 BOOL elf_trace); 00091 00092 00093 /* Write out the elf object file */ 00094 extern void 00095 Em_End_File (void); 00096 00097 00098 /* Create a new section. Its attributes are described in the arguments. 00099 It returns a pointer to the SCNINFO for the new section. 00100 */ 00101 extern pSCNINFO 00102 Em_New_Section ( 00103 char *scnname, 00104 Elf64_Word scntype, 00105 Elf64_Xword scnflags, 00106 Elf64_Xword scnentsize, 00107 Elf64_Xword scnalign); 00108 00109 00110 /* Finish processing of the section 'scninfo'. */ 00111 extern void 00112 Em_End_Section (pSCNINFO scninfo); 00113 00114 00115 /* Initialize a new buffer with the given 'size' and 'alignment' in the 00116 section 'scninfo'. This is used in the cases where we know apriori 00117 the size of the buffer to be written out. It helps by reducing the 00118 number of reallocs needed as we add bytes to the section. 00119 */ 00120 extern void 00121 Em_New_Data_Buffer (pSCNINFO scninfo, Elf64_Xword size, INT alignment); 00122 00123 /* Add an entry to the .symtab section. Returns the index for the entry */ 00124 extern Elf64_Word 00125 Em_Add_New_Symbol ( 00126 char *symname, 00127 Elf64_Addr symvalue, 00128 Elf64_Xword symsize, 00129 unsigned char symbind, 00130 unsigned char symtype, 00131 unsigned char symother, 00132 Elf64_Half symshndx); 00133 00134 00135 /* enter a symbol with name 'symname', symbol binding 'symbind' and 00136 type 'symtype' as UNDEFINED into the symbol table. 00137 */ 00138 extern Elf64_Word 00139 Em_Add_New_Undef_Symbol ( 00140 char *symname, 00141 unsigned char symbind, 00142 unsigned char symtype, 00143 unsigned char symother); 00144 00145 00146 /* Add a new symbol with name 'symname', size 'symsize' and symbol 00147 binding 'symbind' to the symbol table as a COMMON symbol. 00148 */ 00149 extern Elf64_Word 00150 Em_Add_New_Common_Symbol ( 00151 char *symname, 00152 Elf64_Xword symsize, 00153 unsigned char symbind, 00154 unsigned char symother); 00155 00156 /* Add a new weak symbol entry with the name 'weakname'. Use the same 00157 attributes as the symbol table entry with index 'symindex'. 00158 */ 00159 extern Elf64_Word 00160 Em_Add_New_Weak_Symbol ( 00161 char *weakname, 00162 unsigned char symtype, 00163 unsigned char symother, 00164 Elf64_Word symindex); 00165 00166 00167 /* Define the symbol with index 'symindex' to have the value 'symvalue' and 00168 the size 'symsize' in the section 'scninfo'. This is to define a symbol 00169 that was earlier entered as undefined. 00170 */ 00171 extern void 00172 Em_Define_Symbol ( 00173 Elf64_Word symindex, 00174 Elf64_Addr symvalue, 00175 Elf64_Xword symsize, 00176 pSCNINFO scninfo); 00177 00178 /* Undefine a symbol that was previously entered */ 00179 extern void Em_Undefine_Symbol (Elf64_Word symindex); 00180 00181 /* Set the binding for a symbol that was previously entered */ 00182 extern void Em_Set_Symbol_Binding (Elf64_Word symindex, unsigned char symbind); 00183 00184 extern Elf64_Addr 00185 Em_Get_Symbol_Value (Elf64_Word symindex); 00186 00187 extern char * 00188 Em_Get_Symbol_Name (Elf64_Word symindex); 00189 00190 /* Add a new relocation entry to the section 'scninfo'. */ 00191 extern void 00192 Em_Add_New_Rel ( 00193 Elf64_Word symindex, 00194 unsigned char reltype, 00195 Elf64_Addr reloffset, 00196 pSCNINFO scninfo); 00197 00198 00199 /* Add a new entry to the Rela section for the section 'scninfo'. */ 00200 extern void 00201 Em_Add_New_Rela ( 00202 Elf64_Word symindex, 00203 unsigned char reltype, 00204 Elf64_Addr reloffset, 00205 Elf64_Sxword addend, 00206 pSCNINFO scninfo); 00207 00208 /* Add a new composite relocation entry to the Rela section. 00209 * For the 32bit case, emit multiple relocations. 00210 */ 00211 extern void 00212 Em_Add_New_Composite_Rela ( Elf64_Rela *preloc, pSCNINFO scninfo ); 00213 00214 /* Change the origin for the section. Subsequent calls to 00215 * Em_Add_Bytes_To_Scn will add stuff at the new origin. 00216 */ 00217 extern void 00218 Em_Change_Section_Origin ( pSCNINFO scn, Elf64_Xword scn_ofst ); 00219 00220 /* Change the section alignment, if it is less than 'scn_align'. */ 00221 extern void 00222 Em_Change_Section_Alignment ( pSCNINFO scn, Elf64_Word scn_align ); 00223 00224 00225 /* write out 'length' number of bytes from the buffer 'input_buf', to the 00226 section 'scninfo' with the alignment 'align'. Any empty space is padded 00227 with zeros. 00228 00229 This routine can be called with 'length' equal to 0 to just align 00230 the current location in the section to the specified alignment 'align' 00231 without acutally writing out any bytes. 00232 */ 00233 extern Elf64_Xword 00234 Em_Add_Bytes_To_Scn ( 00235 pSCNINFO scninfo, 00236 void *input_buf, 00237 Elf64_Xword length, 00238 Elf64_Word align); 00239 00240 00241 /* write out 'length' number of bytes containing zero to the section 00242 'scninfo' with alignment 'align. 00243 */ 00244 extern Elf64_Xword 00245 Em_Add_Zeros_To_Scn ( 00246 pSCNINFO scninfo, 00247 Elf64_Word length, 00248 Elf64_Word align); 00249 00250 00251 /* Write out an "symbol + constant" expression at the current location in 00252 the section 'scninfo'. The 'symindex' points to the symbol and 'addend' 00253 is the constant value. 00254 */ 00255 extern Elf64_Xword 00256 Em_Add_Address_To_Scn ( 00257 pSCNINFO scninfo, 00258 Elf64_Word symindex, 00259 Elf64_Sxword addend, 00260 Elf64_Word align); 00261 00262 /* Write out a section displacement expression at the current location in 00263 the section 'scninfo'. The 'symindex' points to the symbol and 'addend' 00264 is the constant value. 00265 */ 00266 extern Elf64_Xword 00267 Em_Add_Displacement_To_Scn ( 00268 pSCNINFO scninfo, 00269 Elf64_Word symindex, 00270 Elf64_Sxword addend, 00271 Elf64_Word align); 00272 00273 /* Set the sh_link field of a section. */ 00274 extern void Em_Set_sh_link (pSCNINFO scn, Elf64_Word link); 00275 00276 /* Set the sh_info field of a section. */ 00277 extern void Em_Set_sh_info (pSCNINFO scn, Elf64_Word info); 00278 00279 /* For a given 'scn' return its elf section index. */ 00280 extern size_t Em_Get_Section_Index (pSCNINFO scn); 00281 00282 /* For a given 'scn' return its section offset */ 00283 extern Elf64_Xword Em_Get_Section_Offset (pSCNINFO scn); 00284 00285 extern char *Em_Get_Section_Name (pSCNINFO scn); 00286 extern Elf64_Word Em_Get_Section_Type (pSCNINFO scn); 00287 extern Elf64_Word Em_Get_Section_Flags (pSCNINFO scn); 00288 extern Elf64_Word Em_Get_Section_Entsize (pSCNINFO scn); 00289 extern Elf64_Word Em_Get_Section_Align (pSCNINFO scn); 00290 extern Elf64_Word Em_Get_Section_Info (pSCNINFO scn); 00291 00292 /* Create a section symbol for the given section, if it does not already 00293 exist. In any case, return the symindex of the section symbol. */ 00294 extern Elf64_Word Em_Create_Section_Symbol (pSCNINFO scninfo); 00295 00296 extern void 00297 Em_Write_Reginfo ( 00298 Elf64_Addr gprvalue, 00299 Elf64_Word gprmask, 00300 Elf64_Word fprmask, 00301 BOOL pure_abi); 00302 00303 /* Add a new event to the .events section. The 'operand1' and 'operand2' 00304 parameters are not needed for most of the event kinds. For those 00305 cases, the caller should pass 0 for these arguments. All offsets 00306 passed as parameters should be byte offsets. The following event 00307 kinds need valid operands: 00308 00309 EK_IF_ENTRY: operand1 is offset in interface scn. 00310 00311 EK_FCALL_LOCAL, 00312 EK_FCALL_EXTERN, 00313 EK_FCALL_EXTERN_BIG: operand1 is elf symbol index of called proc. 00314 00315 EK_SWITCH_{32,64}: operand1 is gprel boolean, 00316 operand2 is jumptable address, 00317 operand3 is number of table entries. 00318 */ 00319 extern void 00320 Em_Add_New_Event ( 00321 Elf64_Word ev_kind, 00322 Elf64_Word ev_ofst, 00323 Elf64_Word operand1, 00324 Elf64_Word operand2, 00325 Elf64_Word operand3, 00326 pSCNINFO scn); 00327 00328 /* Add a new entry to the .contents section. */ 00329 extern void 00330 Em_Add_New_Content ( 00331 Elf64_Word con_kind, 00332 Elf64_Xword con_ofst, 00333 Elf64_Word operand1, 00334 Elf64_Word operand2, 00335 pSCNINFO scn); 00336 00337 /* Add a new entry to the .options section. */ 00338 extern void 00339 Em_Add_New_Option ( 00340 Elf32_Byte option_kind, 00341 Elf32_Section option_section, 00342 Elf32_Word option_info, 00343 void *buffer, 00344 Elf32_Byte length); 00345 00346 /* Add a new entry to the .interface section. */ 00347 00348 extern void 00349 Em_Add_New_Interface ( 00350 Elf64_Word length, 00351 Elf64_Byte *data); 00352 00353 /* Add a comment string; 00354 * if the string contains no colons (':'), 00355 * then assume we are only passing the toolname, 00356 * and this routine will go ahead and add the version information. 00357 * E.g. can pass "be" or "be::4.00:". 00358 */ 00359 extern void Em_Add_Comment (char *s); 00360 00361 /* end unwind section (if any). 00362 * must be called before Em_End_File. 00363 * if trace_file is set then will dump ascii form to file. 00364 */ 00365 extern void Em_End_Unwind (FILE *trace_file, pSCNINFO text_scn); 00366 00367 /* must be called after Em_End_File */ 00368 extern void Em_Cleanup_Unwind (void); 00369 00370 00371 #ifdef __cplusplus 00372 } 00373 #endif 00374 00375 #endif /* em_elf_INCLUDED */