Skip to content

Commit fe038f0

Browse files
committed
Merge branch 'mob'
2 parents 46c0c2e + ef7e844 commit fe038f0

File tree

16 files changed

+412
-324
lines changed

16 files changed

+412
-324
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
run: ./configure && make && make test -k
1515

1616
test-x86_64-osx:
17-
runs-on: macos-12
17+
runs-on: macos-13
1818
timeout-minutes: 2
1919
steps:
2020
- uses: actions/checkout@v4

lib/Makefile

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ include $(TOP)/Makefile
77
VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
88
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
99
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
10+
XCFG = $(or $(findstring -win,$T),-unx)
11+
S = $(if $(findstring yes,$(SILENT)),@$(info * $@))
1012

1113
TCC = $(TOP)/$(X)tcc$(EXESUF)
1214
XTCC ?= $(TOP)/$(X)tcc$(EXESUF)
@@ -16,8 +18,6 @@ XFLAGS-unx = -B$(TOPSRC)
1618
XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include
1719
XFLAGS = $(XFLAGS$(XCFG)) -I$(TOP)
1820
BFLAGS = -bt
19-
XCFG = $(or $(findstring -win,$T),-unx)
20-
S = $(if $(findstring yes,$(SILENT)),@$(info * $@))
2121

2222
# in order to use gcc, type: make <target>-libtcc1-usegcc=yes
2323
arm-libtcc1-usegcc ?= no
@@ -29,47 +29,48 @@ arm-libtcc1-usegcc ?= no
2929
ifeq "$($(T)-libtcc1-usegcc)" "yes"
3030
XCC = $(CC)
3131
XAR = $(AR)
32-
XFLAGS = $(CFLAGS) -fPIC -gdwarf -fno-omit-frame-pointer -Wno-unused-function -Wno-unused-variable
33-
BFLAGS = -g
32+
XFLAGS = $(CFLAGS) -fPIC -fno-omit-frame-pointer -Wno-unused-function -Wno-unused-variable
33+
BFLAGS = $(if $(CONFIG_dwarf),-gdwarf,-gstabs)
3434
endif
3535

36-
ifneq ($(CONFIG_backtrace),no)
37-
# only for native compiler
38-
ifneq ($(CONFIG_bcheck),no)
39-
$(X)BCHECK_O = bcheck.o
40-
endif
41-
$(X)BT_O = bt-exe.o bt-log.o
42-
$(X)B_O = $(BCHECK_O) bt-exe.o bt-log.o bt-dll.o
43-
endif
44-
$(X)BT_O += runmain.o tcov.o
36+
I386_O = libtcc1.o alloca.o alloca-bt.o $(COMMON_O)
37+
X86_64_O = libtcc1.o alloca.o alloca-bt.o $(COMMON_O)
38+
ARM_O = libtcc1.o armeabi.o alloca.o armflush.o $(COMMON_O)
39+
ARM64_O = lib-arm64.o $(COMMON_O)
40+
RISCV64_O = lib-arm64.o $(COMMON_O)
41+
COMMON_O = stdatomic.o atomic.o builtin.o
42+
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
43+
LIN_O = dsohandle.o
44+
OSX_O =
45+
46+
# backtrace/bcheck/run only for native compiler
47+
Nat = $(if $X,no,)
48+
Cbt = $(Nat)$(subst yes,,$(CONFIG_backtrace))
49+
Cbc = $(Cbt)$(subst yes,,$(CONFIG_bcheck))
4550

46-
DSO_O = dsohandle.o
51+
$(Nat)COMMON_O += runmain.o tcov.o
52+
$(Cbt)COMMON_O += bt-exe.o bt-log.o
53+
$(Cbt)WIN_O += bt-dll.o
54+
$(Cbc)COMMON_O += bcheck.o
4755

4856
# not in libtcc1.a
4957
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
5058

51-
I386_O = libtcc1.o alloca.o alloca-bt.o stdatomic.o atomic.o builtin.o $(BT_O)
52-
X86_64_O = libtcc1.o alloca.o alloca-bt.o stdatomic.o atomic.o builtin.o $(BT_O)
53-
ARM_O = libtcc1.o armeabi.o alloca.o armflush.o stdatomic.o atomic.o builtin.o $(BT_O)
54-
ARM64_O = lib-arm64.o stdatomic.o atomic.o builtin.o $(BT_O)
55-
RISCV64_O = lib-arm64.o stdatomic.o atomic.o builtin.o $(BT_O)
56-
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
57-
58-
OBJ-i386 = $(I386_O) $(BCHECK_O) $(DSO_O)
59-
OBJ-x86_64 = $(X86_64_O) va_list.o $(BCHECK_O) $(DSO_O)
60-
OBJ-x86_64-osx = $(X86_64_O) va_list.o $(BCHECK_O)
61-
OBJ-i386-win32 = $(I386_O) chkstk.o $(B_O) $(WIN_O)
62-
OBJ-x86_64-win32 = $(X86_64_O) chkstk.o $(B_O) $(WIN_O)
63-
OBJ-arm64 = $(ARM64_O) $(BCHECK_O) $(DSO_O)
64-
OBJ-arm64-osx = $(ARM64_O) $(BCHECK_O)
65-
OBJ-arm = $(ARM_O) $(BCHECK_O) $(DSO_O)
66-
OBJ-arm-fpa = $(ARM_O) $(DSO_O)
67-
OBJ-arm-fpa-ld = $(ARM_O) $(DSO_O)
68-
OBJ-arm-vfp = $(ARM_O) $(DSO_O)
69-
OBJ-arm-eabi = $(ARM_O) $(DSO_O)
70-
OBJ-arm-eabihf = $(ARM_O) $(DSO_O)
59+
OBJ-i386 = $(I386_O) $(LIN_O)
60+
OBJ-x86_64 = $(X86_64_O) va_list.o $(LIN_O)
61+
OBJ-x86_64-osx = $(X86_64_O) va_list.o $(OSX_O)
62+
OBJ-i386-win32 = $(I386_O) chkstk.o $(WIN_O)
63+
OBJ-x86_64-win32 = $(X86_64_O) chkstk.o $(WIN_O)
64+
OBJ-arm64 = $(ARM64_O) $(LIN_O)
65+
OBJ-arm64-osx = $(ARM64_O) $(OSX_O)
66+
OBJ-arm = $(ARM_O) $(LIN_O)
67+
OBJ-arm-fpa = $(OBJ-arm)
68+
OBJ-arm-fpa-ld = $(OBJ-arm)
69+
OBJ-arm-vfp = $(OBJ-arm)
70+
OBJ-arm-eabi = $(OBJ-arm)
71+
OBJ-arm-eabihf = $(OBJ-arm)
7172
OBJ-arm-wince = $(ARM_O) $(WIN_O)
72-
OBJ-riscv64 = $(RISCV64_O) $(BCHECK_O) $(DSO_O)
73+
OBJ-riscv64 = $(RISCV64_O) $(LIN_O)
7374

7475
OBJ-extra = $(filter $(EXTRA_O),$(OBJ-$T))
7576
OBJ-libtcc1 = $(addprefix $(X),$(filter-out $(OBJ-extra),$(OBJ-$T)))

libtcc.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ static void error1(int mode, const char *fmt, va_list ap)
567567
BufferedFile **pf, *f;
568568
TCCState *s1 = tcc_state;
569569
CString cs;
570+
int line = 0;
570571

571572
tcc_exit_state(s1);
572573

@@ -589,6 +590,8 @@ static void error1(int mode, const char *fmt, va_list ap)
589590
}
590591

591592
cstr_new(&cs);
593+
if (fmt[0] == '%' && fmt[1] == 'i' && fmt[2] == ':')
594+
line = va_arg(ap, int), fmt += 3;
592595
f = NULL;
593596
if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */
594597
/* use upper file if inline ":asm:" or token ":paste:" */
@@ -599,8 +602,9 @@ static void error1(int mode, const char *fmt, va_list ap)
599602
for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
600603
cstr_printf(&cs, "In file included from %s:%d:\n",
601604
(*pf)->filename, (*pf)->line_num - 1);
602-
cstr_printf(&cs, "%s:%d: ",
603-
f->filename, f->line_num - ((tok_flags & TOK_FLAG_BOL) && !macro_ptr));
605+
if (0 == line)
606+
line = f->line_num - ((tok_flags & TOK_FLAG_BOL) && !macro_ptr);
607+
cstr_printf(&cs, "%s:%d: ", f->filename, line);
604608
} else if (s1->current_filename) {
605609
cstr_printf(&cs, "%s: ", s1->current_filename);
606610
} else {
@@ -818,6 +822,7 @@ LIBTCCAPI TCCState *tcc_new(void)
818822
s->warn_implicit_function_declaration = 1;
819823
s->warn_discarded_qualifiers = 1;
820824
s->ms_extensions = 1;
825+
s->unwind_tables = 1;
821826

822827
#ifdef CHAR_IS_UNSIGNED
823828
s->char_is_unsigned = 1;
@@ -999,6 +1004,8 @@ static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size)
9991004
}
10001005
#endif
10011006

