aboutsummaryrefslogtreecommitdiff
path: root/tccelf.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix program symbols exported in dynsym sectionThomas Preud'homme2015-04-181-12/+11
| | | | | | | | | | 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.
* ability to specify a type of the input file with the -x switchseyko2015-04-121-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* fix "handle a -s option" commitseyko2015-04-101-12/+8
| | | | for targets which don't support variable length arrays.
* a bounds checking code for the ARCH=x86_64seyko2015-04-101-2/+0
|
* fix installation amd bcheck for Windowsseyko2015-04-101-15/+16
| | | | | | | | | | | | | | | | | | | | | | * 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.
* handle a -s option by executing sstrip/strip programseyko2015-04-101-0/+14
|
* output all sections if we produce an executable fileseyko2015-04-101-0/+1
| | | | | | | | | | 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.
* fix for the bcheck.o (bug #14958)seyko2015-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* fix: try to add a bounds.o only if __bounds_init not foundseyko2015-03-281-3/+6
| | | | | | | | | | | | | | | /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
* 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 for the previous commit: tcc_add_support() was used before definitionseyko2015-03-261-25/+25
|
* fix: enforce bcheck.o linking when -b option is usedseyko2015-03-261-1/+4
| | | | | fixes a crash for the empry program (tcc -b empty.c) empty.c: int main() { return 0; }
* fix for: x86_64-tcc compiled by i386-tcc is wrongseyko2015-03-231-1/+1
| | | | | | | | | | | | | | | | | | | | | 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); }
* fix a gcc compiler warning for the previous commitseyko2015-03-231-1/+1
| | | | mark a constant as long long (or -std=gnu99 is needed)
* revert a commit: Work around for the issue TCC doesn't handle -2147483648 ↵seyko2015-03-231-1/+1
| | | | | | | properly because a tcc handle now -2147483648 properly. Look a commit: Make integer constant parsing C99 compliant
* A correction for the commit: revert a grischka patch: gdb refused to know "main"seyko2015-03-101-0/+7
| | | | | keep revert (check SHF_ALLOC) only for x86 target and keep a grishka patch for other targets
* Find libtcc1.a on arm32Michael Matz2015-03-091-1/+1
| | | | The directory is called "arm", not "ARM".
* tccelf.c: File path component is "arm64", not "ARM64".Edmund Grimley Evans2015-03-041-1/+1
|
* A 32/64 bit tcc on linux: an arch specific path for libtcc1.aseyko2015-03-031-1/+19
| | | | | | | 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
* tcc_add_runtime() for a CONFIG_USE_LIBGCC case: reducing a complexityseyko2015-03-031-5/+2
|
* Revert a grischka patch: gdb refused to know "main"seyko2015-03-031-1/+1
| | | | | | | | | | | | | | | 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.
* aarch64: Fix -run.Michael Matz2015-02-231-9/+53
| | | | | | | 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-4/+133
|
* Use RELA relocations properly for R_DATA_PTR on x86_64.Edmund Grimley Evans2015-02-211-3/+12
| | | | | | | 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.
* tccelf: layout_sections: add missing param strsecMatteo Cypriani2014-09-071-3/+4
| | | | This fixes compilation on (k)FreeBSD.
* win64: try to fix linkagegrischka2014-06-241-14/+16
| | | | | | | | | - 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.
* x86_64: Handle PLT relocs to hidden symbolsMichael Matz2014-04-141-2/+9
| | | | | For calls to hidden symbols we don't need a PLT slot, rewrite the reloc into PC32.
* ELF: Remove traces of old RUNTIME_PLTGOT codeMichael Matz2014-04-061-63/+1
| | | | | The last users of it went away, no use in keeping this code.
* arm: Use proper PLT/GOT for -run.Michael Matz2014-04-061-9/+53
| | | | | | | | | | | 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.
* x86_64: Create proper PLT and GOT also for -runMichael Matz2014-04-061-16/+21
| | | | | | 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.
* arm: Handle R_ARM_NONE relocsMichael Matz2014-04-041-0/+4
| | | | | | | 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.
* run: Always create .got relocsMichael Matz2014-04-041-0/+7
| | | | | | | 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.
* ELF: Make first PT_LOAD cover headersMichael Matz2014-04-031-5/+10
| | | | | | | | 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).
* x86-64: shared libs improvementMichael Matz2014-03-311-25/+45
| | | | | | | | | | 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.
* x86-64: Add basic shared lib supportMichael Matz2014-03-311-36/+40
| | | | Initial support for shared libraries on x86-64.
* Fix again GOT32 + PLT32 reloc commitThomas Preud'homme2014-03-291-4/+3
| | | | | Fix commit aa561d70119accb59a17f10f9ba69076fb0ab516 by setting has_plt_entry once the plt has been created, not before.
* The hack to allow valgrind works with tcc compiled programsmingodad2014-03-281-1/+5
| | | | | | have the undesired side effect of programs compiled with debug info segfaulting after debug info been striped more tought must be done here
* This allow valgrind to work on linux, some how the PHDR is missing and then ↵mingodad2014-03-281-1/+1
| | | | | | valgrind complain with: Inconsistency detected by ld.so: rtld.c: 1284: dl_main: Assertion `_rtld_local._dl_rtld_map.l_libname' failed!
* Simplify and fix GOT32 + PLT32 reloc commitThomas Preud'homme2014-03-261-3/+2
| | | | | | | | 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 dc8ea93b13faefb565fb937f8b8c08c40c063549.
* A possible fix for the memory leak reported by valgrind when running ↵mingodad2014-03-251-0/+1
| | | | tcctest.c with tcc.
* Support GOT32 and PLT32 reloc for same symbolThomas Preud'homme2014-03-251-11/+31
| | | | | | | 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.
* Always link libtcc1.a in (useful for va_* on x86)Thomas Preud'homme2014-03-251-2/+3
| | | | On x86 tcc call to function in libtcc1.a to implement va_* functions.
* Fix relocation of __bound_initThomas Preud'homme2014-03-171-2/+8
| | | | | | | When bound check is enabled, tcc tries to relocate a call to __bound_init in _init. This means that relocation (in tcc_add_bcheck) must be done after libtcc1.a (which countains __bound_init) is loaded but before crtn.o is loaded as this finalize _init.
* Adjust relocation offset for thumb to ARM veneerThomas Preud'homme2014-03-111-1/+1
|
* Fix warning of clangThomas Preud'homme2014-03-091-20/+20
|
* Call fill_got_entry unconditionallyThomas Preud'homme2014-02-101-2/+0
| | | | | | Call fill_got_entry unconditionally from fill_got so as to avoid warnings on !x86-64 architectures. This can be done since this code path is only followed by x86-64 architecture anyway.
* Add support of Thumb to ARM branch relocationThomas Preud'homme2014-02-061-0/+28
|
* Split elf_output_file in smaller functionsThomas Preud'homme2014-02-061-544/+652
|
* Add macro to browse reloc and sym entriesThomas Preud'homme2014-02-061-79/+39
| | | | | Introduce for_each_elem to browse relocation entries and symbols of a section.
* Revert "Add macro to browse reloc and sym entries"Thomas Preud'homme2014-02-021-37/+77
| | | | This reverts commit 3cbc7a2dccf13b96c572623582d6c54394f98c36.