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