aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* tests: add .so/.dll creation testgrischka2016-12-153-9/+23
| | | | | Also remove bitfield test from tcctest.c because gcc versions don't agree among each other.
* tccelf: some linker cleanupgrischka2016-12-159-441/+466
| | | | | | | | | | - generate and use SYM@PLT for plt addresses - get rid of patch_dynsym_undef hack (no idea what it did on FreeBSD) - use sym_attrs instead of symtab_to_dynsym - special case for function pointers into .so on i386 - libtcc_test: test tcc_add_symbol with data object - move target specicic code to *-link.c files - add R_XXX_RELATIVE (needed for PE)
* Use functions to get relocation infoThomas Preud'homme2016-12-107-109/+320
| | | | | | | MSVC does not support array designator so cannot compile source using relocs_info. This commit replace the relocs_info array into a set of functions, each returning the value given by a given field of the struct reloc_info.
* Remove now useless pltoff_addend reloc infoThomas Preud'homme2016-12-106-70/+69
| | | | | | Last use for pltoff_addend field of relocs_info array was removed in commit 25927df3b75c5ce2b64ab8acdcc5974b4e1c89c1. It is now useless so this commit removes it and all initialization related to it.
* Add missing relocation info for C67 targetThomas Preud'homme2016-12-102-4/+14
| | | | | Fill in relocs_info table for C67 and fix R_C60_NUM value to really be greater than all relocation values known to TCC.
* Error out in put_got_entry if no dynamic symbolThomas Preud'homme2016-12-101-0/+2
|
* Allow PLT/GOT entry for weak static symbolThomas Preud'homme2016-12-101-0/+1
|
* Fix PLT creation for i386Thomas Preud'homme2016-12-106-1/+16
| | | | | | | | | | | | | | | | | | | i386 target does not have PC relative loads. Its ABI therefore require ebx register to points to the GOT when executing a PLT entry. This means that PLT entry cannot be used transparently, the compiler needs to expect execution of a PLT entry to be able to use one, that is a PLT entry should only be created if the relocation explicitely asks for it (eg. R_386_PLT32). This patch creates a new target macro PCRELATIVE_DLLPLT to indicate whether a target can do a PC relative load in PLT entry when building a dynamic library. Executable do not normally pose a problem because they are loaded at a fixed address and thus the absolute address of GOT can be used. Note that in such a case, if the compiler does not use a PLT aware relocation for external access then the code relocation will fall on the dynamic loader since there is no PLT entry to relocate too.
* arm64: Fix regression introduced by 6245db9.Edmund Grimley Evans2016-12-051-0/+4
|
* Fix set but not used error in arm64-link.cThomas Preud'homme2016-12-051-5/+4
|
* Fix tcc_error params for R_AARCH64_(JUMP|CALL)26Thomas Preud'homme2016-12-051-3/+2
|
* Error on unrecognized relocationsThomas Preud'homme2016-12-052-1/+6
|
* Add relocs_info array to c67 backendThomas Preud'homme2016-12-051-0/+2
|
* Fix relocs_info declaration in tcc.hThomas Preud'homme2016-12-0512-90/+129
| | | | | | | | | C standard specifies that array should be declared with a non null size or with * for standard array. Declaration of relocs_info in tcc.h was not respecting this rule. This commit add a R_NUM macro that maps to the R_<ARCH>_NUM macros and declare relocs_info using it. This commit also moves all linker-related macros from <arch>-gen.c files to <arch>-link.c ones.
* Control symbol table of which to relocate symbolsThomas Preud'homme2016-12-034-6/+6
| | | | Pass pointer to symbol table to relocate the symbols of in relocate_syms
* Code simplification in relocate_symsThomas Preud'homme2016-12-031-7/+4
|
* Consolidate all relocations in relocate_sectionThomas Preud'homme2016-12-034-66/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Static relocation of functions in dynamic libraries must use the PLT entry as the target. Before this commit, it used to be done in 2 parts for ARM, with the offset of the PLT entry from the beginning of the PLT being put in the relocated place in build_got_entries () and then the address of the PLT being added in relocate_section. This led to code dealing with reading the offset of a bl instruction in build_got_entries. Furthermore, the addition of the address of the start of the PLT was done based on the relocation type which does not convey whether a PLT entry should be used to reach the symbol. This commit moves the decision to use the PLT as the target in relocate_section, therefore having the instruction aware code contained to the target-specific bit of that function (in <target>-link.c). Note that relocate_syms is *not* the right place to do this because two different relocations for the same symbol can make different decision. This is the case in tcc -run mode where the static and dynamic relocation are done by tcc. Storing the PLT entry address in the symbol's st_value field and relying on the specific relocation type being used for dynamic relocation would work but the PLT entry address would then appear in the static symbol table (symtab). This would also make the static symbol table entry differ from the dynamic symbol table entry.
* Allow to get sym attr and fail if no entryThomas Preud'homme2016-12-032-23/+27
| | | | | | Change alloc_sym_attr into get_sym_attr and add a parameter to control whether to allocate a new symattr structure or return NULL if symbol is not found;
* Consolidate GOT creation in build_got_entriesThomas Preud'homme2016-12-032-17/+25
| | | | | | | | | | | | | | | | | | Currently GOT/PLT creation happens in two locations depending on whether the GOT/PLT [entry] is required by the symbol or the relocation: - bind_exe_dynsym for relocations to undefined symbol - build_got_entries/put_got_entry for relocations that require a GOT/PLT entry This commit consolidate GOT/PLT creation in build_got_entries by reducing bind_exe_dynsym's job to create a dynamic symbol for undefined symbols. build_got_entries then invoke put_got_entry if the symbol being relocated is undefined or the relocation asks for a PLT or GOT [entry]. put_got_entry is also modified to only export a symbol in the dynamic symbol table when we are in the case of PLT/GOT [entry] required by the relocation (since undefined symbol are already exported by bind_exe_dynsym).
* Make build_got_entries more target independentThomas Preud'homme2016-12-0311-210/+178
| | | | | Factor most of common logic between targets in build_got_entries by defining target specific info into structures in the backends.
* Only create GOT or GOT entry when neededThomas Preud'homme2016-12-031-22/+27
| | | | | | | | | | | | Currently we always build a GOT when we recognize a relocation in build_got_entries even if the relocation does not require one. In the same spirit, when the relocation does require one we always create a GOT entry even if not entry is necessary. This patch restricts the creation of a GOT and a GOT entry to relocations that needs it, ie: - do not create a GOT if relocation is not related to GOT and symbol is not UNDEF - do not create a GOT entry if relocation only relates to beginning of GOT
* Recognize more relocations as needing GOT/PLT entryThomas Preud'homme2016-12-031-16/+41
|
* Do section relocation in architecture backendThomas Preud'homme2016-12-039-490/+552
|
* Add address of GOT + 8 in PLT + 16 and fix PLT0Thomas Preud'homme2016-12-031-3/+5
| | | | | | | | | | | | | On ARM targets, the jump to ld.so resolution routine is done in PLT0 by loading the offset to the GOT found in PLT+16 and from there loading the address in GOT+8 and jumping to it. Currently tcc starts the first regular PLT entry at PLT+16 which thus does not contain the offset to the GOT. This commit fixes that. Note that calls via PLT still worked nonetheless because of some missing dynamic tag which makes ld.so behaves as if RTLD_BIND_NOW was specified in the environment for all executable created by tcc.
* Improve put_got_entry doc and structureThomas Preud'homme2016-12-032-132/+135
|
* Rename add_elf_sym to set_elf_symThomas Preud'homme2016-12-035-29/+29
| | | | | | | | | | add_elf_sym is a confusing name because it is not clear what the function does compared to put_elf_sym. As a matter of fact, put_elf_sym also adds a symbol in a symbol table. Besides, "add_elf_sym" fails to convey that the function can be used to update a symbol (for instance its value). "set_elf_sym" seems like a more appropriate name: it will set a symbol to a given set of properties (value, size, etc.) and create a new one if non exist for that name as one would expect.
* Improve comments for symbol export and bindingThomas Preud'homme2016-12-031-5/+9
|
* Do not add symbol if it is already thereThomas Preud'homme2016-12-031-4/+9
| | | | | | Do not create a new symbol in add_elf_sym if a symbol with same properties (value, size, info, etc.) already exists. This prevents symbols from being exported twice in the dynamic symbol table.
* Fix error logic for undefined reference in libraryThomas Preud'homme2016-12-031-8/+7
| | | | | | | | Prior to this patch, an error would only be given when a library has an unresolved undefined symbol if there is no undefined reference for the same symbol in the executable itself. This patch changes the logic to check both that the executable has the symbol in its static symbol table *and* that it is defined to decide if the error path should be followed.
* Clear SHF_GROUP flag when linkingroot2016-12-031-1/+1
| | | | | | | | | | | | | | | SHF_GROUP flag set on a section indicates that it is part of a section group and that if the section is removed, the other sections in the same group should be removed as well [1]. Since section group are guide for the linking process, they do not have any meaning after linking has occured. TCC rightfully [2] discard such sections (by not recognizing the section type) but keeps the SHF_GROUP flag set on sections that were part of a section group which confuses binutils (objdump and gdb at least). Clearing that bit makes objdump and gdb accept binaries created by TCC. [1] https://docs.oracle.com/cd/E19683-01/816-1386/chapter7-26/index.html [2] GNU ld does the same
* Remove warning when __builtin_frame_address is used with gcc >= 6.Christian Jullien2016-11-301-0/+13
|
* Implement gcc bitfield algorithm; add -mms-bitfieldsDavid Mertens2016-11-286-7/+44
|
* Minor grammar fixes to docsDavid Mertens2016-11-281-4/+4
|
* configure: prefer lib64 on 64-bit platformsgrischka2016-11-281-3/+4
| | | | | | | use lib64 if - "/usr/lib/multi-arch-triplet" does not work and - we are on a 64-bit platform and - lib64 exists and does contain crti.o
* tccelf: introduce add32/64le()grischka2016-11-203-24/+28
|
* x86_64-asm: =m operand fixesgrischka2016-11-206-33/+81
| | | | | | | | | | | | | | | | | | | | | | 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.
* arm: Fix relocate_section with TCC_OUTPUT_MEMORYThomas Stalder2016-11-131-2/+4
|
* remove warningsThomas Stalder2016-11-132-4/+3
|
* tccgen: fix inline_functions double free fixgrischka2016-11-113-15/+19
|
* tccgen: inline_functions double free fixgrischka2016-11-113-10/+11
| | | | | | Fix double free of the inline function token_string which could happen when an error/longjmp occurred while compiling the inline function.
* bcheck: access fields of local structs w/o bcheckPavlas, Zdenek2016-11-101-3/+3
| | | | Revert previous commit, this is probably a better fix.
* bcheck: add structs to local regionsPavlas, Zdenek2016-11-091-2/+2
| | | | | | | | int test() { struct { int i; } s = { 42 }; return s.i; // bound checked }
* i386 + bcheck: fix __bound_local_newPavlas, Zdenek2016-11-092-7/+9
| | | | | | | | | | | | With -b, this produces garbage. Code to call __bound_local_new is put at wrong place, overwriting the regparam setup code. Fix copied from x86_64-gen.c. void __attribute__((regparm(3))) fun(int unused) { char local[1]; }
* i386-gen: use EBX as 4th registergrischka2016-10-191-4/+13
| | | | | May be enabled/disabled by changing this line: #define USE_EBX 1
* lib/libtcc1.c: cleanupgrischka2016-10-195-62/+25
| | | | | | | - 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-196-48/+100
| | | | | | | | | | | | | | - 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
* configure: --triplet= option, Makefile: cleanupgrischka2016-10-174-83/+69
|
* tccpp_new/delete and other cleanupsgrischka2016-10-1710-190/+202
|
* system-hacks: define __GNUC__ for FreeBSDMichael Matz2016-10-171-10/+9
| | | | | | | | | | | | FreeBSDs system headers contain unconditional usage of macros like __aligned(x), which are only conditionally defined in sys/cdefs.h (conditional on __GNUC__ or __INTEL_COMPILER). Bug in FreeBSD, but as work-around we can define __GNUC__ which picks up these defs. [This also moves back the glibc defines we had before into the non-BSD ifdef branch]
* x86-64: Fix long long bugMichael Matz2016-10-171-2/+7
| | | | | | | With the last improvements to lexpand it's now harmful to use on native 64bit platforms when not necessary. For gv_dup it's not necessary there. It can still be used with really transforming a 64bit value into two 32bit ones.