Commit Graph

3192 Commits

Author SHA1 Message Date
herman ten brugge
2c70652e04 Enabled test 112_backtrace
Changed script in Makefile for testcase 112
Used bound_struct_copy_count in lib/bcheck.c
2022-07-09 11:51:13 +02:00
Ziyao
2d210fef49
Skip test 112_backtrace on x86_64,because commit 3715f1d breaks
it.Commit 3715f1d makes the error message of bound check on x86_64
different from other platforms,which breaks the test process.But that
commit exactly works well.
2022-07-09 12:56:07 +08:00
Ziyao
3715f1d7ee
Optimize small structure copying on x86_64 2022-07-09 12:53:29 +08:00
Detlef Riekenberg
fe7ee1105c libtcc: Let "-Wl,*" also accept "--entry=xxx" as alias for "--e=xxx" 2022-07-08 00:18:14 +02:00
Michael Matz
73c22f831f Fix fallthrough of non-entered stmt expressions
commit ec5d94291 made is to that the nocode_wanted state from
inside a statement expression is retained after it.  That is wrong
if the statement expression can't be entered to start with.  In the
latter case the state from before the stmt-expr is the one we need.
2022-07-01 17:20:37 +02:00
Michael Matz
ebb4e71236 flexarray: Accept empty ones
See testcase, it's a GNU extension, but widely accepted (the
linux kernel uses it).  This got broken with 72b520e709.
2022-07-01 15:37:23 +02:00
Reinhard Urban
9712541156 Add missing ELFOSABI constants
from my github rurban/brandelf
2022-06-13 15:10:15 +02:00
herman ten brugge
cd627c6c40 Fix riscv assembler
riscv64-asm.c:
	asm_opcode: add return
	asm_parse_regvar: add abi register names

riscv64-tok.h:
	add abi register names
2022-06-07 20:53:14 +02:00
herman ten brugge
afc136262e Fix core dump in case -static is used 2022-05-26 15:41:52 +02:00
herman ten brugge
a4e0f7ef05 Fix bitfield long types for stabs/dwarf
Also made dwarf *leb128 fuctions a litlle bit faster.
2022-05-25 17:04:37 +02:00
herman ten brugge
e301a0ba8d Removed __bound_exit_dll from lib/bt-dll.c 2022-05-19 09:42:41 +02:00
herman ten brugge
aaec564a82 Fix bound checking dlcose problem
The main problem is that an application called dlclose and then
had a bound checking problem. The list of dll's in tccrun was
not updated an caused a crash.
Also fixed some minor other things.

tccdbg.c:
- Allow filenames like ../file.c
- Rewrite DWARF_ABBREV_MEMBER_BF/DWARF_ABBREV_MEMBER a bit

tccelf.c:
- Add call to __bt_exit. This solves problem when dlclose is called

tccrun.c:
- Rewrite rt_printline_dwarf a litlle to use opcode_length correctly
- Do not stop at DW_LNE_end_sequence
- Fix DW_LNE_set_address again. Works now in *bsd.

lib/bt-exe.c lib/bt-dll.c:
- Add __bt_exit/__bound_exit_dll

lib/bcheck.c:
- Add __bound_exit_dll
2022-05-19 07:40:14 +02:00
herman ten brugge
4c82b00342 Update for elflint problems
tccgen.c:
- When __FUNCTION__ is used and no code is generated use symbol len = 0.

tccelf.c:
- If library is present in verneed it should be in DT_NEEDED.
- @plt symbols should have size 0
- set _GLOBAL_OFFSET_TABLE_ st_size correct
- Remove version symbol if new value present

reported by elflint:

__FUNCTION__ problem:
  section [19] '.symtab': symbol 2134 (L.195) does not fit completely in referenced section [14] '.data.ro'
DT_NEEDED problem:
  section [26] '.gnu.version_r': entry 2 references unknown dependency
@plt symbols should have size 0:
  section [22] '.symtab': symbol 36557 (r_core_config_init@plt) does not fit completely in referenced section [14] '.plt'
_GLOBAL_OFFSET_TABLE_ size:
  section [44] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol size 4 does not match .got section size 736
Remove version symbol:
  section [25] '.gnu.version': symbol 86: version index 3 is for requested version
  This happened for example with bounds checking symbol malloc
2022-05-17 07:34:10 +02:00
Detlef Riekenberg
a4f9e3cf4c configure: Use the environment variable CC when compiling tcc (resend)
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.

