1
0
Fork 0
Commit Graph

320 Commits

Author SHA1 Message Date
grischka 2b0a663df9 libtcc usability improvements
- tccgen.c: cleanup switch data etc. after errors (*)
- tccpe.c: faster get_dllexports (*)
- tccpe.c: support -Wl,-e[ntry]=... (*)
- libtcc.c: win32: use ANSI functions (GetModuleFileNameA etc.)
- tccrun.c: be nice to tcc-0.9.26 ("struct/enum already defined")
- tccpp.c: be nice to tcc-0.9.27's va_start/end macros

(*) suggested by Robert Schlicht
https://lists.gnu.org/archive/html/tinycc-devel/2024-03/msg00012.html
2024-03-13 21:06:01 +01:00
grischka 9d2068c630 tccrun: add option CONFIG_RUNMEM_RO=2
/* 0 = .text rwx  other rw (memory: min 2 pages) */
/* 1 = .text rx   other rw (memory: min 3 pages) */
/* 2 = .text rx  .rdata ro  .data/.bss rw (memory: min 4 pages) */

tcc -vv -run ... shows some info.
Also when compiled with -DMEM_DEBUG:
tcc -bench -run ... shows some memory usage
2024-03-03 21:39:53 +01:00
grischka 7b9f19eaab tccpp: macro cleanup
- remove TOK_NOSUBST, mark the token itself instead
- get_tok_str(); mask out SYM_FIELD & update uses
- next(): optimize (~5% faster with tcc -E)
- tok_flags: remove some redundancy
- parse_define(): do not remove spaces around '##' and after '#'
    and mark macros with '##' as MACRO_JOIN to avoid unnecessary
    call to macro_twosharps(mstr):
- next_nomacro(): removed, next_nomacro1(): renamed to next_nomacro()
- next_argstream(): cleanup & new function peek_file()
- macro_subst_tok(): handle special macros (__DATE__ etc.)
  like normal macros if they are #defined
- -DPP_DEBUG : more structured output
- pp_error(): better preprocessor expression error message
- tcctok.h: sort basic keywords (somehow)
- testspp/Makefile: generate .expect with 'make testspp.##+'
- tcc.c: tcc -E -o file : put unixy LFs also on windows
2024-02-09 18:38:14 +01:00
grischka da0d43903b review recent commits
tccpp.c:
 - revert "Preprocessor fix + new testcase"
   Fix was not a fix and nobody could understand the test.
   This reverts 6379f2ee76
 - better fix and add new test (pp/18.c)

tccgen.c:
 - remove global variables 'in_sizeof', 'constant_p'
 - rework comma expression (gexpr())
 - merge func/data 'alias_target' codes
   (See 08c777053c)
 - move call to do_Static_assert()
 - better error: "expression expected before '%s'"
 - fix "statement after label"
    - remove unnecessary second parameter to block()
    - remove unnecessary call to decl()
    - revert changes to old C89 test file
    See 7f0a28f6ca

tccelf.c:
 - rework "...make undefined global symbol STT_NOTYPE"
   (See f44060f8fc)
 - move tccelf_add_crtbegin() from libtcc.c

tcctest:
 - unfix K&R fix (keep old look of K&R functions)

tccrun.c:
 - exit(0) returns 0

libtcc.c:
 - move #defines for -dumpmachine
 - more explicit error "file not found"
   (as opposed to error while loading file)

tccpe.c, x86_64-gen.c, i386-asm.c, tccasm.c:
 - use R_X86_64_PLT32 for functions on x86_64-win32

tccdefs.h
 - empty #defines for _Nonnull, __has_builtin(), etc.

configure:
 - Simpler "macOS .dylib ... VERSION letters."
   (See 6b967b1285)

Makefile:
 - macOS version also
 - add cross searchpaths for packages

