| @@ -851,8 +851,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 850 unmodified lines |
| 851 | /* We've put the PLT slot offset into r_addend when generating | 851 | /* We've put the PLT slot offset into r_addend when generating |
| 852 | it, and that's what we must use as relocation value (adjusted | 852 | it, and that's what we must use as relocation value (adjusted |
| 853 | by section offset of course). */ | 853 | by section offset of course). */ |
| 854 | if (s1->output_type != TCC_OUTPUT_MEMORY) | 854 | val = s1->plt->sh_addr + rel->r_addend; |
| 855 | val = s1->plt->sh_addr + rel->r_addend; | | |
| 856 | /* fallthrough. */ | 855 | /* fallthrough. */ |
| 857 | | 856 | |
| 858 | plt32pc32: | 857 | plt32pc32: |
| @@ -878,7 +877,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 19 unmodified lines |
| 878 | case R_X86_64_GLOB_DAT: | 877 | case R_X86_64_GLOB_DAT: |
| 879 | case R_X86_64_JUMP_SLOT: | 878 | case R_X86_64_JUMP_SLOT: |
| 880 | /* They don't need addend */ | 879 | /* They don't need addend */ |
| 881 | *(int *)ptr = val - rel->r_addend; | 880 | *(addr_t *)ptr = val - rel->r_addend; |
| 882 | break; | 881 | break; |
| 883 | case R_X86_64_GOTPCREL: | 882 | case R_X86_64_GOTPCREL: |
| 884 | #ifdef TCC_HAS_RUNTIME_PLTGOT | 883 | #ifdef TCC_HAS_RUNTIME_PLTGOT |
| @@ -1042,7 +1041,7 @@ static unsigned long put_got_entry(TCCState *s1, · 157 unmodified lines |
| 1042 | if (!s1->got) | 1041 | if (!s1->got) |
| 1043 | build_got(s1); | 1042 | build_got(s1); |
| 1044 | | 1043 | |
| 1045 | need_plt_entry = s1->dynsym && | 1044 | need_plt_entry = |
| 1046 | #ifdef TCC_TARGET_X86_64 | 1045 | #ifdef TCC_TARGET_X86_64 |
| 1047 | (reloc_type == R_X86_64_JUMP_SLOT); | 1046 | (reloc_type == R_X86_64_JUMP_SLOT); |
| 1048 | #elif defined(TCC_TARGET_I386) | 1047 | #elif defined(TCC_TARGET_I386) |
| @@ -1053,6 +1052,13 @@ static unsigned long put_got_entry(TCCState *s1, · 4 unmodified lines |
| 1053 | 0; | 1052 | 0; |
| 1054 | #endif | 1053 | #endif |
| 1055 | | 1054 | |
| | 1055 | if (need_plt_entry && !s1->plt) { |
| | 1056 | /* add PLT */ |
| | 1057 | s1->plt = new_section(s1, ".plt", SHT_PROGBITS, |
| | 1058 | SHF_ALLOC | SHF_EXECINSTR); |
| | 1059 | s1->plt->sh_entsize = 4; |
| | 1060 | } |
| | 1061 | |
| 1056 | /* If a got/plt entry already exists for that symbol, no need to add one */ | 1062 | /* If a got/plt entry already exists for that symbol, no need to add one */ |
| 1057 | if (sym_index < s1->nb_sym_attrs) { | 1063 | if (sym_index < s1->nb_sym_attrs) { |
| 1058 | if (need_plt_entry && s1->sym_attrs[sym_index].plt_offset) | 1064 | if (need_plt_entry && s1->sym_attrs[sym_index].plt_offset) |
| @@ -1067,10 +1073,9 @@ static unsigned long put_got_entry(TCCState *s1, · 8 unmodified lines |
| 1067 | if (!need_plt_entry) | 1073 | if (!need_plt_entry) |
| 1068 | symattr->got_offset = s1->got->data_offset; | 1074 | symattr->got_offset = s1->got->data_offset; |
| 1069 | | 1075 | |
| 1070 | if (s1->dynsym) { | 1076 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 1071 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; | 1077 | name = (char *) symtab_section->link->data + sym->st_name; |
| 1072 | name = (char *) symtab_section->link->data + sym->st_name; | 1078 | offset = sym->st_value; |
| 1073 | offset = sym->st_value; | | |
| 1074 | #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) | 1079 | #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) |
| 1075 | if (need_plt_entry) { | 1080 | if (need_plt_entry) { |
| 1076 | Section *plt; | 1081 | Section *plt; |
| @@ -1165,10 +1170,13 @@ static unsigned long put_got_entry(TCCState *s1, · 88 unmodified lines |
| 1165 | offset = plt->data_offset - 16; | 1170 | offset = plt->data_offset - 16; |
| 1166 | } | 1171 | } |
| 1167 | #elif defined(TCC_TARGET_C67) | 1172 | #elif defined(TCC_TARGET_C67) |
| | 1173 | if (s1->dynsym) { |
| 1168 | tcc_error("C67 got not implemented"); | 1174 | tcc_error("C67 got not implemented"); |
| | 1175 | } |
| 1169 | #else | 1176 | #else |
| 1170 | #error unsupported CPU | 1177 | #error unsupported CPU |
| 1171 | #endif | 1178 | #endif |
| | 1179 | if (s1->dynsym) { |
| 1172 | /* XXX This might generate multiple syms for name. */ | 1180 | /* XXX This might generate multiple syms for name. */ |
| 1173 | index = put_elf_sym(s1->dynsym, offset, | 1181 | index = put_elf_sym(s1->dynsym, offset, |
| 1174 | size, info, 0, sym->st_shndx, name); | 1182 | size, info, 0, sym->st_shndx, name); |
| @@ -1316,8 +1324,7 @@ ST_FUNC void build_got_entries(TCCState *s1) · 141 unmodified lines |
| 1316 | reloc_type = R_X86_64_JUMP_SLOT; | 1324 | reloc_type = R_X86_64_JUMP_SLOT; |
| 1317 | ofs = put_got_entry(s1, reloc_type, sym->st_size, | 1325 | ofs = put_got_entry(s1, reloc_type, sym->st_size, |
| 1318 | sym->st_info, sym_index); | 1326 | sym->st_info, sym_index); |
| 1319 | if (type == R_X86_64_PLT32 | 1327 | if (type == R_X86_64_PLT32) |
| 1320 | && s1->output_type != TCC_OUTPUT_MEMORY) | | |
| 1321 | /* We store the place of the generated PLT slot | 1328 | /* We store the place of the generated PLT slot |
| 1322 | in our addend. */ | 1329 | in our addend. */ |
| 1323 | rel->r_addend += ofs; | 1330 | rel->r_addend += ofs; |
| @@ -1754,10 +1761,13 @@ static void export_global_syms(TCCState *s1) · 430 unmodified lines |
| 1754 | | 1761 | |
| 1755 | /* relocate the PLT: compute addresses and offsets in the PLT now that final | 1762 | /* relocate the PLT: compute addresses and offsets in the PLT now that final |
| 1756 | address for PLT and GOT are known (see fill_program_header) */ | 1763 | address for PLT and GOT are known (see fill_program_header) */ |
| 1757 | static void relocate_plt(TCCState *s1) | 1764 | ST_FUNC void relocate_plt(TCCState *s1) |
| 1758 | { | 1765 | { |
| 1759 | uint8_t *p, *p_end; | 1766 | uint8_t *p, *p_end; |
| 1760 | | 1767 | |
| | 1768 | if (!s1->plt) |
| | 1769 | return; |
| | 1770 | |
| 1761 | p = s1->plt->data; | 1771 | p = s1->plt->data; |
| 1762 | p_end = p + s1->plt->data_offset; | 1772 | p_end = p + s1->plt->data_offset; |
| 1763 | if (p < p_end) { | 1773 | if (p < p_end) { |
| @@ -2346,11 +2356,6 @@ static int elf_output_file(TCCState *s1, const char *filename) · 582 unmodified lines |
| 2346 | dynamic->link = dynstr; | 2356 | dynamic->link = dynstr; |
| 2347 | dynamic->sh_entsize = sizeof(ElfW(Dyn)); | 2357 | dynamic->sh_entsize = sizeof(ElfW(Dyn)); |
| 2348 | | 2358 | |
| 2349 | /* add PLT */ | | |
| 2350 | s1->plt = new_section(s1, ".plt", SHT_PROGBITS, | | |
| 2351 | SHF_ALLOC | SHF_EXECINSTR); | | |
| 2352 | s1->plt->sh_entsize = 4; | | |
| 2353 | | | |
| 2354 | build_got(s1); | 2359 | build_got(s1); |
| 2355 | | 2360 | |
| 2356 | if (file_type == TCC_OUTPUT_EXE) { | 2361 | if (file_type == TCC_OUTPUT_EXE) { |