Commit Graph

336 Commits

Author SHA1 Message Date
Thomas Preud'homme
3ad3168125 Clean changes introduced by 47abdbd
* Replace the save/load_buffer_state by a dynarray approach:
  - Filename and libname are added to a dynarray when first encountered
  - Load repeatedly the files in the dynarray until no new undefined
    symbol are encountered
* Replace snprintf by sprintf in libname_to_filename
* Use tcc_fileextension in filename_to_libname
* Introduce a tcc_strcpy_part fonction to copy only a subset of a
  string
* Move new_undef_syms declaration from tcc.h to tccelf.c
2010-04-20 16:02:42 +02:00
Thomas Preud'homme
47abdbd3d5 Better handle ld scripts
* search file from INPUT and GROUP commands in the library path in
  addition to the current directory
* handle libraries specified by -lfoo options
* Search lib in GROUP command repeatedly
2010-04-15 19:30:00 +02:00
grischka
d2cf970a41 tccelf: fix warning 2010-04-13 18:30:01 +02:00
Ali Gholami Rudi
d63ec6f20d fill got table for static linking 2010-02-05 08:25:48 +03:30
Nikos Mavrogiannopoulos
253bad7993 Added patch to detect and use the paths for 64bit libraries as
used by CentOS (affects X86_64 only).
2010-01-28 08:27:38 +01:00
Detlef Riekenberg
2650584ac4 Recognize -Wl,-Bsymbolic
Without -Bsymbolic, a symbol/function in a *.so can be overridden
by a symbol/function in the main module.
That is the default search order, but not supported by tcc.

With -Bsymbolic, the linker tries to resolve a symbol/function in
the current module first.
The loader in tcc implements this search order.

We do not distinguish -Bsymbolic and -Bsymbolic-function

--
By by ... Detlef
2010-01-26 22:55:14 +01:00
grischka
5299142286 x86-64: use uplong for symbol values 2010-01-14 20:59:42 +01:00
grischka
0de95730ad build from multiple objects: fix other targets 2009-12-20 20:33:41 +01:00
grischka
88a3ccab9f allow tcc be build from separate objects
If you want that, run: make NOTALLINONE=1
2009-12-20 01:53:49 +01:00
grischka
7fa712e00c win32: enable bounds checker & exception handler
exception handler borrowed from k1w1. Thanks.
2009-12-19 22:22:43 +01:00
grischka
e81569bc70 tcc: add "-Wl,-rpath=path" option (library search path) 2009-12-19 22:16:20 +01:00
Luigi Rizzo
55cb2170cd solve tccelf problem on FreeBSD
On Sun, Nov 22, 2009 at 05:43:14PM +0100, Luigi Rizzo wrote:
> Hi,
> there is a well known problem with tcc and FreeBSD in the generation
> of elf objects -- see
> http://lists.gnu.org/archive/html/tinycc-devel/2005-07/msg00070.html
>
> Apparently Sergey Lyubka has tried a partial fix to the problem.
> I was wondering if Sergey or someone can post some more detail on
> what needs to be done so we can try to help fixing this issue

I think i have managed to solve the problem and produce
almost valid elf files on FreeBSD. The two patches attached
address a few problems (trying to explain to the
best of my knowledge; i am not very familiar with ELF and
the FreeBSD ELF conventions):

1. ELF file format
  tcc produces an ELF executable which is good for linux but
  not for FreeBSD. It misses the PHDR section which is almost
  mandatory for shared executables, puts in the .dynsym section
  some relocation info that FreeBSD expects to be in .got,
  and expect the relocation sections to be contiguous.

  patch-tccelf.c tries to address the above problem using
  conditional sections (so hopefully can be imported upstream)
  and also adds the ability to override the name of the dynamic
  loader through an environment variable (this is important to
  debug tcc).

2. predefined macros

  patch-libtcc.c adds/fixes some predefined macros when compiling
  on FreeBSD: these are __FreeBSD__ and the usual set of
  __i386__ and __unix__ variants.
  It also sets __INTEL_COMPILER so we can grab the __aligned
  macro from cdefs.h , otherwise many programs would fail

The resulting elf file is still not 100% correct -- if you strip it,
the program will not run (presumably there is some dangling reference).
Other than that, program do seem to run correctly.

It would be nice to integrate these patches in the main repository.
The FreeBSD specific code is in #ifdef so it should not harm
linux users
	cheers
	luigi
