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