tinycc.git
20 hours agoriscv: asm: implement `j offset`mob
Ekaitz Zarraga [Thu, 25 Apr 2024 13:00:12 +0000 (25 15:00 +0200)]
riscv: asm: implement `j offset`

2 days agoriscv: asm: Add branch to label
Ekaitz Zarraga [Tue, 23 Apr 2024 22:37:46 +0000 (24 00:37 +0200)]
riscv: asm: Add branch to label

2 days agoriscv: Add full `fence` instruction support
Ekaitz Zarraga [Tue, 23 Apr 2024 13:01:05 +0000 (23 15:01 +0200)]
riscv: Add full `fence` instruction support

This commit adds support for `fence`'s predecessor and successor
arguments.

2 days agoriscv: asm: Add load-reserved and store-conditional
Ekaitz Zarraga [Tue, 23 Apr 2024 10:05:05 +0000 (23 12:05 +0200)]
riscv: asm: Add load-reserved and store-conditional

Add Atomic instructions `ld` and `sc` in their 32 bit and 64 bit
versions.

10 days agoFix Extended Asm ignored constraints
Ekaitz Zarraga [Mon, 15 Apr 2024 14:21:39 +0000 (15 16:21 +0200)]
Fix Extended Asm ignored constraints

This commit fixes the case where the register of for the Extended Asm
input or output is known. Before this commit, the following case:

  register long __a0 asm ("a0") = one;
  asm volatile (
       "ecall\n\t"
       : "+r" (__a0) // NOTE the +r here
  );

Didn't treat `a0` as an input+output register (+ contraint) as the code
skipped the constraint processing when the register was already chosen
(instead of allocated later).

This issue comes from f081acbfba84ffdf1e479f932906bf10f88cd1c2, that was
taken as a reference in every other Extended Assembler implementation.

12 days agoriscv: Avoid some compiler warnings
herman ten brugge [Sat, 13 Apr 2024 14:26:12 +0000 (13 16:26 +0200)]
riscv: Avoid some compiler warnings

2 weeks agoriscv: Add extended assembly support
Ekaitz Zarraga [Sun, 17 Mar 2024 15:07:04 +0000 (17 16:07 +0100)]
riscv: Add extended assembly support

NOTE: In order to be able to deal with general-purpose vs floating-point
registers, this commit adds a flag in the 6th bit of the register. If
set, it means the register is a floating-point one. This affects all the
assembler.

4 weeks agoriscv: fix jal: fix reloc and parsing
Ekaitz Zarraga [Tue, 26 Mar 2024 23:50:09 +0000 (27 00:50 +0100)]
riscv: fix jal: fix reloc and parsing

4 weeks agofixup! riscv: Add .option assembly directive (unimp)
Ekaitz Zarraga [Sat, 23 Mar 2024 11:32:32 +0000 (23 12:32 +0100)]
fixup! riscv: Add .option assembly directive (unimp)

5 weeks agoriscv: Add .option assembly directive (unimp)
Ekaitz Zarraga [Wed, 20 Mar 2024 16:53:41 +0000 (20 17:53 +0100)]
riscv: Add .option assembly directive (unimp)

5 weeks agoriscv: libtcc1.c support some builtins for __riscv
Ekaitz Zarraga [Thu, 21 Mar 2024 00:32:23 +0000 (21 01:32 +0100)]
riscv: libtcc1.c support some builtins for __riscv

5 weeks agoriscv: Support $ in identifiers in extended asm.
Ekaitz Zarraga [Thu, 21 Mar 2024 00:29:49 +0000 (21 01:29 +0100)]
riscv: Support $ in identifiers in extended asm.

Needed for using `__global_pointer$`.
$ don't have special meaning in RISC-V assembly.

5 weeks agoriscv: jal: Add pseudo instruction support
Ekaitz Zarraga [Wed, 20 Mar 2024 14:27:06 +0000 (20 15:27 +0100)]
riscv: jal: Add pseudo instruction support

5 weeks agoriscv: jalr: implement pseudo and parse like GAS
Ekaitz Zarraga [Wed, 20 Mar 2024 14:08:18 +0000 (20 15:08 +0100)]
riscv: jalr: implement pseudo and parse like GAS

