History

Import more changesets from Rob Landley's fork (part 2)

grischka committed 18 years ago

Commit d778bde1 parent 54bf8c010 files · +157 −79Browse files

Unified · Split

10 files
  1. Changelog +16 −0
  2. Makefile +10 −3
  3. stddef.h +8 −3
  4. tcc.c +92 −67
  5. tccasm.c +1 −1
  6. tccelf.c +18 −1
  7. tcctok.h +1 −1
  8. win32/include/_mingw.h +2 −0
  9. win32/include/stdarg.h +1 −0
  10. win32/include/stddef.h +8 −3
Changelog+16−0
@@ -1,5 +1,21 @@
1version 0.9.24:1version 0.9.24:
2 2
3- Import more changesets from Rob Landley's fork (part 2):
4 487: Handle long long constants in gen_opic() (Rob Landley)
5 484: Handle parentheses within __attribute__((...)) (Rob Landley)
6 480: Remove a goto in decl_initializer_alloc (Rob Landley)
7 475: Fix dereferences in inline assembly output (Joshua Phillips)
8 474: Cast ptrs to ints of different sizes correctly (Joshua Phillips)
9 473: Fix size of structs with empty array member (Joshua Phillips)
10 470: No warning for && and || with mixed pointers/integers (Rob Landley)
11 469: Fix symbol visibility problems in the linker (Vincent Pit)
12 468: Allow && and || involving pointer arguments (Rob Landley)
13 455: Optimize case labels with no code in between (Zdenek Pavlas)
14 450: Implement alloca for x86 (grischka)
15 415: Parse unicode escape sequences (Axel Liljencrantz)
16 407: Add a simple va_copy() in stdarg.h (Hasso Tepper)
17 400: Allow typedef names as symbols (Dave Dodge)
18
3- Import some changesets from Rob Landley's fork (part 1):19- Import some changesets from Rob Landley's fork (part 1):
4 462: Use LGPL with bcheck.c and il-gen.c20 462: Use LGPL with bcheck.c and il-gen.c
5 458: Fix global compound literals (in unary: case '&':) (Andrew Johnson)21 458: Fix global compound literals (in unary: case '&':) (Andrew Johnson)
Makefile+10−3
@@ -176,6 +176,9 @@ else · 175 unmodified lines
176LIBTCC1_OBJS=libtcc1.o176LIBTCC1_OBJS=libtcc1.o
177LIBTCC1_CC=$(CC)177LIBTCC1_CC=$(CC)
178endif178endif
179ifeq ($(ARCH),i386)
180LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
181endif
179 182
180%.o: %.c183%.o: %.c
181 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<184 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
@@ -237,7 +240,11 @@ libinstall: libtcc.a · 55 unmodified lines
237 $(INSTALL) -m644 libtcc.h "$(includedir)"240 $(INSTALL) -m644 libtcc.h "$(includedir)"
238 241
239libtcc.o: tcc.c i386-gen.c Makefile242libtcc.o: tcc.c i386-gen.c Makefile
243ifdef CONFIG_WIN32
244 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
245else
240 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<246 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
247endif
241 248
242libtcc.a: libtcc.o 249libtcc.a: libtcc.o
243 $(AR) rcs $@ $^250 $(AR) rcs $@ $^
@@ -282,11 +289,11 @@ cache: tcc_g · 38 unmodified lines
282 289
283# documentation and man page290# documentation and man page
284tcc-doc.html: tcc-doc.texi291tcc-doc.html: tcc-doc.texi
285 texi2html -monolithic -number $<292 -texi2html -monolithic -number $<
286 293
287tcc.1: tcc-doc.texi294tcc.1: tcc-doc.texi
288 ./texi2pod.pl $< tcc.pod295 -./texi2pod.pl $< tcc.pod
289 pod2man --section=1 --center=" " --release=" " tcc.pod > $@296 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
290 297
291FILE=tcc-$(shell cat VERSION)298FILE=tcc-$(shell cat VERSION)
292 299
stddef.h+8−3
@@ -12,10 +12,15 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; · 11 unmodified lines
12 __GNUC__ ? */12 __GNUC__ ? */
13#if !defined(__int8_t_defined) && !defined(__dietlibc__)13#if !defined(__int8_t_defined) && !defined(__dietlibc__)
14#define __int8_t_defined14#define __int8_t_defined
15typedef char int8_t;15typedef char int8_t;
16typedef short int int16_t;16typedef short int int16_t;
17typedef int int32_t;17typedef int int32_t;
18typedef long long int int64_t;18typedef long long int int64_t;
19#endif19#endif
20 20
21#ifdef __i386__
22void *_alloca(size_t);
23#define alloca _alloca
24#endif
25
21#endif26#endif
tcc.c+92−67
@@ -1290,6 +1290,7 @@ static void put_extern_sym2(Sym *sym, Section *section, · 1289 unmodified lines
1290 case TOK_memset:1290 case TOK_memset:
1291 case TOK_strlen:1291 case TOK_strlen:
1292 case TOK_strcpy:1292 case TOK_strcpy:
1293 case TOK__alloca:
1293 strcpy(buf, "__bound_");1294 strcpy(buf, "__bound_");
1294 strcat(buf, name);1295 strcat(buf, name);
1295 name = buf;1296 name = buf;
@@ -3123,6 +3124,8 @@ static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long · 1827 unmodified lines
3123 c = n;3124 c = n;
3124 goto add_char_nonext;3125 goto add_char_nonext;
3125 case 'x':3126 case 'x':
3127 case 'u':
3128 case 'U':
3126 p++;3129 p++;
3127 n = 0;3130 n = 0;
3128 for(;;) {3131 for(;;) {
@@ -4360,7 +4363,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 1231 unmodified lines
4360 ptr = (int *)macro_ptr;4363 ptr = (int *)macro_ptr;
4361 macro_ptr = ml.p;4364 macro_ptr = ml.p;
4362 if (can_read_stream && *can_read_stream == &ml)4365 if (can_read_stream && *can_read_stream == &ml)
4363 *can_read_stream = ml.prev;4366 *can_read_stream = ml.prev;
4364 if (ret != 0)4367 if (ret != 0)
4365 goto no_subst;4368 goto no_subst;
4366 } else {4369 } else {
@@ -5298,8 +5301,8 @@ void gen_opl(int op) · 931 unmodified lines
5298#if defined(TCC_TARGET_I386)5301#if defined(TCC_TARGET_I386)
5299 b = psym(0x850f, 0);5302 b = psym(0x850f, 0);
5300#elif defined(TCC_TARGET_ARM)5303#elif defined(TCC_TARGET_ARM)
5301 b = ind;5304 b = ind;
5302 o(0x1A000000 | encbranch(ind, 0, 1));5305 o(0x1A000000 | encbranch(ind, 0, 1));
5303#elif defined(TCC_TARGET_C67)5306#elif defined(TCC_TARGET_C67)
5304 error("not implemented");5307 error("not implemented");
5305#else5308#else
@@ -5329,23 +5332,29 @@ void gen_opl(int op) · 23 unmodified lines
5329 independent opt */5332 independent opt */
5330void gen_opic(int op)5333void gen_opic(int op)
5331{5334{
5332 int fc, c1, c2, n;5335 int c1, c2, t1, t2, n, c;
5333 SValue *v1, *v2;5336 SValue *v1, *v2;
5337 long long l1, l2, l;
5338 typedef unsigned long long U;
5334 5339
5335 v1 = vtop - 1;5340 v1 = vtop - 1;
5336 v2 = vtop;5341 v2 = vtop;
5342 t1 = v1->type.t & VT_BTYPE;
5343 t2 = v2->type.t & VT_BTYPE;
5344 l1 = (t1 == VT_LLONG) ? v1->c.ll : v1->c.i;
5345 l2 = (t2 == VT_LLONG) ? v2->c.ll : v2->c.i;
5346
5337 /* currently, we cannot do computations with forward symbols */5347 /* currently, we cannot do computations with forward symbols */
5338 c1 = (v1->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;5348 c1 = (v1->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
5339 c2 = (v2->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;5349 c2 = (v2->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
5340 if (c1 && c2) {5350 if (c1 && c2) {
5341 fc = v2->c.i;
5342 switch(op) {5351 switch(op) {
5343 case '+': v1->c.i += fc; break;5352 case '+': l1 += l2; break;
5344 case '-': v1->c.i -= fc; break;5353 case '-': l1 -= l2; break;
5345 case '&': v1->c.i &= fc; break;5354 case '&': l1 &= l2; break;
5346 case '^': v1->c.i ^= fc; break;5355 case '^': l1 ^= l2; break;
5347 case '|': v1->c.i |= fc; break;5356 case '|': l1 |= l2; break;
5348 case '*': v1->c.i *= fc; break;5357 case '*': l1 *= l2; break;
5349 5358
5350 case TOK_PDIV:5359 case TOK_PDIV:
5351 case '/':5360 case '/':
@@ -5353,66 +5362,68 @@ void gen_opic(int op) · 1 unmodified line
5353 case TOK_UDIV:5362 case TOK_UDIV:
5354 case TOK_UMOD:5363 case TOK_UMOD:
5355 /* if division by zero, generate explicit division */5364 /* if division by zero, generate explicit division */
5356 if (fc == 0) {5365 if (l2 == 0) {
5357 if (const_wanted)5366 if (const_wanted)
5358 error("division by zero in constant");5367 error("division by zero in constant");
5359 goto general_case;5368 goto general_case;
5360 }5369 }
5361 switch(op) {5370 switch(op) {
5362 default: v1->c.i /= fc; break;5371 default: l1 /= l2; break;
5363 case '%': v1->c.i %= fc; break;5372 case '%': l1 %= l2; break;
5364 case TOK_UDIV: v1->c.i = (unsigned)v1->c.i / fc; break;5373 case TOK_UDIV: l1 = (U)l1 / l2; break;
5365 case TOK_UMOD: v1->c.i = (unsigned)v1->c.i % fc; break;5374 case TOK_UMOD: l1 = (U)l1 % l2; break;
5366 }5375 }
5367 break;5376 break;
5368 case TOK_SHL: v1->c.i <<= fc; break;5377 case TOK_SHL: l1 <<= l2; break;
5369 case TOK_SHR: v1->c.i = (unsigned)v1->c.i >> fc; break;5378 case TOK_SHR: l1 = (U)l1 >> l2; break;
5370 case TOK_SAR: v1->c.i >>= fc; break;5379 case TOK_SAR: l1 >>= l2; break;
5371 /* tests */5380 /* tests */
5372 case TOK_ULT: v1->c.i = (unsigned)v1->c.i < (unsigned)fc; break;5381 case TOK_ULT: l1 = (U)l1 < (U)l2; break;
5373 case TOK_UGE: v1->c.i = (unsigned)v1->c.i >= (unsigned)fc; break;5382 case TOK_UGE: l1 = (U)l1 >= (U)l2; break;
5374 case TOK_EQ: v1->c.i = v1->c.i == fc; break;5383 case TOK_EQ: l1 = l1 == l2; break;
5375 case TOK_NE: v1->c.i = v1->c.i != fc; break;5384 case TOK_NE: l1 = l1 != l2; break;
5376 case TOK_ULE: v1->c.i = (unsigned)v1->c.i <= (unsigned)fc; break;5385 case TOK_ULE: l1 = (U)l1 <= (U)l2; break;
5377 case TOK_UGT: v1->c.i = (unsigned)v1->c.i > (unsigned)fc; break;5386 case TOK_UGT: l1 = (U)l1 > (U)l2; break;
5378 case TOK_LT: v1->c.i = v1->c.i < fc; break;5387 case TOK_LT: l1 = l1 < l2; break;
5379 case TOK_GE: v1->c.i = v1->c.i >= fc; break;5388 case TOK_GE: l1 = l1 >= l2; break;
5380 case TOK_LE: v1->c.i = v1->c.i <= fc; break;5389 case TOK_LE: l1 = l1 <= l2; break;
5381 case TOK_GT: v1->c.i = v1->c.i > fc; break;5390 case TOK_GT: l1 = l1 > l2; break;
5382 /* logical */5391 /* logical */
5383 case TOK_LAND: v1->c.i = v1->c.i && fc; break;5392 case TOK_LAND: l1 = l1 && l2; break;
5384 case TOK_LOR: v1->c.i = v1->c.i || fc; break;5393 case TOK_LOR: l1 = l1 || l2; break;
5385 default:5394 default:
5386 goto general_case;5395 goto general_case;
5387 }5396 }
5397 v1->c.ll = l1;
5388 vtop--;5398 vtop--;
5389 } else {5399 } else {
5390 /* if commutative ops, put c2 as constant */5400 /* if commutative ops, put c2 as constant */
5391 if (c1 && (op == '+' || op == '&' || op == '^' || 5401 if (c1 && (op == '+' || op == '&' || op == '^' ||
5392 op == '|' || op == '*')) {5402 op == '|' || op == '*')) {
5393 vswap();5403 vswap();
5394 swap(&c1, &c2);5404 c = c1, c1 = c2, c2 = c;
5405 l = l1, l1 = l2, l2 = l;
5395 }5406 }
5396 fc = vtop->c.i;5407 /* Filter out NOP operations like x*1, x-0, x&-1... */
5397 if (c2 && (((op == '*' || op == '/' || op == TOK_UDIV || 5408 if (c2 && (((op == '*' || op == '/' || op == TOK_UDIV ||
5398 op == TOK_PDIV) && 5409 op == TOK_PDIV) &&
5399 fc == 1) ||5410 l2 == 1) ||
5400 ((op == '+' || op == '-' || op == '|' || op == '^' || 5411 ((op == '+' || op == '-' || op == '|' || op == '^' ||
5401 op == TOK_SHL || op == TOK_SHR || op == TOK_SAR) && 5412 op == TOK_SHL || op == TOK_SHR || op == TOK_SAR) &&
5402 fc == 0) ||5413 l2 == 0) ||
5403 (op == '&' && 5414 (op == '&' &&
5404 fc == -1))) {5415 l2 == -1))) {
5405 /* nothing to do */5416 /* nothing to do */
5406 vtop--;5417 vtop--;
5407 } else if (c2 && (op == '*' || op == TOK_PDIV || op == TOK_UDIV)) {5418 } else if (c2 && (op == '*' || op == TOK_PDIV || op == TOK_UDIV)) {
5408 /* try to use shifts instead of muls or divs */5419 /* try to use shifts instead of muls or divs */
5409 if (fc > 0 && (fc & (fc - 1)) == 0) {5420 if (l2 > 0 && (l2 & (l2 - 1)) == 0) {
5410 n = -1;5421 n = -1;
5411 while (fc) {5422 while (l2) {
5412 fc >>= 1;5423 l2 >>= 1;
5413 n++;5424 n++;
5414 }5425 }
5415 vtop->c.i = n;5426 vtop->c.ll = n;
5416 if (op == '*')5427 if (op == '*')
5417 op = TOK_SHL;5428 op = TOK_SHL;
5418 else if (op == TOK_PDIV)5429 else if (op == TOK_PDIV)
@@ -5426,14 +5437,17 @@ void gen_opic(int op) · 7 unmodified lines
5426 (VT_CONST | VT_SYM)) {5437 (VT_CONST | VT_SYM)) {
5427 /* symbol + constant case */5438 /* symbol + constant case */
5428 if (op == '-')5439 if (op == '-')
5429 fc = -fc;5440 l2 = -l2;
5430 vtop--;5441 vtop--;
5431 vtop->c.i += fc;5442 vtop->c.ll += l2;
5432 } else {5443 } else {
5433 general_case:5444 general_case:
5434 if (!nocode_wanted) {5445 if (!nocode_wanted) {
5435 /* call low level op generator */5446 /* call low level op generator */
5436 gen_opi(op);5447 if (t1 == VT_LLONG || t2 == VT_LLONG)
5448 gen_opl(op);
5449 else
5450 gen_opi(op);
5437 } else {5451 } else {
5438 vtop--;5452 vtop--;
5439 }5453 }
@@ -5540,7 +5554,8 @@ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op) · 100 unmodified lines
5540 bt2 = type2->t & VT_BTYPE;5554 bt2 = type2->t & VT_BTYPE;
5541 /* accept comparison between pointer and integer with a warning */5555 /* accept comparison between pointer and integer with a warning */
5542 if ((is_integer_btype(bt1) || is_integer_btype(bt2)) && op != '-') {5556 if ((is_integer_btype(bt1) || is_integer_btype(bt2)) && op != '-') {
5543 warning("comparison between pointer and integer");5557 if (op != TOK_LOR && op != TOK_LAND )
5558 warning("comparison between pointer and integer");
5544 return;5559 return;
5545 }5560 }
5546 5561
@@ -5586,7 +5601,7 @@ void gen_op(int op) · 39 unmodified lines
5586 if (bt1 == VT_PTR || bt2 == VT_PTR) {5601 if (bt1 == VT_PTR || bt2 == VT_PTR) {
5587 /* at least one operand is a pointer */5602 /* at least one operand is a pointer */
5588 /* relationnal op: must be both pointers */5603 /* relationnal op: must be both pointers */
5589 if (op >= TOK_ULT && op <= TOK_GT) {5604 if (op >= TOK_ULT && op <= TOK_LOR) {
5590 check_comparison_pointer_types(vtop - 1, vtop, op);5605 check_comparison_pointer_types(vtop - 1, vtop, op);
5591 /* pointers are handled are unsigned */5606 /* pointers are handled are unsigned */
5592 t = VT_INT | VT_UNSIGNED;5607 t = VT_INT | VT_UNSIGNED;
@@ -5696,8 +5711,6 @@ void gen_op(int op) · 103 unmodified lines
5696 gen_cast(&type1);5711 gen_cast(&type1);
5697 if (is_float(t))5712 if (is_float(t))
5698 gen_opif(op);5713 gen_opif(op);
5699 else if ((t & VT_BTYPE) == VT_LLONG)
5700 gen_opl(op);
5701 else5714 else
5702 gen_opic(op);5715 gen_opic(op);
5703 if (op >= TOK_ULT && op <= TOK_GT) {5716 if (op >= TOK_ULT && op <= TOK_GT) {
@@ -5947,6 +5960,11 @@ static void gen_cast(CType *type) · 243 unmodified lines
5947 the lvalue already contains the real type size (see5960 the lvalue already contains the real type size (see
5948 VT_LVAL_xxx constants) */5961 VT_LVAL_xxx constants) */
5949 }5962 }
5963 } else if ((dbt & VT_BTYPE) == VT_PTR && !(vtop->r & VT_LVAL)) {
5964 /* if we are casting between pointer types,
5965 we must update the VT_LVAL_xxx size */
5966 vtop->r = (vtop->r & ~VT_LVAL_TYPE)
5967 | (lvalue_type(type->ref->type.t) & VT_LVAL_TYPE);
5950 }5968 }
5951 vtop->type = *type;5969 vtop->type = *type;
5952}5970}
@@ -6502,12 +6520,15 @@ static void parse_attribute(AttributeDef *ad) · 549 unmodified lines
6502 if (tcc_state->warn_unsupported)6520 if (tcc_state->warn_unsupported)
6503 warning("'%s' attribute ignored", get_tok_str(t, NULL));6521 warning("'%s' attribute ignored", get_tok_str(t, NULL));
6504 /* skip parameters */6522 /* skip parameters */
6505 /* XXX: skip parenthesis too */
6506 if (tok == '(') {6523 if (tok == '(') {
6507 next();6524 int parenthesis = 0;
6508 while (tok != ')' && tok != -1)6525 do {
6526 if (tok == '(')
6527 parenthesis++;
6528 else if (tok == ')')
6529 parenthesis--;
6509 next();6530 next();
6510 next();6531 } while (parenthesis && tok != -1);
6511 }6532 }
6512 break;6533 break;
6513 }6534 }
@@ -6668,7 +6689,8 @@ static void struct_decl(CType *type, int u) · 154 unmodified lines
6668 if (a == TOK_STRUCT) {6689 if (a == TOK_STRUCT) {
6669 c = (c + align - 1) & -align;6690 c = (c + align - 1) & -align;
6670 offset = c;6691 offset = c;
6671 c += size;6692 if (size > 0)
6693 c += size;
6672 } else {6694 } else {
6673 offset = 0;6695 offset = 0;
6674 if (size > c)6696 if (size > c)
@@ -6719,13 +6741,14 @@ static void struct_decl(CType *type, int u) · 44 unmodified lines
6719 */6741 */
6720static int parse_btype(CType *type, AttributeDef *ad)6742static int parse_btype(CType *type, AttributeDef *ad)
6721{6743{
6722 int t, u, type_found, typespec_found;6744 int t, u, type_found, typespec_found, typedef_found;
6723 Sym *s;6745 Sym *s;
6724 CType type1;6746 CType type1;
6725 6747
6726 memset(ad, 0, sizeof(AttributeDef));6748 memset(ad, 0, sizeof(AttributeDef));
6727 type_found = 0;6749 type_found = 0;
6728 typespec_found = 0;6750 typespec_found = 0;
6751 typedef_found = 0;
6729 t = 0;6752 t = 0;
6730 while(1) {6753 while(1) {
6731 switch(tok) {6754 switch(tok) {
@@ -6809,9 +6832,9 @@ static int parse_btype(CType *type, AttributeDef *ad) · 77 unmodified lines
6809 case TOK_SIGNED2:6832 case TOK_SIGNED2:
6810 case TOK_SIGNED3:6833 case TOK_SIGNED3:
6811 typespec_found = 1;6834 typespec_found = 1;
6812 t |= VT_SIGNED;6835 t |= VT_SIGNED;
6813 next();6836 next();
6814 break;6837 break;
6815 case TOK_REGISTER:6838 case TOK_REGISTER:
6816 case TOK_AUTO:6839 case TOK_AUTO:
6817 case TOK_RESTRICT1:6840 case TOK_RESTRICT1:
@@ -6858,11 +6881,12 @@ static int parse_btype(CType *type, AttributeDef *ad) · 40 unmodified lines
6858 parse_expr_type(&type1);6881 parse_expr_type(&type1);
6859 goto basic_type2;6882 goto basic_type2;
6860 default:6883 default:
6861 if (typespec_found)6884 if (typespec_found || typedef_found)
6862 goto the_end;6885 goto the_end;
6863 s = sym_find(tok);6886 s = sym_find(tok);
6864 if (!s || !(s->type.t & VT_TYPEDEF))6887 if (!s || !(s->type.t & VT_TYPEDEF))
6865 goto the_end;6888 goto the_end;
6889 typedef_found = 1;
6866 t |= (s->type.t & ~VT_TYPEDEF);6890 t |= (s->type.t & ~VT_TYPEDEF);
6867 type->ref = s->type.ref;6891 type->ref = s->type.ref;
6868 next();6892 next();
@@ -8164,6 +8188,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 1295 unmodified lines
8164 int v1, v2;8188 int v1, v2;
8165 if (!case_sym)8189 if (!case_sym)
8166 expect("switch");8190 expect("switch");
8191 /* since a case is like a label, we must skip it with a jmp */
8192 b = gjmp(0);
8193 next_case:
8167 next();8194 next();
8168 v1 = expr_const();8195 v1 = expr_const();
8169 v2 = v1;8196 v2 = v1;
@@ -8173,24 +8200,26 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 3 unmodified lines
8173 if (v2 < v1)8200 if (v2 < v1)
8174 warning("empty case range");8201 warning("empty case range");
8175 }8202 }
8176 /* since a case is like a label, we must skip it with a jmp */
8177 b = gjmp(0);
8178 gsym(*case_sym);8203 gsym(*case_sym);
8179 vseti(case_reg, 0);8204 vseti(case_reg, 0);
8180 vpushi(v1);8205 vpushi(v1);
8181 if (v1 == v2) {8206 if (v1 == v2) {
8182 gen_op(TOK_EQ);8207 gen_op(TOK_EQ);
8183 *case_sym = gtst(1, 0);8208 *case_sym = 0;
8184 } else {8209 } else {
8185 gen_op(TOK_GE);8210 gen_op(TOK_GE);
8186 *case_sym = gtst(1, 0);8211 *case_sym = gtst(1, 0);
8187 vseti(case_reg, 0);8212 vseti(case_reg, 0);
8188 vpushi(v2);8213 vpushi(v2);
8189 gen_op(TOK_LE);8214 gen_op(TOK_LE);
8190 *case_sym = gtst(1, *case_sym);
8191 }8215 }
8192 gsym(b);
8193 skip(':');8216 skip(':');
8217 if (tok == TOK_CASE) {
8218 b = gtst(0, b);
8219 goto next_case;
8220 }
8221 *case_sym = gtst(1, *case_sym);
8222 gsym(b);
8194 is_expr = 0;8223 is_expr = 0;
8195 goto block_after_label;8224 goto block_after_label;
8196 } else 8225 } else
@@ -8873,11 +8902,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 676 unmodified lines
8873 }8902 }
8874 8903
8875 if (v) {8904 if (v) {
8876 if (scope == VT_CONST) {8905 if (scope != VT_CONST || !sym) {
8877 if (!sym)
8878 goto do_def;
8879 } else {
8880 do_def:
8881 sym = sym_push(v, type, r | VT_SYM, 0);8906 sym = sym_push(v, type, r | VT_SYM, 0);
8882 }8907 }
8883 /* update symbol definition */8908 /* update symbol definition */
tccasm.c+1−1
@@ -806,7 +806,7 @@ static void subst_asm_operands(ASMOperand *operands, int nb_operands, · 805 unmodified lines
806 sv = *op->vt;806 sv = *op->vt;
807 if (op->reg >= 0) {807 if (op->reg >= 0) {
808 sv.r = op->reg;808 sv.r = op->reg;
809 if ((op->vt->r & VT_VALMASK) == VT_LLOCAL)809 if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && op->is_memory)
810 sv.r |= VT_LVAL;810 sv.r |= VT_LVAL;
811 }811 }
812 subst_asm_operand(out_str, &sv, modifier);812 subst_asm_operand(out_str, &sv, modifier);
tccelf.c+18−1
@@ -182,9 +182,11 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 181 unmodified lines
182{182{
183 Elf32_Sym *esym;183 Elf32_Sym *esym;
184 int sym_bind, sym_index, sym_type, esym_bind;184 int sym_bind, sym_index, sym_type, esym_bind;
185 unsigned char sym_vis, esym_vis, new_vis;
185 186
186 sym_bind = ELF32_ST_BIND(info);187 sym_bind = ELF32_ST_BIND(info);
187 sym_type = ELF32_ST_TYPE(info);188 sym_type = ELF32_ST_TYPE(info);
189 sym_vis = ELF32_ST_VISIBILITY(other);
188 190
189 if (sym_bind != STB_LOCAL) {191 if (sym_bind != STB_LOCAL) {
190 /* we search global or weak symbols */192 /* we search global or weak symbols */
@@ -194,6 +196,19 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 3 unmodified lines
194 esym = &((Elf32_Sym *)s->data)[sym_index];196 esym = &((Elf32_Sym *)s->data)[sym_index];
195 if (esym->st_shndx != SHN_UNDEF) {197 if (esym->st_shndx != SHN_UNDEF) {
196 esym_bind = ELF32_ST_BIND(esym->st_info);198 esym_bind = ELF32_ST_BIND(esym->st_info);
199 /* propagate the most constraining visibility */
200 /* STV_DEFAULT(0)<STV_PROTECTED(3)<STV_HIDDEN(2)<STV_INTERNAL(1) */
201 esym_vis = ELF32_ST_VISIBILITY(esym->st_other);
202 if (esym_vis == STV_DEFAULT) {
203 new_vis = sym_vis;
204 } else if (sym_vis == STV_DEFAULT) {
205 new_vis = esym_vis;
206 } else {
207 new_vis = (esym_vis < sym_vis) ? esym_vis : sym_vis;
208 }
209 esym->st_other = (esym->st_other & ~ELF32_ST_VISIBILITY(-1))
210 | new_vis;
211 other = esym->st_other; /* in case we have to patch esym */
197 if (sh_num == SHN_UNDEF) {212 if (sh_num == SHN_UNDEF) {
198 /* ignore adding of undefined symbol if the213 /* ignore adding of undefined symbol if the
199 corresponding symbol is already defined */214 corresponding symbol is already defined */
@@ -202,6 +217,8 @@ static int add_elf_sym(Section *s, unsigned long value, unsigned long size, · 2 unmodified lines
202 goto do_patch;217 goto do_patch;
203 } else if (sym_bind == STB_WEAK && esym_bind == STB_GLOBAL) {218 } else if (sym_bind == STB_WEAK && esym_bind == STB_GLOBAL) {
204 /* weak is ignored if already global */219 /* weak is ignored if already global */
220 } else if (sym_vis == STV_HIDDEN || sym_vis == STV_INTERNAL) {
221 /* ignore hidden symbols after */
205 } else {222 } else {
206#if 0223#if 0
207 printf("new_bind=%d new_shndx=%d last_bind=%d old_shndx=%d\n",224 printf("new_bind=%d new_shndx=%d last_bind=%d old_shndx=%d\n",
@@ -1949,7 +1966,7 @@ static int tcc_load_object_file(TCCState *s1, · 1741 unmodified lines
1949 if (sym_index >= nb_syms)1966 if (sym_index >= nb_syms)
1950 goto invalid_reloc;1967 goto invalid_reloc;
1951 sym_index = old_to_new_syms[sym_index];1968 sym_index = old_to_new_syms[sym_index];
1952 /* ignore link_once in rel section. */1969 /* ignore link_once in rel section. */
1953 if (!sym_index && !sm->link_once) {1970 if (!sym_index && !sm->link_once) {
1954 invalid_reloc:1971 invalid_reloc:
1955 error_noabort("Invalid relocation entry [%2d] '%s' @ %.8x",1972 error_noabort("Invalid relocation entry [%2d] '%s' @ %.8x",
tcctok.h+1−1
@@ -123,7 +123,6 @@ · 122 unmodified lines
123/* builtin functions or variables */123/* builtin functions or variables */
124 DEF(TOK_memcpy, "memcpy")124 DEF(TOK_memcpy, "memcpy")
125 DEF(TOK_memset, "memset")125 DEF(TOK_memset, "memset")
126 DEF(TOK_alloca, "alloca")
127 DEF(TOK___divdi3, "__divdi3")126 DEF(TOK___divdi3, "__divdi3")
128 DEF(TOK___moddi3, "__moddi3")127 DEF(TOK___moddi3, "__moddi3")
129 DEF(TOK___udivdi3, "__udivdi3")128 DEF(TOK___udivdi3, "__udivdi3")
@@ -188,6 +187,7 @@ · 58 unmodified lines
188 DEF(TOK_memmove, "memmove")187 DEF(TOK_memmove, "memmove")
189 DEF(TOK_strlen, "strlen")188 DEF(TOK_strlen, "strlen")
190 DEF(TOK_strcpy, "strcpy")189 DEF(TOK_strcpy, "strcpy")
190 DEF(TOK__alloca, "_alloca")
191#endif191#endif
192 192
193/* Tiny Assembler */193/* Tiny Assembler */
win32/include/_mingw.h+2−0
@@ -18,6 +18,8 @@ · 17 unmodified lines
18#ifndef __MINGW_H18#ifndef __MINGW_H
19#define __MINGW_H19#define __MINGW_H
20 20
21#include <stddef.h>
22
21#define __int64 long long23#define __int64 long long
22#define __int32 long24#define __int32 long
23#define __int16 short25#define __int16 short
win32/include/stdarg.h+1−0
@@ -6,6 +6,7 @@ typedef char *va_list; · 5 unmodified lines
6/* only correct for i386 */6/* only correct for i386 */
7#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)7#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
8#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))8#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
9#define va_copy(dest, src) (dest) = (src)
9#define va_end(ap)10#define va_end(ap)
10 11
11/* fix a buggy dependency on GCC in libio.h */12/* fix a buggy dependency on GCC in libio.h */
win32/include/stddef.h+8−3
@@ -12,10 +12,15 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; · 11 unmodified lines
12 __GNUC__ ? */12 __GNUC__ ? */
13#if !defined(__int8_t_defined) && !defined(__dietlibc__)13#if !defined(__int8_t_defined) && !defined(__dietlibc__)
14#define __int8_t_defined14#define __int8_t_defined
15typedef char int8_t;15typedef char int8_t;
16typedef short int int16_t;16typedef short int int16_t;
17typedef int int32_t;17typedef int int32_t;
18typedef long long int int64_t;18typedef long long int int64_t;
19#endif19#endif
20 20
21#ifdef __i386__
22void *_alloca(size_t);
23#define alloca _alloca
24#endif
25
21#endif26#endif