2009-12-01 17:59:28 +01:00
Feret@.(none)
c15e37edad Removed binary executable output support
This broke writing executables.
2009-11-13 18:09:02 +01:00
Frederic Feret
2f73e42d87 various fixes and new options for PE format 2009-11-13 18:09:00 +01:00
Frederic Feret
0d768b9713 added 16-bit x86 assembly support 2009-11-13 18:08:58 +01:00
Frederic Feret
2349efa61b add binary executable output support 2009-11-13 18:08:58 +01:00
grischka
1026ca5888 fix "symbol not defined" if symbol has offset 0 2009-08-24 13:30:01 +02:00
grischka
f88350b611 fix some warning 2009-07-18 22:07:51 +02:00
grischka
c998985c74 cleanup: constify some global data 2009-07-18 22:07:42 +02:00
grischka
1df662c1b0 tccpe: load dll on the fly 2009-07-18 22:07:25 +02:00
grischka
035918ef2f win64: fix pointer <-> unsigned long typecast issues 2009-07-18 22:05:58 +02:00
grischka
3ea4acb9b9 pe32+ target: add in various #define's 2009-07-18 22:05:27 +02:00
grischka
370cdeb628 tccpe: build IAT vector with with -run too
This prepares for x86_64 where we need the vector
for far jumps.  Also, resolve DLL symbols in place
2009-07-18 21:55:15 +02:00
grischka
bba515afe5 tccelf: accept BSS symbol with same name from other module
... such as 'int baz;' in two files at the same time
2009-06-17 02:08:54 +02:00
grischka
68310299b6 ulibc: #define TCC_UCLIBC and load elf_interp 2009-05-16 22:29:40 +02:00
grischka
03c787d6ce fix unused/uninitalized warnings 2009-05-11 18:46:39 +02:00
grischka
40f5ce002e fix warnings with tcc_add/get_symbol 2009-05-11 18:46:25 +02:00
grischka
f9181416f6 move some global variables into TCCState 2009-05-11 18:45:44 +02:00
Shinichiro Hamaji
9a7173bf69 x86-64: Fix tcc -run. We need extra memory for PLT and GOT.
Size of the extra buffer is too large for now.
2009-04-18 15:08:02 +02:00
grischka
b1697be691 change tcc_add/get_symbol to use void* 2009-04-18 15:08:02 +02:00
Shinichiro Hamaji
85d016b507 x86-64: Remove code for debug print.
Now, we concat buffers before relocation. So this only happens when users try creating >2GB binary.
2009-04-18 15:08:02 +02:00
Shinichiro Hamaji
51a7f163ad Work around for the issue TCC doesn't handle -2147483648 properly.
TCC produces code which is incompatible with GCC for the following code:

    printf("%lld\n", (long long)-2147483648);
    printf("%lld\n", (long long)-2147483649);

For now, just avoid using the corner value.
2009-04-18 15:08:01 +02:00
Shinichiro Hamaji
fcf2e5981f x86-64: Combine buffers of sections before we call tcc_run().
- Now we can run tcc -run tcc.c successfully, though there are some bugs.
- Remove jmp_table and got_table and use text_section for got and plt entries.
- Combine buffers in tcc_relocate().
- Use R_X86_64_64 instead of R_X86_64_32 for R_DATA_32 (now the name R_DATA_32 is inappropriate...).
2009-04-18 15:08:01 +02:00
Shinichiro Hamaji
830b7533c9 Generate PIC code so that we can create shared objects properly.
- Add got_table in TCCState. This approach is naive and the distance between executable code and GOT can be longer than 32bit.
- Handle R_X86_64_GOTPCREL properly. We use got_table for TCC_OUTPUT_MEMORY case for now.
- Fix load() and store() so that they access global variables via GOT.
2009-04-18 15:08:01 +02:00
Shinichiro Hamaji
97072b3cd7 x86-64: Now TCC can create healthy shared objects from object files generated by GCC
- Handle R_X86_64_GOTPCREL.
- Output R_X86_64_RELATIVE reloc generated from R_X86_64_64.
2009-04-18 15:07:10 +02:00
Shinichiro Hamaji
754b0beb7d x86-64 bug fix: Fix stab generation for x86-64.
The size of a stab entry is 12 bytes even in 64bit environments. We must use int instead of long to keep the size of stab entries.
2009-04-18 15:07:09 +02:00
Shinichiro Hamaji
040ef000e4 Better DLL support on x86-64.
- Add a macro TCC_OUTPUT_DLL_WITH_PLT.
-- Now, the DLL with PLT support works only on x86-64, but we may be able to support it on all architectures eventually.
- Define TCC_OUTPUT_DLL_WITH_PLT when target architecture is x86-64.
- Current status (x86-64):
-- Main program should be able to call functions in shared objects.
-- Main program should be able to use global variables in shared objects.
-- Shared objects should be able to call functions in main  program.
-- Shared objects can NOT use global variables in main program.
- To fix the last issue, we may need to add support of -fPIC option in our code generator.
2009-04-18 15:07:09 +02:00
Shinichiro Hamaji
fe8f230ab6 First naive DLL support on x86-64.
This logic depends on x86_64-gen.c and doesn't work with objects compiled by GCC.
2009-04-18 15:07:09 +02:00
Shinichiro Hamaji
0a9873aa22 Add support of x86-64.
Most change was done in #ifdef TCC_TARGET_X86_64. So, nothing should be broken by this change.

