History

Clean up lots of rogue tabs.

Still some more tabs to be taken care of. arm-gen.c and tcccoff.c have so many style issues that I'm just going to throw clang-format at them.

gus knight committed 11 years ago

Commit d6b64e21 parent 410312210 files · +427 −428Browse files

Unified · Split

10 files
  1. c67-gen.c +19 −19
  2. coff.h +1 −1
  3. libtcc.c +9 −9
  4. tccasm.c +17 −17
  5. tccelf.c +140 −140
  6. tccgen.c +169 −169
  7. tccpe.c +24 −24
  8. tccpp.c +4 −4
  9. tccrun.c +9 −9
  10. x86_64-gen.c +35 −36
c67-gen.c+19−19
@@ -30,13 +30,13 @@ typedef int RegArgs; · 29 unmodified lines
3030 /* a register can belong to several classes. The classes must be
3131 sorted from more general to more precise (see gv2() code which does
3232 assumptions on it). */
33−#define RC_INT 0x0001 /* generic integer register */
34−#define RC_FLOAT 0x0002 /* generic float register */
33+#define RC_INT 0x0001 /* generic integer register */
34+#define RC_FLOAT 0x0002 /* generic float register */
3535 #define RC_EAX 0x0004
3636 #define RC_ST0 0x0008
3737 #define RC_ECX 0x0010
3838 #define RC_EDX 0x0020
39−#define RC_INT_BSIDE 0x00000040 /* generic integer register on b side */
39+#define RC_INT_BSIDE 0x00000040 /* generic integer register on b side */
4040 #define RC_C67_A4 0x00000100
4141 #define RC_C67_A5 0x00000200
4242 #define RC_C67_B4 0x00000400
@@ -204,7 +204,7 @@ void C67_g(int c) · 161 unmodified lines
204204 #endif
205205 ind1 = ind + 4;
206206 if (ind1 > (int) cur_text_section->data_allocated)
207− section_realloc(cur_text_section, ind1);
207+ section_realloc(cur_text_section, ind1);
208208 cur_text_section->data[ind] = c & 0xff;
209209 cur_text_section->data[ind + 1] = (c >> 8) & 0xff;
210210 cur_text_section->data[ind + 2] = (c >> 16) & 0xff;
@@ -218,26 +218,26 @@ void gsym_addr(int t, int a) · 7 unmodified lines
218218 {
219219 int n, *ptr;
220220 while (t) {
221− ptr = (int *) (cur_text_section->data + t);
222− {
223− Sym *sym;
221+ ptr = (int *) (cur_text_section->data + t);
222+ {
223+ Sym *sym;
224224
225− // extract 32 bit address from MVKH/MVKL
226− n = ((*ptr >> 7) & 0xffff);
227− n |= ((*(ptr + 1) >> 7) & 0xffff) << 16;
225+ // extract 32 bit address from MVKH/MVKL
226+ n = ((*ptr >> 7) & 0xffff);
227+ n |= ((*(ptr + 1) >> 7) & 0xffff) << 16;
228228
229− // define a label that will be relocated
229+ // define a label that will be relocated
230230
231− sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0);
232− greloc(cur_text_section, sym, t, R_C60LO16);
233− greloc(cur_text_section, sym, t + 4, R_C60HI16);
231+ sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0);
232+ greloc(cur_text_section, sym, t, R_C60LO16);
233+ greloc(cur_text_section, sym, t + 4, R_C60HI16);
234234
235− // clear out where the pointer was
235+ // clear out where the pointer was
236236
237− *ptr &= ~(0xffff << 7);
238− *(ptr + 1) &= ~(0xffff << 7);
239− }
240− t = n;
237+ *ptr &= ~(0xffff << 7);
238+ *(ptr + 1) &= ~(0xffff << 7);
239+ }
240+ t = n;
241241 }
242242 }
243243
coff.h+1−1
@@ -370,7 +370,7 @@ struct syment · 369 unmodified lines
370370 #define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<<N_TSHIFT_COFF)|(DT_PTR<<N_BTSHFT_COFF)|(x&N_BTMASK_COFF))
371371 #define DECREF_COFF(x) ((((x)>>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF))
372372
373−
373+
374374 /*------------------------------------------------------------------------*/
375375 /* AUXILIARY SYMBOL ENTRY */
376376 /*------------------------------------------------------------------------*/
libtcc.c+9−9
@@ -672,7 +672,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 671 unmodified lines
672672 }
673673 #else
674674 if (! (sym->type.t & VT_STATIC))
675− other = (sym->type.t & VT_VIS_MASK) >> VT_VIS_SHIFT;
675+ other = (sym->type.t & VT_VIS_MASK) >> VT_VIS_SHIFT;
676676 #endif
677677 if (tcc_state->leading_underscore && can_add_underscore) {
678678 buf1[0] = '_';
@@ -2101,11 +2101,11 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 1422 unmodified lines
21012101 s->static_link = 1;
21022102 break;
21032103 case TCC_OPTION_std:
2104− /* silently ignore, a current purpose:
2105− allow to use a tcc as a reference compiler for "make test" */
2104+ /* silently ignore, a current purpose:
2105+ allow to use a tcc as a reference compiler for "make test" */
21062106 break;
21072107 case TCC_OPTION_shared:
2108− if (s->output_type)
2108+ if (s->output_type)
21092109 tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);
21102110 s->output_type = TCC_OUTPUT_DLL;
21112111 break;
@@ -2124,7 +2124,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 12 unmodified lines
21242124 break;
21252125 case TCC_OPTION_r:
21262126 /* generate a .o merging several output files */
2127− if (s->output_type)
2127+ if (s->output_type)
21282128 tcc_warning("-r: some compiler action already specified (%d)", s->output_type);
21292129 s->option_r = 1;
21302130 s->output_type = TCC_OUTPUT_OBJ;
@@ -2163,7 +2163,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 32 unmodified lines
21632163 s->print_search_dirs = 1;
21642164 break;
21652165 case TCC_OPTION_run:
2166− if (s->output_type)
2166+ if (s->output_type)
21672167 tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
21682168 s->output_type = TCC_OUTPUT_MEMORY;
21692169 tcc_set_options(s, optarg);
@@ -2194,7 +2194,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 24 unmodified lines
21942194 cstr_ccat(&linker_arg, '\0');
21952195 break;
21962196 case TCC_OPTION_E:
2197− if (s->output_type)
2197+ if (s->output_type)
21982198 tcc_warning("-E: some compiler action already specified (%d)", s->output_type);
21992199 s->output_type = TCC_OUTPUT_PREPROCESS;
22002200 break;
@@ -2251,13 +2251,13 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 50 unmodified lines
22512251 }
22522252
22532253 if (s->output_type == 0)
2254− s->output_type = TCC_OUTPUT_EXE;
2254+ s->output_type = TCC_OUTPUT_EXE;
22552255
22562256 if (pthread && s->output_type != TCC_OUTPUT_OBJ)
22572257 tcc_set_options(s, "-lpthread");
22582258
22592259 if (s->output_type == TCC_OUTPUT_EXE)
2260− tcc_set_linker(s, (const char *)linker_arg.data);
2260+ tcc_set_linker(s, (const char *)linker_arg.data);
22612261 cstr_free(&linker_arg);
22622262
22632263 return optind;
tccasm.c+17−17
@@ -92,10 +92,10 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe) · 91 unmodified lines
9292 break;
9393 case TOK_CCHAR:
9494 case TOK_LCHAR:
95− pe->v = tokc.i;
96− pe->sym = NULL;
97− next();
98− break;
95+ pe->v = tokc.i;
96+ pe->sym = NULL;
97+ next();
98+ break;
9999 case '(':
100100 next();
101101 asm_expr(s1, pe);
@@ -493,7 +493,7 @@ static void asm_parse_directive(TCCState *s1) · 391 unmodified lines
493493 case TOK_ASM_weak:
494494 case TOK_ASM_hidden:
495495 tok1 = tok;
496− do {
496+ do {
497497 Sym *sym;
498498
499499 next();
@@ -502,15 +502,15 @@ static void asm_parse_directive(TCCState *s1) · 2 unmodified lines
502502 sym = label_push(&s1->asm_labels, tok, 0);
503503 sym->type.t = VT_VOID;
504504 }
505− if (tok1 != TOK_ASM_hidden)
505+ if (tok1 != TOK_ASM_hidden)
506506 sym->type.t &= ~VT_STATIC;
507507 if (tok1 == TOK_ASM_weak)
508508 sym->type.t |= VT_WEAK;
509− else if (tok1 == TOK_ASM_hidden)
510− sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
509+ else if (tok1 == TOK_ASM_hidden)
510+ sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
511511 next();
512− } while (tok == ',');
513− break;
512+ } while (tok == ',');
513+ break;
514514 case TOK_ASM_string:
515515 case TOK_ASM_ascii:
516516 case TOK_ASM_asciz:
@@ -536,24 +536,24 @@ static void asm_parse_directive(TCCState *s1) · 19 unmodified lines
536536 break;
537537 }
538538 }
539− }
540− break;
539+ }
540+ break;
541541 case TOK_ASM_text:
542542 case TOK_ASM_data:
543543 case TOK_ASM_bss:
544− {
544+ {
545545 char sname[64];
546546 tok1 = tok;
547547 n = 0;
548548 next();
549549 if (tok != ';' && tok != TOK_LINEFEED) {
550− n = asm_int_expr(s1);
551− next();
550+ n = asm_int_expr(s1);
551+ next();
552552 }
553553 sprintf(sname, (n?".%s%d":".%s"), get_tok_str(tok1, NULL), n);
554554 use_section(s1, sname);
555− }
556− break;
555+ }
556+ break;
557557 case TOK_ASM_file:
558558 {
559559 char filename[512];
tccelf.c+140−140
@@ -451,7 +451,7 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve) · 450 unmodified lines
451451 if (addr) {
452452 sym->st_value = (addr_t)addr;
453453 #ifdef DEBUG_RELOC
454− printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value);
454+ printf ("relocate_sym: %s -> 0x%lx\n", name, sym->st_value);
455455 #endif
456456 goto found;
457457 }
@@ -580,10 +580,10 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 122 unmodified lines
580580 {
581581 int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko;
582582 x = (*(int *) ptr) & 0xffffff;
583− if (sym->st_shndx == SHN_UNDEF)
584− val = s1->plt->sh_addr;
583+ if (sym->st_shndx == SHN_UNDEF)
584+ val = s1->plt->sh_addr;
585585 #ifdef DEBUG_RELOC
586− printf ("reloc %d: x=0x%x val=0x%x ", type, x, val);
586+ printf ("reloc %d: x=0x%x val=0x%x ", type, x, val);
587587 #endif
588588 (*(int *)ptr) &= 0xff000000;
589589 if (x & 0x800000)
@@ -595,8 +595,8 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 5 unmodified lines
595595 is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl));
596596 x += val - addr;
597597 #ifdef DEBUG_RELOC
598− printf (" newx=0x%x name=%s\n", x,
599− (char *) symtab_section->link->data + sym->st_name);
598+ printf (" newx=0x%x name=%s\n", x,
599+ (char *) symtab_section->link->data + sym->st_name);
600600 #endif
601601 h = x & 2;
602602 th_ko = (x & 3) && (!blx_avail || !is_call);
@@ -797,21 +797,21 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 194 unmodified lines
797797 break;
798798 case R_AARCH64_JUMP26:
799799 case R_AARCH64_CALL26:
800− /* This check must match the one in build_got_entries, testing
801− if we really need a PLT slot. */
802− if (sym->st_shndx == SHN_UNDEF)
803− /* We've put the PLT slot offset into r_addend when generating
804− it, and that's what we must use as relocation value (adjusted
805− by section offset of course). */
806− val = s1->plt->sh_addr + rel->r_addend;
800+ /* This check must match the one in build_got_entries, testing
801+ if we really need a PLT slot. */
802+ if (sym->st_shndx == SHN_UNDEF)
803+ /* We've put the PLT slot offset into r_addend when generating
804+ it, and that's what we must use as relocation value (adjusted
805+ by section offset of course). */
806+ val = s1->plt->sh_addr + rel->r_addend;
807807 #ifdef DEBUG_RELOC
808− printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val,
809− (char *) symtab_section->link->data + sym->st_name);
808+ printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr, val,
809+ (char *) symtab_section->link->data + sym->st_name);
810810 #endif
811811 if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc)
812− {
812+ {
813813 tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed (val=%lx, addr=%lx)", addr, val);
814− }
814+ }
815815 *(uint32_t *)ptr = 0x14000000 | (type == R_AARCH64_CALL26) << 31 |
816816 ((val - addr) >> 2 & 0x3ffffff);
817817 break;
@@ -836,9 +836,9 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 18 unmodified lines
836836 case R_AARCH64_JUMP_SLOT:
837837 /* They don't need addend */
838838 #ifdef DEBUG_RELOC
839− printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr,
840− val - rel->r_addend,
841− (char *) symtab_section->link->data + sym->st_name);
839+ printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr,
840+ val - rel->r_addend,
841+ (char *) symtab_section->link->data + sym->st_name);
842842 #endif
843843 *(addr_t *)ptr = val - rel->r_addend;
844844 break;
@@ -879,12 +879,12 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 34 unmodified lines
879879 qrel->r_offset = rel->r_offset;
880880 if (esym_index) {
881881 qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
882− qrel->r_addend = rel->r_addend;
882+ qrel->r_addend = rel->r_addend;
883883 qrel++;
884884 break;
885885 } else {
886− qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
887− qrel->r_addend = *(long long *)ptr + val;
886+ qrel->r_info = ELFW(R_INFO)(0, R_X86_64_RELATIVE);
887+ qrel->r_addend = *(long long *)ptr + val;
888888 qrel++;
889889 }
890890 }
@@ -917,14 +917,14 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 26 unmodified lines
917917 goto plt32pc32;
918918
919919 case R_X86_64_PLT32:
920− /* We've put the PLT slot offset into r_addend when generating
921− it, and that's what we must use as relocation value (adjusted
922− by section offset of course). */
923− val = s1->plt->sh_addr + rel->r_addend;
924− /* fallthrough. */
925−
926− plt32pc32:
927− {
920+ /* We've put the PLT slot offset into r_addend when generating
921+ it, and that's what we must use as relocation value (adjusted
922+ by section offset of course). */
923+ val = s1->plt->sh_addr + rel->r_addend;
924+ /* fallthrough. */
925+
926+ plt32pc32:
927+ {
928928 long long diff;
929929 diff = (long long)val - addr;
930930 if (diff < -2147483648LL || diff > 2147483647LL) {
@@ -1080,8 +1080,8 @@ static void build_got(TCCState *s1) · 149 unmodified lines
10801080 and 'info' can be modifed if more precise info comes from the DLL.
10811081 Returns offset of GOT or PLT slot. */
10821082 static unsigned long put_got_entry(TCCState *s1,
1083− int reloc_type, unsigned long size, int info,
1084− int sym_index)
1083+ int reloc_type, unsigned long size, int info,
1084+ int sym_index)
10851085 {
10861086 int index, need_plt_entry;
10871087 const char *name;
@@ -1107,18 +1107,18 @@ static unsigned long put_got_entry(TCCState *s1, · 19 unmodified lines
11071107 #endif
11081108
11091109 if (need_plt_entry && !s1->plt) {
1110− /* add PLT */
1111− s1->plt = new_section(s1, ".plt", SHT_PROGBITS,
1112− SHF_ALLOC | SHF_EXECINSTR);
1113− s1->plt->sh_entsize = 4;
1110+ /* add PLT */
1111+ s1->plt = new_section(s1, ".plt", SHT_PROGBITS,
1112+ SHF_ALLOC | SHF_EXECINSTR);
1113+ s1->plt->sh_entsize = 4;
11141114 }
11151115
11161116 /* If a got/plt entry already exists for that symbol, no need to add one */
11171117 if (sym_index < s1->nb_sym_attrs) {
1118− if (need_plt_entry && s1->sym_attrs[sym_index].plt_offset)
1119− return s1->sym_attrs[sym_index].plt_offset;
1120− else if (!need_plt_entry && s1->sym_attrs[sym_index].got_offset)
1121− return s1->sym_attrs[sym_index].got_offset;
1118+ if (need_plt_entry && s1->sym_attrs[sym_index].plt_offset)
1119+ return s1->sym_attrs[sym_index].plt_offset;
1120+ else if (!need_plt_entry && s1->sym_attrs[sym_index].got_offset)
1121+ return s1->sym_attrs[sym_index].got_offset;
11221122 }
11231123
11241124 symattr = alloc_sym_attr(s1, sym_index);
@@ -1135,7 +1135,7 @@ static unsigned long put_got_entry(TCCState *s1, · 10 unmodified lines
11351135 Section *plt;
11361136 uint8_t *p;
11371137 int modrm;
1138− unsigned long relofs;
1138+ unsigned long relofs;
11391139
11401140 #if defined(TCC_OUTPUT_DLL_WITH_PLT)
11411141 modrm = 0x25;
@@ -1160,10 +1160,10 @@ static unsigned long put_got_entry(TCCState *s1, · 18 unmodified lines
11601160 put32(p + 8, PTR_SIZE * 2);
11611161 }
11621162
1163− /* The PLT slot refers to the relocation entry it needs
1164− via offset. The reloc entry is created below, so its
1165− offset is the current data_offset. */
1166− relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0;
1163+ /* The PLT slot refers to the relocation entry it needs
1164+ via offset. The reloc entry is created below, so its
1165+ offset is the current data_offset. */
1166+ relofs = s1->got->reloc ? s1->got->reloc->data_offset : 0;
11671167 symattr->plt_offset = plt->data_offset;
11681168 p = section_ptr_add(plt, 16);
11691169 p[0] = 0xff; /* jmp *(got + x) */
@@ -1171,19 +1171,19 @@ static unsigned long put_got_entry(TCCState *s1, · 1 unmodified line
11711171 put32(p + 2, s1->got->data_offset);
11721172 p[6] = 0x68; /* push $xxx */
11731173 #ifdef TCC_TARGET_X86_64
1174− /* On x86-64, the relocation is referred to by _index_. */
1175− put32(p + 7, relofs / sizeof (ElfW_Rel));
1174+ /* On x86-64, the relocation is referred to by _index_. */
1175+ put32(p + 7, relofs / sizeof (ElfW_Rel));
11761176 #else
11771177 put32(p + 7, relofs);
11781178 #endif
11791179 p[11] = 0xe9; /* jmp plt_start */
11801180 put32(p + 12, -(plt->data_offset));
11811181
1182− /* If this was an UNDEF symbol set the offset in the
1183− dynsymtab to the PLT slot, so that PC32 relocs to it
1184− can be resolved. */
1185− if (sym->st_shndx == SHN_UNDEF)
1186− offset = plt->data_offset - 16;
1182+ /* If this was an UNDEF symbol set the offset in the
1183+ dynsymtab to the PLT slot, so that PC32 relocs to it
1184+ can be resolved. */
1185+ if (sym->st_shndx == SHN_UNDEF)
1186+ offset = plt->data_offset - 16;
11871187 }
11881188 #elif defined(TCC_TARGET_ARM)
11891189 if (need_plt_entry) {
@@ -1220,7 +1220,7 @@ static unsigned long put_got_entry(TCCState *s1, · 30 unmodified lines
12201220
12211221 /* the symbol is modified so that it will be relocated to
12221222 the PLT */
1223− if (sym->st_shndx == SHN_UNDEF)
1223+ if (sym->st_shndx == SHN_UNDEF)
12241224 offset = plt->data_offset - 16;
12251225 }
12261226 #elif defined(TCC_TARGET_ARM64)
@@ -1250,19 +1250,19 @@ static unsigned long put_got_entry(TCCState *s1, · 23 unmodified lines
12501250 #error unsupported CPU
12511251 #endif
12521252 if (s1->dynsym) {
1253− /* XXX This might generate multiple syms for name. */
1253+ /* XXX This might generate multiple syms for name. */
12541254 index = put_elf_sym(s1->dynsym, offset,
12551255 size, info, 0, sym->st_shndx, name);
12561256 /* Create the relocation (it's against the GOT for PLT
1257− and GOT relocs). */
1257+ and GOT relocs). */
12581258 put_elf_reloc(s1->dynsym, s1->got,
12591259 s1->got->data_offset,
12601260 reloc_type, index);
12611261 } else {
1262− /* Without .dynsym (i.e. static link or memory output) we
1263− still need relocs against the generated got, so as to fill
1264− the entries with the symbol values (determined later). */
1265− put_elf_reloc(symtab_section, s1->got,
1262+ /* Without .dynsym (i.e. static link or memory output) we
1263+ still need relocs against the generated got, so as to fill
1264+ the entries with the symbol values (determined later). */
1265+ put_elf_reloc(symtab_section, s1->got,
12661266 s1->got->data_offset,
12671267 reloc_type, sym_index);
12681268 }
@@ -1324,8 +1324,8 @@ ST_FUNC void build_got_entries(TCCState *s1) · 55 unmodified lines
13241324 build_got(s1);
13251325 sym_index = ELFW(R_SYM)(rel->r_info);
13261326 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1327− if (type != R_ARM_GOTOFF && type != R_ARM_GOTPC
1328− && sym->st_shndx == SHN_UNDEF) {
1327+ if (type != R_ARM_GOTOFF && type != R_ARM_GOTPC
1328+ && sym->st_shndx == SHN_UNDEF) {
13291329 unsigned long ofs;
13301330 /* look at the symbol got offset. If none, then add one */
13311331 if (type == R_ARM_GOT32)
@@ -1333,27 +1333,27 @@ ST_FUNC void build_got_entries(TCCState *s1) · 1 unmodified line
13331333 else
13341334 reloc_type = R_ARM_JUMP_SLOT;
13351335 ofs = put_got_entry(s1, reloc_type, sym->st_size,
1336− sym->st_info, sym_index);
1336+ sym->st_info, sym_index);
13371337 #ifdef DEBUG_RELOC
13381338 printf ("maybegot: %s, %d, %d --> ofs=0x%x\n",
1339− (char *) symtab_section->link->data + sym->st_name,
1340− type, sym->st_shndx, ofs);
1339+ (char *) symtab_section->link->data + sym->st_name,
1340+ type, sym->st_shndx, ofs);
13411341 #endif
1342− if (type != R_ARM_GOT32) {
1343− addr_t *ptr = (addr_t*)(s1->sections[s->sh_info]->data
1344− + rel->r_offset);
1345− /* x must be signed! */
1346− int x = *ptr & 0xffffff;
1347− x = (x << 8) >> 8;
1348− x <<= 2;
1349− x += ofs;
1350− x >>= 2;
1342+ if (type != R_ARM_GOT32) {
1343+ addr_t *ptr = (addr_t*)(s1->sections[s->sh_info]->data
1344+ + rel->r_offset);
1345+ /* x must be signed! */
1346+ int x = *ptr & 0xffffff;
1347+ x = (x << 8) >> 8;
1348+ x <<= 2;
1349+ x += ofs;
1350+ x >>= 2;
13511351 #ifdef DEBUG_RELOC
1352− printf ("insn=0x%x --> 0x%x (x==0x%x)\n", *ptr,
1353− (*ptr & 0xff000000) | x, x);
1352+ printf ("insn=0x%x --> 0x%x (x==0x%x)\n", *ptr,
1353+ (*ptr & 0xff000000) | x, x);
13541354 #endif
1355− *ptr = (*ptr & 0xff000000) | x;
1356− }
1355+ *ptr = (*ptr & 0xff000000) | x;
1356+ }
13571357 }
13581358 break;
13591359 case R_ARM_THM_JUMP24:
@@ -1397,22 +1397,22 @@ ST_FUNC void build_got_entries(TCCState *s1) · 37 unmodified lines
13971397 sym_index);
13981398 break;
13991399
1400− case R_AARCH64_JUMP26:
1401− case R_AARCH64_CALL26:
1400+ case R_AARCH64_JUMP26:
1401+ case R_AARCH64_CALL26:
14021402 if (!s1->got)
14031403 build_got(s1);
14041404 sym_index = ELFW(R_SYM)(rel->r_info);
14051405 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
14061406 if (sym->st_shndx == SHN_UNDEF) {
1407− unsigned long ofs;
1408− reloc_type = R_AARCH64_JUMP_SLOT;
1407+ unsigned long ofs;
1408+ reloc_type = R_AARCH64_JUMP_SLOT;
14091409 ofs = put_got_entry(s1, reloc_type, sym->st_size,
1410− sym->st_info, sym_index);
1411− /* We store the place of the generated PLT slot
1412− in our addend. */
1413− rel->r_addend += ofs;
1410+ sym->st_info, sym_index);
1411+ /* We store the place of the generated PLT slot
1412+ in our addend. */
1413+ rel->r_addend += ofs;
14141414 }
1415− break;
1415+ break;
14161416 #elif defined(TCC_TARGET_C67)
14171417 case R_C60_GOT32:
14181418 case R_C60_GOTOFF:
@@ -1439,29 +1439,29 @@ ST_FUNC void build_got_entries(TCCState *s1) · 20 unmodified lines
14391439 case R_X86_64_PLT32:
14401440 sym_index = ELFW(R_SYM)(rel->r_info);
14411441 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1442− if (type == R_X86_64_PLT32 &&
1443− ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT)
1444− {
1445− rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32);
1446− break;
1447− }
1442+ if (type == R_X86_64_PLT32 &&
1443+ ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT)
1444+ {
1445+ rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32);
1446+ break;
1447+ }
14481448
14491449 if (!s1->got)
14501450 build_got(s1);
14511451 if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL ||
14521452 type == R_X86_64_PLT32) {
1453− unsigned long ofs;
1453+ unsigned long ofs;
14541454 /* look at the symbol got offset. If none, then add one */
14551455 if (type == R_X86_64_GOT32 || type == R_X86_64_GOTPCREL)
14561456 reloc_type = R_X86_64_GLOB_DAT;
14571457 else
14581458 reloc_type = R_X86_64_JUMP_SLOT;
14591459 ofs = put_got_entry(s1, reloc_type, sym->st_size,
1460− sym->st_info, sym_index);
1461− if (type == R_X86_64_PLT32)
1462− /* We store the place of the generated PLT slot
1463− in our addend. */
1464− rel->r_addend += ofs;
1460+ sym->st_info, sym_index);
1461+ if (type == R_X86_64_PLT32)
1462+ /* We store the place of the generated PLT slot
1463+ in our addend. */
1464+ rel->r_addend += ofs;
14651465 }
14661466 break;
14671467 #else
@@ -1546,21 +1546,21 @@ static int tcc_add_support(TCCState *s1, const char *filename) · 78 unmodified lines
15461546 snprintf(buf, sizeof(buf), "%s/%s/%s", s1->tcc_lib_path,
15471547 /* an cpu specific path inside tcc_lib_path, mainly for keeping libtcc1.a */
15481548 #ifdef TCC_TARGET_I386
1549− "i386"
1549+ "i386"
15501550 #endif
15511551 #ifdef TCC_TARGET_X86_64
15521552 "x86-64"
15531553 #endif
15541554 #ifdef TCC_TARGET_ARM
1555− "arm"
1555+ "arm"
15561556 #endif
15571557 #ifdef TCC_TARGET_ARM64
1558− "arm64"
1558+ "arm64"
15591559 #endif
15601560 #ifdef TCC_TARGET_C67
1561− "C67"
1561+ "C67"
15621562 #endif
1563− ,filename);
1563+ ,filename);
15641564
15651565 return tcc_add_file(s1, buf, TCC_FILETYPE_BINARY);
15661566 }
@@ -1587,17 +1587,17 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1) · 20 unmodified lines
15871587 when __bound_ptr_add, __bound_new_region,
15881588 __bound_delete_region called */
15891589
1590− int sym_index = find_elf_sym(symtab_section, "__bound_init");
1591− if (sym_index) {
1592− Section *init_section = find_section(s1, ".init");
1593− unsigned char *pinit = section_ptr_add(init_section, 5);
1594− pinit[0] = 0xe8;
1595− put32(pinit + 1, -4);
1596− put_elf_reloc(symtab_section, init_section,
1590+ int sym_index = find_elf_sym(symtab_section, "__bound_init");
1591+ if (sym_index) {
1592+ Section *init_section = find_section(s1, ".init");
1593+ unsigned char *pinit = section_ptr_add(init_section, 5);
1594+ pinit[0] = 0xe8;
1595+ put32(pinit + 1, -4);
1596+ put_elf_reloc(symtab_section, init_section,
15971597 init_section->data_offset - 4, R_386_PC32, sym_index);
1598− }
1599− else
1600− tcc_warning("__bound_init not defined");
1598+ }
1599+ else
1600+ tcc_warning("__bound_init not defined");
16011601 }
16021602 #endif
16031603 }
@@ -1905,11 +1905,11 @@ static void export_global_syms(TCCState *s1) · 301 unmodified lines
19051905 s1->symtab_to_dynsym = tcc_mallocz(sizeof(int) * nb_syms);
19061906 for_each_elem(symtab_section, 1, sym, ElfW(Sym)) {
19071907 if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
1908− name = (char *) symtab_section->link->data + sym->st_name;
1909− dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
1910− sym->st_info, 0, sym->st_shndx, name);
1911− index = sym - (ElfW(Sym) *) symtab_section->data;
1912− s1->symtab_to_dynsym[index] = dynindex;
1908+ name = (char *) symtab_section->link->data + sym->st_name;
1909+ dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
1910+ sym->st_info, 0, sym->st_shndx, name);
1911+ index = sym - (ElfW(Sym) *) symtab_section->data;
1912+ s1->symtab_to_dynsym[index] = dynindex;
19131913 }
19141914 }
19151915 }
@@ -2179,15 +2179,15 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 263 unmodified lines
21792179 file_offset += s->sh_size;
21802180 }
21812181 }
2182− if (j == 0) {
2183− /* Make the first PT_LOAD segment include the program
2184− headers itself (and the ELF header as well), it'll
2185− come out with same memory use but will make various
2186− tools like binutils strip work better. */
2187− ph->p_offset &= ~(ph->p_align - 1);
2188− ph->p_vaddr &= ~(ph->p_align - 1);
2189− ph->p_paddr &= ~(ph->p_align - 1);
2190− }
2182+ if (j == 0) {
2183+ /* Make the first PT_LOAD segment include the program
2184+ headers itself (and the ELF header as well), it'll
2185+ come out with same memory use but will make various
2186+ tools like binutils strip work better. */
2187+ ph->p_offset &= ~(ph->p_align - 1);
2188+ ph->p_vaddr &= ~(ph->p_align - 1);
2189+ ph->p_paddr &= ~(ph->p_align - 1);
2190+ }
21912191 ph->p_filesz = file_offset - ph->p_offset;
21922192 ph->p_memsz = addr - ph->p_vaddr;
21932193 ph++;
@@ -2662,10 +2662,10 @@ static int elf_output_file(TCCState *s1, const char *filename) · 468 unmodified lines
26622662 for_each_elem(s1->dynsym, 1, sym, ElfW(Sym)) {
26632663 if (sym->st_shndx == SHN_UNDEF) {
26642664 /* relocate to PLT if symbol corresponds to a PLT entry,
2665− but not if it's a weak symbol */
2666− if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK)
2667− sym->st_value = 0;
2668− else if (sym->st_value)
2665+ but not if it's a weak symbol */
2666+ if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK)
2667+ sym->st_value = 0;
2668+ else if (sym->st_value)
26692669 sym->st_value += s1->plt->sh_addr;
26702670 } else if (sym->st_shndx < SHN_LORESERVE) {
26712671 /* do symbol relocation */
@@ -2690,14 +2690,14 @@ static int elf_output_file(TCCState *s1, const char *filename) · 18 unmodified lines
26902690 /* Create the ELF file with name 'filename' */
26912691 ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order);
26922692 if (s1->do_strip) {
2693− int rc;
2694− const char *strip_cmd = "sstrip "; // super strip utility from ELFkickers
2695− const char *null_dev = " 2> /dev/null";
2696− char buf[1050];
2697− snprintf(buf, sizeof(buf), "%s%s%s", strip_cmd, filename, null_dev);
2698− rc = system(buf);
2699− if (rc)
2700− system(buf+1); // call a strip utility from binutils
2693+ int rc;
2694+ const char *strip_cmd = "sstrip "; // super strip utility from ELFkickers
2695+ const char *null_dev = " 2> /dev/null";
2696+ char buf[1050];
2697+ snprintf(buf, sizeof(buf), "%s%s%s", strip_cmd, filename, null_dev);
2698+ rc = system(buf);
2699+ if (rc)
2700+ system(buf+1); // call a strip utility from binutils
27012701 }
27022702 the_end:
27032703 tcc_free(s1->symtab_to_dynsym);
tccgen.c+169−169
@@ -323,7 +323,7 @@ static void apply_visibility(Sym *sym, CType *type) · 322 unmodified lines
323323 ElfW(Sym) *esym;
324324
325325 esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
326− vis >>= VT_VIS_SHIFT;
326+ vis >>= VT_VIS_SHIFT;
327327 esym->st_other = (esym->st_other & ~ELFW(ST_VISIBILITY)(-1)) | vis;
328328 }
329329 }
@@ -1631,7 +1631,7 @@ static inline int is_null_pointer(SValue *p) · 1301 unmodified lines
16311631 return 0;
16321632 return ((p->type.t & VT_BTYPE) == VT_INT && p->c.i == 0) ||
16331633 ((p->type.t & VT_BTYPE) == VT_LLONG && p->c.ll == 0) ||
1634− ((p->type.t & VT_BTYPE) == VT_PTR && p->c.ptr_offset == 0);
1634+ ((p->type.t & VT_BTYPE) == VT_PTR && p->c.ptr_offset == 0);
16351635 }
16361636
16371637 static inline int is_integer_btype(int bt)
@@ -1761,18 +1761,18 @@ ST_FUNC void gen_op(int op) · 123 unmodified lines
17611761 #if 0
17621762 /* #ifdef CONFIG_TCC_BCHECK
17631763 The main reason to removing this code:
1764− #include <stdio.h>
1765− int main ()
1766− {
1767− int v[10];
1768− int i = 10;
1769− int j = 9;
1770− fprintf(stderr, "v+i-j = %p\n", v+i-j);
1771− fprintf(stderr, "v+(i-j) = %p\n", v+(i-j));
1772− }
1764+ #include <stdio.h>
1765+ int main ()
1766+ {
1767+ int v[10];
1768+ int i = 10;
1769+ int j = 9;
1770+ fprintf(stderr, "v+i-j = %p\n", v+i-j);
1771+ fprintf(stderr, "v+(i-j) = %p\n", v+(i-j));
1772+ }
17731773 When this code is on. then the output looks like
1774− v+i-j = 0xfffffffe
1775− v+(i-j) = 0xbff84000
1774+ v+i-j = 0xfffffffe
1775+ v+(i-j) = 0xbff84000
17761776 */
17771777 /* if evaluating constant expression, no code should be
17781778 generated, so no bound check */
@@ -2450,18 +2450,18 @@ static void gen_assign_cast(CType *dt) · 671 unmodified lines
24502450 dbt = dt->t & VT_BTYPE;
24512451 sbt = st->t & VT_BTYPE;
24522452 if (sbt == VT_VOID || dbt == VT_VOID) {
2453− if (sbt == VT_VOID && dbt == VT_VOID)
2454− ; /*
2455− It is Ok if both are void
2456− A test program:
2457− void func1() {}
2458− void func2() {
2459− return func1();
2460− }
2461− gcc accepts this program
2462− */
2463− else
2464− tcc_error("cannot cast from/to void");
2453+ if (sbt == VT_VOID && dbt == VT_VOID)
2454+ ; /*
2455+ It is Ok if both are void
2456+ A test program:
2457+ void func1() {}
2458+ void func2() {
2459+ return func1();
2460+ }
2461+ gcc accepts this program
2462+ */
2463+ else
2464+ tcc_error("cannot cast from/to void");
24652465 }
24662466 if (dt->t & VT_CONSTANT)
24672467 tcc_warning("assignment of read-only location");
@@ -2542,7 +2542,7 @@ ST_FUNC void vstore(void) · 74 unmodified lines
25422542 dbt = ft & VT_BTYPE;
25432543 if ((((sbt == VT_INT || sbt == VT_SHORT) && dbt == VT_BYTE) ||
25442544 (sbt == VT_INT && dbt == VT_SHORT))
2545− && !(vtop->type.t & VT_BITFIELD)) {
2545+ && !(vtop->type.t & VT_BITFIELD)) {
25462546 /* optimize char/short casts */
25472547 delayed_cast = VT_MUSTCAST;
25482548 vtop->type.t = ft & (VT_TYPE & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT)));
@@ -2764,20 +2764,20 @@ static void parse_attribute(AttributeDef *ad) · 215 unmodified lines
27642764 next();
27652765 skip(')');
27662766 break;
2767− case TOK_VISIBILITY1:
2768− case TOK_VISIBILITY2:
2767+ case TOK_VISIBILITY1:
2768+ case TOK_VISIBILITY2:
27692769 skip('(');
27702770 if (tok != TOK_STR)
27712771 expect("visibility(\"default|hidden|internal|protected\")");
2772− if (!strcmp (tokc.cstr->data, "default"))
2773− ad->a.visibility = STV_DEFAULT;
2774− else if (!strcmp (tokc.cstr->data, "hidden"))
2775− ad->a.visibility = STV_HIDDEN;
2776− else if (!strcmp (tokc.cstr->data, "internal"))
2777− ad->a.visibility = STV_INTERNAL;
2778− else if (!strcmp (tokc.cstr->data, "protected"))
2779− ad->a.visibility = STV_PROTECTED;
2780− else
2772+ if (!strcmp (tokc.cstr->data, "default"))
2773+ ad->a.visibility = STV_DEFAULT;
2774+ else if (!strcmp (tokc.cstr->data, "hidden"))
2775+ ad->a.visibility = STV_HIDDEN;
2776+ else if (!strcmp (tokc.cstr->data, "internal"))
2777+ ad->a.visibility = STV_INTERNAL;
2778+ else if (!strcmp (tokc.cstr->data, "protected"))
2779+ ad->a.visibility = STV_PROTECTED;
2780+ else
27812781 expect("visibility(\"default|hidden|internal|protected\")");
27822782 next();
27832783 skip(')');
@@ -2973,8 +2973,8 @@ static void struct_decl(CType *type, int u, int tdef) · 189 unmodified lines
29732973 while (tok != '}') {
29742974 parse_btype(&btype, &ad);
29752975 while (1) {
2976− if (flexible)
2977− tcc_error("flexible array member '%s' not at the end of struct",
2976+ if (flexible)
2977+ tcc_error("flexible array member '%s' not at the end of struct",
29782978 get_tok_str(v, NULL));
29792979 bit_size = -1;
29802980 v = 0;
@@ -2982,21 +2982,21 @@ static void struct_decl(CType *type, int u, int tdef) · 1 unmodified line
29822982 if (tok != ':') {
29832983 type_decl(&type1, &ad, &v, TYPE_DIRECT | TYPE_ABSTRACT);
29842984 if (v == 0) {
2985− if ((type1.t & VT_BTYPE) != VT_STRUCT)
2986− expect("identifier");
2987− else {
2988− int v = btype.ref->v;
2989− if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
2990− if (tcc_state->ms_extensions == 0)
2991− expect("identifier");
2992− }
2993− }
2985+ if ((type1.t & VT_BTYPE) != VT_STRUCT)
2986+ expect("identifier");
2987+ else {
2988+ int v = btype.ref->v;
2989+ if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
2990+ if (tcc_state->ms_extensions == 0)
2991+ expect("identifier");
2992+ }
2993+ }
29942994 }
29952995 if (type_size(&type1, &align) < 0) {
2996− if ((a == TOK_STRUCT) && (type1.t & VT_ARRAY) && c)
2997− flexible = 1;
2998− else
2999− tcc_error("field '%s' has incomplete type",
2996+ if ((a == TOK_STRUCT) && (type1.t & VT_ARRAY) && c)
2997+ flexible = 1;
2998+ else
2999+ tcc_error("field '%s' has incomplete type",
30003000 get_tok_str(v, NULL));
30013001 }
30023002 if ((type1.t & VT_BTYPE) == VT_FUNC ||
@@ -3807,11 +3807,11 @@ ST_FUNC void unary(void) · 804 unmodified lines
38073807 gen_cast(&type);
38083808 }
38093809 } else if (tok == '{') {
3810− /*
3810+ /*
38113811 if (nocode_wanted)
38123812 tcc_error("statement expression in global scope"); */
3813− /* this check breaks compilation of the linux 2.4.26 with the meesage:
3814− linux/include/net/tcp.h:945: error: statement expression in global scope */
3813+ /* this check breaks compilation of the linux 2.4.26 with the meesage:
3814+ linux/include/net/tcp.h:945: error: statement expression in global scope */
38153815
38163816 /* save all registers */
38173817 save_regs(0);
@@ -3872,12 +3872,12 @@ ST_FUNC void unary(void) · 54 unmodified lines
38723872 if ((vtop->type.t & VT_BTYPE) == VT_PTR)
38733873 tcc_error("pointer not accepted for unary plus");
38743874 /* In order to force cast, we add zero, except for floating point
3875− where we really need an noop (otherwise -0.0 will be transformed
3876− into +0.0). */
3877− if (!is_float(vtop->type.t)) {
3878− vpushi(0);
3879− gen_op('+');
3880− }
3875+ where we really need an noop (otherwise -0.0 will be transformed
3876+ into +0.0). */
3877+ if (!is_float(vtop->type.t)) {
3878+ vpushi(0);
3879+ gen_op('+');
3880+ }
38813881 break;
38823882 case TOK_SIZEOF:
38833883 case TOK_ALIGNOF1:
@@ -4050,20 +4050,20 @@ ST_FUNC void unary(void) · 166 unmodified lines
40504050 next();
40514051 unary();
40524052 t = vtop->type.t & VT_BTYPE;
4053− if (is_float(t)) {
4053+ if (is_float(t)) {
40544054 /* In IEEE negate(x) isn't subtract(0,x), but rather
4055− subtract(-0, x). */
4056− vpush(&vtop->type);
4057− if (t == VT_FLOAT)
4058− vtop->c.f = -0.0f;
4059− else if (t == VT_DOUBLE)
4060− vtop->c.d = -0.0;
4061− else
4062− vtop->c.ld = -0.0;
4063− } else
4064− vpushi(0);
4065− vswap();
4066− gen_op('-');
4055+ subtract(-0, x). */
4056+ vpush(&vtop->type);
4057+ if (t == VT_FLOAT)
4058+ vtop->c.f = -0.0f;
4059+ else if (t == VT_DOUBLE)
4060+ vtop->c.d = -0.0;
4061+ else
4062+ vtop->c.ld = -0.0;
4063+ } else
4064+ vpushi(0);
4065+ vswap();
4066+ gen_op('-');
40674067 break;
40684068 case TOK_LAND:
40694069 if (!gnu_ext)
@@ -4142,7 +4142,7 @@ ST_FUNC void unary(void) · 72 unmodified lines
41424142 /* if forward reference, we must point to s */
41434143 if (vtop->r & VT_SYM) {
41444144 vtop->sym = s;
4145− vtop->c.ptr_offset = 0;
4145+ vtop->c.ptr_offset = 0;
41464146 }
41474147 break;
41484148 }
@@ -4312,10 +4312,10 @@ ST_FUNC void unary(void) · 163 unmodified lines
43124312
43134313
43144314 size = type_size(&s->type, &align);
4315− /* We're writing whole regs often, make sure there's enough
4316− space. Assume register size is power of 2. */
4317− if (regsize > align)
4318− align = regsize;
4315+ /* We're writing whole regs often, make sure there's enough
4316+ space. Assume register size is power of 2. */
4317+ if (regsize > align)
4318+ align = regsize;
43194319 loc = (loc - size) & -align;
43204320 addr = loc;
43214321 #if defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_PE)
@@ -4610,16 +4610,16 @@ static void expr_cond(void) · 288 unmodified lines
46104610 (t2 & (VT_BTYPE | VT_UNSIGNED)) == (VT_LLONG | VT_UNSIGNED))
46114611 type.t |= VT_UNSIGNED;
46124612 } else if (bt1 == VT_PTR || bt2 == VT_PTR) {
4613− /* If one is a null ptr constant the result type
4614− is the other. */
4615− if (is_null_pointer (vtop))
4616− type = type1;
4617− else if (is_null_pointer (&sv))
4618− type = type2;
4613+ /* If one is a null ptr constant the result type
4614+ is the other. */
4615+ if (is_null_pointer (vtop))
4616+ type = type1;
4617+ else if (is_null_pointer (&sv))
4618+ type = type2;
46194619 /* XXX: test pointer compatibility, C99 has more elaborate
4620− rules here. */
4621− else
4622− type = type1;
4620+ rules here. */
4621+ else
4622+ type = type1;
46234623 } else if (bt1 == VT_FUNC || bt2 == VT_FUNC) {
46244624 /* XXX: test function pointer compatibility */
46254625 type = bt1 == VT_FUNC ? type1 : type2;
@@ -4785,14 +4785,14 @@ static void label_or_decl(int l) · 159 unmodified lines
47854785 /* fast test first */
47864786 if (tok >= TOK_UIDENT)
47874787 {
4788− /* no need to save tokc because tok is an identifier */
4789− last_tok = tok;
4790− next();
4791− if (tok == ':') {
4792− unget_tok(last_tok);
4793− return;
4794− }
4795− unget_tok(last_tok);
4788+ /* no need to save tokc because tok is an identifier */
4789+ last_tok = tok;
4790+ next();
4791+ if (tok == ':') {
4792+ unget_tok(last_tok);
4793+ return;
4794+ }
4795+ unget_tok(last_tok);
47964796 }
47974797 decl(l);
47984798 }
@@ -4891,10 +4891,10 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 92 unmodified lines
48914891 Sym *p;
48924892 switch(vtop->type.t & VT_BTYPE) {
48934893 /* case VT_PTR: */
4894− /* this breaks a compilation of the linux kernel v2.4.26 */
4895− /* pmd_t *new = ({ __asm__ __volatile__("ud2\n") ; ((pmd_t *)1); }); */
4896− /* Look a commit a80acab: Display error on statement expressions with complex return type */
4897− /* A pointer is not a complex return type */
4894+ /* this breaks a compilation of the linux kernel v2.4.26 */
4895+ /* pmd_t *new = ({ __asm__ __volatile__("ud2\n") ; ((pmd_t *)1); }); */
4896+ /* Look a commit a80acab: Display error on statement expressions with complex return type */
4897+ /* A pointer is not a complex return type */
48984898 case VT_STRUCT:
48994899 case VT_ENUM:
49004900 case VT_FUNC:
@@ -5642,38 +5642,38 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 741 unmodified lines
56425642 AttributeDef ad1;
56435643 CType type1;
56445644 next();
5645− if (tcc_state->old_struct_init_code) {
5646− /* an old version of struct initialization.
5647− It have a problems. But with a new version
5648− linux 2.4.26 can't load ramdisk.
5649− */
5650− while (tok == '(') {
5651− par_count++;
5652− next();
5653− }
5654− if (!parse_btype(&type1, &ad1))
5655− expect("cast");
5656− type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5657− #if 0
5658− if (!is_assignable_types(type, &type1))
5659− tcc_error("invalid type for cast");
5660− #endif
5661− skip(')');
5662− }
5663− else
5664− {
5645+ if (tcc_state->old_struct_init_code) {
5646+ /* an old version of struct initialization.
5647+ It have a problems. But with a new version
5648+ linux 2.4.26 can't load ramdisk.
5649+ */
5650+ while (tok == '(') {
5651+ par_count++;
5652+ next();
5653+ }
5654+ if (!parse_btype(&type1, &ad1))
5655+ expect("cast");
5656+ type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5657+ #if 0
5658+ if (!is_assignable_types(type, &type1))
5659+ tcc_error("invalid type for cast");
5660+ #endif
5661+ skip(')');
5662+ }
5663+ else
5664+ {
56655665 if (tok != '(') {
5666− if (!parse_btype(&type1, &ad1))
5667− expect("cast");
5668− type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5669− #if 0
5670− if (!is_assignable_types(type, &type1))
5671− tcc_error("invalid type for cast");
5672− #endif
5673− skip(')');
5674− } else
5675− unget_tok(tok);
5676− }
5666+ if (!parse_btype(&type1, &ad1))
5667+ expect("cast");
5668+ type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
5669+ #if 0
5670+ if (!is_assignable_types(type, &type1))
5671+ tcc_error("invalid type for cast");
5672+ #endif
5673+ skip(')');
5674+ } else
5675+ unget_tok(tok);
5676+ }
56775677 }
56785678
56795679 no_oblock = 1;
@@ -5699,28 +5699,28 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 19 unmodified lines
56995699
57005700 /* gr: skip fields from same union - ugly. */
57015701 while (f->next) {
5702− int align = 0;
5703− int f_size = type_size(&f->type, &align);
5704− int f_type = (f->type.t & VT_BTYPE);
5702+ int align = 0;
5703+ int f_size = type_size(&f->type, &align);
5704+ int f_type = (f->type.t & VT_BTYPE);
57055705
57065706 ///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t);
57075707 /* test for same offset */
57085708 if (f->next->c != f->c)
57095709 break;
57105710 if ((f_type == VT_STRUCT) && (f_size == 0)) {
5711− /*
5712− Lets assume a structure of size 0 can't be a member of the union.
5713− This allow to compile the following code from a linux kernel v2.4.26
5714− typedef struct { } rwlock_t;
5715− struct fs_struct {
5716− int count;
5717− rwlock_t lock;
5718− int umask;
5719− };
5720− struct fs_struct init_fs = { { (1) }, (rwlock_t) {}, 0022, };
5721− tcc-0.9.23 can succesfully compile this version of the kernel.
5722− gcc don't have problems with this code too.
5723− */
5711+ /*
5712+ Lets assume a structure of size 0 can't be a member of the union.
5713+ This allow to compile the following code from a linux kernel v2.4.26
5714+ typedef struct { } rwlock_t;
5715+ struct fs_struct {
5716+ int count;
5717+ rwlock_t lock;
5718+ int umask;
5719+ };
5720+ struct fs_struct init_fs = { { (1) }, (rwlock_t) {}, 0022, };
5721+ tcc-0.9.23 can succesfully compile this version of the kernel.
5722+ gcc don't have problems with this code too.
5723+ */
57245724 break;
57255725 }
57265726 /* if yes, test for bitfield shift */
@@ -5760,21 +5760,21 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 33 unmodified lines
57605760 /* just skip expression */
57615761 parlevel = parlevel1 = 0;
57625762 while ((parlevel > 0 || parlevel1 > 0 ||
5763− (tok != '}' && tok != ',')) && tok != -1) {
5763+ (tok != '}' && tok != ',')) && tok != -1) {
57645764 if (tok == '(')
57655765 parlevel++;
57665766 else if (tok == ')') {
5767− if (parlevel == 0 && parlevel1 == 0)
5768− break;
5767+ if (parlevel == 0 && parlevel1 == 0)
5768+ break;
57695769 parlevel--;
57705770 }
5771− else if (tok == '{')
5772− parlevel1++;
5773− else if (tok == '}') {
5774− if (parlevel == 0 && parlevel1 == 0)
5775− break;
5776− parlevel1--;
5777− }
5771+ else if (tok == '{')
5772+ parlevel1++;
5773+ else if (tok == '}') {
5774+ if (parlevel == 0 && parlevel1 == 0)
5775+ break;
5776+ parlevel1--;
5777+ }
57785778 next();
57795779 }
57805780 } else {
@@ -5995,12 +5995,12 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 214 unmodified lines
59955995 } else {
59965996 /* push global reference */
59975997 sym = get_sym_ref(type, sec, addr, size);
5998− vpushsym(type, sym);
5998+ vpushsym(type, sym);
59995999 }
60006000 /* patch symbol weakness */
60016001 if (type->t & VT_WEAK)
60026002 weaken_symbol(sym);
6003− apply_visibility(sym, type);
6003+ apply_visibility(sym, type);
60046004 #ifdef CONFIG_TCC_BCHECK
60056005 /* handles bounds now because the symbol must be defined
60066006 before for the relocation */
@@ -6236,11 +6236,11 @@ static int decl0(int l, int is_for_loop_init) · 229 unmodified lines
62366236 if (((btype.t & VT_BTYPE) == VT_ENUM ||
62376237 (btype.t & VT_BTYPE) == VT_STRUCT) &&
62386238 tok == ';') {
6239− if ((btype.t & VT_BTYPE) == VT_STRUCT) {
6240− int v = btype.ref->v;
6241− if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) >= SYM_FIRST_ANOM)
6242− tcc_warning("unnamed struct/union that defines no instances");
6243− }
6239+ if ((btype.t & VT_BTYPE) == VT_STRUCT) {
6240+ int v = btype.ref->v;
6241+ if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) >= SYM_FIRST_ANOM)
6242+ tcc_warning("unnamed struct/union that defines no instances");
6243+ }
62446244 next();
62456245 continue;
62466246 }
@@ -6286,7 +6286,7 @@ static int decl0(int l, int is_for_loop_init) · 39 unmodified lines
62866286 if (ad.a.func_export)
62876287 type.t |= VT_EXPORT;
62886288 #endif
6289− type.t |= ad.a.visibility << VT_VIS_SHIFT;
6289+ type.t |= ad.a.visibility << VT_VIS_SHIFT;
62906290
62916291 if (tok == '{') {
62926292 if (l == VT_LOCAL)
@@ -6327,10 +6327,10 @@ static int decl0(int l, int is_for_loop_init) · 34 unmodified lines
63276327 if (sym->type.t & VT_STATIC)
63286328 type.t = (type.t & ~VT_EXTERN) | VT_STATIC;
63296329
6330− /* If the definition has no visibility use the
6331− one from prototype. */
6332− if (! (type.t & VT_VIS_MASK))
6333− type.t |= sym->type.t & VT_VIS_MASK;
6330+ /* If the definition has no visibility use the
6331+ one from prototype. */
6332+ if (! (type.t & VT_VIS_MASK))
6333+ type.t |= sym->type.t & VT_VIS_MASK;
63346334
63356335 if (!is_compatible_types(&sym->type, &type)) {
63366336 func_error1:
tccpe.c+24−24
@@ -398,22 +398,22 @@ static int pe_find_import(TCCState * s1, ElfW(Sym) *sym) · 397 unmodified lines
398398 s = pe_export_name(s1, sym);
399399 if (n) {
400400 /* second try: */
401− if (sym->st_other & ST_PE_STDCALL) {
401+ if (sym->st_other & ST_PE_STDCALL) {
402402 /* try w/0 stdcall deco (windows API convention) */
403− p = strrchr(s, '@');
404− if (!p || s[0] != '_')
405− break;
406− strcpy(buffer, s+1)[p-s-1] = 0;
407− } else if (s[0] != '_') { /* try non-ansi function */
408− buffer[0] = '_', strcpy(buffer + 1, s);
409− } else if (0 == memcmp(s, "__imp__", 7)) { /* mingw 2.0 */
410− strcpy(buffer, s + 6);
411− } else if (0 == memcmp(s, "_imp___", 7)) { /* mingw 3.7 */
412− strcpy(buffer, s + 6);
413− } else {
414− break;
415− }
416− s = buffer;
403+ p = strrchr(s, '@');
404+ if (!p || s[0] != '_')
405+ break;
406+ strcpy(buffer, s+1)[p-s-1] = 0;
407+ } else if (s[0] != '_') { /* try non-ansi function */
408+ buffer[0] = '_', strcpy(buffer + 1, s);
409+ } else if (0 == memcmp(s, "__imp__", 7)) { /* mingw 2.0 */
410+ strcpy(buffer, s + 6);
411+ } else if (0 == memcmp(s, "_imp___", 7)) { /* mingw 3.7 */
412+ strcpy(buffer, s + 6);
413+ } else {
414+ break;
415+ }
416+ s = buffer;
417417 }
418418 sym_index = find_elf_sym(s1->dynsymtab_section, s);
419419 // printf("find (%d) %d %s\n", n, sym_index, s);
@@ -565,9 +565,9 @@ static int pe_write(struct pe_info *pe) · 145 unmodified lines
565565 #endif
566566 /* NT additional fields. */
567567 #if defined(TCC_TARGET_ARM)
568− 0x00100000, /*DWORD ImageBase; */
568+ 0x00100000, /*DWORD ImageBase; */
569569 #else
570− 0x00400000, /*DWORD ImageBase; */
570+ 0x00400000, /*DWORD ImageBase; */
571571 #endif
572572 0x00001000, /*DWORD SectionAlignment; */
573573 0x00000200, /*DWORD FileAlignment; */
@@ -1841,13 +1841,13 @@ ST_FUNC int pe_output_file(TCCState * s1, const char *filename) · 1267 unmodified lines
18411841 pe.subsystem = s1->pe_subsystem;
18421842
18431843 /* set default file/section alignment */
1844− if (pe.subsystem == 1) {
1845− pe.section_align = 0x20;
1846− pe.file_align = 0x20;
1847− } else {
1848− pe.section_align = 0x1000;
1849− pe.file_align = 0x200;
1850− }
1844+ if (pe.subsystem == 1) {
1845+ pe.section_align = 0x20;
1846+ pe.file_align = 0x20;
1847+ } else {
1848+ pe.section_align = 0x1000;
1849+ pe.file_align = 0x200;
1850+ }
18511851
18521852 if (s1->section_align != 0)
18531853 pe.section_align = s1->section_align;
tccpp.c+4−4
@@ -786,7 +786,7 @@ redo_start: · 785 unmodified lines
786786 else if (tok == TOK_LINEFEED)
787787 goto redo_start;
788788 } else if (parse_flags & PARSE_FLAG_ASM_FILE)
789− p = parse_line_comment(p);
789+ p = parse_line_comment(p);
790790 break;
791791 _default:
792792 default:
@@ -1786,7 +1786,7 @@ _line_num: · 993 unmodified lines
17861786 total_lines += file->line_num - n;
17871787 file->line_num = n;
17881788 if (s1->do_debug)
1789− put_stabs(file->filename, N_BINCL, 0, 0, 0);
1789+ put_stabs(file->filename, N_BINCL, 0, 0, 0);
17901790 break;
17911791 case TOK_ERROR:
17921792 case TOK_WARNING:
@@ -2272,7 +2272,7 @@ static void parse_number(const char *p) · 479 unmodified lines
22722272 if (n & 0xffffffff00000000LL || must_64bit) {
22732273 tok = TOK_CLLONG;
22742274 n1 = n >> 32;
2275− } else {
2275+ } else {
22762276 tok = TOK_CINT;
22772277 n1 = n;
22782278 }
@@ -2538,7 +2538,7 @@ maybe_newline: · 259 unmodified lines
25382538 } else if (c == '.') {
25392539 PEEKC(c, p);
25402540 if (c != '.')
2541− expect("'.'");
2541+ expect("'.'");
25422542 PEEKC(c, p);
25432543 tok = TOK_DOTS;
25442544 } else {
tccrun.c+9−9
@@ -127,7 +127,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 126 unmodified lines
127127 for (i=0; i<argc; ++i)
128128 bound_new_region(argv[i], strlen(argv[i]));
129129
130− errno = 0; /* clean errno value */
130+ errno = 0; /* clean errno value */
131131 ret = (*prog_main)(argc, argv);
132132
133133 /* unmark argv area */
@@ -139,7 +139,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 5 unmodified lines
139139 } else
140140 #endif
141141 {
142− errno = 0; /* clean errno value */
142+ errno = 0; /* clean errno value */
143143 ret = (*prog_main)(argc, argv);
144144 }
145145 return ret;
@@ -652,7 +652,7 @@ static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info) · 506 unmodified lines
652652 if (rt_bound_error_msg && *rt_bound_error_msg)
653653 rt_error(uc, *rt_bound_error_msg);
654654 else
655− rt_error(uc, "access violation");
655+ rt_error(uc, "access violation");
656656 break;
657657 case EXCEPTION_STACK_OVERFLOW:
658658 rt_error(uc, "stack overflow");
@@ -697,12 +697,12 @@ static int rt_get_caller_pc(addr_t *paddr, CONTEXT *uc, int level) · 38 unmodified lines
697697 fp = uc->Ebp;
698698 #endif
699699 if (level > 0) {
700− for(i=1;i<level;i++) {
701− /* XXX: check address validity with program info */
702− if (fp <= 0x1000 || fp >= 0xc0000000)
703− return -1;
704− fp = ((addr_t*)fp)[0];
705− }
700+ for(i = 1; i < level; i++) {
701+ /* XXX: check address validity with program info */
702+ if (fp <= 0x1000 || fp >= 0xc0000000)
703+ return -1;
704+ fp = ((addr_t*)fp)[0];
705+ }
706706 pc = ((addr_t*)fp)[1];
707707 }
708708 *paddr = pc;
x86_64-gen.c+35−36
@@ -477,18 +477,17 @@ void load(int r, SValue *sv) · 476 unmodified lines
477477 gen_modrm(r, VT_LOCAL, sv->sym, fc);
478478 } else if (v == VT_CMP) {
479479 orex(0,r,0,0);
480− if ((fc & ~0x100) != TOK_NE)
481− oad(0xb8 + REG_VALUE(r), 0); /* mov $0, r */
482− else
483− oad(0xb8 + REG_VALUE(r), 1); /* mov $1, r */
484− if (fc & 0x100)
485− {
486− /* This was a float compare. If the parity bit is
487− set the result was unordered, meaning false for everything
488− except TOK_NE, and true for TOK_NE. */
489− fc &= ~0x100;
490− o(0x037a + (REX_BASE(r) << 8));
491− }
480+ if ((fc & ~0x100) != TOK_NE)
481+ oad(0xb8 + REG_VALUE(r), 0); /* mov $0, r */
482+ else
483+ oad(0xb8 + REG_VALUE(r), 1); /* mov $1, r */
484+ if (fc & 0x100) {
485+ /* This was a float compare. If the parity bit is
486+ * set the result was unordered, meaning false for everything
487+ * except TOK_NE, and true for TOK_NE. */
488+ fc &= ~0x100;
489+ o(0x037a + (REX_BASE(r) << 8));
490+ }
492491 orex(0,r,0, 0x0f); /* setxx %br */
493492 o(fc);
494493 o(0xc0 + REG_VALUE(r));
@@ -619,7 +618,7 @@ static void gcall_or_jmp(int is_jmp) · 124 unmodified lines
619618 {
620619 int r;
621620 if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
622− ((vtop->r & VT_SYM) || (vtop->c.ll-4) == (int)(vtop->c.ll-4))) {
621+ ((vtop->r & VT_SYM) || (vtop->c.ll-4) == (int)(vtop->c.ll-4))) {
623622 /* constant case */
624623 if (vtop->r & VT_SYM) {
625624 /* relocation case */
@@ -1705,7 +1704,7 @@ void gfunc_prolog(CType *func_type) · 1079 unmodified lines
17051704 param_addr = addr;
17061705 addr += size;
17071706 break;
1708− default: break; /* nothing to be done for x86_64_mode_none */
1707+ default: break; /* nothing to be done for x86_64_mode_none */
17091708 }
17101709 sym_push(sym->v & ~SYM_FIELD, type,
17111710 VT_LOCAL | VT_LVAL, param_addr);
@@ -1717,8 +1716,8 @@ void gfunc_prolog(CType *func_type) · 5 unmodified lines
17171716 func_bound_offset = lbounds_section->data_offset;
17181717 func_bound_ind = ind;
17191718 oad(0xb8, 0); /* lbound section pointer */
1720− o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */
1721− oad(0xb8, 0); /* call to function */
1719+ o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */
1720+ oad(0xb8, 0); /* call to function */
17221721 }
17231722 #endif
17241723 }
@@ -1730,7 +1729,7 @@ void gfunc_epilog(void) · 5 unmodified lines
17301729
17311730 #ifdef CONFIG_TCC_BCHECK
17321731 if (tcc_state->do_bounds_check
1733− && func_bound_offset != lbounds_section->data_offset)
1732+ && func_bound_offset != lbounds_section->data_offset)
17341733 {
17351734 addr_t saved_ind;
17361735 addr_t *bounds_ptr;
@@ -1754,7 +1753,7 @@ void gfunc_epilog(void) · 17 unmodified lines
17541753 o(0x5250); /* save returned value, if any */
17551754 greloc(cur_text_section, sym_data, ind + 1, R_386_32);
17561755 oad(0xb8, 0); /* mov xxx, %rax */
1757− o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */
1756+ o(0xc78948); /* mov %rax,%rdi ## first arg in %rdi, this must be ptr */
17581757 gen_static_call(TOK___bound_local_delete);
17591758 o(0x585a); /* restore returned value, if any */
17601759 }
@@ -1806,24 +1805,24 @@ int gtst(int inv, int t) · 45 unmodified lines
18061805 v = vtop->r & VT_VALMASK;
18071806 if (v == VT_CMP) {
18081807 /* fast case : can jump directly since flags are set */
1809− if (vtop->c.i & 0x100)
1810− {
1811− /* This was a float compare. If the parity flag is set
1812− the result was unordered. For anything except != this
1813− means false and we don't jump (anding both conditions).
1814− For != this means true (oring both).
1815− Take care about inverting the test. We need to jump
1816− to our target if the result was unordered and test wasn't NE,
1817− otherwise if unordered we don't want to jump. */
1818− vtop->c.i &= ~0x100;
1819− if (!inv == (vtop->c.i != TOK_NE))
1820− o(0x067a); /* jp +6 */
1821− else
1822− {
1823− g(0x0f);
1824− t = psym(0x8a, t); /* jp t */
1825− }
1826− }
1808+ if (vtop->c.i & 0x100)
1809+ {
1810+ /* This was a float compare. If the parity flag is set
1811+ the result was unordered. For anything except != this
1812+ means false and we don't jump (anding both conditions).
1813+ For != this means true (oring both).
1814+ Take care about inverting the test. We need to jump
1815+ to our target if the result was unordered and test wasn't NE,
1816+ otherwise if unordered we don't want to jump. */
1817+ vtop->c.i &= ~0x100;
1818+ if (!inv == (vtop->c.i != TOK_NE))
1819+ o(0x067a); /* jp +6 */
1820+ else
1821+ {
1822+ g(0x0f);
1823+ t = psym(0x8a, t); /* jp t */
1824+ }
1825+ }
18271826 g(0x0f);
18281827 t = psym((vtop->c.i - 16) ^ inv, t);
18291828 } else if (v == VT_JMP || v == VT_JMPI) {