History

misc fixes

misc fixes including: - tcc.c: fix "tcc -vv" for libtcc1.a on win32/PE - tccelf.c: fix a crash when GOT has no relocs (witn -nostdlib) - tccelf.c: fix stab linkage for zero n_strx - tccgen.c: fix stdcall decoration for array parameters int __stdcall func(char buf[10]) is _func@4 (was _func@12) - tccgen.c: fix static variables with nocode/nodata_wanted see tests2/96_nodata_wanted.c - tccrun.c: align sections using sh_addralign (for reliable function_alignment) - tests2/Makefile sort 100 after 99 - win32/include/sys/stat.h fix _stat and _wstat - x86_64-gen.c: win64/gfunc_call: fix a bug with xmmN register args previously overwrote valid other xmmN registers eventually

grischka committed 8 years ago

Commit 8f6fcb71 parent 2b155a89 files · +73 −49Browse files

Unified · Split

9 files
  1. tcc.c +3 −1
  2. tccelf.c +7 −2
  3. tccgen.c +11 −8
  4. tccrun.c +20 −24
  5. tests/tests2/96_nodata_wanted.c +19 −5
  6. tests/tests2/96_nodata_wanted.expect +3 −0
  7. tests/tests2/Makefile +3 −1
  8. win32/include/sys/stat.h +2 −2
  9. x86_64-gen.c +5 −6
