| @@ -18,6 +18,16 @@ · 17 unmodified lines |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ | 19 | */ |
| 20 | | 20 | |
| | 21 | #ifdef TCC_TARGET_X86_64 |
| | 22 | #define ElfW_Rel ElfW(Rela) |
| | 23 | #define SHT_RELX SHT_RELA |
| | 24 | #define REL_SECTION_FMT ".rela%s" |
| | 25 | #else |
| | 26 | #define ElfW_Rel ElfW(Rel) |
| | 27 | #define SHT_RELX SHT_REL |
| | 28 | #define REL_SECTION_FMT ".rel%s" |
| | 29 | #endif |
| | 30 | |
| 21 | static int put_elf_str(Section *s, const char *sym) | 31 | static int put_elf_str(Section *s, const char *sym) |
| 22 | { | 32 | { |
| 23 | int offset, len; | 33 | int offset, len; |
| @@ -49,12 +59,12 @@ static unsigned long elf_hash(const unsigned char *name) · 25 unmodified lines |
| 49 | /* NOTE: we do factorize the hash table code to go faster */ | 59 | /* NOTE: we do factorize the hash table code to go faster */ |
| 50 | static void rebuild_hash(Section *s, unsigned int nb_buckets) | 60 | static void rebuild_hash(Section *s, unsigned int nb_buckets) |
| 51 | { | 61 | { |
| 52 | Elf32_Sym *sym; | 62 | ElfW(Sym) *sym; |
| 53 | int *ptr, *hash, nb_syms, sym_index, h; | 63 | int *ptr, *hash, nb_syms, sym_index, h; |
| 54 | char *strtab; | 64 | char *strtab; |
| 55 | | 65 | |
| 56 | strtab = s->link->data; | 66 | strtab = s->link->data; |
| 57 | nb_syms = s->data_offset / sizeof(Elf32_Sym); | 67 | nb_syms = s->data_offset / sizeof(ElfW(Sym)); |
| 58 | | 68 | |
| 59 | s->hash->data_offset = 0; | 69 | s->hash->data_offset = 0; |
| 60 | ptr = section_ptr_add(s->hash, (2 + nb_buckets + nb_syms) * sizeof(int)); | 70 | ptr = section_ptr_add(s->hash, (2 + nb_buckets + nb_syms) * sizeof(int)); |
| @@ -65,9 +75,9 @@ static void rebuild_hash(Section *s, unsigned int nb_buckets) · 4 unmodified lines |
| 65 | memset(hash, 0, (nb_buckets + 1) * sizeof(int)); | 75 | memset(hash, 0, (nb_buckets + 1) * sizeof(int)); |
| 66 | ptr += nb_buckets + 1; | 76 | ptr += nb_buckets + 1; |
| 67 | | 77 | |
| 68 | sym = (Elf32_Sym *)s->data + 1; | 78 | sym = (ElfW(Sym) *)s->data + 1; |
| 69 | for(sym_index = 1; sym_index < nb_syms; sym_index++) { | 79 | for(sym_index = 1; sym_index < nb_syms; sym_index++) { |
| 70 | if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL) { | 80 | if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { |
| 71 | h = elf_hash(strtab + sym->st_name) % nb_buckets; | 81 | h = elf_hash(strtab + sym->st_name) % nb_buckets; |
| 72 | *ptr = hash[h]; | 82 | *ptr = hash[h]; |
| 73 | hash[h] = sym_index; | 83 | hash[h] = sym_index; |
| @@ -86,10 +96,10 @@ static int put_elf_sym(Section *s, · 12 unmodified lines |
| 86 | { | 96 | { |
| 87 | int name_offset, sym_index; | 97 | int name_offset, sym_index; |
| 88 | int nbuckets, h; | 98 | int nbuckets, h; |
| 89 | Elf32_Sym *sym; | 99 | ElfW(Sym) *sym; |
| 90 | Section *hs; | 100 | Section *hs; |
| 91 | | 101 | |
| 92 | sym = section_ptr_add(s, sizeof(Elf32_Sym)); | 102 | sym = section_ptr_add(s, sizeof(ElfW(Sym))); |
| 93 | if (name) | 103 | if (name) |
| 94 | name_offset = put_elf_str(s->link, name); | 104 | name_offset = put_elf_str(s->link, name); |
| 95 | else | 105 | else |
| @@ -101,14 +111,14 @@ static int put_elf_sym(Section *s, · 5 unmodified lines |
| 101 | sym->st_info = info; | 111 | sym->st_info = info; |
| 102 | sym->st_other = other; | 112 | sym->st_other = other; |
| 103 | sym->st_shndx = shndx; | 113 | sym->st_shndx = shndx; |
| 104 | sym_index = sym - (Elf32_Sym *)s->data; | 114 | sym_index = sym - (ElfW(Sym) *)s->data; |
| 105 | hs = s->hash; | 115 | hs = s->hash; |
| 106 | if (hs) { | 116 | if (hs) { |
| 107 | int *ptr, *base; | 117 | int *ptr, *base; |
| 108 | ptr = section_ptr_add(hs, sizeof(int)); | 118 | ptr = section_ptr_add(hs, sizeof(int)); |
| 109 | base = (int *)hs->data; | 119 | base = (int *)hs->data; |
| 110 | /* only add global or weak symbols */ | 120 | /* only add global or weak symbols */ |
| 111 | if (ELF32_ST_BIND(info) != STB_LOCAL) { | 121 | if (ELFW(ST_BIND)(info) != STB_LOCAL) { |
| 112 | /* add another hashing entry */ | 122 | /* add another hashing entry */ |
| 113 | nbuckets = base[0]; | 123 | nbuckets = base[0]; |
| 114 | h = elf_hash(name) % nbuckets; | 124 | h = elf_hash(name) % nbuckets; |
| @@ -132,7 +142,7 @@ static int put_elf_sym(Section *s, · 17 unmodified lines |
| 132 | found. */ | 142 | found. */ |
| 133 | static int find_elf_sym(Section *s, const char *name) | 143 | static int find_elf_sym(Section *s, const char *name) |
| 134 | { | 144 | { |
| 135 | Elf32_Sym *sym; | 145 | ElfW(Sym) *sym; |
| 136 | Section *hs; | 146 | Section *hs; |
| 137 | int nbuckets, sym_index, h; | 147 | int nbuckets, sym_index, h; |
| 138 | const char *name1; | 148 | const char *name1; |
| @@ -144,7 +154,7 @@ static int find_elf_sym(Section *s, const char *name) · 5 unmodified lines |
| 144 | h = elf_hash(name) % nbuckets; | 154 | h = elf_hash(name) % nbuckets; |
| 145 | sym_index = ((int *)hs->data)[2 + h]; | 155 | sym_index = ((int *)hs->data)[2 + h]; |
| 146 | while (sym_index != 0) { | 156 | while (sym_index != 0) { |
| 147 | sym = &((Elf32_Sym *)s->data)[sym_index]; | 157 | sym = &((ElfW(Sym) *)s->data)[sym_index]; |
| 148 | name1 = s->link->data + sym->st_name; | 158 | name1 = s->link->data + sym->st_name; |
| 149 | if (!strcmp(name, name1)) | 159 | if (!strcmp(name, name1)) |
| 150 | return sym_index; | 160 | return sym_index; |
| @@ -157,12 +167,12 @@ static int find_elf_sym(Section *s, const char *name) · 6 unmodified lines |
| 157 | int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name) | 167 | int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name) |
| 158 | { | 168 | { |
| 159 | int sym_index; | 169 | int sym_index; |
| 160 | Elf32_Sym *sym; | 170 | ElfW(Sym) *sym; |
| 161 | | 171 | |
| 162 | sym_index = find_elf_sym(symtab_section, name); | 172 | sym_index = find_elf_sym(symtab_section, name); |
| 163 | if (!sym_index) | 173 | if (!sym_index) |
| 164 | return -1; | 174 | return -1; |
| 165 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 175 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 166 | *pval = sym->st_value; | 176 | *pval = sym->st_value; |
| 167 | return 0; | 177 | return 0; |
| 168 | } | 178 | } |
| @@ -180,25 +190,25 @@ void *tcc_get_symbol_err(TCCState *s, const char *name) · 11 unmodified lines |
| 180 | static int add_elf_sym(Section *s, unsigned long value, unsigned long size, | 190 | static int add_elf_sym(Section *s, unsigned long value, unsigned long size, |
| 181 | int info, int other, int sh_num, const char *name) | 191 | int info, int other, int sh_num, const char *name) |
| 182 | { | 192 | { |
| 183 | Elf32_Sym *esym; | 193 | ElfW(Sym) *esym; |
| 184 | int sym_bind, sym_index, sym_type, esym_bind; | 194 | int sym_bind, sym_index, sym_type, esym_bind; |
| 185 | unsigned char sym_vis, esym_vis, new_vis; | 195 | unsigned char sym_vis, esym_vis, new_vis; |
| 186 | | 196 | |
| 187 | sym_bind = ELF32_ST_BIND(info); | 197 | sym_bind = ELFW(ST_BIND)(info); |
| 188 | sym_type = ELF32_ST_TYPE(info); | 198 | sym_type = ELFW(ST_TYPE)(info); |
| 189 | sym_vis = ELF32_ST_VISIBILITY(other); | 199 | sym_vis = ELFW(ST_VISIBILITY)(other); |
| 190 | | 200 | |
| 191 | if (sym_bind != STB_LOCAL) { | 201 | if (sym_bind != STB_LOCAL) { |
| 192 | /* we search global or weak symbols */ | 202 | /* we search global or weak symbols */ |
| 193 | sym_index = find_elf_sym(s, name); | 203 | sym_index = find_elf_sym(s, name); |
| 194 | if (!sym_index) | 204 | if (!sym_index) |
| 195 | goto do_def; | 205 | goto do_def; |
| 196 | esym = &((Elf32_Sym *)s->data)[sym_index]; | 206 | esym = &((ElfW(Sym) *)s->data)[sym_index]; |
| 197 | if (esym->st_shndx != SHN_UNDEF) { | 207 | if (esym->st_shndx != SHN_UNDEF) { |
| 198 | esym_bind = ELF32_ST_BIND(esym->st_info); | 208 | esym_bind = ELFW(ST_BIND)(esym->st_info); |
| 199 | /* propagate the most constraining visibility */ | 209 | /* propagate the most constraining visibility */ |
| 200 | /* STV_DEFAULT(0)<STV_PROTECTED(3)<STV_HIDDEN(2)<STV_INTERNAL(1) */ | 210 | /* STV_DEFAULT(0)<STV_PROTECTED(3)<STV_HIDDEN(2)<STV_INTERNAL(1) */ |
| 201 | esym_vis = ELF32_ST_VISIBILITY(esym->st_other); | 211 | esym_vis = ELFW(ST_VISIBILITY)(esym->st_other); |
| 202 | if (esym_vis == STV_DEFAULT) { | 212 | if (esym_vis == STV_DEFAULT) { |
| 203 | new_vis = sym_vis; | 213 | new_vis = sym_vis; |
| 204 | } else if (sym_vis == STV_DEFAULT) { | 214 | } else if (sym_vis == STV_DEFAULT) { |
| @@ -206,7 +216,7 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 1 unmodified line |
| 206 | } else { | 216 | } else { |
| 207 | new_vis = (esym_vis < sym_vis) ? esym_vis : sym_vis; | 217 | new_vis = (esym_vis < sym_vis) ? esym_vis : sym_vis; |
| 208 | } | 218 | } |
| 209 | esym->st_other = (esym->st_other & ~ELF32_ST_VISIBILITY(-1)) | 219 | esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1)) |
| 210 | | new_vis; | 220 | | new_vis; |
| 211 | other = esym->st_other; /* in case we have to patch esym */ | 221 | other = esym->st_other; /* in case we have to patch esym */ |
| 212 | if (sh_num == SHN_UNDEF) { | 222 | if (sh_num == SHN_UNDEF) { |
| @@ -234,7 +244,7 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 21 unmodified lines |
| 234 | } | 244 | } |
| 235 | } else { | 245 | } else { |
| 236 | do_patch: | 246 | do_patch: |
| 237 | esym->st_info = ELF32_ST_INFO(sym_bind, sym_type); | 247 | esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type); |
| 238 | esym->st_shndx = sh_num; | 248 | esym->st_shndx = sh_num; |
| 239 | esym->st_value = value; | 249 | esym->st_value = value; |
| 240 | esym->st_size = size; | 250 | esym->st_size = size; |
| @@ -243,7 +253,7 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 2 unmodified lines |
| 243 | } else { | 253 | } else { |
| 244 | do_def: | 254 | do_def: |
| 245 | sym_index = put_elf_sym(s, value, size, | 255 | sym_index = put_elf_sym(s, value, size, |
| 246 | ELF32_ST_INFO(sym_bind, sym_type), other, | 256 | ELFW(ST_INFO)(sym_bind, sym_type), other, |
| 247 | sh_num, name); | 257 | sh_num, name); |
| 248 | } | 258 | } |
| 249 | return sym_index; | 259 | return sym_index; |
| @@ -255,7 +265,7 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 5 unmodified lines |
| 255 | { | 265 | { |
| 256 | char buf[256]; | 266 | char buf[256]; |
| 257 | Section *sr; | 267 | Section *sr; |
| 258 | Elf32_Rel *rel; | 268 | ElfW_Rel *rel; |
| 259 | | 269 | |
| 260 | sr = s->reloc; | 270 | sr = s->reloc; |
| 261 | if (!sr) { | 271 | if (!sr) { |
| @@ -263,15 +273,15 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 1 unmodified line |
| 263 | snprintf(buf, sizeof(buf), ".rel%s", s->name); | 273 | snprintf(buf, sizeof(buf), ".rel%s", s->name); |
| 264 | /* if the symtab is allocated, then we consider the relocation | 274 | /* if the symtab is allocated, then we consider the relocation |
| 265 | are also */ | 275 | are also */ |
| 266 | sr = new_section(tcc_state, buf, SHT_REL, symtab->sh_flags); | 276 | sr = new_section(tcc_state, buf, SHT_RELX, symtab->sh_flags); |
| 267 | sr->sh_entsize = sizeof(Elf32_Rel); | 277 | sr->sh_entsize = sizeof(ElfW_Rel); |
| 268 | sr->link = symtab; | 278 | sr->link = symtab; |
| 269 | sr->sh_info = s->sh_num; | 279 | sr->sh_info = s->sh_num; |
| 270 | s->reloc = sr; | 280 | s->reloc = sr; |
| 271 | } | 281 | } |
| 272 | rel = section_ptr_add(sr, sizeof(Elf32_Rel)); | 282 | rel = section_ptr_add(sr, sizeof(ElfW_Rel)); |
| 273 | rel->r_offset = offset; | 283 | rel->r_offset = offset; |
| 274 | rel->r_info = ELF32_R_INFO(symbol, type); | 284 | rel->r_info = ELFW(R_INFO)(symbol, type); |
| 275 | } | 285 | } |
| 276 | | 286 | |
| 277 | /* put stab debug information */ | 287 | /* put stab debug information */ |
| @@ -327,22 +337,22 @@ static void put_stabd(int type, int other, int desc) · 49 unmodified lines |
| 327 | static void sort_syms(TCCState *s1, Section *s) | 337 | static void sort_syms(TCCState *s1, Section *s) |
| 328 | { | 338 | { |
| 329 | int *old_to_new_syms; | 339 | int *old_to_new_syms; |
| 330 | Elf32_Sym *new_syms; | 340 | ElfW(Sym) *new_syms; |
| 331 | int nb_syms, i; | 341 | int nb_syms, i; |
| 332 | Elf32_Sym *p, *q; | 342 | ElfW(Sym) *p, *q; |
| 333 | Elf32_Rel *rel, *rel_end; | 343 | ElfW_Rel *rel, *rel_end; |
| 334 | Section *sr; | 344 | Section *sr; |
| 335 | int type, sym_index; | 345 | int type, sym_index; |
| 336 | | 346 | |
| 337 | nb_syms = s->data_offset / sizeof(Elf32_Sym); | 347 | nb_syms = s->data_offset / sizeof(ElfW(Sym)); |
| 338 | new_syms = tcc_malloc(nb_syms * sizeof(Elf32_Sym)); | 348 | new_syms = tcc_malloc(nb_syms * sizeof(ElfW(Sym))); |
| 339 | old_to_new_syms = tcc_malloc(nb_syms * sizeof(int)); | 349 | old_to_new_syms = tcc_malloc(nb_syms * sizeof(int)); |
| 340 | | 350 | |
| 341 | /* first pass for local symbols */ | 351 | /* first pass for local symbols */ |
| 342 | p = (Elf32_Sym *)s->data; | 352 | p = (ElfW(Sym) *)s->data; |
| 343 | q = new_syms; | 353 | q = new_syms; |
| 344 | for(i = 0; i < nb_syms; i++) { | 354 | for(i = 0; i < nb_syms; i++) { |
| 345 | if (ELF32_ST_BIND(p->st_info) == STB_LOCAL) { | 355 | if (ELFW(ST_BIND)(p->st_info) == STB_LOCAL) { |
| 346 | old_to_new_syms[i] = q - new_syms; | 356 | old_to_new_syms[i] = q - new_syms; |
| 347 | *q++ = *p; | 357 | *q++ = *p; |
| 348 | } | 358 | } |
| @@ -352,9 +362,9 @@ static void sort_syms(TCCState *s1, Section *s) · 3 unmodified lines |
| 352 | s->sh_info = q - new_syms; | 362 | s->sh_info = q - new_syms; |
| 353 | | 363 | |
| 354 | /* then second pass for non local symbols */ | 364 | /* then second pass for non local symbols */ |
| 355 | p = (Elf32_Sym *)s->data; | 365 | p = (ElfW(Sym) *)s->data; |
| 356 | for(i = 0; i < nb_syms; i++) { | 366 | for(i = 0; i < nb_syms; i++) { |
| 357 | if (ELF32_ST_BIND(p->st_info) != STB_LOCAL) { | 367 | if (ELFW(ST_BIND)(p->st_info) != STB_LOCAL) { |
| 358 | old_to_new_syms[i] = q - new_syms; | 368 | old_to_new_syms[i] = q - new_syms; |
| 359 | *q++ = *p; | 369 | *q++ = *p; |
| 360 | } | 370 | } |
| @@ -362,21 +372,21 @@ static void sort_syms(TCCState *s1, Section *s) · 1 unmodified line |
| 362 | } | 372 | } |
| 363 | | 373 | |
| 364 | /* we copy the new symbols to the old */ | 374 | /* we copy the new symbols to the old */ |
| 365 | memcpy(s->data, new_syms, nb_syms * sizeof(Elf32_Sym)); | 375 | memcpy(s->data, new_syms, nb_syms * sizeof(ElfW(Sym))); |
| 366 | tcc_free(new_syms); | 376 | tcc_free(new_syms); |
| 367 | | 377 | |
| 368 | /* now we modify all the relocations */ | 378 | /* now we modify all the relocations */ |
| 369 | for(i = 1; i < s1->nb_sections; i++) { | 379 | for(i = 1; i < s1->nb_sections; i++) { |
| 370 | sr = s1->sections[i]; | 380 | sr = s1->sections[i]; |
| 371 | if (sr->sh_type == SHT_REL && sr->link == s) { | 381 | if (sr->sh_type == SHT_RELX && sr->link == s) { |
| 372 | rel_end = (Elf32_Rel *)(sr->data + sr->data_offset); | 382 | rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); |
| 373 | for(rel = (Elf32_Rel *)sr->data; | 383 | for(rel = (ElfW_Rel *)sr->data; |
| 374 | rel < rel_end; | 384 | rel < rel_end; |
| 375 | rel++) { | 385 | rel++) { |
| 376 | sym_index = ELF32_R_SYM(rel->r_info); | 386 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 377 | type = ELF32_R_TYPE(rel->r_info); | 387 | type = ELFW(R_TYPE)(rel->r_info); |
| 378 | sym_index = old_to_new_syms[sym_index]; | 388 | sym_index = old_to_new_syms[sym_index]; |
| 379 | rel->r_info = ELF32_R_INFO(sym_index, type); | 389 | rel->r_info = ELFW(R_INFO)(sym_index, type); |
| 380 | } | 390 | } |
| 381 | } | 391 | } |
| 382 | } | 392 | } |
| @@ -387,11 +397,11 @@ static void sort_syms(TCCState *s1, Section *s) · 4 unmodified lines |
| 387 | /* relocate common symbols in the .bss section */ | 397 | /* relocate common symbols in the .bss section */ |
| 388 | static void relocate_common_syms(void) | 398 | static void relocate_common_syms(void) |
| 389 | { | 399 | { |
| 390 | Elf32_Sym *sym, *sym_end; | 400 | ElfW(Sym) *sym, *sym_end; |
| 391 | unsigned long offset, align; | 401 | unsigned long offset, align; |
| 392 | | 402 | |
| 393 | sym_end = (Elf32_Sym *)(symtab_section->data + symtab_section->data_offset); | 403 | sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset); |
| 394 | for(sym = (Elf32_Sym *)symtab_section->data + 1; | 404 | for(sym = (ElfW(Sym) *)symtab_section->data + 1; |
| 395 | sym < sym_end; | 405 | sym < sym_end; |
| 396 | sym++) { | 406 | sym++) { |
| 397 | if (sym->st_shndx == SHN_COMMON) { | 407 | if (sym->st_shndx == SHN_COMMON) { |
| @@ -411,13 +421,13 @@ static void relocate_common_syms(void) · 13 unmodified lines |
| 411 | true and output error if undefined symbol. */ | 421 | true and output error if undefined symbol. */ |
| 412 | static void relocate_syms(TCCState *s1, int do_resolve) | 422 | static void relocate_syms(TCCState *s1, int do_resolve) |
| 413 | { | 423 | { |
| 414 | Elf32_Sym *sym, *esym, *sym_end; | 424 | ElfW(Sym) *sym, *esym, *sym_end; |
| 415 | int sym_bind, sh_num, sym_index; | 425 | int sym_bind, sh_num, sym_index; |
| 416 | const char *name; | 426 | const char *name; |
| 417 | unsigned long addr; | 427 | unsigned long addr; |
| 418 | | 428 | |
| 419 | sym_end = (Elf32_Sym *)(symtab_section->data + symtab_section->data_offset); | 429 | sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset); |
| 420 | for(sym = (Elf32_Sym *)symtab_section->data + 1; | 430 | for(sym = (ElfW(Sym) *)symtab_section->data + 1; |
| 421 | sym < sym_end; | 431 | sym < sym_end; |
| 422 | sym++) { | 432 | sym++) { |
| 423 | sh_num = sym->st_shndx; | 433 | sh_num = sym->st_shndx; |
| @@ -425,7 +435,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 1 unmodified line |
| 425 | name = strtab_section->data + sym->st_name; | 435 | name = strtab_section->data + sym->st_name; |
| 426 | if (do_resolve) { | 436 | if (do_resolve) { |
| 427 | name = symtab_section->link->data + sym->st_name; | 437 | name = symtab_section->link->data + sym->st_name; |
| 428 | addr = (unsigned long)resolve_sym(s1, name, ELF32_ST_TYPE(sym->st_info)); | 438 | addr = (unsigned long)resolve_sym(s1, name, ELFW(ST_TYPE)(sym->st_info)); |
| 429 | if (addr) { | 439 | if (addr) { |
| 430 | sym->st_value = addr; | 440 | sym->st_value = addr; |
| 431 | goto found; | 441 | goto found; |
| @@ -434,7 +444,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 2 unmodified lines |
| 434 | /* if dynamic symbol exist, then use it */ | 444 | /* if dynamic symbol exist, then use it */ |
| 435 | sym_index = find_elf_sym(s1->dynsym, name); | 445 | sym_index = find_elf_sym(s1->dynsym, name); |
| 436 | if (sym_index) { | 446 | if (sym_index) { |
| 437 | esym = &((Elf32_Sym *)s1->dynsym->data)[sym_index]; | 447 | esym = &((ElfW(Sym) *)s1->dynsym->data)[sym_index]; |
| 438 | sym->st_value = esym->st_value; | 448 | sym->st_value = esym->st_value; |
| 439 | goto found; | 449 | goto found; |
| 440 | } | 450 | } |
| @@ -445,7 +455,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 4 unmodified lines |
| 445 | goto found; | 455 | goto found; |
| 446 | /* only weak symbols are accepted to be undefined. Their | 456 | /* only weak symbols are accepted to be undefined. Their |
| 447 | value is zero */ | 457 | value is zero */ |
| 448 | sym_bind = ELF32_ST_BIND(sym->st_info); | 458 | sym_bind = ELFW(ST_BIND)(sym->st_info); |
| 449 | if (sym_bind == STB_WEAK) { | 459 | if (sym_bind == STB_WEAK) { |
| 450 | sym->st_value = 0; | 460 | sym->st_value = 0; |
| 451 | } else { | 461 | } else { |
| @@ -463,8 +473,8 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 11 unmodified lines |
| 463 | static void relocate_section(TCCState *s1, Section *s) | 473 | static void relocate_section(TCCState *s1, Section *s) |
| 464 | { | 474 | { |
| 465 | Section *sr; | 475 | Section *sr; |
| 466 | Elf32_Rel *rel, *rel_end, *qrel; | 476 | ElfW_Rel *rel, *rel_end, *qrel; |
| 467 | Elf32_Sym *sym; | 477 | ElfW(Sym) *sym; |
| 468 | int type, sym_index; | 478 | int type, sym_index; |
| 469 | unsigned char *ptr; | 479 | unsigned char *ptr; |
| 470 | unsigned long val, addr; | 480 | unsigned long val, addr; |
| @@ -473,17 +483,17 @@ static void relocate_section(TCCState *s1, Section *s) · 2 unmodified lines |
| 473 | #endif | 483 | #endif |
| 474 | | 484 | |
| 475 | sr = s->reloc; | 485 | sr = s->reloc; |
| 476 | rel_end = (Elf32_Rel *)(sr->data + sr->data_offset); | 486 | rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); |
| 477 | qrel = (Elf32_Rel *)sr->data; | 487 | qrel = (ElfW_Rel *)sr->data; |
| 478 | for(rel = qrel; | 488 | for(rel = qrel; |
| 479 | rel < rel_end; | 489 | rel < rel_end; |
| 480 | rel++) { | 490 | rel++) { |
| 481 | ptr = s->data + rel->r_offset; | 491 | ptr = s->data + rel->r_offset; |
| 482 | | 492 | |
| 483 | sym_index = ELF32_R_SYM(rel->r_info); | 493 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 484 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 494 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 485 | val = sym->st_value; | 495 | val = sym->st_value; |
| 486 | type = ELF32_R_TYPE(rel->r_info); | 496 | type = ELFW(R_TYPE)(rel->r_info); |
| 487 | addr = s->sh_addr + rel->r_offset; | 497 | addr = s->sh_addr + rel->r_offset; |
| 488 | | 498 | |
| 489 | /* CPU specific */ | 499 | /* CPU specific */ |
| @@ -494,11 +504,11 @@ static void relocate_section(TCCState *s1, Section *s) · 4 unmodified lines |
| 494 | esym_index = s1->symtab_to_dynsym[sym_index]; | 504 | esym_index = s1->symtab_to_dynsym[sym_index]; |
| 495 | qrel->r_offset = rel->r_offset; | 505 | qrel->r_offset = rel->r_offset; |
| 496 | if (esym_index) { | 506 | if (esym_index) { |
| 497 | qrel->r_info = ELF32_R_INFO(esym_index, R_386_32); | 507 | qrel->r_info = ELFW(R_INFO)(esym_index, R_386_32); |
| 498 | qrel++; | 508 | qrel++; |
| 499 | break; | 509 | break; |
| 500 | } else { | 510 | } else { |
| 501 | qrel->r_info = ELF32_R_INFO(0, R_386_RELATIVE); | 511 | qrel->r_info = ELFW(R_INFO)(0, R_386_RELATIVE); |
| 502 | qrel++; | 512 | qrel++; |
| 503 | } | 513 | } |
| 504 | } | 514 | } |
| @@ -510,7 +520,7 @@ static void relocate_section(TCCState *s1, Section *s) · 5 unmodified lines |
| 510 | esym_index = s1->symtab_to_dynsym[sym_index]; | 520 | esym_index = s1->symtab_to_dynsym[sym_index]; |
| 511 | if (esym_index) { | 521 | if (esym_index) { |
| 512 | qrel->r_offset = rel->r_offset; | 522 | qrel->r_offset = rel->r_offset; |
| 513 | qrel->r_info = ELF32_R_INFO(esym_index, R_386_PC32); | 523 | qrel->r_info = ELFW(R_INFO)(esym_index, R_386_PC32); |
| 514 | qrel++; | 524 | qrel++; |
| 515 | break; | 525 | break; |
| 516 | } | 526 | } |
| @@ -624,11 +634,11 @@ static void relocate_section(TCCState *s1, Section *s) · 107 unmodified lines |
| 624 | static void relocate_rel(TCCState *s1, Section *sr) | 634 | static void relocate_rel(TCCState *s1, Section *sr) |
| 625 | { | 635 | { |
| 626 | Section *s; | 636 | Section *s; |
| 627 | Elf32_Rel *rel, *rel_end; | 637 | ElfW_Rel *rel, *rel_end; |
| 628 | | 638 | |
| 629 | s = s1->sections[sr->sh_info]; | 639 | s = s1->sections[sr->sh_info]; |
| 630 | rel_end = (Elf32_Rel *)(sr->data + sr->data_offset); | 640 | rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); |
| 631 | for(rel = (Elf32_Rel *)sr->data; | 641 | for(rel = (ElfW_Rel *)sr->data; |
| 632 | rel < rel_end; | 642 | rel < rel_end; |
| 633 | rel++) { | 643 | rel++) { |
| 634 | rel->r_offset += s->sh_addr; | 644 | rel->r_offset += s->sh_addr; |
| @@ -639,14 +649,14 @@ static void relocate_rel(TCCState *s1, Section *sr) · 4 unmodified lines |
| 639 | their space */ | 649 | their space */ |
| 640 | static int prepare_dynamic_rel(TCCState *s1, Section *sr) | 650 | static int prepare_dynamic_rel(TCCState *s1, Section *sr) |
| 641 | { | 651 | { |
| 642 | Elf32_Rel *rel, *rel_end; | 652 | ElfW_Rel *rel, *rel_end; |
| 643 | int sym_index, esym_index, type, count; | 653 | int sym_index, esym_index, type, count; |
| 644 | | 654 | |
| 645 | count = 0; | 655 | count = 0; |
| 646 | rel_end = (Elf32_Rel *)(sr->data + sr->data_offset); | 656 | rel_end = (ElfW_Rel *)(sr->data + sr->data_offset); |
| 647 | for(rel = (Elf32_Rel *)sr->data; rel < rel_end; rel++) { | 657 | for(rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) { |
| 648 | sym_index = ELF32_R_SYM(rel->r_info); | 658 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 649 | type = ELF32_R_TYPE(rel->r_info); | 659 | type = ELFW(R_TYPE)(rel->r_info); |
| 650 | switch(type) { | 660 | switch(type) { |
| 651 | case R_386_32: | 661 | case R_386_32: |
| 652 | count++; | 662 | count++; |
| @@ -663,7 +673,7 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 10 unmodified lines |
| 663 | if (count) { | 673 | if (count) { |
| 664 | /* allocate the section */ | 674 | /* allocate the section */ |
| 665 | sr->sh_flags |= SHF_ALLOC; | 675 | sr->sh_flags |= SHF_ALLOC; |
| 666 | sr->sh_size = count * sizeof(Elf32_Rel); | 676 | sr->sh_size = count * sizeof(ElfW_Rel); |
| 667 | } | 677 | } |
| 668 | return count; | 678 | return count; |
| 669 | } | 679 | } |
| @@ -712,7 +722,7 @@ static void build_got(TCCState *s1) · 42 unmodified lines |
| 712 | /* if no got, then create it */ | 722 | /* if no got, then create it */ |
| 713 | s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); | 723 | s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE); |
| 714 | s1->got->sh_entsize = 4; | 724 | s1->got->sh_entsize = 4; |
| 715 | add_elf_sym(symtab_section, 0, 4, ELF32_ST_INFO(STB_GLOBAL, STT_OBJECT), | 725 | add_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), |
| 716 | 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); | 726 | 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_"); |
| 717 | ptr = section_ptr_add(s1->got, 3 * sizeof(int)); | 727 | ptr = section_ptr_add(s1->got, 3 * sizeof(int)); |
| 718 | /* keep space for _DYNAMIC pointer, if present */ | 728 | /* keep space for _DYNAMIC pointer, if present */ |
| @@ -730,7 +740,7 @@ static void put_got_entry(TCCState *s1, · 11 unmodified lines |
| 730 | { | 740 | { |
| 731 | int index; | 741 | int index; |
| 732 | const char *name; | 742 | const char *name; |
| 733 | Elf32_Sym *sym; | 743 | ElfW(Sym) *sym; |
| 734 | unsigned long offset; | 744 | unsigned long offset; |
| 735 | int *ptr; | 745 | int *ptr; |
| 736 | | 746 | |
| @@ -745,7 +755,7 @@ static void put_got_entry(TCCState *s1, · 8 unmodified lines |
| 745 | put_got_offset(s1, sym_index, s1->got->data_offset); | 755 | put_got_offset(s1, sym_index, s1->got->data_offset); |
| 746 | | 756 | |
| 747 | if (s1->dynsym) { | 757 | if (s1->dynsym) { |
| 748 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 758 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 749 | name = symtab_section->link->data + sym->st_name; | 759 | name = symtab_section->link->data + sym->st_name; |
| 750 | offset = sym->st_value; | 760 | offset = sym->st_value; |
| 751 | #ifdef TCC_TARGET_I386 | 761 | #ifdef TCC_TARGET_I386 |
| @@ -838,23 +848,23 @@ static void put_got_entry(TCCState *s1, · 86 unmodified lines |
| 838 | static void build_got_entries(TCCState *s1) | 848 | static void build_got_entries(TCCState *s1) |
| 839 | { | 849 | { |
| 840 | Section *s, *symtab; | 850 | Section *s, *symtab; |
| 841 | Elf32_Rel *rel, *rel_end; | 851 | ElfW_Rel *rel, *rel_end; |
| 842 | Elf32_Sym *sym; | 852 | ElfW(Sym) *sym; |
| 843 | int i, type, reloc_type, sym_index; | 853 | int i, type, reloc_type, sym_index; |
| 844 | | 854 | |
| 845 | for(i = 1; i < s1->nb_sections; i++) { | 855 | for(i = 1; i < s1->nb_sections; i++) { |
| 846 | s = s1->sections[i]; | 856 | s = s1->sections[i]; |
| 847 | if (s->sh_type != SHT_REL) | 857 | if (s->sh_type != SHT_RELX) |
| 848 | continue; | 858 | continue; |
| 849 | /* no need to handle got relocations */ | 859 | /* no need to handle got relocations */ |
| 850 | if (s->link != symtab_section) | 860 | if (s->link != symtab_section) |
| 851 | continue; | 861 | continue; |
| 852 | symtab = s->link; | 862 | symtab = s->link; |
| 853 | rel_end = (Elf32_Rel *)(s->data + s->data_offset); | 863 | rel_end = (ElfW_Rel *)(s->data + s->data_offset); |
| 854 | for(rel = (Elf32_Rel *)s->data; | 864 | for(rel = (ElfW_Rel *)s->data; |
| 855 | rel < rel_end; | 865 | rel < rel_end; |
| 856 | rel++) { | 866 | rel++) { |
| 857 | type = ELF32_R_TYPE(rel->r_info); | 867 | type = ELFW(R_TYPE)(rel->r_info); |
| 858 | switch(type) { | 868 | switch(type) { |
| 859 | #if defined(TCC_TARGET_I386) | 869 | #if defined(TCC_TARGET_I386) |
| 860 | case R_386_GOT32: | 870 | case R_386_GOT32: |
| @@ -864,8 +874,8 @@ static void build_got_entries(TCCState *s1) · 3 unmodified lines |
| 864 | if (!s1->got) | 874 | if (!s1->got) |
| 865 | build_got(s1); | 875 | build_got(s1); |
| 866 | if (type == R_386_GOT32 || type == R_386_PLT32) { | 876 | if (type == R_386_GOT32 || type == R_386_PLT32) { |
| 867 | sym_index = ELF32_R_SYM(rel->r_info); | 877 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 868 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 878 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 869 | /* look at the symbol got offset. If none, then add one */ | 879 | /* look at the symbol got offset. If none, then add one */ |
| 870 | if (type == R_386_GOT32) | 880 | if (type == R_386_GOT32) |
| 871 | reloc_type = R_386_GLOB_DAT; | 881 | reloc_type = R_386_GLOB_DAT; |
| @@ -883,8 +893,8 @@ static void build_got_entries(TCCState *s1) · 11 unmodified lines |
| 883 | if (!s1->got) | 893 | if (!s1->got) |
| 884 | build_got(s1); | 894 | build_got(s1); |
| 885 | if (type == R_ARM_GOT_BREL || type == R_ARM_PLT32) { | 895 | if (type == R_ARM_GOT_BREL || type == R_ARM_PLT32) { |
| 886 | sym_index = ELF32_R_SYM(rel->r_info); | 896 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 887 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 897 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 888 | /* look at the symbol got offset. If none, then add one */ | 898 | /* look at the symbol got offset. If none, then add one */ |
| 889 | if (type == R_ARM_GOT_BREL) | 899 | if (type == R_ARM_GOT_BREL) |
| 890 | reloc_type = R_ARM_GLOB_DAT; | 900 | reloc_type = R_ARM_GLOB_DAT; |
| @@ -902,8 +912,8 @@ static void build_got_entries(TCCState *s1) · 11 unmodified lines |
| 902 | if (!s1->got) | 912 | if (!s1->got) |
| 903 | build_got(s1); | 913 | build_got(s1); |
| 904 | if (type == R_C60_GOT32 || type == R_C60_PLT32) { | 914 | if (type == R_C60_GOT32 || type == R_C60_PLT32) { |
| 905 | sym_index = ELF32_R_SYM(rel->r_info); | 915 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 906 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 916 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 907 | /* look at the symbol got offset. If none, then add one */ | 917 | /* look at the symbol got offset. If none, then add one */ |
| 908 | if (type == R_C60_GOT32) | 918 | if (type == R_C60_GOT32) |
| 909 | reloc_type = R_C60_GLOB_DAT; | 919 | reloc_type = R_C60_GLOB_DAT; |
| @@ -932,7 +942,7 @@ static Section *new_symtab(TCCState *s1, · 22 unmodified lines |
| 932 | int *ptr, nb_buckets; | 942 | int *ptr, nb_buckets; |
| 933 | | 943 | |
| 934 | symtab = new_section(s1, symtab_name, sh_type, sh_flags); | 944 | symtab = new_section(s1, symtab_name, sh_type, sh_flags); |
| 935 | symtab->sh_entsize = sizeof(Elf32_Sym); | 945 | symtab->sh_entsize = sizeof(ElfW(Sym)); |
| 936 | strtab = new_section(s1, strtab_name, SHT_STRTAB, sh_flags); | 946 | strtab = new_section(s1, strtab_name, SHT_STRTAB, sh_flags); |
| 937 | put_elf_str(strtab, ""); | 947 | put_elf_str(strtab, ""); |
| 938 | symtab->link = strtab; | 948 | symtab->link = strtab; |
| @@ -955,8 +965,8 @@ static Section *new_symtab(TCCState *s1, · 16 unmodified lines |
| 955 | /* put dynamic tag */ | 965 | /* put dynamic tag */ |
| 956 | static void put_dt(Section *dynamic, int dt, unsigned long val) | 966 | static void put_dt(Section *dynamic, int dt, unsigned long val) |
| 957 | { | 967 | { |
| 958 | Elf32_Dyn *dyn; | 968 | ElfW(Dyn) *dyn; |
| 959 | dyn = section_ptr_add(dynamic, sizeof(Elf32_Dyn)); | 969 | dyn = section_ptr_add(dynamic, sizeof(ElfW(Dyn))); |
| 960 | dyn->d_tag = dt; | 970 | dyn->d_tag = dt; |
| 961 | dyn->d_un.d_val = val; | 971 | dyn->d_un.d_val = val; |
| 962 | } | 972 | } |
| @@ -981,11 +991,11 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 18 unmodified lines |
| 981 | | 991 | |
| 982 | add_elf_sym(symtab_section, | 992 | add_elf_sym(symtab_section, |
| 983 | 0, 0, | 993 | 0, 0, |
| 984 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 994 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 985 | s->sh_num, sym_start); | 995 | s->sh_num, sym_start); |
| 986 | add_elf_sym(symtab_section, | 996 | add_elf_sym(symtab_section, |
| 987 | end_offset, 0, | 997 | end_offset, 0, |
| 988 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 998 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 989 | s->sh_num, sym_end); | 999 | s->sh_num, sym_end); |
| 990 | } | 1000 | } |
| 991 | | 1001 | |
| @@ -1007,7 +1017,7 @@ static void tcc_add_runtime(TCCState *s1) · 15 unmodified lines |
| 1007 | ptr = section_ptr_add(bounds_section, sizeof(unsigned long)); | 1017 | ptr = section_ptr_add(bounds_section, sizeof(unsigned long)); |
| 1008 | *ptr = 0; | 1018 | *ptr = 0; |
| 1009 | add_elf_sym(symtab_section, 0, 0, | 1019 | add_elf_sym(symtab_section, 0, 0, |
| 1010 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 1020 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1011 | bounds_section->sh_num, "__bounds_start"); | 1021 | bounds_section->sh_num, "__bounds_start"); |
| 1012 | /* add bound check code */ | 1022 | /* add bound check code */ |
| 1013 | snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "bcheck.o"); | 1023 | snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "bcheck.o"); |
| @@ -1054,15 +1064,15 @@ static void tcc_add_linker_symbols(TCCState *s1) · 40 unmodified lines |
| 1054 | | 1064 | |
| 1055 | add_elf_sym(symtab_section, | 1065 | add_elf_sym(symtab_section, |
| 1056 | text_section->data_offset, 0, | 1066 | text_section->data_offset, 0, |
| 1057 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 1067 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1058 | text_section->sh_num, "_etext"); | 1068 | text_section->sh_num, "_etext"); |
| 1059 | add_elf_sym(symtab_section, | 1069 | add_elf_sym(symtab_section, |
| 1060 | data_section->data_offset, 0, | 1070 | data_section->data_offset, 0, |
| 1061 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 1071 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1062 | data_section->sh_num, "_edata"); | 1072 | data_section->sh_num, "_edata"); |
| 1063 | add_elf_sym(symtab_section, | 1073 | add_elf_sym(symtab_section, |
| 1064 | bss_section->data_offset, 0, | 1074 | bss_section->data_offset, 0, |
| 1065 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 1075 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1066 | bss_section->sh_num, "_end"); | 1076 | bss_section->sh_num, "_end"); |
| 1067 | /* horrible new standard ldscript defines */ | 1077 | /* horrible new standard ldscript defines */ |
| 1068 | add_init_array_defines(s1, ".preinit_array"); | 1078 | add_init_array_defines(s1, ".preinit_array"); |
| @@ -1091,12 +1101,12 @@ static void tcc_add_linker_symbols(TCCState *s1) · 22 unmodified lines |
| 1091 | snprintf(buf, sizeof(buf), "__start_%s", s->name); | 1101 | snprintf(buf, sizeof(buf), "__start_%s", s->name); |
| 1092 | add_elf_sym(symtab_section, | 1102 | add_elf_sym(symtab_section, |
| 1093 | 0, 0, | 1103 | 0, 0, |
| 1094 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 1104 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1095 | s->sh_num, buf); | 1105 | s->sh_num, buf); |
| 1096 | snprintf(buf, sizeof(buf), "__stop_%s", s->name); | 1106 | snprintf(buf, sizeof(buf), "__stop_%s", s->name); |
| 1097 | add_elf_sym(symtab_section, | 1107 | add_elf_sym(symtab_section, |
| 1098 | s->data_offset, 0, | 1108 | s->data_offset, 0, |
| 1099 | ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0, | 1109 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1100 | s->sh_num, buf); | 1110 | s->sh_num, buf); |
| 1101 | } | 1111 | } |
| 1102 | next_sec: ; | 1112 | next_sec: ; |
| @@ -1140,18 +1150,18 @@ static void tcc_output_binary(TCCState *s1, FILE *f, · 37 unmodified lines |
| 1140 | /* XXX: suppress unneeded sections */ | 1150 | /* XXX: suppress unneeded sections */ |
| 1141 | int elf_output_file(TCCState *s1, const char *filename) | 1151 | int elf_output_file(TCCState *s1, const char *filename) |
| 1142 | { | 1152 | { |
| 1143 | Elf32_Ehdr ehdr; | 1153 | ElfW(Ehdr) ehdr; |
| 1144 | FILE *f; | 1154 | FILE *f; |
| 1145 | int fd, mode, ret; | 1155 | int fd, mode, ret; |
| 1146 | int *section_order; | 1156 | int *section_order; |
| 1147 | int shnum, i, phnum, file_offset, offset, size, j, tmp, sh_order_index, k; | 1157 | int shnum, i, phnum, file_offset, offset, size, j, tmp, sh_order_index, k; |
| 1148 | unsigned long addr; | 1158 | unsigned long addr; |
| 1149 | Section *strsec, *s; | 1159 | Section *strsec, *s; |
| 1150 | Elf32_Shdr shdr, *sh; | 1160 | ElfW(Shdr) shdr, *sh; |
| 1151 | Elf32_Phdr *phdr, *ph; | 1161 | ElfW(Phdr) *phdr, *ph; |
| 1152 | Section *interp, *dynamic, *dynstr; | 1162 | Section *interp, *dynamic, *dynstr; |
| 1153 | unsigned long saved_dynamic_data_offset; | 1163 | unsigned long saved_dynamic_data_offset; |
| 1154 | Elf32_Sym *sym; | 1164 | ElfW(Sym) *sym; |
| 1155 | int type, file_type; | 1165 | int type, file_type; |
| 1156 | unsigned long rel_addr, rel_size; | 1166 | unsigned long rel_addr, rel_size; |
| 1157 | | 1167 | |
| @@ -1177,7 +1187,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 19 unmodified lines |
| 1177 | if (!s1->static_link) { | 1187 | if (!s1->static_link) { |
| 1178 | const char *name; | 1188 | const char *name; |
| 1179 | int sym_index, index; | 1189 | int sym_index, index; |
| 1180 | Elf32_Sym *esym, *sym_end; | 1190 | ElfW(Sym) *esym, *sym_end; |
| 1181 | | 1191 | |
| 1182 | if (file_type == TCC_OUTPUT_EXE) { | 1192 | if (file_type == TCC_OUTPUT_EXE) { |
| 1183 | char *ptr; | 1193 | char *ptr; |
| @@ -1198,7 +1208,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 14 unmodified lines |
| 1198 | dynamic = new_section(s1, ".dynamic", SHT_DYNAMIC, | 1208 | dynamic = new_section(s1, ".dynamic", SHT_DYNAMIC, |
| 1199 | SHF_ALLOC | SHF_WRITE); | 1209 | SHF_ALLOC | SHF_WRITE); |
| 1200 | dynamic->link = dynstr; | 1210 | dynamic->link = dynstr; |
| 1201 | dynamic->sh_entsize = sizeof(Elf32_Dyn); | 1211 | dynamic->sh_entsize = sizeof(ElfW(Dyn)); |
| 1202 | | 1212 | |
| 1203 | /* add PLT */ | 1213 | /* add PLT */ |
| 1204 | s1->plt = new_section(s1, ".plt", SHT_PROGBITS, | 1214 | s1->plt = new_section(s1, ".plt", SHT_PROGBITS, |
| @@ -1211,22 +1221,22 @@ int elf_output_file(TCCState *s1, const char *filename) · 6 unmodified lines |
| 1211 | dynamic symbols. If a symbol STT_FUNC is found, then we | 1221 | dynamic symbols. If a symbol STT_FUNC is found, then we |
| 1212 | add it in the PLT. If a symbol STT_OBJECT is found, we | 1222 | add it in the PLT. If a symbol STT_OBJECT is found, we |
| 1213 | add it in the .bss section with a suitable relocation */ | 1223 | add it in the .bss section with a suitable relocation */ |
| 1214 | sym_end = (Elf32_Sym *)(symtab_section->data + | 1224 | sym_end = (ElfW(Sym) *)(symtab_section->data + |
| 1215 | symtab_section->data_offset); | 1225 | symtab_section->data_offset); |
| 1216 | if (file_type == TCC_OUTPUT_EXE) { | 1226 | if (file_type == TCC_OUTPUT_EXE) { |
| 1217 | for(sym = (Elf32_Sym *)symtab_section->data + 1; | 1227 | for(sym = (ElfW(Sym) *)symtab_section->data + 1; |
| 1218 | sym < sym_end; | 1228 | sym < sym_end; |
| 1219 | sym++) { | 1229 | sym++) { |
| 1220 | if (sym->st_shndx == SHN_UNDEF) { | 1230 | if (sym->st_shndx == SHN_UNDEF) { |
| 1221 | name = symtab_section->link->data + sym->st_name; | 1231 | name = symtab_section->link->data + sym->st_name; |
| 1222 | sym_index = find_elf_sym(s1->dynsymtab_section, name); | 1232 | sym_index = find_elf_sym(s1->dynsymtab_section, name); |
| 1223 | if (sym_index) { | 1233 | if (sym_index) { |
| 1224 | esym = &((Elf32_Sym *)s1->dynsymtab_section->data)[sym_index]; | 1234 | esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index]; |
| 1225 | type = ELF32_ST_TYPE(esym->st_info); | 1235 | type = ELFW(ST_TYPE)(esym->st_info); |
| 1226 | if (type == STT_FUNC) { | 1236 | if (type == STT_FUNC) { |
| 1227 | put_got_entry(s1, R_JMP_SLOT, esym->st_size, | 1237 | put_got_entry(s1, R_JMP_SLOT, esym->st_size, |
| 1228 | esym->st_info, | 1238 | esym->st_info, |
| 1229 | sym - (Elf32_Sym *)symtab_section->data); | 1239 | sym - (ElfW(Sym) *)symtab_section->data); |
| 1230 | } else if (type == STT_OBJECT) { | 1240 | } else if (type == STT_OBJECT) { |
| 1231 | unsigned long offset; | 1241 | unsigned long offset; |
| 1232 | offset = bss_section->data_offset; | 1242 | offset = bss_section->data_offset; |
| @@ -1244,14 +1254,14 @@ int elf_output_file(TCCState *s1, const char *filename) · 11 unmodified lines |
| 1244 | /* STB_WEAK undefined symbols are accepted */ | 1254 | /* STB_WEAK undefined symbols are accepted */ |
| 1245 | /* XXX: _fp_hw seems to be part of the ABI, so we ignore | 1255 | /* XXX: _fp_hw seems to be part of the ABI, so we ignore |
| 1246 | it */ | 1256 | it */ |
| 1247 | if (ELF32_ST_BIND(sym->st_info) == STB_WEAK || | 1257 | if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK || |
| 1248 | !strcmp(name, "_fp_hw")) { | 1258 | !strcmp(name, "_fp_hw")) { |
| 1249 | } else { | 1259 | } else { |
| 1250 | error_noabort("undefined symbol '%s'", name); | 1260 | error_noabort("undefined symbol '%s'", name); |
| 1251 | } | 1261 | } |
| 1252 | } | 1262 | } |
| 1253 | } else if (s1->rdynamic && | 1263 | } else if (s1->rdynamic && |
| 1254 | ELF32_ST_BIND(sym->st_info) != STB_LOCAL) { | 1264 | ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { |
| 1255 | /* if -rdynamic option, then export all non | 1265 | /* if -rdynamic option, then export all non |
| 1256 | local symbols */ | 1266 | local symbols */ |
| 1257 | name = symtab_section->link->data + sym->st_name; | 1267 | name = symtab_section->link->data + sym->st_name; |
| @@ -1266,9 +1276,9 @@ int elf_output_file(TCCState *s1, const char *filename) · 8 unmodified lines |
| 1266 | | 1276 | |
| 1267 | /* now look at unresolved dynamic symbols and export | 1277 | /* now look at unresolved dynamic symbols and export |
| 1268 | corresponding symbol */ | 1278 | corresponding symbol */ |
| 1269 | sym_end = (Elf32_Sym *)(s1->dynsymtab_section->data + | 1279 | sym_end = (ElfW(Sym) *)(s1->dynsymtab_section->data + |
| 1270 | s1->dynsymtab_section->data_offset); | 1280 | s1->dynsymtab_section->data_offset); |
| 1271 | for(esym = (Elf32_Sym *)s1->dynsymtab_section->data + 1; | 1281 | for(esym = (ElfW(Sym) *)s1->dynsymtab_section->data + 1; |
| 1272 | esym < sym_end; | 1282 | esym < sym_end; |
| 1273 | esym++) { | 1283 | esym++) { |
| 1274 | if (esym->st_shndx == SHN_UNDEF) { | 1284 | if (esym->st_shndx == SHN_UNDEF) { |
| @@ -1277,12 +1287,12 @@ int elf_output_file(TCCState *s1, const char *filename) · 2 unmodified lines |
| 1277 | if (sym_index) { | 1287 | if (sym_index) { |
| 1278 | /* XXX: avoid adding a symbol if already | 1288 | /* XXX: avoid adding a symbol if already |
| 1279 | present because of -rdynamic ? */ | 1289 | present because of -rdynamic ? */ |
| 1280 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 1290 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 1281 | put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, | 1291 | put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, |
| 1282 | sym->st_info, 0, | 1292 | sym->st_info, 0, |
| 1283 | sym->st_shndx, name); | 1293 | sym->st_shndx, name); |
| 1284 | } else { | 1294 | } else { |
| 1285 | if (ELF32_ST_BIND(esym->st_info) == STB_WEAK) { | 1295 | if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) { |
| 1286 | /* weak symbols can stay undefined */ | 1296 | /* weak symbols can stay undefined */ |
| 1287 | } else { | 1297 | } else { |
| 1288 | warning("undefined dynamic symbol '%s'", name); | 1298 | warning("undefined dynamic symbol '%s'", name); |
| @@ -1293,18 +1303,18 @@ int elf_output_file(TCCState *s1, const char *filename) · 4 unmodified lines |
| 1293 | } else { | 1303 | } else { |
| 1294 | int nb_syms; | 1304 | int nb_syms; |
| 1295 | /* shared library case : we simply export all the global symbols */ | 1305 | /* shared library case : we simply export all the global symbols */ |
| 1296 | nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym); | 1306 | nb_syms = symtab_section->data_offset / sizeof(ElfW(Sym)); |
| 1297 | s1->symtab_to_dynsym = tcc_mallocz(sizeof(int) * nb_syms); | 1307 | s1->symtab_to_dynsym = tcc_mallocz(sizeof(int) * nb_syms); |
| 1298 | for(sym = (Elf32_Sym *)symtab_section->data + 1; | 1308 | for(sym = (ElfW(Sym) *)symtab_section->data + 1; |
| 1299 | sym < sym_end; | 1309 | sym < sym_end; |
| 1300 | sym++) { | 1310 | sym++) { |
| 1301 | if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL) { | 1311 | if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { |
| 1302 | name = symtab_section->link->data + sym->st_name; | 1312 | name = symtab_section->link->data + sym->st_name; |
| 1303 | index = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, | 1313 | index = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, |
| 1304 | sym->st_info, 0, | 1314 | sym->st_info, 0, |
| 1305 | sym->st_shndx, name); | 1315 | sym->st_shndx, name); |
| 1306 | s1->symtab_to_dynsym[sym - | 1316 | s1->symtab_to_dynsym[sym - |
| 1307 | (Elf32_Sym *)symtab_section->data] = | 1317 | (ElfW(Sym) *)symtab_section->data] = |
| 1308 | index; | 1318 | index; |
| 1309 | } | 1319 | } |
| 1310 | } | 1320 | } |
| @@ -1385,7 +1395,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 74 unmodified lines |
| 1385 | /* when generating a DLL, we include relocations but we may | 1395 | /* when generating a DLL, we include relocations but we may |
| 1386 | patch them */ | 1396 | patch them */ |
| 1387 | if (file_type == TCC_OUTPUT_DLL && | 1397 | if (file_type == TCC_OUTPUT_DLL && |
| 1388 | s->sh_type == SHT_REL && | 1398 | s->sh_type == SHT_RELX && |
| 1389 | !(s->sh_flags & SHF_ALLOC)) { | 1399 | !(s->sh_flags & SHF_ALLOC)) { |
| 1390 | /* //gr: avoid bogus relocs for empty (debug) sections */ | 1400 | /* //gr: avoid bogus relocs for empty (debug) sections */ |
| 1391 | if (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC) | 1401 | if (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC) |
| @@ -1402,10 +1412,10 @@ int elf_output_file(TCCState *s1, const char *filename) · 10 unmodified lines |
| 1402 | } | 1412 | } |
| 1403 | | 1413 | |
| 1404 | /* allocate program segment headers */ | 1414 | /* allocate program segment headers */ |
| 1405 | phdr = tcc_mallocz(phnum * sizeof(Elf32_Phdr)); | 1415 | phdr = tcc_mallocz(phnum * sizeof(ElfW(Phdr))); |
| 1406 | | 1416 | |
| 1407 | if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) { | 1417 | if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) { |
| 1408 | file_offset = sizeof(Elf32_Ehdr) + phnum * sizeof(Elf32_Phdr); | 1418 | file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr)); |
| 1409 | } else { | 1419 | } else { |
| 1410 | file_offset = 0; | 1420 | file_offset = 0; |
| 1411 | } | 1421 | } |
| @@ -1471,7 +1481,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 59 unmodified lines |
| 1471 | s->sh_type == SHT_HASH) { | 1481 | s->sh_type == SHT_HASH) { |
| 1472 | if (k != 1) | 1482 | if (k != 1) |
| 1473 | continue; | 1483 | continue; |
| 1474 | } else if (s->sh_type == SHT_REL) { | 1484 | } else if (s->sh_type == SHT_RELX) { |
| 1475 | if (k != 2) | 1485 | if (k != 2) |
| 1476 | continue; | 1486 | continue; |
| 1477 | } else if (s->sh_type == SHT_NOBITS) { | 1487 | } else if (s->sh_type == SHT_NOBITS) { |
| @@ -1498,7 +1508,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 20 unmodified lines |
| 1498 | ph->p_paddr = ph->p_vaddr; | 1508 | ph->p_paddr = ph->p_vaddr; |
| 1499 | } | 1509 | } |
| 1500 | /* update dynamic relocation infos */ | 1510 | /* update dynamic relocation infos */ |
| 1501 | if (s->sh_type == SHT_REL) { | 1511 | if (s->sh_type == SHT_RELX) { |
| 1502 | if (rel_size == 0) | 1512 | if (rel_size == 0) |
| 1503 | rel_addr = addr; | 1513 | rel_addr = addr; |
| 1504 | rel_size += s->sh_size; | 1514 | rel_size += s->sh_size; |
| @@ -1541,7 +1551,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 36 unmodified lines |
| 1541 | | 1551 | |
| 1542 | /* if dynamic section, then add corresponing program header */ | 1552 | /* if dynamic section, then add corresponing program header */ |
| 1543 | if (dynamic) { | 1553 | if (dynamic) { |
| 1544 | Elf32_Sym *sym_end; | 1554 | ElfW(Sym) *sym_end; |
| 1545 | | 1555 | |
| 1546 | ph = &phdr[phnum - 1]; | 1556 | ph = &phdr[phnum - 1]; |
| 1547 | | 1557 | |
| @@ -1589,8 +1599,8 @@ int elf_output_file(TCCState *s1, const char *filename) · 41 unmodified lines |
| 1589 | } | 1599 | } |
| 1590 | | 1600 | |
| 1591 | /* relocate symbols in .dynsym */ | 1601 | /* relocate symbols in .dynsym */ |
| 1592 | sym_end = (Elf32_Sym *)(s1->dynsym->data + s1->dynsym->data_offset); | 1602 | sym_end = (ElfW(Sym) *)(s1->dynsym->data + s1->dynsym->data_offset); |
| 1593 | for(sym = (Elf32_Sym *)s1->dynsym->data + 1; | 1603 | for(sym = (ElfW(Sym) *)s1->dynsym->data + 1; |
| 1594 | sym < sym_end; | 1604 | sym < sym_end; |
| 1595 | sym++) { | 1605 | sym++) { |
| 1596 | if (sym->st_shndx == SHN_UNDEF) { | 1606 | if (sym->st_shndx == SHN_UNDEF) { |
| @@ -1610,18 +1620,18 @@ int elf_output_file(TCCState *s1, const char *filename) · 13 unmodified lines |
| 1610 | put_dt(dynamic, DT_STRTAB, dynstr->sh_addr); | 1620 | put_dt(dynamic, DT_STRTAB, dynstr->sh_addr); |
| 1611 | put_dt(dynamic, DT_SYMTAB, s1->dynsym->sh_addr); | 1621 | put_dt(dynamic, DT_SYMTAB, s1->dynsym->sh_addr); |
| 1612 | put_dt(dynamic, DT_STRSZ, dynstr->data_offset); | 1622 | put_dt(dynamic, DT_STRSZ, dynstr->data_offset); |
| 1613 | put_dt(dynamic, DT_SYMENT, sizeof(Elf32_Sym)); | 1623 | put_dt(dynamic, DT_SYMENT, sizeof(ElfW(Sym))); |
| 1614 | put_dt(dynamic, DT_REL, rel_addr); | 1624 | put_dt(dynamic, DT_REL, rel_addr); |
| 1615 | put_dt(dynamic, DT_RELSZ, rel_size); | 1625 | put_dt(dynamic, DT_RELSZ, rel_size); |
| 1616 | put_dt(dynamic, DT_RELENT, sizeof(Elf32_Rel)); | 1626 | put_dt(dynamic, DT_RELENT, sizeof(ElfW_Rel)); |
| 1617 | if (do_debug) | 1627 | if (do_debug) |
| 1618 | put_dt(dynamic, DT_DEBUG, 0); | 1628 | put_dt(dynamic, DT_DEBUG, 0); |
| 1619 | put_dt(dynamic, DT_NULL, 0); | 1629 | put_dt(dynamic, DT_NULL, 0); |
| 1620 | } | 1630 | } |
| 1621 | | 1631 | |
| 1622 | ehdr.e_phentsize = sizeof(Elf32_Phdr); | 1632 | ehdr.e_phentsize = sizeof(ElfW(Phdr)); |
| 1623 | ehdr.e_phnum = phnum; | 1633 | ehdr.e_phnum = phnum; |
| 1624 | ehdr.e_phoff = sizeof(Elf32_Ehdr); | 1634 | ehdr.e_phoff = sizeof(ElfW(Ehdr)); |
| 1625 | } | 1635 | } |
| 1626 | | 1636 | |
| 1627 | /* all other sections come after */ | 1637 | /* all other sections come after */ |
| @@ -1662,7 +1672,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 34 unmodified lines |
| 1662 | for(i = 1; i < s1->nb_sections; i++) { | 1672 | for(i = 1; i < s1->nb_sections; i++) { |
| 1663 | s = s1->sections[i]; | 1673 | s = s1->sections[i]; |
| 1664 | if ((s->sh_flags & SHF_ALLOC) && | 1674 | if ((s->sh_flags & SHF_ALLOC) && |
| 1665 | s->sh_type == SHT_REL) { | 1675 | s->sh_type == SHT_RELX) { |
| 1666 | relocate_rel(s1, s); | 1676 | relocate_rel(s1, s); |
| 1667 | } | 1677 | } |
| 1668 | } | 1678 | } |
| @@ -1733,14 +1743,14 @@ int elf_output_file(TCCState *s1, const char *filename) · 64 unmodified lines |
| 1733 | ehdr.e_machine = EM_TCC_TARGET; | 1743 | ehdr.e_machine = EM_TCC_TARGET; |
| 1734 | ehdr.e_version = EV_CURRENT; | 1744 | ehdr.e_version = EV_CURRENT; |
| 1735 | ehdr.e_shoff = file_offset; | 1745 | ehdr.e_shoff = file_offset; |
| 1736 | ehdr.e_ehsize = sizeof(Elf32_Ehdr); | 1746 | ehdr.e_ehsize = sizeof(ElfW(Ehdr)); |
| 1737 | ehdr.e_shentsize = sizeof(Elf32_Shdr); | 1747 | ehdr.e_shentsize = sizeof(ElfW(Shdr)); |
| 1738 | ehdr.e_shnum = shnum; | 1748 | ehdr.e_shnum = shnum; |
| 1739 | ehdr.e_shstrndx = shnum - 1; | 1749 | ehdr.e_shstrndx = shnum - 1; |
| 1740 | | 1750 | |
| 1741 | fwrite(&ehdr, 1, sizeof(Elf32_Ehdr), f); | 1751 | fwrite(&ehdr, 1, sizeof(ElfW(Ehdr)), f); |
| 1742 | fwrite(phdr, 1, phnum * sizeof(Elf32_Phdr), f); | 1752 | fwrite(phdr, 1, phnum * sizeof(ElfW(Phdr)), f); |
| 1743 | offset = sizeof(Elf32_Ehdr) + phnum * sizeof(Elf32_Phdr); | 1753 | offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr)); |
| 1744 | | 1754 | |
| 1745 | for(i=1;i<s1->nb_sections;i++) { | 1755 | for(i=1;i<s1->nb_sections;i++) { |
| 1746 | s = s1->sections[section_order[i]]; | 1756 | s = s1->sections[section_order[i]]; |
| @@ -1763,7 +1773,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 16 unmodified lines |
| 1763 | | 1773 | |
| 1764 | for(i=0;i<s1->nb_sections;i++) { | 1774 | for(i=0;i<s1->nb_sections;i++) { |
| 1765 | sh = &shdr; | 1775 | sh = &shdr; |
| 1766 | memset(sh, 0, sizeof(Elf32_Shdr)); | 1776 | memset(sh, 0, sizeof(ElfW(Shdr))); |
| 1767 | s = s1->sections[i]; | 1777 | s = s1->sections[i]; |
| 1768 | if (s) { | 1778 | if (s) { |
| 1769 | sh->sh_name = s->sh_name; | 1779 | sh->sh_name = s->sh_name; |
| @@ -1778,7 +1788,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 8 unmodified lines |
| 1778 | sh->sh_offset = s->sh_offset; | 1788 | sh->sh_offset = s->sh_offset; |
| 1779 | sh->sh_size = s->sh_size; | 1789 | sh->sh_size = s->sh_size; |
| 1780 | } | 1790 | } |
| 1781 | fwrite(sh, 1, sizeof(Elf32_Shdr), f); | 1791 | fwrite(sh, 1, sizeof(ElfW(Shdr)), f); |
| 1782 | } | 1792 | } |
| 1783 | } else { | 1793 | } else { |
| 1784 | tcc_output_binary(s1, f, section_order); | 1794 | tcc_output_binary(s1, f, section_order); |
| @@ -1830,15 +1840,15 @@ typedef struct SectionMergeInfo { · 45 unmodified lines |
| 1830 | static int tcc_load_object_file(TCCState *s1, | 1840 | static int tcc_load_object_file(TCCState *s1, |
| 1831 | int fd, unsigned long file_offset) | 1841 | int fd, unsigned long file_offset) |
| 1832 | { | 1842 | { |
| 1833 | Elf32_Ehdr ehdr; | 1843 | ElfW(Ehdr) ehdr; |
| 1834 | Elf32_Shdr *shdr, *sh; | 1844 | ElfW(Shdr) *shdr, *sh; |
| 1835 | int size, i, j, offset, offseti, nb_syms, sym_index, ret; | 1845 | int size, i, j, offset, offseti, nb_syms, sym_index, ret; |
| 1836 | unsigned char *strsec, *strtab; | 1846 | unsigned char *strsec, *strtab; |
| 1837 | int *old_to_new_syms; | 1847 | int *old_to_new_syms; |
| 1838 | char *sh_name, *name; | 1848 | char *sh_name, *name; |
| 1839 | SectionMergeInfo *sm_table, *sm; | 1849 | SectionMergeInfo *sm_table, *sm; |
| 1840 | Elf32_Sym *sym, *symtab; | 1850 | ElfW(Sym) *sym, *symtab; |
| 1841 | Elf32_Rel *rel, *rel_end; | 1851 | ElfW_Rel *rel, *rel_end; |
| 1842 | Section *s; | 1852 | Section *s; |
| 1843 | | 1853 | |
| 1844 | int stab_index; | 1854 | int stab_index; |
| @@ -1865,7 +1875,7 @@ static int tcc_load_object_file(TCCState *s1, · 20 unmodified lines |
| 1865 | } | 1875 | } |
| 1866 | /* read sections */ | 1876 | /* read sections */ |
| 1867 | shdr = load_data(fd, file_offset + ehdr.e_shoff, | 1877 | shdr = load_data(fd, file_offset + ehdr.e_shoff, |
| 1868 | sizeof(Elf32_Shdr) * ehdr.e_shnum); | 1878 | sizeof(ElfW(Shdr)) * ehdr.e_shnum); |
| 1869 | sm_table = tcc_mallocz(sizeof(SectionMergeInfo) * ehdr.e_shnum); | 1879 | sm_table = tcc_mallocz(sizeof(SectionMergeInfo) * ehdr.e_shnum); |
| 1870 | | 1880 | |
| 1871 | /* load section names */ | 1881 | /* load section names */ |
| @@ -1886,7 +1896,7 @@ static int tcc_load_object_file(TCCState *s1, · 14 unmodified lines |
| 1886 | ret = -1; | 1896 | ret = -1; |
| 1887 | goto the_end; | 1897 | goto the_end; |
| 1888 | } | 1898 | } |
| 1889 | nb_syms = sh->sh_size / sizeof(Elf32_Sym); | 1899 | nb_syms = sh->sh_size / sizeof(ElfW(Sym)); |
| 1890 | symtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size); | 1900 | symtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size); |
| 1891 | sm_table[i].s = symtab_section; | 1901 | sm_table[i].s = symtab_section; |
| 1892 | | 1902 | |
| @@ -1906,7 +1916,7 @@ static int tcc_load_object_file(TCCState *s1, · 13 unmodified lines |
| 1906 | sh_name = strsec + sh->sh_name; | 1916 | sh_name = strsec + sh->sh_name; |
| 1907 | /* ignore sections types we do not handle */ | 1917 | /* ignore sections types we do not handle */ |
| 1908 | if (sh->sh_type != SHT_PROGBITS && | 1918 | if (sh->sh_type != SHT_PROGBITS && |
| 1909 | sh->sh_type != SHT_REL && | 1919 | sh->sh_type != SHT_RELX && |
| 1910 | #ifdef TCC_ARM_EABI | 1920 | #ifdef TCC_ARM_EABI |
| 1911 | sh->sh_type != SHT_ARM_EXIDX && | 1921 | sh->sh_type != SHT_ARM_EXIDX && |
| 1912 | #endif | 1922 | #endif |
| @@ -2000,7 +2010,7 @@ static int tcc_load_object_file(TCCState *s1, · 87 unmodified lines |
| 2000 | sh = &shdr[i]; | 2010 | sh = &shdr[i]; |
| 2001 | if (sh->sh_link > 0) | 2011 | if (sh->sh_link > 0) |
| 2002 | s->link = sm_table[sh->sh_link].s; | 2012 | s->link = sm_table[sh->sh_link].s; |
| 2003 | if (sh->sh_type == SHT_REL) { | 2013 | if (sh->sh_type == SHT_RELX) { |
| 2004 | s->sh_info = sm_table[sh->sh_info].s->sh_num; | 2014 | s->sh_info = sm_table[sh->sh_info].s->sh_num; |
| 2005 | /* update backward link */ | 2015 | /* update backward link */ |
| 2006 | s1->sections[s->sh_info]->reloc = s; | 2016 | s1->sections[s->sh_info]->reloc = s; |
| @@ -2020,7 +2030,7 @@ static int tcc_load_object_file(TCCState *s1, · 13 unmodified lines |
| 2020 | /* if a symbol is in a link once section, we use the | 2030 | /* if a symbol is in a link once section, we use the |
| 2021 | already defined symbol. It is very important to get | 2031 | already defined symbol. It is very important to get |
| 2022 | correct relocations */ | 2032 | correct relocations */ |
| 2023 | if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL) { | 2033 | if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) { |
| 2024 | name = strtab + sym->st_name; | 2034 | name = strtab + sym->st_name; |
| 2025 | sym_index = find_elf_sym(symtab_section, name); | 2035 | sym_index = find_elf_sym(symtab_section, name); |
| 2026 | if (sym_index) | 2036 | if (sym_index) |
| @@ -2052,18 +2062,18 @@ static int tcc_load_object_file(TCCState *s1, · 25 unmodified lines |
| 2052 | sh = &shdr[i]; | 2062 | sh = &shdr[i]; |
| 2053 | offset = sm_table[i].offset; | 2063 | offset = sm_table[i].offset; |
| 2054 | switch(s->sh_type) { | 2064 | switch(s->sh_type) { |
| 2055 | case SHT_REL: | 2065 | case SHT_RELX: |
| 2056 | /* take relocation offset information */ | 2066 | /* take relocation offset information */ |
| 2057 | offseti = sm_table[sh->sh_info].offset; | 2067 | offseti = sm_table[sh->sh_info].offset; |
| 2058 | rel_end = (Elf32_Rel *)(s->data + s->data_offset); | 2068 | rel_end = (ElfW_Rel *)(s->data + s->data_offset); |
| 2059 | for(rel = (Elf32_Rel *)(s->data + offset); | 2069 | for(rel = (ElfW_Rel *)(s->data + offset); |
| 2060 | rel < rel_end; | 2070 | rel < rel_end; |
| 2061 | rel++) { | 2071 | rel++) { |
| 2062 | int type; | 2072 | int type; |
| 2063 | unsigned sym_index; | 2073 | unsigned sym_index; |
| 2064 | /* convert symbol index */ | 2074 | /* convert symbol index */ |
| 2065 | type = ELF32_R_TYPE(rel->r_info); | 2075 | type = ELFW(R_TYPE)(rel->r_info); |
| 2066 | sym_index = ELF32_R_SYM(rel->r_info); | 2076 | sym_index = ELFW(R_SYM)(rel->r_info); |
| 2067 | /* NOTE: only one symtab assumed */ | 2077 | /* NOTE: only one symtab assumed */ |
| 2068 | if (sym_index >= nb_syms) | 2078 | if (sym_index >= nb_syms) |
| 2069 | goto invalid_reloc; | 2079 | goto invalid_reloc; |
| @@ -2075,7 +2085,7 @@ static int tcc_load_object_file(TCCState *s1, · 5 unmodified lines |
| 2075 | i, strsec + sh->sh_name, rel->r_offset); | 2085 | i, strsec + sh->sh_name, rel->r_offset); |
| 2076 | goto fail; | 2086 | goto fail; |
| 2077 | } | 2087 | } |
| 2078 | rel->r_info = ELF32_R_INFO(sym_index, type); | 2088 | rel->r_info = ELFW(R_INFO)(sym_index, type); |
| 2079 | /* offset the relocation offset */ | 2089 | /* offset the relocation offset */ |
| 2080 | rel->r_offset += offseti; | 2090 | rel->r_offset += offseti; |
| 2081 | } | 2091 | } |
| @@ -2120,7 +2130,7 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 38 unmodified lines |
| 2120 | uint8_t *data; | 2130 | uint8_t *data; |
| 2121 | const char *ar_names, *p; | 2131 | const char *ar_names, *p; |
| 2122 | const uint8_t *ar_index; | 2132 | const uint8_t *ar_index; |
| 2123 | Elf32_Sym *sym; | 2133 | ElfW(Sym) *sym; |
| 2124 | | 2134 | |
| 2125 | data = tcc_malloc(size); | 2135 | data = tcc_malloc(size); |
| 2126 | if (read(fd, data, size) != size) | 2136 | if (read(fd, data, size) != size) |
| @@ -2134,7 +2144,7 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 7 unmodified lines |
| 2134 | for(p = ar_names, i = 0; i < nsyms; i++, p += strlen(p)+1) { | 2144 | for(p = ar_names, i = 0; i < nsyms; i++, p += strlen(p)+1) { |
| 2135 | sym_index = find_elf_sym(symtab_section, p); | 2145 | sym_index = find_elf_sym(symtab_section, p); |
| 2136 | if(sym_index) { | 2146 | if(sym_index) { |
| 2137 | sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; | 2147 | sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; |
| 2138 | if(sym->st_shndx == SHN_UNDEF) { | 2148 | if(sym->st_shndx == SHN_UNDEF) { |
| 2139 | off = get_be32(ar_index + i * 4) + sizeof(ArchiveHeader); | 2149 | off = get_be32(ar_index + i * 4) + sizeof(ArchiveHeader); |
| 2140 | #if 0 | 2150 | #if 0 |
| @@ -2214,11 +2224,11 @@ static int tcc_load_archive(TCCState *s1, int fd) · 73 unmodified lines |
| 2214 | the generated ELF file) */ | 2224 | the generated ELF file) */ |
| 2215 | static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) | 2225 | static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) |
| 2216 | { | 2226 | { |
| 2217 | Elf32_Ehdr ehdr; | 2227 | ElfW(Ehdr) ehdr; |
| 2218 | Elf32_Shdr *shdr, *sh, *sh1; | 2228 | ElfW(Shdr) *shdr, *sh, *sh1; |
| 2219 | int i, j, nb_syms, nb_dts, sym_bind, ret; | 2229 | int i, j, nb_syms, nb_dts, sym_bind, ret; |
| 2220 | Elf32_Sym *sym, *dynsym; | 2230 | ElfW(Sym) *sym, *dynsym; |
| 2221 | Elf32_Dyn *dt, *dynamic; | 2231 | ElfW(Dyn) *dt, *dynamic; |
| 2222 | unsigned char *dynstr; | 2232 | unsigned char *dynstr; |
| 2223 | const char *name, *soname; | 2233 | const char *name, *soname; |
| 2224 | DLLReference *dllref; | 2234 | DLLReference *dllref; |
| @@ -2233,7 +2243,7 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 8 unmodified lines |
| 2233 | } | 2243 | } |
| 2234 | | 2244 | |
| 2235 | /* read sections */ | 2245 | /* read sections */ |
| 2236 | shdr = load_data(fd, ehdr.e_shoff, sizeof(Elf32_Shdr) * ehdr.e_shnum); | 2246 | shdr = load_data(fd, ehdr.e_shoff, sizeof(ElfW(Shdr)) * ehdr.e_shnum); |
| 2237 | | 2247 | |
| 2238 | /* load dynamic section and dynamic symbols */ | 2248 | /* load dynamic section and dynamic symbols */ |
| 2239 | nb_syms = 0; | 2249 | nb_syms = 0; |
| @@ -2244,11 +2254,11 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 4 unmodified lines |
| 2244 | for(i = 0, sh = shdr; i < ehdr.e_shnum; i++, sh++) { | 2254 | for(i = 0, sh = shdr; i < ehdr.e_shnum; i++, sh++) { |
| 2245 | switch(sh->sh_type) { | 2255 | switch(sh->sh_type) { |
| 2246 | case SHT_DYNAMIC: | 2256 | case SHT_DYNAMIC: |
| 2247 | nb_dts = sh->sh_size / sizeof(Elf32_Dyn); | 2257 | nb_dts = sh->sh_size / sizeof(ElfW(Dyn)); |
| 2248 | dynamic = load_data(fd, sh->sh_offset, sh->sh_size); | 2258 | dynamic = load_data(fd, sh->sh_offset, sh->sh_size); |
| 2249 | break; | 2259 | break; |
| 2250 | case SHT_DYNSYM: | 2260 | case SHT_DYNSYM: |
| 2251 | nb_syms = sh->sh_size / sizeof(Elf32_Sym); | 2261 | nb_syms = sh->sh_size / sizeof(ElfW(Sym)); |
| 2252 | dynsym = load_data(fd, sh->sh_offset, sh->sh_size); | 2262 | dynsym = load_data(fd, sh->sh_offset, sh->sh_size); |
| 2253 | sh1 = &shdr[sh->sh_link]; | 2263 | sh1 = &shdr[sh->sh_link]; |
| 2254 | dynstr = load_data(fd, sh1->sh_offset, sh1->sh_size); | 2264 | dynstr = load_data(fd, sh1->sh_offset, sh1->sh_size); |
| @@ -2289,7 +2299,7 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 34 unmodified lines |
| 2289 | | 2299 | |
| 2290 | /* add dynamic symbols in dynsym_section */ | 2300 | /* add dynamic symbols in dynsym_section */ |
| 2291 | for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) { | 2301 | for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) { |
| 2292 | sym_bind = ELF32_ST_BIND(sym->st_info); | 2302 | sym_bind = ELFW(ST_BIND)(sym->st_info); |
| 2293 | if (sym_bind == STB_LOCAL) | 2303 | if (sym_bind == STB_LOCAL) |
| 2294 | continue; | 2304 | continue; |
| 2295 | name = dynstr + sym->st_name; | 2305 | name = dynstr + sym->st_name; |