5 weeks agoriscv: Add pseudoinstructions
Ekaitz Zarraga [Tue, 19 Mar 2024 22:27:58 +0000 (19 23:27 +0100)]
riscv: Add pseudoinstructions

call, tail, jump, jr, mv, not, neg, negw, seqz, snez, sltz, sgtz, bnez,
beqz, blez, bgez, bltz, bgtz, li

5 weeks agoriscv: Use GAS syntax for loads/stores:
Ekaitz Zarraga [Tue, 19 Mar 2024 10:11:25 +0000 (19 11:11 +0100)]
riscv: Use GAS syntax for loads/stores:

Before:
    ld rd, rs, imm
    sd rs1, rs2, imm

Now:
    ld rd, imm(rs)
    sd rs2, imm(rs1)

NOTES: Just as in GAS:
    - In stores the register order is swapped
    - imm is optional
    - when imm is not included parenthesis can be removed

5 weeks agoriscv: Move operand parsing to a separate function
Ekaitz Zarraga [Tue, 19 Mar 2024 08:45:48 +0000 (19 09:45 +0100)]
riscv: Move operand parsing to a separate function

6 weeks agolibtcc usability improvements
grischka [Mon, 11 Mar 2024 10:53:46 +0000 (11 11:53 +0100)]
libtcc usability improvements

- tccgen.c: cleanup switch data etc. after errors (*)
- tccpe.c: faster get_dllexports (*)
- tccpe.c: support -Wl,-e[ntry]=... (*)
- libtcc.c: win32: use ANSI functions (GetModuleFileNameA etc.)
- tccrun.c: be nice to tcc-0.9.26 ("struct/enum already defined")
- tccpp.c: be nice to tcc-0.9.27's va_start/end macros

(*) suggested by Robert Schlicht
https://lists.gnu.org/archive/html/tinycc-devel/2024-03/msg00012.html

7 weeks agotccrun: add option CONFIG_RUNMEM_RO=2
grischka [Sun, 3 Mar 2024 19:40:53 +0000 (3 20:40 +0100)]
tccrun: add option CONFIG_RUNMEM_RO=2

/* 0 = .text rwx  other rw (memory: min 2 pages) */
/* 1 = .text rx   other rw (memory: min 3 pages) */
/* 2 = .text rx  .rdata ro  .data/.bss rw (memory: min 4 pages) */

tcc -vv -run ... shows some info.
Also when compiled with -DMEM_DEBUG:
tcc -bench -run ... shows some memory usage

7 weeks agoi386-asm: fix pc-relative label ariths
grischka [Sat, 2 Mar 2024 11:48:44 +0000 (2 12:48 +0100)]
i386-asm: fix pc-relative label ariths

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)

7 weeks agoUse CONFIG_RUNMEM_RO=1 on apple
herman ten brugge [Sun, 3 Mar 2024 05:41:27 +0000 (3 06:41 +0100)]
Use CONFIG_RUNMEM_RO=1 on apple

8 weeks agotccrun: PAGEALIGN'ed mprotect
grischka [Thu, 29 Feb 2024 19:20:39 +0000 (29 20:20 +0100)]
tccrun: PAGEALIGN'ed mprotect

the un-mprotect() after run was severly off the limits.

Also in tcc.c:main: do not confuse errors with non-zero
results from tcc_run()

8 weeks agoriscv: Implement large addend for global address
Ekaitz Zarraga [Mon, 26 Feb 2024 21:26:32 +0000 (26 22:26 +0100)]
riscv: Implement large addend for global address

8 weeks agoFix win64 noreturn problem
herman ten brugge [Wed, 28 Feb 2024 06:37:09 +0000 (28 07:37 +0100)]
Fix win64 noreturn problem

On win64 the code would hang in longjump with previous change

8 weeks agotccrun: update for apple and openbsd
herman ten brugge [Mon, 26 Feb 2024 06:18:07 +0000 (26 07:18 +0100)]
tccrun: update for apple and openbsd

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

8 weeks agotccrun: resign from "advanced" system calls (memaligh/gettid)
grischka [Wed, 21 Feb 2024 09:27:32 +0000 (21 10:27 +0100)]
tccrun: resign from "advanced" system calls (memaligh/gettid)

