| OLD | NEW |
| 1 /* $Id: elf.h 2040 2008-02-21 08:57:23Z peter $ | 1 /* $Id: elf.h 2208 2009-07-22 05:45:03Z peter $ |
| 2 * ELF object format helpers | 2 * ELF object format helpers |
| 3 * | 3 * |
| 4 * Copyright (C) 2003-2007 Michael Urman | 4 * Copyright (C) 2003-2007 Michael Urman |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 R_386_TLS_GD_POP = 27, /* Tag for popl in GD TLS code */ | 296 R_386_TLS_GD_POP = 27, /* Tag for popl in GD TLS code */ |
| 297 R_386_TLS_LDM_32 = 28, /* Direct 32 bit for local dynamic code */ | 297 R_386_TLS_LDM_32 = 28, /* Direct 32 bit for local dynamic code */ |
| 298 R_386_TLS_LDM_PUSH = 29, /* Tag for pushl in LDM TLS code */ | 298 R_386_TLS_LDM_PUSH = 29, /* Tag for pushl in LDM TLS code */ |
| 299 R_386_TLS_LDM_CALL = 30, /* Relocation for call to */ | 299 R_386_TLS_LDM_CALL = 30, /* Relocation for call to */ |
| 300 R_386_TLS_LDM_POP = 31, /* Tag for popl in LDM TLS code */ | 300 R_386_TLS_LDM_POP = 31, /* Tag for popl in LDM TLS code */ |
| 301 R_386_TLS_LDO_32 = 32, /* Offset relative to TLS block */ | 301 R_386_TLS_LDO_32 = 32, /* Offset relative to TLS block */ |
| 302 R_386_TLS_IE_32 = 33, /* GOT entry for static TLS block */ | 302 R_386_TLS_IE_32 = 33, /* GOT entry for static TLS block */ |
| 303 R_386_TLS_LE_32 = 34, /* Offset relative to static TLS block */ | 303 R_386_TLS_LE_32 = 34, /* Offset relative to static TLS block */ |
| 304 R_386_TLS_DTPMOD32 = 35, /* ID of module containing symbol */ | 304 R_386_TLS_DTPMOD32 = 35, /* ID of module containing symbol */ |
| 305 R_386_TLS_DTPOFF32 = 36, /* Offset in TLS block */ | 305 R_386_TLS_DTPOFF32 = 36, /* Offset in TLS block */ |
| 306 R_386_TLS_TPOFF32 = 37 /* Offset in static TLS block */ | 306 R_386_TLS_TPOFF32 = 37, /* Offset in static TLS block */ |
| 307 R_386_TLS_GOTDESC = 39, |
| 308 R_386_TLS_DESC_CALL = 40, |
| 309 R_386_TLS_DESC = 41 |
| 307 } elf_386_relocation_type; | 310 } elf_386_relocation_type; |
| 308 | 311 |
| 309 typedef enum { | 312 typedef enum { |
| 310 R_X86_64_NONE = 0, /* none */ | 313 R_X86_64_NONE = 0, /* none */ |
| 311 R_X86_64_64 = 1, /* word64, S + A */ | 314 R_X86_64_64 = 1, /* word64, S + A */ |
| 312 R_X86_64_PC32 = 2, /* word32, S + A - P */ | 315 R_X86_64_PC32 = 2, /* word32, S + A - P */ |
| 313 R_X86_64_GOT32 = 3, /* word32, G + A */ | 316 R_X86_64_GOT32 = 3, /* word32, G + A */ |
| 314 R_X86_64_PLT32 = 4, /* word32, L + A - P */ | 317 R_X86_64_PLT32 = 4, /* word32, L + A - P */ |
| 315 R_X86_64_COPY = 5, /* none */ | 318 R_X86_64_COPY = 5, /* none */ |
| 316 R_X86_64_GLOB_DAT = 6, /* word64, S, set GOT entry to data address */ | 319 R_X86_64_GLOB_DAT = 6, /* word64, S, set GOT entry to data address */ |
| 317 R_X86_64_JMP_SLOT = 7, /* word64, S, set GOT entry to code address */ | 320 R_X86_64_JMP_SLOT = 7, /* word64, S, set GOT entry to code address */ |
| 318 R_X86_64_RELATIVE = 8, /* word64, B + A */ | 321 R_X86_64_RELATIVE = 8, /* word64, B + A */ |
| 319 R_X86_64_GOTPCREL = 9, /* word32, G + GOT + A - P */ | 322 R_X86_64_GOTPCREL = 9, /* word32, G + GOT + A - P */ |
| 320 R_X86_64_32 = 10, /* word32 (zero extend), S + A */ | 323 R_X86_64_32 = 10, /* word32 (zero extend), S + A */ |
| 321 R_X86_64_32S = 11, /* word32 (sign extend), S + A */ | 324 R_X86_64_32S = 11, /* word32 (sign extend), S + A */ |
| 322 R_X86_64_16 = 12, /* word16, S + A */ | 325 R_X86_64_16 = 12, /* word16, S + A */ |
| 323 R_X86_64_PC16 = 13, /* word16, S + A - P */ | 326 R_X86_64_PC16 = 13, /* word16, S + A - P */ |
| 324 R_X86_64_8 = 14, /* word8, S + A */ | 327 R_X86_64_8 = 14, /* word8, S + A */ |
| 325 R_X86_64_PC8 = 15, /* word8, S + A - P */ | 328 R_X86_64_PC8 = 15, /* word8, S + A - P */ |
| 326 R_X86_64_DPTMOD64 = 16, /* word64, ID of module containing symbol */ | 329 R_X86_64_DPTMOD64 = 16, /* word64, ID of module containing symbol */ |
| 327 R_X86_64_DTPOFF64 = 17, /* word64, offset in TLS block */ | 330 R_X86_64_DTPOFF64 = 17, /* word64, offset in TLS block */ |
| 328 R_X86_64_TPOFF64 = 18, /* word64, offset in initial TLS block */ | 331 R_X86_64_TPOFF64 = 18, /* word64, offset in initial TLS block */ |
| 329 R_X86_64_TLSGD = 19, /* word32, PC-rel offset to GD GOT block */ | 332 R_X86_64_TLSGD = 19, /* word32, PC-rel offset to GD GOT block */ |
| 330 R_X86_64_TLSLD = 20, /* word32, PC-rel offset to LD GOT block */ | 333 R_X86_64_TLSLD = 20, /* word32, PC-rel offset to LD GOT block */ |
| 331 R_X86_64_DTPOFF32 = 21, /* word32, offset to TLS block */ | 334 R_X86_64_DTPOFF32 = 21, /* word32, offset to TLS block */ |
| 332 R_X86_64_GOTTPOFF = 22, /* word32, PC-rel offset to IE GOT entry */ | 335 R_X86_64_GOTTPOFF = 22, /* word32, PC-rel offset to IE GOT entry */ |
| 333 R_X86_64_TPOFF32 = 23 /* word32, offset in initial TLS block */ | 336 R_X86_64_TPOFF32 = 23, /* word32, offset in initial TLS block */ |
| 337 R_X86_64_PC64 = 24, /* word64, PC relative */ |
| 338 R_X86_64_GOTOFF64 = 25, /* word64, offset to GOT */ |
| 339 R_X86_64_GOTPC32 = 26, /* word32, signed pc relative to GOT */ |
| 340 R_X86_64_GOT64 = 27, /* word64, GOT entry offset */ |
| 341 R_X86_64_GOTPCREL64 = 28, /* word64, signed pc relative to GOT entry */ |
| 342 R_X86_64_GOTPC64 = 29, /* word64, signed pc relative to GOT */ |
| 343 R_X86_64_GOTPLT64 = 30, /* like GOT64, but indicates PLT entry needed */ |
| 344 R_X86_64_PLTOFF64 = 31, /* word64, GOT relative offset to PLT entry */ |
| 345 R_X86_64_GOTPC32_TLSDESC = 34, /* GOT offset for TLS descriptor */ |
| 346 R_X86_64_TLSDESC_CALL = 35, /* Marker for call through TLS descriptor */ |
| 347 R_X86_64_TLSDESC = 36 /* TLS descriptor */ |
| 334 } elf_x86_64_relocation_type; | 348 } elf_x86_64_relocation_type; |
| 335 | 349 |
| 336 struct elf_secthead { | 350 struct elf_secthead { |
| 337 elf_section_type type; | 351 elf_section_type type; |
| 338 elf_section_flags flags; | 352 elf_section_flags flags; |
| 339 elf_address offset; | 353 elf_address offset; |
| 340 yasm_intnum *size; | 354 yasm_intnum *size; |
| 341 elf_section_index link; | 355 elf_section_index link; |
| 342 elf_section_info info; /* see note ESD1 */ | 356 elf_section_info info; /* see note ESD1 */ |
| 343 unsigned long align; | 357 unsigned long align; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 370 * link -> SHN_UNDEF | 384 * link -> SHN_UNDEF |
| 371 * info -> 0 | 385 * info -> 0 |
| 372 */ | 386 */ |
| 373 | 387 |
| 374 struct elf_reloc_entry { | 388 struct elf_reloc_entry { |
| 375 yasm_reloc reloc; | 389 yasm_reloc reloc; |
| 376 int rtype_rel; | 390 int rtype_rel; |
| 377 size_t valsize; | 391 size_t valsize; |
| 378 yasm_intnum *addend; | 392 yasm_intnum *addend; |
| 379 /*@null@*/ yasm_symrec *wrt; | 393 /*@null@*/ yasm_symrec *wrt; |
| 394 int is_GOT_sym; |
| 380 }; | 395 }; |
| 381 | 396 |
| 382 STAILQ_HEAD(elf_strtab_head, elf_strtab_entry); | 397 STAILQ_HEAD(elf_strtab_head, elf_strtab_entry); |
| 383 struct elf_strtab_entry { | 398 struct elf_strtab_entry { |
| 384 STAILQ_ENTRY(elf_strtab_entry) qlink; | 399 STAILQ_ENTRY(elf_strtab_entry) qlink; |
| 385 unsigned long index; | 400 unsigned long index; |
| 386 char *str; | 401 char *str; |
| 387 }; | 402 }; |
| 388 | 403 |
| 389 STAILQ_HEAD(elf_symtab_head, elf_symtab_entry); | 404 STAILQ_HEAD(elf_symtab_head, elf_symtab_entry); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 400 elf_symbol_binding bind; | 415 elf_symbol_binding bind; |
| 401 elf_symbol_type type; | 416 elf_symbol_type type; |
| 402 elf_symbol_vis vis; | 417 elf_symbol_vis vis; |
| 403 elf_symbol_index symindex; | 418 elf_symbol_index symindex; |
| 404 }; | 419 }; |
| 405 | 420 |
| 406 #endif /* defined(YASM_OBJFMT_ELF_INTERNAL) */ | 421 #endif /* defined(YASM_OBJFMT_ELF_INTERNAL) */ |
| 407 | 422 |
| 408 extern const yasm_assoc_data_callback elf_section_data; | 423 extern const yasm_assoc_data_callback elf_section_data; |
| 409 extern const yasm_assoc_data_callback elf_symrec_data; | 424 extern const yasm_assoc_data_callback elf_symrec_data; |
| 425 extern const yasm_assoc_data_callback elf_ssym_symrec_data; |
| 410 | 426 |
| 411 | 427 |
| 412 const elf_machine_handler *elf_set_arch(struct yasm_arch *arch, | 428 const elf_machine_handler *elf_set_arch(struct yasm_arch *arch, |
| 413 yasm_symtab *symtab, | 429 yasm_symtab *symtab, |
| 414 int bits_pref); | 430 int bits_pref); |
| 415 | 431 |
| 416 yasm_symrec *elf_get_special_sym(const char *name, const char *parser); | 432 yasm_symrec *elf_get_special_sym(const char *name, const char *parser); |
| 417 | 433 |
| 418 /* reloc functions */ | 434 /* reloc functions */ |
| 419 int elf_is_wrt_sym_relative(yasm_symrec *wrt); | 435 int elf_is_wrt_sym_relative(yasm_symrec *wrt); |
| 420 int elf_is_wrt_pos_adjusted(yasm_symrec *wrt); | 436 int elf_is_wrt_pos_adjusted(yasm_symrec *wrt); |
| 421 elf_reloc_entry *elf_reloc_entry_create(yasm_symrec *sym, | 437 elf_reloc_entry *elf_reloc_entry_create(yasm_symrec *sym, |
| 422 /*@null@*/ yasm_symrec *wrt, | 438 /*@null@*/ yasm_symrec *wrt, |
| 423 yasm_intnum *addr, | 439 yasm_intnum *addr, |
| 424 int rel, | 440 int rel, |
| 425 size_t valsize); | 441 size_t valsize, |
| 442 int is_GOT_sym); |
| 426 void elf_reloc_entry_destroy(void *entry); | 443 void elf_reloc_entry_destroy(void *entry); |
| 427 | 444 |
| 428 /* strtab functions */ | 445 /* strtab functions */ |
| 429 elf_strtab_entry *elf_strtab_entry_create(const char *str); | 446 elf_strtab_entry *elf_strtab_entry_create(const char *str); |
| 430 void elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str); | 447 void elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str); |
| 431 elf_strtab_head *elf_strtab_create(void); | 448 elf_strtab_head *elf_strtab_create(void); |
| 432 elf_strtab_entry *elf_strtab_append_str(elf_strtab_head *head, const char *str); | 449 elf_strtab_entry *elf_strtab_append_str(elf_strtab_head *head, const char *str); |
| 433 void elf_strtab_destroy(elf_strtab_head *head); | 450 void elf_strtab_destroy(elf_strtab_head *head); |
| 434 unsigned long elf_strtab_output_to_file(FILE *f, elf_strtab_head *head); | 451 unsigned long elf_strtab_output_to_file(FILE *f, elf_strtab_head *head); |
| 435 | 452 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 elf_section_index link); | 501 elf_section_index link); |
| 485 elf_section_index elf_secthead_set_rel_index(elf_secthead *shead, | 502 elf_section_index elf_secthead_set_rel_index(elf_secthead *shead, |
| 486 elf_section_index sectidx); | 503 elf_section_index sectidx); |
| 487 elf_strtab_entry *elf_secthead_set_rel_name(elf_secthead *shead, | 504 elf_strtab_entry *elf_secthead_set_rel_name(elf_secthead *shead, |
| 488 elf_strtab_entry *entry); | 505 elf_strtab_entry *entry); |
| 489 elf_size elf_secthead_set_entsize(elf_secthead *shead, elf_size size); | 506 elf_size elf_secthead_set_entsize(elf_secthead *shead, elf_size size); |
| 490 struct yasm_symrec *elf_secthead_set_sym(elf_secthead *shead, | 507 struct yasm_symrec *elf_secthead_set_sym(elf_secthead *shead, |
| 491 struct yasm_symrec *sym); | 508 struct yasm_symrec *sym); |
| 492 void elf_secthead_add_size(elf_secthead *shead, yasm_intnum *size); | 509 void elf_secthead_add_size(elf_secthead *shead, yasm_intnum *size); |
| 493 char *elf_secthead_name_reloc_section(const char *basesect); | 510 char *elf_secthead_name_reloc_section(const char *basesect); |
| 494 void elf_handle_reloc_addend(yasm_intnum *intn, elf_reloc_entry *reloc); | 511 void elf_handle_reloc_addend(yasm_intnum *intn, |
| 512 elf_reloc_entry *reloc, |
| 513 unsigned long offset); |
| 495 unsigned long elf_secthead_write_rel_to_file(FILE *f, elf_section_index symtab, | 514 unsigned long elf_secthead_write_rel_to_file(FILE *f, elf_section_index symtab, |
| 496 yasm_section *sect, | 515 yasm_section *sect, |
| 497 elf_secthead *esd, | 516 elf_secthead *esd, |
| 498 elf_section_index sindex); | 517 elf_section_index sindex); |
| 499 unsigned long elf_secthead_write_relocs_to_file(FILE *f, yasm_section *sect, | 518 unsigned long elf_secthead_write_relocs_to_file(FILE *f, yasm_section *sect, |
| 500 elf_secthead *shead, | 519 elf_secthead *shead, |
| 501 yasm_errwarns *errwarns); | 520 yasm_errwarns *errwarns); |
| 502 long elf_secthead_set_file_offset(elf_secthead *shead, long pos); | 521 long elf_secthead_set_file_offset(elf_secthead *shead, long pos); |
| 503 | 522 |
| 504 /* program header function */ | 523 /* program header function */ |
| 505 unsigned long | 524 unsigned long |
| 506 elf_proghead_get_size(void); | 525 elf_proghead_get_size(void); |
| 507 unsigned long | 526 unsigned long |
| 508 elf_proghead_write_to_file(FILE *f, | 527 elf_proghead_write_to_file(FILE *f, |
| 509 elf_offset secthead_addr, | 528 elf_offset secthead_addr, |
| 510 unsigned long secthead_count, | 529 unsigned long secthead_count, |
| 511 elf_section_index shstrtab_index); | 530 elf_section_index shstrtab_index); |
| 512 | 531 |
| 513 #endif /* ELF_H_INCLUDED */ | 532 #endif /* ELF_H_INCLUDED */ |
| OLD | NEW |