Skip to content

Commit e41730f

Browse files
author
grischka
committed
- tcc -vv: show cross-libtcc1.a correctly (and more)
(As long as it is in the default install location and was not moved elsewhere into the library search path manually) Also: - libtcc.c: - error1(): show correct line with "In file included from ..." - support "tcc -Bxxx -vv" - tcc_new()/tcc_compile(): Don't create elf sections for tcc -E - tccdbg.c: - tcc -E -g : revert 1de025c Let's keep things simple, everybody understands 'do_debug' and dState is set by tcov too (but no debug sections). - tccgen.c: - avoid the extra parameter for gind() (from c3e3a07) - vla func params: use skip_or_save_block() and enable VT_LVAL (see 313855c) - cleanup nocode_wanted a bit - tccelf.c: - tccelf_end_file(): don't try to translate zero-sym relocs (seems to happen with asm "jmp 0x1000") - version_add(): do not make "ld-linux.so" DT_NEEDED
1 parent 414c22c commit e41730f

File tree

9 files changed

+137
-111
lines changed

9 files changed

+137
-111
lines changed

libtcc.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static void error1(int mode, const char *fmt, va_list ap)
572572
if (f) {
573573
for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
574574
cstr_printf(&cs, "In file included from %s:%d:\n",
575-
(*pf)->filename, (*pf)->line_num);
575+
(*pf)->filename, (*pf)->line_num - 1);
576576
cstr_printf(&cs, "%s:%d: ",
577577
f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
578578
} else if (s1->current_filename) {
@@ -733,24 +733,25 @@ static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
733733
file->fd = fd;
734734
}
735735

736-
tccelf_begin_file(s1);
737736
preprocess_start(s1, filetype);
738737
tccgen_init(s1);
738+
739739
if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
740740
tcc_preprocess(s1);
741-
} else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
742-
tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
743741
} else {
744-
tccgen_compile(s1);
742+
tccelf_begin_file(s1);
743+
if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
744+
tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
745+
} else {
746+
tccgen_compile(s1);
747+
}
748+
tccelf_end_file(s1);
745749
}
746750
}
747751
tccgen_finish(s1);
748752
preprocess_end(s1);
749-
750753
s1->error_set_jmp_enabled = 0;
751754
tcc_exit_state(s1);
752-
753-
tccelf_end_file(s1);
754755
return s1->nb_errors != 0 ? -1 : 0;
755756
}
756757

@@ -819,8 +820,6 @@ LIBTCCAPI TCCState *tcc_new(void)
819820
/* might be used in error() before preprocess_start() */
820821
s->include_stack_ptr = s->include_stack;
821822

822-
tccelf_new(s);
823-
824823
tcc_set_lib_path(s, CONFIG_TCCDIR);
825824
return s;
826825
}
@@ -879,19 +878,23 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
879878
tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
880879
}
881880

882-
if (output_type == TCC_OUTPUT_PREPROCESS)
881+
if (output_type == TCC_OUTPUT_PREPROCESS) {
882+
s->do_debug = 0;
883883
return 0;
884+
}
884885

