Commit Graph

3655 Commits

Author SHA1 Message Date
herman ten brugge
b45cea5f4b Update bsd notes
freebsd 13 must not have note section.
freebsd 14 must have note section.

also added version info.
2025-09-03 07:09:42 +02:00
herman ten brugge
b427545419 Update for freebsd versions >= 14.0 2025-08-31 12:24:03 +02:00
herman ten brugge
e6ea0d0424 tccgen: fix several problems
Fix 'void func2(char *(*md)(char *md))' declaration.
Fix global array and local extern array problems.
Fix scope problem with old function declaration.
Fix 'typedef int t[]' declaration. Empty size should remain.
2025-08-30 07:13:49 +02:00
herman ten brugge
8c59fd3cb6 Check enum range for typed enums 2025-08-24 11:22:38 +02:00
herman ten brugge
6ca6328e29 Fix long double to long long for x86_64 2025-08-23 14:48:34 +02:00
grischka
acb2a909dd tccgen.c: fix two scope problems
... see tests

Also:
- tccgen.c: cleanup _Generic a little
- libtcc.c: cleanup mem-debug a little
- arm-link.c: read/write only once
- tcc.h: another fix for clang offsetof
- tccdbg.c:
  * stabs: handle forward struct/enum decls
  * stabs: fix anonymous struct members (must not have a .L123 name)
  * avoid strncpy()
2025-08-22 19:14:44 +02:00
herman ten brugge
4e6c4db340 Small debug cleanup
A little bit better string hashing
Move free code to seperate function
2025-08-22 16:45:06 +02:00
herman ten brugge
e5e3dc687b Make debug info smaller
Currently debug size is big because some types are output multiple times.
Function scope was not treated correctly.
Rename anon(ymous) into forw(ard).
Compact string table by reusing names.
2025-08-22 10:27:59 +02:00
Matthias Gatto
f52b480f89 c2y if declaration (std n3356)
standart is here: https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3356.htm

This feature should not add bug to existing features,
as it is called only if there is a declaration in a switch or an if.
2025-08-22 00:01:58 +02:00
herman ten brugge
80e7040d0c tcc loops with some input arguments
This is one example:
tcc -c a b -o c

