aboutsummaryrefslogtreecommitdiff
path: root/tccasm.c
Commit message (Collapse)AuthorAgeFilesLines
* various stuffgrischka2017-10-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | win32/Makefile ("for cygwin") removed - On cygwin, the normal ./configure && make can be used with either cygwin's "GCC for Win32 Toolchain" ./configure --cross-prefix=i686-w64-mingw32- or with an existing tcc: ./configure --cc=<old-tccdir>/tcc.exe tcctest.c: - exclude test_high_clobbers() on _WIN64 (does not work) tests2/95_bitfield.c: - use 'signed char' for ARM (where default 'char' is unsigned) tests: - remove -I "expr" diff option to allow tests with busybox-diff. libtcc.c, tcc.c: - removed -iwithprefix option. It is supposed to be combined with -iprefix which we don't have either. tccgen.c: - fix assignments and return of 'void', as in void f() { void *p, *q; *p = *q: return *p; } This appears to be allowed but should do nothing. tcc.h, libtcc.c, tccpp.c: - Revert "Introduce VIP sysinclude paths which are always searched first" This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1. The patch was giving tcc's system includes priority over -I which is not how it should be. tccelf.c: - add DT_TEXTREL tag only if text relocations are actually used (which is likely not the case on x86_64) - prepare_dynamic_rel(): avoid relocation of unresolved (weak) symbols tccrun.c: - for HAVE_SELINUX, use two mappings to the same (real) file. (it was so once except the RX mapping wasn't used at all). tccpe.c: - fix relocation constant used for x86_64 (by Andrei E. Warentin) - #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin. tccasm.c: - keep forward asm labels static, otherwise they will endup in dynsym eventually. configure, Makefile: - mingw32: respect ./configure options --bindir --docdir --libdir - allow overriding tcc when building libtcc1.a and libtcc.def with make XTCC=<tcc program to use> - use $(wildcard ...) for install to allow installing just a cross compiler for example make cross-arm make install - use name <target>-libtcc1.a build-tcc.bat: - add options: -clean, -b bindir
* tcc -dt -run ... : simpler is bettergrischka2017-07-201-29/+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 ... */
* refactor sym & attributesgrischka2017-07-091-5/+5
| | | | | | | | | | | | 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()
* configure: --config-musl/-uClibc switch & misc cleanupsgrischka2017-05-131-2/+0
| | | | | | | | | | | | | | | - 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
* Remove some unused argumentsMichael Matz2017-05-081-2/+1
| | | | these ones are really superfluous.
* Remove some unused-parameter lintLarry Doolittle2017-05-081-0/+2
| | | | | | | | Mark TCCState parameter as unused in tcc_undefine_symbol(), tcc_add_symbol(), tcc_print_stats(), asm_get_local_label_name(), use_section1(), tccpp_delete(), tcc_tool_ar(), tcc_tool_impdef(), and tcc_tool_cross(). Also mark it unused in tcc_add_bcheck() unless CONFIG_TCC_BCHECK. Remove it entirely in ld_next().
* final adjustments for releasegrischka2017-04-251-2/+2
| | | | | | | | | | | | | | | | | | | | | - configure/Makefiles: minor adjustments - build-tcc.bat: add -static to gcc options (avoids libgcc_s*.dll dependency with some mingw versions) - tccpe.c/tcctools.c: eliminate MAX_PATH (not available for cross compilers) - tccasm.c: use uint64_t/strtoull in unary() (unsigned long sometimes is only uint32_t, as always on windows) - tccgen.c: Revert (f077d16c) "tccgen: gen_cast: cast FLOAT to DOUBLE" Was a rather experimental, tentative commit, not really necessary and somewhat ugly too. - cleanup recent osx support: - Makefile/libtcc.c: cleanup copy&paste code - tccpp.c: restore deleted function
* tcc: re-enable correct option -r supportgrischka2017-02-201-12/+7
| | | | | | | | | | | | | | | 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
* tcctools.c: integrate tiny_libmaker/_impdefgrischka2017-02-181-0/+1
| | | | | | | | | | | | | | 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)
* mems & leaksgrischka2017-02-131-2/+1
| | | | | | | | | | | | - define_start: set above preprocess_start because now preprocess_start is defining macros. - free "cmd_include_files" - free defines always (after error-longjmps) - close all files (after error-longjmps) - tccpe.c: free imports always - libtcc.c: call tcc_memstats only after all states have been deleted.
* Fix some code suppression falloutMichael Matz2016-12-201-16/+16
| | | | | | | | | | Some more subtle issues with code suppression: - outputting asms but not their operand setup is broken - but global asms must always be output - statement expressions are transparent to code suppression - vtop can't be transformed from VT_CMP/VT_JMP when nocode_wanted Also remove .exe files from tests2 if they don't fail.
* tccgen: nocode_wanted alternativelygrischka2016-12-181-1/+6
| | | | | | | | | | | | | | | tccgen.c: remove any 'nocode_wanted' checks, except in - greloca(), disables output elf symbols and relocs - get_reg(), will return just the first suitable reg) - save_regs(), will do nothing Some minor adjustments were made where nocode_wanted is set. xxx-gen.c: disable code output directly where it happens in functions: - g(), output disabled - gjmp(), will do nothing - gtst(), dto.
* tccasm: Support refs to anon symbols from asmMichael Matz2016-12-151-11/+17
| | | | | | | 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/+2
| | | | | | | 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).
* tccasm: Lookup C symbols from ASM blocksMichael Matz2016-12-151-19/+43
| | | | | It's now possible to use symbols defined in C code to be used from later inline asm blocks. See testcase.
* tccasm: Implement .set sym, exprMichael Matz2016-12-151-16/+49
| | | | | | | | | | That, as well as "sym = expr", if expr contains symbols. Slightly tricky because a definition from .set is overridable, whereas proper definitions aren't. This doesn't yet allow using this for override tricks from C and global asm blocks because the symbol tables from C and asm are separate.
* enums and ints are compatibleMichael Matz2016-12-151-1/+1
| | | | | | | 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).
* tcc-asm: Parse .size directive correctlyMichael Matz2016-12-151-1/+1
| | | | | When the .size directive was closed with a ';' tcc eat everything after it up to lineend.
* inline asm: accept concatenated strings in constraintsMichael Matz2016-12-151-5/+5
| | | | | This really should be handled implicitly in the preprocessor, but for now this is enough.
* inline asm: Fix 'P' and accept some r<nr> registersMichael Matz2016-12-151-4/+4
| | | | | | A 'P' template modifier should avoid adding a '$' to literal arguments. Also accept the numbered r8+ registers in an inline asm clobber list (ignoring them for now).
* tccasm: Implement compare expressionsMichael Matz2016-12-151-1/+45
| | | | | I.e. implement < > <= >= == !=. Comparisons are signed and result is -1 if true, 0 if false.
* x86-64-asm: Accept expressions for .quadMichael Matz2016-12-151-0/+9
| | | | | The x86-64 target has 64bit relocs, and hence can accept generic expressions for '.quad'.
* inline asm: Accept 'p' constraint and 'P' template modMichael Matz2016-12-151-1/+4
| | | | | 'p' is conservatively the same as 'r' and 'P' as template modifier can be ignored in TCC.
* tccasm: Accept .balignMichael Matz2016-12-151-1/+2
|
* Accept more asm expressionsMichael Matz2016-12-151-18/+37
| | | | | | In particular subtracting a defined symbol from current section makes the value PC relative, and .org accepts symbolic expressions as well, if the symbol is from the current section.
* tccasm: Implement .pushsection and .popsectionMichael Matz2016-12-151-1/+26
|
* x86-asm: Accept 'q' modifierMichael Matz2016-12-151-1/+1
| | | | In inline extended asm '%q1' refers to the 64bit register of operand 1.
* x86-asm: move stats codeMichael Matz2016-12-151-32/+0
| | | | | The old place (tccasm.c) didn't have access to the variables anymore and was ifdefed out. Move it to i386-asm.c.
* x86_64-asm: =m operand fixesgrischka2016-11-201-2/+4
| | | | | | | | | | | | | | | | | | | | | | The problem was with tcctest.c: unsigned set; __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc"); when with tcc compiled with the HAVE_SELINUX option, run with tcc -run, it would use large addresses far beyond the 32bits range when tcc did not use the pc-relative mode for accessing 'set' in global data memory. In fact the assembler did not know about %rip at all. Changes: - memory operands use (%rax) not (%eax) - conversion from VT_LLOCAL: use type VT_PTR - support 'k' modifier - support %rip register - support X(%rip) pc-relative addresses The test in tcctest.c is from Michael Matz.
* tccpp_new/delete and other cleanupsgrischka2016-10-171-1/+1
|
* tccpp: cleanupgrischka2016-10-011-7/+7
| | | | | | | | | | | | | | | | - "utf8 in identifiers" from 936819a1b90f2618bb3f86730189cf2895948ba0 - CValue: remove member str.data_allocated - make tiny allocator private to tccpp - allocate macro_stack objects on heap because otherwise it could crash after error/setjmp in preprocess_delete():end_macro() - mov "TinyAlloc" defs to tccpp.c - define_push: take int* str again
* fix asm_expr_unary()seyko2016-05-161-1/+1
| | | | | | | | keep unary unsigned. problem is exposed on i386 with unary like 0xC0000000. In this case a sign is extended in pe->v = n; if n declared as long.
* x86-64-asm: Clean up 64bit immediate supportMichael Matz2016-05-111-1/+2
| | | | | | | | | Fix it to actually be able to parse 64bit immediates (enlarge operand value type). Then, generally there's no need for accepting IM64 anywhere, except in the 0xba+r mov opcodes, so OP_IM is unnecessary, as is OPT_IMNO64. Improve the generated code a bit by preferring the 0xc7 opcode for im32->reg64, instead of the im64->reg64 form (which we therefore hardcode).
* __asm__() outside functionseyko2016-05-011-0/+10
| | | | | | | | gcc/pcc allow __asm__() outside a function body: extern void vide(void); __asm__("vide: ret"); There is many such code in the Linux kernels.
* .rept asm directiveseyko2016-04-221-0/+37
| | | | | and '.' alone is a token now in *.S (not an identifier) representing a current position in the code (PC).
* correct version of "Identifiers can start and/or contain"seyko2016-04-131-43/+48
| | | | | | | A problem was in TOK_ASMDIR_text: - sprintf(sname, ".%s", get_tok_str(tok1, NULL)); + sprintf(sname, "%s", get_tok_str(tok1, NULL)); When tok1 is '.text', then sname is '..text'
* revert of the 'Identifiers can start and/or contain'seyko2016-04-131-46/+41
| | | | | | | | When tccboot kernels compiles with 'Identifiers can start and/or', this kernel don't start. It is hard to find what is wrong. PS: there was no test for identifiers in *.S with '.'
* Identifiers can start and/or contain '.' in *.Sseyko2016-04-051-41/+46
| | | | | | | | | | | | | | | | | modified version of the old one which don't allow '.' in #define Identifiers. This allow correctly preprocess the following code in *.S #define SRC(y...) \ 9999: y; \ .section __ex_table, "a"; \ .long 9999b, 6001f ; \ // .previous SRC(1: movw (%esi), %bx) 6001: A test included.
* reverse of the "Identifiers can start and/or contain '.'"seyko2016-04-031-46/+41
| | | | | | | | | | | | | | | | | - Identifiers can start and/or contain '.' in PARSE_FLAG_ASM_FILE - Move all GAS directives under TOK_ASMDIR prefix This patches breaks compilation of the tccboot (linux 2.4.26 kernel). A test.S which fails with this patches: #define SRC(y...) \ 9999: y; \ .section __ex_table, "a"; \ .long 9999b, 6001f<---->; \ .previous SRC(1:<>movw (%esi), %bx<------>) // 029-test.S:7: error: macro 'SRC' used with too many args
* Move all GAS directives under TOK_ASMDIR prefix to include leading '.'Vlad Vissoultchev2016-03-151-41/+46
| | | | Use only these tokens in `asm_parse_directive` and don't recycle others' tokens (like TOK_SECTION1)
* Change the way struct CStrings are handled.Edmund Grimley Evans2015-11-261-12/+12
| | | | | | | | | A CString used to be copied into a token string, which is an int array. On a 64-bit architecture the pointers were misaligned, so ASan gave lots of warnings. On a 64-bit architecture that required memory accesses to be correctly aligned it would not work at all. The CString is now included in CValue instead.
* Trivial changes to avoid some compiler warnings.Edmund Grimley Evans2015-11-191-1/+4
|
* Revert all of my changes to directories & codingstyle.gus knight2015-07-291-0/+1130
|
* Reorganize the source tree.gus knight2015-07-271-1130/+0
| | | | | | | | | | * Documentation is now in "docs". * Source code is now in "src". * Misc. fixes here and there so that everything still works. I think I got everything in this commit, but I only tested this on Linux (Make) and Windows (CMake), so I might've messed something up on other platforms...
* Clean up lots of rogue tabs.gus knight2015-07-271-17/+17
| | | | | | Still some more tabs to be taken care of. arm-gen.c and tcccoff.c have so many style issues that I'm just going to throw clang-format at them.
* Trim trailing spaces everywhere.gus knight2015-07-271-25/+25
|
* tccpp: fix issues, add testsgrischka2015-05-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fix some macro expansion issues * add some pp tests in tests/pp * improved tcc -E output for better diff'ability * remove -dD feature (quirky code, exotic feature, didn't work well) Based partially on ideas / researches from PipCet Some issues remain with VA_ARGS macros (if used in a rather tricky way). Also, to keep it simple, the pp doesn't automtically add any extra spaces to separate tokens which otherwise would form wrong tokens if re-read from tcc -E output (such as '+' '=') GCC does that, other compilers don't. * cleanups - #line 01 "file" / # 01 "file" processing - #pragma comment(lib,"foo") - tcc -E: forward some pragmas to output (pack, comment(lib)) - fix macro parameter list parsing mess from a3fc54345949535524d01319e1ca6378b7c2c201 a715d7143d9d17da17e67fec6af1c01409a71a31 (some coffee might help, next time ;) - introduce TOK_PPSTR - to have character constants as written in the file (similar to TOK_PPNUM) - allow '\' appear in macros - new functions begin/end_macro to: - fix switching macro levels during expansion - allow unget_tok to unget more than one tok - slight speedup by using bitflags in isidnum_table Also: - x86_64.c : fix decl after statements - i386-gen,c : fix a vstack leak with VLA on windows - configure/Makefile : build on windows (MSYS) was broken - tcc_warning: fflush stderr to keep output order (win32)
* replace PARSE_FLAG_ASM_COMMENTS with PARSE_FLAG_ASM_FILEseyko2015-04-271-1/+1
| | | | | after "assign PARSE_FLAG_ASM_COMMENTS only for asm files" functions of this flags are identical
* Revert "* and #pragma pop_macro("macro_name")"grischka2015-04-231-3/+0
| | | | | | | | | | | | - pop_macro incorrect with initially undefined macro - horrible implementation (tcc_open_bf) - crashes eventually (abuse of Sym->prev_tok) - the (unrelated) asm_label part is the opposite of a fix (Despite of its name this variable has nothing to do with the built-in assembler) This reverts commit 0c8447db7970813292a8be74ee50e49091be5d15.
* * and #pragma pop_macro("macro_name")seyko2015-04-211-1/+4
| | | | | | | | | | * give warning if pragma is unknown for tcc * don't free asm_label in sym_free(), it's a job of the asm_free_labels(). The above pragmas are used in the mingw headers. Thise pragmas are implemented in gcc-4.5+ and current clang.