... let's stay compatible

2 months agotccrun: review last changes
grischka [Fri, 16 Feb 2024 18:11:56 +0000 (16 19:11 +0100)]
tccrun: review last changes

- 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

2 months agotccrun: exit() via rt_longjmp()
grischka [Wed, 14 Feb 2024 09:00:22 +0000 (14 10:00 +0100)]
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)

2 months agoAllow tcc to run with bounds checking enabled
herman ten brugge [Thu, 15 Feb 2024 06:17:15 +0000 (15 07:17 +0100)]
Allow tcc to run with bounds checking enabled

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.

2 months agobcheck: fix argument order for memalign
Detlef Riekenberg [Wed, 14 Feb 2024 23:56:54 +0000 (15 00:56 +0100)]
bcheck: fix argument order for memalign

Spotted by George Sedov on the mailing list.

The bug was in the tcc source since >20 years:
https://repo.or.cz/tinycc.git?a=commit;h=ad28d4c5b03da27dc0381afb58f255d49962cca0

manpage for memalign:
https://linux.die.net/man/3/memalign

--
Regards ... Detlef

2 months agotccrun: 'tcc_relocate()' twice no longer supported
grischka [Sun, 11 Feb 2024 12:13:13 +0000 (11 13:13 +0100)]
tccrun: 'tcc_relocate()' twice no longer supported

- 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

2 months agotccpp: macro cleanup
grischka [Fri, 9 Feb 2024 15:07:43 +0000 (9 16:07 +0100)]
tccpp: macro cleanup

- 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

2 months agoLIBTCCAPI tcc_relocate(s) : REMOVED 2nd argument
grischka [Wed, 7 Feb 2024 06:42:56 +0000 (7 07:42 +0100)]
LIBTCCAPI tcc_relocate(s) : REMOVED 2nd argument

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()

2 months agoPointer diff should use signed size
herman ten brugge [Fri, 9 Feb 2024 07:35:32 +0000 (9 08:35 +0100)]
Pointer diff should use signed size

2 months agoadd MemoryBarrier marco define; tested gcc msvc
kbkpbot [Thu, 8 Feb 2024 03:11:55 +0000 (8 11:11 +0800)]
add MemoryBarrier marco define; tested gcc msvc

2 months agoFix default_reallocator declaration
herman ten brugge [Wed, 7 Feb 2024 06:01:36 +0000 (7 07:01 +0100)]
Fix default_reallocator declaration

2 months agoAllow use of a custom allocator in libtcc
Eric Raible [Tue, 6 Feb 2024 18:36:00 +0000 (6 10:36 -0800)]
Allow use of a custom allocator in libtcc

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.

2 months agoatomic_load/atomic_store : to ensure return the latest value, should we add a memory...
kbkpbot [Mon, 5 Feb 2024 00:37:41 +0000 (5 08:37 +0800)]
atomic_load/atomic_store : to ensure return the latest value, should we add a memory barrier here?

If have no these memory barriers, sometime it will cause bug in multiple threads program.

2 months agoreview recent commits
grischka [Sun, 4 Feb 2024 16:38:23 +0000 (4 17:38 +0100)]
review recent commits

tccpp.c:
 - revert "Preprocessor fix + new testcase"
   Fix was not a fix and nobody could understand the test.
   This reverts 6379f2ee76ac8d95c413f78b56e31a560e14ac6e
 - 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 08c777053cb3b7f4f5d33bb0beeb82787d30ebe0)
 - 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 7f0a28f6ca026a0b2b50282a2168346eef668651

tccelf.c:
 - rework "...make undefined global symbol STT_NOTYPE"
   (See f44060f8fcdfa9a21bb63476cf2758d497a053b9)
 - 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 6b967b1285704db13188895d86e7b3b34c3d2ff4)

Makefile:
 - macOS version also
 - add cross searchpaths for packages

