Still some more tabs to be taken care of. arm-gen.c and tcccoff.c have so many style issues that I'm just going to throw clang-format at them.
Showing the changes to tccelf.c (1 of 10 files). Show all
Unified · Split
| @@ -451,7 +451,7 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve) · 450 unmodified lines | |||
| 451 | if (addr) { | 451 | if (addr) { |
| 452 | sym->st_value = (addr_t)addr; | 452 | sym->st_value = (addr_t)addr; |
| 453 | #ifdef DEBUG_RELOC | 453 | #ifdef DEBUG_RELOC |
| 454 | printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value); | 454 | printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value); |
| 455 | #endif | 455 | #endif |
| 456 | goto found; | 456 | goto found; |
| 457 | } | 457 | } |
| @@ -580,10 +580,10 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 122 unmodified lines | |||
| 580 | { | 580 | { |
| 581 | int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko; | 581 | int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko; |
| 582 | x = (*(int *) ptr) & 0xffffff; | 582 | x = (*(int *) ptr) & 0xffffff; |
| 583 | if (sym->st_shndx == SHN_UNDEF) | 583 | if (sym->st_shndx == SHN_UNDEF) |
| 584 | val = s1->plt->sh_addr; | 584 | val = s1->plt->sh_addr; |
| 585 | #ifdef DEBUG_RELOC | 585 | #ifdef DEBUG_RELOC |
| 586 | printf ("reloc %d: x=0x%x val=0x%x ", type, x, val); | 586 | printf ("reloc %d: x=0x%x val=0x%x ", type, x, val); |
| 587 | #endif | 587 | #endif |
| 588 | (*(int *)ptr) &= 0xff000000; | 588 | (*(int *)ptr) &= 0xff000000; |
| 589 | if (x & 0x800000) | 589 | if (x & 0x800000) |
| @@ -595,8 +595,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 5 unmodified lines | |||
| 595 | is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl)); | 595 | is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl)); |
| 596 | x += val - addr; | 596 | x += val - addr; |
| 597 | #ifdef DEBUG_RELOC | 597 | #ifdef DEBUG_RELOC |
| 598 | printf (" newx=0x%x name=%s\n", x, | 598 | printf (" newx=0x%x name=%s\n", x, |
| 599 | (char *) symtab_section->link->data + sym->st_name); | 599 | (char *) symtab_section->link->data + sym->st_name); |
| 600 | #endif | 600 | #endif |
| 601 | h = x & 2; | 601 | h = x & 2; |
| 602 | th_ko = (x & 3) && (!blx_avail || !is_call); | 602 | th_ko = (x & 3) && (!blx_avail || !is_call); |
| @@ -797,21 +797,21 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 194 unmodified lines | |||
| 797 | break; | 797 | break; |
| 798 | case R_AARCH64_JUMP26: | 798 | case R_AARCH64_JUMP26: |
| 799 | case R_AARCH64_CALL26: | 799 | case R_AARCH64_CALL26: |
| 800 | /* This check must match the one in build_got_entries, testing | 800 | /* This check must match the one in build_got_entries, testing |
| 801 | if we really need a PLT slot. */ | 801 | if we really need a PLT slot. */ |
| 802 | if (sym->st_shndx == SHN_UNDEF) | 802 | if (sym->st_shndx == SHN_UNDEF) |
| 803 | /* We've put the PLT slot offset into r_addend when generating | 803 | /* We've put the PLT slot offset into r_addend when generating |
| 804 | it, and that's what we must use as relocation value (adjusted | 804 | it, and that's what we must use as relocation value (adjusted |
| 805 | by section offset of course). */ | 805 | by section offset of course). */ |
| 806 | val = s1->plt->sh_addr + rel->r_addend; | 806 | val = s1->plt->sh_addr + rel->r_addend; |
| 807 | #ifdef DEBUG_RELOC | 807 | #ifdef DEBUG_RELOC |
| 808 | printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val, | 808 | printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val, |
| 809 | (char *) symtab_section->link->data + sym->st_name); | 809 | (char *) symtab_section->link->data + sym->st_name); |
| 810 | #endif | 810 | #endif |
| 811 | if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc) | 811 | if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc) |
| 812 | { | 812 | { |
| 813 | tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed (val=%lx, addr=%lx)", addr, val); | 813 | tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed (val=%lx, addr=%lx)", addr, val); |
| 814 | } | 814 | } |
| 815 | *(uint32_t *)ptr = 0x14000000 | (type == R_AARCH64_CALL26) << 31 | | 815 | *(uint32_t *)ptr = 0x14000000 | (type == R_AARCH64_CALL26) << 31 | |
| 816 | ((val - addr) >> 2 & 0x3ffffff); | 816 | ((val - addr) >> 2 & 0x3ffffff); |
| 817 | break; | 817 | break; |
| @@ -836,9 +836,9 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 18 unmodified lines | |||
| 836 | case R_AARCH64_JUMP_SLOT: | 836 | case R_AARCH64_JUMP_SLOT: |
| 837 | /* They don't need addend */ | 837 | /* They don't need addend */ |
| 838 | #ifdef DEBUG_RELOC | 838 | #ifdef DEBUG_RELOC |
| 839 | printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, | 839 | printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, |
| 840 | val - rel->r_addend, | 840 | val - rel->r_addend, |
| 841 | (char *) symtab_section->link->data + sym->st_name); | 841 | (char *) symtab_section->link->data + sym->st_name); |
| 842 | #endif | 842 | #endif |
| 843 | *(addr_t *)ptr = val - rel->r_addend; | 843 | *(addr_t *)ptr = val - rel->r_addend; |
| 844 | break; | 844 | break; |
| @@ -879,12 +879,12 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 34 unmodified lines | |||
| 879 | qrel->r_offset = rel->r_offset; | 879 | qrel->r_offset = rel->r_offset; |
| 880 | if (esym_index) { | 880 | if (esym_index) { |
| 881 | qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64); | 881 | qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64); |
| 882 | qrel->r_addend = rel->r_addend; | 882 | qrel->r_addend = rel->r_addend; |
| 883 | qrel++; | 883 | qrel++; |
| 884 | break; | 884 | break; |
| 885 | } else { | 885 | } else { |
| 886 | qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE); | 886 | qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE); |
| 887 | qrel->r_addend = *(long long *)ptr + val; | 887 | qrel->r_addend = *(long long *)ptr + val; |
| 888 | qrel++; | 888 | qrel++; |
| 889 | } | 889 | } |
| 890 | } | 890 | } |
| @@ -917,14 +917,14 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 26 unmodified lines | |||
| 917 | goto plt32pc32; | 917 | goto plt32pc32; |
| 918 | 918 | ||
| 919 | case R_X86_64_PLT32: | 919 | case R_X86_64_PLT32: |
| 920 | /* We've put the PLT slot offset into r_addend when generating | 920 | /* We've put the PLT slot offset into r_addend when generating |
| 921 | it, and that's what we must use as relocation value (adjusted | 921 | it, and that's what we must use as relocation value (adjusted |
| 922 | by section offset of course). */ | 922 | by section offset of course). */ |
| 923 | val = s1->plt->sh_addr + rel->r_addend; | 923 | val = s1->plt->sh_addr + rel->r_addend; |
| 924 | /* fallthrough. */ | 924 | /* fallthrough. */ |
| 925 | 925 | ||
| 926 | plt32pc32: | 926 | plt32pc32: |
| 927 | { | 927 | { |
| 928 | long long diff; | 928 | long long diff; |
| 929 | diff = (long long)val - addr; | 929 | diff = (long long)val - addr; |
| 930 | if (diff < -2147483648LL || diff > 2147483647LL) { | 930 | if (diff < -2147483648LL || diff > 2147483647LL) { |
| @@ -1080,8 +1080,8 @@ static void build_got(TCCState *s1) · 149 unmodified lines | |||
| 1080 | and 'info' can be modifed if more precise info comes from the DLL. | 1080 | and 'info' can be modifed if more precise info comes from the DLL. |
| 1081 | Returns offset of GOT or PLT slot. */ | 1081 | Returns offset of GOT or PLT slot. */ |
| 1082 | static unsigned long put_got_entry(TCCState *s1, | 1082 | static unsigned long put_got_entry(TCCState *s1, |
| 1083 | int reloc_type, unsigned long size, int info, | 1083 | int reloc_type, unsigned long size, int info, |
| 1084 | int sym_index) | 1084 | int sym_index) |
| 1085 | { | 1085 | { |
| 1086 | int index, need_plt_entry; | 1086 | int index, need_plt_entry; |
| 1087 | const char *name; | 1087 | const char *name; |
| @@ -1107,18 +1107,18 @@ static unsigned long put_got_entry(TCCState *s1, · 19 unmodified lines | |||
| 1107 | #endif | 1107 | #endif |
| 1108 | 1108 | ||
| 1109 | if (need_plt_entry && !s1->plt) { | 1109 | if (need_plt_entry && !s1->plt) { |
| 1110 | /* add PLT */ | 1110 | /* add PLT */ |
| 1111 | s1->plt = new_section(s1, ".plt", SHT_PROGBITS, | 1111 | s1->plt = new_section(s1, ".plt", SHT_PROGBITS, |
| 1112 | SHF_ALLOC | SHF_EXECINSTR); | 1112 | SHF_ALLOC | SHF_EXECINSTR); |
| 1113 | s1->plt->sh_entsize = 4; | 1113 | s1->plt->sh_entsize = 4; |
| 1114 | } | 1114 | } |
| 1115 | 1115 | ||
| 1116 | /* If a got/plt entry already exists for that symbol, no need to add one */ | 1116 | /* If a got/plt entry already exists for that symbol, no need to add one */ |
| 1117 | if (sym_index < s1->nb_sym_attrs) { | 1117 | if (sym_index < s1->nb_sym_attrs) { |
| 1118 | if (need_plt_entry && s1->sym_attrs[sym_index].plt_offset) | 1118 | if (need_plt_entry && s1->sym_attrs[sym_index].plt_offset) |
| 1119 | return s1->sym_attrs[sym_index].plt_offset; | 1119 | return s1->sym_attrs[sym_index].plt_offset; |
| 1120 | else if (!need_plt_entry && s1->sym_attrs[sym_index].got_offset) | 1120 | else if (!need_plt_entry && s1->sym_attrs[sym_index].got_offset) |
| 1121 | return s1->sym_attrs[sym_index].got_offset; | 1121 | return s1->sym_attrs[sym_index].got_offset; |
| 1122 | } | 1122 | } |
| 1123 | 1123 | ||
| 1124 | symattr = alloc_sym_attr(s1, sym_index); | 1124 | symattr = alloc_sym_attr(s1, sym_index); |
| @@ -1135,7 +1135,7 @@ static unsigned long put_got_entry(TCCState *s1, · 10 unmodified lines | |||
| 1135 | Section *plt; | 1135 | Section *plt; |
| 1136 | uint8_t *p; | 1136 | uint8_t *p; |
| 1137 | int modrm; | 1137 | int modrm; |
| 1138 | unsigned long relofs; | 1138 | unsigned long relofs; |
| 1139 | 1139 | ||
| 1140 | #if defined(TCC_OUTPUT_DLL_WITH_PLT) | 1140 | #if defined(TCC_OUTPUT_DLL_WITH_PLT) |
| 1141 | modrm = 0x25; | 1141 | modrm = 0x25; |
| @@ -1160,10 +1160,10 @@ static unsigned long put_got_entry(TCCState *s1, · 18 unmodified lines | |||
| 1160 | put32(p + 8, PTR_SIZE * 2); | 1160 | put32(p + 8, PTR_SIZE * 2); |
| 1161 | } | 1161 | } |
| 1162 | 1162 | ||
| 1163 | /* The PLT slot refers to the relocation entry it needs | 1163 | /* The PLT slot refers to the relocation entry it needs |
| 1164 | via offset. The reloc entry is created below, so its | 1164 | via offset. The reloc entry is created below, so its |
| 1165 | offset is the current data_offset. */ | 1165 | offset is the current data_offset. */ |
| 1166 | relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0; | 1166 | relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0; |
| 1167 | symattr->plt_offset = plt->data_offset; | 1167 | symattr->plt_offset = plt->data_offset; |
| 1168 | p = section_ptr_add(plt, 16); | 1168 | p = section_ptr_add(plt, 16); |
| 1169 | p[0] = 0xff; /* jmp *(got + x) */ | 1169 | p[0] = 0xff; /* jmp *(got + x) */ |
| @@ -1171,19 +1171,19 @@ static unsigned long put_got_entry(TCCState *s1, · 1 unmodified line | |||
| 1171 | put32(p + 2, s1->got->data_offset); | 1171 | put32(p + 2, s1->got->data_offset); |
| 1172 | p[6] = 0x68; /* push $xxx */ | 1172 | p[6] = 0x68; /* push $xxx */ |
| 1173 | #ifdef TCC_TARGET_X86_64 | 1173 | #ifdef TCC_TARGET_X86_64 |
| 1174 | /* On x86-64, the relocation is referred to by _index_. */ | 1174 | /* On x86-64, the relocation is referred to by _index_. */ |
| 1175 | put32(p + 7, relofs / sizeof (ElfW_Rel)); | 1175 | put32(p + 7, relofs / sizeof (ElfW_Rel)); |
| 1176 | #else | 1176 | #else |
| 1177 | put32(p + 7, relofs); | 1177 | put32(p + 7, relofs); |
| 1178 | #endif | 1178 | #endif |
| 1179 | p[11] = 0xe9; /* jmp plt_start */ | 1179 | p[11] = 0xe9; /* jmp plt_start */ |
| 1180 | put32(p + 12, -(plt->data_offset)); | 1180 | put32(p + 12, -(plt->data_offset)); |
| 1181 | 1181 | ||
| 1182 | /* If this was an UNDEF symbol set the offset in the | 1182 | /* If this was an UNDEF symbol set the offset in the |
| 1183 | dynsymtab to the PLT slot, so that PC32 relocs to it | 1183 | dynsymtab to the PLT slot, so that PC32 relocs to it |
| 1184 | can be resolved. */ | 1184 | can be resolved. */ |
| 1185 | if (sym->st_shndx == SHN_UNDEF) | 1185 | if (sym->st_shndx == SHN_UNDEF) |
| 1186 | offset = plt->data_offset - 16; | 1186 | offset = plt->data_offset - 16; |
| 1187 | } | 1187 | } |
| 1188 | #elif defined(TCC_TARGET_ARM) | 1188 | #elif defined(TCC_TARGET_ARM) |
| 1189 | if (need_plt_entry) { | 1189 | if (need_plt_entry) { |
| @@ -1220,7 +1220,7 @@ static unsigned long put_got_entry(TCCState *s1, · 30 unmodified lines | |||
| 1220 | 1220 | ||
| 1221 | /* the symbol is modified so that it will be relocated to | 1221 | /* the symbol is modified so that it will be relocated to |
| 1222 | the PLT */ | 1222 | the PLT */ |
| 1223 | if (sym->st_shndx == SHN_UNDEF) | 1223 | if (sym->st_shndx == SHN_UNDEF) |
| 1224 | offset = plt->data_offset - 16; | 1224 | offset = plt->data_offset - 16; |
| 1225 | } | 1225 | } |
| 1226 | #elif defined(TCC_TARGET_ARM64) | 1226 | #elif defined(TCC_TARGET_ARM64) |
| @@ -1250,19 +1250,19 @@ static unsigned long put_got_entry(TCCState *s1, · 23 unmodified lines | |||
| 1250 | #error unsupported CPU | 1250 | #error unsupported CPU |
| 1251 | #endif | 1251 | #endif |
| 1252 | if (s1->dynsym) { | 1252 | if (s1->dynsym) { |
| 1253 | /* XXX This might generate multiple syms for name. */ | 1253 | /* XXX This might generate multiple syms for name. */ |
| 1254 | index = put_elf_sym(s1->dynsym, offset, | 1254 | index = put_elf_sym(s1->dynsym, offset, |
| 1255 | size, info, 0, sym->st_shndx, name); | 1255 | size, info, 0, sym->st_shndx, name); |
| 1256 | /* Create the relocation (it's against the GOT for PLT | 1256 | /* Create the relocation (it's against the GOT for PLT |
| 1257 | and GOT relocs). */ | 1257 | and GOT relocs). */ |
| 1258 | put_elf_reloc(s1->dynsym, s1->got, | 1258 | put_elf_reloc(s1->dynsym, s1->got, |
| 1259 | s1->got->data_offset, | 1259 | s1->got->data_offset, |
| 1260 | reloc_type, index); | 1260 | reloc_type, index); |
| 1261 | } else { | 1261 | } else { |
| 1262 | /* Without .dynsym (i.e. static link or memory output) we | 1262 | /* Without .dynsym (i.e. static link or memory output) we |
| 1263 | still need relocs against the generated got, so as to fill | 1263 | still need relocs against the generated got, so as to fill |
| 1264 | the entries with the symbol values (determined later). */ | 1264 | the entries with the symbol values (determined later). */ |
| 1265 | put_elf_reloc(symtab_section, s1->got, | 1265 | put_elf_reloc(symtab_section, s1->got, |
| 1266 | s1->got->data_offset, | 1266 | s1->got->data_offset, |
| 1267 | reloc_type, sym_index); | 1267 | reloc_type, sym_index); |
| 1268 | } | 1268 | } |
| @@ -1324,8 +1324,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 55 unmodified lines | |||
| 1324 | build_got(s1); | 1324 | build_got(s1); |
| 1325 | sym_index = ELFW(R_SYM)(rel->r_info); | 1325 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 1326 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; | 1326 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 1327 | if (type != R_ARM_GOTOFF && type != R_ARM_GOTPC | 1327 | if (type != R_ARM_GOTOFF && type != R_ARM_GOTPC |
| 1328 | && sym->st_shndx == SHN_UNDEF) { | 1328 | && sym->st_shndx == SHN_UNDEF) { |
| 1329 | unsigned long ofs; | 1329 | unsigned long ofs; |
| 1330 | /* look at the symbol got offset. If none, then add one */ | 1330 | /* look at the symbol got offset. If none, then add one */ |
| 1331 | if (type == R_ARM_GOT32) | 1331 | if (type == R_ARM_GOT32) |
| @@ -1333,27 +1333,27 @@ ST_FUNC void build_got_entries(TCCState *s1) · 1 unmodified line | |||
| 1333 | else | 1333 | else |
| 1334 | reloc_type = R_ARM_JUMP_SLOT; | 1334 | reloc_type = R_ARM_JUMP_SLOT; |
| 1335 | ofs = put_got_entry(s1, reloc_type, sym->st_size, | 1335 | ofs = put_got_entry(s1, reloc_type, sym->st_size, |
| 1336 | sym->st_info, sym_index); | 1336 | sym->st_info, sym_index); |
| 1337 | #ifdef DEBUG_RELOC | 1337 | #ifdef DEBUG_RELOC |
| 1338 | printf ("maybegot: %s, %d, %d --> ofs=0x%x\n", | 1338 | printf ("maybegot: %s, %d, %d --> ofs=0x%x\n", |
| 1339 | (char *) symtab_section->link->data + sym->st_name, | 1339 | (char *) symtab_section->link->data + sym->st_name, |
| 1340 | type, sym->st_shndx, ofs); | 1340 | type, sym->st_shndx, ofs); |
| 1341 | #endif | 1341 | #endif |
| 1342 | if (type != R_ARM_GOT32) { | 1342 | if (type != R_ARM_GOT32) { |
| 1343 | addr_t *ptr = (addr_t*)(s1->sections[s->sh_info]->data | 1343 | addr_t *ptr = (addr_t*)(s1->sections[s->sh_info]->data |
| 1344 | + rel->r_offset); | 1344 | + rel->r_offset); |
| 1345 | /* x must be signed! */ | 1345 | /* x must be signed! */ |
| 1346 | int x = *ptr & 0xffffff; | 1346 | int x = *ptr & 0xffffff; |
| 1347 | x = (x << 8) >> 8; | 1347 | x = (x << 8) >> 8; |
| 1348 | x <<= 2; | 1348 | x <<= 2; |
| 1349 | x += ofs; | 1349 | x += ofs; |
| 1350 | x >>= 2; | 1350 | x >>= 2; |
| 1351 | #ifdef DEBUG_RELOC | 1351 | #ifdef DEBUG_RELOC |
| 1352 | printf ("insn=0x%x --> 0x%x (x==0x%x)\n", *ptr, | 1352 | printf ("insn=0x%x --> 0x%x (x==0x%x)\n", *ptr, |
| 1353 | (*ptr & 0xff000000) | x, x); | 1353 | (*ptr & 0xff000000) | x, x); |
| 1354 | #endif | 1354 | #endif |
| 1355 | *ptr = (*ptr & 0xff000000) | x; | 1355 | *ptr = (*ptr & 0xff000000) | x; |
| 1356 | } | 1356 | } |
| 1357 | } | 1357 | } |
| 1358 | break; | 1358 | break; |
| 1359 | case R_ARM_THM_JUMP24: | 1359 | case R_ARM_THM_JUMP24: |
| @@ -1397,22 +1397,22 @@ ST_FUNC void build_got_entries(TCCState *s1) · 37 unmodified lines | |||
| 1397 | sym_index); | 1397 | sym_index); |
| 1398 | break; | 1398 | break; |
| 1399 | 1399 | ||
| 1400 | case R_AARCH64_JUMP26: | 1400 | case R_AARCH64_JUMP26: |
| 1401 | case R_AARCH64_CALL26: | 1401 | case R_AARCH64_CALL26: |
| 1402 | if (!s1->got) | 1402 | if (!s1->got) |
| 1403 | build_got(s1); | 1403 | build_got(s1); |
| 1404 | sym_index = ELFW(R_SYM)(rel->r_info); | 1404 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 1405 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; | 1405 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 1406 | if (sym->st_shndx == SHN_UNDEF) { | 1406 | if (sym->st_shndx == SHN_UNDEF) { |
| 1407 | unsigned long ofs; | 1407 | unsigned long ofs; |
| 1408 | reloc_type = R_AARCH64_JUMP_SLOT; | 1408 | reloc_type = R_AARCH64_JUMP_SLOT; |
| 1409 | ofs = put_got_entry(s1, reloc_type, sym->st_size, | 1409 | ofs = put_got_entry(s1, reloc_type, sym->st_size, |
| 1410 | sym->st_info, sym_index); | 1410 | sym->st_info, sym_index); |
| 1411 | /* We store the place of the generated PLT slot | 1411 | /* We store the place of the generated PLT slot |
| 1412 | in our addend. */ | 1412 | in our addend. */ |
| 1413 | rel->r_addend += ofs; | 1413 | rel->r_addend += ofs; |
| 1414 | } | 1414 | } |
| 1415 | break; | 1415 | break; |
| 1416 | #elif defined(TCC_TARGET_C67) | 1416 | #elif defined(TCC_TARGET_C67) |
| 1417 | case R_C60_GOT32: | 1417 | case R_C60_GOT32: |
| 1418 | case R_C60_GOTOFF: | 1418 | case R_C60_GOTOFF: |
| @@ -1439,29 +1439,29 @@ ST_FUNC void build_got_entries(TCCState *s1) · 20 unmodified lines | |||
| 1439 | case R_X86_64_PLT32: | 1439 | case R_X86_64_PLT32: |
| 1440 | sym_index = ELFW(R_SYM)(rel->r_info); | 1440 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 1441 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; | 1441 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 1442 | if (type == R_X86_64_PLT32 && | 1442 | if (type == R_X86_64_PLT32 && |
| 1443 | ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT) | 1443 | ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT) |
| 1444 | { | 1444 | { |
| 1445 | rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32); | 1445 | rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32); |
| 1446 | break; | 1446 | break; |
| 1447 | } | 1447 | } |
| 1448 | 1448 | ||
| 1449 | if (!s1->got) | 1449 | if (!s1->got) |
| 1450 | build_got(s1); | 1450 | build_got(s1); |
| 1451 | if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL || | 1451 | if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL || |
| 1452 | type == R_X86_64_PLT32) { | 1452 | type == R_X86_64_PLT32) { |
| 1453 | unsigned long ofs; | 1453 | unsigned long ofs; |
| 1454 | /* look at the symbol got offset. If none, then add one */ | 1454 | /* look at the symbol got offset. If none, then add one */ |
| 1455 | if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL) | 1455 | if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL) |
| 1456 | reloc_type = R_X86_64_GLOB_DAT; | 1456 | reloc_type = R_X86_64_GLOB_DAT; |
| 1457 | else | 1457 | else |
| 1458 | reloc_type = R_X86_64_JUMP_SLOT; | 1458 | reloc_type = R_X86_64_JUMP_SLOT; |
| 1459 | ofs = put_got_entry(s1, reloc_type, sym->st_size, | 1459 | ofs = put_got_entry(s1, reloc_type, sym->st_size, |
| 1460 | sym->st_info, sym_index); | 1460 | sym->st_info, sym_index); |
| 1461 | if (type == R_X86_64_PLT32) | 1461 | if (type == R_X86_64_PLT32) |
| 1462 | /* We store the place of the generated PLT slot | 1462 | /* We store the place of the generated PLT slot |
| 1463 | in our addend. */ | 1463 | in our addend. */ |
| 1464 | rel->r_addend += ofs; | 1464 | rel->r_addend += ofs; |
| 1465 | } | 1465 | } |
| 1466 | break; | 1466 | break; |
| 1467 | #else | 1467 | #else |
| @@ -1546,21 +1546,21 @@ static int tcc_add_support(TCCState *s1, const char *filename) · 78 unmodified lines | |||
| 1546 | snprintf(buf, sizeof(buf), "%s/%s/%s", s1->tcc_lib_path, | 1546 | snprintf(buf, sizeof(buf), "%s/%s/%s", s1->tcc_lib_path, |
| 1547 | /* an cpu specific path inside tcc_lib_path, mainly for keeping libtcc1.a */ | 1547 | /* an cpu specific path inside tcc_lib_path, mainly for keeping libtcc1.a */ |
| 1548 | #ifdef TCC_TARGET_I386 | 1548 | #ifdef TCC_TARGET_I386 |
| 1549 | "i386" | 1549 | "i386" |
| 1550 | #endif | 1550 | #endif |
| 1551 | #ifdef TCC_TARGET_X86_64 | 1551 | #ifdef TCC_TARGET_X86_64 |
| 1552 | "x86-64" | 1552 | "x86-64" |
| 1553 | #endif | 1553 | #endif |
| 1554 | #ifdef TCC_TARGET_ARM | 1554 | #ifdef TCC_TARGET_ARM |
| 1555 | "arm" | 1555 | "arm" |
| 1556 | #endif | 1556 | #endif |
| 1557 | #ifdef TCC_TARGET_ARM64 | 1557 | #ifdef TCC_TARGET_ARM64 |
| 1558 | "arm64" | 1558 | "arm64" |
| 1559 | #endif | 1559 | #endif |
| 1560 | #ifdef TCC_TARGET_C67 | 1560 | #ifdef TCC_TARGET_C67 |
| 1561 | "C67" | 1561 | "C67" |
| 1562 | #endif | 1562 | #endif |
| 1563 | ,filename); | 1563 | ,filename); |
| 1564 | 1564 | ||
| 1565 | return tcc_add_file(s1, buf, TCC_FILETYPE_BINARY); | 1565 | return tcc_add_file(s1, buf, TCC_FILETYPE_BINARY); |
| 1566 | } | 1566 | } |
| @@ -1587,17 +1587,17 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 20 unmodified lines | |||
| 1587 | when __bound_ptr_add, __bound_new_region, | 1587 | when __bound_ptr_add, __bound_new_region, |
| 1588 | __bound_delete_region called */ | 1588 | __bound_delete_region called */ |
| 1589 | 1589 | ||
| 1590 | int sym_index = find_elf_sym(symtab_section, "__bound_init"); | 1590 | int sym_index = find_elf_sym(symtab_section, "__bound_init"); |
| 1591 | if (sym_index) { | 1591 | if (sym_index) { |
| 1592 | Section *init_section = find_section(s1, ".init"); | 1592 | Section *init_section = find_section(s1, ".init"); |
| 1593 | unsigned char *pinit = section_ptr_add(init_section, 5); | 1593 | unsigned char *pinit = section_ptr_add(init_section, 5); |
| 1594 | pinit[0] = 0xe8; | 1594 | pinit[0] = 0xe8; |
| 1595 | put32(pinit + 1, -4); | 1595 | put32(pinit + 1, -4); |
| 1596 | put_elf_reloc(symtab_section, init_section, | 1596 | put_elf_reloc(symtab_section, init_section, |
| 1597 | init_section->data_offset - 4, R_386_PC32, sym_index); | 1597 | init_section->data_offset - 4, R_386_PC32, sym_index); |
| 1598 | } | 1598 | } |
| 1599 | else | 1599 | else |
| 1600 | tcc_warning("__bound_init not defined"); | 1600 | tcc_warning("__bound_init not defined"); |
| 1601 | } | 1601 | } |
| 1602 | #endif | 1602 | #endif |
| 1603 | } | 1603 | } |
| @@ -1905,11 +1905,11 @@ static void export_global_syms(TCCState *s1) · 301 unmodified lines | |||
| 1905 | s1->symtab_to_dynsym = tcc_mallocz(sizeof(int) * nb_syms); | 1905 | s1->symtab_to_dynsym = tcc_mallocz(sizeof(int) * nb_syms); |
| 1906 | for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { | 1906 | for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { |
| 1907 | if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { | 1907 | if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { |
| 1908 | name = (char *) symtab_section->link->data + sym->st_name; | 1908 | name = (char *) symtab_section->link->data + sym->st_name; |
| 1909 | dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, | 1909 | dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, |
| 1910 | sym->st_info, 0, sym->st_shndx, name); | 1910 | sym->st_info, 0, sym->st_shndx, name); |
| 1911 | index = sym - (ElfW(Sym) *) symtab_section->data; | 1911 | index = sym - (ElfW(Sym) *) symtab_section->data; |
| 1912 | s1->symtab_to_dynsym[index] = dynindex; | 1912 | s1->symtab_to_dynsym[index] = dynindex; |
| 1913 | } | 1913 | } |
| 1914 | } | 1914 | } |
| 1915 | } | 1915 | } |
| @@ -2179,15 +2179,15 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 263 unmodified lines | |||
| 2179 | file_offset += s->sh_size; | 2179 | file_offset += s->sh_size; |
| 2180 | } | 2180 | } |
| 2181 | } | 2181 | } |
| 2182 | if (j == 0) { | 2182 | if (j == 0) { |
| 2183 | /* Make the first PT_LOAD segment include the program | 2183 | /* Make the first PT_LOAD segment include the program |
| 2184 | headers itself (and the ELF header as well), it'll | 2184 | headers itself (and the ELF header as well), it'll |
| 2185 | come out with same memory use but will make various | 2185 | come out with same memory use but will make various |
| 2186 | tools like binutils strip work better. */ | 2186 | tools like binutils strip work better. */ |
| 2187 | ph->p_offset &= ~(ph->p_align - 1); | 2187 | ph->p_offset &= ~(ph->p_align - 1); |
| 2188 | ph->p_vaddr &= ~(ph->p_align - 1); | 2188 | ph->p_vaddr &= ~(ph->p_align - 1); |
| 2189 | ph->p_paddr &= ~(ph->p_align - 1); | 2189 | ph->p_paddr &= ~(ph->p_align - 1); |
| 2190 | } | 2190 | } |
| 2191 | ph->p_filesz = file_offset - ph->p_offset; | 2191 | ph->p_filesz = file_offset - ph->p_offset; |
| 2192 | ph->p_memsz = addr - ph->p_vaddr; | 2192 | ph->p_memsz = addr - ph->p_vaddr; |
| 2193 | ph++; | 2193 | ph++; |
| @@ -2662,10 +2662,10 @@ static int elf_output_file(TCCState *s1, const char *filename) · 468 unmodified lines | |||
| 2662 | for_each_elem(s1->dynsym, 1, sym, ElfW(Sym)) { | 2662 | for_each_elem(s1->dynsym, 1, sym, ElfW(Sym)) { |
| 2663 | if (sym->st_shndx == SHN_UNDEF) { | 2663 | if (sym->st_shndx == SHN_UNDEF) { |
| 2664 | /* relocate to PLT if symbol corresponds to a PLT entry, | 2664 | /* relocate to PLT if symbol corresponds to a PLT entry, |
| 2665 | but not if it's a weak symbol */ | 2665 | but not if it's a weak symbol */ |
| 2666 | if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK) | 2666 | if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK) |
| 2667 | sym->st_value = 0; | 2667 | sym->st_value = 0; |
| 2668 | else if (sym->st_value) | 2668 | else if (sym->st_value) |
| 2669 | sym->st_value += s1->plt->sh_addr; | 2669 | sym->st_value += s1->plt->sh_addr; |
| 2670 | } else if (sym->st_shndx < SHN_LORESERVE) { | 2670 | } else if (sym->st_shndx < SHN_LORESERVE) { |
| 2671 | /* do symbol relocation */ | 2671 | /* do symbol relocation */ |
| @@ -2690,14 +2690,14 @@ static int elf_output_file(TCCState *s1, const char *filename) · 18 unmodified lines | |||
| 2690 | /* Create the ELF file with name 'filename' */ | 2690 | /* Create the ELF file with name 'filename' */ |
| 2691 | ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order); | 2691 | ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order); |
| 2692 | if (s1->do_strip) { | 2692 | if (s1->do_strip) { |
| 2693 | int rc; | 2693 | int rc; |
| 2694 | const char *strip_cmd = "sstrip "; // super strip utility from ELFkickers | 2694 | const char *strip_cmd = "sstrip "; // super strip utility from ELFkickers |
| 2695 | const char *null_dev = " 2> /dev/null"; | 2695 | const char *null_dev = " 2> /dev/null"; |
| 2696 | char buf[1050]; | 2696 | char buf[1050]; |
| 2697 | snprintf(buf, sizeof(buf), "%s%s%s", strip_cmd, filename, null_dev); | 2697 | snprintf(buf, sizeof(buf), "%s%s%s", strip_cmd, filename, null_dev); |
| 2698 | rc = system(buf); | 2698 | rc = system(buf); |
| 2699 | if (rc) | 2699 | if (rc) |
| 2700 | system(buf+1); // call a strip utility from binutils | 2700 | system(buf+1); // call a strip utility from binutils |
| 2701 | } | 2701 | } |
| 2702 | the_end: | 2702 | the_end: |
| 2703 | tcc_free(s1->symtab_to_dynsym); | 2703 | tcc_free(s1->symtab_to_dynsym); |