Commit Graph

3165 Commits

Author SHA1 Message Date
herman ten brugge
2f2708a769 Add dwarf support
The new gcc12 release does not support stabs any more.
This was a good reason to add support for dwarf.

The stabs code still works and is used if configure option --dwarf
is not used.

Tested on x86_64, i386, arm, arm64, riscv64 with dwarf-5.
Some debuggers may not support dwarf-5. Try using older dwarf versions
i that case.
The tccmacho.c code probably need some support for dwarf.

arm-gen.c, arm64-gen.c, i386-gen.c, riscv64-gen.c, x86_64-gen.
- fix get_sym_ref symbol size

arm-link.c, arm64-link.c, i386-link.c, riscv64-link.c, x86_64-link.c
- add R_DATA_32U

libtcc.c:
- parse -gdwarf option

tcc.c:
- add dwarf option

tcc.h:
- add dwarf option and sections

tccelf.c:
- init dwarf sections
- avoid adding sh_addr for dwarf sections
- remove dwarf relocs for output dll
- add dwarf sections for tccrun

tccgen.c:
- add dwarf defines + global data
- add dwarf_* functions
- mix dwarf code with stabs code
- a trick is used to emit function name in .debug_line section so
  only this section has to be parsed instead of .debug_info and
  .debug_abbrev.
- fix init debug_modes

tccrun.c:
- add dwarf sections in rt_context
- init them in tcc_run
- add new dwarf code rt_printline_dwarf to find file/function

dwarf.h:
- New file

tcc-doc.texi:
- document dwarf

configure:
- add dwarf option

lib/Makefile
- change -gstabs into -gdwarf

lib/bt-exe.c, tests/tests2/Makefile, tests/tests2/126_bound_global:
- Add __bound_init call
- Add new testcase to test it
2022-05-05 09:10:37 +02:00
illiliti
d3e940c71c include/float.h: Define DECIMAL_DIG
Values were shamelessly stolen from musl libc. Needed for hare compiler.
2022-04-28 21:44:01 +03:00
Detlef Riekenberg
fa9c31c3db tcc.h: Extend search path for include, lib and crt.
This allows more tcc cross compiler to work out of the box
without a buildsystem-specific config-extra.mak
2022-04-28 17:36:10 +02:00
Detlef Riekenberg
9ac128c0bd Makefile: Add a comment with an option to debug the Makefile 2022-04-27 20:25:23 +02:00
Christian Jullien
5a3d1024d9 Update global help to tell that obj files are now optional with -ar driver 2022-04-19 07:53:19 +02:00
Ziyao
39ea340a31
Add option -e for setting ELF file's entry 2022-04-18 14:26:15 +08:00
Ziyao
0366924047
Add support of ldmxcsr and stmxcsr instructions on x86_64 and i386 2022-04-18 14:25:11 +08:00
Ziyao
8777ae984c
Allowing 'tcc -ar' to create empty archives 2022-04-18 14:23:03 +08:00
herman ten brugge
d3e4664629 Optimize prolog code on arm64
Only store registers that are needed in arm64 gfunc_prolog code.
Fix code in gen_bounds_epilog.
2022-04-15 20:11:18 +02:00
herman ten brugge
e86aae4f6d Add default case to relocate function for x86_64 2022-04-12 07:11:52 +02:00
herman ten brugge
c1725a8f6e Only define alloca on i386/x86_64 2022-04-12 07:07:40 +02:00
herman ten brugge
a5588501ab Fix vla support for arrays with no size 2022-04-12 07:03:33 +02:00
Detlef Riekenberg
aea68dbb40 arm-asm, arm64-link: Silence warnings for unused functions
The code needs to be fixed: use the functions or remove them.

arm-asm.c:
asm_parse_vfp_regvar()

arm64-link:
gotplt_entry_type()
create_plt_entry()

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-12 02:11:06 +02:00
Detlef Riekenberg
ac42d6826b tccgen: Avoid warnings in callers of the type_size() function.
Warnings reported in in x86_64-gen.c and arm-gen.c:

