Commit Graph

223 Commits (951c23f25708a0e39ed0fcaac1862fbc2fad178b)

Author SHA1 Message Date
seyko 35e715a1e3 defined twice: revert
An error message is changed to suggest -fcommon
2015-10-29 17:10:04 +03:00
seyko c07785a1ea comment out tcc_error_noabort("'%s' defined twice"...
gcc-3.4.6 don't give such error by default
    example file1
	char __version_303_xxxxxxxx;
	void func1() {}
    example file2
	char __version_303_xxxxxxxx;
	void func2() {}
	int main() { return 0; }
2015-10-25 00:41:17 +03:00
Edmund Grimley Evans f0b7566181 tccelf.c: Reset sym after call to build_got.
The call to build_got can cause symtab_section->data to be reallocated
(build_got -> add_elf_sym -> put_elf_sym -> section_ptr_add ->
section_realloc -> tcc_realloc). This is not obvious on a cursory
inspection, but fortunately Valgrind spotted it immediately.
Are there other, similar bugs that Valgrind did not detect?
2015-10-16 20:33:41 +01:00
gus knight 89ad24e7d6 Revert all of my changes to directories & codingstyle. 2015-07-29 16:57:12 -04:00
gus knight 47e06c6d4e Reorganize the source tree.
* 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...
2015-07-27 16:03:25 -04:00
gus knight d6b64e2574 Clean up lots of rogue tabs.
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.
2015-07-27 14:14:41 -04:00
gus knight 41031221c8 Trim trailing spaces everywhere. 2015-07-27 12:43:40 -04:00
grischka 30df3189b1 tccpp: fix issues, add tests
* 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
    a3fc543459
    a715d7143d
    (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)
2015-05-09 14:29:39 +02:00
Philip 951a43ea6c fix a potential end-of-buffer issue in tccelf.c
also read characters one at a time when PARSE_DEBUG is set; after this
patch, things seem to work with that.
2015-04-30 21:35:21 +00:00
Thomas Preud'homme 9336fa7ae5 Fix program symbols exported in dynsym section
Prior to this commit TinyCC was exporting symbols defined in programs
only when they resolve an undefined symbol of a library. However, the
expected behavior (see --export-dynamic in GNU ld manpage) is that all
symbols used by libraries and defined by a program should be exported in
dynsym section. This is because symbol resolution search first in
program and then in libraries, thus allowing program symbol to interpose
symbol defined in a library.
2015-04-18 15:34:04 +08:00
seyko 0536407204 ability to specify a type of the input file with the -x switch
Usage example: tcc -xc ex5.cgi
    From a gcc docs:

    You can specify the input language explicitly with the -x option:

    -x language
    Specify explicitly the language for the following input files
    (rather than letting the compiler choose a default based on the file
    name suffix). This option applies to all following input files until
    the next -x option. Possible values for language are:

        c  c-header  c-cpp-output
        c++  c++-header  c++-cpp-output
        objective-c  objective-c-header  objective-c-cpp-output
        objective-c++ objective-c++-header objective-c++-cpp-output
        assembler  assembler-with-cpp
        ada
        f77  f77-cpp-input f95  f95-cpp-input
        java

    -x none
    Turn off any specification of a language, so that subsequent files
    are handled according to their file name suffixes (as they are if -x
    has not been used at all)
2015-04-12 15:35:37 +03:00
seyko 92efee6e52 fix "handle a -s option" commit
for targets which don't support variable length arrays.
2015-04-10 17:35:54 +03:00
seyko 559675b90a a bounds checking code for the ARCH=x86_64 2015-04-10 15:17:22 +03:00
seyko 7e7e6148fd fix installation amd bcheck for Windows
* define targetos=Windows when --enable-tcc32-mingw, --enable-cygwin, ...
    * use TARGETOS insteed HOST_OS when selecting PROGS
    * use "$(tccdir)" insteed $(tccdir) on install (spaces in path)
    * install tcc.exe too
    * produce bcheck.o when cross-compiling too (lib/Makefile)
    * force bcheck.o linking by compiling inside tcc_set_output_type()
      a dummy program with local array. Otherwise bcheck.o may be not linked.
    * replace %xz format specifier with %p in bcheck (don't supported on
      Windows)
    * call a __bound_init when __bound_ptr_add, __bound_ptr_indir,
      __bound_new_region, __bound_delete_region called.
      This is because a __bound_init inside ".init" section is not called
      on Windows for unknown reason.
    * print on stderr a message when an illegal pointer is returned:
        there is no segmentation violation on Windows for a program
        compiled with "tcc -b"
    * remove "C:" subdir on clean if $HOST_OS = "Linux"
    * default CFLAGS="-Wall -g -O0" insteed CFLAGS="-Wall -g -O2"
      to speed up compilation and more precise debugging.
2015-04-10 07:37:31 +03:00
seyko 5cd4393a54 handle a -s option by executing sstrip/strip program 2015-04-10 06:53:48 +03:00
seyko 089ce6235c output all sections if we produce an executable file
tcc w/o -g option generate an executable file which format
    is not recognized by binutils. It is like stripped one but
    binutils don't think so. Solution: generate not stripped
    file which can be correctly stripped by external utils.

    may be there is a need to handle a -s option and call
    a sstrip/strip program to do a job.
2015-04-10 06:49:24 +03:00
seyko d80593bc4d fix for the bcheck.o (bug #14958)
- care about __attribute__ redefinition in the system headers
    - an invalid pointer must be returned when (addr >= e->size),
      and not (addr > e->size)

    A test program:
    #include <stdio.h>
    #include <stdlib.h>
    int main ()
    {
	int v[10];
	fprintf(stderr, "&v[0]  = %p\n", &v[0]);
	fprintf(stderr, "&v[10] = %p\n", &v[10]);
	exit(1);
	return 0;
    }
    // tcc -b test.c

    The output before a patch:
    &v[0]  = 0xbf929d8c
    &v[10] = 0xbf929db4

    The output after a patch:
    &v[0]  = 0xbff6e33c
    &v[10] = 0xfffffffe
2015-03-29 11:28:02 +03:00
seyko f2cfc07554 fix: try to add a bounds.o only if __bounds_init not found
/usr/local/lib/tcc/i386/bcheck.o: error: '__bound_error_msg' defined twice
    #include <stdio.h>
    int main ()
    {
        #if 1
    	    int v[10];
            v[10] = 0;
            fprintf(stderr, "is bounds error catched?\n");
        #endif
        return 0;
    }
    // tcc -b test.c
2015-03-28 19:41:01 +03:00
seyko acef4ff244 make a bound checking more compatible with Windows 64
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
2015-03-26 07:47:45 +03:00
seyko 548a55eda5 fix for the previous commit: tcc_add_support() was used before definition 2015-03-26 06:22:37 +03:00
seyko a105837aae fix: enforce bcheck.o linking when -b option is used
fixes a crash for the empry program (tcc -b empty.c)
    empty.c: int main() { return 0; }
2015-03-26 06:04:36 +03:00
seyko 8f6390061d fix for: x86_64-tcc compiled by i386-tcc is wrong
A test program (must be compiled by the above version of the tcc):

    /* Tickle a bug in TinyC on 64-bit systems:
     * the LSB of the top word or ARGP gets set
     * for no obvious reason.
     *
     * Source: a legacy language interpreter which
     * has a little stack / stack pointer for arguments.
     *
     * Output is: 0x8049620 0x10804961c
     * Should be: 0x8049620 0x804961c
     */
    #include <stdio.h>
    #define NARGS 20000
    int ARG[NARGS];
    int *ARGSPACE = ARG;
    int *ARGP = ARG - 1;
    main() { printf("%p %p\n", ARGSPACE, ARGP); }
2015-03-23 19:24:55 +03:00
seyko 8dbe129ab7 fix a gcc compiler warning for the previous commit
mark a constant as long long (or -std=gnu99 is needed)
2015-03-23 16:36:09 +03:00
seyko c2efd7c53b revert a commit: Work around for the issue TCC doesn't handle -2147483648 properly
because a tcc handle now -2147483648 properly. Look a commit:
    Make integer constant parsing C99 compliant
2015-03-23 15:31:10 +03:00
seyko 4ba7e5dc5a A correction for the commit: revert a grischka patch: gdb refused to know "main"
keep revert (check SHF_ALLOC) only for x86 target and keep a grishka patch for
other targets
2015-03-10 14:21:14 +03:00
Michael Matz 0ecee0072d Find libtcc1.a on arm32
The directory is called "arm", not "ARM".
2015-03-09 00:47:27 +01:00
Edmund Grimley Evans 3fb8b14806 tccelf.c: File path component is "arm64", not "ARM64". 2015-03-04 19:43:29 +00:00
seyko d70440b406 A 32/64 bit tcc on linux: an arch specific path for libtcc1.a
Don't use /usr/local/lib/tcc/libtcc1.a for i386 and x86_64
A $(tccdir)/i386 directory was used to install a libtcc1.a
but only when cross compiling. And no x86_64 directory.
And this directory location was unknown inside tccelf.c
2015-03-03 18:34:22 +03:00
seyko 6cbf4fb740 tcc_add_runtime() for a CONFIG_USE_LIBGCC case: reducing a complexity 2015-03-03 17:11:18 +03:00
seyko 09d4e4f408 Revert a grischka patch: gdb refused to know "main"
It is a strange patch because before this commit a gdb is working well
and after this commit there is exactly the same problem on Linux:
gdb refuses to know "main"

    Author: grischka <grischka>
    Date:   Tue Feb 5 21:18:29 2013 +0100
    tccelf: fix debug section relocation
    With:
       tcc -g hello.c
       gdb a.out
         b main
    gdb refused to know "main" because of broken dwarf info.
2015-03-03 14:39:27 +03:00
Michael Matz 6d055312a2 aarch64: Fix -run.
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.
2015-02-23 22:51:10 +00:00
Edmund Grimley Evans b14ef0e24b Add arm64 (AArch64) as a target architecture. 2015-02-23 22:51:03 +00:00
Edmund Grimley Evans 738606dbd5 Use RELA relocations properly for R_DATA_PTR on x86_64.
libtcc.c: Add greloca, a generalisation of greloc that takes an addend.
tcc.h: Add greloca and put_elf_reloca.
tccelf.c: Add put_elf_reloca, a generalisation of put_elf_reloc.
tccgen.c: On x86_64, use greloca instead of greloc in init_putv.
2015-02-21 21:29:03 +00:00
Matteo Cypriani 63376d7712 tccelf: layout_sections: add missing param strsec
This fixes compilation on (k)FreeBSD.
2014-09-07 12:04:53 -04:00
grischka 6e0a658e96 win64: try to fix linkage
- revert to R_X86_64_PC32 for near calls on PE
- revert to s1->section_align set to zero by default

Untested. Compared to release_0_9_26 the pe-image looks back to
normal.  There are some differences in dissassembly (r10/r11 usage)
but maybe that's ok.
2014-06-24 22:09:12 -04:00
Michael Matz e69c506617 x86_64: Handle PLT relocs to hidden symbols
For calls to hidden symbols we don't need a PLT slot, rewrite
the reloc into PC32.
2014-04-14 04:58:05 +02:00
Michael Matz 6a947d9d26 ELF: Remove traces of old RUNTIME_PLTGOT code
The last users of it went away, no use in keeping
this code.
2014-04-06 01:59:35 +02:00
Michael Matz 01c0419234 arm: Use proper PLT/GOT for -run.
Same as with x86_64, disable the runtime_plt_and_got hack
for -run on arm as well.  For that we need to handle several
relocations as (potentially) generating PLT slots as well.
Tested with mpfr-3.1.2 and gawk (both using --disable-shared),
there are two resp. five pre-existing problems, so no regressions.

This also works toward enabling real shared libs for arm,
but it's not there yet.
2014-04-06 01:50:35 +02:00
Michael Matz 9750d0b725 x86_64: Create proper PLT and GOT also for -run
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.
2014-04-06 00:30:22 +02:00
Michael Matz 0688afdd34 arm: Handle R_ARM_NONE relocs
These relocations are used to express a dependency on a certain
symbol (e.g. for EABIs exception handling to the
__aeabi_unwind_cpp_pr{0,1,2} routines).  Just ignore them in
reloc processing.
2014-04-04 23:33:04 +02:00
Michael Matz 2024c44541 run: Always create .got relocs
When output is memory we applied the correct GOT offset for certain
relocations (e.g. _GOT32), but we forgot to actually fill the got
entries with the final symbol values, so unconditionally create relocs
against .got as well.
2014-04-04 17:54:52 +02:00
Michael Matz f2c8491fc0 ELF: Make first PT_LOAD cover headers
This makes it so that the first PT_LOAD segment covers
ELF and program header and .interp (contained in the same page anyway,
right before the start of the first loaded section).  binutils
strip creates invalid output otherwise (which strictly is a binutils
bug, but let's be nice anyway).
2014-04-03 18:00:44 +02:00
Michael Matz 0bd1282059 x86-64: shared libs improvement
This correctly resolves local references to global functions from
shared libs to their PLT slot (instead of directly to the target
symbol), so that interposition works.

This is still not 100% conforming (executables don't export symbols
that are also defined in linked shared libs, as they must), but
normal shared lib situations work.
2014-03-31 05:36:12 +02:00
Michael Matz 080ad7e62a x86-64: Add basic shared lib support
Initial support for shared libraries on x86-64.
2014-03-31 03:45:35 +02:00
Thomas Preud'homme b018bac9c8 Fix again GOT32 + PLT32 reloc commit
Fix commit aa561d7011 by setting
has_plt_entry once the plt has been created, not before.
2014-03-29 14:46:26 +08:00
mingodad 5c233f2cf3 The hack to allow valgrind works with tcc compiled programs
have the undesired side effect of programs compiled with
debug info segfaulting after debug info been striped
more tought must be done here
2014-03-28 21:07:06 +00:00
mingodad 0ba7c8670c This allow valgrind to work on linux, some how the PHDR is missing and then valgrind complain with:
Inconsistency detected by ld.so: rtld.c: 1284: dl_main: Assertion `_rtld_local._dl_rtld_map.l_libname' failed!
2014-03-28 11:44:00 +00:00
Thomas Preud'homme aa561d7011 Simplify and fix GOT32 + PLT32 reloc commit
Introduce a new attribute to check the existence of a PLT entry for a
given symbol has the presence of an entry for that symbol in the dynsym
section is not proof that a PLT entry exists.

This fixes commit dc8ea93b13.
2014-03-26 23:13:28 +08:00
mingodad ad9568060e A possible fix for the memory leak reported by valgrind when running tcctest.c with tcc. 2014-03-25 18:06:14 +00:00
Thomas Preud'homme dc8ea93b13 Support GOT32 and PLT32 reloc for same symbol
Some symbol (such as __gmon_start__ but this one does not matter to tcc)
can have both a R_386_GOT32 and R_386_PLT32 relocation. It is thus not
enough to test if a GOT reloc was already done when deciding whether to
return early from put_got_entry.
2014-03-25 22:35:11 +08:00