aboutsummaryrefslogtreecommitdiff
path: root/tccrun.c
Commit message (Collapse)AuthorAgeFilesLines
* final update for 0.9.27maingrischka2017-12-121-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* tccgen_begin/end_filegrischka2017-12-121-1/+1
| | | | | | | | | | | | | | | | | | This is supposed to make compilation and linking with multiple source files (tcc f1.c f2.S ...) behave just the same as linking object files. tccgen.c:put_extern_sym2(): - use put_elf_sym to enter new symbols unconditionally tccelf.c: - save section state before compilation - disable symbol hashing during compilation - merge symbols and update relocations after compilation tccpe.c: - re-create s1->uw_sym for each compilation (because it may change)
* Fix some multi-file corner cases with asmMichael Matz2017-12-101-2/+1
| | | | | | | | | | | | | 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).
* Win64/PE: Changed runtime function unwind info to be added after relocation, ↵janus.lt2017-11-041-4/+5
| | | | fixes SEH + long jmps
* various stuffgrischka2017-10-111-17/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * -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 ... */
* win32: adjust new unicode supportgrischka2017-02-181-0/+1
| | | | | | | | | | | | | | | | | | | - lib/Makefile: add (win)crt1_w.o - crt1.c/_runtmain: return to tcc & only use for UNICODE (because it might be not 100% reliable with for example wildcards (tcc *.c -run ...) - tccrun.c/tccpe.c: load -run startup_code only if called from tcc_run(). Otherwise main may not be defined. See libtcc_test.c - tests2/Makefile: pass extra options in FLAGS to allow overriding TCC Also: - tccpe.c: support weak attribute. (I first tried to solve the problem above by using it but then didn't)
* tccrun: sort sectionsgrischka2017-02-051-12/+26
| | | | | | | Sort executable before other sections. Also, apply RUN_SECTION_ALIGNMENT=63 for TCC_TARGET_I386 as well.
* tccrun: 'selinux' mmap: use only one mappinggrischka2017-02-051-38/+19
| | | | | | | | In the previous implementation, the rx mapping was never used. Therefor it is assumed that it is not needed. With only one mapping there is no reason to use a real /tmp/.xxxx file either as we can use an anonymous mapping.
* SECTION_ALIGNMENT -> RUN_SECTION_ALIGNMENT, and tweaksDavid Mertens2017-01-081-4/+5
| | | | | | | | | | | | Based on feedback from grischka, this commit (1) updates the name of the alignment constant to be more specific (2) aligns all sections, including the first (which previosly was not aligned) (3) reduces the x86-64 alignment from 512 to 64 bytes. The original x86-64 alignment of 512 bytes was based on testing. After ensuring that the initial section is also aligned, the same tests indicated that 64 bytes is sufficient.
* Architecture-specific section alignmentDavid Mertens2017-01-061-1/+7
| | | | | | | | Tests found excessive cache thrashing on x86-64 architectures. The problem was traced to the alignment of sections. This patch sets up an architecture-specific alignment of 512 bytes for x86-64 and 16 bytes for all others. It uses preprocessor directives that, hopefully, make it easy to tweak for other architectures.
* Control symbol table of which to relocate symbolsThomas Preud'homme2016-12-031-1/+1
| | | | Pass pointer to symbol table to relocate the symbols of in relocate_syms
* x86_64-asm: =m operand fixesgrischka2016-11-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | 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.
* remove warningsThomas Stalder2016-11-131-3/+2
|
* lib/libtcc1.c: cleanupgrischka2016-10-191-7/+6
| | | | | | | - remove #include dependencies from libtcc1.c for easier cross compilation - clear_cache only on ARM - error-message for mprotect failure
* tccrun/win64: cleanup runtime function tablegrischka2016-10-191-35/+74
| | | | | | | | | | | | | | - call RtlDeleteFunctionTable (important for multiple compilations) - the RUNTIME_FUNCTION* is now at the beginning of the runtime memory. Therefor when tcc_relocate is called with user memory, this should be done manually before it is free'd: RtlDeleteFunctionTable(*(void**)user_mem); [ free(user_mem); ] - x86_64-gen.c: expand char/short return values to int
* tccpp_new/delete and other cleanupsgrischka2016-10-171-7/+15
|
* Start support of OpenBSD, tcc compiler can be produced from source treeChristian Jullien2016-10-151-0/+4
|
* Misc. fixesgrischka2016-10-051-8/+1
| | | | | | | | | | | | | | | | | | | | Makefile : - do not 'uninstall' peoples /usr/local/doc entirely libtcc.c : - MEM_DEBUG : IDE-friendly output "file:line: ..." - always ELF for objects tccgen.c : - fix memory leak in new switch code - move static 'in_sizeof' out of function profiling : - define 'static' to empty resolve_sym() : - replace by dlsym() win32/64: fix R_XXX_RELATIVE fixme - was fixed for i386 already in 8e4d64be2fc1d707c7800c5096f6e0ea22cbd - do not -Lsystemdir if compiling to .o
* Revert part of "fix installation amd bcheck for Windows"grischka2016-10-011-12/+8
| | | | | | | tccelf.c : force linking bcheck by adding elf symbol __bound_init bcheck.c : use (size_t)1 for x86_64 Fixes 7e7e6148fdb4adbda936f80b5d4ac3d738908d95
* allow to compile tcc by pccseyko2016-04-151-0/+4
| | | | | * pcc have only __linux__ macro (and no __linux) * pcc don't have __clear_cache proc
* Trivial changes to avoid some compiler warnings.Edmund Grimley Evans2015-11-191-1/+1
|
* Correct prototype: void __clear_cache(void *, void *).Edmund Grimley Evans2015-10-151-1/+1
|
* Revert all of my changes to directories & codingstyle.gus knight2015-07-291-0/+772
|
* Reorganize the source tree.gus knight2015-07-271-772/+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-9/+9
| | | | | | 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.
* make a bound checking more compatible with Windows 64seyko2015-03-261-1/+1
| | | | | | On Linux 32: sizeof(long)=32 == sizeof(void *)=32 on Linux 64: sizeof(long)=64 == sizeof(void *)=64 on Windows 64: sizeof(long)=32 != sizeof(void *)=64
* fix a bug #43984: tcc -run reports errno=2seyko2015-03-251-0/+4
| | | | | | | | | The following program (errno.c) reports errno=2 when run using "tcc -run errno.c" #include <errno.h> #include <stdio.h> int main(void) { printf("errno=%d\n", errno); return 0; }
* aarch64: Fix -run.Michael Matz2015-02-231-1/+1
| | | | | | | This adds some more support for properly transfering some offsets over the different stages of a relocations life. Still not at all psABI compliant and DSOs can't yet be generated. But it runs the testsuite in qemu-arm64.
* Add arm64 (AArch64) as a target architecture.Edmund Grimley Evans2015-02-231-0/+21
|
* build: add initial NetBSD support.minux2014-04-121-2/+10
| | | | | | | | | | | | Not able to generate ELF files on NetBSD yet (lacks the note and crt1.o is actually named crt0.o on NetBSD), but -run works with these extra defines: -D__lint__ -D"__symbolrename(x)=asm(#x)" -D__NetBSD__ The -D__lint__ is an ugly hack, TCC should be able to emulate GCC just fine, but it seems TCC doesn't support __builtin_va_list yet? typedef __builtin_va_list __va_list; /usr/include/sys/ansi.h:72: error: ';' expected (got "__va_list")
* tccrun: fix build on DragonFly BSD.minux2014-04-121-2/+2
|
* ELF: Remove traces of old RUNTIME_PLTGOT codeMichael Matz2014-04-061-13/+0
| | | | | The last users of it went away, no use in keeping this code.
* x86_64: Create proper PLT and GOT also for -runMichael Matz2014-04-061-0/+1
| | | | | | This makes us use the normal PLT/GOT codepaths also for -run, which formerly used an on-the-side blob for the jump tables. For x86_64 only for now, arm coming up.
* Fix warning of clangThomas Preud'homme2014-03-091-2/+2
|
* Fix warning about undeclared __clear_cache function call.Christian Jullien2014-02-081-0/+1
|
* tccrun: Mark argv area as valid for bcheckKirill Smelkov2014-01-191-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On my x86_64 box in i386 mode with address space randomization turned off, I've observed the following: tests$ ../tcc -B.. -b -run boundtest.c 1 Runtime error: dereferencing invalid pointer boundtest.c:222: at 0x808da73 main() With diagnostic patch (like in efd9d92b "lib/bcheck: Don't assume heap goes right after bss") and bcheck traces for __bound_new_region, __bound_ptr_indir, etc... here is how the program run looks like: >>> TCC etext: 0x8067ed8 edata: 0x807321d end: 0x807d95c brk: 0x807e000 stack: 0xffffd0b4 &errno: 0xf7dbd688 mark_invalid 0xfff80000 - (nil) mark_invalid 0x80fa000 - 0x100fa000 new 808fdb0 808ff40 101 101 fd0 ff0 new 808ff44 808ff48 101 101 ff0 ff0 new 808ff49 8090049 101 101 ff0 1000 new 808fd20 808fd29 101 101 fd0 fd0 new 808fd2c 808fd6c 101 101 fd0 fd0 new 808fd6d 808fda0 101 101 fd0 fd0 E: __bound_ptr_indir4(0xffffd184, 0x4) Runtime error: dereferencing invalid pointer boundtest.c:222: at 0x808ea83 main() So we are accessing something on stack, above stack entry for compiled main. Investigating with gdb shows that this is argv: tests$ gdb ../tcc Reading symbols from /home/kirr/src/tools/tinycc/tcc...done. (gdb) set args -B.. -b -run boundtest.c 1 (gdb) r Starting program: /home/kirr/src/tools/tinycc/tests/../tcc -B.. -b -run boundtest.c 1 warning: Could not load shared library symbols for linux-gate.so.1. Do you need "set solib-search-path" or "set sysroot"? >>> TCC etext: 0x8067ed8 edata: 0x807321d end: 0x807d95c brk: 0x807e000 stack: 0xffffd074 &errno: 0xf7dbd688 mark_invalid 0xfff80000 - (nil) mark_invalid 0x80fa000 - 0x100fa000 new 808fdb0 808ff40 101 101 fd0 ff0 new 808ff44 808ff48 101 101 ff0 ff0 new 808ff49 8090049 101 101 ff0 1000 new 808fd20 808fd29 101 101 fd0 fd0 new 808fd2c 808fd6c 101 101 fd0 fd0 new 808fd6d 808fda0 101 101 fd0 fd0 E: __bound_ptr_indir4(0xffffd144, 0x4) Program received signal SIGSEGV, Segmentation fault. 0x0808ea83 in ?? () (gdb) bt #0 0x0808ea83 in ?? () #1 0x080639b3 in tcc_run (s1=s1@entry=0x807e008, argc=argc@entry=2, argv=argv@entry=0xffffd144) at tccrun.c:132 #2 0x080492b0 in main (argc=6, argv=0xffffd134) at tcc.c:346 (gdb) f 1 #1 0x080639b3 in tcc_run (s1=s1@entry=0x807e008, argc=argc@entry=2, argv=argv@entry=0xffffd144) at tccrun.c:132 132 ret = (*prog_main)(argc, argv); 132 ret = (*prog_main)(argc, argv); (gdb) p argv $1 = (char **) 0xffffd144 So before running compiled program, mark argv as valid region and we are done - now the test passes. P.S. maybe it would be better to just mark the whole vector kernel passes to program (argv, env, auxv, etc...) as valid all at once...
* Revert "Use anonymous file instead of regular file to back mmap"Iavael2014-01-121-5/+12
| | | | | | This reverts commit 935d8169b8e3570f1a5e726c5295be2f460c1540, because two anonymous mappings would have different content, while they must have the same one.
* Fix missing mem_size assignment when using mmap()keren2014-01-101-0/+2
|
* Use anonymous file instead of regular file to back mmapkeren2014-01-091-14/+5
| | | | Signed-off-by: Keren Tan <tankeren@gmail.com>
* i386-gen: preserve fp control word in gen_cvt_ftoigrischka2013-08-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | - Use runtime function for conversion - Also initialize fp with tcc -run on windows This fixes a bug where double x = 1.0; double y = 1.0000000000000001; double z = x < y ? 0 : sqrt (x*x - y*y); caused a bad sqrt because rounding precision for the x < y comparison was different to the one used within the sqrt function. This also fixes a bug where printf("%d, %d", (int)pow(10, 2), (int)pow(10, 2)); would print 100, 99 Unrelated: win32: document relative include & lib lookup win32: normalize_slashes: do not mirror silly gcc behavior This reverts part of commit 8a81f9e1036637e21a47e14fb56bf64133546890 winapi: add missing WINAPI decl. for some functions
* Fix synchronization between data and instr cachesThomas Preud'homme2013-03-191-1/+1
|
* Flush caches before -running programThomas Preud'homme2013-03-181-0/+1
| | | | | | | | | | | | On some architectures, ARM for instance, the data and instruction caches are not coherent with each other. This is a problem for the -run feature since instructions are written in memory, and are thus written in the data cache first and then later flushed to the main memory. If the instructions are executed before they are pushed out of the cache, then the processor will fetch the old content from the memory and not the newly generated code. The solution is to flush from the data cache all the data in the memory region containing the instructions and to invalidate the same region in the instruction cache.
* libtcc: new LIBTCCAPI tcc_set_options(TCCState*, const char*str)grischka2013-02-121-37/+41
| | | | | | | | | | | | | | | | | | | This replaces -> use instead: ----------------------------------- - tcc_set_linker -> tcc_set_options(s, "-Wl,..."); - tcc_set_warning -> tcc_set_options(s, "-W..."); - tcc_enable_debug -> tcc_set_options(s, "-g"); parse_args is moved to libtcc.c (now tcc_parse_args). Also some cleanups: - reorder TCCState members - add some comments here and there - do not use argv's directly, make string copies - use const char* in tcc_set_linker - tccpe: use fd instead of fp tested with -D MEM_DEBUG: 0 bytes left
* tests: cleanupgrischka2013-02-051-2/+1
| | | | | | | | | | | | | | | | tests: - add "hello" to test first basic compilation to file/memory - add "more" test (tests2 suite) - remove some tests tests2: - move into tests dir - Convert some files from DOS to unix LF - remove 2>&1 redirection win32: - tccrun.c: modify exception filter to exit correctly (needed for btest) - tcctest.c: exclude weak_test() (feature does not exist on win32)
* tccrun.c: unify rt_get_caller_pc prototypegrischka2013-02-041-18/+15
|
* portability: fix void* <-> target address conversion confusiongrischka2013-02-041-24/+22
| | | | | | - #define addr_t as ElfW(Addr) - replace uplong by addr_t - #define TCC_HAS_RUNTIME_PLTGOT and use it
* tccrun: another incompatible change to the tcc_relocate APIgrischka2012-09-011-2/+6
| | | | | | We are now compatible with the 0.9,25 version though. A special value for the second (ptr) argument is used to get the simple behavior as with the 0.9.24 version.
* tcc.h: define TCC_IS_NATIVEgrischka2012-03-051-0/+5
| | | | | | - disable tccrun feature for non-native (cross-) compilers - define uplong for target adress size - fix using -Wl,-Ttext=... for Win64 (tccpe: ADDR3264 imagebase)
* Revert "Multiple fixes for 64 bit sections"Andrew Mulbrook2012-03-031-6/+3
| | | | This reverts commit d7a7c3769d0a1dcb8400258cd8adf78a8566de61.