aboutsummaryrefslogtreecommitdiff
path: root/tccelf.c
Commit message (Collapse)AuthorAgeFilesLines
* freebsd: allow building tcc which targets windowsAvi Halachmi (:avih)2017-09-251-1/+2
| | | | | | | | | | | Currently tcc doesn't have a compile-time config indicating that the target is freebsd, and as a result, the tcc binary adds freebsh stuff to elf headers if the compile-time (of tcc) *host* is freebsd. Test also that the target is not PE while generating an elf header. This still likely fails (but untested) when tcc targets other non-freebsd systems on a freebsd system, but for now fix it only when targetting windows.
* When creating a staticaly linked ELF program should not includeEmil2017-06-091-5/+7
| | | | | | | | | any dyn symbols. The if( !s1->static_link ) prevents tcc from crashing when buiding a program linked to dietlibc. The section header should not contain the number of local symbols when the sh_size is null. This makes the header compliant and IDA will not issue any warnings when an executable is disassembled.
* configure: --config-musl/-uClibc switch & misc cleanupsgrischka2017-05-131-12/+10
| | | | | | | | | | | | | | | - configure: - add --config-uClibc,-musl switch and suggest to use it if uClibc/musl is detected - make warning options magic clang compatible - simplify (use $confvars instead of individual options) - Revert "Remove some unused-parameter lint" 7443db0d5f841b81a55e918bf8c228dd20f9ddb2 rather use -Wno-unused-parameter (or just not -Wextra) - #ifdef functions that are unused on some targets - tccgen.c: use PTR_SIZE==8 instead of (X86_64 || ARM64) - tccpe.c: fix some warnings - integrate dummy arm-asm better
* Remove some unused argumentsMichael Matz2017-05-081-2/+2
| | | | these ones are really superfluous.
* Remove some unused-parameter lintLarry Doolittle2017-05-081-9/+11
| | | | | | | | Mark TCCState parameter as unused in tcc_undefine_symbol(), tcc_add_symbol(), tcc_print_stats(), asm_get_local_label_name(), use_section1(), tccpp_delete(), tcc_tool_ar(), tcc_tool_impdef(), and tcc_tool_cross(). Also mark it unused in tcc_add_bcheck() unless CONFIG_TCC_BCHECK. Remove it entirely in ld_next().
* Spelling fixes in C comments onlyLarry Doolittle2017-05-071-1/+1
|
* elf: Fix last commitMichael Matz2017-05-071-7/+53
| | | | Forgot to mark tccelf.c as to be committed in last commit :-/
* elf: Ignore SHF_COMPRESSED sectionsMichael Matz2017-05-061-1/+10
| | | | | | | | | | | | some newer systems have debug sections compressed by default, which includes those in the crt[1in].o startup files. These can't simply be concatenated like all others (which leads to invalid section contents ultimately making gdb fail) but need special handling. Instead of that special handling (decompressing, which in turn requires linking against zlib) let's just ignore such sections, even though that means to also ignore all other debug sections from that particular input file. Our own generated files of course don't have the problem.
* Cleanups (float consts, sections, symbols)Michael Matz2017-05-021-13/+21
| | | | | | | | introduce common_section (SHN_COMMON), factorize some handling in decl_initializer_alloc, add section_add and use it to factorize some code that allocates stuff in sections (at the same time also fixing harmless bugs re section alignment), use init_putv to emit float consts into .data from gv() (fixing an XXX).
* elf: Tidy section headersMichael Matz2017-05-021-2/+51
| | | | | | | Don't emit useless section headers and also sort them in allocated order. Doesn't change behaviour except makes the resulting files a tiny bit smaller (though at the expense of some very tiny compile time and code size increase of tcc itself; not 100% it's worth it).
* arm: Fix build_got_entriesThomas Stalder2017-04-271-1/+5
|
* 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>
* Add support of musl-libcMarc Vertes2017-04-201-1/+1
| | | | The port is functional. Bound checking is not supported yet.
* cross-compilers: allow individual configurationgrischka2017-02-231-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | since configure supports only native configuration a file 'cross-tcc.mak' needs to be created manually. It is included in the Makefile if present. # ---------------------------------------------------- # Example config-cross.mak: # # windows -> i386-linux cross-compiler # (it expects the linux files in <prefix>/i386-linux) ROOT-i386 = {B}/i386-linux CRT-i386 = $(ROOT-i386)/usr/lib LIB-i386 = $(ROOT-i386)/lib:$(ROOT-i386)/usr/lib INC-i386 = {B}/lib/include:$(ROOT-i386)/usr/include DEF-i386 += -D__linux__ # ---------------------------------------------------- Also: - use libtcc1-<target>.a instead of directories - add dummy arm assembler - remove include dependencies from armeabi.c/lib-arm64.c - tccelf/ld_add_file: add SYSROOT (when defined) to absolute filenames coming from ld-scripts
* -Wl, --enable-new-dtags for DT_RUNPATH instead of DT_RPATHSteffen Nurpmeso2017-02-181-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Today by accident i had to deal with linker problems of some software and found an issue that mentioned DT_RUNPATH, which mentioned that DT_RPATH is legacy and searched for $LD_LIBRARY_PATH, whereas the newer DT_RUNPATH is searched thereafter. Completely unencrypted! Well. For what's it worth, i for one am astonished because of course i want to override $LD_LIBRARY_PATH, but it surely has its merites, smart people came to the conclusion, did they. The attached diff below seems to be sufficient to support DT_RUNPATH instead of DT_RPATH with tcc(1). But i have no insight in what --enable-new-dtags is supposed to change in addition, so i wonder. Ciao! --steffen libtcc.c | 2 ++ tcc-doc.texi | 4 ++++ tcc.h | 1 + tccelf.c | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-)
* fixes & cleanupsgrischka2017-02-131-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - tccgen.c/tcc.h: allow function declaration after use: int f() { return g(); } int g() { return 1; } may be a warning but not an error see also 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 - tccgen.c: redundant code related to inline functions removed (functions used anywhere have sym->c set automatically) - tccgen.c: make 32bit llop non-equal test portable (probably not on C67) - dynarray_add: change prototype to possibly avoid aliasing problems or at least warnings - lib/alloca*.S: ".section .note.GNU-stack,"",%progbits" removed (has no effect) - tccpe: set SizeOfCode field (for correct upx decompression) - libtcc.c: fixed alternative -run invocation tcc "-run -lxxx ..." file.c (meant to load the library after file). Also supported now: tcc files ... options ... -run @ arguments ...
* Fix gawk miscompileMichael Matz2016-12-181-24/+32
| | | | | See testcase. Function pointer use was hosed when the destination function wasn't also called normally by the program.
* Fix initializing members multiple timesMichael Matz2016-12-151-0/+37
| | | | | | | When intializing members where the initializer needs relocations and the member is initialized multiple times we can't allow that to lead to multiple relocations to the same place. The last one must win.
* tccelf: some linker cleanupgrischka2016-12-151-411/+144
| | | | | | | | | | - 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-12/+10
| | | | | | | 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.
* 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-101-1/+11
| | | | | | | | | | | | | | | | | | | 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.
* Error on unrecognized relocationsThomas Preud'homme2016-12-051-0/+4
|
* Control symbol table of which to relocate symbolsThomas Preud'homme2016-12-031-3/+3
| | | | 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-031-49/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-031-21/+23
| | | | | | 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-031-16/+24
| | | | | | | | | | | | | | | | | | 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-031-207/+56
| | | | | 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-031-482/+2
|
* 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-031-132/+132
|
* Rename add_elf_sym to set_elf_symThomas Preud'homme2016-12-031-24/+24
| | | | | | | | | | 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
* tccelf: introduce add32/64le()grischka2016-11-201-23/+21
|
* arm: Fix relocate_section with TCC_OUTPUT_MEMORYThomas Stalder2016-11-131-2/+4
|
* tccrun/win64: cleanup runtime function tablegrischka2016-10-191-0/+4
| | | | | | | | | | | | | | - 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
* tccpp_new/delete and other cleanupsgrischka2016-10-171-2/+24
|
* tccgen/tccelf: move code from libtcc.cgrischka2016-10-151-0/+169
|
* arm64: Fix -runMichael Matz2016-10-141-8/+10
| | | | | | | With -run the call instruction and a defined function can be far away, if the function is defined in the executable itself, not in the to be compiled code. So we always need PLT slots for -run, not just for undefined symbols.
* arm64: Support PREL32 relocationMichael Matz2016-10-141-0/+3
| | | | A PC-relative 32bit value is stored.
* Support archives with 64 bit indicesMichael Matz2016-10-141-7/+20
| | | | | Some systems started using SYM64 .a libraries, so start supporting them.
* Misc. fixesgrischka2016-10-051-3/+15
| | | | | | | | | | | | | | | | | | | | Makefile : - do not 'uninstall' peoples /usr/local/doc entirely libtcc.c : - MEM_DEBUG : IDE-friendly output "file:line: ..." - always ELF for objects tccgen.c : - fix memory leak in new switch code - move static 'in_sizeof' out of function profiling : - define 'static' to empty resolve_sym() : - replace by dlsym() win32/64: fix R_XXX_RELATIVE fixme - was fixed for i386 already in 8e4d64be2fc1d707c7800c5096f6e0ea22cbd - do not -Lsystemdir if compiling to .o
* tccelf: allow multiple declaration of bss/common symbolsgrischka2016-10-011-5/+8
| | | | | | | | | | | | | | also in combination with one initialized: For example 1.c int xxx; 2.c int xxx = 2; 3.c int xxx; tcc 1.c 2.c 3.c