See test. We need to use 'ind' from later when the address
field of the instruction is put.
Also: fix crash when the substracted symbol is undefined
Also: assume asm-symbols to be lvalues (except func/array)
Apple needs CONFIG_RUNMEM_RO=1
I now only set CONFIG_RUNMEM_RO=0 on _WIN32
Openbsd does not have malloc.h so remove some code
Also fix some warnings when compiling lib with gcc
- LIBTCCAPI int tcc_set_backtrace_func(void *ud, ...)
accept opaque user data pointer,
- tcc -vv -run... : show section info
- use memalign() to allocate runtime memory
- printline_/dwarf : pass output to parent function
- tccpe.c : fix -nostdlib -run
- --config-backtrace=no : make it work again
- 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)
tcc failed to run with bounds checking enabled because the functions
rt_wait_sem, rt_post_sem and _rt_error where defined twice.
This is solved by making them weak in tccrun.c
Also a nested lock was present when setting TCC_BOUNDS_PRINT_CALLS=1
This is solved in lib/bt-exe.c by moving lock/unlock code.
Also added a testcase in tests/Makefile to test tcc with bounds
checking enabled.
- abort with notice when tcc_relocate() is called with the
former two-step method
- support backtrace & bcheck not only with tcc_run() but also
for directly called functions from tcc_get_symbol(); enable
witn 'tcc_set_options("-bt/-b");'
- move struct rt_context and debug sections into compiled code
for TCC_OUTPUT_MEMORY also
- protect access (g_rc) with semaphore
Also:
- add armv7/aarch4/riscv64 github tests (qemu emulated)
- win32/build-tcc.bat: build cross compiler only with -x
- remove TOK_NOSUBST, mark the token itself instead
- get_tok_str(); mask out SYM_FIELD & update uses
- next(): optimize (~5% faster with tcc -E)
- tok_flags: remove some redundancy
- parse_define(): do not remove spaces around '##' and after '#'
and mark macros with '##' as MACRO_JOIN to avoid unnecessary
call to macro_twosharps(mstr):
- next_nomacro(): removed, next_nomacro1(): renamed to next_nomacro()
- next_argstream(): cleanup & new function peek_file()
- macro_subst_tok(): handle special macros (__DATE__ etc.)
like normal macros if they are #defined
- -DPP_DEBUG : more structured output
- pp_error(): better preprocessor expression error message
- tcctok.h: sort basic keywords (somehow)
- testspp/Makefile: generate .expect with 'make testspp.##+'
- tcc.c: tcc -E -o file : put unixy LFs also on windows
removed second argument for tcc_relocate(s). previous
'TCC_RELOCATE_AUTO' is now default and only behavior.
Rationale:
In the past, the option to compile into memory provided by the
user was introduced because only one TCCState could exist at a time.
This is no longer a limitation. As such it is also possible now to
keep any number of compiled code snippets around together with their
state in order to run them as needed.
- Also
- LIBTCCAPI tcc_get_error_func/opaque() removed
- tccrun/SELINUX: switch rx/rw mappings such that rx comes first
(risc64-link.c:relocate_plt() does not like got < plt)
- tcc_relocate_ex(): free local symbols and obsolete sections
to reduce memory after tcc_relocate()
When using libtcc it's reasonable to be able to use the application's
memory allocator for all allocations, including tcc_new(), and including
#define MEM_DEBUG
Ideally the allocator would be stored in the TCCState, like TCCErrorFunc.
That would imply a new API tcc_new_with_allocator(), but more importantly
would require all uses of tcc_malloc(x) to be changed to s->tcc_malloc(x).
That's a non-starter in my book.
Instead I refactored the memory management code so that all allocations
flow through tcc_realloc(). Which simply calls a function pointer, the
default value of which is the previous tcc_realloc().
It then becomess trivial to install a new allocator with the new function:
LIBTCCAPI void tcc_set_realloc(TCCReallocFunc realloc);
The resulting code adds the trivial cost of an additional function call
per allocation/free. It also doesn't distinguish between malloc failure
and realloc failure, but since both just fprintf then exit() that seems
unimportant to me.
On the plus side the preprocessor magic is much more clear. The diffs
don't hightlight that, but take a look at the result to see if you agree.
All tests passed on my x86 linux box.
tccpp.c:
- revert "Preprocessor fix + new testcase"
Fix was not a fix and nobody could understand the test.
This reverts 6379f2ee76
- better fix and add new test (pp/18.c)
tccgen.c:
- remove global variables 'in_sizeof', 'constant_p'
- rework comma expression (gexpr())
- merge func/data 'alias_target' codes
(See 08c777053c)
- move call to do_Static_assert()
- better error: "expression expected before '%s'"
- fix "statement after label"
- remove unnecessary second parameter to block()
- remove unnecessary call to decl()
- revert changes to old C89 test file
See 7f0a28f6ca
tccelf.c:
- rework "...make undefined global symbol STT_NOTYPE"
(See f44060f8fc)
- move tccelf_add_crtbegin() from libtcc.c
tcctest:
- unfix K&R fix (keep old look of K&R functions)
tccrun.c:
- exit(0) returns 0
libtcc.c:
- move #defines for -dumpmachine
- more explicit error "file not found"
(as opposed to error while loading file)
tccpe.c, x86_64-gen.c, i386-asm.c, tccasm.c:
- use R_X86_64_PLT32 for functions on x86_64-win32
tccdefs.h
- empty #defines for _Nonnull, __has_builtin(), etc.
configure:
- Simpler "macOS .dylib ... VERSION letters."
(See 6b967b1285)
Makefile:
- macOS version also
- add cross searchpaths for packages
build.yml:
- disable codesign on macos-11 (doesn't seem to work)
In `load` and `store` RISC-V gen used `type_size` to retrieve the size
of the types being moved around, the problem with that function is it
tries to obtain internal information of the type. When using `type_size`
with a `char *` it returns 1, and emits a `lb` instruction when using a
conditional expression like so (but probably also in other cases):
char *a, *b;
b = "hello";
a = x ? b : "" ; // this emits an `lb`
That `lb` clobbers the pointer, only loading the latest byte of it:
// if `b` was, say: 0x1f822e
a = b;
// now `a` is 0x00002e
NOTE: We spotted this when building make-3.82, in `init_switches`
function in the `main.c` file. This error made `make` unable to
run long options like `make --help` (segfault when doing the
`strlen` later)
This happens because a `char *` is internally stored as a `char[1]` or
something similar, it's result is the size of a `char` (1) times the
size of the array `1`. This is not what we want, we are copying the
pointer, not the array itself. Using `type_size` for this is not
appropriate even if it works for some cases.
If the conditional expression is rewritten to imperative style using an
`if` it works properly, so it might be related with the fact the pointer
is `load`ed to a register.
`load` and `store` should only work with integral types, so reading the
size of the array is not useful. This commit creates a simpler version
of this function that only reads the integral type of what's working
with: char * is considered just a pointer. So it makes an `ld` instead,
and the code above works.
add nop
fix asm_emit_i immediate check (negative offsets were missing)
fix check for IM12S
remove non-existent instructions (example: slli64 is just slli with imm=0)
After the change to DT_NEEDED I get warnings for some functions.
The reason is that libc.so on my machine contains:
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
Before the change to DT_NEEDED we solved the symbols because the
/lib64/libc.so.6 file has as DT_NEEDED set for ld-linux-x86-64.so.2
The above AS_NEEDED section was not followed so symbols in this
file gives a warning.
Currently fixed by including AS_NEEDED files.