tccrun: exit() via rt_longjmp()

- new LIBTCC API tcc_setjmp() to allow longjmps & signals
  from compiled code back to libtcc per TCCState
- new LIBTCC API tcc_set_backtrace_func() to handle backtrace output
- move c/dtor/atexit stuff to runtime (lib/runmain.c)
- move bt-log.o into libtcc1.a
- add timeouts to github action (beware, it did happen to hang
  infinitely in the signal handler at some point)
This commit is contained in:
grischka
2024-02-14 10:00:22 +01:00
parent 8d8d75ca75
commit c88b19966c
16 changed files with 395 additions and 210 deletions

View File

@@ -14,23 +14,20 @@ TESTS = \
libtest \
libtest_mt \
test3 \
memtest \
dlltest \
abitest \
asm-c-connect-test \
vla_test-run \
cross-test \
tests2-dir \
pp-dir
pp-dir \
memtest \
dlltest \
cross-test
# test4_static -- Not all relocation types are implemented yet.
# asmtest / asmtest2 -- minor differences with gcc
ifneq ($(CONFIG_bcheck),no)
TESTS += btest test1b
ifndef CONFIG_WIN32
TESTS += tccb
endif
TESTS += btest test1b tccb
endif
ifeq ($(CONFIG_dll),no)
TESTS := $(filter-out dlltest, $(TESTS))
@@ -82,7 +79,9 @@ all test :
@echo ------------ version ------------
@$(TCC_LOCAL) -v
@$(MAKE) --no-print-directory -s clean
@$(MAKE) --no-print-directory -s -r $(TESTS)
@$(MAKE) --no-print-directory -s -r _all
_all : $(TESTS)
hello-exe: ../examples/ex1.c
@echo ------------ $@ ------------
@@ -199,14 +198,15 @@ btest: boundtest.c
echo "Test $$i failed as expected" ; \
fi ;\
done ;\
echo Bound test OK
echo Bound-Test OK
tccb:
@echo ------------ $@ ------------
$(TCC) -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o v1-tcc$(EXESUF)
mv v1-tcc$(EXESUF) v2-tcc$(EXESUF)
./v2-tcc$(EXESUF) -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o v1-tcc$(EXESUF)
cmp -s v1-tcc$(EXESUF) v2-tcc$(EXESUF) && echo "Bound-Test tcc OK"
$(TCC) -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o tccb1.exe
mv tccb1.exe tccb2.exe
./tccb2.exe -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o tccb1.exe
cmp -s tccb1.exe tccb2.exe && echo "Exe Bound-Rest OK"
# speed test
speedtest: ex2 ex3

View File

@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "libtcc.h"
#define M 20 /* number of states */
@@ -84,6 +85,8 @@ PROG(my_program)
"\n"
"int foo(int n)\n"
"{\n"
" if (n >= N_CRASH && n < N_CRASH + 3)\n"
" *(void**)0 = 0;\n"
" printf(\" %d\", fib(n));\n"
" return 0;\n"
"# warning is this the correct file:line...\n"
@@ -110,6 +113,11 @@ void parse_args(TCCState *s)
}
}
void bt_func(void *pc, const char *file, int line, const char *func)
{
printf(" *** at %s:%d in '%s'\n", file, line, func);
}
TCCState *new_state(int w)
{
TCCState *s = tcc_new();
@@ -119,7 +127,14 @@ TCCState *new_state(int w)
}
tcc_set_error_func(s, stdout, handle_error);
parse_args(s);
if (!w) tcc_set_options(s, "-w");
if (0 == (w & 1))
tcc_set_options(s, "-w");
if (w & 2) {
tcc_set_options(s, "-bt");
tcc_define_symbol(s, "N_CRASH", str(M/2));
tcc_set_backtrace_func(s, bt_func);
} else
tcc_define_symbol(s, "N_CRASH", "99");
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
return s;
}
@@ -139,23 +154,28 @@ void *reloc_state(TCCState *s, const char *entry)
}
/* work with several states at the same time */
int state_test(void)
int state_test(int w)
{
TCCState *s[M];
int (*func[M])(int);
int (*funcs[M])(int);
int n;
jmp_buf jb;
for (n = 0; n < M + 4; ++n) {
unsigned a = n, b = n - 1, c = n - 2, d = n - 3, e = n - 4;
if (a < M)
s[a] = new_state(0);
s[a] = new_state(w);
if (b < M)
if (tcc_compile_string(s[b], my_program) == -1)
break;
if (c < M)
func[c] = reloc_state(s[c], "foo");
if (d < M && func[d])
func[d](F(d));
funcs[c] = reloc_state(s[c], "foo");
if (d < M && funcs[d]) {
if ((w & 2) && d == 8)
printf("\n");
if (0 == tcc_setjmp(s[d], jb, funcs[d]))
funcs[d](F(d));
}
if (e < M)
tcc_delete(s[e]);
}
@@ -257,7 +277,13 @@ int main(int argc, char **argv)
#if 1
printf("running fib with mixed calls\n "), fflush(stdout);
t = getclock_ms();
state_test();
state_test(0);
printf("\n (%u ms)\n", getclock_ms() - t);
#endif
#if 1
printf("producing some exceptions\n "), fflush(stdout);
t = getclock_ms();
state_test(2);
printf("\n (%u ms)\n", getclock_ms() - t);
#endif
#if 1

View File

@@ -4,6 +4,11 @@ int atexit(void (*function)(void));
int on_exit(void (*function)(int, void *), void *arg);
void exit(int status);
void __attribute((constructor)) startup5(void)
{
printf ("startup5\n");
}
void cleanup1(void)
{
printf ("cleanup1\n");

View File

@@ -1,4 +1,5 @@
[test_128_return]
startup5
cleanup5
1 cleanup4
1 cleanup3
@@ -7,6 +8,7 @@ cleanup1
[returns 1]
[test_128_exit]
startup5
cleanup5
2 cleanup4
2 cleanup3