tinycc.git
9 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)

9 months agotccpp: #pragma once normalized
grischka [Mon, 26 Jun 2023 00:05:27 +0000 (26 02:05 +0200)]
tccpp: #pragma once normalized

In order to detect a "same file" faster, this makes one
restriction to the feature: the basenames are required to
match at least (as in "test.h" and "dir/../test.h")

Also remove obsolete 'pp_once' (cached includes do not persist
across compilations anymore anyway)

This rewrites commits
30fd24abd4e2f4223d75313909cb0c10a9c8e738
4e363a17284eb45de659ab2ca847a179938451d0

 3 files changed, 38 insertions(+), 74 deletions(-)

9 months agoAlign stack when returning structs.
herman ten brugge [Mon, 31 Jul 2023 07:24:06 +0000 (31 09:24 +0200)]
Align stack when returning structs.

The stack was not aligned when a returned structure was stored on stack.
This resulted in destoying of previous values stored on stack.
See testcase 119 (tst_struct_return_align) where value d is overwritten.

10 months agoFix test 131 for 32 bits targets
herman ten brugge [Wed, 5 Jul 2023 17:28:58 +0000 (5 19:28 +0200)]
Fix test 131 for 32 bits targets

10 months agoFix invalid load generated by gfunc_return()
Yao Zi [Sat, 1 Jul 2023 19:58:02 +0000 (2 03:58 +0800)]
Fix invalid load generated by gfunc_return()

  On backends that rely on gfunc_return() to handle structures
  returned in registers (like RISC-V), gfunc_return() may generate
  invalid loads for structures without VT_LOCAL and VT_LVAL. This
  commit fixes it and adds a regression test
  (131_return_struct_in_reg)

10 months agoUpdate pragma once for file operations
herman ten brugge [Mon, 26 Jun 2023 09:19:41 +0000 (26 11:19 +0200)]
Update pragma once for file operations

Use open/read/close instead of fopen/fread/fclose for tcc4tcl and ziptcc

10 months agoSmall update on pragma once
herman ten brugge [Mon, 26 Jun 2023 04:33:46 +0000 (26 06:33 +0200)]
Small update on pragma once

Update on calc_file_hash. Use xor instead of +.
Only calculate has if file name differs in search_cached_include.

10 months agoAllow different names for pragma once
herman ten brugge [Sun, 25 Jun 2023 18:23:58 +0000 (25 20:23 +0200)]
Allow different names for pragma once

pragma once can now be used with
test.h
./test.h

and other references to the same file just like gcc/clang.

On linux we can use stat and st_ino to check for the same file.
On windows the st_ino does not work so we calculate a file hash
if the size of the file differs and then compare the hash.

10 months agochange which to command -v
OldWorldOrdr [Mon, 12 Jun 2023 07:53:05 +0000 (12 03:53 -0400)]
change which to command -v

11 months agoUpdate to previous patch (remove the strcpy.)
waltje [Tue, 30 May 2023 00:46:44 +0000 (29 20:46 -0400)]
Update to previous patch (remove the strcpy.)

