| OLD | NEW |
| 1 /* | 1 /* |
| 2 * ELF object format | 2 * ELF object format |
| 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 |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' | 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
| 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE | 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
| 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 * POSSIBILITY OF SUCH DAMAGE. | 25 * POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 #include <util.h> | 27 #include <util.h> |
| 28 /*@unused@*/ RCSID("$Id: elf-objfmt.c 2166 2009-01-02 08:33:21Z peter $"); | 28 /*@unused@*/ RCSID("$Id: elf-objfmt.c 2310 2010-03-28 19:28:54Z peter $"); |
| 29 | 29 |
| 30 /* Notes | 30 /* Notes |
| 31 * | 31 * |
| 32 * elf-objfmt uses the "linking" view of an ELF file: | 32 * elf-objfmt uses the "linking" view of an ELF file: |
| 33 * ELF header, an optional program header table, several sections, | 33 * ELF header, an optional program header table, several sections, |
| 34 * and a section header table | 34 * and a section header table |
| 35 * | 35 * |
| 36 * The ELF header tells us some overall program information, | 36 * The ELF header tells us some overall program information, |
| 37 * where to find the PHT (if it exists) with phnum and phentsize, | 37 * where to find the PHT (if it exists) with phnum and phentsize, |
| 38 * and where to find the SHT with shnum and shentsize | 38 * and where to find the SHT with shnum and shentsize |
| (...skipping 22 matching lines...) Expand all Loading... |
| 61 } yasm_objfmt_elf; | 61 } yasm_objfmt_elf; |
| 62 | 62 |
| 63 typedef struct { | 63 typedef struct { |
| 64 yasm_objfmt_elf *objfmt_elf; | 64 yasm_objfmt_elf *objfmt_elf; |
| 65 yasm_errwarns *errwarns; | 65 yasm_errwarns *errwarns; |
| 66 FILE *f; | 66 FILE *f; |
| 67 elf_secthead *shead; | 67 elf_secthead *shead; |
| 68 yasm_section *sect; | 68 yasm_section *sect; |
| 69 yasm_object *object; | 69 yasm_object *object; |
| 70 unsigned long sindex; | 70 unsigned long sindex; |
| 71 yasm_symrec *GOT_sym; |
| 71 } elf_objfmt_output_info; | 72 } elf_objfmt_output_info; |
| 72 | 73 |
| 73 typedef struct { | 74 typedef struct { |
| 74 yasm_object *object; | 75 yasm_object *object; |
| 75 yasm_objfmt_elf *objfmt_elf; | 76 yasm_objfmt_elf *objfmt_elf; |
| 76 yasm_errwarns *errwarns; | 77 yasm_errwarns *errwarns; |
| 77 int local_names; | 78 int local_names; |
| 78 } build_symtab_info; | 79 } build_symtab_info; |
| 79 | 80 |
| 80 yasm_objfmt_module yasm_elf_LTX_objfmt; | 81 yasm_objfmt_module yasm_elf_LTX_objfmt; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 elf_objfmt_output_reloc(yasm_symrec *sym, yasm_bytecode *bc, | 448 elf_objfmt_output_reloc(yasm_symrec *sym, yasm_bytecode *bc, |
| 448 unsigned char *buf, unsigned int destsize, | 449 unsigned char *buf, unsigned int destsize, |
| 449 unsigned int valsize, int warn, void *d) | 450 unsigned int valsize, int warn, void *d) |
| 450 { | 451 { |
| 451 elf_reloc_entry *reloc; | 452 elf_reloc_entry *reloc; |
| 452 elf_objfmt_output_info *info = d; | 453 elf_objfmt_output_info *info = d; |
| 453 yasm_intnum *zero; | 454 yasm_intnum *zero; |
| 454 int retval; | 455 int retval; |
| 455 | 456 |
| 456 reloc = elf_reloc_entry_create(sym, NULL, | 457 reloc = elf_reloc_entry_create(sym, NULL, |
| 457 yasm_intnum_create_uint(bc->offset), 0, valsize); | 458 yasm_intnum_create_uint(bc->offset), 0, valsize, 0); |
| 458 if (reloc == NULL) { | 459 if (reloc == NULL) { |
| 459 yasm_error_set(YASM_ERROR_TYPE, N_("elf: invalid relocation size")); | 460 yasm_error_set(YASM_ERROR_TYPE, N_("elf: invalid relocation size")); |
| 460 return 1; | 461 return 1; |
| 461 } | 462 } |
| 462 /* allocate .rel[a] sections on a need-basis */ | 463 /* allocate .rel[a] sections on a need-basis */ |
| 463 elf_secthead_append_reloc(info->sect, info->shead, reloc); | 464 elf_secthead_append_reloc(info->sect, info->shead, reloc); |
| 464 | 465 |
| 465 zero = yasm_intnum_create_uint(0); | 466 zero = yasm_intnum_create_uint(0); |
| 466 elf_handle_reloc_addend(zero, reloc); | 467 elf_handle_reloc_addend(zero, reloc, 0); |
| 467 retval = yasm_arch_intnum_tobytes(info->object->arch, zero, buf, destsize, | 468 retval = yasm_arch_intnum_tobytes(info->object->arch, zero, buf, destsize, |
| 468 valsize, 0, bc, warn); | 469 valsize, 0, bc, warn); |
| 469 yasm_intnum_destroy(zero); | 470 yasm_intnum_destroy(zero); |
| 470 return retval; | 471 return retval; |
| 471 } | 472 } |
| 472 | 473 |
| 473 static int | 474 static int |
| 474 elf_objfmt_output_value(yasm_value *value, unsigned char *buf, | 475 elf_objfmt_output_value(yasm_value *value, unsigned char *buf, |
| 475 unsigned int destsize, unsigned long offset, | 476 unsigned int destsize, unsigned long offset, |
| 476 yasm_bytecode *bc, int warn, /*@null@*/ void *d) | 477 yasm_bytecode *bc, int warn, /*@null@*/ void *d) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 sym = elf_secthead_get_sym(sym_shead); | 540 sym = elf_secthead_get_sym(sym_shead); |
| 540 | 541 |
| 541 intn_val = yasm_bc_next_offset(sym_precbc); | 542 intn_val = yasm_bc_next_offset(sym_precbc); |
| 542 } | 543 } |
| 543 } | 544 } |
| 544 | 545 |
| 545 /* For PC-relative, need to add offset of expression within bc. */ | 546 /* For PC-relative, need to add offset of expression within bc. */ |
| 546 if (value->curpos_rel) | 547 if (value->curpos_rel) |
| 547 intn_val += offset; | 548 intn_val += offset; |
| 548 | 549 |
| 550 /* Check for _GLOBAL_OFFSET_TABLE_ symbol reference */ |
| 549 reloc = elf_reloc_entry_create(sym, wrt, | 551 reloc = elf_reloc_entry_create(sym, wrt, |
| 550 yasm_intnum_create_uint(bc->offset + offset), value->curpos_rel, | 552 yasm_intnum_create_uint(bc->offset + offset), value->curpos_rel, |
| 551 valsize); | 553 valsize, sym == info->GOT_sym); |
| 552 if (reloc == NULL) { | 554 if (reloc == NULL) { |
| 553 yasm_error_set(YASM_ERROR_TYPE, | 555 yasm_error_set(YASM_ERROR_TYPE, |
| 554 N_("elf: invalid relocation (WRT or size)")); | 556 N_("elf: invalid relocation (WRT or size)")); |
| 555 return 1; | 557 return 1; |
| 556 } | 558 } |
| 557 /* allocate .rel[a] sections on a need-basis */ | 559 /* allocate .rel[a] sections on a need-basis */ |
| 558 elf_secthead_append_reloc(info->sect, info->shead, reloc); | 560 elf_secthead_append_reloc(info->sect, info->shead, reloc); |
| 559 } | 561 } |
| 560 | 562 |
| 561 intn = yasm_intnum_create_uint(intn_val); | 563 intn = yasm_intnum_create_uint(intn_val); |
| 562 | 564 |
| 563 if (value->abs) { | 565 if (value->abs) { |
| 564 yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, 0); | 566 yasm_intnum *intn2 = yasm_expr_get_intnum(&value->abs, 0); |
| 565 if (!intn2) { | 567 if (!intn2) { |
| 566 yasm_error_set(YASM_ERROR_TOO_COMPLEX, | 568 yasm_error_set(YASM_ERROR_TOO_COMPLEX, |
| 567 N_("elf: relocation too complex")); | 569 N_("elf: relocation too complex")); |
| 568 yasm_intnum_destroy(intn); | 570 yasm_intnum_destroy(intn); |
| 569 return 1; | 571 return 1; |
| 570 } | 572 } |
| 571 yasm_intnum_calc(intn, YASM_EXPR_ADD, intn2); | 573 yasm_intnum_calc(intn, YASM_EXPR_ADD, intn2); |
| 572 } | 574 } |
| 573 | 575 |
| 574 if (reloc) | 576 if (reloc) |
| 575 elf_handle_reloc_addend(intn, reloc); | 577 elf_handle_reloc_addend(intn, reloc, offset); |
| 576 retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, | 578 retval = yasm_arch_intnum_tobytes(info->object->arch, intn, buf, destsize, |
| 577 valsize, 0, bc, warn); | 579 valsize, 0, bc, warn); |
| 578 yasm_intnum_destroy(intn); | 580 yasm_intnum_destroy(intn); |
| 579 return retval; | 581 return retval; |
| 580 } | 582 } |
| 581 | 583 |
| 582 static int | 584 static int |
| 583 elf_objfmt_output_bytecode(yasm_bytecode *bc, /*@null@*/ void *d) | 585 elf_objfmt_output_bytecode(yasm_bytecode *bc, /*@null@*/ void *d) |
| 584 { | 586 { |
| 585 /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; | 587 /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 } | 627 } |
| 626 | 628 |
| 627 /* If bigbuf was allocated, free it */ | 629 /* If bigbuf was allocated, free it */ |
| 628 if (bigbuf) | 630 if (bigbuf) |
| 629 yasm_xfree(bigbuf); | 631 yasm_xfree(bigbuf); |
| 630 | 632 |
| 631 return 0; | 633 return 0; |
| 632 } | 634 } |
| 633 | 635 |
| 634 static int | 636 static int |
| 635 elf_objfmt_create_dbg_secthead(yasm_section *sect, /*@null@*/ void *d) | |
| 636 { | |
| 637 /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; | |
| 638 elf_secthead *shead; | |
| 639 elf_section_type type=SHT_PROGBITS; | |
| 640 elf_size entsize=0; | |
| 641 const char *sectname; | |
| 642 /*@dependent@*/ yasm_symrec *sym; | |
| 643 elf_strtab_entry *name; | |
| 644 | |
| 645 shead = yasm_section_get_data(sect, &elf_section_data); | |
| 646 if (shead) | |
| 647 return 0; /* only create new secthead if missing */ | |
| 648 | |
| 649 sectname = yasm_section_get_name(sect); | |
| 650 name = elf_strtab_append_str(info->objfmt_elf->shstrtab, sectname); | |
| 651 | |
| 652 if (yasm__strcasecmp(sectname, ".stab")==0) { | |
| 653 entsize = 12; | |
| 654 } else if (yasm__strcasecmp(sectname, ".stabstr")==0) { | |
| 655 type = SHT_STRTAB; | |
| 656 } else if (yasm__strncasecmp(sectname, ".debug_", 7)==0) { | |
| 657 ; | |
| 658 } else | |
| 659 yasm_internal_error(N_("Unrecognized section without data")); | |
| 660 | |
| 661 shead = elf_secthead_create(name, type, 0, 0, 0); | |
| 662 elf_secthead_set_entsize(shead, entsize); | |
| 663 | |
| 664 sym = yasm_symtab_define_label(info->object->symtab, sectname, | |
| 665 yasm_section_bcs_first(sect), 1, 0); | |
| 666 elf_secthead_set_sym(shead, sym); | |
| 667 | |
| 668 yasm_section_add_data(sect, &elf_section_data, shead); | |
| 669 | |
| 670 return 0; | |
| 671 } | |
| 672 | |
| 673 static int | |
| 674 elf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) | 637 elf_objfmt_output_section(yasm_section *sect, /*@null@*/ void *d) |
| 675 { | 638 { |
| 676 /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; | 639 /*@null@*/ elf_objfmt_output_info *info = (elf_objfmt_output_info *)d; |
| 677 /*@dependent@*/ /*@null@*/ elf_secthead *shead; | 640 /*@dependent@*/ /*@null@*/ elf_secthead *shead; |
| 678 long pos; | 641 long pos; |
| 679 char *relname; | 642 char *relname; |
| 680 const char *sectname; | 643 const char *sectname; |
| 681 | 644 |
| 682 if (info == NULL) | 645 if (info == NULL) |
| 683 yasm_internal_error("null info struct"); | 646 yasm_internal_error("null info struct"); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 elf_secthead *esdn; | 736 elf_secthead *esdn; |
| 774 unsigned long elf_strtab_offset, elf_shstrtab_offset, elf_symtab_offset; | 737 unsigned long elf_strtab_offset, elf_shstrtab_offset, elf_symtab_offset; |
| 775 unsigned long elf_strtab_size, elf_shstrtab_size, elf_symtab_size; | 738 unsigned long elf_strtab_size, elf_shstrtab_size, elf_symtab_size; |
| 776 elf_strtab_entry *elf_strtab_name, *elf_shstrtab_name, *elf_symtab_name; | 739 elf_strtab_entry *elf_strtab_name, *elf_shstrtab_name, *elf_symtab_name; |
| 777 unsigned long elf_symtab_nlocal; | 740 unsigned long elf_symtab_nlocal; |
| 778 | 741 |
| 779 info.object = object; | 742 info.object = object; |
| 780 info.objfmt_elf = objfmt_elf; | 743 info.objfmt_elf = objfmt_elf; |
| 781 info.errwarns = errwarns; | 744 info.errwarns = errwarns; |
| 782 info.f = f; | 745 info.f = f; |
| 746 info.GOT_sym = yasm_symtab_get(object->symtab, "_GLOBAL_OFFSET_TABLE_"); |
| 783 | 747 |
| 784 /* Update filename strtab */ | 748 /* Update filename strtab */ |
| 785 elf_strtab_entry_set_str(objfmt_elf->file_strtab_entry, | 749 elf_strtab_entry_set_str(objfmt_elf->file_strtab_entry, |
| 786 object->src_filename); | 750 object->src_filename); |
| 787 | 751 |
| 788 /* Allocate space for Ehdr by seeking forward */ | 752 /* Allocate space for Ehdr by seeking forward */ |
| 789 if (fseek(f, (long)(elf_proghead_get_size()), SEEK_SET) < 0) { | 753 if (fseek(f, (long)(elf_proghead_get_size()), SEEK_SET) < 0) { |
| 790 yasm_error_set(YASM_ERROR_IO, N_("could not seek on output file")); | 754 yasm_error_set(YASM_ERROR_IO, N_("could not seek on output file")); |
| 791 yasm_errwarn_propagate(errwarns, 0); | 755 yasm_errwarn_propagate(errwarns, 0); |
| 792 return; | 756 return; |
| 793 } | 757 } |
| 794 | 758 |
| 795 /* Create missing section headers */ | |
| 796 if (yasm_object_sections_traverse(object, &info, | |
| 797 elf_objfmt_create_dbg_secthead)) | |
| 798 return; | |
| 799 | |
| 800 /* add all (local) syms to symtab because relocation needs a symtab index | 759 /* add all (local) syms to symtab because relocation needs a symtab index |
| 801 * if all_syms, register them by name. if not, use strtab entry 0 */ | 760 * if all_syms, register them by name. if not, use strtab entry 0 */ |
| 802 buildsym_info.object = object; | 761 buildsym_info.object = object; |
| 803 buildsym_info.objfmt_elf = objfmt_elf; | 762 buildsym_info.objfmt_elf = objfmt_elf; |
| 804 buildsym_info.errwarns = errwarns; | 763 buildsym_info.errwarns = errwarns; |
| 805 buildsym_info.local_names = all_syms; | 764 buildsym_info.local_names = all_syms; |
| 806 yasm_symtab_traverse(object->symtab, &buildsym_info, | 765 yasm_symtab_traverse(object->symtab, &buildsym_info, |
| 807 elf_objfmt_build_symtab); | 766 elf_objfmt_build_symtab); |
| 808 elf_symtab_nlocal = elf_symtab_assign_indices(objfmt_elf->elf_symtab); | 767 elf_symtab_nlocal = elf_symtab_assign_indices(objfmt_elf->elf_symtab); |
| 809 | 768 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 static void | 874 static void |
| 916 elf_objfmt_destroy(yasm_objfmt *objfmt) | 875 elf_objfmt_destroy(yasm_objfmt *objfmt) |
| 917 { | 876 { |
| 918 yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; | 877 yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt; |
| 919 elf_symtab_destroy(objfmt_elf->elf_symtab); | 878 elf_symtab_destroy(objfmt_elf->elf_symtab); |
| 920 elf_strtab_destroy(objfmt_elf->shstrtab); | 879 elf_strtab_destroy(objfmt_elf->shstrtab); |
| 921 elf_strtab_destroy(objfmt_elf->strtab); | 880 elf_strtab_destroy(objfmt_elf->strtab); |
| 922 yasm_xfree(objfmt); | 881 yasm_xfree(objfmt); |
| 923 } | 882 } |
| 924 | 883 |
| 925 static elf_secthead * | 884 static void |
| 926 elf_objfmt_init_new_section(yasm_object *object, yasm_section *sect, | 885 elf_objfmt_init_new_section(yasm_section *sect, unsigned long line) |
| 927 const char *sectname, unsigned long type, | |
| 928 unsigned long flags, unsigned long line) | |
| 929 { | 886 { |
| 887 yasm_object *object = yasm_section_get_object(sect); |
| 888 const char *sectname = yasm_section_get_name(sect); |
| 930 yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; | 889 yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)object->objfmt; |
| 931 elf_secthead *esd; | 890 elf_secthead *esd; |
| 932 yasm_symrec *sym; | 891 yasm_symrec *sym; |
| 933 elf_strtab_entry *name = elf_strtab_append_str(objfmt_elf->shstrtab, | 892 elf_strtab_entry *name = elf_strtab_append_str(objfmt_elf->shstrtab, |
| 934 sectname); | 893 sectname); |
| 935 | 894 |
| 936 esd = elf_secthead_create(name, type, flags, 0, 0); | 895 elf_section_type type=SHT_PROGBITS; |
| 896 elf_size entsize=0; |
| 897 |
| 898 if (yasm__strcasecmp(sectname, ".stab")==0) { |
| 899 entsize = 12; |
| 900 } else if (yasm__strcasecmp(sectname, ".stabstr")==0) { |
| 901 type = SHT_STRTAB; |
| 902 } |
| 903 |
| 904 esd = elf_secthead_create(name, type, 0, 0, 0); |
| 905 elf_secthead_set_entsize(esd, entsize); |
| 937 yasm_section_add_data(sect, &elf_section_data, esd); | 906 yasm_section_add_data(sect, &elf_section_data, esd); |
| 938 sym = yasm_symtab_define_label(object->symtab, sectname, | 907 sym = yasm_symtab_define_label(object->symtab, sectname, |
| 939 yasm_section_bcs_first(sect), 1, line); | 908 yasm_section_bcs_first(sect), 1, line); |
| 940 | 909 |
| 941 elf_secthead_set_sym(esd, sym); | 910 elf_secthead_set_sym(esd, sym); |
| 942 | |
| 943 return esd; | |
| 944 } | 911 } |
| 945 | 912 |
| 946 static yasm_section * | 913 static yasm_section * |
| 947 elf_objfmt_add_default_section(yasm_object *object) | 914 elf_objfmt_add_default_section(yasm_object *object) |
| 948 { | 915 { |
| 949 yasm_section *retval; | 916 yasm_section *retval; |
| 950 int isnew; | 917 int isnew; |
| 951 elf_secthead *esd; | |
| 952 | 918 |
| 953 retval = yasm_object_get_general(object, ".text", 16, 1, 0, &isnew, 0); | 919 retval = yasm_object_get_general(object, ".text", 16, 1, 0, &isnew, 0); |
| 954 esd = elf_objfmt_init_new_section(object, retval, ".text", SHT_PROGBITS, | 920 if (isnew) |
| 955 SHF_ALLOC + SHF_EXECINSTR, 0); | 921 { |
| 956 yasm_section_set_default(retval, 1); | 922 elf_secthead *esd = yasm_section_get_data(retval, &elf_section_data); |
| 923 elf_secthead_set_typeflags(esd, SHT_PROGBITS, |
| 924 SHF_ALLOC + SHF_EXECINSTR); |
| 925 yasm_section_set_default(retval, 1); |
| 926 } |
| 957 return retval; | 927 return retval; |
| 958 } | 928 } |
| 959 | 929 |
| 960 struct elf_section_switch_data { | 930 struct elf_section_switch_data { |
| 961 /*@only@*/ /*@null@*/ yasm_intnum *align_intn; | 931 /*@only@*/ /*@null@*/ yasm_intnum *align_intn; |
| 962 unsigned long flags; | 932 unsigned long flags; |
| 963 unsigned long type; | 933 unsigned long type; |
| 964 int gasflags; | 934 int gasflags; |
| 965 int stdsect; | 935 int stdsect; |
| 966 }; | 936 }; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 yasm_warn_set(YASM_WARN_GENERAL, | 1105 yasm_warn_set(YASM_WARN_GENERAL, |
| 1136 N_("entity size for SHF_MERGE not specified")); | 1106 N_("entity size for SHF_MERGE not specified")); |
| 1137 data.flags &= ~SHF_MERGE; | 1107 data.flags &= ~SHF_MERGE; |
| 1138 } | 1108 } |
| 1139 } | 1109 } |
| 1140 | 1110 |
| 1141 retval = yasm_object_get_general(object, sectname, align, | 1111 retval = yasm_object_get_general(object, sectname, align, |
| 1142 (data.flags & SHF_EXECINSTR) != 0, | 1112 (data.flags & SHF_EXECINSTR) != 0, |
| 1143 resonly, &isnew, line); | 1113 resonly, &isnew, line); |
| 1144 | 1114 |
| 1145 if (isnew) | 1115 esd = yasm_section_get_data(retval, &elf_section_data); |
| 1146 esd = elf_objfmt_init_new_section(object, retval, sectname, data.type, | |
| 1147 data.flags, line); | |
| 1148 else | |
| 1149 esd = yasm_section_get_data(retval, &elf_section_data); | |
| 1150 | 1116 |
| 1151 if (isnew || yasm_section_is_default(retval)) { | 1117 if (isnew || yasm_section_is_default(retval)) { |
| 1152 yasm_section_set_default(retval, 0); | 1118 yasm_section_set_default(retval, 0); |
| 1153 elf_secthead_set_typeflags(esd, data.type, data.flags); | 1119 elf_secthead_set_typeflags(esd, data.type, data.flags); |
| 1154 if (merge_intn) | 1120 if (merge_intn) |
| 1155 elf_secthead_set_entsize(esd, yasm_intnum_get_uint(merge_intn)); | 1121 elf_secthead_set_entsize(esd, yasm_intnum_get_uint(merge_intn)); |
| 1156 yasm_section_set_align(retval, align, line); | 1122 yasm_section_set_align(retval, align, line); |
| 1157 } else if (flags_override && !data.gasflags) | 1123 } else if (flags_override && !data.gasflags) |
| 1158 yasm_warn_set(YASM_WARN_GENERAL, | 1124 yasm_warn_set(YASM_WARN_GENERAL, |
| 1159 N_("section flags ignored on section redeclaration")); | 1125 N_("section flags ignored on section redeclaration")); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 32, | 1315 32, |
| 1350 0, | 1316 0, |
| 1351 elf_objfmt_dbgfmt_keywords, | 1317 elf_objfmt_dbgfmt_keywords, |
| 1352 "null", | 1318 "null", |
| 1353 elf_objfmt_directives, | 1319 elf_objfmt_directives, |
| 1354 elf_objfmt_stdmacs, | 1320 elf_objfmt_stdmacs, |
| 1355 elf_objfmt_create, | 1321 elf_objfmt_create, |
| 1356 elf_objfmt_output, | 1322 elf_objfmt_output, |
| 1357 elf_objfmt_destroy, | 1323 elf_objfmt_destroy, |
| 1358 elf_objfmt_add_default_section, | 1324 elf_objfmt_add_default_section, |
| 1325 elf_objfmt_init_new_section, |
| 1359 elf_objfmt_section_switch, | 1326 elf_objfmt_section_switch, |
| 1360 elf_objfmt_get_special_sym | 1327 elf_objfmt_get_special_sym |
| 1361 }; | 1328 }; |
| 1362 | 1329 |
| 1363 yasm_objfmt_module yasm_elf32_LTX_objfmt = { | 1330 yasm_objfmt_module yasm_elf32_LTX_objfmt = { |
| 1364 "ELF (32-bit)", | 1331 "ELF (32-bit)", |
| 1365 "elf32", | 1332 "elf32", |
| 1366 "o", | 1333 "o", |
| 1367 32, | 1334 32, |
| 1368 0, | 1335 0, |
| 1369 elf_objfmt_dbgfmt_keywords, | 1336 elf_objfmt_dbgfmt_keywords, |
| 1370 "null", | 1337 "null", |
| 1371 elf_objfmt_directives, | 1338 elf_objfmt_directives, |
| 1372 elf_objfmt_stdmacs, | 1339 elf_objfmt_stdmacs, |
| 1373 elf32_objfmt_create, | 1340 elf32_objfmt_create, |
| 1374 elf_objfmt_output, | 1341 elf_objfmt_output, |
| 1375 elf_objfmt_destroy, | 1342 elf_objfmt_destroy, |
| 1376 elf_objfmt_add_default_section, | 1343 elf_objfmt_add_default_section, |
| 1344 elf_objfmt_init_new_section, |
| 1377 elf_objfmt_section_switch, | 1345 elf_objfmt_section_switch, |
| 1378 elf_objfmt_get_special_sym | 1346 elf_objfmt_get_special_sym |
| 1379 }; | 1347 }; |
| 1380 | 1348 |
| 1381 yasm_objfmt_module yasm_elf64_LTX_objfmt = { | 1349 yasm_objfmt_module yasm_elf64_LTX_objfmt = { |
| 1382 "ELF (64-bit)", | 1350 "ELF (64-bit)", |
| 1383 "elf64", | 1351 "elf64", |
| 1384 "o", | 1352 "o", |
| 1385 64, | 1353 64, |
| 1386 0, | 1354 0, |
| 1387 elf_objfmt_dbgfmt_keywords, | 1355 elf_objfmt_dbgfmt_keywords, |
| 1388 "null", | 1356 "null", |
| 1389 elf_objfmt_directives, | 1357 elf_objfmt_directives, |
| 1390 elf_objfmt_stdmacs, | 1358 elf_objfmt_stdmacs, |
| 1391 elf64_objfmt_create, | 1359 elf64_objfmt_create, |
| 1392 elf_objfmt_output, | 1360 elf_objfmt_output, |
| 1393 elf_objfmt_destroy, | 1361 elf_objfmt_destroy, |
| 1394 elf_objfmt_add_default_section, | 1362 elf_objfmt_add_default_section, |
| 1363 elf_objfmt_init_new_section, |
| 1395 elf_objfmt_section_switch, | 1364 elf_objfmt_section_switch, |
| 1396 elf_objfmt_get_special_sym | 1365 elf_objfmt_get_special_sym |
| 1397 }; | 1366 }; |
| OLD | NEW |