warning: ‘align’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-12 01:30:44 +02:00
Detlef Riekenberg
ecf8e5a00e tccelf: Avoid a compiler warning with snprintf
Target buffer must be larger as the format string + the replacement for %s
to avoid a warning [-Wformat-truncation=]

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-12 01:06:10 +02:00
Detlef Riekenberg
fe6b5c08dc configure: Use the environment variable CC when compiling tcc
Using the environment CC is a common used feature to
select a compiler to build any software,
so it should be supported when building tcc.

The old way using the parameter --cc still works.

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-12 00:33:35 +02:00
herman ten brugge
6bb41a05d7 Update for gcc12 on x86_64
gcc12 uses the xmm registers a lot more.

- save xmm0/xmm1 in gen_bounds_epilog
- align stack for call to (__bound_)memmove call in gfunc_call
2022-04-11 08:21:34 +02:00
Detlef Riekenberg
5fb582ab7f libtcc: Accept "-g0" to disable debug in addition to "-g", "-g1", "-g2" and "-g3"
This does not change our generated code.

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-10 18:26:14 +02:00
Detlef Riekenberg
3ce7bc6efc Accept option "-Os" and define "__OPTIMIZE_SIZE__"
Some headers and source code change macros and
implementation, when __OPTIMIZE_SIZE__ is defined.

This does not change our generated code.

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-10 17:32:38 +02:00
Detlef Riekenberg
b3bebdb20a libtcc: Allow more values for the -std= option
With this code, we can compile more projects,
who expect gcc or clang as compiler. (-std=gnu11 used in Makefiles)

As a further extension, it would be easy to disable gcc extensions

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-10 00:55:11 +02:00
Detlef Riekenberg
8759b2581d Makefile: Use the .exe extension only on Windows for the c2str helper program
Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-07 02:18:19 +02:00
Detlef Riekenberg
e2e5377e7b Makefile: Add a doc target.
"make help" already documents a "doc" target,
but it was not present.

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-04-01 21:26:55 +02:00
herman ten brugge
4a03f1fb20 Fix bounds checking struct return on arm/arm64 2022-03-28 09:07:09 +02:00
herman ten brugge
0244320b88 Add vla support for arrays with no size
Support vla arrays like arr[][s]

- tcc.h: add nesting parameter
- tccgen.c: use nesting to test for illegal vla's
- test/tcctest.c: add test case
2022-03-24 10:16:37 +01:00
Christian Jullien
750f0a3e3f As suggested by Herman, move comment to the next line otherwise it incorrectly handles --config-bcheck=no --config-backtrace=no 2022-03-23 09:03:54 +01:00
herman ten brugge
313855c232 Fix multi dimensional vla arrays on stack
There is no code generation in post_type for vla arrays. This code
generation has to be delayed until gen_function.

- post_type save code in type info.
- gen_function use this code to generate vla code.
- enable testcode for vla arrays.
2022-03-21 11:40:43 +01:00
herman ten brugge
8a3d0a0557 Fix multidimensional arrays on stack 2022-03-18 07:26:07 +01:00
herman ten brugge
4efcada291 Fix when bound checking and test coverage is used at the same time 2022-03-17 18:06:02 +01:00
herman ten brugge
184d845838 Fix riscv64 test 90 after struct init commit 2022-03-17 17:16:24 +01:00
herman ten brugge
291eccc154 Vla fix for 64 bits targets 2022-03-17 10:06:24 +01:00
grischka
719d96665e tccgen: Allow struct init from struct
Example:
    struct S {int x,y;}
        a = {1, 2},
        b = {3, 4},
        c[] = {a, b}, // new
        d[] = {b, (struct S){5,6}}; // new