1007+
static int guess_filetype(const char *filename);
1008+
10021009
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
10031010
{
10041011
int fd, ret = -1;
@@ -1009,6 +1016,9 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
10091016
filename = buf;
10101017
#endif
10111018

1019+
if (0 == (flags & AFF_TYPE_MASK))
1020+
flags |= guess_filetype(filename);
1021+
10121022
/* ignore binary files with -E */
10131023
if (s1->output_type == TCC_OUTPUT_PREPROCESS
10141024
&& (flags & AFF_TYPE_BIN))
@@ -1118,10 +1128,10 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
11181128
return ret;
11191129
}
11201130

1121-
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
1131+
static int guess_filetype(const char *filename)
11221132
{
1123-
int filetype = s->filetype;
1124-
if (0 == (filetype & AFF_TYPE_MASK)) {
1133+
int filetype = 0;
1134+
if (1) {
11251135
/* use a file extension to detect a filetype */
11261136
const char *ext = tcc_fileextension(filename);
11271137
if (ext[0]) {
@@ -1140,7 +1150,12 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
11401150
filetype = AFF_TYPE_C;
11411151
}
11421152
}
1143-
return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR);
1153+
return filetype;
1154+
}
1155+
1156+
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
1157+
{
1158+
return tcc_add_file_internal(s, filename, s->filetype | AFF_PRINT_ERROR);
11441159
}
11451160

11461161
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
@@ -1157,12 +1172,12 @@ static int tcc_add_library_internal(TCCState *s1, const char *fmt,
11571172

11581173
for(i = 0; i < nb_paths; i++) {
11591174
snprintf(buf, sizeof(buf), fmt, paths[i], filename);
1160-
ret = tcc_add_file_internal(s1, buf, (flags & ~AFF_PRINT_ERROR) | AFF_TYPE_BIN);
1175+
ret = tcc_add_file_internal(s1, buf, flags & ~AFF_PRINT_ERROR);
11611176
if (ret != FILE_NOT_FOUND)
11621177
return ret;
11631178
}
11641179
if (flags & AFF_PRINT_ERROR)
1165-
tcc_error_noabort("file '%s' not found", filename);
1180+
tcc_error_noabort("library '%s' not found", filename);
11661181
return FILE_NOT_FOUND;
11671182
}
11681183

@@ -1214,23 +1229,15 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
12141229
return ret;
12151230
++pp;
12161231
}
1217-
return FILE_NOT_FOUND;
1218-
}
1219-
1220-
PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname)
1221-
{
1222-
int ret = tcc_add_library(s1, libname);
1223-
if (ret == FILE_NOT_FOUND)
1224-
tcc_error_noabort("library '%s' not found", libname);
1225-
return ret;
1232+
return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR);
12261233
}
12271234

12281235
/* handle #pragma comment(lib,) */
12291236
ST_FUNC void tcc_add_pragma_libs(TCCState *s1)
12301237
{
12311238
int i;
12321239
for (i = 0; i < s1->nb_pragma_libs; i++)
1233-
tcc_add_library_err(s1, s1->pragma_libs[i]);
1240+
tcc_add_library(s1, s1->pragma_libs[i]);
12341241
}
12351242

