| @@ -76,6 +76,7 @@ static int is_compatible_types(CType *type1, CType *type2); · 75 unmodified lines |
| 76 | 76 | static int parse_btype(CType *type, AttributeDef *ad); |
| 77 | 77 | static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td); |
| 78 | 78 | static void parse_expr_type(CType *type); |
| 79 | +static void init_putv(CType *type, Section *sec, unsigned long c); |
| 79 | 80 | static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); |
| 80 | 81 | static void block(int *bsym, int *csym, int is_expr); |
| 81 | 82 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); |
| @@ -302,8 +303,6 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 220 unmodified lines |
| 302 | 303 | sh_num = SHN_UNDEF; |
| 303 | 304 | else if (section == SECTION_ABS) |
| 304 | 305 | sh_num = SHN_ABS; |
| 305 | | − else if (section == SECTION_COMMON) |
| 306 | | − sh_num = SHN_COMMON; |
| 307 | 306 | else |
| 308 | 307 | sh_num = section->sh_num; |
| 309 | 308 | |
| @@ -1065,7 +1064,7 @@ static void gbound(void) · 755 unmodified lines |
| 1065 | 1064 | register value (such as structures). */ |
| 1066 | 1065 | ST_FUNC int gv(int rc) |
| 1067 | 1066 | { |
| 1068 | | − int r, bit_pos, bit_size, size, align, i; |
| 1067 | + int r, bit_pos, bit_size, size, align; |
| 1069 | 1068 | int rc2; |
| 1070 | 1069 | |
| 1071 | 1070 | /* NOTE: get_reg can modify vstack[] */ |
| @@ -1096,44 +1095,15 @@ ST_FUNC int gv(int rc) · 24 unmodified lines |
| 1096 | 1095 | } else { |
| 1097 | 1096 | if (is_float(vtop->type.t) && |
| 1098 | 1097 | (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) { |
| 1099 | | − Sym *sym; |
| 1100 | | − int *ptr; |
| 1101 | 1098 | unsigned long offset; |
| 1102 | | −#if defined(TCC_TARGET_ARM) && !defined(TCC_ARM_VFP) |
| 1103 | | − CValue check; |
| 1104 | | −#endif |
| 1105 | | − |
| 1106 | | − /* XXX: unify with initializers handling ? */ |
| 1107 | 1099 | /* CPUs usually cannot use float constants, so we store them |
| 1108 | 1100 | generically in data segment */ |
| 1109 | 1101 | size = type_size(&vtop->type, &align); |
| 1110 | | − offset = (data_section->data_offset + align - 1) & -align; |
| 1111 | | − data_section->data_offset = offset; |
| 1112 | | − /* XXX: not portable yet */ |
| 1113 | | −#if defined(__i386__) || defined(__x86_64__) |
| 1114 | | − /* Zero pad x87 tenbyte long doubles */ |
| 1115 | | − if (size == LDOUBLE_SIZE) { |
| 1116 | | − vtop->c.tab[2] &= 0xffff; |
| 1117 | | −#if LDOUBLE_SIZE == 16 |
| 1118 | | − vtop->c.tab[3] = 0; |
| 1119 | | −#endif |
| 1120 | | − } |
| 1121 | | −#endif |
| 1122 | | − ptr = section_ptr_add(data_section, size); |
| 1123 | | − size = size >> 2; |
| 1124 | | −#if defined(TCC_TARGET_ARM) && !defined(TCC_ARM_VFP) |
| 1125 | | − check.d = 1; |
| 1126 | | − if(check.tab[0]) |
| 1127 | | − for(i=0;i<size;i++) |
| 1128 | | − ptr[i] = vtop->c.tab[size-1-i]; |
| 1129 | | − else |
| 1130 | | −#endif |
| 1131 | | − for(i=0;i<size;i++) |
| 1132 | | − ptr[i] = vtop->c.tab[i]; |
| 1133 | | − sym = get_sym_ref(&vtop->type, data_section, offset, size << 2); |
| 1134 | | − vtop->r |= VT_LVAL | VT_SYM; |
| 1135 | | − vtop->sym = sym; |
| 1136 | | − vtop->c.i = 0; |
| 1102 | + offset = section_add(data_section, size, align); |
| 1103 | + vpush_ref(&vtop->type, data_section, offset, size); |
| 1104 | + vswap(); |
| 1105 | + init_putv(&vtop->type, data_section, offset); |
| 1106 | + vtop->r |= VT_LVAL; |
| 1137 | 1107 | } |
| 1138 | 1108 | #ifdef CONFIG_TCC_BCHECK |
| 1139 | 1109 | if (vtop->r & VT_MUSTBOUND) |
| @@ -4351,7 +4321,7 @@ ST_FUNC void unary(void) · 3211 unmodified lines |
| 4351 | 4321 | t = VT_LLONG; |
| 4352 | 4322 | goto push_tokc; |
| 4353 | 4323 | case TOK_CULLONG: |
| 4354 | | − t =VT_LLONG | VT_UNSIGNED; |
| 4324 | + t = VT_LLONG | VT_UNSIGNED; |
| 4355 | 4325 | goto push_tokc; |
| 4356 | 4326 | case TOK_CFLOAT: |
| 4357 | 4327 | t = VT_FLOAT; |
| @@ -6098,9 +6068,7 @@ static void init_putv(CType *type, Section *sec, unsigned long c) · 1740 unmodified lines |
| 6098 | 6068 | gen_assign_cast(&dtype); |
| 6099 | 6069 | bt = type->t & VT_BTYPE; |
| 6100 | 6070 | size = type_size(type, &align); |
| 6101 | | − if (c + size > sec->data_allocated) { |
| 6102 | | − section_realloc(sec, c + size); |
| 6103 | | − } |
| 6071 | + section_reserve(sec, c + size); |
| 6104 | 6072 | ptr = sec->data + c; |
| 6105 | 6073 | /* XXX: make code faster ? */ |
| 6106 | 6074 | if (!(type->t & VT_BITFIELD)) { |
| @@ -6190,6 +6158,9 @@ static void init_putv(CType *type, Section *sec, unsigned long c) · 83 unmodified lines |
| 6190 | 6158 | case VT_SHORT: |
| 6191 | 6159 | *(short *)ptr |= (vtop->c.i & bit_mask) << bit_pos; |
| 6192 | 6160 | break; |
| 6161 | + case VT_FLOAT: |
| 6162 | + *(float*)ptr = vtop->c.f; |
| 6163 | + break; |
| 6193 | 6164 | case VT_DOUBLE: |
| 6194 | 6165 | *(double *)ptr = vtop->c.d; |
| 6195 | 6166 | break; |
| @@ -6475,7 +6446,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 279 unmodified lines |
| 6475 | 6446 | static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, |
| 6476 | 6447 | int has_init, int v, int scope) |
| 6477 | 6448 | { |
| 6478 | | − int size, align, addr, data_offset; |
| 6449 | + int size, align, addr; |
| 6479 | 6450 | ParseState saved_parse_state = {0}; |
| 6480 | 6451 | TokenString *init_str = NULL; |
| 6481 | 6452 | Section *sec; |
| @@ -6624,41 +6595,24 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 142 unmodified lines |
| 6624 | 6595 | } |
| 6625 | 6596 | |
| 6626 | 6597 | if (sec) { |
| 6627 | | − data_offset = sec->data_offset; |
| 6628 | | − data_offset = (data_offset + align - 1) & -align; |
| 6629 | | − addr = data_offset; |
| 6630 | | − /* very important to increment global pointer at this time |
| 6631 | | − because initializers themselves can create new initializers */ |
| 6632 | | − data_offset += size; |
| 6598 | + addr = section_add(sec, size, align); |
| 6633 | 6599 | #ifdef CONFIG_TCC_BCHECK |
| 6634 | 6600 | /* add padding if bound check */ |
| 6635 | 6601 | if (tcc_state->do_bounds_check) |
| 6636 | | − data_offset++; |
| 6602 | + section_add(sec, 1, 1); |
| 6637 | 6603 | #endif |
| 6638 | | − sec->data_offset = data_offset; |
| 6639 | | − /* allocate section space to put the data */ |
| 6640 | | − if (sec->sh_type != SHT_NOBITS && |
| 6641 | | − data_offset > sec->data_allocated) |
| 6642 | | − section_realloc(sec, data_offset); |
| 6643 | | − /* align section if needed */ |
| 6644 | | − if (align > sec->sh_addralign) |
| 6645 | | − sec->sh_addralign = align; |
| 6646 | 6604 | } else { |
| 6647 | | − addr = 0; /* avoid warning */ |
| 6605 | + addr = align; /* SHN_COMMON is special, symbol value is align */ |
| 6606 | + sec = common_section; |
| 6648 | 6607 | } |
| 6649 | 6608 | |
| 6650 | 6609 | if (v) { |
| 6651 | | − if (scope != VT_CONST || !sym) { |
| 6610 | + if (!sym) { |
| 6652 | 6611 | sym = sym_push(v, type, r | VT_SYM, 0); |
| 6653 | 6612 | sym->asm_label = ad->asm_label; |
| 6654 | 6613 | } |
| 6655 | 6614 | /* update symbol definition */ |
| 6656 | | − if (sec) { |
| 6657 | | − put_extern_sym(sym, sec, addr, size); |
| 6658 | | − } else { |
| 6659 | | − put_extern_sym(sym, SECTION_COMMON, align, size); |
| 6660 | | − } |
| 6661 | | − |
| 6615 | + put_extern_sym(sym, sec, addr, size); |
| 6662 | 6616 | } else { |
| 6663 | 6617 | /* push global reference */ |
| 6664 | 6618 | sym = get_sym_ref(type, sec, addr, size); |