build.yml:
 - disable codesign on macos-11 (doesn't seem to work)

2 months agoRevert "riscv64-gen: Fix `load` and `store` type_size usage"
Ekaitz Zarraga [Tue, 30 Jan 2024 16:41:26 +0000 (30 17:41 +0100)]
Revert "riscv64-gen: Fix `load` and `store` type_size usage"

It was already contemplated by c81116e29a8e2467681da7e1437911657cccb831.

This reverts commit c7263571d217e0863d3e62629207659b6aaf2b8b.

2 months agoriscv64-gen: Fix `load` and `store` type_size usage
Ekaitz Zarraga [Sat, 20 Jan 2024 22:36:45 +0000 (20 23:36 +0100)]
riscv64-gen: Fix `load` and `store` type_size usage

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.

2 months agoC23: Implement declaration after label
herman ten brugge [Sun, 28 Jan 2024 06:18:12 +0000 (28 07:18 +0100)]
C23: Implement declaration after label

Only allow declaration after label if it is inside '{...}'

3 months agoUpdate for clang
herman ten brugge [Wed, 17 Jan 2024 06:07:48 +0000 (17 07:07 +0100)]
Update for clang

Clang also removed K&R support so define IMPLICIT_INT.
Fix clang warning in lib/bt-log.c

3 months agoPrepare for gcc 14
herman ten brugge [Tue, 16 Jan 2024 21:21:19 +0000 (16 22:21 +0100)]
Prepare for gcc 14

Gcc 14 reports -Wimplicit-int errors because old K&R is not supported
any more.

3 months agoAllow declarations in case statement
herman ten brugge [Tue, 16 Jan 2024 06:51:56 +0000 (16 07:51 +0100)]
Allow declarations in case statement

This now works:

 case 1:
    int z = 123;
    break;

3 months agoriscv64-asm.c: fix assembly instruction with negative immediate offsets.
Andrius Štikonas [Fri, 12 Jan 2024 21:06:46 +0000 (12 21:06 +0000)]
riscv64-asm.c: fix assembly instruction with negative immediate offsets.

This fixes expressions like ld a0, s0, -24 that regressed in
d87801bd50abb04be894628338164537d88654dc

3 months agoRewrite gexpr a bit
herman ten brugge [Mon, 8 Jan 2024 10:34:47 +0000 (8 11:34 +0100)]
Rewrite gexpr a bit

3 months agoAdd some relocations to riscv64-link.c
herman ten brugge [Sun, 7 Jan 2024 06:45:31 +0000 (7 07:45 +0100)]
Add some relocations to riscv64-link.c

dlltest failed on a riscv machine.

3 months agoAdd type promotion in comma expression and update testcase 94
herman ten brugge [Sat, 6 Jan 2024 06:54:34 +0000 (6 07:54 +0100)]
Add type promotion in comma expression and update testcase 94

3 months agoPreprocessor fix + new testcase
herman ten brugge [Fri, 29 Dec 2023 08:08:25 +0000 (29 09:08 +0100)]
Preprocessor fix + new testcase

4 months agoUpdate riscv64-asm prototypes
herman ten brugge [Sat, 16 Dec 2023 11:28:19 +0000 (16 12:28 +0100)]
Update riscv64-asm prototypes

4 months agoriscv64-asm.c: add support for calculating addresses of symbols
noneofyourbusiness [Sun, 10 Dec 2023 21:36:49 +0000 (10 22:36 +0100)]
riscv64-asm.c: add support for calculating addresses of symbols

add some pseudoinstructions
riscv64-tok.h: add pseudoinstructions from tables 25.{2,3}

4 months agoriscv64-asm.c: add Zicsr registers
noneofyourbusiness [Sun, 10 Dec 2023 14:24:25 +0000 (10 15:24 +0100)]
riscv64-asm.c: add Zicsr registers

4 months agoriscv64-tok.h: add Zicsr pseudoinstructions, registers
noneofyourbusiness [Sun, 10 Dec 2023 14:22:41 +0000 (10 15:22 +0100)]
riscv64-tok.h: add Zicsr pseudoinstructions, registers

4 months agoriscv64-asm.c: implement Zicsr extension
noneofyourbusiness [Sat, 9 Dec 2023 13:32:14 +0000 (9 14:32 +0100)]
riscv64-asm.c: implement Zicsr extension

4 months agoriscv64-asm.c: correct check for 12-bit immediate
noneofyourbusiness [Fri, 8 Dec 2023 23:57:52 +0000 (9 00:57 +0100)]
riscv64-asm.c: correct check for 12-bit immediate

asm_emit_cj: correct check for offset size

4 months agoriscv64-asm.c: implement M extension
noneofyourbusiness [Fri, 8 Dec 2023 21:48:43 +0000 (8 22:48 +0100)]
riscv64-asm.c: implement M extension

4 months agoriscv64 elf flags should be configurable
noneofyourbusiness [Thu, 7 Dec 2023 15:27:27 +0000 (7 16:27 +0100)]
riscv64 elf flags should be configurable

4 months agoriscv64-asm.c: implement C extension
noneofyourbusiness [Sat, 2 Dec 2023 22:46:39 +0000 (2 23:46 +0100)]
riscv64-asm.c: implement C extension

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)