11 months agoSmall patch to allow for the TCC.EXE (and TCCLIB.DLL) to reside in a (directory under...
waltje [Sat, 27 May 2023 00:16:01 +0000 (26 20:16 -0400)]
Small patch to allow for the TCC.EXE (and TCCLIB.DLL) to reside in a (directory under) a "bin/" directory at the same level where the "include/" and "lib/" directories are. This allows one to set the PATH to the (proper) binaries directory and TCC will then "find" itself there.  Tested under Windows 7, Windows 8.1 (ARM) and Windows 10+11, but should also be workable for Linux and macOS.

11 months agoAdd support for constant float compare
herman ten brugge [Mon, 22 May 2023 13:09:59 +0000 (22 15:09 +0200)]
Add support for constant float compare

12 months agoabout CONST_WANTED & VT_NONCONST
grischka [Sun, 12 Mar 2023 10:16:27 +0000 (12 11:16 +0100)]
about CONST_WANTED & VT_NONCONST

- integrate CONST_WANTED with nocode_wanted
- expr_const() checks VT_NONCONST

12 months agostuff & etc..
grischka [Fri, 31 Mar 2023 16:20:49 +0000 (31 18:20 +0200)]
stuff & etc..

- tccpp.c: rename ... to __TCC_BCHECK__/__TCC_BACKTRACE__
- libtcc.c: correct total line count
- libtcc.c: support -run -- args... (instead of -run @ args ...)
- Makefile/build-tcc.bat: streamline GITHASH string somewhat
- bt-exe.c: avoid redef of pstrcpy() with 'tcc -bt tcc.c ...'

12 months agoCStrings leakless
grischka [Mon, 24 Apr 2023 19:58:50 +0000 (24 21:58 +0200)]
CStrings leakless

avoid memory leaks with lost CStrings on stack after errors.

tccpp.c:
- use/abuse static Cstring tokcstr where possible
tccgen.c:
- use/abuse static Cstring initstr where possible
tcc.h/libtcc.a:
- add 'stk_data' array to track memory pointer on stack
- add macros stk_push/pop() and cstr_new/free_s()
tccasm.c:
- use that
- use char[16] instead of char* for op.constraint

12 months agoMEM_DEBUG thread-safe & tccdbg leakless
grischka [Sat, 15 Apr 2023 14:57:02 +0000 (15 16:57 +0200)]
MEM_DEBUG thread-safe & tccdbg leakless

libtcc.c:
- guard tcc_realloc/free_debug() with a semaphore
tccdbg.c:
- allow tcc_debug_end() to be called twice safely

12 months agotcc_error_noabort(): always use this unless compiling
grischka [Sat, 15 Apr 2023 07:54:23 +0000 (15 09:54 +0200)]
tcc_error_noabort(): always use this unless compiling

This avoids 'exit(1)' with errors outside of compilation
(nasty in particular with libtcc usage)

As a sideeffect multiple errors can be seen for linker
errors (such as undefined symbols, relocation errors, ...)

12 months agolib/armeabi.c: fix zero from/to double conversion
grischka [Tue, 25 Apr 2023 06:59:42 +0000 (25 08:59 +0200)]
lib/armeabi.c: fix zero from/to double conversion

tccgen.c:
- allow cross-compiling 0.0L (cross-compile tcc with tcc)
tccelf.c:
- use alignment of TLS section for PT_TLS
tccpp.c:
- support long double constants on systems that do not support
  long doubles (i.e. mark them (VT_DOUBLE | VT_LONG))
tccdefs.h:
  #define __has_feature() for android
  remove _unaligned (why define a msvc extension under !_WIN32)

12 months agotccpp: remove unwanted space with __VA_ARGS__
grischka [Thu, 6 Apr 2023 22:45:20 +0000 (7 00:45 +0200)]
tccpp: remove unwanted space with __VA_ARGS__

reported by "vsfos"
https://lists.gnu.org/archive/html/tinycc-devel/2023-04/msg00007.html

12 months agoDo not crach when compiling with libtcc.
herman ten brugge [Sat, 15 Apr 2023 13:36:13 +0000 (15 15:36 +0200)]
Do not crach when compiling with libtcc.

12 months agoAllow _unaligned and __unaligned on WIN32
herman ten brugge [Sat, 15 Apr 2023 13:33:14 +0000 (15 15:33 +0200)]
Allow _unaligned and __unaligned on WIN32

12 months agoFix passing of large function arguments on riscv64
Ziyao [Sat, 8 Apr 2023 22:06:10 +0000 (9 06:06 +0800)]
Fix passing of large function arguments on riscv64

- Correct stack adjustment in gfunc_call()
- Add a regression test (130_large_argument)

13 months agoPrint correct values in tcc_print_stats (yarpgen v1)
Detlef Riekenberg [Thu, 23 Mar 2023 19:02:19 +0000 (23 20:02 +0100)]
Print correct values in tcc_print_stats (yarpgen v1)

Value 0 and values >2GB where printed wrong during tests with yarpgen (v1)
Starting the output with a hashtag make it compatible to TAP

--
Regards ... Detlef

13 months agoIgnore _unaligned and __unaligned. Required >15years ago, but still present in old...
Detlef Riekenberg [Thu, 23 Mar 2023 16:14:29 +0000 (23 17:14 +0100)]
Ignore _unaligned and __unaligned. Required >15years ago, but still present in old code

These extensions where used by other compiler
to generate different code on old cpu's (arm and x86 before pentium/pentiumpro)
to prevent processor exceptions / very high delays when accessing an unaligned pointer.

--
Regards ... Detlef

13 months agotests/tcctest.c: Add support for osx with clang 10
herman ten brugge [Sat, 18 Mar 2023 13:02:52 +0000 (18 14:02 +0100)]
tests/tcctest.c: Add support for osx with clang 10

13 months agoconfigure: OSX/macos: autodetect new_macho value
Avi Halachmi (:avih) [Sat, 18 Mar 2023 09:02:56 +0000 (18 11:02 +0200)]
configure: OSX/macos: autodetect new_macho value

Use old (=no) if autodetect succeeded and osx ver <= 10, else new.
Override is possible, and now also documented at ./configure --help.

13 months agoFix 128_run_atexit.c on linux
Michael Matz [Mon, 13 Mar 2023 16:01:35 +0000 (13 17:01 +0100)]
Fix 128_run_atexit.c on linux

if we include standard headers on glibc-based systems then
we can't use '__attribute__' (those are defined away for unknown
compilers) but must use '__attribute' (or #undef that token).

13 months agosmall scopes cleanup etc.
grischka [Mon, 6 Mar 2023 01:04:17 +0000 (6 02:04 +0100)]
small scopes cleanup etc.

tccgen.c:
- just track local_stack for small scopes (can't declare variables)
- fix a vla problem with nested scopes
- move debug N_L/RBRAC into curly braced block

Also:
- tccpp.c: move 'label_...' functions to tccgen.c
- tccpp.c: let get_tok_str() say "<no name>" for anonymous symbols
- tcctest.c: let __pa_symbol() work for memory > 2GB
- 119_random_stuff.c: revert strtoll test (no reason to test libc)
- tccdefs.h/tcctest.c: enable bit fncs for _WIN32
- Makefile:
  - use i686-linux-gnu instead of i386-linux-gnu for cross-i386
  - update 'make help'
  - revert umplicit 'make all' with 'make install' (but print warning)

13 months agoRevert ""Fix" nocode_wanted in expr_landor"
grischka [Sat, 11 Mar 2023 20:35:12 +0000 (11 21:35 +0100)]
Revert ""Fix" nocode_wanted in expr_landor"

instead in vcheck_cmp(), pass the CODE_OFF_BIT to generators
unless other nocode purposes are set.

This reverts commit cad873959410ddacfcd1a61d59755adf870dd592.

Also in 128_run_atexit.c:
avoid line output disorder which may happen on windows when
tcc itself and runned code are using two different printf
implementations and tcc would print the "[Returns 1]" above
any output from the runned test.

13 months agofix: Do not define INCLUDE_STACK_SIZE twice
Detlef Riekenberg [Sat, 11 Mar 2023 13:13:23 +0000 (11 14:13 +0100)]
fix: Do not define INCLUDE_STACK_SIZE twice

We have that define already in tcc.h
and changing the define in tcc.h breaks compilation of tcc
without this fix.

--
Regards ... Detlef

13 months agoFix nocode_wanted in expr_landor
herman ten brugge [Sat, 11 Mar 2023 06:51:00 +0000 (11 07:51 +0100)]
Fix nocode_wanted in expr_landor

The generated code by yarpgen failed. I traced the problem to
expr_landor. The problem was that nocode_wanted was removing
too much code.
See also testcase 33.

13 months agoIncrease VSTACK_SIZE to 512.
herman ten brugge [Sat, 11 Mar 2023 06:40:56 +0000 (11 07:40 +0100)]
Increase VSTACK_SIZE to 512.

The yarpgen test code uses very complex expressions.

13 months agoUpdate casted boolean expressions
herman ten brugge [Sat, 11 Mar 2023 06:35:42 +0000 (11 07:35 +0100)]
Update casted boolean expressions

The problem was that enums can also be present in vset_VT_JMP.
Also see testcode.

13 months agoFix type of cond-op
Michael Matz [Fri, 10 Mar 2023 16:23:55 +0000 (10 17:23 +0100)]
Fix type of cond-op

the optimization of a ternary op with two boolean operands had
the same problem (as in the last commit) of loosing the type.

13 months agoFix casted boolean expressions
Michael Matz [Fri, 10 Mar 2023 15:49:27 +0000 (10 16:49 +0100)]
Fix casted boolean expressions

the casted type was lost when a delayed bool was finally converted
to a value.  See testcase, in the wrong case the '(unsigned int)' cast
was ignored, and hence the division was signed reulting in -1 instead of
the proper 0x7fffffff.

13 months agoAdd attribute nodebug support and skip bitfield padding
herman ten brugge [Fri, 10 Mar 2023 11:41:43 +0000 (10 12:41 +0100)]
Add attribute nodebug support and skip bitfield padding

The following code:
typedef struct {
  unsigned int a __attribute__((nodebug));
  unsigned int b;
  unsigned int : 32;
  unsigned int c;
} tst;

Supresses a and also suppresses bitfield padding.
So debugger shows only b and c in above example.

13 months agoFix more jumpopts (in ternary op)
Michael Matz [Thu, 9 Mar 2023 17:18:29 +0000 (9 18:18 +0100)]
Fix more jumpopts (in ternary op)

the code in expr_cond save nocode_wanted around some parts of
expression evaluation, but at the wrong spots.  If the evaluation
of the condition itself (e.g. in the testcase the first whole ternary
expression) resulted in CODE_OFF, then that was saved, and restored
before return, even if in-between codegen would have CODE_ON'ed already.
Thus the whole CODE_OFF state bled out to outside the expression
evaluation and also disabled the whole if-block.  Found by yarpgen v1
(seed 64).

13 months agoFix test90 for 32 bits targets
herman ten brugge [Thu, 9 Mar 2023 15:11:39 +0000 (9 16:11 +0100)]
Fix test90 for 32 bits targets

Should have used 'long long' instead of 'long' for 32 bits targets.

13 months agoFix Makefile install target
herman ten brugge [Thu, 9 Mar 2023 15:00:46 +0000 (9 16:00 +0100)]
Fix Makefile install target

Update target all before installing

13 months agoFix init bitfield padding with size 32/64
herman ten brugge [Thu, 9 Mar 2023 14:53:48 +0000 (9 15:53 +0100)]
Fix init bitfield padding with size 32/64

The init code did not work for padding bitfields with size 32 and 64.

14 months agoFix code suppression during nocode_wanted
Michael Matz [Tue, 7 Mar 2023 17:10:02 +0000 (7 18:10 +0100)]
Fix code suppression during nocode_wanted

we activate code (CODE_ON) only when the target labels are used,
which doesn't happen during nocode_wanted regions.  So, we cannot
just switch off code either during nocode_wanted regions, nothing
would switch it on again (except in the happy coincidences when we
outright save/restore nocode_wanted).  See the testcase for one
example, reduced from code generated by yarpgen: in
  ext = (xxx || 1)           // #1
        || ((xxx && 1) || 1) // #2
code is first suppressed in #1 normally, then (before this commit)
was suppressed via CODE_OFF during #2 (via indirect gjmp),
then the suppression from #1 was undone, but nothing undoes the
suppression from #2 anymore as everything therein was generated
while nocode_wanted was active.

So, we would either need to save/restore nocode_wanted around
some more expressions, activate CODE_ON also with unused labels (breaks
some optimizations we want), or deactivate CODE_OFF only when not
already in nocode_wanted state.  This does the latter.

14 months agoCreate scopes for switches/whiles/do-whiles
Petr Skocik [Sun, 5 Mar 2023 21:31:40 +0000 (5 22:31 +0100)]
Create scopes for switches/whiles/do-whiles

The C standard has required this since at least C99.
A new scope should also be created for ifs, but that's currently
breaking tests2/122_vla_reuse.

14 months agoOpenBSD has removed the syscall() function from its libc, so we
Brian Callahan [Thu, 23 Feb 2023 22:19:37 +0000 (23 17:19 -0500)]
OpenBSD has removed the syscall() function from its libc, so we
need to use getthrid() directly in lib/bcheck.c

14 months agoFix sym_scope of typedefs
Michael Matz [Wed, 22 Feb 2023 16:59:31 +0000 (22 17:59 +0100)]
Fix sym_scope of typedefs

Sym.sym_scope and Sym.f (FuncAttr) share space, so blindly setting
one clobbers the other.  Right now this only leads to missing errors
on incompatible typedefs (see testcase), which this commit fixes.

But it points to a larger problem:
Generally we can only manipulate Sym.f for anonymous and field symbols,
not for anything that has a top-level name (basically any proper decl),
because the latter use sym_scope.  Luckily the functions type always
contains an anonymous symbol (in sym->type.ref), so we can use that.
But some of the functions attributes actually _do_ apply to the decl,
not the type (e.g. always_inline), so we still have a problem possibly,
when we update an pre-existing type that may already be shared with
another decl.

Would need untangling and perhaps using accessor functions that check
that Sym.f and Sym.sym_scope aren't used for the same symbol.

15 months agoUse unsigned int to count sizes for -bench (YARPgen) (part 2)
Detlef Riekenberg [Fri, 3 Feb 2023 17:04:56 +0000 (3 18:04 +0100)]
Use unsigned int to count sizes for -bench (YARPgen) (part 2)

I have a testfile created by YARPGen (seed=9), which displayed
a negative bss size without this patch.

* tcc needs also a bigger VSTACK_SIZE (i used 512)

--
bye bye ... Detlef

15 months agoUse unsigned int to count sizes for -bench (YARPgen)
Detlef Riekenberg [Fri, 3 Feb 2023 00:04:38 +0000 (3 01:04 +0100)]
Use unsigned int to count sizes for -bench (YARPgen)

I have a testfile created by YARPGen (seed=9), which displayed
a negative bss size without this patch.

* tcc needs also a bigger VSTACK_SIZE (i used 512)

--
bye bye ... Detlef

15 months agoFix preprocessor line directive update
herman ten brugge [Tue, 17 Jan 2023 19:08:14 +0000 (17 20:08 +0100)]
Fix preprocessor line directive update

The last commit was not a problem with macos.
The problem was that dwarf version < 5 uses different indexes for
files and directories.
They start at 1 for dwarf version < 5 and 0 for dwarf version >= 5.

15 months agoDon't forget to mention the amazing job made by Herman on native macOS.
Christian Jullien [Tue, 17 Jan 2023 14:29:57 +0000 (17 15:29 +0100)]
Don't forget to mention the amazing job made by Herman on native macOS.

15 months agoupdate changelog
noneofyourbusiness [Tue, 17 Jan 2023 12:35:36 +0000 (17 13:35 +0100)]
update changelog

15 months agoFix preprocessor line directive for macos
herman ten brugge [Mon, 16 Jan 2023 19:26:44 +0000 (16 20:26 +0100)]
Fix preprocessor line directive for macos

Macos has an offset of 1 for DW_LNS_set_file.

Also rewrite dwarf_file to not scan list twice and
move check for <command line> to this function.

15 months agoFix preprocessor line directive
herman ten brugge [Mon, 16 Jan 2023 07:39:34 +0000 (16 08:39 +0100)]
Fix preprocessor line directive

The preprocessor line directive did not result in correct debug info
when -g was used.
Line directives like:
 #line 1 "filename"
should now work.

15 months agoAllow const expr in builtin_frame_address/builtin_return_address
herman ten brugge [Mon, 16 Jan 2023 07:37:47 +0000 (16 08:37 +0100)]
Allow const expr in builtin_frame_address/builtin_return_address

16 months agoChangelog: get started with the changelog since 0.9.27
noneofyourbusiness [Sun, 1 Jan 2023 15:39:14 +0000 (1 16:39 +0100)]
Changelog: get started with the changelog since 0.9.27

16 months agoMakefile: remove unportable -v flag from distclean target
noneofyourbusiness [Sun, 1 Jan 2023 15:30:57 +0000 (1 16:30 +0100)]
Makefile: remove unportable -v flag from distclean target

16 months agoFix tcc -ar c symbol header size
herman ten brugge [Wed, 28 Dec 2022 06:38:39 +0000 (28 07:38 +0100)]
Fix tcc -ar c symbol header size

tcc -ar t failed sometimes because the header size was not correct.

16 months agotcc -ar: change mode to 644, use ARMAG
noneofyourbusiness [Wed, 28 Dec 2022 02:07:53 +0000 (28 03:07 +0100)]
tcc -ar: change mode to 644, use ARMAG

16 months agoRemove _Static_assert verifying the size of CString because it breaks C99 builds...
Per Nordlöw [Tue, 27 Dec 2022 23:31:14 +0000 (28 00:31 +0100)]
Remove _Static_assert verifying the size of CString because it breaks C99 builds with gcc-5

16 months agoReduce CString memory usage from 3 to two 2 words
Per Nordlöw [Tue, 27 Dec 2022 20:50:39 +0000 (27 21:50 +0100)]
Reduce CString memory usage from 3 to two 2 words

16 months agoAllow parallel build testsuite
herman ten brugge [Tue, 27 Dec 2022 13:11:18 +0000 (27 14:11 +0100)]
Allow parallel build testsuite

16 months agoFix problem with large section size.
herman ten brugge [Tue, 27 Dec 2022 06:45:38 +0000 (27 07:45 +0100)]
Fix problem with large section size.

In tcc_load_object_file use unsigned long for size/offset.
This avoids strange sizes of sections in case of overflow.
The sections that are now larger then 4G may not work.
This avoids a hang on macos in realloc.

16 months agohelp: also update main help with tcc -ar options and sort them
noneofyourbusiness [Mon, 26 Dec 2022 00:48:54 +0000 (26 01:48 +0100)]
help: also update main help with tcc -ar options and sort them

16 months agoAdd -Wl,-install_name macOS clang compatible flag as clang refuses -Wl,-soname. This...
Christian Jullien [Sat, 24 Dec 2022 08:30:00 +0000 (24 09:30 +0100)]
Add -Wl,-install_name macOS clang compatible flag as clang refuses -Wl,-soname. This helps configure scripts using both clang and tcc.

16 months agoFix multiple rpath tccmacho
herman ten brugge [Fri, 23 Dec 2022 18:48:39 +0000 (23 19:48 +0100)]
Fix multiple rpath tccmacho

If multiple rpaths are specified then output multiple LC_RPATH load
commands instead of one with : seperator.

16 months agoUpdate bind problem macho
herman ten brugge [Fri, 23 Dec 2022 11:17:55 +0000 (23 12:17 +0100)]
Update bind problem macho

Changed -1 into -2 for plt_offset,

16 months agoFix bind problem macho
herman ten brugge [Thu, 22 Dec 2022 19:50:37 +0000 (22 20:50 +0100)]
Fix bind problem macho

The problem occurs when a shared library creates a pointer to
a function and then the application also uses this function.

16 months agotccgen: better find_field() not found error messages
grischka [Thu, 22 Dec 2022 12:08:36 +0000 (22 13:08 +0100)]
tccgen: better find_field() not found error messages

Also: return all of 'cumofs' (no extra '+' required at caller)

16 months agoAdd tcc -ar x and t options
herman ten brugge [Tue, 20 Dec 2022 06:34:41 +0000 (20 07:34 +0100)]
Add tcc -ar x and t options

On macos we cannot use the ar because is does not support elf files
and then does not generate a symbol table.
The solution is to use 'tcc -ar'. The problem now is that some
pacages first built an archive with 'tcc -ar c' and later extracts
the archive with 'tcc -ar x' and built with this a dylib file.
The 'tcc -ar x' failed. So I implemented it. I also added the t
option because it was simple to do,

16 months agoAdd macos clang/ld compiler options
herman ten brugge [Tue, 20 Dec 2022 06:24:48 +0000 (20 07:24 +0100)]
Add macos clang/ld compiler options

With these option I can now built several packages without problem.
There are a lot of options we can add so I tried to implement the
minumum.

Add the following options:
dynamiclib same as -shared
flat_namespace default/ignored
two_levelnamespace ignored
undefined default/ignored
install_name name of dynmic lib
compatibility_version version dynamic lib
current_version version version dynamic lib

-Wl options:
all_load same as whole-archive
force_load same as whole-archive with lib
single_module ignored

16 months agoFix dll support for macho
herman ten brugge [Sun, 18 Dec 2022 13:07:19 +0000 (18 14:07 +0100)]
Fix dll support for macho

Export now all global symbols in export trie instead of only text
symbols.

I wrote too much data into dylib file because I did not check
for sk_unknown/sk_discard/sk_uw_info.

Simplified code in tccrun.c

16 months agoAllow building lib with gcc/clang
herman ten brugge [Sat, 17 Dec 2022 08:37:37 +0000 (17 09:37 +0100)]
Allow building lib with gcc/clang

Needed when using ...libtcc1-usegcc=yes in lib/Makefile.

lib/bcheck.c: Add __clang__ for pragma diagnostic
lib/bt-log.c: Add pragma diagnostic as in lib/bcheck.c
lib/builtin.c: Add a lot of alias code to allow building with gcc/clang
lib/stdatomic.c: Same as lib/builtin.c
lib/tcov.c: Avoid clang compiler warning

16 months agoFix dll support macho for x86_64
herman ten brugge [Sat, 17 Dec 2022 06:43:01 +0000 (17 07:43 +0100)]
Fix dll support macho for x86_64

Macho uses bind/rebase instead of dynsym so disable them for relocate_sections.

16 months agoAdd dll support for macho
herman ten brugge [Fri, 16 Dec 2022 19:57:45 +0000 (16 20:57 +0100)]
Add dll support for macho

Update configure and remove dll=no for Darwin.
Also removed dwarf=$dwarf because this is not a config option.

In tccelf.c only add __PAGEZERO if stabs and executable.

In tccrun.c correct rt_printline_dwarf code for dll.

In tests/Makefile disable dlltest with PIC for Darwin because object
format of .o file is still in elf.

In tccmacho.c add dll support and and rpath support.
Corrected trie code. For some reason symbol 'xx' should be after 'xx1'.
Corrected weak symbol support for old macho code.
Used R_JMP_SLOT instead of R_DATA_PTR in check_relocs.

16 months agox86asm: Add lzcnt/tzcnt support
Mathias Krause [Tue, 13 Dec 2022 10:34:54 +0000 (13 11:34 +0100)]
x86asm: Add lzcnt/tzcnt support

We already support popcnt, add lzcnt and tzcnt as well.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
16 months agoFix stab debug problem with common section
herman ten brugge [Sun, 11 Dec 2022 14:36:37 +0000 (11 15:36 +0100)]
Fix stab debug problem with common section

16 months agoAdd builtins ffs, clz, ctz, clrsb, popcount, parity
herman ten brugge [Sun, 11 Dec 2022 07:23:22 +0000 (11 08:23 +0100)]
Add builtins ffs, clz, ctz, clrsb, popcount, parity

Add new file lib/builtin.c
Modify include/tccdefs.h, lib/Makefile to compile it.
Update tests/tcctest.c to test it.

16 months agoAllow _Static_assert declarations in structs
Petr Skocik [Sat, 10 Dec 2022 00:12:44 +0000 (10 01:12 +0100)]
Allow _Static_assert declarations in structs

This usage has been part of the C grammar since C11
(http://port70.net/~nsz/c/c11/n1570.html#6.7.2.1) and is
also supported by gcc and clang.

17 months agoEnable vla_test-run on all targets
herman ten brugge [Tue, 6 Dec 2022 10:21:50 +0000 (6 11:21 +0100)]
Enable vla_test-run on all targets

Fix gen_vla_sp_save/gen_vla_sp_restore in riscv64-gen.c

17 months agoEnable testcases on apple and x86_64
herman ten brugge [Tue, 6 Dec 2022 07:09:16 +0000 (6 08:09 +0100)]
Enable testcases on apple and x86_64

17 months agoOSX is used and can't be replaced by macOS yet, revert previous change
Christian Jullien [Mon, 5 Dec 2022 15:28:54 +0000 (5 16:28 +0100)]
OSX is used and can't be replaced by macOS yet, revert previous change

17 months agocosmetic: OSX is a deprecated name, macOS is the official system name for Apple Opera...
Christian Jullien [Mon, 5 Dec 2022 14:42:38 +0000 (5 15:42 +0100)]
cosmetic: OSX is a deprecated name, macOS is the official system name for Apple Operating System since 2016.

17 months agoon macOS, configure displays the dwarf version used, currently dwarf=4
Christian Jullien [Mon, 5 Dec 2022 14:22:46 +0000 (5 15:22 +0100)]
on macOS, configure displays the dwarf version used, currently dwarf=4

17 months agoDefault is now config-new_macho and dwarf=4 for apple
herman ten brugge [Mon, 5 Dec 2022 10:10:03 +0000 (5 11:10 +0100)]
Default is now config-new_macho and dwarf=4 for apple

I tested on macos 10, 11, 12 and 13 that old and new macho code work.
I do not know when this new format is introduced but it is now
available on a lot of versions. So make it the default.

Also default to dwarf=4 because stabs and dwarf=5 is not supported.

17 months agoFix libtcc_test_mt
herman ten brugge [Sun, 4 Dec 2022 10:55:06 +0000 (4 11:55 +0100)]
Fix libtcc_test_mt

The test failed because atexit/on_exit code was not correct.
Make it look more like the g_exit_context.
Added a sleep to libtcc_test_mt to allow overlap of threads to
detect this problem.

17 months agoUpdate load segment code for macho
herman ten brugge [Sun, 4 Dec 2022 06:27:10 +0000 (4 07:27 +0100)]
Update load segment code for macho

Add an array with segement to load instead of code.
Dynamically check if segment is used or not.
This fixes the strange __DWARF code segment handling.

17 months agoFix for lldb usage
herman ten brugge [Sun, 4 Dec 2022 06:19:48 +0000 (4 07:19 +0100)]
Fix for lldb usage

lldb does not like function end and next function start at same pc

17 months agoproduce a more informative error message when _Thread_local is used
noneofyourbusiness [Sat, 3 Dec 2022 19:09:11 +0000 (3 20:09 +0100)]
produce a more informative error message when _Thread_local is used

17 months agoBetter fix for old macho format
herman ten brugge [Fri, 2 Dec 2022 21:57:49 +0000 (2 22:57 +0100)]
Better fix for old macho format

The last commit only worked on arm64.

The problem was that the new __DWARF segment was empty.
I now remove the __DWARF segment if it is not needed.
This resolves the rebase problem on x86_64.

17 months agoOld macho format does not work with previous push
herman ten brugge [Fri, 2 Dec 2022 19:25:27 +0000 (2 20:25 +0100)]
Old macho format does not work with previous push

17 months agoReduce memory size macho executables
herman ten brugge [Fri, 2 Dec 2022 12:53:37 +0000 (2 13:53 +0100)]
Reduce memory size macho executables

Do not align vmsize/filesize to SEG_PAGE_SIZE every time.
Move rel_offset check down due to this change.

17 months agoFix bounds checking without -run on macos
herman ten brugge [Fri, 2 Dec 2022 12:09:47 +0000 (2 13:09 +0100)]
Fix bounds checking without -run on macos

Update tccrun.c to detect rebase for dwarf debug info.
Enabled testcase 126 on macos.
Add prologue_end/epilogue_begin supoort in tcc.h, tccdbg.c, tccgen.c.

17 months agoTest was inverted for locally modified version
Christian Jullien [Fri, 2 Dec 2022 07:40:12 +0000 (2 08:40 +0100)]
Test was inverted for locally modified version

17 months agoMinor -v improvement: remove extra space
Christian Jullien [Fri, 2 Dec 2022 07:28:14 +0000 (2 08:28 +0100)]
Minor -v improvement: remove extra space

17 months agoUse my latest proposed patch for improved -v message. It is simpler and gives a bette...
Christian Jullien [Fri, 2 Dec 2022 07:05:01 +0000 (2 08:05 +0100)]
Use my latest proposed patch for improved -v message. It is simpler and gives a better message, especially when repository has been locally modified: 'tcc version 0.9.27 mob:fef701b 2022-12-02T07:11:55+01:00 locally modified (ARM eabihf Linux)'. Hope it's Ok for maintainers

17 months agoAllow on_exit to be used with -run
herman ten brugge [Fri, 2 Dec 2022 06:11:55 +0000 (2 07:11 +0100)]
Allow on_exit to be used with -run

Added on_exit support for tcc -run.
Also fixed the last atexit code.
Updated testcase 128
Fixed test/test2/Mafile for testcase 126

17 months agoFix add debug support to macos
herman ten brugge [Fri, 2 Dec 2022 06:05:12 +0000 (2 07:05 +0100)]
Fix add debug support to macos

17 months agoTODO: add releases - it's been a while since the last release
noneofyourbusiness [Thu, 1 Dec 2022 09:03:56 +0000 (1 10:03 +0100)]
TODO: add releases - it's been a while since the last release

17 months agomake tcc -v more informative (also add commit date/time)
noneofyourbusiness [Thu, 1 Dec 2022 05:33:51 +0000 (1 06:33 +0100)]
make tcc -v more informative (also add commit date/time)
patch from 'Christian Jullien' <eligis@orange.fr>

17 months agoAdd debug support to macos
herman ten brugge [Wed, 30 Nov 2022 20:49:07 +0000 (30 21:49 +0100)]
Add debug support to macos

lldb now works with this push.

In tccmacho.c add S_ATTR_DEBUG to all debug sections.
Add __DWARF section and rearange struct skinfo.

In tccdbg.c The first filename in dwarf_line can not be used.
Also had to fix structure/union/lexical_block/subroutine to
allow empty childs.
dwarfdump --verify complained about this.

17 months agoAllow atexit to be used with -run
herman ten brugge [Tue, 29 Nov 2022 20:13:20 +0000 (29 21:13 +0100)]
Allow atexit to be used with -run

Add atexit code to tccrun.c and added testcase 128

17 months agoFix static assert with empty string
herman ten brugge [Tue, 29 Nov 2022 18:45:05 +0000 (29 19:45 +0100)]
Fix static assert with empty string