1
0
Fork 0
Commit Graph

733 Commits

Author SHA1 Message Date
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
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
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 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
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
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
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 6c0e0b998b Fix memcpy1/memcpy2 asm testcode on x86_64 2021-12-27 11:24:33 +01:00
grischka 675046bd59 tcc/lib: reduce number of files
271 insertions(+), 292 deletions(-), -21 lines, -5 files
Also:
- tccdefs.h: WIN32: less (no) __builtins
- libtcc.c: simply ignore -arch
2021-08-03 22:49:18 +02:00
grischka dda95e9b0b WAIT/POST_SEM(): generalize interface (and more)
Currently used only with 'tcc_compile_sem' to protect
tcc_compile(),  but can be used with other semaphores

Also fix deadlock when tcc_enter_state() is called
recursively for the same state, for example with
tcc_warning() from #pragma comment(option,"...")

Also:
- libtcc.c: error1(): use cstr_[v]printf()
- tcc.h: set TCC_USING_DOUBLE_FOR_LDOUBLE for macho-arm64
  (rather than for macho-X86_64)
- tcc.h: define TCC_TARGET_MACHO on __APPLE__ by default
- tcc.h: cleanup TCCState, move DEFASM token stuff to tcctok.h
- tccgen.c: more static
- Makefile/tcc.c: review githash
- tccpe/tcctools: use read() instead of fgets() in pe_load_def()
  (all files opened by tcc for reading are now read via 'int fd')
- configure/win32: don't preset CONFIG_TCCDIR (to allow to override it)
- tcc.c -bench: do not include output/run-time
2021-08-01 20:33:31 +02:00
grischka 4b2c6cf3a4 -W[no-]error...: features by shrinkage
136 insertions(+), 226 deletions(-), less 90 lines (except tests)
only one set_flag() function required
* can now turn off specific errors: -Werror -Wno-error=option
* new interface: tcc_warning_c(warn_option)("format", args...);
* new warning: -Wdiscarded-qualifiers (on by default)
* new variable 'warn_all' for conditional warnings with -Wall
see also the tests
2021-07-31 21:45:33 +02:00
grischka eadcee6501 macos: yet another tbd adjustment
configure:
- re-enable apple M1-arm64
- however, with --cpu=x86_64,  set -arch in CFLAGS/LDFLAGS too
  (assume rosetta)

Makefile:
- re-enable osx cross-test (Please do not disable tests)

tcc.h
- set TCC_IS_NATIVE for TCC_TARGET_MACHO on __APPLE__
- apply TCC_USING_DOUBLE_FOR_LDOUBLE for x86_64-osx

libtcc.c:
- cleanup tcc_add_file_internal()
- new function char *tcc_load_text(int fd); and use it for tbd files
2021-07-25 20:55:05 +02:00
Christian Jullien 592cf7fb25 Temporary remove osx cross build which is broken, at least on Windows. 2021-07-07 09:09:12 +02:00
herman ten brugge b5d4b908c4 Fix function call on arm64 and riscv
arm64-gen.c/riscv64-gen.c
- Copy code from x86_64-gen.c (fetch cpu flag before generating any code)

tests/tcctest.c:
- Add test code
2021-06-22 07:38:39 +02:00
herman ten brugge 0378168c13 Fix macro processing
The code:

printf("%d\n", CALL(CONST));

did not work because we did not check for TOK_PLCHLDR.
2021-05-04 11:22:11 +02:00
herman ten brugge 0f0f701212 Fix va_arg fox x86_64 2021-04-13 09:23:13 +02:00
herman ten brugge d64923c7b4 Fix testcase 125 fox x86_64 2021-04-13 09:13:25 +02:00
grischka 48df89e10e stdatomics: tidy & cleanup
- remove any error messages that were just for debugging the
  templates really
- don't use c99 in tcc (array designators etc.)
- remove memory model type (cannot be an own type really)
  and move memory model defines from built-in to stdatomics.h
- apply normal casts to non-pointer atomic_function arguments
- tidy the library support
- add some tests for errors/warnings

Also:
- Makefile: move GIT_HASH stuff from CFLAGS to DEFINES and into
  main section (away from what is included by tests for example)
- tccelf.c/tccgen.c: avoid some warnings with newer GCC
2021-04-09 10:47:35 +02:00
Dmitry Selyutin 4bb3b3cec7 stdatomic: simple counter test 2021-04-05 20:57:05 +03:00
grischka 97800177c9 tccgen: gen_cast(): detect 'cast from void' error 2021-02-19 09:55:40 +01:00
grischka 72f1dea537 tccelf: use rodata_section, use more rodata in tcc itself
libtcc.c: add -Wwrite-strings to -Wall
tccgen.c: ro float-consts, string-consts, ro arrays if base type is
tccpe.c: merge IAT with rodata
tccrun.c: mprotect rodata accordingly. free section data after copy
x86_64.c: do not use got for static data.
tcc -bench: show data.rw/ro

Probably STB_LOCAL should never get to put_got_entry(), and currently
it doesn't seem to happen (See "Hack Alarm" there)

Other files: use more ro-data in tinycc
2021-02-18 14:43:34 +01:00
Michael Matz 5201312cb2 Fix segfault with nested flex array structs
when used with string initialization the size of nested struct flex
array member was tested too late for < 0.

GCC accepts but discards such initializers (the flex array member will
become zero sized).  TCC supports flex arrays members only in
top-level structs and gives an error in this case.
2021-02-16 00:01:28 +01:00
Arthur Williams 355897a920 Allow declared arrays to be initialized without an explicit size
When defining an array with non-explicit size, one would get
"incompatible types for redefinition of 'array' if the array was already
declared with a different size.
For example:

    extern int array[2];
    int array[] = {1};

would fail to compile with tcc. Instead the above is now equivalent to:
    int array[] = {1, 0};
2021-02-13 19:18:08 -08:00
Danny Milosavljevic 24c94fff09
arm-asm: Add vcvt 2021-02-13 01:03:41 +01:00
Michael Matz fbef90a703 Fix a VLA problem
see testcase, reduced example of a situation reported by
Kyryl Melekhin in https://github.com/kyx0r/neatvi/ .
Problem is that setting up the VLA sp-save in a scope that isn't
entered at runtime leaves traces of it in outer scopes that then
try to restore the stack pointer from uninitialized slots.
2021-02-03 04:30:11 +01:00
grischka 557b4a1f6d configure chmod 755 etc.
lib/tcov.c:
- can't be cross-compiled (needs stdio.h)
- can be included in libtcc1.a

Reason why bt-xxx.o/bcheck.o are linked separatly is because we
don't want then to linked into exe's and dlls at the same time.
2021-01-26 18:44:37 +01:00
Danny Milosavljevic 25628cffe5
arm-asm: Add vmsr, vmrs 2021-01-26 14:25:39 +01:00
Danny Milosavljevic 1c9d999114 arm-asm: Implement "vmov.f32 Sn, Rd", "vmov.f32 Rd, Sn", "vmov.f64 Dm, Rd, Rn", "vmov.f64 Rd, Rn, Dm" 2021-01-26 03:31:33 +01:00
Danny Milosavljevic 0416594071 arm-asm: Add vmov 2021-01-25 21:56:52 +01:00
Danny Milosavljevic b82e52a497 arm-asm: Add vmla, vmls, vnmls, vnmla, vmul, vnmul, vadd, vsub, vdiv, vneg, vabs, vsqrt, vcmp, vcmpe 2021-01-25 21:56:52 +01:00
grischka 1ed4b6ba1a debug_modes, re-unalign, cleanups
tccgen.c: debug_modes
- don't waste debug function calls during normal execution.
libtcc.c:
- mem_debug: no C99 features in tcc please, for example
  ({compound expressions}): do not use.
