Repository navigation
Compiler Option Fsanitize
Home › Compiler Option: -fsanitize
In tiko: build the program with AddressSanitizer, which stops it at the first use-after-free, double free, out-of-bounds access or use of a returned local's address, and names the line.
-fsanitize=address
-fsanitize address
Every procedure is compiled with clang's AddressSanitizer, and the program is linked with its runtime. Each memory access is checked against shadow memory, freed blocks are held back from reuse, and every frame's locals get a stack of their own. The first bad access stops the program with a report on standard error:
dim p as long ptr = new long
delete p
print *p '' stops here==9960==ERROR: AddressSanitizer: heap-use-after-free on address 0x116d453a0070 ...
READ of size 4 at 0x116d453a0070 thread T0
#0 0x7ff6630b1264 in main demo.tiko:3
It catches:
| Bug | Report |
|---|---|
Reading or writing memory after delete or deallocate
|
heap-use-after-free |
| Freeing a block twice | attempting double-free |
A ptr past either end of an allocated block |
heap-buffer-overflow |
| Using the address of a procedure's local after it returns | stack-use-after-return |
A local array or type indexed past its end through a pointer |
stack-buffer-overflow |
Build with -g as well, or the report names procedures and not lines. tiko build --profile asan does both: the built-in asan profile is -g -exx -O1 -fsanitize=address, written to out/asan/.
The program exits 1 after a report on Windows and Linux; macOS aborts it (exit 134). It runs more slowly and uses more memory than a plain build, so this is a debugging build, not a release one.
__TIKO_ASAN__ is defined, as 1, when the program is built this way.
Where the runtime comes from. AddressSanitizer's runtime is clang's, from the LLVM tiko uses:
-
windows-x86_64:
clang_rt.asan_dynamic-x86_64.dlland its import library, from LLVM'slib\clang\<version>\lib\windows. The DLL is copied beside the program, unless-nocopylibs. An LLVM without it isTKO0111. -
linux-x86_64, linux-arm64: clang links
libclang_rt.asanitself. On Ubuntu it is in thelibclang-rt-<version>-devpackage. (linux-arm64 has not been measured yet.) -
macos-arm64: clang links
libclang_rt.asan_osx_dynamic.dyliband records where it is. -
win64 (the MinGW target) has no runtime:
TKO0179.
Only address is accepted; anything else is TKO0106.
-
tiko's own runtime is not instrumented. Every allocation still goes through the checked
mallocandfree, so a bug in the program's use of memory is caught, but one inside a runtime routine is not. - A procedure that divides by a variable on x86-64 holds an inline instruction, and AddressSanitizer does not give it a separate stack: a returned local of that procedure is not caught.
- A different build of the same program:
-fsanitize=addressis part of the module and unit cache keys, so nothing compiled without it is reused.
- Not in FreeBASIC.
-exxchecks array bounds and null pointers; it does not see freed memory.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Match
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Array Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- tiko test
- tiko doc
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing