Commit Graph

2732 Commits

Author SHA1 Message Date
Michael Matz
40671f76e4 Fix parsing of .s files
those aren't preprocessed, but our use of a fake file in
preprocess_start requires inline stack processing (which isn't done
without preprocessing).  Just don't try to setup anything requiring
preprocessing at all in this case.
2020-07-06 18:12:35 +02:00
Michael Matz
de06193d88 tccpp: Add -bench -E mode
for benchmarking the preprocessor, without having to use the PP_BENCH
macro.  No output will be produced for '-E -bench', so it's the raw
tokenization/preprocess speed.
2020-07-06 17:41:05 +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
coltrane
90e9e34bec Add missing ws2tcpip.h which lets Microsoft Winsock Server sample compile ROOTB on Windows platform. 2020-07-06 09:47:09 +02:00
coltrane
e5d7e37157 Add missing ws2tcpip.h which lets tcc compile Microsoft Winsock Server sample on Windows platform. 2020-07-06 09:45:41 +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
Christian Jullien
383acf8eff Fix warning detected by clang when passing unsigned int pointer when signed is expected. Instead of a cast, it would be better to pass the exact type. 2020-06-25 07:15:34 +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
herman ten brugge
d5822b725e Fix ctype.h warning in lib/bcheck.c 2020-06-24 15:12:58 +02:00
Christian Jullien
f6e392a4af macos: add __builtin_flt_rounds. Forced to 1 which means 'to nearest' 2020-06-24 10:37:28 +02:00
Christian Jullien
f635de709e macos: clang -s option is obsolete - at least on macOS. 2020-06-24 07:06:48 +02:00
Christian Jullien
8bad5bfae5 macos: internally define _DONT_USE_CTYPE_INLINE_ otherwise, ctype.h macros may be defined multiple times in different translation units. 2020-06-23 15:53:01 +02:00
Christian Jullien
6b2bed447f macos: add some macros to replace few __builtin_xxx functions used in headers. 2020-06-23 12:27:03 +02:00
Christian Jullien
15e4f8b3b0 macos: Add DYLD_LIBRARY_PATH to tcc when configured with --disable-static - i.e. with .dylib support 2020-06-23 09:14:02 +02:00
Christian Jullien
9617ea6a3a macos: workaround to build tcc using tcc until .o object files generated by tcc are fully compatible with ar. Instead of ar, use 'tcc -ar' 2020-06-23 06:51:51 +02:00
herman ten brugge
3c53d54a43 Fix environ variable for macos. 2020-06-22 18:10:30 +02:00
herman ten brugge
039e4ec2a4 Call __bound_main_arg at startup
This uses a glibc feature present since constructor/destructor support was added.

Modify tccrun.c to call constructor with argc, argcv, envp.
In lib/bcheck.c use these values to register them in the splay tree.
Remove HAS_ENVIRON is lib/bcheck.c as it is not needed any more.
Modify win32/lib/crt1.c/win32/lib/dllcrt1.c/win32/lib/wincrt1.c to also
call constructor with argc, argcv, envp.
While implementing I saw that tccrun did nog call main with envp. Fixed it.
Also fix fetch_and_add_arm.S to make it work on armv6 (raspberry pi default).
2020-06-22 14:55:27 +02:00
Christian Jullien
0262f0eb1e macos: fix typo in conftest 2020-06-22 10:19:09 +02:00
Christian Jullien
f84e96fe81 macos: add 'c' option to conftest to get real compiler name and not an alias as with gcc on macOS 2020-06-22 10:12:18 +02:00
Christian Jullien
28d5c5e54f macos: apply readlink to get exact compiler name 2020-06-22 10:11:08 +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
Christian Jullien
c69356635c macos: add darwin OS detection. 2020-06-21 10:58:36 +02:00
Christian Jullien
a3d1e9cd3d macos: Reorder C compiler detection so that conftest allows to boostrap tcc with tcc on macos. 2020-06-21 10:52:04 +02:00
Christian Jullien
8d9b83bd11 macOS configure correctly reports clang and version 2020-06-21 09:53:52 +02:00
Michael Matz
ba8980f492 limit gnu_inline hack to macos
some linux programs (kernel) really want to have 'extern inline'
functions be visible from other units, i.e. not be static, but also
mark them as always_inline.  That's -fgnu89-inline semantics, so it's
fine, but we don't (yet) implement this, so we can't make them static
just so.  But we do need this hack on MacOS due to some uses in
system headers (see commit f18f8651).

