Commit Graph

186 Commits

Author SHA1 Message Date
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
Thomas Preud'homme
078ba241d9 Always link libtcc1.a in (useful for va_* on x86)
On x86 tcc call to function in libtcc1.a to implement va_* functions.
2014-03-25 21:18:57 +08:00
Thomas Preud'homme
ec1c83081d Fix relocation of __bound_init
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.
2014-03-17 23:14:38 +08:00
Thomas Preud'homme
b2192fc50b Adjust relocation offset for thumb to ARM veneer 2014-03-11 21:45:52 +08:00
Thomas Preud'homme
62d1da1b3e Fix warning of clang 2014-03-09 22:54:30 +08:00
Thomas Preud'homme
361ec4f98e Call fill_got_entry unconditionally
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.
2014-02-10 21:35:00 +08:00
Thomas Preud'homme
e571850d79 Add support of Thumb to ARM branch relocation 2014-02-06 21:38:24 +08:00
Thomas Preud'homme
4aec2902ca Split elf_output_file in smaller functions 2014-02-06 19:38:28 +08:00
Thomas Preud'homme
55f751ac6d Add macro to browse reloc and sym entries
Introduce for_each_elem to browse relocation entries and symbols of a
section.
2014-02-06 19:38:24 +08:00
Thomas Preud'homme
2eb844f8b5 Revert "Add macro to browse reloc and sym entries"
This reverts commit 3cbc7a2dcc.
2014-02-02 20:02:12 +08:00
Thomas Preud'homme
e5a706a091 Revert "Split elf_output_file in smaller functions"
This reverts commit b5b82df3e3.
2014-02-02 20:02:11 +08:00
Thomas Preud'homme
f62e97e0ed Revert "Add support of Thumb to ARM branch relocation"
This reverts commit 8635939b8d.
2014-02-02 20:02:08 +08:00
Thomas Preud'homme
8635939b8d Add support of Thumb to ARM branch relocation 2014-02-02 17:23:15 +08:00
Thomas Preud'homme
b5b82df3e3 Split elf_output_file in smaller functions 2014-02-02 17:23:15 +08:00
Thomas Preud'homme
3cbc7a2dcc Add macro to browse reloc and sym entries
Introduce for_each_elem to browse relocation entries and symbols of a
section.
2014-02-02 17:23:15 +08:00
Thomas Preud'homme
599677a5e2 Give ARM asm mnemonic of PLT entries
Give ARM assembly mnemonic of PLT entries in put_got_entry
2014-02-02 17:23:15 +08:00
Thomas Preud'homme
3d4b57ffe3 Clean tccelf.c
- remove debug printf and commented out code
- remove C++-like comments
- remove whitespace at end of lines
- replace tabs by spaces
2014-02-02 17:23:14 +08:00
Thomas Preud'homme
da0601e490 Remove WITHOUT_LIBTCC macro: no more user 2014-01-08 21:32:53 +08:00
Thomas Preud'homme
3352cb8aef Shared libraries also have entry points
This fix commit 32734680cb
2014-01-08 18:10:02 +08:00
Thomas Preud'homme
32734680cb Improve ELF on ARM
* set whether soft or hardfloat calling convention is used
* mark ELF file has having an entry point when there is
2014-01-08 17:59:16 +08:00
Thomas Preud'homme
28f0286479 Update elf.h 2014-01-08 17:38:31 +08:00
Thomas Preud'homme
b6247d1f3c Add support for runtime selection of float ABI 2014-01-08 15:00:52 +08:00
grischka
4ad186c5ef i386: use __fixdfdi instead of __tcc_cvt_ftol
Variants __fixsfdi/__fixxfdi are not needed for now because
the value is converted to double always.

Also:
- remove __tcc_fpinit for unix as it seems redundant by the
  __setfpucw call in the startup code
