aboutsummaryrefslogtreecommitdiff
path: root/tccasm.c
Commit message (Collapse)AuthorAgeFilesLines
* final update for 0.9.27maingrischka2017-12-121-18/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tccgen.c: - fix ldouble asm hack - fix a VLA problem on Win64 (also x86_64-gen.c) - patch_type(): make sure that no symbol ever changes from global to static tcc.c: - tcc -vv: print libtcc1.a path also on win32 tccpe.c, tcctools.c: - use unix LF mode to for .def output files (that is for creating reproducible output trees) Makefile: - suppress some warnings when makeinfo is missing - call 'which install' only on win32 tests/Makefile: - change PATH only on WINNT systems (i.e. not if cross-compiling on linux for win32) - asm-c-connect.test: slim output and do diff tccrun.c tccpe.c *-link.c: - integrate former 'pe_relocate_rva()' into normal relocation This also fixes linkage of the unwind data on WIN64 for -run (reported by Janus Lynggaard Thorborg) tccasm.c, tests/tcctest.c: - fix dot (sym_index of -1 crashed in put_elf_reloc) - massage .set a bit (see test) other: - #define SECTION_ABS removed - ST_DATA Section *strtab_section: removed - put_extern_sym2(): take int section number Conflicts: tccelf.c tccpe.c Conflicts: tccelf.c
* Fix some multi-file corner cases with asmMichael Matz2017-12-101-15/+6
| | | | | | | | | | | | | for this we have to create also asm symbols as VT_STATIC initially except if there's an indication that it should be global (.globl or undefined at end of unit). For this to work we need to be able to globalize symbols after they were local and enter them into the ELF hash tables, and also adjust the symbols that were potentially already used in relocs when they were still local. The easiest is to do a proper symbol resolution step also in multi-file mode, for regular symbols (the non-dynamic ones, i.e. not from shared libs).
* tccasm: use global(_symbol)_stackgrischka2017-12-051-44/+23
| | | | | | | | | * removed asm_label stack * removed asm_free_labels() post-processing * using "impossible C type" for asm labels (VT_ASM) * tccgen.c:update_storage(): use it to refresh symbol attributes * tccelf.c:find_elf_sym(): ignore STB_LOCAL symbols * tccgen.c:unary(): asm symbols are supposed to be undeclared in C
* Fix another corner case with C/asm symtableMichael Matz2017-12-041-2/+3
| | | | | | See testcase (from grischka). If the asm has no .globl, but there's a (non-static) C definition the symbol should be exported, even if the first reference comes from asm.
* tccasm: Unify C and asm symbol tableMichael Matz2017-11-271-151/+89
| | | | | | | | | | This makes the asm symbols use the same members as the C symbols for global decls, e.g. using the ELF symbol to hold offset and section. That allows us to use only one symbol table for C and asm symbols and to get rid of hacks to synch between them. We still need some special handling for symbols that come purely from asm sources.
* tccasm: Don't abuse dllexport/dllimportMichael Matz2017-11-251-7/+7
| | | | | | | | | For tracking if asm symbols are connected with a C symbol, and if asm symbols need to be global use new flags, instead of reusing dllimport/dllexport, which would cause unrequested exported entries on Windows. This is a stop-gap until the C and asm symtable are unified.
* tccasm: synch C and asm symtab tighterMichael Matz2017-11-221-22/+63
| | | | | | | | | | | | | See testcase. The C and asm symtab are still separate, but integrated tighter: the asm labels are only synched at file end, not after each asm snippet (this fixes references from one to another asm block), the C and asm syms are synched both ways, so defining things in asm and refering from C, or the other way around works. In effect this model reflects what happens with GCC better. For this the asm labels aren't using the C label namespace anymore, but their own, which increases the size of each TokenSym by a pointer.
* Fix forward asm labels differentlyMichael Matz2017-11-191-9/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | while last change fixed one part of label behaviour (undefined ones must be global) it again broke a different aspect (forward defs without .globl must stay local). This fixes both aspects. That a label is local instead of global is difficult to test without resorting to look at the symbol table or using two-file testcases, so we do without. In essence the local/global-ness of symbols should be the same between GAS and TCC for this input: .globl glob1 glob1: call glob1 .globl glob2 call glob2 glob2: glob3: .globl glob3 call glob3 glob4: call glob4 .globl glob4 call glob5 .globl glob5 glob5: call glob6 glob6: .globl glob6 locl1: call locl1 call locl2 locl2: unref1: unref2: .globl unref2 .globl unref3 unref3: call undef
* Don't make forard asm symbols static by defaultMichael Matz2017-11-161-2/+0
| | | | | | | fixes the problem in the testcase. A symbolic reference from asm, which remains undefined at the end of processing is always a global reference, not a static (STB_LOCAL) one. This also affected the linux kernel.
* 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.