886+
tccelf_new(s);
887+
if (s->do_debug) {
888+
/* add debug sections */
889+
tcc_debug_new(s);
890+
}
885891
#ifdef CONFIG_TCC_BCHECK
886892
if (s->do_bounds_check) {
887893
/* if bound checking, then add corresponding sections */
888894
tccelf_bounds_new(s);
889895
}
890896
#endif
891-
if (s->do_debug) {
892-
/* add debug sections */
893-
tcc_debug_new(s);
894-
}
897+
895898
if (output_type == TCC_OUTPUT_OBJ) {
896899
/* always elf for objects */
897900
s->output_format = TCC_OUTPUT_FORMAT_ELF;
@@ -1195,11 +1198,9 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
11951198
/* find [cross-]libtcc1.a and tcc helper objects in library path */
11961199
ST_FUNC void tcc_add_support(TCCState *s1, const char *filename)
11971200
{
1198-
#ifdef CONFIG_TCC_CROSSPREFIX
11991201
char buf[100];
1200-
snprintf(buf, sizeof buf, "%s%s", CONFIG_TCC_CROSSPREFIX, filename);
1201-
filename = buf;
1202-
#endif
1202+
if (CONFIG_TCC_CROSSPREFIX[0])
1203+
filename = strcat(strcpy(buf, CONFIG_TCC_CROSSPREFIX), filename);
12031204
if (tcc_add_dll(s1, filename, 0) < 0)
12041205
tcc_error_noabort("%s not found", filename);
12051206
}
@@ -1838,6 +1839,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
18381839
case TCC_OPTION_B:
18391840
/* set tcc utilities path (mainly for tcc development) */
18401841
tcc_set_lib_path(s, optarg);
1842+
++noaction;
18411843
break;
18421844
case TCC_OPTION_l:
18431845
args_parser_add_file(s, optarg, AFF_TYPE_LIB | (s->filetype & ~AFF_TYPE_MASK));

tcc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,8 @@ static void print_search_dirs(TCCState *s)
206206
/* print_dirs("programs", NULL, 0); */
207207
print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
208208
print_dirs("libraries", s->library_paths, s->nb_library_paths);
209-
#ifdef TCC_TARGET_PE
210-
printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", s->tcc_lib_path);
211-
#else
212-
printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path);
209+
printf("libtcc1:\n %s/%s\n", s->library_paths[0], CONFIG_TCC_CROSSPREFIX TCC_LIBTCC1);
210+
#ifndef TCC_TARGET_PE
213211
print_dirs("crt", s->crt_paths, s->nb_crt_paths);
214212
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
215213
#endif
@@ -281,7 +279,7 @@ int main(int argc0, char **argv0)
281279
redo:
282280
argc = argc0, argv = argv0;
283281
s = s1 = tcc_new();
284-
#ifdef CONFIG_TCC_SWITCHES
282+
#ifdef CONFIG_TCC_SWITCHES /* predefined options */
285283
tcc_set_options(s, CONFIG_TCC_SWITCHES);
286284
#endif
287285
opt = tcc_parse_args(s, &argc, &argv, 1);

tcc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ extern long double strtold (const char *__nptr, char **__endptr);
361361
# define TCC_LIBTCC1 "libtcc1.a"
362362
#endif
363363

364+
#ifndef CONFIG_TCC_CROSSPREFIX
365+
# define CONFIG_TCC_CROSSPREFIX ""
366+
#endif
367+
364368
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
365369
#if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
366370
#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"

tccdbg.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ ST_FUNC void tcc_debug_start(TCCState *s1)
666666
ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
667667
SHN_ABS, filename);
668668

