From afd09586d7ead4f146ad7a7a471be34196b3c6bc Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Fri, 14 Aug 2020 23:04:13 +0100 Subject: New upstream version 0.9.27+git20200814.62c30a4a --- tcc-doc.texi | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 10 deletions(-) (limited to 'tcc-doc.texi') diff --git a/tcc-doc.texi b/tcc-doc.texi index 5e718a2..65aff2d 100644 --- a/tcc-doc.texi +++ b/tcc-doc.texi @@ -322,6 +322,11 @@ Binary image (only for executable output) COFF output format (only for executable output for TMS320C67xx target) @end table +@item -Wl,--export-all-symbols +@item -Wl,--export-dynamic +Export global symbols to the dynamic linker. It is useful when a library +opened with @code{dlopen()} needs to access executable symbols. + @item -Wl,-subsystem=console/gui/wince/... Set type for PE (Windows) executables. @@ -349,12 +354,30 @@ fault}. Generate additional support code to check memory allocations and array/pointer bounds. @option{-g} is implied. Note that the generated code is slower and bigger in this case. +The bound checking code is not included in shared libraries. The main executable should always be compiled with the @option{-b}. + +There are five environment variables that can be used: +@table @option +@item TCC_BOUNDS_WARN_POINTER_ADD +Print warning when pointer add creates an illegal pointer. +@item TCC_BOUNDS_PRINT_CALLS +Print bound checking calls. Can be used for debugging. +@item TCC_BOUNDS_PRINT_HEAP +Print heap objects that are not freed at exit of program. +@item TCC_BOUNDS_PRINT_STATISTIC +Print statistic information at exit of program. +@item TCC_BOUNDS_NEVER_FATAL +Try to continue in case of a bound checking error. +@end table + +Note: @option{-b} is only available on i386 (linux and windows), x86_64 (linux and windows), arm, arm64 and riscv64 for the moment. -Note: @option{-b} is only available on i386 when using libtcc for the moment. +@item -bt[N] +Display N callers in stack traces. This is useful with @option{-g} or @option{-b}. +With executables, additional support for stack traces is included. -@item -bt N -Display N callers in stack traces. This is useful with @option{-g} or -@option{-b}. +A function @code{ int tcc_backtrace(const char *fmt, ...); } is provided +to trigger a stack trace with a message on demand. @end table @@ -543,6 +566,7 @@ instead of @cindex stdcall attribute @cindex regparm attribute @cindex dllexport attribute +@cindex nodecorate attribute @item The keyword @code{__attribute__} is handled to specify variable or function attributes. The following attributes are supported: @@ -570,6 +594,8 @@ registers @code{%eax}, @code{%edx} and @code{%ecx}. @item @code{dllexport}: export function from dll/executable (win32 only) + @item @code{nodecorate}: do not apply any decorations that would otherwise be applied when exporting function from dll/executable (win32 only) + @end itemize Here are some examples: @@ -893,7 +919,7 @@ Here are some examples of caught errors: int *tab; tab = malloc(20 * sizeof(int)); for(i=0;i<21;i++) @{ - sum += tab4[i]; + sum += tab[i]; @} free(tab); @} @@ -906,7 +932,7 @@ Here are some examples of caught errors: tab = malloc(20 * sizeof(int)); free(tab); for(i=0;i<20;i++) @{ - sum += tab4[i]; + sum += tab[i]; @} @} @end example @@ -923,6 +949,59 @@ Here are some examples of caught errors: @end table +Signal handlers are not compatible with bounds checking. The code +below can be used to protect signal handlers. +The @code{__attribute__((bound_no_checking))} will prevent all bound checking +code generation. If a signal handler calls another function this +function must also use @code{__attribute__((bound_no_checking))}. + +The fork() function call in a multi threaded application is also a problem. +To solve this all bounds checking can be disabled by calling +@code{__bound_checking(1)}. The call to @code{__bound_checking(1)} will disable bounds +checking in the whole application. + +The @code{BOUNDS_CHECKING_OFF} and @code{BOUNDS_CHECKING_ON} can also be used to +disable bounds checking for some code. This is not recommended. +It is better to fix the code. + +@example + +#if defined(__TINYC__) && __BOUNDS_CHECKING_ON +#undef __attribute__ +extern void __bound_checking (int no_check); +#define BOUNDS_CHECKING_OFF __bound_checking(1) +#define BOUNDS_CHECKING_ON __bound_checking(-1) +#define BOUNDS_NO_CHECKING __attribute__((bound_no_checking)) +#else +#define BOUNDS_CHECKING_OFF +#define BOUNDS_CHECKING_ON +#define BOUNDS_NO_CHECKING +#endif + +void signal_handler(int sig, void *info, void *ucontext) BOUNDS_NO_CHECKING +@{ + ... signal handler code without generated bounds checking code. +@} + +void run(const char *cmd) +@{ + switch (fork()) @{ + case 0: + BOUNDS_CHECKING_OFF; + ... + exec... + exit(1); + case -1: + ... + break; + default: + ... + break; + @} +@} + +@end example + @node Libtcc @chapter The @code{libtcc} library @@ -1294,10 +1373,6 @@ floating point to integer conversion. @item gen_cvt_ftof() floating point to floating point of different size conversion. -@item gen_bounded_ptr_add() -@item gen_bounded_ptr_deref() -are only used for bounds checking. - @end table @section Optimizations done -- cgit v1.2.3