12361243
LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val)
@@ -1669,6 +1676,9 @@ static const FlagDef options_f[] = {
16691676
{ offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
16701677
{ offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers" },
16711678
{ offsetof(TCCState, test_coverage), 0, "test-coverage" },
1679+
{ offsetof(TCCState, reverse_funcargs), 0, "reverse-funcargs" },
1680+
{ offsetof(TCCState, gnu89_inline), 0, "gnu89-inline" },
1681+
{ offsetof(TCCState, unwind_tables), 0, "asynchronous-unwind-tables" },
16721682
{ 0, 0, NULL }
16731683
};
16741684

tcc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ static const char help2[] =
115115
" leading-underscore decorate extern symbols\n"
116116
" ms-extensions allow anonymous struct in struct\n"
117117
" dollars-in-identifiers allow '$' in C symbols\n"
118+
" reverse-funcargs evaluate function arguments right to left\n"
119+
" gnu89-inline 'extern inline' is like 'static inline'\n"
120+
" asynchronous-unwind-tables create eh_frame section [on]\n"
118121
" test-coverage create code coverage code\n"
119122
"-m... target specific options:\n"
120123
" ms-bitfields use MSVC bitfield layout\n"
@@ -363,7 +366,7 @@ int main(int argc0, char **argv0)
363366
struct filespec *f = s->files[n];
364367
s->filetype = f->type;
365368
if (f->type & AFF_TYPE_LIB) {
366-
ret = tcc_add_library_err(s, f->name);
369+
ret = tcc_add_library(s, f->name);
367370
} else {
368371
if (1 == s->verbose)
369372
printf("-> %s\n", f->name);
@@ -389,17 +392,17 @@ int main(int argc0, char **argv0)
389392
} else {
390393
if (!s->outfile)
391394
s->outfile = default_outputfile(s, first_file);
392-
if (!s->just_deps && tcc_output_file(s, s->outfile))
393-
;
394-
else if (s->gen_deps)
395+
if (!s->just_deps)
396+
ret = tcc_output_file(s, s->outfile);
397+
if (!ret && s->gen_deps)
395398
gen_makedeps(s, s->outfile, s->deps_outfile);
396399
}
397400
}
398401

399402
done = 1;
400403
if (t)
401404
done = 0; /* run more tests with -dt -run */
402-
else if (s->nb_errors)
405+
else if (ret)
403406
ret = 1;
404407
else if (n < s->nb_files)
405408
done = 0; /* compile more files with -c */

tcc.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,16 @@ typedef struct Sym {
564564
union {
565565
int sym_scope; /* scope level for locals */
566566
int jnext; /* next jump label */
567+
int jind; /* label position */
567568
struct FuncAttr f; /* function attributes */
568569
int auxtype; /* bitfield access type */
569570
};
570571
};
571572
long long enum_val; /* enum constant if IS_ENUM_VAL */
572573
int *d; /* define token stream */
573-
struct Sym *ncl; /* next cleanup */
574+
struct Sym *cleanup_func;
574575
};
576+
575577
CType type; /* associated type */
576578
union {
577579
struct Sym *next; /* next related symbol (for fields and anoms) */
@@ -774,6 +776,9 @@ struct TCCState {
774776
unsigned char ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
775777
unsigned char dollars_in_identifiers; /* allows '$' char in identifiers */
776778
unsigned char ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
779+
unsigned char reverse_funcargs; /* if true, evaluate last function arg first */
780+
unsigned char gnu89_inline; /* treat 'extern inline' like 'static inline' */
781+
unsigned char unwind_tables; /* create eh_frame section */
777782

778783
/* warning switches */
779784
unsigned char warn_none;
@@ -969,8 +974,6 @@ struct TCCState {
969974
int uw_sym;
970975
unsigned uw_offs;
971976
# endif
972-
#else
973-
unsigned shf_RELRO; /* section flags for RELRO sections */
974977
#endif
975978

976979
#if defined TCC_TARGET_MACHO
@@ -1488,9 +1491,9 @@ ST_FUNC void vpushi(int v);
14881491
ST_FUNC void vpushv(SValue *v);
14891492
ST_FUNC void vpushsym(CType *type, Sym *sym);
14901493
ST_FUNC void vswap(void);
1491-
ST_FUNC void vrote(SValue *e, int n);
14921494
ST_FUNC void vrott(int n);
14931495
ST_FUNC void vrotb(int n);
1496+
ST_FUNC void vrev(int n);
14941497
ST_FUNC void vpop(void);
14951498
#if PTR_SIZE == 4
14961499
ST_FUNC void lexpand(void);
@@ -1869,10 +1872,6 @@ ST_FUNC int gen_makedeps(TCCState *s, const char *target, const char *filename);
18691872

18701873
/* ------------ tccdbg.c ------------ */
18711874

1872-
ST_FUNC void tcc_eh_frame_start(TCCState *s1);
1873-
ST_FUNC void tcc_eh_frame_end(TCCState *s1);
1874-
ST_FUNC void tcc_eh_frame_hdr(TCCState *s1, int final);
1875-
18761875
ST_FUNC void tcc_debug_new(TCCState *s);
18771876

18781877
ST_FUNC void tcc_debug_start(TCCState *s1);
@@ -1891,6 +1890,13 @@ ST_FUNC void tcc_debug_typedef(TCCState *s1, Sym *sym);
18911890
ST_FUNC void tcc_debug_stabn(TCCState *s1, int type, int value);
18921891
ST_FUNC void tcc_debug_fix_anon(TCCState *s1, CType *t);
18931892

1893+
#if !(defined ELF_OBJ_ONLY || defined TCC_TARGET_ARM || defined TARGETOS_BSD)
1894+
ST_FUNC void tcc_eh_frame_start(TCCState *s1);
1895+
ST_FUNC void tcc_eh_frame_end(TCCState *s1);
1896+
ST_FUNC void tcc_eh_frame_hdr(TCCState *s1, int final);
1897+
#define TCC_EH_FRAME 1
1898+
#endif
1899+
18941900
ST_FUNC void tcc_tcov_start(TCCState *s1);
18951901
ST_FUNC void tcc_tcov_end(TCCState *s1);
18961902
ST_FUNC void tcc_tcov_check_line(TCCState *s1, int start);

0 commit comments

Comments
 (0)