669-
if (s1->dState) {
669+
if (s1->do_debug) {
670670

671671
new_file = last_line_num = 0;
672672
debug_next_type = N_DEFAULT_DEBUG;
@@ -835,7 +835,7 @@ ST_FUNC void tcc_debug_start(TCCState *s1)
835835
/* put end of translation unit info */
836836
ST_FUNC void tcc_debug_end(TCCState *s1)
837837
{
838-
if (!s1->dState)
838+
if (!s1->do_debug)
839839
return;
840840
if (s1->dwarf) {
841841
int i, j;
@@ -992,7 +992,7 @@ ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename)
992992
if (0 == strcmp(file->filename, filename))
993993
return;
994994
pstrcpy(file->filename, sizeof(file->filename), filename);
995-
if (!s1->dState)
995+
if (!s1->do_debug)
996996
return;
997997
if (s1->dwarf)
998998
dwarf_file(s1);
@@ -1002,7 +1002,7 @@ ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename)
10021002
/* begin of #include */
10031003
ST_FUNC void tcc_debug_bincl(TCCState *s1)
10041004
{
1005-
if (!s1->dState)
1005+
if (!s1->do_debug)
10061006
return;
10071007
if (s1->dwarf) {
10081008
int i, j;
@@ -1059,7 +1059,7 @@ ST_FUNC void tcc_debug_bincl(TCCState *s1)
10591059
/* end of #include */
10601060
ST_FUNC void tcc_debug_eincl(TCCState *s1)
10611061
{
1062-
if (!s1->dState)
1062+
if (!s1->do_debug)
10631063
return;
10641064
if (s1->dwarf)
10651065
dwarf_file(s1);
@@ -1073,7 +1073,7 @@ ST_FUNC void tcc_debug_line(TCCState *s1)
10731073
{
10741074
BufferedFile *f;
10751075

1076-
if (!s1->dState)
1076+
if (!s1->do_debug)
10771077
return;
10781078
if (cur_text_section != text_section)
10791079
return;
@@ -1161,7 +1161,7 @@ static void tcc_debug_stabs (TCCState *s1, const char *str, int type, unsigned l
11611161

11621162
ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value)
11631163
{
1164-
if (!s1->dState)
1164+
if (!s1->do_debug)
11651165
return;
11661166
if (type == N_LBRAC) {
11671167
struct _debug_info *info =
@@ -1234,7 +1234,7 @@ ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t)
12341234
{
12351235
int i, j, debug_type;
12361236

1237-
if (!s1->dState || !s1->dwarf || debug_info)
1237+
if (!s1->do_debug || !s1->dwarf || debug_info)
12381238
return;
12391239
if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1)
12401240
for (i = 0; i < n_debug_anon_hash; i++)
@@ -1747,7 +1747,7 @@ static void tcc_debug_finish (TCCState *s1, struct _debug_info *cur)
17471747
ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e)
17481748
{
17491749
CString debug_str;
1750-
if (!s1->dState)
1750+
if (!s1->do_debug)
17511751
return;
17521752
cstr_new (&debug_str);
17531753
for (; s != e; s = s->prev) {
@@ -1777,7 +1777,7 @@ ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym)
17771777
CString debug_str;
17781778
BufferedFile *f;
17791779

1780-
if (!s1->dState)
1780+
if (!s1->do_debug)
17811781
return;
17821782
debug_info_root = NULL;
17831783
debug_info = NULL;
@@ -1816,7 +1816,7 @@ ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym)
18161816
/* put function size */
18171817
ST_FUNC void tcc_debug_funcend(TCCState *s1, int size)
18181818
{
1819-
if (!s1->dState)
1819+
if (!s1->do_debug)
18201820
return;
18211821
tcc_debug_line(s1);
18221822
tcc_debug_stabn(s1, N_RBRAC, size);
@@ -1873,7 +1873,7 @@ ST_FUNC void tcc_debug_funcend(TCCState *s1, int size)
18731873

18741874
ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type)
18751875
{
1876-
if (!s1->dState)
1876+
if (!s1->do_debug)
18771877
return;
18781878
if (sym_type == STT_FUNC || sym->v >= SYM_FIRST_ANOM)
18791879
return;
@@ -1925,7 +1925,7 @@ ST_FUNC void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bi
19251925

19261926
ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym)
19271927
{
1928-
if (!s1->dState)
1928+
if (!s1->do_debug)
19291929
return;
19301930
if (s1->dwarf) {
19311931
int debug_type;

tccelf.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ ST_FUNC void tccelf_end_file(TCCState *s1)
187187
ElfW_Rel *rel_end = (ElfW_Rel*)(sr->data + sr->data_offset);
188188
for (; rel < rel_end; ++rel) {
189189
int n = ELFW(R_SYM)(rel->r_info) - first_sym;
190-
//if (n < 0) tcc_error("internal: invalid symbol index in relocation");
190+
if (n < 0) /* zero sym_index in reloc (can happen with asm) */
191+
continue;
191192
rel->r_info = ELFW(R_INFO)(tr[n], ELFW(R_TYPE)(rel->r_info));
192193
}
193194
}
@@ -596,8 +597,14 @@ version_add (TCCState *s1)
596597
ElfW(Vernaux) *vna = 0;
597598
if (sv->out_index < 1)
598599
continue;
600+
599601
/* make sure that a DT_NEEDED tag is put */
600-
tcc_add_dllref(s1, sv->lib, 0);
602+
/* abitest-tcc fails on older i386-linux with "ld-linux.so.2" DT_NEEDED
603+
ret_int_test... Inconsistency detected by ld.so: dl-minimal.c: 148:
604+
realloc: Assertion `ptr == alloc_last_block' failed! */
605+
if (strcmp(sv->lib, "ld-linux.so.2"))
606+
tcc_add_dllref(s1, sv->lib, 0);
607+
601608
vnofs = section_add(verneed_section, sizeof(*vn), 1);
602609
vn = (ElfW(Verneed)*)(verneed_section->data + vnofs);
603610
vn->vn_version = 1;

0 commit comments

Comments
 (0)