tcc.c+3−1
@@ -182,8 +182,10 @@ static void print_search_dirs(TCCState *s) · 181 unmodified lines
182182 /* print_dirs("programs", NULL, 0); */
183183 print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
184184 print_dirs("libraries", s->library_paths, s->nb_library_paths);
185+#ifdef TCC_TARGET_PE
186+ printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", s->tcc_lib_path);
187+#else
185188 printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path);
186−#ifndef TCC_TARGET_PE
187189 print_dirs("crt", s->crt_paths, s->nb_crt_paths);
188190 printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
189191 #endif
tccelf.c+7−2
@@ -1364,6 +1364,8 @@ ST_FUNC void fill_got(TCCState *s1) · 1363 unmodified lines
13641364 static void fill_local_got_entries(TCCState *s1)
13651365 {
13661366 ElfW_Rel *rel;
1367+ if (!s1->got->reloc)
1368+ return;
13671369 for_each_elem(s1->got->reloc, 0, rel, ElfW_Rel) {
13681370 if (ELFW(R_TYPE)(rel->r_info) == R_RELATIVE) {
13691371 int sym_index = ELFW(R_SYM) (rel->r_info);
@@ -2443,8 +2445,11 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 1073 unmodified lines
24432445 a = (Stab_Sym *)(s->data + sm_table[stab_index].offset);
24442446 b = (Stab_Sym *)(s->data + s->data_offset);
24452447 o = sm_table[stabstr_index].offset;
2446− while (a < b)
2447− a->n_strx += o, a++;
2448+ while (a < b) {
2449+ if (a->n_strx)
2450+ a->n_strx += o;
2451+ a++;
2452+ }
24482453 }
24492454
24502455 /* second short pass to update sh_link and sh_info fields of new
tccgen.c+11−8
@@ -4294,7 +4294,6 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 4293 unmodified lines
42944294 type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
42954295 if ((pt.t & VT_BTYPE) == VT_VOID)
42964296 tcc_error("parameter declared as void");
4297− arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
42984297 } else {
42994298 n = tok;
43004299 if (n < TOK_UIDENT)
@@ -4303,6 +4302,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 2 unmodified lines
43034302 next();
43044303 }
43054304 convert_parameter_type(&pt);
4305+ arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
43064306 s = sym_push(n | SYM_FIELD, &pt, 0, 0);
43074307 *plast = s;
43084308 plast = &s->next;
@@ -6856,11 +6856,16 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 2547 unmodified lines
68566856 Sym *sym = NULL;
68576857 int saved_nocode_wanted = nocode_wanted;
68586858 #ifdef CONFIG_TCC_BCHECK
6859− int bcheck = tcc_state->do_bounds_check && !NODATA_WANTED;
6859+ int bcheck;
68606860 #endif
68616861
6862− if (type->t & VT_STATIC)
6863− nocode_wanted |= NODATA_WANTED ? 0x40000000 : 0x80000000;
6862+ /* Always allocate static or global variables */
6863+ if (v && (r & VT_VALMASK) == VT_CONST)
6864+ nocode_wanted |= 0x80000000;
6865+
6866+#ifdef CONFIG_TCC_BCHECK
6867+ bcheck = tcc_state->do_bounds_check && !NODATA_WANTED;
6868+#endif
68646869
68656870 flexible_array = NULL;
68666871 if ((type->t & VT_BTYPE) == VT_STRUCT) {
@@ -6926,7 +6931,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 59 unmodified lines
69266931 align = 1;
69276932 }
69286933
6929− if (NODATA_WANTED)
6934+ if (!v && NODATA_WANTED)
69306935 size = 0, align = 1;
69316936
69326937 if ((r & VT_VALMASK) == VT_LOCAL) {
@@ -7088,9 +7093,7 @@ static void gen_function(Sym *sym) · 155 unmodified lines
70887093 if (sym->a.aligned) {
70897094 size_t newoff = section_add(cur_text_section, 0,
70907095 1 << (sym->a.aligned - 1));
7091− if (ind != newoff)
7092− gen_fill_nops(newoff - ind);
7093− ind = newoff;
7096+ gen_fill_nops(newoff - ind);
70947097 }
70957098 /* NOTE: we patch the symbol size later */
70967099 put_extern_sym(sym, cur_text_section, ind, 0);
tccrun.c+20−24
@@ -169,9 +169,12 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 168 unmodified lines
169169 }
170170
171171 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
172+/* To avoid that x86 processors would reload cached instructions
173+ each time when data is written in the near, we need to make
174+ sure that code and data do not share the same 64 byte unit */
172175 #define RUN_SECTION_ALIGNMENT 63
173176 #else
174− #define RUN_SECTION_ALIGNMENT 15
177+ #define RUN_SECTION_ALIGNMENT 0
175178 #endif
176179
177180 /* relocate code. Return -1 on error, required size if ptr is NULL,
@@ -179,8 +182,8 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 1 unmodified line
179182 static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff)
180183 {
181184 Section *s;
182− unsigned offset, length, fill, i, k;
183− addr_t mem;
185+ unsigned offset, length, align, max_align, i, k, f;
186+ addr_t mem, addr;
184187
185188 if (NULL == ptr) {
186189 s1->nb_errors = 0;
@@ -195,39 +198,32 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff) · 8 unmodified lines
195198 return -1;
196199 }
197200
198− offset = 0, mem = (addr_t)ptr;
199− fill = -mem & RUN_SECTION_ALIGNMENT;
201+ offset = max_align = 0, mem = (addr_t)ptr;
200202 #ifdef _WIN64
201− offset += sizeof (void*);
203+ offset += sizeof (void*); /* space for function_table pointer */
202204 #endif
203205 for (k = 0; k < 2; ++k) {
206+ f = 0, addr = k ? mem : mem + ptr_diff;
204207 for(i = 1; i < s1->nb_sections; i++) {
205208 s = s1->sections[i];
206209 if (0 == (s->sh_flags & SHF_ALLOC))
207210 continue;
208211 if (k != !(s->sh_flags & SHF_EXECINSTR))
209212 continue;
210− offset += fill;
211− if (!mem)
212− s->sh_addr = 0;
213− else if (s->sh_flags & SHF_EXECINSTR)
214− s->sh_addr = mem + offset + ptr_diff;
215− else
216− s->sh_addr = mem + offset;
213+ align = s->sh_addralign - 1;
214+ if (++f == 1 && align < RUN_SECTION_ALIGNMENT)
215+ align = RUN_SECTION_ALIGNMENT;
216+ if (max_align < align)
217+ max_align = align;
218+ offset += -(addr + offset) & align;
219+ s->sh_addr = mem ? addr + offset : 0;
220+ offset += s->data_offset;
217221 #if 0
218222 if (mem)
219− printf("%-16s +%02lx %p %04x\n",
220− s->name, fill, (void*)s->sh_addr, (unsigned)s->data_offset);
223+ printf("%-16s %p len %04x align %2d\n",
224+ s->name, (void*)s->sh_addr, (unsigned)s->data_offset, align + 1);
221225 #endif
222− offset += s->data_offset;
223− fill = -(mem + offset) & 15;
224226 }
225−#if RUN_SECTION_ALIGNMENT > 15
226− /* To avoid that x86 processors would reload cached instructions each time
227− when data is written in the near, we need to make sure that code and data
228− do not share the same 64 byte unit */
229− fill = -(mem + offset) & RUN_SECTION_ALIGNMENT;
230−#endif
231227 }
232228
233229 /* relocate symbols */
@@ -236,7 +232,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff) · 2 unmodified lines
236232 return -1;
237233
238234 if (0 == mem)
239− return offset + RUN_SECTION_ALIGNMENT;
235+ return offset + max_align;
240236
241237 #ifdef TCC_TARGET_PE
242238 s1->pe_imagebase = mem;
tests/tests2/96_nodata_wanted.c+19−5
@@ -55,11 +55,10 @@ te0:; · 54 unmodified lines
5555 static char ds1 = 0;
5656 ts1:;
5757 if (!SKIP) {
58− static void *p = (void*)&main;
59− static char cc[] = "static string";
60− static double d = 8.0;
61−
62− static struct __attribute__((packed)) {
58+ void *p = (void*)&main;
59+ char cc[] = "static string";
60+ double d = 8.0;
61+ struct __attribute__((packed)) {
6362 unsigned x : 12;
6463 unsigned char y : 7;
6564 unsigned z : 28, a: 4, b: 5;
@@ -81,4 +80,19 @@ te1:; · 15 unmodified lines
8180 /*printf("# %d/%d\n", dl, tl);*/
8281 }
8382
83+#elif defined test_static_data
84+
85+#include <stdio.h>
86+int main(int argc, char **argv)
87+{
88+ goto there;
89+ if (0) {
90+ static int a = 1;
91+ printf("hello\n"); /* the "hello\n" string is still suppressed */
92+there:
93+ printf("a = %d\n", a);
94+ }
95+ return 0;
96+}
97+
8498 #endif
tests/tests2/96_nodata_wanted.expect+3−0
@@ -21,3 +21,6 @@ size of data/text: · 20 unmodified lines
2121 [test_data_suppression_on]
2222 size of data/text:
2323 zero/zero
24+
25+[test_static_data]
26+a = 1
tests/tests2/Makefile+3−1
@@ -3,7 +3,9 @@ include $(TOP)/Makefile · 2 unmodified lines
33 SRC = $(TOPSRC)/tests/tests2
44 VPATH = $(SRC)
55
6−TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c))))
6+TESTS = $(patsubst %.c,%.test,\
7+ $(sort $(notdir $(wildcard $(SRC)/??_*.c)))\
8+ $(sort $(notdir $(wildcard $(SRC)/???_*.c))))
79
810 # some tests do not pass on all platforms, remove them for now
911 SKIP = 34_array_assignment.test # array assignment is not in C standard
win32/include/sys/stat.h+2−2
@@ -81,9 +81,9 @@ extern "C" { · 80 unmodified lines
8181 #else
8282 #define _fstat _fstat64i32
8383 #define _fstati64 _fstat64
84−#define _stat _stat64i32
84+#define _stat _stat64
8585 #define _stati64 _stat64
86−#define _wstat _wstat64i32
86+#define _wstat _wstat64
8787 #define _wstati64 _wstat64
8888 #endif
8989
x86_64-gen.c+5−6
@@ -877,19 +877,18 @@ void gfunc_call(int nb_args) · 876 unmodified lines
877877 if (is_sse_float(vtop->type.t)) {
878878 if (tcc_state->nosse)
879879 tcc_error("SSE disabled");
880− gv(RC_XMM0); /* only use one float register */
881880 if (arg >= REGN) {
881+ gv(RC_XMM0);
882882 /* movq %xmm0, j*8(%rsp) */
883883 gen_offs_sp(0xd60f66, 0x100, arg*8);
884884 } else {
885− /* movaps %xmm0, %xmmN */
886− o(0x280f);
887− o(0xc0 + (arg << 3));
885+ /* Load directly to xmmN register */
886+ gv(RC_XMM0 << arg);
888887 d = arg_prepare_reg(arg);
889− /* mov %xmm0, %rxx */
888+ /* mov %xmmN, %rxx */
890889 o(0x66);
891890 orex(1,d,0, 0x7e0f);
892− o(0xc0 + REG_VALUE(d));
891+ o(0xc0 + arg*8 + REG_VALUE(d));
893892 }
894893 } else {
895894 if (bt == VT_STRUCT) {

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