So, for now conditionalize the hack on Mach-O.
2020-06-21 02:03:46 +02:00
Michael Matz
c883d43ae5 fixes for deadlocks and dollars in asm
* tccelf code doesn't use USING_GLOBALS, hence must be called from
  outside the semaphore
* dollars aren't part of identifiers in asm mode
2020-06-21 01:45:35 +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
1711eb2ef3 macos: add overview comment 2020-06-20 22:25:08 +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
ac86fb50cd macos: Tidy code 2020-06-20 22:17:08 +02:00
Michael Matz
c86760c1e9 macos: Read exported symbols from dylibs
up to now we simply assumed that any undefined symbols will be
provided by some shared libs on the cmdline.  Now we check this.
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
f486b19f56 macos: bound_alloca symbol adjust
so that tests/boundtest.c links as well.
2020-06-20 22:17:08 +02:00
Michael Matz
f2e154e1e5 macos: Disable verbose linking output 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
f18f865159 Handle always_inline as GNU inline
this is needed for multi-file testcases using stdio.h, as
the __sputc function is implemented as a extern inline
function (with gnu_inline attribute, but we don't support that for now).

Without this change that leads to multiply defined symbols when using
multiple units including stdio.h.

It also has an always_inline attribute, which we can use to guide our
behaviour, as in ISO-C an always_inline can't be defined with ISO
'extern inline' semantics.  This is the minimal change and not a full
implementation of GNU inline semantics, which would require thorough
testcases.

If __clang__ would be defined the header would make use of C99 semantics,
which would work for us.  It would also do that if _GNUC_ wouldn't be
defined.  But we can't do the latter (as the whole MacOSX SDK refuses
to be compiled with anything not defining that).  I haven't tested
defining __clang__, but suspect that's going to be problematic.
2020-06-20 22:14:56 +02:00
Michael Matz
5d2f4cb403 macos: various fixes
* alloca needs to be _alloca
* int64_t and uint64_t are also defined in <sys/_types/_int64_t.h>
  but as long long, not as long, so adjust out <stddef.h> to agree
  on Darwin
* define __APPLE_CC__ so that <TargetConditionals.h> correctly defines
  various macros like TARGET_OS_MAC and TARGET_CPU_X86_64
2020-06-20 22:14:56 +02:00
Michael Matz
b0b0e48409 macos: Use <dispatch.h> for locking
the global compiler lock can't be a POSIX non-shared semaphore on
Darwin (because not implemented there).  Use the dispatch framework.
2020-06-20 22:14:56 +02:00
Michael Matz
57ba50e611 macos: support bounds checking
* non-process-shared POSIX semaphores aren't supported on
  Darwin, we use the dispatch framework
* dlsym segfaults with RTLD_NEXT from JIT code, so we must not
  even try this for -run.  So we need to know in __bound_init
  if called from -run code, or from normal code, which means passing
  this down also from __bt_init and hence from the stub added in
  tcc_add_btstub
* Darwin uses different structures for <ctype.h> facilities, this
  merely adds a warning about this
* __libc_freeres doesn't exist
* for non -run modus the context (.prog_base member) is constructed
  incorrectly (uses symbol zero for trying to get at the load bias,
  which doesn't really work that way), on Mach-O this errors out
  (and could also error out on ELF).  For now deactivate this, which
  makes backtraces not be symbolic on MacOS for not -run.
2020-06-20 22:14:56 +02:00
Michael Matz
0b3c8360a0 macos: section syms, strtab, runtime
uncovered by the backtrace/boundcheck tests:

* handle STT_SECTION symbols
* call tcc_add_runtime (to get the bcheck.o/bt-exe.o files added)
* add .stab strtab into segments (we should probably add all stab
  syms to the output LC_SYMTAB eventually, but right now TCC uses
  32 bit stabs, while mach-o uses 32/64bit stabs
2020-06-20 22:14:56 +02:00