Detected with some configure scripts.
2025-08-18 22:28:05 +02:00
grischka
2662b7b43c tccgen: local scope for types of function parameters
int foo(struct xxx {int x[3];} *p) { ...

We want 'xxx' be visible only inside the function. To get that,
the patch removes the 'sym_push(param)' in xxx-gen.c, and instead
(in tccgen.c:gen_function()) pushes all symbols that were newly
defined during parsing of the parameter list in post_type().

Also,
- decl_initializer_alloc():
  patch existing globals earlier, which updates flex arrays too
- let patch_type() do the 'redefinition' check and FUNC_OLD update
2025-08-18 21:06:03 +02:00
grischka
deb7a3fc73 tcc.c:main() free all & etc...
tcc.c:
- be nice to leak checkers
tcctools.c:
- remove unused TCCState params
tccrun.c:
- call bound_exit() after signals to let it free mem
tccelf.c:
- use section_add() instead of section_ptr_add() when
  more appropriate
tccpp.c:
- use size_t to align tal_header naturally
- 'POINTER_SIZE' and 'PTR_SIZE' in the same source is confusing
- "char file_name[TAL_DEBUG_FILE_LEN + 1];" looks silly.
- next_nomacro(): skip UTF8 BOM at BOF
tccgen.c:
- get rid of STMT_EXPR clause on top of block
- warn with useless type like 'int;'
- move skip()'s in block() for better error line-info
- BIT_SIZE bits are meaningful only with VT_BITFIELD
  (not with enums for example)
workflow/test-win32:
- build with MSVC using build-tcc.bat also
alloca.S:
- fix 'off by one' problem on win32 (must touch current page
  too because the 'push %edx' at the end could touch the next page)
- must not align greater than 4 when used for struct args
  (i386-gen.c:gfunc_call())
libtcc.c:
- accept -g1dwarf (dwarf output, only line info)
2025-08-18 20:43:52 +02:00
herman ten brugge
8845b6cd45 Make signed/unsigned bitfields the same as gcc/clang 2025-08-18 16:22:00 +02:00
herman ten brugge
199e135142 arm double to (unsigned) long long conversion
Bug found with openssl test suite.
2025-08-17 08:49:29 +02:00
herman ten brugge
f8eb5f4ab8 Add -znodelete linker option
This option is needed for openssl to create a correct library.
2025-08-16 18:29:19 +02:00
herman ten brugge
19fdef46f9 Allow mixing old/new function prototypes
This fixes another external testsuite failure
2025-08-15 09:59:11 +02:00
Marek Knápek
571868c4f7 Fix for MSVC's usage of __declspec(align(#)). 2025-08-15 04:41:24 +02:00
herman ten brugge
03184fe33b riscv target did not handle FUNC_OLD correctly. 2025-08-11 06:49:22 +02:00
herman ten brugge
37e1c88d78 Convert float to double for old function code. 2025-08-10 22:02:44 +02:00
herman ten brugge
087cf2e579 x86_64 bound checking failure
The code:
void mul(double *p)
{
    *p *= 2.0;
}

failed on x86_64 because register was not loaded after
bound checking call.
Also printed size when pointer indir failes.
2025-08-10 21:55:48 +02:00
herman ten brugge
fa9795406d Do not read past array end in struct return 2025-08-07 11:32:09 +02:00
herman ten brugge
9dffcd29d3 Fix tests/boundtest.c
The test leaks memory on arm/arm64/riscv because alloca is
replaced by malloc and the memory is not freed for test16 and test17.
2025-08-05 22:14:13 +02:00
herman ten brugge
311218ee5f Allow testsuite to be build with CC -fsanitize
Makefile: Add sani-test* targets + help
tcc.h: redefine offsetof for clang -fsanitize
tccelf.c: section_ptr_add: allow clang -fsanitize
          tcc_add_btstub/tcc_load_object_file: revert previous change.
tccpp.c: Fix -fsanitize problem by casting to unsigned.
tests/Makefile: tcc -v leaks memory (a lot of returns in main() leak memory)
tests/tests2/Makefile: testcase 112 aborts and leaks memory. Disable leak test.
2025-08-05 16:47:11 +02:00
herman ten brugge
5364bc7c82 Fix i386 alloca code.
I commited the wrong version in previous commit.
2025-08-03 18:41:32 +02:00
herman ten brugge
6694391b74 Update gcctestsuite
I updated the tests/gcctestsuite.sh a bit.
before:
  3329 test(s) ok.
  210 test(s) skipped.
  168 test(s) failed.
  28 test(s) exe failed.
after:
  3331 test(s) ok.
  299 test(s) skipped.
  79 test(s) failed.
  26 test(s) exe failed.

I found some small problems:
include/tccdefs.h: Add alloca definition for i386 and x86_64
lib/alloca.S/lib/alloca-bt.S: align i386 alloca to 16 bytes.
			      i386_gen.c vla code and gcc do the same.
x86_64-gen.c: fix typo in comment
2025-08-03 10:35:58 +02:00
herman ten brugge
80bef6162a Unshare typedef definitions if it used more then once. 2025-08-03 10:29:16 +02:00
herman ten brugge
8a0ccbbd94 Another update for clang -fsanitize
arm-link.c:    remove some casts
tccelf.c:      code style and remove code
tccpp.c:       use correct pointer size so cross compiling works
riscv64-gen.c: make code more readable
2025-08-03 10:22:26 +02:00
herman ten brugge
666e88ee2a Update for clang -fsanitize
I tried to fix all remaining warnings/errors reported by -fsanitize.

The riscv64-gen.c is a bit large because it contained a lot of warnings.
I forgot some arm-link.c changes in last commit.
The other changes are all small fixes to avoid warnings/errors.
2025-07-29 08:26:57 +02:00
herman ten brugge
8025a829cc Check with clang -fsanitize
Tested code with:
clang -fsanitize=address,undefined,nullability -pie -fPIE -Iinclude -I. -g tcc.c -o tcc.tcc -lm -ldl -lpthread
./tcc.tcc -Iinclude -I. -b -g tcc.c -o tcc.tcc1 -lm -ldl -lpthread

Also checked on i386/x86_64 with -fsanitize=memory (others not supported).

arm-link.c: use read32le/write32le/add32le to avoid unaligned access
tcc.h i386-asm.c: fix signed left shift
lib/bcheck.c: Add _Atomic
libtcc.c: Correct MEM_DEBUG_CHECK3 to avoid unaligned access
riscv64-link.c: Fix R_RISCV_SET16
tccpp.c: Align tal_header_t to avoid unaligned access
tccgen.c x86_64-gen.c: avoid use of uninitialized value

There are still warnings reported:
tccgen.c:4031:13: runtime error: member access within null pointer of type 'TCCState' (aka 'struct TCCState')
tccelf.c:321:22: runtime error: applying zero offset to null pointer
tccelf.c:1132:23: runtime error: applying non-zero offset 169184 to null pointer

A lot of left shift of negative value warnings.

I ignored these for the moment.

Also the -run option does no work well with -fsanitize. It gets confused
because it does not detect that the generated code in memory is used
without -fsanitize option.

There are a lot more -fsanitize options. I did not find serious problems
with them.
2025-07-27 11:22:16 +02:00
DAVID
a2902d37a1 testing 2025-07-21 00:48:51 -03:00
Haelwenn (lanodan) Monnier
2ffb5869e0 lib/atomic.S: add GNU libatomic copyright notice 2025-07-19 00:30:12 +02:00
herman ten brugge
2eca4df6e9 Correct riscv load_large_constant 2025-07-18 08:15:58 +02:00
herman ten brugge
7c23c48a93 Riscv struct saving
While adding some testcases for attribute cleanup I found a
bug in the riscv code. It modifies the sv->c.i in load_symofs.
If a structure contains more then one element only the
first is stored correctly. This only happens on a large
stack frame.
Fixed by saving/restoring sv->c.i.
2025-07-17 06:50:15 +02:00
grischka
9670d10294 fix github CI & stuff
workflows/build.yml:
- win32/64: install mingw32/64 gcc on msys (because the default
  gcc installed elsewhere seems to use ucrt, producing incompatible
  fp printf formats.)
tccgen.c:
- cleanup funcs: save any lvalues from return expressions.  Also use
  get_temp_local_var() which however was causing a problem on i386
  because its gfunc_call() removes the arguments from vstack and by
  that defeats the 'in-use'  tracking of get_temp_local_var().  Fixed by:
i386/arm/arm64/x86_64-gen.c:
- in gfunc_call(): save_regs before anything else, fixes
  problems seen in arm64/i386
tccpp.c:
- allow arm asm specific use of '#' in macros
libtcc.c:
- organize -M options, and:
tccpe.c:
- move the subsystem option parsing from libtcc.c
tccelf.c:
- improved error handling in tcc_load_ldscript()
lib/atomic.S:
- TCC_TARGET_... not defined when building the lib
- endbrNN security feature not supported by TCC
tests/tests2/136_atomic_gcc_style.c:
- never use standard assert() in tests
2025-07-16 21:32:21 +02:00
herman ten brugge
28d7fb85b2 Change windows_2019(deprecated) to windows_2022 in buid.xml 2025-07-14 16:39:33 +02:00
herman ten brugge
717a510a19 Enable atomic test for all targets 2025-07-14 15:37:13 +02:00
herman ten brugge
7657d871c1 Add endbr32 for i386 2025-07-14 08:27:14 +02:00
herman ten brugge
854d6c5ab4 Update arm and windows atomic functions
I edited the arm thumb code so it works on armv6k.
I used the minga64w libatomic.a for windows.
2025-07-14 08:17:42 +02:00
kbkpbot
0c12363fd3 arm64: Save func results before struct args
In gfunc_call(), structure members are loaded into registers during
argument handling.
This operation may overwrite previous function call results stored in
registers (e.g., s0). To prevent this, we must save function call
results to the stack before processing structure arguments.
2025-07-11 22:13:30 +08:00
herman ten brugge
32b597746c Update bcheck for recent atomic change
The functions fetch_and_add_arm, fetch_and_add_arm64 and
fetch_and_add_riscv64 where removed with atomic change.

Replace the code in bcheck.c with call to atomic_fetch_add.
2025-06-24 21:38:31 +02:00
kbkpbot
7f13f24e12 Use asm implements some atomic functions
Use asm implements for i386/x86_64/arm/aarch64/riscv:

 __atomic_load_[1,2,4,8]
 __atomic_store_[1,2,4,8]
 __atomic_compare_exchange_[1,2,4,8]
 __atomic_test_and_set_[1,2,4,8]
 atomic_thread_fence
 atomic_signal_fence
 atomic_flag_test_and_set
 atomic_flag_test_and_set_explicit
 atomic_flag_clear
 atomic_flag_clear_explicit

`atomic.S` is extracted from `gcc` v15.1.0 `libatomic.a`.
And generated by https://github.com/kbkpbot/gen_atomic.git
2025-06-24 22:40:07 +08:00
Urs Janssen
3f06cb0f2e always search library paths 2025-06-24 14:23:47 +02:00
Avi Halachmi (:avih)
2d4e4a69c4 win32: winbase.h: fix broken LOAD_LIBRARY_AS_IMAGE_RESOURCE
Typo fix: s/LINRARY/LIBRARY/
2025-06-23 10:30:24 +03:00
Detlef Riekenberg
5fad6dc4a3 libtcc: Fix a double free, when option -o is used twice
tcc_set_str() already calls tcc_free() to free the memory of the stringpointer in s->outfile.
With the additional tcc_free(), the memory would be freed twice.

--
Regards ... Detlef
2025-06-19 03:27:59 +02:00
Detlef Riekenberg
f2b9fcf85d libtcc: Avoid a regression for some usecases
Thanks tylo for hints on the mailing list

--
Regards ... Detlef
2025-06-19 03:12:41 +02:00
herman ten brugge
59aecdb539 Another hex float fix
Hex floating point number did fail when a lot of digits are present.
See testcase 70.
2025-05-28 21:33:30 +02:00
herman ten brugge
c6792dac03 Add LIBS when testing tccb on bsd
ldexpl is in -lm library on bsd
2025-05-27 20:50:33 +02:00
herman ten brugge
cb39bc4cac Calculate hex floating point with 128 bits instead of 64 bits. 2025-05-27 07:36:33 +02:00
grischka
83de532563 revert "Save registers around attribute cleanup" (almost)
In fact, we don't need to save registers.  We need to
save the symbol if it is a SValue on vstack (the return
value in this case)

Replaces b6a16e3be4
2025-05-25 00:20:23 +02:00
herman ten brugge
b6a16e3be4 Save registers around attribute cleanup
This makes attribute cleanup code work the same as gcc and also
makes bound checking a very little bit faster.

tcc.h:
  Add save_return_reg(CType *) and restore_return_reg(CType *)
  Change gfunc_epilog() to gfunc_epilog(Sym *)

arm-gen.c:
arm64-gen.c:
c67-gen.c:
i386-gen.c:
il-gen.c:
riscv64-gen.c:
x86_64-gen.c:
  Move save and restore register around bound_local_delete call
  to save_return_reg and restore_return_reg.
  Pass func_type from gfunc_epilog to gen_bounds_epilog.

tccgen.c:
  Call save_return_reg/restore_return_reg in try_call_scope_cleanup
  when RETURN is found.

tccrun.c:
  Fix warning when bound checking not used.

tests/tests2/101_cleanup.c
tests/tests2/101_cleanup.expect
  Extra checks attribute cleanup save/restore registers.

tests/tests2/Makefile:
  Fix when bound checking not used.
2025-05-22 16:58:12 +02:00