build.yml:
 - disable codesign on macos-11 (doesn't seem to work)
2024-02-04 18:18:40 +01:00
herman ten brugge 6379f2ee76 Preprocessor fix + new testcase 2023-12-29 09:08:25 +01:00
Eric Raible b214fb6ed3 Produce better error message on malformed while loop
echo "void bugged() { do {} }" | tcc -run -
now produces the sensible:  -:1: error: 'while' expected (got "}")

I believe (but am far from sure) that the additional use of &tokc is ok.
2023-10-03 22:13:56 -07:00
grischka cd75ca692a stuff & fixes
libtcc.c:
- revert "Small patch to allow..." (someone's personal easteregg)
  (see da3a763e97)
- check return value from macho_load_tbd/dylib

tcc.c:
- remove help for "not yet implemented" option

tccelf.c:
- check PIE's for "unresolved symbols"

tccgen.c:
- avoid int->double->int cast
  (see a46372e910)
- fix constant propagation with pseudo long doubles
  (must mask out VT_LONG from type)
- cleanup find_field() (again)

tccpp.c:
- disallow strings and double constants in #if expressions

win32/include/uchar.h:
- change file mode
2023-09-06 22:42:30 +02:00
grischka 022fb4293b tccpp: #pragma once normalized
In order to detect a "same file" faster, this makes one
restriction to the feature: the basenames are required to
match at least (as in "test.h" and "dir/../test.h")

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

This rewrites commits
30fd24abd4
4e363a1728

 3 files changed, 38 insertions(+), 74 deletions(-)
2023-07-31 12:22:10 +02:00
herman ten brugge c92f4f52d9 Update pragma once for file operations
Use open/read/close instead of fopen/fread/fclose for tcc4tcl and ziptcc
2023-06-26 11:19:41 +02:00
herman ten brugge 4e363a1728 Small update on pragma once
Update on calc_file_hash. Use xor instead of +.
Only calculate has if file name differs in search_cached_include.
2023-06-26 06:33:46 +02:00
herman ten brugge 30fd24abd4 Allow different names for pragma once
pragma once can now be used with
test.h
./test.h

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

On linux we can use stat and st_ino to check for the same file.
On windows the st_ino does not work so we calculate a file hash
if the size of the file differs and then compare the hash.
2023-06-25 20:23:58 +02:00
grischka bb93bf8cd2 stuff & etc..
- tccpp.c: rename ... to __TCC_BCHECK__/__TCC_BACKTRACE__
- libtcc.c: correct total line count
- libtcc.c: support -run -- args... (instead of -run @ args ...)
- Makefile/build-tcc.bat: streamline GITHASH string somewhat
- bt-exe.c: avoid redef of pstrcpy() with 'tcc -bt tcc.c ...'
2023-04-25 15:22:31 +02:00
grischka a045400501 CStrings leakless
avoid memory leaks with lost CStrings on stack after errors.

tccpp.c:
- use/abuse static Cstring tokcstr where possible
tccgen.c:
- use/abuse static Cstring initstr where possible
tcc.h/libtcc.a:
- add 'stk_data' array to track memory pointer on stack
- add macros stk_push/pop() and cstr_new/free_s()
tccasm.c:
- use that
- use char[16] instead of char* for op.constraint
2023-04-25 15:22:20 +02:00
grischka 19ef024aa9 lib/armeabi.c: fix zero from/to double conversion
tccgen.c:
- allow cross-compiling 0.0L (cross-compile tcc with tcc)
tccelf.c:
- use alignment of TLS section for PT_TLS
tccpp.c:
- support long double constants on systems that do not support
  long doubles (i.e. mark them (VT_DOUBLE | VT_LONG))
tccdefs.h:
  #define __has_feature() for android
  remove _unaligned (why define a msvc extension under !_WIN32)
2023-04-25 08:59:42 +02:00
grischka 86f3d8e331 tccpp: remove unwanted space with __VA_ARGS__
reported by "vsfos"
https://lists.gnu.org/archive/html/tinycc-devel/2023-04/msg00007.html
2023-04-20 14:18:29 +02:00
grischka 19e3e10e4b small scopes cleanup etc.
tccgen.c:
- just track local_stack for small scopes (can't declare variables)
- fix a vla problem with nested scopes
- move debug N_L/RBRAC into curly braced block

Also:
- tccpp.c: move 'label_...' functions to tccgen.c
- tccpp.c: let get_tok_str() say "<no name>" for anonymous symbols
- tcctest.c: let __pa_symbol() work for memory > 2GB
- 119_random_stuff.c: revert strtoll test (no reason to test libc)
- tccdefs.h/tcctest.c: enable bit fncs for _WIN32
- Makefile:
  - use i686-linux-gnu instead of i386-linux-gnu for cross-i386
  - update 'make help'
  - revert umplicit 'make all' with 'make install' (but print warning)
2023-03-12 20:40:50 +01:00
herman ten brugge 065b401c6e Fix static assert with empty string 2022-11-29 19:45:05 +01:00
herman ten brugge 878fcccdb2 Small preprocessor fix
Set BOL flag for code like:
  #define tcc_test()
  #if 1
  tcc_test
  #endif
2022-10-17 07:49:47 +02:00
grischka aef64762c1 tccpp: #define max(a,b) && max /= 8;
This fixes 20a1ebf854
where the '/' above was lost when max() was defined

Also: ignore binary files with -E (for example 'tcc -lxxx -E ...')
2022-10-09 20:30:15 +02:00
grischka e41730f11a - tcc -vv: show cross-libtcc1.a correctly (and more)
(As long as it is in the default install location and was not
moved elsewhere into the library search path manually)

Also:
- libtcc.c:
  - error1(): show correct line with "In file included from ..."
  - support "tcc -Bxxx -vv"
  - tcc_new()/tcc_compile(): Don't create elf sections for tcc -E
- tccdbg.c:
  - tcc -E -g : revert 1de025c13a
    Let's keep things simple, everybody understands 'do_debug'
    and dState is set by tcov too (but no debug sections).
- tccgen.c:
  - avoid the extra parameter for gind()
    (from c3e3a07ed4)
  - vla func params: use skip_or_save_block() and enable
    VT_LVAL (see 313855c232)
  - cleanup nocode_wanted a bit
- tccelf.c:
  - tccelf_end_file(): don't try to translate zero-sym relocs
    (seems to happen with asm "jmp 0x1000")
  - version_add(): do not make "ld-linux.so" DT_NEEDED
2022-09-24 09:46:17 +02:00
herman ten brugge 76b88e22a4 Fix last __has_include update
After this last change the radare2 project did not compile anymore.

Start with BOL flag after include ends in tccpp.c.
Update testcase 18.
2022-09-12 11:37:47 +02:00
grischka 20a1ebf854 tccpp : get rid of 'ch'
- also simplify parse(_line)_comment() and parse_pp_string()
- fixes a continuation problem in strings (see tcctest.c)
- no differences in performance could be observed

161 insertions(+), 246 deletions(-), less 85 lines
2022-08-18 11:34:36 +02:00
grischka 85c32ddd0b tccpp: integrate __has_include() more nicely
- make only one function from previously four pieces
- use parse_pp_string() for the normal cases "..." and <...>
- use the sanity check for computed include as end-condition too.
- use 's1' instead of 'tcc_state' when possible

117 insertions(+), 165 deletions(-), less 48 lines
2022-08-18 10:23:13 +02:00
Michael Matz 64f4b00d34 tccpp: Fix #ifdef in macro args
see testcase.  We have to "empty" the macro-stack string on
end_macro, as it may be 'tokstr_buf' which is going to be used
twice in recursive invocations of macro_subst_tok.  The uses aren't
overlapping but the first one needs to be properly finalized.
2022-08-16 15:59:41 +02:00
Michael Matz 98bab41cba Support asm goto
this adds generic support for asm goto, but I've tested only
on x86.
2022-08-16 15:59:41 +02:00
herman ten brugge 47dc6e6d7b Add __has_include and __has_include_next support
tcctok.h:
- Add __has_include_next

tccpp.c:
- New functions parse_include and get_include_file
- Changed expr_preprocess and preprocess
2022-08-14 12:17:31 +02:00
herman ten brugge b7733aeef1 Fix wchar_t strings with 'x', 'u' and 'U' 2022-08-11 08:37:00 +02:00
grischka 09808f327f tcc android-enabled (armeabi-v7a)
On an armeabi-v7a device (phone) in the termux app with
clang & make installed this passes all the tests.

Can be used as a cross compiler to create "native apps" as well.
Example 'config-extra.mak' for the cross arm-eabi-tcc:

  SYSROOT = <path_to_android_ndk...>/sysroot/usr
  TRIPLET = arm-linux-androideabi
  ANDRVER = 32

  ROOT-arm-eabi = $(SYSROOT)

  CRT-arm-eabi = {R}/lib/$(TRIPLET)/$(ANDRVER)
  LIB-arm-eabi = {B};{R}/lib/$(TRIPLET)/$(ANDRVER);{R}/lib/$(TRIPLET)
  INC-arm-eabi = {B}/lib/include;{R}/include/$(TRIPLET);{R}/include

  DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
  DEF-arm-eabi += -DTARGETOS_ANDROID -DCONFIG_TCC_PIE -DCONFIG_NEW_DTAGS
  DEF-arm-eabi += -DCONFIG_TCC_ELFINTERP=\"/system/bin/linker\"

  # on unix replace ';' by ':'.
  $ ./configure && make cross-arm-eabi && make install
2022-07-24 09:51:32 +02:00
Arthur Williams 8482682061 Define __TCC_BACKTRACE_ENABLED__ if backtrace is enabled
If the `-btN` was specified, then the __TCC_BACKTRACE_ENABLED__
macro will be defined. This provides a way for user code
to tell if tcc_backtrace is defined or not.
2022-07-23 15:12:15 -07:00
grischka af1abf1f45 Revert "Fix wrong handling of strings..." (almost)
See commit e588b65390.
Was not "wrong" really, just different. But appears to be outdated.
Now disabled by default (top of tccpp.c: ACCEPT_LF_IN_STRINGS)
Also, in skipped code, just warn.

Also: cleanup "Optimize small structure copying on x86_64"
(commit 3715f1d7ee)
- remove some copy&paste coding (tccgen.c)
- RSI/RDI need to be preserved on windows
- simply don't use under bcheck (this is tinycc)
2022-07-16 00:41:37 +02:00
Ziyao e588b65390
Fix wrong handling of strings which do not end properly at the end of line 2022-07-13 15:43:26 +08: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
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 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
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 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
grischka e97e108d0b tccpe: #pragma pack(push) - support this form 2021-09-01 19:36:24 +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
Steffen Nurpmeso 0c16762418 -W[no-]error=X: gcc compat: when disabling X again, do not unset the warning 2021-07-27 19:48:29 +02:00
Steffen Nurpmeso a7a13896b3 Add -W[no-]error=OPTION specific abortions 2021-07-27 00:37:22 +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
Arthur Williams ee75521dd5 Support -M, -MM, and -MMD
Add support for some more options to generate dependency fragments.
-M is likes -MD but doesn't compile anything so the command won't fail
when just supplied a file without all the relevant libs.
-MM and -MMD are like their counterparts but skip system libs.

Note the behavior of -MD has changed to include system libs. Use -MMD
for the old behavior. This matches gcc's corresponding flags
2021-07-01 01:44:34 -05: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
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
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
CodeHz a1d10c8bde
Fix unnecessary symbol collision 2021-02-18 20:41:47 +08:00