tccgen.c: struct_layout:
- unaligned access is completely ok for most targets.
- Moreover the patch was triggering single byte mode even
  for normal aligned access (as with tcc's SymAttr)

static Sym label: don't do this

arm-gen.c:
- use some #ifdefs to explain some code
tccpp.c:
- cleanup UCN chars
libtcc.c:
- replace openbsd library search
configure:
- cleanup strip fallouts
tccgen.c:
- expr_cond(): remove an exotic optimization that eventually
  got fixed to do the contrary by a gv(RC_InT)
- pop_local_syms(): remove some args
- init_putv() : use write##le functions to avoid cross-compiler
  unaligned access
- __bt_init(): remove unused param 'mode'
2021-01-24 18:00:33 +01:00
Danny Milosavljevic 66de1550ab
arm-asm: Add vpush, vpop, vldm, vldmia, vldmdb, vstm, vstmia, vstmdb 2021-01-23 14:57:33 +01:00
Danny Milosavljevic 3fc55e15e8
arm-asm: Enable VFP when invoking GNU as for testing VFP instructions 2021-01-21 20:33:04 +01:00
Danny Milosavljevic cdbb55396c
arm-asm: Add vldr, vstr
Also add s0...s31, d0...d15
2021-01-21 18:15:19 +01:00
Danny Milosavljevic 7900a6bb61
arm-asm: Add ldc, ldcl, stc, stcl 2021-01-21 16:42:28 +01:00
Danny Milosavljevic d1a6c4aefa
arm-asm: Add mcr, mrc 2021-01-21 16:42:23 +01:00
Danny Milosavljevic a1dad7a9f7
arm-asm: Add cdp2
Also allow instructions without condition code in the first place
2021-01-21 16:42:20 +01:00
Danny Milosavljevic 036a7fe7d4
arm-asm: Add cdp
Also add p0...p15 (coprocessors), c0...c15 (coprocessor register aliases)
2021-01-21 16:42:16 +01:00
Danny Milosavljevic d60d2bb60e
arm-asm: Make "!" optional in asm_block_data_transfer_opcode 2021-01-18 18:58:08 +01:00
Petr Skocik 704c8163fd re-add accidentally deleted printf("\n"); to tests2/97*.c 2021-01-18 08:32:50 +01:00
Petr Skocik ffb95c2e0c Better handling of UCNs in strings
As the standard requires, take 4 hex digits after the \u opener of a
Universal Character Name, or take 8 hex digits after \U, but reject
smaller counts and don't consume more (https://port70.net/~nsz/c/c11/n1570.html#6.4.3,
https://port70.net/~nsz/c/c99/n1256.html#6.4.3).

The unicode codepoint used to get truncated to 1 byte. Now it gets expanded into UTF-8,
matching gcc & clang behavior on Linux.

TODO: Universal character names should also be supported in identifiers,
as in, e.g., char \u010dau_sv\u011bte[]="čau_světe";
2021-01-18 00:49:24 +01:00
Christian Jullien f5f8326531 FreeBSD: arm port is fully supported and added to cross list 2021-01-16 16:25:22 +01:00
herman ten brugge 5aba20f270 BSD: arm support
Support OpenBSD/FreeBSD/NetBSD on asm.

move PAGESIZE to tcc.h and use _SC_PAGESIZE (netbsd/arm has 8192 pagesize)

arm:
- fix cmp instruction for qemu (raspberry pi works without patch?)
- increase start address/size
- use large plt size
- add return R_ARM_PREL31
- add R_ARM_TARGET1 to prepare_dynamic_rel
- add gcc_s to FreeBSD (unwind code)
- do not use __clear_cache on bsd (sometimes bad system call)
- do stack unwinding on bsd
- test/tcctest.c: use %lld %llu on bsd
2021-01-16 07:01:59 +01:00
Danny Milosavljevic 007839597f
arm-asm: Implement ldr and str with shifted register offset
Factor out asm_parse_optional_shift
2021-01-14 23:16:31 +01:00
Christian Jullien d5c78ce655 Add more supported systems for cross test 2021-01-13 09:34:37 +01:00
grischka 62c0c4c77a tccelf.c: factor out elf_output_obj()
The small common parts within elf_output_file() aren't
worth the many #ifdefs.  Also, set section sizes and
allocate section names in 2 separate functions.
2021-01-12 18:39:35 +01:00
herman ten brugge c74c6ed61a Serveral updates
arm-gen.c:
- remove fr parameter from load_value

tccelf.c:
- update comment and remove check for sh_size

tests/boundtest.c:
- fix testcase 16/17
2021-01-12 18:06:23 +01:00
herman ten brugge cd91ea658a OpenBSD: x86 update 2021-01-11 19:26:10 +01:00
grischka bbc7070c82 make test: run cross-test always
To see inconsistencies when they happen.
2021-01-11 15:17:26 +01:00
Danny Milosavljevic aed4941e6b
arm-asm: Add ldrh, ldrsh, ldrsb, strh 2021-01-08 13:52:25 +01:00
Danny Milosavljevic f9c3b61884
arm-asm-testsuite.sh: Prefer current tcc as specified in $(TCC) 2021-01-06 02:18:14 +01:00
Danny Milosavljevic f3912fafdd
arm-asm-testsuite.sh: Prefer cross-binutils' objdump 2021-01-06 02:14:49 +01:00
herman ten brugge 81fec84012 disable nan test for clang 2021-01-05 19:44:06 +01:00
Danny Milosavljevic 77a6a9166d tests: Make arm-asm-testsuite.sh print the failed test cases. 2021-01-05 17:46:08 +00:00
Danny Milosavljevic 0c399306b8 tests: Call arm-asm-testsuite.sh on "asmtest" target. 2021-01-05 17:46:08 +00:00
Danny Milosavljevic 0754912ebd arm-asm: Add testsuite 2021-01-05 17:46:08 +00:00
Michael Matz 29d8871d61 Implement proper floating point negation
Using "-0.0 - x" still isn't enough if x is a NaN, so bite the bullet
and implement sign-bit flipping via memory.  (It's usually not too bad,
the -0.0-x method also uses memory for the floating point constant).

This way is at least shorter than implementing a new top-level operation
for all backends (a negate) that would be unary.
2021-01-04 04:13:42 +01:00
herman ten brugge 2633c30fb4 riscv64 update
implement load/store to constant address
use VT_LLONG instead of VT_PTR in register passing
fix bound checking problem with small structs
enable riscv tests in tests/tcctest.c and tests/tests2/119_random_stuff.c
2021-01-01 20:36:57 +01:00
grischka ea82d0826d tccpp: cleanup target-os defines
moved target_machine defines to the <target>-gen.c files.

Also:
- c2str.c moved into conftest.c
- tccdefs.h ; defined(__TINYC__) && !defined(_LOCORE) removed
  (in tinycc __TINYC__ is always defined and _LO... is never.)
- stddef.h : too many #ifdefs, removed
- tccgen.c:stabs: support win32 long doubles aka doubles.
- win32: math.h/tcc_libm.h: fix pointer mismatch in modfl
- tccpp.c: increment include_stack_ptr after the file was
  actually found otherwise it would print
  "in file included from <itself>: file not found..."
2020-12-31 02:03:31 +01:00
herman ten brugge 0821940e26 text relocation for netbsd
netbsd does not allow text relocations in text segment.

tcc.h:
- Add data_ro_section
- Fix typo rela.plt

tccelf.c:
- Add data_ro_section
- Make bounds_section/lbounds_section rw
- Add GNU_RELRO section for data_ro_section/bounds_section/lbounds_section
- Fix relocation for __dso_handle in atexit()

tccgen.c:
- Use data_ro_section

x86_64-gen.c:
- Use R_X86_64_PC32 instead of R_X86_64_64 for bounds checking

tests/Makefile, tests/tests2/Makefile
- Enable dll tests for netbsd
2020-12-30 14:08:06 +01:00
Christian Jullien c13c434383 Fix warnings detected by clang when compiling c2str. 2020-12-30 08:57:30 +01:00
Christian Jullien 16ed67537c NetBSD: longjmp(jmp_buf, 0) is not supported. 2020-12-24 09:29:25 +01:00
grischka 9f6b65230a include/tccdefs.h: moved and use it
tcc_define_symbol(): now only for -D on command line
include/tccdefs.h: converted to strings and compiled into
the tcc executable.  Can be disabled with
    ./configure --config-predefs=no
In this case include/tccdefs.h is loaded at runtime.  This is
default for other build-methods (build-tcc.bat) also (to avoid
some complexity).

Also:
- lib/Makefile: fix typo
- tcc.h : avoid _strto(u)i64 (for TCC on WIN98/2K)
- tccpp.h:cstr_printf() : workaround incompatible vsnprintf's
  (generally faster too)
2020-12-22 11:06:19 +01:00
herman ten brugge 8f8abcc756 more bsd updates
This implements support for FreeBSD on aarch64
This partial implements support on FreeBSD(32). This still needs fixing
i386_gen.c because small structures on this target are passed in registers.

Add aligned 16 to __int128_t for FreeBSD
Support __i386__ on FreeBSD/NetBSD
Fix testcase 115 on FreeBSD/NetBSD
Disable testcase 116 on *BSD* because TLS_FUNC/TLS_VAR not set in bcheck.c
Remove FreeBSD/FreeBSD_kernel code from tccelf.c
2020-12-22 07:02:47 +01:00
herman ten brugge 7eea5306e9 rename testcase 106 2020-12-19 21:02:44 +01:00
herman ten brugge 7f898abb82 bsd update
Fix crtbegin/crtend
Use dlsym on all bsd targets
Check .eh_frame on all bsd targets
Disable test3 on FreeBSD and NetBSD and use test1 instead because dlsym not working (WIP)
Disable dlltest and 113_btdll on NetBSD because text relocations are not allowed
Disable 115_bound_setjmp on NetBSD because longjmp is renamed into __longjmp14
2020-12-19 20:55:52 +01:00
herman ten brugge 50b4f320dc lazy binding
Currently tcc does not use lazy binding. It puts all relocations in the RELX
section and solve them all at startup.
This was not working on bsd.

tcc.h:
- New RELPLT_SECTION_FMT for plt relocations
- New entry relocplt in struct Section

tccelf.c:
- put_elf_reloca: put R_JMP_SLOT in relocplt section
- build_got_entries*: Use two passes because R_JMP_SLOT and R_GLOB_DAT
                      can not be intermixed on some targets (arm, arm64)
- layout_sections: Calculate correct size relocplt section for DT_ values.
                   Make sure relocplt is last
- fill_dynamic: Add DT_ values when got is filled
                move DT_VERSYM because dynamic linker cannot handle it standone
- Add note section for NetBSD

arm-link.c/arm64-link.c/i386-link.c/riscv64-link.c/x86_64-link.c:
- fill got table with pointer to plt section or symbol value in case
  of TCC_OUTPUT_MEMORY

arm-link.c/arm64-link.c:
- fix offset first plt entry

i386-link.c/x86_64-link.c:
- use correct reloc entry
- use relofs - sizeof (ElfW_Rel) because the reloc is already done

lib/bcheck.c:
- no __libc_freeres on FreeBSD and NetBSD

tests/Makefile:
- Add -fno-stack-protector for OpenBSD

tests/tests2/Makefile:
- disable 106_pthread/114_bound_signal
2020-12-18 15:24:32 +01:00
grischka e2e62fcb8b replace native platform macros in the compiler
- The compiler should not use these
- However tccrun.c & libtcc1.a files should use these
Also:
- use s1->loaded_dlls for loaded dlls instead of dlopens
- alpine musl: fully supported now and tested
- ./configure ...
   --config-backtrace=no : disable backtraces
   --config-bcheck=no : disable bcheck
- tests:dlltest: enable by default
- tccrun.c : simplify mmaps
- __builtin_alloca : always use asm-alias (instead of #define)
- tccpe.c : use write32le
2020-12-17 12:39:16 +01:00
herman ten brugge 6eef0e35b4 OpenBSD: testcases
Fix all testcases for openbsd except dlltest.

Remember dlopen calls and use them to fix openbsd dlsym problem
Use crtbeginS.o/crtendS.o for DLL for bsd
Do not include -ldl for __NetBSD__
Redirect malloc, realloc, ..., free for bsd
Align stack in tests/asm-c-connect-*.c for x86_64
Remove -B in tests/pp/Makefile (not supported on bsd)
2020-12-16 17:52:59 +01:00
grischka 8ff705554d tcc_enter/exit_state(): do not use!
tcc_enter/exit_state() are meant exclusively to protect
the tcc_compile() and its sub-functions in tccpp.c,
tccgen.c, tccasm.c and xxx-gen.c.

Other files that are part of libtcc simply must not use global
variables.

- riscv64/last_hi: move to TCCState
  from 72250bece2

- tccrun.c: Using a fixed address would not work anyway
  ("tcc -run tcc.c -run ..." for example)
  from baacb0f52a

- tests/Makefile: support for a platform doesn't make sense if
  it doesn't pass our basic tests.
  from 591feda103
Also:
- tccgen: cleanup "duplicate member" (only 2 passes,
  avoids additional TokenSym field)
  from 170be79a42
2020-12-08 19:57:57 +01:00
herman ten brugge 591feda103 OpenBSD: disable some tests 2020-12-07 12:06:17 +01:00
herman ten brugge baacb0f52a OpenBSD: runtime fixes
After this commit we can compile and run code with some limitations.
- The dlsym function is broken so this makes -run and bound checking
  not work all the time. Make -k test does work for most code.
- You have to do:
    ln -s /usr/lib/libN.so.x.y /usr/lib/libN.so
  for all .so files in /usr/lib.
  OpenBSD uses opendir/readdir to find the correct so file. This is
  not the way other platforms do this.
  Also the .a versions do not have all symbols that are present in the .so
  files.

tcc.h:
- Use different dynamic loader

elf.h:
- Add SHT_X86_64_UNWIND

tccelf.c:
- Do not use -dl
- Add required NOTE section
- Add extra dynamic tags
- Allow SHT_X86_64_UNWIND/SHT_NOTE in tcc_load_object_file

tccrun.c:
- Uses MAP_FIXED because without the offset between exec and data section
  becomes too big for x86_64

lib/bcheck.c:
- Do not use __libc_freeres

tests/tcctest.c:
- aligned_function also disabled for __GNUC__ == 4
2020-12-07 08:27:10 +01:00
herman ten brugge 170be79a42 duplicate member
Check duplicate struct/union member names

tcc.h: Add cnt field in TokenSym

tccgen.c: New function check_fields to find duplicate member names.

This avoids quadratic behavior and can be used for large structs.
2020-12-03 07:53:44 +01:00
Arthur Williams 3709f8de14 Treat func pointers with different return types as not compatible
Tcc considered function ptrs with different return types to be
compatible which disallowed some otherwise valid operations like:
`_Generic(foo, int(*)():0, void(*)(void):1)`
which would fail to compile with a error message of "type match twice"

This changed also required longjump's return type to be void and
munmap's to be int to be compatible with standard headers.
2020-11-22 16:30:34 -06:00
herman ten brugge 08d8015750 Fix fork problem 114_bound_signal
There is a race condition in old libc in fork().
The result was that 'end' was sometimes printed twice.

This did not happen with glibc-2.32.
2020-11-10 10:08:30 +01:00
herman ten brugge 54b4aa3cd6 Disable signals in bcheck.c pthread_create
glibc-2.32 contains new code to prevent a race conditions with signals
in pthread_create.
2020-11-09 10:57:14 +01:00
grischka 8b69059f66 three small fixes & three reverts
- tcc.h: msvc doesn't grok __func__ (reverts previous commit)

- tccgen.c: fortify tcc against bogus code:
  - n[sizeof({3;})]; // statement expression outside of function
  - f(){"123"4}; // tokens with values following each other
  (also, add "type defaults to int" warning for variables)

- tccpe.c: removed a check that caused BSS symbols not to be
  exported.  Whatever that check was meant to prevent.

- win32/build-tcc.bat: cmd.exe sometimes doesn't grok '-' in labels

- Revert "libtcc: no need to undef"
  This reverts commit 2b7aa2a1e1.
- Revert "tcc.h libtcc.c: remove unused defines"
  This reverts commit 985d963745.

The point of these "unused defines" is to be unused,  that is
to remind people not to use malloc but please to "use_tcc_malloc",
instead.
2020-11-02 18:08:56 +01:00
grischka 72b520e709 tccgen: flex arrays etc.
Fixes potential writes past the allocated space with mostly
illegal flex array initializers. (60_errors_and_warnings.c
:test_var_array)

In exchange suspicious precautions such as section_reserve
or checks with sec->data_allocated were removed.  (There is
an hard check 'init_assert()' for now but it's meant to be
just temporary)

Also, instead of filling holes, always memset(0) structures
& arrays on stack.  Sometimes more efficient, sometimes isn't.
At least we can omit putting null initializers.

About array range inititializers:  Reparsing tokens has a
small problem with sideeffects, for example

   int c = 0, dd[] = { [0 ... 1] = ++c, [2 ... 3] = ++c };

Also, instead of 'squeeze_multi_relocs()', delete pre-existing
relocations in advance. This works even if secondary initializers
don't even have relocations, as with
    [0 ... 7] = &stuff,
    [4] = NULL

Also, in tcc.h: new macro "tcc_internal_error()"
2020-10-03 18:12:46 +02:00
grischka 40395511d7 Revert "function pointer compare"
Always fine to try out things but not everything must be shown
to the public. ;)

Also, AFAIK pointers must compare equal only if derived directly
from each other (for example by cast to void* and back).

This reverts commit 8f9bf3f223.
2020-10-03 17:40:22 +02:00
herman ten brugge ae1796fc34 Fix testcase 114 for arm and apple
Arm has a problem with tls after a fork. The pthread_key_create seems to
be forgotten?

Apple has a problem with the exit(0) code in do_fork(). An IO mutex
is still held after a fork().
2020-10-02 17:50:31 +02:00
Michael Matz 78da4586a0 Fix tests2/120_alias.c on macos
While MacOS doesn't natively support the alias attribute, let's support
it with TCC anyway.  This means we need to make a decision if the
string in the alias attribute is decorated or not due to the implicit
underscore on MacOS.  To make life easier we decide that it's the C name,
i.e. without underscore, and so TCC needs to emit alias names with
underscore handling.

Irrespective of that the test case needs to deal with the underscore
itself for __asm__ renaming which is always requiring the assembler name.
2020-10-01 18:03:56 +02:00
herman ten brugge 0da93838c1 Init range wth symbols
The init range with symbols did only init the first value.
The relocation for all other symbols was missing.
Also see testcase.

tccgen.c:
- New function get_init_string
- Use macro processing in decl_designator for each init string
- Use get_init_string in decl_initializer_alloc

tccelf.c:
- Fix insertion sort in squeeze_multi_relocs

tests/tests2/90_struct-init.c:
- Add test case test_init_ranges
2020-10-01 17:50:20 +02:00
herman ten brugge afc0917f88 Bound checking fixes
tccgen.c:
- Fix 'tcc -b conftest.s'
- Add offset during bound checking for struct return

lib/bcheck.c:
- Check overlap when reusing vla/alloca

arm-gen.c:
arm64-gen.c:
riscv64-gen.c:
lib/alloca86-bt.S:
- add space for vla/alloca during bound checking

tests/tests2/Makefile:
tests/tests2/121_struct_return:
tests/tests2/122_vla_reuse:
- New test cases with bound checking enabled to test vla and struct return
2020-10-01 17:09:09 +02:00
Michael Matz 352e1d0fc4 Reinstate attribute alias handling
commit 2a0167a merged alias and asm symbol renaming, but broke
semantics of aliases, see testcase.  Basically the difference between
the two is that an asm rename doesn't generate a new symbol, i.e. with

  int foo __asm__("bar");

all source reference to 'foo' will be to 'bar', nothing of the name
'foo' will remain in the object file, and for instance reference to
'foo' from other compilation units won't be resolved to this one.

Aliases OTOH create an additional symbol.  With:

  void target (void) { return; }
  void afunc (void) __attribute__((alias("target")));

reference to 'afunc' will remain 'afunc' in the object file.  It will
generate two symbols, 'afunc' and 'target' referring to the same entity.
This difference matters if other compilation units make references to
'afunc'.

A side requirement of this is that for alias to work that the target
symbol needs to be defined in the same unit.  For TCC we even require a
stricter variant: it must be defined before the alias is created.

Now, with this I merely re-instated the old flow of events before above
commit.  It didn't seem useful anymore to place both names in the
asm_label member of attributes, and the asm_label member of Sym now
again only needs the hold the __asm__ rename.

It also follows that tcc_predefs.h can't make use of attribute alias to
e.g. map __builtin_memcpy to __bound_memcpy (simply because the latter
isn't defined in all units), but rather must use __asm__ renaming, which
in turn means that the underscore handling needs to be done by hand.
2020-09-30 17:46:01 +02:00
herman ten brugge 8fd7a384e2 Fix bitfields init : tiny solution
tccgen.c: Check struct/union size for bitfield.
tests/tcctest.c: Add test code.
2020-09-25 12:23:48 +02:00
herman ten brugge 89ea62481d clang7 does not support zero sized structs
This happens with aarch64 on raspberry pi.
2020-09-21 15:55:58 +02:00
herman ten brugge 8f9bf3f223 function pointer compare
tccelf.c:
- Check if symbol is in data section and UNDEF. Then generate new
  relocation and let dynamic linker solve it.

tests/tests2/42_function_pointer.c:
- Add new test code
2020-09-21 09:18:48 +02:00
Christian Jullien ffac4e7688 Herman proposed patch seems to fix clang issue on x64 Debian 2020-09-19 08:04:20 +02:00
herman ten brugge 5c6356ff8e default-initialization of bitfields
The code:

struct bf_SS {unsigned int bit:1,bits31:31; };
void func(void) {
  struct bf_SS bf_finit = { .bit = 1 };
}

will not init bits31 to 0.

tccgen.c:
- check_bf: New function to check if bitfield is present in struct/union
- decl_initializer: Call check_bf and set value to 0 is bitfield found

tests/tcctest.c:
- Add struct bitfield test code
2020-09-18 19:20:57 +02:00
Kyryl Melekhin 55b4754e84 Revert "add tests for float conversions to u64"
Because test's are not applicable in this case.

This reverts commit a5e714abec.
2020-09-17 07:12:49 +00:00
herman ten brugge c9bbd4e707 Allow strings in __builtin_constant_p
tccgen.c:
- Fix handling __builtin_constant_p

tests/bug.c:
- Remove tst3

tests/tcctest.c:
- Add new tests for __builtin_constant_p
2020-09-17 09:11:10 +02:00
herman ten brugge 4a16bebfab Struct va_arg fix
lib/va_list.c:
- Handle struct {double, double} correctly

arm64-gen.c:
riscv64-gen.c:
x86_64-gen.c:
- Allow zero sized structs to work with va_arg

tcctest.c:
- Add new va_arg test code

test/bug.c:
- Remove tst2 va_arg test
2020-09-17 08:42:28 +02:00
herman ten brugge 757a97466f Fix testcase 114 for macos
lib/bt-exe.c:
- call __bound_init before sigset_exception_handler because sigaction
  is redirected.

tests/tests2/Makefile:
- run testcase 114 on macos again
2020-09-17 08:22:53 +02:00
wanjochan 55eafa66b7 test 114: skip bcheck for osx (tcc -run not support fork with -b) 2020-09-17 00:43:19 +08:00
herman ten brugge d55e586bc6 Fix boundschecking fork for macos/SELINUX
lib/bcheck.c:
- Use INIT_SEM for child process fork on macos

tests/tests2/Makefile:
- tcc -run does not work for fork due to SHARED mmap
2020-09-14 19:31:56 +02:00
herman ten brugge 61c0c852b5 Update boundschecking for fork
bcheck.c:
- Fix fork function.
- Move use_sem
- Fix bound_alloc_error text

tests/tests2/114_bound_signal.c:
- Add test for fork
2020-09-14 08:24:01 +02:00
Kyryl Melekhin a5e714abec add tests for float conversions to u64
Note:
I removed the test that used sin()
function because it makes no sense
to use that there and besides I could
not get the test to work because
sin requires -lm linked but for some reason
make does not compile with -lm and
I get errors like undefined symbol sin.
Coerce function should do the same thing
for the purposes of that test.
2020-09-11 09:18:58 +00:00
herman ten brugge 853a498f2c Fix boundschecking for signal/sigaction/fork
The BOUNDS_CHECKING_ON/BOUNDS_CHECKING_OFF is not working for
signal/sigaction/fork. The reason is that the code stops bound checking
for the whole application. This result in wrong handling of
__bound_local_new/__bound_local_delete and malloc/calloc/realloc/free.
Consider the following code:

void tst(int n) {
  int i, arr[n];
  for (i = 0; i < n; i++) arr[i] = 0;
}

void *some_thread(void *dummy) {
  while (running) { tst(10); tst(20); }
}

void signal_handler(int sig) { ... }

When the signal handler is called the some_thread code can be interrupted when
is just registered the arr[10] data. When the signal handler is leaved the
arr[10] is still registered and did not see the call to deregister arr[10] and
then register arr[20]. The code resumes when tst(20) is running. This results
in a bound checking error when i >= 10.

To solve the above problem I changed the bound checking code to use
tls (thread local storage) for the no_checking variable.
This also makes it now possible to redirect signal/sigaction/fork code
through the bound checking library and disable checking when a signal is
running and to correct the bounds_sem for the fork child process.
The BOUNDS_CHECKING_ON/BOUNDS_CHECKING_OFF is not needed any more for
signal/sigaction/fork. In fact I could remove them from all my applications.

The use of the tls function code slows down the code by about 10%.
So if the slowdown due to bound checking was 5. It is now 5.5 times slower.

For x86_64/i386 I also allowed to use __thread variable in bcheck.c when
compiled with gcc with:
make x86_64-libtcc1-usegcc=yes
make i386-libtcc1-usegcc=yes
This makes code run faster due to use of gcc and __thread variable.
With the __thread variable there is no 10% slowdown.
For other targets this does not work because stabs is not supported.

Changes:

lib/bcheck.c:
- Add TRY_SEM
- Add HAVE_SIGNAL/HAVE_SIGACTION/HAVE_FORK/HAVE_TLS_FUNC/HAVE_TLS_VAR
  - HAVE_SIGNAL: redirect signal() call if set.
  - HAVE_SIGACTION: redirect sigaction() call if set.
  - HAVE_FORK: redirect fork() call if set.
  - HAVE_TLS_FUNC: If target has tls function calls.
  - HAVE_TLS_VAR: If target has __thread tls support.
- Replace all no_checking refecrences to NO_CHECKING_SET/NO_CHECKING_GET macros

tcc-doc.texi:
- Remove examples for signal/sigaction/fork code.
- Add some explanation for signal/sigaction/fork code.
- Add documentaion for __bounds_checking().

tccelf.c:
- Add support for SHF_TLS

tests/tests2/114_bound_signal.c:
- Remove BOUNDS_CHECKING_ON/BOUNDS_CHECKING_OFF
- Add code to trigger failure when tls is not working.

x86_64-link.c:
- Add support for R_X86_64_TLSGD/R_X86_64_TLSLD/R_X86_64_DTPOFF32/R_X86_64_TPOFF32

i386-link.c:
- Add support for R_386_TLS_GD/R_386_TLS_LDM/R_386_TLS_LDO_32/R_386_TLS_LE
2020-09-08 14:31:58 +02:00
grischka d746e32349 tests2: rework 117..119 to follow our conventions
Please respect some conventions:

- tests2 filenames don't end with '..._test'

- tests2 tests are meant to produce some output

- the output should be somehow informative, not just
  "error" or "dummy". Because other people would want to
  know where it fails if it does.

- tests2 tests should work with both GCC and TCC, except
  if there are specifc reasons (like testing tcc-only
  feature such as bounds checking)

- tests2 tests should never crash or abort.  Because that
  would cause gui dialogs to pop up on windows, and because
  other people would not know where it fails if it does.

- tests2 tests should be somehow specific, in general.
  (rather than just collections of random stuff)

- in general, do not use 'long' if you mean 'larger than int'
  Because it isn't on many platforms.

- use four (4) spaces for block indention.  Do not insert
  tab characters in files if possible.

Also:
- tccgen.c:gen_cast() simplify last fix.
2020-08-21 21:44:11 +02:00
grischka f9870f7860 bcheck: remove static (compile-time) control
Providing both run-time and compile-time control for bounds
checking as an user interface appears unnecessary and confusing.

Also:
- replace 'bound_...' by 'bounds_...' for consistency
- tcc-doc: put related info into one place and cleanup

The __bounds_checking(x) function is still missing explanation.
(I.e. what happens if the accumulated value drops below zero.)
2020-08-21 20:26:36 +02:00
herman ten brugge a34a9775ba Fix char to ushort cast
tccgen.c:
- gen_cast: add check for char to ushort cast

tests/bug.c:
- remove tst1

tests/tests2/117_gcc_test.c:
- add tst_cast
2020-08-21 19:35:30 +02:00
herman ten brugge 696b765437 Fix switch/case
Fix switch for signed/unsigned switch
Also add new testcase 118
2020-08-18 20:05:53 +02:00
herman ten brugge 4c9e3a5988 Update attribute bound_no_checking
tcctok.h:
- Add CONFIG_TCC_BCHECK  arround TOK_NO_BOUND_CHECK1/TOK_NO_BOUND_CHECK2

tccgen.c:
- Add CONFIG_TCC_BCHECK  arround TOK_NO_BOUND_CHECK1/TOK_NO_BOUND_CHECK2
- Undo alias definition in tccpp.c when function bound checking if off

tests/tests2/114_bound_signal.c:
- Test alias undo
- fix sleep problem
2020-08-14 06:35:47 +02:00
herman ten brugge 50fe33f880 Add attribute bound_no_checking
tcc-doc.texi:
- Document attribute bound_no_checking

tcctok.h:
- Add bound_no_checking attribute

tcc.h:
- Add no_bcheck function attribute

tccgen.c:
- Use function attribute no_bcheck in merge_funcattr/parse_attribute/gen_function

bcheck.c:
- Fix no_checking in __bound_new_region/__bound_free/__bound_check

tests/tests2/114_bound_signal.c:
- Fix code with new attribute bound_no_checking

tests/tests2/103_implicit_memmove.c:
- Fix memmove prototype
2020-08-13 11:19:11 +02:00
herman ten brugge 8b8e714517 Fix bound checking for packed struct 2020-08-11 07:33:11 +02:00
herman ten brugge e5da657c85 Fix testcase 95 for windows 2020-08-09 08:28:45 +02:00
herman ten brugge dcb87d36fe Fix long bitfield
The fix is avoiding a core dump for radare2 project.
2020-08-09 07:50:34 +02:00
herman ten brugge d55a3f3362 Fix riscv64 compare problem.
Fix 64->32 bits sign/zero extention for riscv64.
2020-07-30 09:40:35 +02:00
Michael Matz 2e798523e4 Fix conversions of subnormals to long double
those need to be normalized when extending from float/double to
binary128.
2020-07-15 22:02:02 +02:00
Michael Matz a614269794 riscv64: Fix a corner case
found in mpfr.  Expressions like "(longlong)i <= MAX_ULONGLONG" are
always true (not yet short-circuited in tcc), but still need to be
handled correctly in the backends.
2020-07-15 21:47:39 +02:00
Christian Jullien b5a89c8c93 macos: tcc searches for libtcc.dyln in the same directory as its executable 2020-07-09 12:04:57 +02:00
Christian Jullien 1ea425811a macos: ldd does not exit, use otool instead 2020-07-09 08:03:31 +02:00
herman ten brugge 20fa63488a Fix bounds checking
i386-gen.c:
- Fix large stack size alloca code.
  The returned value of alloca was not used corectly.

libtcc.c:
- Use __SIZE_TYPE__ for __builtin_offsetof

tccpp.c:
- Fix __MAYBE_REDIR and abort builtins.

tests/tests2/Makefile
- Run 117_gcc_test also with bound checking enabled
  This found the above problems.
2020-07-07 21:10:51 +02:00
grischka 2a0167adfe __builtin_/__bound_: A 'stay tiny' approach to the matter
tccgen.c:
- cleanup __builtin_... stuff
- merge __attribute((alias("sym"))) with __asm__("sym")
    Now one cannot have both, however for alias underscores are
    added if enabled.  For __asm__ they aren't.
tccpp.c:
- extend tcc_predefs accordingly.  Was generated with
  'cd tests/misc && tcc -run c2str.c tcc_predef.h tcc_predefs'
xxx-gen.c:
- move bcheck setjmp test to tccgen.c:gbound_args()
i386-gen.c:
- create win32 compatible stack space for big structures
tcctest.c:
- some cleanup + nicer output
2020-07-06 13:42:02 +02:00
grischka 6a4f3cf127 rework leading underscores
tested on win32/64 to pass the tests when enabled

- libtcc.c :
  let tcc define __leading_underscore if enabled
  tcc_add_symbol() : add _ automatically
- tccelf.c : remove tcc_get_symbol_err(), find_c_sym()
  currently symbol length is limited to 256 in several
  places, so we can use a fixed local buffer for now as well.
- win32/lib/crtinit.c : new file for init/fini
- lib/*.S, tests7* : use __leading_underscore
- bt-log.c: this file wont work relibaly if compiled with gcc
2020-07-06 13:00:47 +02:00
grischka 72277967ff some cleanups related to recent commits
- configure/Makefile : cleanup, really use CC_NAME
- tccasm.c : remove C99 construct that MSVC doesn't compile
- arm-gen.c, x86_64-gen.c, riscv64-gen.c, tccmacho.c : ditto
- arm64-gen.c: commit 383acf8eff wrote:
  "Instead of a cast, it would be better to pass the exact type."
  It is true that there are better solutions but it is not
  passing the exact type (I think).
- tcctest.c: revert "fix cast test for clang" 03646ad46f
  this obviously wants to test non-portable conversions
- 114_bound_signal.test: clock_nanosleep is too new for older
  linuxes, just use sleep() instead
2020-07-06 13:00:47 +02:00
grischka 0ee4989ed3 libtcc: accept tcc_define_symbol(s1, "sym=value", NULL)
Thus it can parse command-line -Dsym=value directly, for the
convenience of libtcc users or tcc itself

Also used in libtcc_test_mt.c to avoid strdup().
2020-07-06 13:00:47 +02:00
herman ten brugge 9712aff9c0 Fix gcc testsuite problems
arm-gen.c:
- is_hgen_float_aggr/gfunc_sret: Fix for zero sized structs

arm64-gen.c:
- arm64_ldrs: Fix for zero sized structs
- arm64_sym: Use R_AARCH64_ABS64 instead of R_AARCH64_MOVW_UABS_G*
             This has same speed. See 117_gcc_test.c(tst_adr)
- load: Fix for zero sized structs and add VT_CONST | VT_LVAL support
- store: add VT_CONST | VT_LVAL support
- arm64_gen_bl_or_b: Allow branch. See 117_gcc_test.c(tst_branch)
- gen_bounds_prolog: Use R_AARCH64_ABS64 for bound checking
- gen_bounds_epilog: Use R_AARCH64_ABS64 for bound checking
- gfunc_call: Allow large stack
- arm64_gen_opic: Do not crash on large shift

riscv64-gen.c:
- load: Move type_size call. (move_reg set sv.type.ref NULL for VT_STRUCT)
- gfunc_call: Allow large stack
- gen_opil: Fix word mode calls

x86_64-gen.c:
- load: Fix for zero sized structs

libtcc.c:
- Add some defines for gcc testsuite (only most common)

tccgen.c:
- parse_builtin_params: Add types for builtins
- unary: Add builtins: __builtin_abort __builtin_memcpy __builtin_memcmp
                       __builtin_memmove __builtin_memset __builtin_strlen
                       __builtin_strcpy __builtin_strncpy __builtin_strcmp
                       __builtin_strncmp __builtin_strcat __builtin_strchr
                       __builtin_strdup __builtin_malloc __builtin_realloc
                       __builtin_calloc __builtin_free __builtin_alloca
- decl_initializer: Fix crash. See 60_errors_and_warnings(test_var_array)

tccmacho.c:
- Remove 'ret = 0'

tcctok.h:
- Add builtin/bound checking tokens

tests/gcctestsuite.sh:
- Add more counters and run execute tests

tests/bug.c
- Some remaining bugs in tcc (not complete)

tests/tests2/60_errors_and_warnings:
- Add test_var_array test

tests/tests2/117_gcc_test:
- New test

Results of gcctestsuite.sh for all targets:

linux:
x86_64: 3036 test(s) ok.  328 test(s) failed.  24 test(s) exe failed.
i386:   3037 test(s) ok.  327 test(s) failed.  24 test(s) exe failed.
arm:    2986 test(s) ok.  362 test(s) failed.  40 test(s) exe failed.
arm64:  2996 test(s) ok.  367 test(s) failed.  25 test(s) exe failed.
macos:  3031 test(s) ok.  332 test(s) failed.  25 test(s) exe failed.
riscv:  2948 test(s) ok.  401 test(s) failed.  39 test(s) exe failed.

windows:
x86_64: 3027 test(s) ok.  333 test(s) failed.  28 test(s) exe failed.
i386:   3029 test(s) ok.  331 test(s) failed.  28 test(s) exe failed.

linux with bounds checking:
x86_64: 3030 test(s) ok.  328 test(s) failed.  30 test(s) exe failed.
i386:   3028 test(s) ok.  327 test(s) failed.  33 test(s) exe failed.
arm:    2997 test(s) ok.  362 test(s) failed.  29 test(s) exe failed.
arm64:  2986 test(s) ok.  367 test(s) failed.  35 test(s) exe failed.
macos:  3026 test(s) ok.  332 test(s) failed.  30 test(s) exe failed.
riscv:  2936 test(s) ok.  409 test(s) failed.  43 test(s) exe failed.

windows with bounds checking:
x86_64: 3029 test(s) ok.  332 test(s) failed.  27 test(s) exe failed.
i386:   3027 test(s) ok.  331 test(s) failed.  30 test(s) exe failed.

all: fail for complex and vector types, nested functions
     and a lot of gcc defines/buitins.
arm/arm64/riscv: fail for asm and alloca.
riscv: fail with 'error: unimp: store(struct)'
2020-07-05 14:01:50 +02:00
Christian Jullien 6a15f15093 Fix coredump on linux when boostrapping tcc with -std=c11 2020-06-26 11:36:41 +02:00
herman ten brugge 03646ad46f Fix cast_test for clang.
The code was not portable and gcc could produce the same problem.
2020-06-25 09:29:45 +02:00
herman ten brugge 86992622dc do not disable all asm_test for macos 2020-06-25 09:10:11 +02:00
herman ten brugge 50abaaeb0a Support clang on all targets
tccelf.c/tccpp.c/tccrun.c
Change: "..."+int into &"..."[int] to avoid clang warning.

tests/tcctest.c:
- Change __APPLE__ into __clang__
- Add undefined_function for clang
- disable most asm code for clang
- Fix res6/res8 for __builtin_constant_p
2020-06-24 20:51:18 +02:00
Christian Jullien 9ad25d7257 Add clock_nanosleep emulation for macOS
modified:   tests/tests2/114_bound_signal.c
2020-06-22 07:37:54 +02:00
Christian Jullien 925f6704ce Add clock_nanosleep emulation for macOS 2020-06-22 07:36:15 +02:00
Christian Jullien 4d28120e9b macos: test 114 is not supported on macOS and this is not related to old gcc version 2020-06-21 11:49:29 +02:00
Michael Matz 18db8da7df Workaround old GCC viz indexed string literals
GCCs before gcc8 didn't deal with these where constants are
required.
2020-06-20 23:17:02 +02:00
Michael Matz d174af08f9 macos: Fix memtest
* free allocated memory
* fix weak symbols related to -run
* remove memtest from ignored tests for OSX
2020-06-20 22:17:08 +02:00
Michael Matz fbfe6209be macos: Fix asm-c-connect-test
via some heavy-handed hackery in the ASM symbol handling in case
C symbols get a leading underscore (but ASM symbols do not).
But this is now like clang and GCC on Darwin work: asm symbols are
undecorated, C symbols get a _ prepended, so to connect both some
trickery is involved for the ASM symbols that don't have a _ prepended.
They must be included in the C symbol table (because that's what we use
to lookup also ASM labels), but they also must not disturb the normal
C symbol (which don't have the _ prepended), so they need some mangling.

A bit unsatisfying, but well.  So, add asm-c-connect-test to the working
ones for Darwin as well.
2020-06-20 22:17:08 +02:00
Michael Matz 3cf7bec12f macos: Enable all working tests
all except the below work now on MacOS, also as executable test,
not just with -run:
* dlltest - we don't support dylib generation (yet)
* memtest - tccmacho.c contains some leaks
* asm-c-connect-test - some confusion with underscores still
2020-06-20 22:17:08 +02:00
Michael Matz 9ce5b4a691 macos: Adjust tcctest.c for clang
we need to disable or adjust some tests where clang behaves
slightly different from GCC:
* slight difference in __FILE__ behaviour
* difference (to less useful vs GCC) in computed #include
* difference in __builtin_constant_p
* attribute(weak, alias) isn't supported by clang on MacOS (though
  it could be, as Mach-O has the capabilities for this)
* the built-in assembler of clang is mediocre

this was all checked with
  Apple LLVM version 10.0.1 (clang-1001.0.46.4)
2020-06-20 22:17:08 +02:00
Michael Matz 4eff2b5f6a macos: more adjustments for OSX systems
* instead of /usr/include use the current SDK path as system
  include directory (/usr/include is empty with current tools)
  (this also removes the need to add these paths in individual
  Makefiles)
* define _DARWIN_C_SOURCE in tcc.h to get the full set of decls
  from system headers (e.g. vsnprintf), similar to _GNU_SOURCE
  (and don't define _ANSI_SOURCE in the main Makefile anymore)
* tests/tests2/Makefile: remove the -w flag, it's added when necessary
  in the rules generating the .expect files
2020-06-20 22:17:06 +02:00
Michael Matz 91cb41330d macos: Adjust tests2.112 and tests2 Makefile
* <malloc.h> isn't as portable as <stdlib.h>
* skip 113_btdll.c on Darwin
* replace [...]\+ with [...]\{1,\} in the sed regex (basic REs
  have no + even some sed(1) accept it as \+, but bounds _are_ part
  of POSIX BREs)
2020-06-20 22:14:38 +02:00
Michael Matz 9d2ce50d2f macos: Use SDK path for headers
until we have it properly encoded within TCC itself.
2020-06-20 22:09:21 +02:00
Michael Matz 7b6931ed1f Fix some string literal expressions in initializers
Things like 'char x[] = { "foo"[1], 0 }' (which should initialize
a two-character array 'x' with "o\0").  See added testcase.
2020-06-20 22:00:18 +02:00
grischka 781872517d tccpp.c: compile 'tcc_predefs' from string
It might have advantages in cases if tcc/libtcc does not
depend on extern files.

Also:
- apply "stray \\ ..." check to macros only. For files it
  was already checked. Add positive test.
2020-06-17 18:01:45 +02:00
herman ten brugge 8fb8d88ea6 Add vla bound support for arm,arm64 and riscv64
tcctok.h:
- Add __bound_new_region

arm-gen.c arm64-gen.c riscv64-gen.c:
- Add bound checking support to gen_vla_alloc

tests/Makefile boundtest.c
- Add test18 vla bound checking test
2020-06-17 11:24:17 +02:00
herman ten brugge 0b8ee7364a Add bound checking to arm, arm64 and riscv64
Checked on:
- i386/x86_64 (linux/windows)
- arm/arm64 (rapberry pi)
- riscv64 (simulator)
Not tested for arm softfloat because raspberry pi does not support it.

Modifications:

Makefile:
  add arm-asm.c to arm64_FILES
  add riscv64-asm.c (new file) to riscv64_FILES

lib/Makefile:
  add fetch_and_add_arm.o(new file) to ARM_O
  add fetch_and_add_arm64.o(new file) to ARM64_O
  add fetch_and_add_riscv64.o(new file) to RISCV64_O
  add $(BCHECK_O) to OBJ-arm/OBJ-arm64/OBJ-riscv64

tcc.h:
  Enable CONFIG_TCC_BCHECK for arm32/arm64/riscv64
  Add arm-asm.c, riscv64-asm.c

tcctok.h:
  for arm use memmove4 instead of memcpy4
  for arm use memmove8 instead of memcpy8

tccgen.c:
  put_extern_sym2: for arm check memcpy/memmove/memset/memmove4/memmove8
                   only use alloca for i386/x86_64
  for arm use memmove4 instead of memcpy4
  for arm use memmove8 instead of memcpy8
  fix builtin_frame_address/builtin_return_address for arm/riscv64

tccrun.c:
  Add riscv64 support
  fix rt_getcontext/rt_get_caller_pc for arm

tccelf.c:
  tcc_load_dll: Print filename for bad architecture

libtcc.c:
  add arm-asm.c/riscv64-asm.c

tcc-doc.texi:
  Add arm, arm64, riscv64 support for bound checking

lib/bcheck.c:
  add __bound___aeabi_memcpy/__bound___aeabi_memmove
      __bound___aeabi_memmove4/__bound___aeabi_memmove8
      __bound___aeabi_memset for arm
  call fetch_and_add_arm/fetch_and_add_arm64/fetch_and_add_riscv64
  __bound_init: Fix type for start/end/ad
  __bound_malloc/__bound_memalign/__bound_realloc/__bound_calloc: Use size + 1

arm-gen.c:
  add bound checking code like i386/x86_64
  assign_regs: only malloc if nb_args != 0
  gen_opi/gen_opf: Fix reload problems

arm-link.c:
  relocate_plt: Fix address calculating

arm64-gen.c:
  add bound checking code like i386/x86_64
  load/store: remove VT_BOUNDED from sv->r
  arm64_hfa_aux/arm64_hfa_aux: Fix array code
  gfunc_prolog: only malloc if n != 0

arm64-link.c:
  code_reloc/gotplt_entry_type/relocate: add R_AARCH64_LDST64_ABS_LO12_NC
  relocate: Use addXXle instead of writeXXle

riscv64-gen.c:
  add bound checking code like i386/x86_64
  add NB_ASM_REGS/CONFIG_TCC_ASM

riscv64-link.c:
  relocate: Use addXXle instead of writeXXle

i386-gen.c/x86_64-gen.c
  gen_bounds_epilog: Fix code (unrelated)

tests/Makefile:
  add $(BTESTS) for arm/arm64/riscv64

tests/tests2/Makefile:
  Use 85 only on i386/x86_64 because of asm code
  Use 113 only on i386/x86_64 because of DLL code
  Add 112/114/115/116 for arm/arm64/riscv64
  Fix FILTER (failed on riscv64)

tests/boundtest.c:
  Only use alloca for i386/x86_64
2020-06-16 07:39:48 +02:00
Michael Matz 9eef33993a Fix type compatiblity of enums and ints
an enum must be compatible with one or more integer type,
so adjust the test accordingly.  That means the following
redeclarations should work:

  enum e6 { E1 = -1, E0 };
  void f3(enum e6);
  void f3(int);        // should work as int and e6 are compatible

while the following should not:

  void f4(enum e6 e);
  void f4(unsigned e); // should error as unsigned and e6 are incompatible
2020-06-05 16:02:08 +02:00
Michael Matz 068d5b3d20 pp: Move errors about stray backslashes
they were emitted too early, in particular also in macro
substitution which might turn out to not be stray in case it's
further stringified.  Check in next() instead.  Add two testcases
that an error is still emitted for obvious top-level baskslashes,
and that stringifying such a thing works.
2020-06-03 18:38:11 +02:00
herman ten brugge 3b617fdc53 Add sigsetjmp/siglongjmp bound checking support
tcctok.h:
- Add sigsetjmp/__sigsetjmp/siglongjmp

tccgen.c:
- redirect sigsetjmp/siglongjmp to bcheck.c code

i386-gen.c/x86_64-gen.c
- gcall_or_jmp: Set func_bound_add_epilog also when sigsetjmp is called
- gen_bounds_epilog: Only call __bound_local_new when needed (unrelated)

bcheck.c:
- Add __bound_siglongjmp
- __bound_setjmp/__bound_long_jump: Check no_checking
- Optimize __bound_local_delete (unrelated)

Modify testcase:
- 114_bound_signal
2020-05-25 12:26:55 +02:00
herman ten brugge b5b92c7d6d Add setjmp/longjmp bound checking support
tcctok.h:
- Add __bound_setjmp/setjmp/_setjmp/longjmp

tccgen.c:
- redirect setjmp/longjmp to bcheck.c code

i386-gen.c/x86_64-gen.c
- Change func_bound_alloca_used into func_bound_add_epilog
- Set func_bound_add_epilog also when setjmp is called

bcheck.c:
- Add __bound_setjmp/__bound_longjmp
- __bound_local_delete: remove setjmp if used in function
- __bound_exit: clear setjmp list and print statistic
- make malloc_redir more readable (unrelated)

New testcases:
- 115_bound_setjmp
- 116_bound_setjmp2
2020-05-23 20:02:41 +02:00
grischka 4429cef9f6 tccgen.c: merge more function attributes
Merge function attributes with those given given for the
prototype, also handle post-decl appearance such as

    void func() __attribute__((noreturn))
    {
    }

Also, some test fixes (unrelated).
2020-05-13 11:39:39 +02:00
grischka 7bb5454ef3 make SILENT=yes
This allows to run make more silently.

Also, turns off debug info for binaries by default,
but adds a switch to get it back easily

    ./configure --debug
2020-05-12 20:35:43 +02:00
herman ten brugge 8370bc03a1 Allow signal handlers when bound checking
Disable generating bound_local_new/bound_local_delete when not needed.
Add new testcase 114_bound_signal.
2020-05-05 08:31:57 +02:00
Michael Matz 2f94390223 musl: disable boundcheck tests
for now that doesn't work with musl libc.
2020-04-15 22:08:18 +02:00