00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef __FAKE_H__
00037 #define __FAKE_H__
00038
00039 typedef struct an_object_file an_object_file, *an_object_file_ptr;
00040
00041 struct an_object_file {
00042
00043 an_object_file_ptr next;
00044 string name;
00045 char *map_addr;
00046 char ftype;
00047 int offset;
00048 struct {
00049 int idx_to_ipa_file_hdr;
00050 char gp_status;
00051
00052 char flags;
00053 int16 partition_grp;
00054
00055 } ipa_info;
00056 };
00057
00058 struct extern_sym {
00059 an_object_file_ptr pobj;
00060 };
00061
00062 typedef struct extern_sym EXTSYM;
00063
00064
00065
00066
00067
00068 #define STO_DEFAULT 0x0
00069 #define STO_INTERNAL 0x1
00070 #define STO_HIDDEN 0x2
00071 #define STO_PROTECTED 0x3
00072 #define STO_OPTIONAL 0x4
00073 #define STO_SC_ALIGN_UNUSED 0xff
00074
00075 #define ELF_COMMENT ".comment"
00076
00077 typedef enum {
00078 ER_ILLEGAL = -1,
00079 ER_NOERROR = 0,
00080 ER_FATAL,
00081 ER_WARNING,
00082 ER_INFO,
00083 ER_DEBUG,
00084 ER_VERBOSE,
00085 ER_ERROR,
00086 ER_MSG,
00087 ER_DEFAULT,
00088 ER_OFF
00089 }msgtype_t;
00090
00091
00092
00093
00094
00095
00096 typedef enum {
00097 ERN_IGNORED,
00098 ERN_BAD_OPTION,
00099 ERN_INTERNAL_FATAL,
00100 ERN_USAGE,
00101 ERN_ILL_FLAG,
00102 ERN_NOT_IMP,
00103 ERN_MISSARG_FATAL,
00104 ERN_CONFLICT_RFLAG,
00105 ERN_BAD_HEX,
00106 ERN_IO_FATAL,
00107 ERN_NO_OUTFILE,
00108 ERN_OBJ_FATAL,
00109 ERN_OBJ_CLASS,
00110 ERN_MALLOC,
00111 ERN_SYM_TRACE,
00112 ERN_MULT_DEF,
00113 ERN_MISMATCH_GP,
00114 ERN_MISMATCH_USGP,
00115 ERN_MISMATCH_VAL,
00116 ERN_UNDEF_EXIST,
00117 ERN_0SIZE_EXT,
00118 ERN_HALF_OVFL,
00119 ERN_OFS_OVFL,
00120 ERN_BAD_RTYPE,
00121 ERN_MISS_RLO,
00122 ERN_JMP_OVFL,
00123 ERN_JMP_OVFLS,
00124 ERN_BAD_LIT,
00125 ERN_GP_OVFL,
00126 ERN_GP_OVFLS,
00127 ERN_PRED_CONFLICT,
00128 ERN_LIBLIST_UNMATCH,
00129 ERN_LIBLIST_NOTFOUND,
00130 ERN_UNDEFINED_SYMBOL_ERROR,
00131 ERN_CNFLCT_DEF_SYM,
00132 ERN_ARCHIVE_OBJ,
00133 ERN_LOAD_OBJ,
00134 ERN_LOAD_SO,
00135 ERN_UNLOADED_SEC,
00136 ERN_ROUNDED,
00137 ERN_OVERLAP,
00138 ERN_SAMEPAGE,
00139 ERN_SHARABLE_FLGS,
00140 ERN_MIX_OBJ,
00141 ERN_NS_PIC,
00142 ERN_S_NPIC,
00143 ERN_NO_OBJ,
00144 ERN_BAD_R4K,
00145 ERN_NO_REGISTRY,
00146 ERN_NO_UPDATE,
00147 ERN_BAD_REGISTRY,
00148 ERN_REGISTRY_FAIL,
00149 ERN_BAD_NAME,
00150 ERN_SYM_NOMATCH_SEC,
00151 ERN_BAD_LOCAL,
00152 ERN_NOT_SO,
00153 ERN_WARN_RANGE,
00154 ERN_BAD_WARN,
00155 ERN_BAD_MEMBER,
00156 ERN_MULT_TXT_SEG,
00157 ERN_MESSAGE,
00158 ERN_MESSAGE2,
00159 ERN_BAD_LCL_RELOC,
00160 ERN_BAD_SYMIDX,
00161 ERN_BAD_RELOC_SYM,
00162 ERN_R4K_JUMP,
00163 ERN_NO_BACKUP_FATAL,
00164 ERN_SEARCH_LIB,
00165 ERN_BAD_IFACE_REC,
00166 ERN_CONFLICT_IFACE,
00167 ERN_MISMATCH_PCNT,
00168 ERN_MISMATCH_PTYPE,
00169 ERN_MISMATCH_PSIZE,
00170 ERN_PARM_FLOAT,
00171 ERN_MISSING_EXT,
00172 ERN_LOCAL_UNDEF,
00173 ERN_UNREF_SYM,
00174 ERN_WARN_PLACEMENT,
00175 ERN_NOFILE,
00176 ERN_NOSTAT,
00177 ERN_LSPEC_SYNTAX,
00178 ERN_LSPEC_DEFAULT_UNPLACED,
00179 ERN_ELS_REL,
00180 ERN_NOLOAD_ATTRIBUTE,
00181 ERN_UNUSED_LIB,
00182 ERN_CONFLICT_SYM,
00183 ERN_ISCN_NOT_LOADED,
00184 ERN_DELETION_ILLEGAL,
00185 ERN_INVALID_RELFOR,
00186 ERN_MISMATCHED_QUOTE,
00187 ERN_INVALID_SYM,
00188 ERN_INVALID_SYMSPEC,
00189 ERN_SYMSPEC_BADSHNDX,
00190 ERN_CANT_RESTORE_REG,
00191 ERN_GP_TOO_FAR,
00192 ERN_AVD_SEC_MISSING,
00193 ERN_AVD_SYM_MISSING,
00194 ERN_GOT_OVERFLOW,
00195 ERN_INCOMPATIBLE_MERGE_SZ,
00196 ERN_GOT_2FAR,
00197 ERN_GP_DSO,
00198 ERN_NONEST,
00199 ERN_COM_DSO,
00200 ERN_NOT_PROTECTED,
00201 ERN_NO_GOTPAGE,
00202 ERN_COM_ALIGN,
00203 ERN_LSPEC_REGEXP,
00204 ERN_CONFLICT_IFACE_FPMASK,
00205 ERN_OMIT_HEADERS,
00206 ERN_MUL_SEG,
00207 ERN_VARARG_WITH_FP,
00208 ERN_NOTIMP,
00209 ERN_OLD_OBJ,
00210 ERN_NEW_OBJ,
00211 ERN_WRONG_ALIGN,
00212 ERN_XLOCAL_MISSING,
00213 ERN_COMPILE,
00214 ERN_EXEC,
00215 ERN_NO_MEMBER,
00216 ERN_XFLAG_REPLACED,
00217 ERN_NO_IPA,
00218 ERN_BAD_DYN_ORDER,
00219 ERN_BAD_SCNIDX,
00220 ERN_IFD_OVERFLOW,
00221 ERN_QI_NOLIB,
00222 ERN_CHNG_CLASS,
00223 ERN_ARCHIVE_EMPTY,
00224 ERN_TWO_SO,
00225 ERN_LS_DUP_OSCN,
00226 ERN_NO_EXPORT,
00227 ERN_T5_NOP,
00228 ERN_MULTW_DEF,
00229 ERN_NO_CORDING,
00230 ERN_BAD_R5K,
00231 ERN_CONFLICT_WEAK_SYM,
00232 ERN_LIBLIST_OUTNAME,
00233 ERN_SPLIT_SUCCEDED,
00234 ERN_UNALIGNED_MEMBER,
00235 ERN_BAD_SEG_PLACEMENT,
00236
00237
00238
00239 ERN_INTERNAL_ERROR,
00240 ERN_INTERNAL_WARNING,
00241 ERN_ILL_FLAG_FATAL,
00242 ERN_MISSARG_WARNING,
00243 ERN_IO_ERROR,
00244 ERN_OBJ_ERROR,
00245 ERN_OBJ_WARNING,
00246 ERN_OBJ_CLASS_WHIRL,
00247 ERN_MISMATCH_GP_ERROR,
00248 ERN_RTYPE_ERROR,
00249 ERN_GP_OVFL_FATAL,
00250 ERN_BAD_ENTRY_NAME,
00251 ERN_NO_ELSPEC_FILE,
00252 ERN_INFO_MESSAGE,
00253 ERN_INFO_MESSAGE2,
00254 ERN_FATAL_MESSAGE2,
00255 ERN_OPTION_SYNTAX,
00256 ERN_NO_BACKUP_WARNING,
00257 ERN_UNDEFINED_SYMBOL_WARNING,
00258 ERN_OBJ_CLASS_WARNING,
00259
00260 ERN_SYM_UNRESOLVED_WEAK,
00261 ERN_SYM_UNRESOLVED_OPTIONAL,
00262 ERN_SYM_INHERIT_OPTIONAL,
00263 ERN_DELAY_LOAD_1,
00264 ERN_DELAY_LOAD_2,
00265 ERN_TEXT_DATA_MISMATCH,
00266 ERN_INVALID_ALIGN,
00267
00268 ERN_MISMATCH_RTYPE,
00269 ERN_MISMATCH_RSIZE,
00270 ERN_FEEDBACK_MESG_1,
00271 ERN_FEEDBACK_MESG_2,
00272 ERN_FEEDBACK_MESG_3,
00273 ERN_MULTIGOT_INVOKED,
00274 ERN_FEEDBACK_MESG_4,
00275 ERN_LSPEC_NOGPREL,
00276 ERN_CONFLICT_WEAK_SYM_2,
00277 ERN_CONFLICT_WEAK_SYM_3,
00278 ERN_CONFLICT_WEAK_SYM_4,
00279 ERN_CONFLICT_WEAK_SYM_5,
00280 ERN_MISMATCH_DATA_FUNC,
00281
00282
00283 MAX_ERN_MESSAGE
00284
00285 } error_number;
00286
00287
00288 #ifdef _64BIT_OBJECTS
00289
00290 #if defined(__GNUC__)
00291 typedef u_int64_t ADDR;
00292 typedef int64_t OFFSET;
00293 typedef int64_t FILE_SZ;
00294 #else
00295 typedef uint64 ADDR;
00296 typedef int64 OFFSET;
00297 typedef int64 FILE_SZ;
00298 #endif
00299
00300 #define ELF_ADDR Elf64_Addr
00301 #define ELF_HALF Elf64_Half
00302 #define ELF_OFF Elf64_Off
00303 #define ELF_SWORD Elf64_Sword
00304 #define ELF_SXWORD Elf64_Sxword
00305 #define ELF_WORD Elf64_Word
00306 #define ELF_XWORD Elf64_Xword
00307 #define ELF_BYTE Elf64_Byte
00308 #define ELF_SECTION Elf64_Section
00309 #define ELF_FLAGS Elf64_Xword
00310 #define ELF_SIZE Elf64_Xword
00311 #define ELF_INT Elf64_Sxword
00312
00313 #define ELFCLASS ELFCLASS64
00314
00315
00316 #define _fmt_w "w64"
00317 #define _fmt_v "lld"
00318 #define _fmt_a "llx"
00319 #define _fmt_s "llx"
00320 #define _fmt_w_a "016llx"
00321 #define _fmt_w_s "016llx"
00322
00323 #else
00324
00325 typedef uint32 ADDR;
00326 typedef int32 OFFSET;
00327 typedef int32 FILE_SZ;
00328
00329 #define ELF_ADDR Elf32_Addr
00330 #define ELF_HALF Elf32_Half
00331 #define ELF_OFF Elf32_Off
00332 #define ELF_SWORD Elf32_Sword
00333 #define ELF_WORD Elf32_Word
00334 #define ELF_SIZE Elf32_Word
00335 #define ELF_INT Elf32_Sword
00336
00337 typedef longlong_t ELF_SXWORD;
00338 typedef unsigned char ELF_BYTE;
00339 typedef unsigned short ELF_SECTION;
00340 #define ELF_FLAGS Elf32_Word
00341
00342 #define ELFCLASS ELFCLASS32
00343
00344
00345
00346 #define _fmt_w "w32"
00347 #define _fmt_v "d"
00348 #define _fmt_a "x"
00349 #define _fmt_s "x"
00350 #define _fmt_w_a "08x"
00351 #define _fmt_w_s "08x"
00352
00353 #endif
00354
00355
00356
00357 #define MALLOC_ASSERT(addr) \
00358 if (addr == 0) {perror("malloc failed");exit(1);}
00359
00360 #define FOPEN(filename, type) \
00361 fopen((const char *)(filename), (const char *)(type))
00362
00363 #define FDOPEN(fid, type) \
00364 fdopen((int)(fid), (const char *)(type))
00365
00366 #define FCLOSE(stream) \
00367 fclose ((FILE *)(stream))
00368
00369 #if 0
00370 #define FSEEK(stream, offset, whence) \
00371 fseek ((FILE *)(stream), (long)(offset), (int)(whence))
00372 #endif
00373
00374 #define FTRUNCATE(fildes, length) \
00375 ftruncate ((int)(fildes), (off_t)(length)
00376
00377 #define OPEN(path, oflag, mode) \
00378 open((char *)(path), (int)(oflag), (int)(mode))
00379
00380 #define LSEEK(fid, offset, whence) \
00381 lseek((int)(fid), (off_t)(offset), (int)(whence))
00382
00383 #define READ(fid, buf, nbyte) \
00384 read((int)(fid), (void *)(buf), (unsigned)(nbyte))
00385
00386 #define WRITE(fid, buf, nbyte) \
00387 write((int)(fid), (const void *)(buf), (unsigned)(nbyte))
00388
00389 #define CLOSE(fid) \
00390 close((int)(fid))
00391
00392 #define FCHMOD(fid, mode) \
00393 fchmod((int)(fid), (mode_t)(mode))
00394
00395 #define UNLINK(path) \
00396 unlink((const char *)(path))
00397
00398 #define MKDIR(path, mode) \
00399 mkdir((const char *)(path), (mode_t)(mode))
00400
00401 #define RMDIR(path) \
00402 rmdir((const char *)(path))
00403
00404 #define STAT(path, buf) \
00405 stat((const char *)(path), (struct stat *) (buf))
00406
00407 #define FSTAT(fid, buf) \
00408 fstat((int)(fid), (buf))
00409
00410 #define FSTATVFS(fid, buf) \
00411 fstatvfs((int)(fid), (buf))
00412
00413 #define MMAP(addr, len, prot, flags, fd, off) \
00414 mmap((void *)(addr), (int)(len), (int)(prot), (int)(flags), (int)(fd), \
00415 (off_t)(off))
00416
00417 #define PERROR(s) \
00418 perror((char *) s)
00419
00420 #define MUNMAP(addr, len) \
00421 munmap((void *)(addr), (int)(len))
00422
00423 #define MALLOC(nbytes) \
00424 malloc((size_t)(nbytes))
00425
00426 #define FREE(ptr) \
00427 free((void *) (ptr))
00428
00429 #define REALLOC(ptr, size) \
00430 realloc((void *)(ptr), (size_t)(size))
00431
00432 #define CALLOC(nelem, elsize) \
00433 calloc((size_t)(nelem), (size_t)(elsize))
00434
00435 #define ALLOCA(size) \
00436 alloca((unsigned int)(size))
00437
00438 #define MEMCCPY(s1, s2, c, n) \
00439 memccpy((void *)(s1), (void *)(s2), (int)(c), (size_t)(n))
00440
00441 #define MEMCHR(s, c, n) \
00442 memchr((void *)(s), (int)(c), (size_t)(n))
00443
00444 #define MEMCPY(s1, s2, n) \
00445 memcpy((void *)(s1), (void *)(s2), (size_t)(n))
00446
00447 #define MEMSET(s, c, n) \
00448 memset((void *)(s), (int)(c), (size_t)(n))
00449
00450 #define MEMCMP(s1, s2, n) \
00451 memcmp((void *)(s1), (void *)(s2), (size_t)(n))
00452
00453 #ifndef BZERO
00454 #define BZERO(b, len) \
00455 bzero((void *)(b), (int)(len))
00456 #endif
00457
00458 #ifndef BCOPY
00459 #define BCOPY(src, dst, len) \
00460 bcopy((const void *)(src), (void *)(dst), (int)(len))
00461 #endif
00462
00463 #define PCREATEVE(path, argv, envp) \
00464 pcreateve((const char *)(path), (char *const *)(argv), \
00465 (char *const *)(envp))
00466
00467 #define WAIT(stat) \
00468 wait((int *)(stat))
00469
00470
00471 #ifdef __cplusplus
00472 extern "C" {
00473 #endif
00474
00475 extern void msg(int, int, ...);
00476
00477 extern char* concat_names(const char*, const char*);
00478
00479 extern EXTSYM *
00480 slookup_mext(char *);
00481
00482 extern void read_one_section (int, an_object_file_ptr);
00483
00484 extern void
00485 merge_ext(an_elf_sym_record *, char *, int, an_object_file *);
00486
00487 #ifdef __cplusplus
00488 }
00489 #endif
00490
00491 #endif