History

Introduce ElfW macro and ELFW to encapsulate the difference between Elf32_* and Elf64_*. Also, introduce ElfW_Rel and SHT_RELX for difference between REL and RELA.

Shinichiro Hamaji committed 17 years ago

Commit 7dd792e1 parent 76b02c23 files · +198 −177Browse files

Unified · Split

3 files
  1. elf.h +10 −0
  2. tcc.c +15 −14
  3. tccelf.c +173 −163
elf.h+10−0
@@ -1630,4 +1630,14 @@ typedef Elf32_Addr Elf32_Conflict; · 1629 unmodified lines
16301630 #define R_C60HI16 0x55 // high 16 bit MVKH embedded
16311631 #define R_C60LO16 0x54 // low 16 bit MVKL embedded
16321632
1633+#ifdef TCC_TARGET_X86_64
1634+#define TCC_ELFCLASS ELFCLASS64
1635+#define ElfW(type) Elf##64##_##type
1636+#define ELFW(type) ELF##64##_##type
1637+#else
1638+#define TCC_ELFCLASS ELFCLASS32
1639+#define ElfW(type) Elf##32##_##type
1640+#define ELFW(type) ELF##32##_##type
1641+#endif
1642+
16331643 #endif /* elf.h */
tcc.c+15−14
@@ -1261,6 +1261,7 @@ Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags) · 1260 unmodified lines
12611261 switch(sh_type) {
12621262 case SHT_HASH:
12631263 case SHT_REL:
1264+ case SHT_RELA:
12641265 case SHT_DYNSYM:
12651266 case SHT_SYMTAB:
12661267 case SHT_DYNAMIC:
@@ -1349,7 +1350,7 @@ static void put_extern_sym2(Sym *sym, Section *section, · 82 unmodified lines
13491350 int can_add_underscore)
13501351 {
13511352 int sym_type, sym_bind, sh_num, info, other, attr;
1352− Elf32_Sym *esym;
1353+ ElfW(Sym) *esym;
13531354 const char *name;
13541355 char buf1[256];
13551356
@@ -1424,10 +1425,10 @@ static void put_extern_sym2(Sym *sym, Section *section, · 68 unmodified lines
14241425 pstrcpy(buf1 + 1, sizeof(buf1) - 1, name);
14251426 name = buf1;
14261427 }
1427− info = ELF32_ST_INFO(sym_bind, sym_type);
1428+ info = ELFW(ST_INFO)(sym_bind, sym_type);
14281429 sym->c = add_elf_sym(symtab_section, value, size, info, other, sh_num, name);
14291430 } else {
1430− esym = &((Elf32_Sym *)symtab_section->data)[sym->c];
1431+ esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
14311432 esym->st_value = value;
14321433 esym->st_size = size;
14331434 esym->st_shndx = sh_num;
@@ -9140,11 +9141,11 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 7706 unmodified lines
91409141 if (sec) {
91419142 put_extern_sym(sym, sec, addr, size);
91429143 } else {
9143− Elf32_Sym *esym;
9144+ ElfW(Sym) *esym;
91449145 /* put a common area */
91459146 put_extern_sym(sym, NULL, align, size);
91469147 /* XXX: find a nicer way */
9147− esym = &((Elf32_Sym *)symtab_section->data)[sym->c];
9148+ esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
91489149 esym->st_shndx = SHN_COMMON;
91499150 }
91509151 } else {
@@ -9270,7 +9271,7 @@ static void gen_function(Sym *sym) · 119 unmodified lines
92709271 sym_pop(&local_stack, NULL); /* reset local stack */
92719272 /* end of function */
92729273 /* patch symbol size */
9273− ((Elf32_Sym *)symtab_section->data)[sym->c].st_size =
9274+ ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size =
92749275 ind - func_ind;
92759276 if (do_debug) {
92769277 put_stabn(N_FUN, 0, 0, ind - func_ind);
@@ -9552,7 +9553,7 @@ static int tcc_compile(TCCState *s1) · 275 unmodified lines
95529553 section_sym = 0; /* avoid warning */
95539554 if (do_debug) {
95549555 section_sym = put_elf_sym(symtab_section, 0, 0,
9555− ELF32_ST_INFO(STB_LOCAL, STT_SECTION), 0,
9556+ ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
95569557 text_section->sh_num, NULL);
95579558 getcwd(buf, sizeof(buf));
95589559 #ifdef _WIN32
@@ -9567,7 +9568,7 @@ static int tcc_compile(TCCState *s1) · 8 unmodified lines
95679568 /* an elf symbol of type STT_FILE must be put so that STB_LOCAL
95689569 symbols can be safely used */
95699570 put_elf_sym(symtab_section, 0, 0,
9570− ELF32_ST_INFO(STB_LOCAL, STT_FILE), 0,
9571+ ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
95719572 SHN_ABS, file->filename);
95729573
95739574 /* define some often used types */
@@ -9872,14 +9873,14 @@ static void rt_printline(unsigned long wanted_pc) · 298 unmodified lines
98729873 /* second pass: we try symtab symbols (no line number info) */
98739874 incl_index = 0;
98749875 {
9875− Elf32_Sym *sym, *sym_end;
9876+ ElfW(Sym) *sym, *sym_end;
98769877 int type;
98779878
9878− sym_end = (Elf32_Sym *)(symtab_section->data + symtab_section->data_offset);
9879− for(sym = (Elf32_Sym *)symtab_section->data + 1;
9879+ sym_end = (ElfW(Sym) *)(symtab_section->data + symtab_section->data_offset);
9880+ for(sym = (ElfW(Sym) *)symtab_section->data + 1;
98809881 sym < sym_end;
98819882 sym++) {
9882− type = ELF32_ST_TYPE(sym->st_info);
9883+ type = ELFW(ST_TYPE)(sym->st_info);
98839884 if (type == STT_FUNC) {
98849885 if (wanted_pc >= sym->st_value &&
98859886 wanted_pc < sym->st_value + sym->st_size) {
@@ -10329,7 +10330,7 @@ int tcc_add_sysinclude_path(TCCState *s1, const char *pathname) · 443 unmodified lines
1032910330 static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
1033010331 {
1033110332 const char *ext;
10332− Elf32_Ehdr ehdr;
10333+ ElfW(Ehdr) ehdr;
1033310334 int fd, ret;
1033410335 BufferedFile *saved_file;
1033510336
@@ -10502,7 +10503,7 @@ int tcc_add_library(TCCState *s, const char *libraryname) · 166 unmodified lines
1050210503 int tcc_add_symbol(TCCState *s, const char *name, unsigned long val)
1050310504 {
1050410505 add_elf_sym(symtab_section, val, 0,
10505− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
10506+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1050610507 SHN_ABS, name);
1050710508 return 0;
1050810509 }
tccelf.c+173−163
@@ -18,6 +18,16 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
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+
2131 static int put_elf_str(Section *s, const char *sym)
2232 {
2333 int offset, len;
@@ -49,12 +59,12 @@ static unsigned long elf_hash(const unsigned char *name) · 25 unmodified lines
4959 /* NOTE: we do factorize the hash table code to go faster */
5060 static void rebuild_hash(Section *s, unsigned int nb_buckets)
5161 {
52− Elf32_Sym *sym;
62+ ElfW(Sym) *sym;
5363 int *ptr, *hash, nb_syms, sym_index, h;
5464 char *strtab;
5565
5666 strtab = s->link->data;
57− nb_syms = s->data_offset / sizeof(Elf32_Sym);
67+ nb_syms = s->data_offset / sizeof(ElfW(Sym));
5868
5969 s->hash->data_offset = 0;
6070 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
6575 memset(hash, 0, (nb_buckets + 1) * sizeof(int));
6676 ptr += nb_buckets + 1;
6777
68− sym = (Elf32_Sym *)s->data + 1;
78+ sym = (ElfW(Sym) *)s->data + 1;
6979 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) {
7181 h = elf_hash(strtab + sym->st_name) % nb_buckets;
7282 *ptr = hash[h];
7383 hash[h] = sym_index;
@@ -86,10 +96,10 @@ static int put_elf_sym(Section *s, · 12 unmodified lines
8696 {
8797 int name_offset, sym_index;
8898 int nbuckets, h;
89− Elf32_Sym *sym;
99+ ElfW(Sym) *sym;
90100 Section *hs;
91101
92− sym = section_ptr_add(s, sizeof(Elf32_Sym));
102+ sym = section_ptr_add(s, sizeof(ElfW(Sym)));
93103 if (name)
94104 name_offset = put_elf_str(s->link, name);
95105 else
@@ -101,14 +111,14 @@ static int put_elf_sym(Section *s, · 5 unmodified lines
101111 sym->st_info = info;
102112 sym->st_other = other;
103113 sym->st_shndx = shndx;
104− sym_index = sym - (Elf32_Sym *)s->data;
114+ sym_index = sym - (ElfW(Sym) *)s->data;
105115 hs = s->hash;
106116 if (hs) {
107117 int *ptr, *base;
108118 ptr = section_ptr_add(hs, sizeof(int));
109119 base = (int *)hs->data;
110120 /* only add global or weak symbols */
111− if (ELF32_ST_BIND(info) != STB_LOCAL) {
121+ if (ELFW(ST_BIND)(info) != STB_LOCAL) {
112122 /* add another hashing entry */
113123 nbuckets = base[0];
114124 h = elf_hash(name) % nbuckets;
@@ -132,7 +142,7 @@ static int put_elf_sym(Section *s, · 17 unmodified lines
132142 found. */
133143 static int find_elf_sym(Section *s, const char *name)
134144 {
135− Elf32_Sym *sym;
145+ ElfW(Sym) *sym;
136146 Section *hs;
137147 int nbuckets, sym_index, h;
138148 const char *name1;
@@ -144,7 +154,7 @@ static int find_elf_sym(Section *s, const char *name) · 5 unmodified lines
144154 h = elf_hash(name) % nbuckets;
145155 sym_index = ((int *)hs->data)[2 + h];
146156 while (sym_index != 0) {
147− sym = &((Elf32_Sym *)s->data)[sym_index];
157+ sym = &((ElfW(Sym) *)s->data)[sym_index];
148158 name1 = s->link->data + sym->st_name;
149159 if (!strcmp(name, name1))
150160 return sym_index;
@@ -157,12 +167,12 @@ static int find_elf_sym(Section *s, const char *name) · 6 unmodified lines
157167 int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name)
158168 {
159169 int sym_index;
160− Elf32_Sym *sym;
170+ ElfW(Sym) *sym;
161171
162172 sym_index = find_elf_sym(symtab_section, name);
163173 if (!sym_index)
164174 return -1;
165− sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
175+ sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
166176 *pval = sym->st_value;
167177 return 0;
168178 }
@@ -180,25 +190,25 @@ void *tcc_get_symbol_err(TCCState *s, const char *name) · 11 unmodified lines
180190 static int add_elf_sym(Section *s, unsigned long value, unsigned long size,
181191 int info, int other, int sh_num, const char *name)
182192 {
183− Elf32_Sym *esym;
193+ ElfW(Sym) *esym;
184194 int sym_bind, sym_index, sym_type, esym_bind;
185195 unsigned char sym_vis, esym_vis, new_vis;
186196
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);
190200
191201 if (sym_bind != STB_LOCAL) {
192202 /* we search global or weak symbols */
193203 sym_index = find_elf_sym(s, name);
194204 if (!sym_index)
195205 goto do_def;
196− esym = &((Elf32_Sym *)s->data)[sym_index];
206+ esym = &((ElfW(Sym) *)s->data)[sym_index];
197207 if (esym->st_shndx != SHN_UNDEF) {
198− esym_bind = ELF32_ST_BIND(esym->st_info);
208+ esym_bind = ELFW(ST_BIND)(esym->st_info);
199209 /* propagate the most constraining visibility */
200210 /* 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);
202212 if (esym_vis == STV_DEFAULT) {
203213 new_vis = sym_vis;
204214 } 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
206216 } else {
207217 new_vis = (esym_vis < sym_vis) ? esym_vis : sym_vis;
208218 }
209− esym->st_other = (esym->st_other & ~ELF32_ST_VISIBILITY(-1))
219+ esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1))
210220 | new_vis;
211221 other = esym->st_other; /* in case we have to patch esym */
212222 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
234244 }
235245 } else {
236246 do_patch:
237− esym->st_info = ELF32_ST_INFO(sym_bind, sym_type);
247+ esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type);
238248 esym->st_shndx = sh_num;
239249 esym->st_value = value;
240250 esym->st_size = size;
@@ -243,7 +253,7 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 2 unmodified lines
243253 } else {
244254 do_def:
245255 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,
247257 sh_num, name);
248258 }
249259 return sym_index;
@@ -255,7 +265,7 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 5 unmodified lines
255265 {
256266 char buf[256];
257267 Section *sr;
258− Elf32_Rel *rel;
268+ ElfW_Rel *rel;
259269
260270 sr = s->reloc;
261271 if (!sr) {
@@ -263,15 +273,15 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 1 unmodified line
263273 snprintf(buf, sizeof(buf), ".rel%s", s->name);
264274 /* if the symtab is allocated, then we consider the relocation
265275 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);
268278 sr->link = symtab;
269279 sr->sh_info = s->sh_num;
270280 s->reloc = sr;
271281 }
272− rel = section_ptr_add(sr, sizeof(Elf32_Rel));
282+ rel = section_ptr_add(sr, sizeof(ElfW_Rel));
273283 rel->r_offset = offset;
274− rel->r_info = ELF32_R_INFO(symbol, type);
284+ rel->r_info = ELFW(R_INFO)(symbol, type);
275285 }
276286
277287 /* put stab debug information */
@@ -327,22 +337,22 @@ static void put_stabd(int type, int other, int desc) · 49 unmodified lines
327337 static void sort_syms(TCCState *s1, Section *s)
328338 {
329339 int *old_to_new_syms;
330− Elf32_Sym *new_syms;
340+ ElfW(Sym) *new_syms;
331341 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;
334344 Section *sr;
335345 int type, sym_index;
336346
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)));
339349 old_to_new_syms = tcc_malloc(nb_syms * sizeof(int));
340350
341351 /* first pass for local symbols */
342− p = (Elf32_Sym *)s->data;
352+ p = (ElfW(Sym) *)s->data;
343353 q = new_syms;
344354 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) {
346356 old_to_new_syms[i] = q - new_syms;
347357 *q++ = *p;
348358 }
@@ -352,9 +362,9 @@ static void sort_syms(TCCState *s1, Section *s) · 3 unmodified lines
352362 s->sh_info = q - new_syms;
353363
354364 /* then second pass for non local symbols */
355− p = (Elf32_Sym *)s->data;
365+ p = (ElfW(Sym) *)s->data;
356366 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) {
358368 old_to_new_syms[i] = q - new_syms;
359369 *q++ = *p;
360370 }
@@ -362,21 +372,21 @@ static void sort_syms(TCCState *s1, Section *s) · 1 unmodified line
362372 }
363373
364374 /* 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)));
366376 tcc_free(new_syms);
367377
368378 /* now we modify all the relocations */
369379 for(i = 1; i < s1->nb_sections; i++) {
370380 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;
374384 rel < rel_end;
375385 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);
378388 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);
380390 }
381391 }
382392 }
@@ -387,11 +397,11 @@ static void sort_syms(TCCState *s1, Section *s) · 4 unmodified lines
387397 /* relocate common symbols in the .bss section */
388398 static void relocate_common_syms(void)
389399 {
390− Elf32_Sym *sym, *sym_end;
400+ ElfW(Sym) *sym, *sym_end;
391401 unsigned long offset, align;
392402
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;
395405 sym < sym_end;
396406 sym++) {
397407 if (sym->st_shndx == SHN_COMMON) {
@@ -411,13 +421,13 @@ static void relocate_common_syms(void) · 13 unmodified lines
411421 true and output error if undefined symbol. */
412422 static void relocate_syms(TCCState *s1, int do_resolve)
413423 {
414− Elf32_Sym *sym, *esym, *sym_end;
424+ ElfW(Sym) *sym, *esym, *sym_end;
415425 int sym_bind, sh_num, sym_index;
416426 const char *name;
417427 unsigned long addr;
418428
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;
421431 sym < sym_end;
422432 sym++) {
423433 sh_num = sym->st_shndx;
@@ -425,7 +435,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 1 unmodified line
425435 name = strtab_section->data + sym->st_name;
426436 if (do_resolve) {
427437 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));
429439 if (addr) {
430440 sym->st_value = addr;
431441 goto found;
@@ -434,7 +444,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 2 unmodified lines
434444 /* if dynamic symbol exist, then use it */
435445 sym_index = find_elf_sym(s1->dynsym, name);
436446 if (sym_index) {
437− esym = &((Elf32_Sym *)s1->dynsym->data)[sym_index];
447+ esym = &((ElfW(Sym) *)s1->dynsym->data)[sym_index];
438448 sym->st_value = esym->st_value;
439449 goto found;
440450 }
@@ -445,7 +455,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 4 unmodified lines
445455 goto found;
446456 /* only weak symbols are accepted to be undefined. Their
447457 value is zero */
448− sym_bind = ELF32_ST_BIND(sym->st_info);
458+ sym_bind = ELFW(ST_BIND)(sym->st_info);
449459 if (sym_bind == STB_WEAK) {
450460 sym->st_value = 0;
451461 } else {
@@ -463,8 +473,8 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 11 unmodified lines
463473 static void relocate_section(TCCState *s1, Section *s)
464474 {
465475 Section *sr;
466− Elf32_Rel *rel, *rel_end, *qrel;
467− Elf32_Sym *sym;
476+ ElfW_Rel *rel, *rel_end, *qrel;
477+ ElfW(Sym) *sym;
468478 int type, sym_index;
469479 unsigned char *ptr;
470480 unsigned long val, addr;
@@ -473,17 +483,17 @@ static void relocate_section(TCCState *s1, Section *s) · 2 unmodified lines
473483 #endif
474484
475485 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;
478488 for(rel = qrel;
479489 rel < rel_end;
480490 rel++) {
481491 ptr = s->data + rel->r_offset;
482492
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];
485495 val = sym->st_value;
486− type = ELF32_R_TYPE(rel->r_info);
496+ type = ELFW(R_TYPE)(rel->r_info);
487497 addr = s->sh_addr + rel->r_offset;
488498
489499 /* CPU specific */
@@ -494,11 +504,11 @@ static void relocate_section(TCCState *s1, Section *s) · 4 unmodified lines
494504 esym_index = s1->symtab_to_dynsym[sym_index];
495505 qrel->r_offset = rel->r_offset;
496506 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);
498508 qrel++;
499509 break;
500510 } else {
501− qrel->r_info = ELF32_R_INFO(0, R_386_RELATIVE);
511+ qrel->r_info = ELFW(R_INFO)(0, R_386_RELATIVE);
502512 qrel++;
503513 }
504514 }
@@ -510,7 +520,7 @@ static void relocate_section(TCCState *s1, Section *s) · 5 unmodified lines
510520 esym_index = s1->symtab_to_dynsym[sym_index];
511521 if (esym_index) {
512522 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);
514524 qrel++;
515525 break;
516526 }
@@ -624,11 +634,11 @@ static void relocate_section(TCCState *s1, Section *s) · 107 unmodified lines
624634 static void relocate_rel(TCCState *s1, Section *sr)
625635 {
626636 Section *s;
627− Elf32_Rel *rel, *rel_end;
637+ ElfW_Rel *rel, *rel_end;
628638
629639 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;
632642 rel < rel_end;
633643 rel++) {
634644 rel->r_offset += s->sh_addr;
@@ -639,14 +649,14 @@ static void relocate_rel(TCCState *s1, Section *sr) · 4 unmodified lines
639649 their space */
640650 static int prepare_dynamic_rel(TCCState *s1, Section *sr)
641651 {
642− Elf32_Rel *rel, *rel_end;
652+ ElfW_Rel *rel, *rel_end;
643653 int sym_index, esym_index, type, count;
644654
645655 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);
650660 switch(type) {
651661 case R_386_32:
652662 count++;
@@ -663,7 +673,7 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 10 unmodified lines
663673 if (count) {
664674 /* allocate the section */
665675 sr->sh_flags |= SHF_ALLOC;
666− sr->sh_size = count * sizeof(Elf32_Rel);
676+ sr->sh_size = count * sizeof(ElfW_Rel);
667677 }
668678 return count;
669679 }
@@ -712,7 +722,7 @@ static void build_got(TCCState *s1) · 42 unmodified lines
712722 /* if no got, then create it */
713723 s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
714724 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),
716726 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_");
717727 ptr = section_ptr_add(s1->got, 3 * sizeof(int));
718728 /* keep space for _DYNAMIC pointer, if present */
@@ -730,7 +740,7 @@ static void put_got_entry(TCCState *s1, · 11 unmodified lines
730740 {
731741 int index;
732742 const char *name;
733− Elf32_Sym *sym;
743+ ElfW(Sym) *sym;
734744 unsigned long offset;
735745 int *ptr;
736746
@@ -745,7 +755,7 @@ static void put_got_entry(TCCState *s1, · 8 unmodified lines
745755 put_got_offset(s1, sym_index, s1->got->data_offset);
746756
747757 if (s1->dynsym) {
748− sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
758+ sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
749759 name = symtab_section->link->data + sym->st_name;
750760 offset = sym->st_value;
751761 #ifdef TCC_TARGET_I386
@@ -838,23 +848,23 @@ static void put_got_entry(TCCState *s1, · 86 unmodified lines
838848 static void build_got_entries(TCCState *s1)
839849 {
840850 Section *s, *symtab;
841− Elf32_Rel *rel, *rel_end;
842− Elf32_Sym *sym;
851+ ElfW_Rel *rel, *rel_end;
852+ ElfW(Sym) *sym;
843853 int i, type, reloc_type, sym_index;
844854
845855 for(i = 1; i < s1->nb_sections; i++) {
846856 s = s1->sections[i];
847− if (s->sh_type != SHT_REL)
857+ if (s->sh_type != SHT_RELX)
848858 continue;
849859 /* no need to handle got relocations */
850860 if (s->link != symtab_section)
851861 continue;
852862 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;
855865 rel < rel_end;
856866 rel++) {
857− type = ELF32_R_TYPE(rel->r_info);
867+ type = ELFW(R_TYPE)(rel->r_info);
858868 switch(type) {
859869 #if defined(TCC_TARGET_I386)
860870 case R_386_GOT32:
@@ -864,8 +874,8 @@ static void build_got_entries(TCCState *s1) · 3 unmodified lines
864874 if (!s1->got)
865875 build_got(s1);
866876 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];
869879 /* look at the symbol got offset. If none, then add one */
870880 if (type == R_386_GOT32)
871881 reloc_type = R_386_GLOB_DAT;
@@ -883,8 +893,8 @@ static void build_got_entries(TCCState *s1) · 11 unmodified lines
883893 if (!s1->got)
884894 build_got(s1);
885895 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];
888898 /* look at the symbol got offset. If none, then add one */
889899 if (type == R_ARM_GOT_BREL)
890900 reloc_type = R_ARM_GLOB_DAT;
@@ -902,8 +912,8 @@ static void build_got_entries(TCCState *s1) · 11 unmodified lines
902912 if (!s1->got)
903913 build_got(s1);
904914 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];
907917 /* look at the symbol got offset. If none, then add one */
908918 if (type == R_C60_GOT32)
909919 reloc_type = R_C60_GLOB_DAT;
@@ -932,7 +942,7 @@ static Section *new_symtab(TCCState *s1, · 22 unmodified lines
932942 int *ptr, nb_buckets;
933943
934944 symtab = new_section(s1, symtab_name, sh_type, sh_flags);
935− symtab->sh_entsize = sizeof(Elf32_Sym);
945+ symtab->sh_entsize = sizeof(ElfW(Sym));
936946 strtab = new_section(s1, strtab_name, SHT_STRTAB, sh_flags);
937947 put_elf_str(strtab, "");
938948 symtab->link = strtab;
@@ -955,8 +965,8 @@ static Section *new_symtab(TCCState *s1, · 16 unmodified lines
955965 /* put dynamic tag */
956966 static void put_dt(Section *dynamic, int dt, unsigned long val)
957967 {
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)));
960970 dyn->d_tag = dt;
961971 dyn->d_un.d_val = val;
962972 }
@@ -981,11 +991,11 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 18 unmodified lines
981991
982992 add_elf_sym(symtab_section,
983993 0, 0,
984− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
994+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
985995 s->sh_num, sym_start);
986996 add_elf_sym(symtab_section,
987997 end_offset, 0,
988− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
998+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
989999 s->sh_num, sym_end);
9901000 }
9911001
@@ -1007,7 +1017,7 @@ static void tcc_add_runtime(TCCState *s1) · 15 unmodified lines
10071017 ptr = section_ptr_add(bounds_section, sizeof(unsigned long));
10081018 *ptr = 0;
10091019 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,
10111021 bounds_section->sh_num, "__bounds_start");
10121022 /* add bound check code */
10131023 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
10541064
10551065 add_elf_sym(symtab_section,
10561066 text_section->data_offset, 0,
1057− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1067+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
10581068 text_section->sh_num, "_etext");
10591069 add_elf_sym(symtab_section,
10601070 data_section->data_offset, 0,
1061− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1071+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
10621072 data_section->sh_num, "_edata");
10631073 add_elf_sym(symtab_section,
10641074 bss_section->data_offset, 0,
1065− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1075+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
10661076 bss_section->sh_num, "_end");
10671077 /* horrible new standard ldscript defines */
10681078 add_init_array_defines(s1, ".preinit_array");
@@ -1091,12 +1101,12 @@ static void tcc_add_linker_symbols(TCCState *s1) · 22 unmodified lines
10911101 snprintf(buf, sizeof(buf), "__start_%s", s->name);
10921102 add_elf_sym(symtab_section,
10931103 0, 0,
1094− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1104+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
10951105 s->sh_num, buf);
10961106 snprintf(buf, sizeof(buf), "__stop_%s", s->name);
10971107 add_elf_sym(symtab_section,
10981108 s->data_offset, 0,
1099− ELF32_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1109+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
11001110 s->sh_num, buf);
11011111 }
11021112 next_sec: ;
@@ -1140,18 +1150,18 @@ static void tcc_output_binary(TCCState *s1, FILE *f, · 37 unmodified lines
11401150 /* XXX: suppress unneeded sections */
11411151 int elf_output_file(TCCState *s1, const char *filename)
11421152 {
1143− Elf32_Ehdr ehdr;
1153+ ElfW(Ehdr) ehdr;
11441154 FILE *f;
11451155 int fd, mode, ret;
11461156 int *section_order;
11471157 int shnum, i, phnum, file_offset, offset, size, j, tmp, sh_order_index, k;
11481158 unsigned long addr;
11491159 Section *strsec, *s;
1150− Elf32_Shdr shdr, *sh;
1151− Elf32_Phdr *phdr, *ph;
1160+ ElfW(Shdr) shdr, *sh;
1161+ ElfW(Phdr) *phdr, *ph;
11521162 Section *interp, *dynamic, *dynstr;
11531163 unsigned long saved_dynamic_data_offset;
1154− Elf32_Sym *sym;
1164+ ElfW(Sym) *sym;
11551165 int type, file_type;
11561166 unsigned long rel_addr, rel_size;
11571167
@@ -1177,7 +1187,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 19 unmodified lines
11771187 if (!s1->static_link) {
11781188 const char *name;
11791189 int sym_index, index;
1180− Elf32_Sym *esym, *sym_end;
1190+ ElfW(Sym) *esym, *sym_end;
11811191
11821192 if (file_type == TCC_OUTPUT_EXE) {
11831193 char *ptr;
@@ -1198,7 +1208,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 14 unmodified lines
11981208 dynamic = new_section(s1, ".dynamic", SHT_DYNAMIC,
11991209 SHF_ALLOC | SHF_WRITE);
12001210 dynamic->link = dynstr;
1201− dynamic->sh_entsize = sizeof(Elf32_Dyn);
1211+ dynamic->sh_entsize = sizeof(ElfW(Dyn));
12021212
12031213 /* add PLT */
12041214 s1->plt = new_section(s1, ".plt", SHT_PROGBITS,
@@ -1211,22 +1221,22 @@ int elf_output_file(TCCState *s1, const char *filename) · 6 unmodified lines
12111221 dynamic symbols. If a symbol STT_FUNC is found, then we
12121222 add it in the PLT. If a symbol STT_OBJECT is found, we
12131223 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 +
12151225 symtab_section->data_offset);
12161226 if (file_type == TCC_OUTPUT_EXE) {
1217− for(sym = (Elf32_Sym *)symtab_section->data + 1;
1227+ for(sym = (ElfW(Sym) *)symtab_section->data + 1;
12181228 sym < sym_end;
12191229 sym++) {
12201230 if (sym->st_shndx == SHN_UNDEF) {
12211231 name = symtab_section->link->data + sym->st_name;
12221232 sym_index = find_elf_sym(s1->dynsymtab_section, name);
12231233 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);
12261236 if (type == STT_FUNC) {
12271237 put_got_entry(s1, R_JMP_SLOT, esym->st_size,
12281238 esym->st_info,
1229− sym - (Elf32_Sym *)symtab_section->data);
1239+ sym - (ElfW(Sym) *)symtab_section->data);
12301240 } else if (type == STT_OBJECT) {
12311241 unsigned long offset;
12321242 offset = bss_section->data_offset;
@@ -1244,14 +1254,14 @@ int elf_output_file(TCCState *s1, const char *filename) · 11 unmodified lines
12441254 /* STB_WEAK undefined symbols are accepted */
12451255 /* XXX: _fp_hw seems to be part of the ABI, so we ignore
12461256 it */
1247− if (ELF32_ST_BIND(sym->st_info) == STB_WEAK ||
1257+ if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK ||
12481258 !strcmp(name, "_fp_hw")) {
12491259 } else {
12501260 error_noabort("undefined symbol '%s'", name);
12511261 }
12521262 }
12531263 } else if (s1->rdynamic &&
1254− ELF32_ST_BIND(sym->st_info) != STB_LOCAL) {
1264+ ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
12551265 /* if -rdynamic option, then export all non
12561266 local symbols */
12571267 name = symtab_section->link->data + sym->st_name;
@@ -1266,9 +1276,9 @@ int elf_output_file(TCCState *s1, const char *filename) · 8 unmodified lines
12661276
12671277 /* now look at unresolved dynamic symbols and export
12681278 corresponding symbol */
1269− sym_end = (Elf32_Sym *)(s1->dynsymtab_section->data +
1279+ sym_end = (ElfW(Sym) *)(s1->dynsymtab_section->data +
12701280 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;
12721282 esym < sym_end;
12731283 esym++) {
12741284 if (esym->st_shndx == SHN_UNDEF) {
@@ -1277,12 +1287,12 @@ int elf_output_file(TCCState *s1, const char *filename) · 2 unmodified lines
12771287 if (sym_index) {
12781288 /* XXX: avoid adding a symbol if already
12791289 present because of -rdynamic ? */
1280− sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
1290+ sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
12811291 put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
12821292 sym->st_info, 0,
12831293 sym->st_shndx, name);
12841294 } else {
1285− if (ELF32_ST_BIND(esym->st_info) == STB_WEAK) {
1295+ if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) {
12861296 /* weak symbols can stay undefined */
12871297 } else {
12881298 warning("undefined dynamic symbol '%s'", name);
@@ -1293,18 +1303,18 @@ int elf_output_file(TCCState *s1, const char *filename) · 4 unmodified lines
12931303 } else {
12941304 int nb_syms;
12951305 /* 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));
12971307 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;
12991309 sym < sym_end;
13001310 sym++) {
1301− if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL) {
1311+ if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
13021312 name = symtab_section->link->data + sym->st_name;
13031313 index = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
13041314 sym->st_info, 0,
13051315 sym->st_shndx, name);
13061316 s1->symtab_to_dynsym[sym -
1307− (Elf32_Sym *)symtab_section->data] =
1317+ (ElfW(Sym) *)symtab_section->data] =
13081318 index;
13091319 }
13101320 }
@@ -1385,7 +1395,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 74 unmodified lines
13851395 /* when generating a DLL, we include relocations but we may
13861396 patch them */
13871397 if (file_type == TCC_OUTPUT_DLL &&
1388− s->sh_type == SHT_REL &&
1398+ s->sh_type == SHT_RELX &&
13891399 !(s->sh_flags & SHF_ALLOC)) {
13901400 /* //gr: avoid bogus relocs for empty (debug) sections */
13911401 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
14021412 }
14031413
14041414 /* allocate program segment headers */
1405− phdr = tcc_mallocz(phnum * sizeof(Elf32_Phdr));
1415+ phdr = tcc_mallocz(phnum * sizeof(ElfW(Phdr)));
14061416
14071417 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));
14091419 } else {
14101420 file_offset = 0;
14111421 }
@@ -1471,7 +1481,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 59 unmodified lines
14711481 s->sh_type == SHT_HASH) {
14721482 if (k != 1)
14731483 continue;
1474− } else if (s->sh_type == SHT_REL) {
1484+ } else if (s->sh_type == SHT_RELX) {
14751485 if (k != 2)
14761486 continue;
14771487 } else if (s->sh_type == SHT_NOBITS) {
@@ -1498,7 +1508,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 20 unmodified lines
14981508 ph->p_paddr = ph->p_vaddr;
14991509 }
15001510 /* update dynamic relocation infos */
1501− if (s->sh_type == SHT_REL) {
1511+ if (s->sh_type == SHT_RELX) {
15021512 if (rel_size == 0)
15031513 rel_addr = addr;
15041514 rel_size += s->sh_size;
@@ -1541,7 +1551,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 36 unmodified lines
15411551
15421552 /* if dynamic section, then add corresponing program header */
15431553 if (dynamic) {
1544− Elf32_Sym *sym_end;
1554+ ElfW(Sym) *sym_end;
15451555
15461556 ph = &phdr[phnum - 1];
15471557
@@ -1589,8 +1599,8 @@ int elf_output_file(TCCState *s1, const char *filename) · 41 unmodified lines
15891599 }
15901600
15911601 /* 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;
15941604 sym < sym_end;
15951605 sym++) {
15961606 if (sym->st_shndx == SHN_UNDEF) {
@@ -1610,18 +1620,18 @@ int elf_output_file(TCCState *s1, const char *filename) · 13 unmodified lines
16101620 put_dt(dynamic, DT_STRTAB, dynstr->sh_addr);
16111621 put_dt(dynamic, DT_SYMTAB, s1->dynsym->sh_addr);
16121622 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)));
16141624 put_dt(dynamic, DT_REL, rel_addr);
16151625 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));
16171627 if (do_debug)
16181628 put_dt(dynamic, DT_DEBUG, 0);
16191629 put_dt(dynamic, DT_NULL, 0);
16201630 }
16211631
1622− ehdr.e_phentsize = sizeof(Elf32_Phdr);
1632+ ehdr.e_phentsize = sizeof(ElfW(Phdr));
16231633 ehdr.e_phnum = phnum;
1624− ehdr.e_phoff = sizeof(Elf32_Ehdr);
1634+ ehdr.e_phoff = sizeof(ElfW(Ehdr));
16251635 }
16261636
16271637 /* all other sections come after */
@@ -1662,7 +1672,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 34 unmodified lines
16621672 for(i = 1; i < s1->nb_sections; i++) {
16631673 s = s1->sections[i];
16641674 if ((s->sh_flags & SHF_ALLOC) &&
1665− s->sh_type == SHT_REL) {
1675+ s->sh_type == SHT_RELX) {
16661676 relocate_rel(s1, s);
16671677 }
16681678 }
@@ -1733,14 +1743,14 @@ int elf_output_file(TCCState *s1, const char *filename) · 64 unmodified lines
17331743 ehdr.e_machine = EM_TCC_TARGET;
17341744 ehdr.e_version = EV_CURRENT;
17351745 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));
17381748 ehdr.e_shnum = shnum;
17391749 ehdr.e_shstrndx = shnum - 1;
17401750
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));
17441754
17451755 for(i=1;i<s1->nb_sections;i++) {
17461756 s = s1->sections[section_order[i]];
@@ -1763,7 +1773,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 16 unmodified lines
17631773
17641774 for(i=0;i<s1->nb_sections;i++) {
17651775 sh = &shdr;
1766− memset(sh, 0, sizeof(Elf32_Shdr));
1776+ memset(sh, 0, sizeof(ElfW(Shdr)));
17671777 s = s1->sections[i];
17681778 if (s) {
17691779 sh->sh_name = s->sh_name;
@@ -1778,7 +1788,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 8 unmodified lines
17781788 sh->sh_offset = s->sh_offset;
17791789 sh->sh_size = s->sh_size;
17801790 }
1781− fwrite(sh, 1, sizeof(Elf32_Shdr), f);
1791+ fwrite(sh, 1, sizeof(ElfW(Shdr)), f);
17821792 }
17831793 } else {
17841794 tcc_output_binary(s1, f, section_order);
@@ -1830,15 +1840,15 @@ typedef struct SectionMergeInfo { · 45 unmodified lines
18301840 static int tcc_load_object_file(TCCState *s1,
18311841 int fd, unsigned long file_offset)
18321842 {
1833− Elf32_Ehdr ehdr;
1834− Elf32_Shdr *shdr, *sh;
1843+ ElfW(Ehdr) ehdr;
1844+ ElfW(Shdr) *shdr, *sh;
18351845 int size, i, j, offset, offseti, nb_syms, sym_index, ret;
18361846 unsigned char *strsec, *strtab;
18371847 int *old_to_new_syms;
18381848 char *sh_name, *name;
18391849 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;
18421852 Section *s;
18431853
18441854 int stab_index;
@@ -1865,7 +1875,7 @@ static int tcc_load_object_file(TCCState *s1, · 20 unmodified lines
18651875 }
18661876 /* read sections */
18671877 shdr = load_data(fd, file_offset + ehdr.e_shoff,
1868− sizeof(Elf32_Shdr) * ehdr.e_shnum);
1878+ sizeof(ElfW(Shdr)) * ehdr.e_shnum);
18691879 sm_table = tcc_mallocz(sizeof(SectionMergeInfo) * ehdr.e_shnum);
18701880
18711881 /* load section names */
@@ -1886,7 +1896,7 @@ static int tcc_load_object_file(TCCState *s1, · 14 unmodified lines
18861896 ret = -1;
18871897 goto the_end;
18881898 }
1889− nb_syms = sh->sh_size / sizeof(Elf32_Sym);
1899+ nb_syms = sh->sh_size / sizeof(ElfW(Sym));
18901900 symtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
18911901 sm_table[i].s = symtab_section;
18921902
@@ -1906,7 +1916,7 @@ static int tcc_load_object_file(TCCState *s1, · 13 unmodified lines
19061916 sh_name = strsec + sh->sh_name;
19071917 /* ignore sections types we do not handle */
19081918 if (sh->sh_type != SHT_PROGBITS &&
1909− sh->sh_type != SHT_REL &&
1919+ sh->sh_type != SHT_RELX &&
19101920 #ifdef TCC_ARM_EABI
19111921 sh->sh_type != SHT_ARM_EXIDX &&
19121922 #endif
@@ -2000,7 +2010,7 @@ static int tcc_load_object_file(TCCState *s1, · 87 unmodified lines
20002010 sh = &shdr[i];
20012011 if (sh->sh_link > 0)
20022012 s->link = sm_table[sh->sh_link].s;
2003− if (sh->sh_type == SHT_REL) {
2013+ if (sh->sh_type == SHT_RELX) {
20042014 s->sh_info = sm_table[sh->sh_info].s->sh_num;
20052015 /* update backward link */
20062016 s1->sections[s->sh_info]->reloc = s;
@@ -2020,7 +2030,7 @@ static int tcc_load_object_file(TCCState *s1, · 13 unmodified lines
20202030 /* if a symbol is in a link once section, we use the
20212031 already defined symbol. It is very important to get
20222032 correct relocations */
2023− if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL) {
2033+ if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
20242034 name = strtab + sym->st_name;
20252035 sym_index = find_elf_sym(symtab_section, name);
20262036 if (sym_index)
@@ -2052,18 +2062,18 @@ static int tcc_load_object_file(TCCState *s1, · 25 unmodified lines
20522062 sh = &shdr[i];
20532063 offset = sm_table[i].offset;
20542064 switch(s->sh_type) {
2055− case SHT_REL:
2065+ case SHT_RELX:
20562066 /* take relocation offset information */
20572067 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);
20602070 rel < rel_end;
20612071 rel++) {
20622072 int type;
20632073 unsigned sym_index;
20642074 /* 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);
20672077 /* NOTE: only one symtab assumed */
20682078 if (sym_index >= nb_syms)
20692079 goto invalid_reloc;
@@ -2075,7 +2085,7 @@ static int tcc_load_object_file(TCCState *s1, · 5 unmodified lines
20752085 i, strsec + sh->sh_name, rel->r_offset);
20762086 goto fail;
20772087 }
2078− rel->r_info = ELF32_R_INFO(sym_index, type);
2088+ rel->r_info = ELFW(R_INFO)(sym_index, type);
20792089 /* offset the relocation offset */
20802090 rel->r_offset += offseti;
20812091 }
@@ -2120,7 +2130,7 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 38 unmodified lines
21202130 uint8_t *data;
21212131 const char *ar_names, *p;
21222132 const uint8_t *ar_index;
2123− Elf32_Sym *sym;
2133+ ElfW(Sym) *sym;
21242134
21252135 data = tcc_malloc(size);
21262136 if (read(fd, data, size) != size)
@@ -2134,7 +2144,7 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 7 unmodified lines
21342144 for(p = ar_names, i = 0; i < nsyms; i++, p += strlen(p)+1) {
21352145 sym_index = find_elf_sym(symtab_section, p);
21362146 if(sym_index) {
2137− sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
2147+ sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
21382148 if(sym->st_shndx == SHN_UNDEF) {
21392149 off = get_be32(ar_index + i * 4) + sizeof(ArchiveHeader);
21402150 #if 0
@@ -2214,11 +2224,11 @@ static int tcc_load_archive(TCCState *s1, int fd) · 73 unmodified lines
22142224 the generated ELF file) */
22152225 static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
22162226 {
2217− Elf32_Ehdr ehdr;
2218− Elf32_Shdr *shdr, *sh, *sh1;
2227+ ElfW(Ehdr) ehdr;
2228+ ElfW(Shdr) *shdr, *sh, *sh1;
22192229 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;
22222232 unsigned char *dynstr;
22232233 const char *name, *soname;
22242234 DLLReference *dllref;
@@ -2233,7 +2243,7 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 8 unmodified lines
22332243 }
22342244
22352245 /* 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);
22372247
22382248 /* load dynamic section and dynamic symbols */
22392249 nb_syms = 0;
@@ -2244,11 +2254,11 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 4 unmodified lines
22442254 for(i = 0, sh = shdr; i < ehdr.e_shnum; i++, sh++) {
22452255 switch(sh->sh_type) {
22462256 case SHT_DYNAMIC:
2247− nb_dts = sh->sh_size / sizeof(Elf32_Dyn);
2257+ nb_dts = sh->sh_size / sizeof(ElfW(Dyn));
22482258 dynamic = load_data(fd, sh->sh_offset, sh->sh_size);
22492259 break;
22502260 case SHT_DYNSYM:
2251− nb_syms = sh->sh_size / sizeof(Elf32_Sym);
2261+ nb_syms = sh->sh_size / sizeof(ElfW(Sym));
22522262 dynsym = load_data(fd, sh->sh_offset, sh->sh_size);
22532263 sh1 = &shdr[sh->sh_link];
22542264 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
22892299
22902300 /* add dynamic symbols in dynsym_section */
22912301 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);
22932303 if (sym_bind == STB_LOCAL)
22942304 continue;
22952305 name = dynstr + sym->st_name;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t