Summary of current status of x86-64 support:

- produces x86-64 object files and executables.
- the x86-64 code generator is based on x86's.
-- for long long integers, we use 64bit registers instead of tcc's generic implementation.
-- for float or double, we use SSE. SSE registers are not utilized well (we only use xmm0 and xmm1).
-- for long double, we use x87 FPU.
- passes make test.
- passes ./libtcc_test.
- can compile tcc.c. The compiled tcc can compile tcc.c, too. (there should be some bugs since the binary size of tcc2 and tcc3 is differ where tcc tcc.c -o tcc2 and tcc2 tcc.c -o tcc3)
- can compile links browser. It seems working.
- not tested well. I tested this work only on my linux box with few programs.
- calling convention of long-double-integer or struct is not exactly the same as GCC's x86-64 ABI.
- implementation of tcc -run is naive (tcc -run tcctest.c works, but tcc -run tcc.c doesn't work). Relocating 64bit addresses seems to be not as simple as 32bit environments.
- shared object support isn't unimplemented
- no bounds checker support
- some builtin functions such as __divdi3 aren't supported
2008-12-02 02:30:47 +01:00
Shinichiro Hamaji
ba8c95a98d silly bug fix: s/#ifdef PTR_SIZE == 4/#if PTR_SIZE == 4/ 2008-12-02 02:26:37 +01:00
Shinichiro Hamaji
27d23342ea Make tccelf.c 64bit ready.
- Use REL_SECTION_FMT instead of ".rel%s".
- Use PTR_SIZE instead of sizeof(int) for GOT entries.
- Use sizeof(ElfW(Dyn)) instead of magic number 8.
- Use TCC_ELFCLASS instead of ELFCLASS32.
2008-12-02 02:26:34 +01:00
Shinichiro Hamaji
7dd792ef51 Introduce ElfW macro and ELFW to encapsulate the difference between Elf32_* and Elf64_*. Also, introduce ElfW_Rel and SHT_RELX for difference between REL and RELA. 2008-12-02 02:25:45 +01:00
Daniel Glöckner
15e0dc08a6 Allow to use libgcc instead of libtcc1
This patch adds a switch --with-libgcc to configure.
When passed it prevents libtcc1.a from being built and links to
/lib/libgcc_s.so.1 instead of PREFIX/lib/tcc/libtcc1.a.

It will work on ARM when using libgcc from GCC >= 4.2.0.
Prior versions don't have the __floatun[sd]i[sdx]f functions.

It won't work on i386 because of two missing symbols emitted when
floats are cast to integers, but users can provide those symbols
(global short constants) in their code if needed.

  Daniel
2008-09-12 22:22:58 +02:00
grischka
f9bf48d643 release loaded dlls cleanly (Sam K) 2008-05-05 22:40:49 +00:00
grischka
96bd8f2b25 enable pe-output from libtcc (Shmuel Zeigerman) 2008-05-05 22:39:43 +00:00
grischka
5247bbc2f0 fix stabstr with linked objects 2008-04-27 18:49:31 +00:00
grischka
0d598aca08 fix bogus relocations with TCC_OUTPUT_DLL 2008-04-27 18:48:19 +00:00
grischka
a327c7a552 added verbosity levels (-vv -vvv) 2008-03-31 19:49:14 +00:00
grischka
9bcc0b970b Add -soname linker option (Marc Andre Tanner) 2008-03-25 21:04:47 +00:00
grischka
e2c89576c7 Fix 'tcc -static' with recent glibc 2008-03-08 19:58:57 +00:00
grischka
5342b32eef Switch to newer tccpe.c (includes support for resources) 2007-12-19 17:36:42 +00:00
grischka
f99d3de221 Import 409,410: ARM EABI by Daniel Glckner 2007-12-04 20:38:09 +00:00
grischka
d778bde7f9 Import more changesets from Rob Landley's fork (part 2) 2007-11-21 17:16:31 +00:00
grischka
2bcc187b1b Fix 'invalid relocation entry' problem on ubuntu - from Bernhard Fischer 2007-10-30 15:13:21 +00:00
bellard
5487bc23c8 tcc_load_dll fix (Tao Wu) 2005-10-30 21:53:14 +00:00
bellard
bb24eb9de4 ignore AS_NEEDED ld command 2005-09-03 21:32:06 +00:00
bellard
fe9b1f60ce win32 merge (grischka) 2005-04-17 13:15:54 +00:00
bellard
d733dc752e better st_other support 2005-04-13 21:37:06 +00:00
bellard
2c538d7a2b initial PE format support 2005-04-10 21:46:58 +00:00
bellard
6bbfb8f610 removed warnings 2004-11-07 15:43:15 +00:00
bellard
c9c05ca5f0 copyright update 2004-10-27 21:38:03 +00:00
bellard
3e74b91de6 correct libtcc1 link order 2004-10-27 21:24:42 +00:00
bellard
38e8a23025 fixed linker symbol generation - output format support 2004-10-23 22:53:42 +00:00
bellard
ff3a5daf25 _end symbol definition fix - fixed section alignment logic 2004-10-18 00:20:26 +00:00
bellard
ec7d36326d C67 COFF executable format support (TK) 2004-10-05 22:33:55 +00:00
bellard
79c72b2419 initial TMS320C67xx support (TK) 2004-10-04 21:57:35 +00:00
bellard
4df5bd2eb0 ARM target support (Daniel Glockner) - allow unsigned char as default on ARM (Daniel Glockner) - fixed small ld script support (Daniel Glockner) 2003-10-14 22:15:56 +00:00
bellard
feed3262c9 fixed libc linking when running in memory 2003-10-04 21:24:46 +00:00
bellard
46169b92d9 .gnu.linkonce section support (useful to link with recent glibc) 2003-10-04 14:45:23 +00:00
bellard
f8d0241764 changed tcc_get_symbol() prototype 2003-07-20 19:19:58 +00:00
bellard
9d95be78c8 added init_array defines for new ld compatibility 2003-05-29 22:52:53 +00:00
bellard
98713a6be3 added -rdynamic support 2003-05-24 15:46:29 +00:00
bellard
8f5e44a439 changed license to LGPL 2003-05-24 14:11:17 +00:00
bellard
c4e6b2e9be alacarte linking (Dave Long) 2003-04-28 22:06:38 +00:00
bellard
2b64f2f570 added -nostdlib 2003-04-27 11:45:01 +00:00
bellard
066d5e7a84 ignore OUTPUT_FORMAT and TARGET ld script commands (fixes Redhat >= 7 static link problems) 2003-04-16 21:25:59 +00:00
bellard
cab6018913 fixed comment parsing 2003-04-13 18:05:51 +00:00
bellard
c2e6daafc1 PLT generation fix 2003-04-13 14:38:05 +00:00
bellard
fa6ac83ec5 FreeBSB fixes - elf align issues 2002-12-08 14:35:48 +00:00
bellard
8901fbeef1 parsing optimizations 2002-11-23 18:15:17 +00:00
bellard
b81d4ba6b3 prepared parser for direct use of file->buf_ptr - faster comment parsing 2002-11-22 23:28:06 +00:00
bellard
2956bd85cd suppressed ch1 and preparser 2002-11-22 18:12:41 +00:00
bellard
e4c7dd5e60 removed many memory leaks - suppressed many global variables 2002-11-02 14:13:21 +00:00
bellard
d8ef07df04 added tcc_relocate() and tcc_get_symbol() 2002-09-08 22:46:32 +00:00
bellard
f946dffd33 suppressed section_ptr - fixed constant string allocation 2002-08-18 14:34:57 +00:00
bellard
3a58c53eaf moved ELF specific stuff to tccelf.c 2002-08-18 13:17:59 +00:00