4 months agoriscv64-asm.c: asm_emit_j: correct check of immediate
noneofyourbusiness [Sat, 2 Dec 2023 16:07:16 +0000 (2 17:07 +0100)]
riscv64-asm.c: asm_emit_j: correct check of immediate

4 months agoconfigure: enable codesign by default on macOS.
Reimar Döffinger [Mon, 27 Nov 2023 19:16:09 +0000 (27 20:16 +0100)]
configure: enable codesign by default on macOS.

It is useful for the default configuration to just
work out of the box and pass tests instead of crashing
in unexplained ways.

4 months agotcctools.c: reduce duplicated code for -MP option.
Reimar Döffinger [Mon, 30 Oct 2023 17:33:35 +0000 (30 18:33 +0100)]
tcctools.c: reduce duplicated code for -MP option.

Generate list of escaped dependencies as a separate
first step.

4 months agoriscv64-asm.c: added asm_emit_j (J-type), changed jal to J-type
noneofyourbusiness [Sun, 26 Nov 2023 10:59:02 +0000 (26 11:59 +0100)]
riscv64-asm.c: added asm_emit_j (J-type), changed jal to J-type

additionally added a comment about B-type instruction format

4 months agoError out for incomplete type initialisation
Rob Pilling [Sun, 26 Nov 2023 09:29:06 +0000 (26 09:29 +0000)]
Error out for incomplete type initialisation

5 months agoCheck for errors before codesign
herman ten brugge [Wed, 8 Nov 2023 20:08:54 +0000 (8 21:08 +0100)]
Check for errors before codesign

5 months agoFix STT_NOTYPE problem on win32
herman ten brugge [Wed, 8 Nov 2023 20:03:10 +0000 (8 21:03 +0100)]
Fix STT_NOTYPE problem on win32

Since 'make undefined global symbol STT_NOTYPE' change win32 code
did not build any more.

5 months agoIgnore as_needed in ld_add_file_list
herman ten brugge [Wed, 8 Nov 2023 18:58:26 +0000 (8 19:58 +0100)]
Ignore as_needed in ld_add_file_list

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.

5 months agoUpdate do_debug handling
herman ten brugge [Wed, 8 Nov 2023 18:52:13 +0000 (8 19:52 +0100)]
Update do_debug handling

Make options '-g -b' and '-b -g' set -g2 in both cases.

5 months agoAllow libtcc1-usegcc in lib/Makefile
herman ten brugge [Wed, 8 Nov 2023 18:48:39 +0000 (8 19:48 +0100)]
Allow libtcc1-usegcc in lib/Makefile

5 months agoAllow make tcov-test on bsd targets
herman ten brugge [Wed, 8 Nov 2023 18:45:29 +0000 (8 19:45 +0100)]
Allow make tcov-test on bsd targets

5 months agoRelicensing TinyCC
Steffen Nurpmeso [Tue, 31 Oct 2023 21:59:44 +0000 (31 22:59 +0100)]
Relicensing TinyCC

5 months agoRevert "tests: Add support for codesigning command."
Reimar Döffinger [Mon, 30 Oct 2023 17:38:36 +0000 (30 18:38 +0100)]
Revert "tests: Add support for codesigning command."

This reverts commit ece74ceaaf0f1dd89e8520f73149867a6fa73082.

codesigning is already supported via --config-codesign.
This patch actually broke testing for tcc builds with
that set.