(resend)

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-05-15 23:18:41 +02:00
herman ten brugge
0e47167cbe New dwarf update
tccdbg.c
- Fix typo in dwarf_file. This resulted in not finding correct include
  files.

tccrun.c:
- Change FILE_TABLE_SIZE to 512. Some files use very large includes.
- When a dll containted more then 1 file the pc was not calculated
  correctly.
2022-05-14 15:58:40 +02:00
herman ten brugge
53dd065daf Fix unicode compiler warning again 2022-05-14 15:55:27 +02:00
herman ten brugge
19cc80788d Fix unicode compiler warning
The compiler warned about the unicode_to_utf8 code.
I fixed it by giving an error. This is the same as gcc does.
2022-05-12 11:18:37 +02:00
herman ten brugge
e7396c99b0 Dwarf update
Some small updates in tccdbg.c found by checking readelf output from
gcc/clang.

- Change encoding type bool type
- Fix enum signed/unsigned
- Do not hash anon symbol
- Use correct filename/line_number for global variables
- Fix compiler warning in tcc_get_dwarf_info
- Use unsigned long long for array indexes
- Display correct first line of function in gdb
2022-05-12 08:15:28 +02:00
herman ten brugge
748e38ad99 Fix stupid typo. 2022-05-10 07:21:49 +02:00
herman ten brugge
9a81e6366b Fix vla type bug for stabs/dwarf
The wrong vla stabs code was accepted by gdb.
The dwarf vla code was fatal.
2022-05-10 07:16:38 +02:00
grischka
2caaff20fb tccdbg.c: new file
Better avoid global variables, at least in new code.

tccdbg.c hopefully should be logically identical to the
former parts in tccgen/elf.c (s1 tccstate added in some
places)

tccelf.c: dwarf linkage seems special per dwarf rather
than special per target.
2022-05-09 22:37:25 +02:00
grischka
56481d554f bored...
/* Use "-g" as alias for "-g1". Use "-g0" to disable debug */

So not using -g is now the alias for -g0 ?!?

This reverts commit 8759b2581d.
This reverts commit 3ce7bc6efc.
This reverts commit 5fb582ab7f.
This reverts commit aea68dbb40.
This reverts commit fa9c31c3db.
This reverts commit b3bebdb20a.
This reverts commit ecf8e5a00e.
This reverts commit fe6b5c08dc.
This reverts commit e2e5377e7b.
This reverts commit 1cd7998905.
2022-05-09 22:19:15 +02:00
Detlef Riekenberg
1cd7998905 tccmacho: avoid warnings with strncpy and always terminate the target string 2022-05-09 12:49:48 +02:00
herman ten brugge
0241120b54 Dwarf update for readelf
readelf complained about DW_AT_stmt_list and DW_AT_location.
For dwarf >= 4 we should use DW_FORM_sec_offset instead of DW_FORM_data4
and DW_FORM_exprloc instead of DW_FORM_block1.
This is fixed in tccgen.c

I also updated tccrun.c to use dwarf_read_1 instead of DW_GETC.
2022-05-09 08:04:37 +02:00
herman ten brugge
499cf2305b Add dwarf clang support
This if for clang (pre)release 15.0.0.

tccrun.c:
- update directory/filename read. clang has extra md5 section
- start with filename 0 instead of 1. clang starts at 0
- change dwarf_read_32/dwarf_read_64 into macros

x86_64-link.c:
- Add support for R_X86_64_DTPOFF64/R_X86_64_TPOFF64. Needed by clang

tests/tcctest.c:
- add prototypes for puts/alloca. clang fails with error
- disable other_constraints_test for clang. clang prints 1 instead of 0
2022-05-07 18:10:59 +02:00
herman ten brugge
18808e325f Update dwarf2 support
tccgen.c:
- add anon support. So tcc_state in tcc works now.
- add function pointer support
- remove DW_FORM_implicit_const from DW_TAG_pointer_type

tccrun.c:
- set initial file name
- correctly use pc in DW_LNE_set_address (see lib/bt-exe.c)
- add DW_LNE_define_file support (even if it is deprecated)

tccelf.c
- do not include debug/test_coverage information for stub functions

lib/bt-exe.c
- use num_callers=-1 to mark dll
2022-05-07 06:54:13 +02:00
herman ten brugge
f0df48fcdd Fix dwarf on 32 bits targets
Never do last minute commits :-(
2022-05-05 09:23:29 +02:00
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