aboutsummaryrefslogtreecommitdiff
path: root/x86_64-link.c
Commit message (Collapse)AuthorAgeFilesLines
* added 64-bit relocation types that required to linking against 64-bit (large ↵Aron BARATH2017-05-121-11/+51
| | | | model) libraries
* Spelling fixes in C comments onlyLarry Doolittle2017-05-071-2/+2
|
* elf: Support STB_LOCAL dynamic symbolsMichael Matz2017-05-071-0/+1
| | | | | | | | local symbols can be resolved statically, they don't have to be done dynamically, so this is a slight speedup at load time for produced executables and shared libs. The musl libc also rejects any STB_LOCAL symbols for dynamic symbol resolution, so there it also fixes use of shared libs created by tcc.
* tcc: fixup clang warningsAndrei Warkentin2017-04-251-1/+1
| | | | | | | | | | | The O(xxx) stuff in i386-asm.c had me scratching my head. Extracting the macro and trying it out in a separate program doesn't give me any warnings, so I'm confused about what could be going on there. Any cast will make things happy. I used a uint64_t to catch actual cases of overflow, which will still cause a -Wconstant-conversion warning. Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
* Fix gawk miscompileMichael Matz2016-12-181-0/+3
| | | | | See testcase. Function pointer use was hosed when the destination function wasn't also called normally by the program.
* x86-64: Prefer 32S relocationsMichael Matz2016-12-151-1/+1
| | | | | | | | | | | | | | | | This target has _32 and _32S relocs (the latter being for signed 32 bit entities). All instruction displacements have to use the 32S variants. Normal references like .long s normally would use the _32 variant. For normal executables this doesn't matter. For shared libraries neither (which use PC-relative relocs). But it matters for things like the kernel that are linked to high addresses (signed ones). There the GNU linker would error out on overflow for the _32 variant. To keep life simple we simply switch from _32 to _32S altogether. Strictly speaking it's still wrong, but in practice using _32 is more often wrong than using _32S ;)
* tccelf: some linker cleanupgrischka2016-12-151-3/+73
| | | | | | | | | | - 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-101-14/+59
| | | | | | | 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-101-12/+12
| | | | | | 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.
* Fix PLT creation for i386Thomas Preud'homme2016-12-101-0/+1
| | | | | | | | | | | | | | | | | | | 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.
* Fix relocs_info declaration in tcc.hThomas Preud'homme2016-12-051-2/+23
| | | | | | | | | 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.
* Consolidate all relocations in relocate_sectionThomas Preud'homme2016-12-031-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Make build_got_entries more target independentThomas Preud'homme2016-12-031-0/+14
| | | | | Factor most of common logic between targets in build_got_entries by defining target specific info into structures in the backends.
* Do section relocation in architecture backendThomas Preud'homme2016-12-031-0/+99