5 months agotcctools: delete created ar file on error.
Reimar Döffinger [Sun, 29 Oct 2023 17:13:19 +0000 (29 18:13 +0100)]
tcctools: delete created ar file on error.

Leaving 0-sized files around might confuse the build system.

5 months agostdatomic.h: Add ATOMIC_VAR_INIT macro.
Reimar Döffinger [Sun, 29 Oct 2023 17:12:31 +0000 (29 18:12 +0100)]
stdatomic.h: Add ATOMIC_VAR_INIT macro.

5 months agotests: Add support for codesigning command.
Reimar Döffinger [Sun, 29 Oct 2023 16:05:40 +0000 (29 17:05 +0100)]
tests: Add support for codesigning command.

Allows running the tests out-of-the-box on macOS.
Also delete *.dylib in tests2 dir on "make clean".
One remaining issue on macOS 14.1 is that the
-undefined warning option no longer works,
thus breaking test3 and test1b.

5 months agoAdd support for -dumpmachine option.
Reimar Döffinger [Sun, 29 Oct 2023 14:55:16 +0000 (29 15:55 +0100)]
Add support for -dumpmachine option.

Better compatibility with some build systems assuming gcc.

5 months agoAdd -MP option.
Reimar Döffinger [Sun, 29 Oct 2023 14:20:16 +0000 (29 15:20 +0100)]
Add -MP option.

5 months agoRelicensing TinyCC
Reimar Döffinger [Sun, 29 Oct 2023 13:53:06 +0000 (29 14:53 +0100)]
Relicensing TinyCC

5 months agotccdefs.h: Apple target requires __has_builtin definition.
Reimar Döffinger [Sun, 29 Oct 2023 13:37:50 +0000 (29 14:37 +0100)]
tccdefs.h: Apple target requires __has_builtin definition.

Note: I have not been able to create working binaries on
macOS 14.1 so far, but at least tcc compiles and produces
binaries now...

5 months agoarm64-gen.c: Add __AARCH64EL__ target_machine_defs.
Reimar Döffinger [Sun, 29 Oct 2023 13:36:11 +0000 (29 14:36 +0100)]
arm64-gen.c: Add __AARCH64EL__ target_machine_defs.

The Python headers require __AARCH64EL__ to be defined.
Also simplify ifdef to avoid duplicating __aarch64__ entry.

6 months agotccelf: Do not load all referenced libraries when linking a library
Detlef Riekenberg [Thu, 26 Oct 2023 15:51:30 +0000 (26 17:51 +0200)]
tccelf: Do not load all referenced libraries when linking a library

Recursive loading of all references can break linking of libraries
(Example: building of netbsd-curses)

Thanks grischka, Michael and Herman for the comments.

--
Regards ... Detlef

6 months agoFix macOS .dylib build when VERSION contains letters.
Ben C [Thu, 26 Oct 2023 02:17:35 +0000 (25 22:17 -0400)]
Fix macOS .dylib build when VERSION contains letters.

macOS builds with --disable-static fail to link if the version number
contains letters because of the -current_version and
-compatibility_version arguments (current version is 0.9.28rc).

This commit adds a new MACOS_DYLIB_VERSION variable to config.mak for
builds that target macOS. It has no impact on other targets.

6 months agoELF Relocatable: make undefined global symbol STT_NOTYPE
Sylvain BERTRAND [Tue, 24 Oct 2023 18:13:39 +0000 (24 18:13 +0000)]
ELF Relocatable: make undefined global symbol STT_NOTYPE

If undefined global symbols in ELF Relocatable files are not of
type STT_NOTYPE, it will confuse binutils bfd and corrupt product
files.

6 months agoSupport aliasing static global nonfunction objects
Petr Skocik [Sun, 8 Oct 2023 16:55:04 +0000 (8 18:55 +0200)]
Support aliasing static global nonfunction objects

Enables code such as:

    #undef NDEBUG
    #include <assert.h>
    #include <stdint.h>
    static int st_x = 42;
    static int st_x_ __attribute((alias("st_x")));
    int main(void){ assert((uintptr_t)&st_x == (uintptr_t)&st_x_); }