2022-03-16 19:18:16 +01:00
grischka
0c6adcbe53 tccgen: multi-dimensional vla: bug fixes
fixes these cases:
   ptr - ptr             (-> ptrdiff_t)
   ptr +/- num           (-> ptr)
   sizeof (ptr+/-num)    (-> size_t)

Also some cleanups
2022-03-16 19:18:16 +01:00
grischka
ec5d94291c tccgen: accept array-size expressions in function paramters
Modify function parameter parser such that symbols are
put into token-table temporarily.  Benefits are:
- detects redefinitions, as with
    int foo(int a, int a);
- detects reserved symbols, as with
    int foo(int if);
- can parse expressions like
    int main(int argc, char *argv[argc + 1]);
- doesn't fix this one
    int main(int argc, char *argv[++argc]);

Also: fix unexpected "function might return no value"
with statement expression
    int f() { ({ return 0; }); }
2022-03-16 19:16:29 +01:00
Steffen Nurpmeso
917aad3bcf Add some missing fdopen(3) checks (Domingo Alvarez Duarte) 2022-02-28 21:19:41 +01:00
herman ten brugge
308d8d17dc Fix get thread id in lib/bcheck.c for freebsd
The api for getting the thread id is different for freebsd.
2022-02-21 09:15:43 +01:00
Christian Jullien
7225282ea5 Small patch from collective work to better support FreeBSD. 2022-02-20 15:45:24 +01:00
herman ten brugge
e9f59c804d Update for freebsd 13.0
Add __RUNETYPE_INTERNAL define in include/tccdefs.h
2022-02-08 18:53:16 +01:00
Christian Jullien
4e0e9b8f21 Add '#define __LITTLE_ENDIAN__ 1' which was missing for macOS port 2022-01-11 07:06:09 +01:00
herman ten brugge
d33b189427 Fix vla bug
This fixes a vla bug. Probably more fixes are needed.
Add testcode for bug.
2021-12-27 11:39:52 +01:00
herman ten brugge
1692060fb0 Fix cross compiling tcc on freebsd 2021-12-27 11:32:35 +01:00
herman ten brugge
6c0e0b998b Fix memcpy1/memcpy2 asm testcode on x86_64 2021-12-27 11:24:33 +01:00
Riccardo Schirone
027b8fb9b8 Add rpath to the library paths instead of state->rpath 2021-12-15 17:45:16 +01:00
Riccardo Schirone
d88857b210 If the DLL has a RPATH, use it when looking for NEEDED libraries 2021-12-15 17:30:25 +01:00
Alexander Sosedkin
da11cf6515 Don't skip weak symbols during ar creation
```
$ echo 'int __attribute__((__weak__)) f(void) { return 4; }' > w.c
$ tcc -c w.c -o w.o

$ tcc-old -ar rc w.a w.o; nm -s w.a  # previous behaviour, not indexed
w.o:
0000000000000000 W f

$ ar rc w.a w.o; nm -s w.a           # GNU binutils behaviour, indexed
Archive index:
f in w.o

0000000000000000 W f

$ tcc-new rc w.a w.o; nm -s w.a      # new behaviour, indexed
Archive index:
f in w.o

0000000000000000 W f
```
2021-10-30 16:07:00 +02:00
mingodad
1645616843 Revert "Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64"
This reverts commit af686a796b.
2021-10-22 07:39:54 +02:00
mingodad
2ce2dbcb09 Revert "Fix some errors on arm64-asm.c, rename some variables, fix several code style declarations"
This reverts commit 61537d899a.
2021-10-22 07:39:26 +02:00
mingodad
d33f582e25 Revert "Fix missing parameter"
This reverts commit 1a8fb94350.
2021-10-22 07:37:39 +02:00
mingodad
1a8fb94350 Fix missing parameter 2021-10-22 07:37:15 +02:00
mingodad
61537d899a Fix some errors on arm64-asm.c, rename some variables, fix several code style declarations 2021-10-22 07:20:00 +02:00
mingodad
af686a796b Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64 2021-10-21 20:09:42 +02:00