aboutsummaryrefslogtreecommitdiff
path: root/tcc.h
Commit message (Collapse)AuthorAgeFilesLines
* Introduce VIP sysinclude paths which are always searched firstSteffen Nurpmeso2017-10-031-5/+13
|
* Use more conventional punctuation for sequential assignmentsLarry Doolittle2017-09-251-6/+6
|
* Spelling fixesLarry Doolittle2017-09-241-1/+1
| | | | Comments only, no change to functionality
* 'long' reviewgrischka2017-09-241-12/+11
| | | | | | | | | | | | | | | | | | | | | add some features for more complete 'long' support tcc.h: - use LONG_SIZE=4/8 instead of TCC_LONG_ARE_64_BIT tccgen.c: - add ptrdiff_type, update size_type - support shift and ?: operations - support long enum types - display 'long' from type_to_str - nwchar_t is unsigned short on windows - unrelated: use memcpy in init_putv for long doubles to avoid random bytes in the image (if tcc was compiled by gcc) for diff purposes. tccpp.c: - make parse_number return correct types - improve multi-character-constants 'XX' 'abcd' Changelog: - update
* tccgen: nodata_wanted fix, default ONE_SOURCE, etc...grischka2017-07-231-23/+36
| | | | | | | | | | | | | | | | | | | | | | | | | tccgen.c: doubles need to be aligned, on ARM. The section_reserve() in init_putv does not do that. -D ONE_SOURCE: is now the default and not longer needed. Also, tcc.h now sets the default native target. These both make compiling tcc simple as "gcc tcc.c -o tcc -ldl" again. arm-asm.c: enable pseudo asm also for inline asm tests/tests2/Makefile: disable bitfield tests except on windows and x86_64 and don't generate-always tcc.c: fix a loop with -dt on errors configure: print compiler version (as recognized) tccpp.c: actually define symbols for tcc -dt clear static variables (needed for -dt or libtcc usage) 96_nodata_wanted.c: use __label__ instead of asm lib/files: use native symbols (__i386__ etc.) instead of TCC_TARGET_...
* mutiples fix for _Genericmatthias2017-07-211-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * check that _Generic don't match unsigned char * with char * this case is usefull as with -funsigned-char, 'char *' are unsigned * change VT_LONG so it's now a qualifier VT_LONG are never use for code generation, but only durring parsing state, in _Generic we need to be able to make diference between 'long' and 'long long' So VT_LONG is now use as a type qualifier, it's old behaviour is still here, but we can keep trace of what was a long and what wasn't * add TOK_CLONG and TOK_CULONG tcc was directly converting value like '7171L' into TOK_CLLONG or TOK_CINT depending of the machine architecture. because of that, we was unable to make diference between a long and a long long, which doesn't work with _Generic. So now 7171L is a TOK_CLONG, and we can handle _Generic properly * check that _Generic can make diference between long and long long * uncomment "type match twice" as it should now pass tests on any platforms * add inside_generic global the point of this variable is to use VT_LONG in comparaison only when we are evaluating a _Generic. problem is with my lastest patchs tcc can now make the diference between a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc break when stdint.h and stddef.h are include together. Another solution woud be to modifie include/stddef.h so it define uint64_t as unsigned long int when processor is 64 bit, but this could break some legacy code, so for now, VT_LONG are use only inside generc. * check that _Generic parse first argument correctly * check that _Generic evaluate correctly exresion like "f() / 2"
* tcc -dt -run ... : simpler is bettergrischka2017-07-201-22/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * -dt now with lowercase t * test snippets now separated by real preprocessor statements which is valid C also for other compilers #if defined test_xxx < test snippet x > #elif defined test_yyy < test snippet y > #elif ... #endif * simpler implementation, behaves like -run if no 'test_...' macros are seen, works with -E too * for demonstration I combined some of the small tests for errors and warnings (56..63,74) in "60_errors_and_warnings.c" Also: * libtcc.c: put tcc_preprocess() and tcc_assemble() under the setjmp clause to let them return to caller after errors. This is for -dt -E. * tccgen.c: - get rid of save/restore_parse_state(), macro_ptr is saved by begin_macro anyway, now line_num too. - use expr_eq for parsing _Generic's controlling_type - set nocode_wanted with const_wanted. too, This is to keep VT_JMP on vtop when parsing preprocessor expressions. * tccpp.c: tcc -E: suppress trailing whitespace from lines with comments (that -E removes) such as NO_GOTPLT_ENTRY,\t /* never generate ... */
* tccgen: nodata_wantedgrischka2017-07-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | The existing variable 'nocode_wanted' is now used to control output of static data too. So... (nocode_wanted == 0) code and data (normal within functions) (nocode_wanted < 0) means: no code, but data (global or static data) (nocode_wanted > 0) means: no code and no data (code and data suppressed) (nocode_wanted & 0xC0000000) means: we're in declaration of static data Also: new option '-dT' to be used with -run tcc -dT -run file.c This will look in file.c for certain comment-boundaries: /*-* test-xxx: ...some description */ and then for each test below run it from memory. This way various features and error messages can be tested with one single file. See 96_nodata_wanted.c for an example. Also: tccgen.c: one more bitfield fix
* #pragma comment(option,"-..."), bitfields test, etc...grischka2017-07-141-0/+1
| | | | | | | | | | | | | | | | | | tccpp.c: * #pragma comment(option,"-some-option") to set commandline option from C code. May work only for some options. libtcc.c: * option "-d1..9": sets a 'g_debug' global variable. (for development) tests2/Makefile: * new make targets: tests2.37 / tests2.37+ run single test from tests2, optionally update .expect * new variable GEN-ALWAYS to always generate certain .expects * bitfields test tccgen.c: * bitfields: fix a bug and improve slightly more * _Generic: ignore "type match twice"
* Fix statement exprs returning a local labelMichael Matz2017-07-101-1/+1
| | | | | | Like returned local variables also labels local to a statement expression can be returned, and so their symbols must not be immediately freed (though they need to be removed from the symbol table).
* refactor bitfieldsgrischka2017-07-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use 2 level strategy to access packed bitfields cleanly: 1) Allow to override the original declaration type with an auxilary "access type". This solves cases such as struct { ... unsigned f1:1; }; by using VT_BYTE to access f1. 2) Allow byte-wise split accesses using two new functions load/store_packed_bf. This solves any cases, also ones such as struct __attribute((packed)) _s { unsigned x : 12; unsigned char y : 7; unsigned z : 28; unsigned a: 3; unsigned b: 3; unsigned c: 3; }; where for field 'z': - VT_INT access from offset 2 would be unaligned - VT_LLONG from offset 0 would go past the total struct size (7) and for field 'a' because it is in two bytes and aligned access with VT_SHORT/INT is not possible. Also, static bitfield initializers are stored byte-wise always. Also, cleanup the struct_layout function a bit.
* refactor enumsgrischka2017-07-091-13/+18
| | | | | | Eliminate VT_ENUM as a basic type. Instead use the integral types VT_InT/VT_LLONG with an additional flag to indicate that it is an enum.
* refactor sym & attributesgrischka2017-07-091-72/+77
| | | | | | | | | | | | tcc.h: * cleanup struct 'Sym' * include some 'Attributes' into 'Sym' * in turn get rid of VT_IM/EXPORT, VT_WEAK * re-number VT_XXX flags * replace some 'long' function args by 'int' tccgen.c: * refactor parse_btype()
* unsorted adjustmentsgrischka2017-07-091-12/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - configure * use aarch64 instead of arm64 - Makefile * rename the custom include file to "config-extra.mak" * Also avoid "rm -r /*" if $(tccdir) is empty - pp/Makefile * fix .expect generation with gcc - tcc.h * cleanup #defines for _MSC_VER - tccgen.c: * fix const-propagation for &,| * fix anonymous named struct (ms-extension) and enable -fms-extension by default - i386-gen.c * clear VT_DEFSIGN - x86_64-gen.c/win64: * fix passing structs in registers * fix alloca (need to keep "func_scratch" below each alloca area on stack) (This allows to compile a working gnu-make on win64) - tccpp.c * alternative approach to 37999a4fbf3487b363fd0c2f9b7ab622401b202a This is to avoid some slowdown with ## token pasting. * get_tok_str() : return <eof> for TOK_EOF * -funsigned-char: apply to "string" literals as well - tccpe/tools.c: -impdef: support both 32 and 64 bit dlls anyway
* tccpp: allow "#define X defined Y ..."grischka2017-07-091-0/+1
| | | | | | | That means: we do not macro-expand the argument of 'defined' Also: store the last token position into the TokenString structure in order to get rid of the tok_last function.
* configure: --config-musl/-uClibc switch & misc cleanupsgrischka2017-05-131-31/+28
| | | | | | | | | | | | | | | - configure: - add --config-uClibc,-musl switch and suggest to use it if uClibc/musl is detected - make warning options magic clang compatible - simplify (use $confvars instead of individual options) - Revert "Remove some unused-parameter lint" 7443db0d5f841b81a55e918bf8c228dd20f9ddb2 rather use -Wno-unused-parameter (or just not -Wextra) - #ifdef functions that are unused on some targets - tccgen.c: use PTR_SIZE==8 instead of (X86_64 || ARM64) - tccpe.c: fix some warnings - integrate dummy arm-asm better
* bitfields: one more hack and a "-Wgcc-compat" switchgrischka2017-05-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | bit_pos + bit_size > type_size * 8 must NEVER happen because the code generator can read/write only the basic integral types. Warn if tcc has to break GCC compatibility for that reason and if -Wgcc-compat is given. Example: struct __attribute__((packed)) _s { unsigned int x : 12; unsigned char y : 7; unsigned int z : 28; }; Expected (GCC) layout (sizeof struct = 6) .xxxxxxxx.xxxxyyyy.yyyzzzzz.zzzzzzzz.zzzzzzzz.zzzzzzz0. But we cannot read/write 'char y'from 2 bytes in memory. So we have to adjust: .xxxxxxxx.xxxx0000.yyyyyyyz.zzzzzzzz.zzzzzzzz.zzzzzzzz.zzz00000 Now 'int z' cannot be accessed from 5 bytes. So we arrive at this (sizeof struct = 7): .xxxxxxxx.xxxx0000.yyyyyyy0.zzzzzzzz.zzzzzzzz.zzzzzzzz.zzzz0000 Otherwise the bitfield load/store generator needs to be changed to allow byte-wise accesses. Also we may touch memory past the struct in some cases currently. The patch adds a warning for that too. 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 81 ec 04 00 00 00 sub $0x4,%esp 9: 90 nop struct __attribute__((packed)) { unsigned x : 5; } b = {0} ; a: 8b 45 ff mov -0x1(%ebp),%eax d: 83 e0 e0 and $0xffffffe0,%eax 10: 89 45 ff mov %eax,-0x1(%ebp) This touches -0x1 ... +0x3(%ebp), hence 3 bytes beyond stack space. Since the data is not changed, nothing else happens here.
* C string litteral is const, fix return type of default_elfinterp. Remove ↵Christian Jullien2017-05-081-1/+1
| | | | #ifndef TCC_IS_NATIVE in arm-gen.c as suggested by grischka.
* Spelling fixes in C comments onlyLarry Doolittle2017-05-071-6/+6
|
* Cleanups (float consts, sections, symbols)Michael Matz2017-05-021-1/+2
| | | | | | | | introduce common_section (SHN_COMMON), factorize some handling in decl_initializer_alloc, add section_add and use it to factorize some code that allocates stuff in sections (at the same time also fixing harmless bugs re section alignment), use init_putv to emit float consts into .data from gv() (fixing an XXX).
* Remove VT_REFMichael Matz2017-05-021-1/+0
| | | | | | The canonical way to describe a local variable that actually holds the address of an lvalue is VT_LLOCAL. Remove the last user of VT_REF, and handling of it, thereby freeing a flag for SValue.r.
* Simple-minded fix for bug #50847Larry Doolittle2017-04-251-0/+1
| | | | | | bug #50847: #line directive corrupts #include search path Keep a second copy of the filename, that isn't changed by the #line directive, and use that on the initial search path for #include files.
* tcc: fixup clang warningsAndrei Warkentin2017-04-251-2/+3
| | | | | | | | | | | The O(xxx) stuff in i386-asm.c had me scratching my head. Extracting the macro and trying it out in a separate program doesn't give me any warnings, so I'm confused about what could be going on there. Any cast will make things happy. I used a uint64_t to catch actual cases of overflow, which will still cause a -Wconstant-conversion warning. Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
* Add support of musl-libcMarc Vertes2017-04-201-4/+16
| | | | The port is functional. Bound checking is not supported yet.
* tccgen/win32: let __declspec(dllimport) imply externgrischka2017-04-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Also, retain storage qualifiers in type_decl, in particular also for function pointers. This allows to get rid of this very early hack in decl() type.t |= (btype.t & VT_STATIC); /* Retain "static". */ which was to fix the case of int main() { static int (*foo)(); ... Also: - missing __declspec(dllimport) is an error now - except if the symbol is "_imp__symbol" - demonstrate export/import of data in the dll example (while 'extern' isn't strictly required with dllimport anymore) - new function 'patch_storage()' replaces 'weaken_symbol()' and 'apply_visibility()' - new function 'update_storage()' applies storage attributes to Elf symbols. - put_extern_sym/2 accepts new pseudo section SECTION_COMMON - add -Wl,-export-all-symbols as alias for -rdynamic - add -Wl,-subsystem=windows for mingw compatibility - redefinition of 'sym' error for initialized global data
* makefile: unify cross with native buildsgrischka2017-02-251-1/+1
| | | | | | | | | | | | | supports building cross compilers on the fly without need for configure --enable-cross $ make cross # all compilers $ make cross-TARGET # only TARGET-compiler & its libtcc1.a with TARGET one from i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince c67 Type 'make help' for more information
* cross-compilers: allow individual configurationgrischka2017-02-231-27/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | since configure supports only native configuration a file 'cross-tcc.mak' needs to be created manually. It is included in the Makefile if present. # ---------------------------------------------------- # Example config-cross.mak: # # windows -> i386-linux cross-compiler # (it expects the linux files in <prefix>/i386-linux) ROOT-i386 = {B}/i386-linux CRT-i386 = $(ROOT-i386)/usr/lib LIB-i386 = $(ROOT-i386)/lib:$(ROOT-i386)/usr/lib INC-i386 = {B}/lib/include:$(ROOT-i386)/usr/include DEF-i386 += -D__linux__ # ---------------------------------------------------- Also: - use libtcc1-<target>.a instead of directories - add dummy arm assembler - remove include dependencies from armeabi.c/lib-arm64.c - tccelf/ld_add_file: add SYSROOT (when defined) to absolute filenames coming from ld-scripts
* tcc: re-enable correct option -r supportgrischka2017-02-201-5/+8
| | | | | | | | | | | | | | | Forgot about it. It allows to compile several sources (and other .o's) to one single .o file; tcc -r -o all.o f1.c f2.c f3.S o4.o ... Also: - option -fold-struct-init-code removed, no effect anymore - (tcc_)set_environment() moved to tcc.c - win32/lib/(win)crt1 minor fix & add dependency - debug line output for asm (tcc -c -g xxx.S) enabled - configure/Makefiles: x86-64 -> x86_64 changes - README: cleanup
* tcc -hh: show more optionsgrischka2017-02-181-0/+1
|
* tcctools.c: integrate tiny_libmaker/_impdefgrischka2017-02-181-7/+27
| | | | | | | | | | | | | | usage: tcc -ar [rcsv] lib files... tcc -impdef lib.dll [-v] [-o lib.def] also: - support more files with -c: tcc -c f1.c f2.c ... - fix a bug which caused tcc f1.c f2.S to produce no asm - allow tcc -ar @listfile too - change prototype: _void_ tcc_set_options(...) - apply -Wl,-whole-archive when a librariy is given as libxxx.a also (not just for -lxxx)
* -Wl, --enable-new-dtags for DT_RUNPATH instead of DT_RPATHSteffen Nurpmeso2017-02-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Today by accident i had to deal with linker problems of some software and found an issue that mentioned DT_RUNPATH, which mentioned that DT_RPATH is legacy and searched for $LD_LIBRARY_PATH, whereas the newer DT_RUNPATH is searched thereafter. Completely unencrypted! Well. For what's it worth, i for one am astonished because of course i want to override $LD_LIBRARY_PATH, but it surely has its merites, smart people came to the conclusion, did they. The attached diff below seems to be sufficient to support DT_RUNPATH instead of DT_RPATH with tcc(1). But i have no insight in what --enable-new-dtags is supposed to change in addition, so i wonder. Ciao! --steffen libtcc.c | 2 ++ tcc-doc.texi | 4 ++++ tcc.h | 1 + tccelf.c | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-)
* fixes & cleanupsgrischka2017-02-131-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - tccgen.c/tcc.h: allow function declaration after use: int f() { return g(); } int g() { return 1; } may be a warning but not an error see also 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 - tccgen.c: redundant code related to inline functions removed (functions used anywhere have sym->c set automatically) - tccgen.c: make 32bit llop non-equal test portable (probably not on C67) - dynarray_add: change prototype to possibly avoid aliasing problems or at least warnings - lib/alloca*.S: ".section .note.GNU-stack,"",%progbits" removed (has no effect) - tccpe: set SizeOfCode field (for correct upx decompression) - libtcc.c: fixed alternative -run invocation tcc "-run -lxxx ..." file.c (meant to load the library after file). Also supported now: tcc files ... options ... -run @ arguments ...
* tcc: don't use pstrcpy, fix win32 spanwn quotinggrischka2017-02-081-3/+3
| | | | | | | | | | | | - we're now exporting tcc_prefixed symbols from libtcc only - On windows, the msvcrt startup code would remove backslashes from commandline arguments such as -DFOO=\"foo\" which would appear in argv as -DFOO="foo" Therefor before passing these to spawnvp, we need to restore the backslashes.
* tccgen: factor out gfunc_returngrischka2017-02-081-2/+1
| | | | | | | Also: - on windows i386 and x86-64, structures of size <= 8 are NOT returned in registers if size is not one of 1,2,4,8. - cleanup: put all tv-push/pop/swap/rot into one place
* win32: support "-Wl,--large-address-aware" optionPavlas, Zdenek2016-12-301-0/+1
|
* tests: OOT build fixes etc.grischka2016-12-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | tests/Makefile: fix out-of-tree build issues Also: - win64: align(16) MEM_DEBUG user memory on win64 the struct jmp_buf in the TCCState structure which we allocate by tcc_malloc needs alignment 16 because the msvcrt setjmp uses MMX instructions. - libtcc_test.c: win32/64 need __attribute__((dllimport)) for extern data objects - tcctest.c: exclude stuff that gcc does not compile except for relocation_test() the other issues are mostly ASM related. We should probably check GCC versions but I have no idea which mingw/gcc versions support what and which don't. - lib/Makefile: use tcc to compile libtcc1.a (except on arm which needs arm-asm
* libtcc.c: -m option cleanupgrischka2016-12-181-1/+1
| | | | | | | | | | | handle mms-bitfields as sub-options of -m. (-mfloat-abi is still special because it requires arguments) tcc.c: help(): - list -mms-bitfields under 'Target specific options' libtcc.c/MEM_DEBUG - add check for past buffer writes
* tests: add memory leak testgrischka2016-12-181-0/+1
| | | | | | | | | | | | | Also ... tcctest.c: - exclude stuff that gcc doesn't compile on windows. libtcc.c/tccpp.c: - use unsigned for memory sizes to avoid printf format warnings - use "file:line: message" to make IDE error parsers happy. tccgen.c: fix typo
* Support large alignment requestsMichael Matz2016-12-151-1/+1
| | | | | | | | The linux kernel has some structures that are page aligned, i.e. 4096. Instead of enlarging the bit fields to specify this, use the fact that alignment is always power of two, and store only the log2 minus 1 of it. The 5 bits are enough to specify an alignment of 1 << 30.
* Fix 64bit enums and switch casesMichael Matz2016-12-151-3/+3
| | | | | | | See testcases. We now support 64bit case constants. At the same time also 64bit enum constants on L64 platforms (otherwise the Sym struct isn't large enough for now). The testcase also checks for various cases where sign/zero extension was confused.
* tccpp: Fix token pastingMichael Matz2016-12-151-0/+1
| | | | | | | | | See testcase. We must always paste tokens (at least if not currently substing a normal argument, which is a speed optimization only now) but at the same time must not regard a ## token coming from argument expansion as the token-paste operator, nor if we constructed a ## token due to pasting itself (that was already checked by pp/01.c).
* Fix initializing members multiple timesMichael Matz2016-12-151-0/+2
| | | | | | | When intializing members where the initializer needs relocations and the member is initialized multiple times we can't allow that to lead to multiple relocations to the same place. The last one must win.
* Support local register variablesMichael Matz2016-12-151-3/+5
| | | | | | | | | Similar to GCC a local asm register variable enforces the use of a specified register in asm operands (and doesn't otherwise matter). Works only if the variable is directly mentioned as operand. For that we now generally store a backpointer from an SValue to a Sym when the SValue was the result of unary() parsing a symbol identifier.
* x86_64: Add -mno-sse optionMichael Matz2016-12-151-0/+3
| | | | | This disables generation of any SSE instructions (in particular in stdarg function prologues). Necessary for kernel compiles.
* x86-64: relocation addend is 64bitMichael Matz2016-12-151-2/+2
| | | | | | | | Some routines were using the wrong type (int) in passing addends, truncating it. This matters when bit 31 isn't set and the high 32 bits are set: the truncation would make it unsigned where in reality it's signed (happen e.g. on the x86-64 with it's load address at top-2GB).
* tccasm: Support refs to anon symbols from asmMichael Matz2016-12-151-0/+1
| | | | | | | This happens when e.g. string constants (or other static data) are passed as operands to inline asm as immediates. The produced symbol ref wouldn't be found. So tighten the connection between C and asm-local symbol table even more.
* tccasm: Don't ignore # in preprocessor directivesMichael Matz2016-12-151-0/+6
| | | | | | | Our preprocessor throws away # line-comments in asm mode. It did so also inside preprocessor directives, thereby removing stringification. Parse defines in non-asm mode (but retain '.' as identifier character inside macro definitions).
* Fix access-after-free with statement expressionsMichael Matz2016-12-151-1/+1
| | | | | | | | | | | | The return value of statement expressions might refer to local symbols, so those can't be popped. The old error message always was just a band-aid, and since disabling it for pointer types it wasn't effective anyway. It also never considered that also the vtop->sym member might have referred to such symbols (see the testcase with the local static, that used to segfault). For fixing this (can be seen better with valgrind and SYM_DEBUG) simply leave local symbols of stmt exprs on the stack.
* enums and ints are compatibleMichael Matz2016-12-151-1/+2
| | | | | | | But like GCC do warn about changes in signedness. The latter leads to some changes in gen_assign_cast to not also warn about unsigned* = int* (where GCC warns, but only with extra warnings).
* inline asm: accept concatenated strings in constraintsMichael Matz2016-12-151-0/+1
| | | | | This really should be handled implicitly in the preprocessor, but for now this is enough.