which would previously fail with no compiler warnings. The limitation of
this is that the alias must be done (or redone) after an actual definition.
An alias done right after a later overridden tentative declaration won't
work (sufficient for my use case).

6 months agoProduce better error message on malformed while loop
Eric Raible [Wed, 4 Oct 2023 05:11:59 +0000 (3 22:11 -0700)]
Produce better error message on malformed while loop

echo "void bugged() { do {} }" | tcc -run -
now produces the sensible:  -:1: error: 'while' expected (got "}")

I believe (but am far from sure) that the additional use of &tokc is ok.

7 months agoinclude/tccdefs: Add function renaming with __REDIRECT_NTHNL (0.9.28rc testing)
Detlef Riekenberg [Sun, 17 Sep 2023 10:15:28 +0000 (17 12:15 +0200)]
include/tccdefs: Add function renaming with __REDIRECT_NTHNL (0.9.28rc testing)

Fixes a compilation break in "glob.h"
Detected during tcc 0.9.28rc testing.
Affected project: https://github.com/craigbarnes/dte

--
Regards ... Detlef

7 months agoFix typo in atomic_compare_exchange_weak()
Sergey Sushilin [Sat, 9 Sep 2023 20:28:45 +0000 (9 23:28 +0300)]
Fix typo in atomic_compare_exchange_weak()

7 months agoFix tests/tests2/Makefile for win32
herman ten brugge [Thu, 7 Sep 2023 18:19:42 +0000 (7 20:19 +0200)]
Fix tests/tests2/Makefile for win32

7 months agoSmall fixes
herman ten brugge [Thu, 7 Sep 2023 18:05:51 +0000 (7 20:05 +0200)]
Small fixes

The testcases 22_floating_point and 24_math_library did not work with
make tcov-test
Add -lm for these in tests/tests2/Makefile

gcc -fanalyzer complains about tcc_malloc and tcc_realloc because
malloc(0) and realloc(ptr, 0) is not tested correctly.

7 months agoconfigury update & bump VERSION to 0.9.28rc
grischka [Wed, 6 Sep 2023 20:21:15 +0000 (6 22:21 +0200)]
configury update & bump VERSION to 0.9.28rc

configure:
- option --targetos=... for cross build
- cleanup

win32/build-tcc.bat:
- option -b <bindir>
- make 'libtcc1.a' and cross-prefix-libtcc1.a
  (same convention as with makefile)

Makefile:
- streamline tcov-tests, help, etc.

workflow/build.xml: simplify
- using "windows-2019" runner (instead of windows-latest)
  because its msys seems more complete and has no problems
  with the 96_nodata_wanted.test either.

Changelog,TODO,USES,tcc-doc.texi: update

7 months agotcc -g1 : small debug info (lines/functions only)
grischka [Wed, 6 Sep 2023 20:17:03 +0000 (6 22:17 +0200)]
tcc -g1 : small debug info (lines/functions only)

7 months agowin32: pe dwarf sections & option -g.pdb
grischka [Sun, 18 Jun 2023 17:58:16 +0000 (18 19:58 +0200)]
win32: pe dwarf sections & option -g.pdb

On windows, create a .pdb file with option "-g.pdb"
Such executables created by tcc can be debugged with
"ollydbg" or "x64dbg"

This currently relies on the 3rd party tool cv2pdb from
    https://github.com/rainers/cv2pdb
which again relies on
    mspdbsrv.exe mspdbcore.dll msobj80.dll mspdb80.dll
from a MSVC installation.

cv2pdb.exe + the ms* files may be put in the path or in the
same directory as tcc.exe.

7 months agostuff & fixes
grischka [Sat, 3 Jun 2023 19:20:48 +0000 (3 21:20 +0200)]
stuff & fixes

