diff --git a/libtcc.c b/libtcc.c index c532f1c2..4e42c363 100644 --- a/libtcc.c +++ b/libtcc.c @@ -508,15 +508,13 @@ static void error1(int mode, const char *fmt, va_list ap) BufferedFile **pf, *f; TCCState *s1 = tcc_state; - /* 's1->error_set_jmp_enabled' means that we're called from - within the parser/generator and 'tcc_state' was already - set (i.e. not by the function above). + buf[0] = '\0'; + if (s1 == NULL) + /* can happen only if called from tcc_malloc(): 'out of memory' */ + goto no_file; - Otherwise, 's1 = NULL' means we're called because of severe - problems from tcc_malloc() which under normal conditions - should never happen. */ - - if (s1 && !s1->error_set_jmp_enabled) { + if (!s1->error_set_jmp_enabled) { + /* tcc_state just was set by tcc_enter_state() */ tcc_state = NULL; POST_SEM(); } @@ -528,24 +526,25 @@ static void error1(int mode, const char *fmt, va_list ap) mode = ERROR_ERROR; } - buf[0] = '\0'; - /* use upper file if inline ":asm:" or token ":paste:" */ - for (f = file; f && f->filename[0] == ':'; f = f->prev) - ; + f = NULL; + if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */ + /* use upper file if inline ":asm:" or token ":paste:" */ + for (f = file; f && f->filename[0] == ':'; f = f->prev) + ; + } if (f) { for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++) strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n", (*pf)->filename, (*pf)->line_num); - if (s1->error_set_jmp_enabled) { - strcat_printf(buf, sizeof(buf), "%s:%d: ", - f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); - } else { - strcat_printf(buf, sizeof(buf), "%s: ", - f->filename); - } - } else { - strcat_printf(buf, sizeof(buf), "tcc: "); + strcat_printf(buf, sizeof(buf), "%s:%d: ", + f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL)); + } else if (s1->current_filename) { + strcat_printf(buf, sizeof(buf), "%s: ", s1->current_filename); } + +no_file: + if (0 == buf[0]) + strcat_printf(buf, sizeof(buf), "tcc: "); if (mode == ERROR_WARN) strcat_printf(buf, sizeof(buf), "warning: "); else @@ -1071,10 +1070,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) return -1; } - /* update target deps */ - dynarray_add(&s1->target_deps, &s1->nb_target_deps, - tcc_strdup(filename)); - + s1->current_filename = filename; if (flags & AFF_TYPE_BIN) { ElfW(Ehdr) ehdr; int obj_type; @@ -1126,8 +1122,11 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) } close(fd); } else { + /* update target deps */ + dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename)); ret = tcc_compile(s1, flags, filename, fd); } + s1->current_filename = NULL; return ret; } diff --git a/tcc.h b/tcc.h index 5cb9f576..b6166198 100644 --- a/tcc.h +++ b/tcc.h @@ -911,6 +911,9 @@ struct TCCState { /* option -dnum (for general development purposes) */ int g_debug; + /* for warnings/errors for object files*/ + const char *current_filename; + /* used by main and tcc_parse_args only */ struct filespec **files; /* files seen on command line */ int nb_files; /* number thereof */ diff --git a/tccelf.c b/tccelf.c index fec53a28..558846c1 100644 --- a/tccelf.c +++ b/tccelf.c @@ -3125,7 +3125,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) /* test CPU specific stuff */ if (ehdr.e_ident[5] != ELFDATA2LSB || ehdr.e_machine != EM_TCC_TARGET) { - tcc_error_noabort("bad architecture: %s", filename); + tcc_error_noabort("bad architecture"); return -1; } diff --git a/tccpe.c b/tccpe.c index 0fb2480a..d5242946 100644 --- a/tccpe.c +++ b/tccpe.c @@ -861,7 +861,7 @@ static void pe_build_imports(struct pe_info *pe) v = (ADDR3264)GetProcAddress(dllref->handle, ordinal?(char*)0+ordinal:name); } if (!v) - tcc_error_noabort("can't build symbol '%s'", name); + tcc_error_noabort("could not resolve symbol '%s'", name); } else #endif if (ordinal) { diff --git a/tccpp.c b/tccpp.c index 1c2c8bc9..a7df1f11 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1808,7 +1808,7 @@ ST_FUNC void preprocess(int is_bof) tcc_error("#include recursion too deep"); /* push current file on stack */ *s1->include_stack_ptr++ = file; - i = tok == TOK_INCLUDE_NEXT ? file->include_next_index: 0; + i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0; n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; for (; i < n; ++i) { char buf1[sizeof file->filename]; @@ -1851,14 +1851,19 @@ ST_FUNC void preprocess(int is_bof) if (tcc_open(s1, buf1) < 0) continue; - file->include_next_index = i + 1; + file->include_next_index = i; #ifdef INC_DEBUG printf("%s: including %s\n", file->prev->filename, file->filename); #endif /* update target deps */ if (s1->gen_deps) { - dynarray_add(&s1->target_deps, &s1->nb_target_deps, - tcc_strdup(buf1)); + BufferedFile *bf = file; + while (i == 1 && (bf = bf->prev)) + i = bf->include_next_index; + /* skip system include files */ + if (n - i > s1->nb_sysinclude_paths) + dynarray_add(&s1->target_deps, &s1->nb_target_deps, + tcc_strdup(buf1)); } /* add include file debug info */ tcc_debug_bincl(tcc_state); @@ -3866,8 +3871,10 @@ ST_FUNC int tcc_preprocess(TCCState *s1) s1->dflag &= ~1; } - token_seen = TOK_LINEFEED, spcs = 0; - pp_line(s1, file, 0); + token_seen = TOK_LINEFEED, spcs = 0, level = 0; + if (file->prev) + pp_line(s1, file->prev, level++); + pp_line(s1, file, level); for (;;) { iptr = s1->include_stack_ptr; next(); diff --git a/tcctools.c b/tcctools.c index d696d66b..7b6988c0 100644 --- a/tcctools.c +++ b/tcctools.c @@ -519,7 +519,7 @@ ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename { FILE *depout; char buf[1024]; - int i; + int i, k; if (!filename) { /* compute filename automatically: dir/file.o -> dir/file.d */ @@ -535,10 +535,14 @@ ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename depout = fopen(filename, "w"); if (!depout) tcc_error("could not open '%s'", filename); - - fprintf(depout, "%s: \\\n", target); - for (i=0; inb_target_deps; ++i) - fprintf(depout, " %s \\\n", s1->target_deps[i]); + fprintf(depout, "%s:", target); + for (i = 0; inb_target_deps; ++i) { + for (k = 0; k < i; ++k) + if (0 == strcmp(s1->target_deps[i], s1->target_deps[k])) + goto next; + fprintf(depout, " \\\n %s", s1->target_deps[i]); + next:; + } fprintf(depout, "\n"); fclose(depout); }