Update bound checking code.

Add __attribute__((constructor)) to __bounds_init.
- remove tcc_add_bcheck from i386-link.c and x86_64-link.c
- add simplified tcc_add_bcheck to tccelf.c
- Update tccrun.c to call constructor/destructor.
Set dynsym sh_info to number of local symbols in tccelf.c
Reduce stack size when bounds checking is enabled.
Added variable TCC_LIBBCHECK for windows support.
Add signal stack to detect stack overflow.
Add all & parameters in lbound_section and remove them if not used.
Close fd in tcc_relocate in tccrun.c
Fix section type constructor/destructor in tccelf.c
Add check code in tests/boundtest.c for mem/str functions.
Remove -ba from documentation.
Add bounds check signal info in documentation.

bcheck.c:
- Fix initial_pool alignment.
. Fix printf statements.
. Add prototypes for all external interface functions.
- Add TCC_BOUNDS_WARN_POINTER_ADD environment variable.
. Add ctype and errno data.
- Fix alloca when multithreading is used.
- Add lock for __bound_checking and __bound_never_fatal.
- Catch pthread_create and use locks when called.
- Detect in loaded in shared lib and use locks when found
- Use spin locks instead of semaphore locks.
- Make spin locked code as small as possible.
- Fix mem/str functions checking.
- Fix overlap checking mem/str functions.
This commit is contained in:
herman ten brugge
2020-01-15 08:53:19 +01:00
parent 0d6801b130
commit 3877618785
13 changed files with 1201 additions and 610 deletions

View File

@@ -356,8 +356,10 @@ 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 libaries. The main executable should always be compiled with the @option{-b}.
There are four environment variables that can be used:
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
@@ -368,10 +370,7 @@ Print statistic information at exit of program.
Try to continue in case of a bound checking error.
@end table
Note: @option{-b} is only available on i386 (linux and windows) and x86_64 (linux and windows) when using libtcc for the moment.
@item -ba
Generate address checking tests when using @option{-b}. This will be a lot slower but finds more errors.
Note: @option{-b} is only available on i386 (linux and windows) and x86_64 (linux and windows) for the moment.
@item -bt N
Display N callers in stack traces. This is useful with @option{-g} or
@@ -947,6 +946,40 @@ 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 call to __bound_checking(1) will disable bounds checking in the
whole application.
The BOUNDS_CHECKING_OFF and 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
#ifdef __BOUNDS_CHECKING_ON
extern void __bound_checking (int no_check);
#define BOUNDS_CHECKING_OFF __bound_checking(1)
#define BOUNDS_CHECKING_ON __bound_checking(-1)
#else
#define BOUNDS_CHECKING_OFF
#define BOUNDS_CHECKING_ON
#endif
void real_signal_handler(int sig, siginfo_t *info, void *ucontext)
@{
...
@}
void signal_handler(int sig, void *info, void *ucontext)
@{
BOUNDS_CHECKING_OFF;
real_signal_handler(sig, info, data);
BOUNDS_CHECKING_ON;
@}
@end example
@node Libtcc
@chapter The @code{libtcc} library