libtcc.c:
- revert "Small patch to allow..." (someone's personal easteregg)
  (see da3a763e977a84edf43c5ca101deae768ae8480d)
- check return value from macho_load_tbd/dylib

tcc.c:
- remove help for "not yet implemented" option

tccelf.c:
- check PIE's for "unresolved symbols"

tccgen.c:
- avoid int->double->int cast
  (see a46372e910710b9b00d4f4122ef6c1b00b2b909c)
- fix constant propagation with pseudo long doubles
  (must mask out VT_LONG from type)
- cleanup find_field() (again)

tccpp.c:
- disallow strings and double constants in #if expressions

win32/include/uchar.h:
- change file mode

7 months agobcheck: remove "tcc_location()" & x86_64 double fix
grischka [Wed, 30 Aug 2023 19:20:13 +0000 (30 21:20 +0200)]
bcheck: remove "tcc_location()" & x86_64 double fix

using (modified) tcc_backtrace() instead.
Also

Also fix the original bug with doubles on x86_64.
(which was not caused by incr_offset() actually).
See 598134fff6a1c85bd048ab307ff91cd24dcfbafd

Also cleanup on_exit() stuff
From fef701b57fa75f1c387c3e6e8e7ba251a053698f

7 months agoAdd tcov support in Makefile
herman ten brugge [Thu, 31 Aug 2023 09:09:49 +0000 (31 11:09 +0200)]
Add tcov support in Makefile

The following targets are added:
testc / testc2.all / testc2.37 / testc2.37+ / testc2.37-
testcpp.all / make testcpp.17
This allows to check that the testcase(s) test the code modified.
See Makefile tests/pp/Makefile tests/tests2/Makefile

lib/tcov.c: Fix while loops with fgets.

tcc.h: Fix tcc_p compilation with latest gcc

tests/tests2/22_floating_point.*: Better test floating point

7 months agoAdd bound checking for test 132
herman ten brugge [Wed, 30 Aug 2023 14:44:44 +0000 (30 16:44 +0200)]
Add bound checking for test 132

7 months agoUndo part of incr_offset patch.
herman ten brugge [Wed, 30 Aug 2023 14:10:39 +0000 (30 16:10 +0200)]
Undo part of incr_offset patch.

The incr_offset offset code was not working with bounds checking.
So I reverted part of tccgen.c.
See new test code 132.

Also added some debugging code that prints location of
bounds checking calls. Needed this to find the problem.
See lib/bcheck.c, lib/bt-dll.c, lib/bt-exe.c, lib/bt-log.c, tccrun.c

8 months agoriscv64-asm.c: add jal/jalr
noneofyourbusiness [Thu, 10 Aug 2023 14:19:49 +0000 (10 16:19 +0200)]
riscv64-asm.c: add jal/jalr

this implements the base instructions, not the pseudoinstructions

examples
 jal ra, 0
 jalr x0, ra, 0

8 months agoriscv64-tok.h: update with more instructions from the spec
noneofyourbusiness [Thu, 10 Aug 2023 11:27:11 +0000 (10 13:27 +0200)]
riscv64-tok.h: update with more instructions from the spec

defined tokens for C, M, Ziscr extensions.

separate the base RV32 instructions from the RV64, for potential future
re-use in a RV32-only assembler, from which the RV64-tok can #include

scall, sbreak have been renamed (page 7 of spec),
necessitating some renaming in riscv64-asm.c

riscv-spec-20191213.pdf was used,
in which the "V" extension is not yet ratified.
available under https://riscv.org/technical/specifications/

Tables 16.5–16.7 do not list any "scall"
neither does the privileged spec

3 additional tokens not present in the tables were removed

note that this riscv64-asm.c still contains defects, which will
be addressed in another commit

8 months agotccgen: update "Fix invalid load generated by gfunc_return()"
grischka [Mon, 31 Jul 2023 09:43:15 +0000 (31 11:43 +0200)]
tccgen: update "Fix invalid load generated by gfunc_return()"

tccgen.c:
- new function incr_offset(int) to increment a lvalue
- use it in gv/vstore to load/store from/to two-word types
- use it to advance the pointer to struct fields
- use it to load/store structs passed in registers
- structs: always assume that reg-classes of registers are 2^n
- adjust stack space when regsize > sizeof the_struct

x86_64-gen.c:
- return regsize=16 for VT_QLONG/QFLOAT

i386-gen.c:
- pass structs of size(8) as two VT_INT rather than one VT_LLONG
  (both should work now)

fixes a82aff333774f3bd38841d3c167f1add8c473c1c
fixes fd6d2180c5c801bb0b4c5dde27d61503059fc97d (slightly)