- Use REL_SECTION_FMT instead of ".rel%s". - Use PTR_SIZE instead of sizeof(int) for GOT entries. - Use sizeof(ElfW(Dyn)) instead of magic number 8. - Use TCC_ELFCLASS instead of ELFCLASS32.
Unified · Split
| @@ -270,7 +270,7 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 269 unmodified lines | ||
| 270 | 270 | sr = s->reloc; |
| 271 | 271 | if (!sr) { |
| 272 | 272 | /* if no relocation section, create it */ |
| 273 | − snprintf(buf, sizeof(buf), ".rel%s", s->name); | |
| 273 | + snprintf(buf, sizeof(buf), REL_SECTION_FMT, s->name); | |
| 274 | 274 | /* if the symtab is allocated, then we consider the relocation |
| 275 | 275 | are also */ |
| 276 | 276 | sr = new_section(tcc_state, buf, SHT_RELX, symtab->sh_flags); |
| @@ -724,12 +724,23 @@ static void build_got(TCCState *s1) · 447 unmodified lines | ||
| 724 | 724 | s1->got->sh_entsize = 4; |
| 725 | 725 | add_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), |
| 726 | 726 | 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); |
| 727 | − ptr = section_ptr_add(s1->got, 3 * sizeof(int)); | |
| 727 | + ptr = section_ptr_add(s1->got, 3 * PTR_SIZE); | |
| 728 | +#ifdef PTR_SIZE == 4 | |
| 728 | 729 | /* keep space for _DYNAMIC pointer, if present */ |
| 729 | 730 | put32(ptr, 0); |
| 730 | 731 | /* two dummy got entries */ |
| 731 | 732 | put32(ptr + 4, 0); |
| 732 | 733 | put32(ptr + 8, 0); |
| 734 | +#else | |
| 735 | + /* keep space for _DYNAMIC pointer, if present */ | |
| 736 | + put32(ptr, 0); | |
| 737 | + put32(ptr + 4, 0); | |
| 738 | + /* two dummy got entries */ | |
| 739 | + put32(ptr + 8, 0); | |
| 740 | + put32(ptr + 12, 0); | |
| 741 | + put32(ptr + 16, 0); | |
| 742 | + put32(ptr + 20, 0); | |
| 743 | +#endif | |
| 733 | 744 | } |
| 734 | 745 | |
| 735 | 746 | /* put a got entry corresponding to a symbol in symtab_section. 'size' |
| @@ -775,12 +786,12 @@ static void put_got_entry(TCCState *s1, · 39 unmodified lines | ||
| 775 | 786 | if (plt->data_offset == 0) { |
| 776 | 787 | /* first plt entry */ |
| 777 | 788 | p = section_ptr_add(plt, 16); |
| 778 | − p[0] = 0xff; /* pushl got + 4 */ | |
| 789 | + p[0] = 0xff; /* pushl got + PTR_SIZE */ | |
| 779 | 790 | p[1] = modrm + 0x10; |
| 780 | − put32(p + 2, 4); | |
| 781 | − p[6] = 0xff; /* jmp *(got + 8) */ | |
| 791 | + put32(p + 2, PTR_SIZE); | |
| 792 | + p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */ | |
| 782 | 793 | p[7] = modrm; |
| 783 | − put32(p + 8, 8); | |
| 794 | + put32(p + 8, PTR_SIZE * 2); | |
| 784 | 795 | } |
| 785 | 796 | |
| 786 | 797 | p = section_ptr_add(plt, 16); |
| @@ -840,7 +851,7 @@ static void put_got_entry(TCCState *s1, · 53 unmodified lines | ||
| 840 | 851 | s1->got->data_offset, |
| 841 | 852 | reloc_type, index); |
| 842 | 853 | } |
| 843 | − ptr = section_ptr_add(s1->got, sizeof(int)); | |
| 854 | + ptr = section_ptr_add(s1->got, PTR_SIZE); | |
| 844 | 855 | *ptr = 0; |
| 845 | 856 | } |
| 846 | 857 | |
| @@ -1338,7 +1349,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 491 unmodified lines | ||
| 1338 | 1349 | |
| 1339 | 1350 | /* add necessary space for other entries */ |
| 1340 | 1351 | saved_dynamic_data_offset = dynamic->data_offset; |
| 1341 | − dynamic->data_offset += 8 * 9; | |
| 1352 | + dynamic->data_offset += sizeof(ElfW(Dyn)) * 9; | |
| 1342 | 1353 | } else { |
| 1343 | 1354 | /* still need to build got entries in case of static link */ |
| 1344 | 1355 | build_got_entries(s1); |
| @@ -1714,7 +1725,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 369 unmodified lines | ||
| 1714 | 1725 | ehdr.e_ident[1] = ELFMAG1; |
| 1715 | 1726 | ehdr.e_ident[2] = ELFMAG2; |
| 1716 | 1727 | ehdr.e_ident[3] = ELFMAG3; |
| 1717 | − ehdr.e_ident[4] = ELFCLASS32; | |
| 1728 | + ehdr.e_ident[4] = TCC_ELFCLASS; | |
| 1718 | 1729 | ehdr.e_ident[5] = ELFDATA2LSB; |
| 1719 | 1730 | ehdr.e_ident[6] = EV_CURRENT; |
| 1720 | 1731 | #ifdef __FreeBSD__ |