- avoid reference to s->runtime_main in cross compilers
- configure: fix --with-libgcc help
- tcctok.h: cleanup
2014-01-06 19:07:08 +01:00
Thomas Preud'homme
9e79b18bca Use libtcc.a for static link even with USE_LIBGCC
When statically linking, runtime library should be static as well. tcc
could link with libgcc.a but it's in a gcc version specific directory.
Another solution, followed by this patch, is to use libtcc.a when
statically linking, even if USE_LIBGCC was configured.
2014-01-03 18:20:51 +08:00
Thomas Preud'homme
1b606d1884 Allow thumb transition for R_ARM_PC24
Allow bl -> blx conversion in the case of R_ARM_PC24 relocation with
instruction being an unconditional bl. Also make spacing more uniform.
2013-11-18 00:03:38 +08:00
Thomas Preud'homme
cf02f920c1 Revert "Add support for thread-local storage variables"
TLS support in tinyCC is absolutely not ready:
- segment register not select in load and store
- no relocation added for computing offset of per-thread symbol
- no support for TLS-specific relocations
- no program header added as per Drepper document about TLS

This reverts commit 1c4afd1350.
2013-11-03 18:55:54 +08:00
Thomas Preud'homme
1c4afd1350 Add support for thread-local storage variables 2013-10-29 22:10:02 +08:00
Urs Janssen
0bdbd49eac add version number to manpage
avoid c++/c99 style comments in preprocessor directives
avoid leadings whitespaces in preprocessor directives
mention implemented variable length arrays in documentation
fixed ambiguous option in texi2html call (Austin English)
2013-02-17 00:48:51 +01:00
grischka
05108a3b0a libtcc: new LIBTCCAPI tcc_set_options(TCCState*, const char*str)
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
2013-02-12 19:13:28 +01:00
grischka
d6d7686b60 tcc.h: declare CValue.tab[LDOUBLE_SIZE/4]
Should fix some warnings wrt. access out of array bounds.

tccelf.c: fix "static function unused" warning
x86_64-gen.c: fix "ctype.ref uninitialzed" warning and cleanup
tcc-win32.txt: remove obsolete limitation notes.
2013-02-08 19:07:11 +01:00
grischka
7a477d70ca lib/Makefile: use CC, add bcheck to libtcc1.a
Also:
- fix "make tcc_p" (profiling version)
- remove old gcc flags:
  -mpreferred-stack-boundary=2 -march=i386 -falign-functions=0
- remove test "hello" for Darwin (cannot compile to file)
2013-02-06 19:01:07 +01:00
grischka
92024ab07a 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.

This partially reverts commit 0d598aca08.
I don't remember what the problem was but it was the wrong way
to fix it.
2013-02-05 21:18:29 +01:00
grischka
e0aee4f455 portability: make tcc_get_symbol() available for non-native
For consistency with tcc_add_symbol().
Use uintptr_t here also.
2013-02-04 20:57:57 +01:00
grischka
82bcbd027f portability: fix void* <-> target address conversion confusion
- #define addr_t as ElfW(Addr)
- replace uplong by addr_t
- #define TCC_HAS_RUNTIME_PLTGOT and use it
2013-02-04 16:24:59 +01:00
Thomas Preud'homme
ae33c30b49 Revert "Don't call elf_hash on NULL value"
This reverts commit 505329b5b3.
2013-01-31 13:43:04 +01:00
grischka
2f6b8469cc safety: replace occurrences of strcpy by pstrcpy 2013-01-31 13:23:19 +01:00
Domingo Alvarez Duarte
505329b5b3 Don't call elf_hash on NULL value
Make sur elf_hash is never invoked with a NULL value.

Signed-off-by: Thomas Preud'homme <robotux@celest.fr>
2013-01-31 12:07:20 +01:00
Thomas Preud'homme
bcac413c30 Fix overflow detection in ARM relocation
Fix overflow detection for R_ARM_CALL, R_ARM_PC24, R_ARM_JUMP24 and
R_ARM_PLT32 relocations on ARM. 26 bits means 25 bits for positive and
negative offsets !
2013-01-28 19:13:25 +01:00