Commit Graph

147 Commits

Author SHA1 Message Date
Jonas Maebe
b16677a75b * only pass --gc-sections to the linker if smart linking is enabled
(mantis #24396)

git-svn-id: trunk@24465 -
2013-05-07 20:28:54 +00:00
florian
7511968f2b + warn if one of the linux libc startup code files is not found
git-svn-id: trunk@23892 -
2013-03-17 14:51:19 +00:00
sergei
af4935e346 + Support dynamic copy relocations.
* For unresolved weak symbols, provide dynamic binding only if they are referenced via GOT or PLT (ld-compatible behavior).
* Made more TElfExeOutput properties/methods usable by descendant classes.
* x86_64/cpuelf.pas: some refactoring, handle DTPOFF relocations, prohibit TPOFF relocations in shared objects.
* i386/cpuelf.pas: set symref_from_text flags for copy relocations to work correctly.

git-svn-id: trunk@23375 -
2013-01-13 17:44:14 +00:00
sergei
b197919953 * Handle relocation section prefixes (.rel/.rela) in internal linker script based on ElfTarget.relocs_use_addend, getting rid of $ifdef's.
+ Linker script adjustments for ARM target.

git-svn-id: trunk@23338 -
2013-01-07 15:13:05 +00:00
sergei
0196c62ee8 + Initial work to support versions of ELF dynamic symbols.
git-svn-id: trunk@23170 -
2012-12-18 08:25:57 +00:00
sergei
a7e7d97da6 * ELF linker: fixed written values of STT_TLS symbols, they must be relative to PT_TLS segment address.
* Made name of dynamic interpreter variable, it is now set correctly for each target.
- Removed setting header flags for ARM. This functionality belongs to CPU-specific unit anyway, and probably must be implemented using object attributes in modern ABIs.

git-svn-id: trunk@23032 -
2012-11-19 09:07:45 +00:00
sergei
49501413e1 + Support library grouping in internal linker script, use it to load C libraries.
git-svn-id: trunk@22962 -
2012-11-09 14:38:11 +00:00
sergei
f94ba86bb9 * ModulesLinkToLibc: another fix. We also have to look in ImportLibraryList because items contained there aren't yet merged into linkothersharedlibs when this function is called.
git-svn-id: trunk@22831 -
2012-10-23 14:51:35 +00:00
sergei
6d70009f06 + ELF linker. Works on x86_64-linux and i386-linux good enough to pass the testsuite, but still requires a lot of work in nearly all aspects. In particular, no attempt to resolve symbols from shared libs is done, everything is just treated as imports. Symbol versioning isn't supported either.
x86_64 is the most elaborated, has some degree of indirect function (GNU_IFUNC) and TLS support, so it is even able to link with static libc/pthreads code (tw14265) and produce an executable that can launch (but still fails due to invalid DWARF unwind info).

i386 produces working shared libraries if they are compiled with -Cg, without one your mileage may vary. tw14265 does not link yet due to missing COMDAT group support.

git-svn-id: trunk@22775 -
2012-10-19 17:21:08 +00:00
sergei
0e8829e4e2 * ModulesLinkToLibc: Search for both bare and prefixed names of libc. When this function is invoked, import library names are not yet normalized and either one may be present. Failure to detect libc may end up in using wrong sysinit unit, this fortunately affects only i386-linux (other Linux targets aren't using Pascal sysinit units yet).
git-svn-id: trunk@22620 -
2012-10-12 20:47:07 +00:00
tom_at_work
f5ddc02a5c + add debian armel library search path
+ for armhf, use the more canonical ld-linux-armhf.so.3 as defdynlinker

git-svn-id: trunk@22416 -
2012-09-17 21:13:37 +00:00
florian
ad3aa937d3 * respect Dontlinkstdlibpath when adding a default library search path
git-svn-id: trunk@22011 -
2012-08-04 17:29:07 +00:00
florian
2b6fc9b1ee + at least raspian has no soft links in /usr/lib to crt*.o, so add their location to the search path
git-svn-id: trunk@22004 -
2012-08-04 08:16:02 +00:00
sergei
2638bc01d9 * Fixed error introduced in r21732. For libraries, startup is always dllprt0.o, regardless of profiling/linking to libc. Mantis #22397.
git-svn-id: trunk@21824 -
2012-07-09 12:18:34 +00:00
sergei
32e399159f * Factored common parts that can be/should be reused in the internal linker.
git-svn-id: trunk@21732 -
2012-06-28 20:21:17 +00:00
pierre
600dd162af Merge of rev21557 by Foxsen
Make macro MIPS/CPUMIPS/MIPS32 common for big endian and little endian mips processors
use MIPSEL* for little endian systems
use MIPSEB* for big endian systems

git-svn-id: trunk@21599 -
2012-06-13 22:25:38 +00:00
Jonas Maebe
c27f9da1b2 * always surround ld link.res SEARCH_DIR() arguments with double quotes,
rather than with single/double quotes depending on the target platform
    (ld only supports double quotes), and rather than only quoting when
    necessary (wastes time since quotes are always allowed, and double
    quotes inside a directory name cannot be escaped for ld; they are
    simply not supported by the program) (mantis #22059, follow-up to
    r21069 and r21208)

git-svn-id: trunk@21343 -
2012-05-20 13:30:51 +00:00
Jonas Maebe
0841ee6e4f * GNU ld only supports double quotes in its response file -> requote there
as well under Unix (mantis #21928, caused by r21069)

git-svn-id: trunk@21208 -
2012-05-03 12:41:16 +00:00
Jonas Maebe
14cfe770a4 * replaced most (if not all) remaining fields/parameters in the compiler
that deal with paths/filenames with TPathStr (= ansistring) to prevent
    cutting off long paths (no change in speed when compiling the compiler,
    1% extra memory usage)

git-svn-id: trunk@21120 -
2012-04-29 17:36:23 +00:00
Jonas Maebe
6ba8dc7146 + support for the ARM hard float EABI on Linux (patch by Peter Green):
o new eabihf (hard float) abi
   o vfpv3_d16 variant of VFP (default variant used by EABI assemblers: VFPv3
     with only 16 double registers instead of 32) and pass it to GNU as
   o make the odd numbered single precision floating point VFP registers
     available for explicit allocation for use by the calling convention
  * fixed copy/paste error in stdname of S30 register
  -> use -dFPC_ARMHF to create an ARM eabi hard float compiler
  (mantis #21554)

git-svn-id: trunk@20660 -
2012-03-29 20:50:09 +00:00
tom_at_work
9ce34c63c9 Fix shared library loading and unloading for Linux platforms. Shared library initialization and finalization are now called correctly at program startup for compile-time linked dynamic libraries on powerpc-/powerpc64-/arm-/i386- and x86_64-linux.
Every startup code must now provide an additional entry point called "_dynamic_start" that is set as new the entry point if the program links to a Pascal shared library. Its purpose is to set up an exit hook usually passed via a register, which should be called during program finalization if non-nil.

We use this additional entry point because this register only has meaningful content when there are any compile-time linked shared libraries, otherwise it often contains random garbage. The difference between the _dynamic_start and the original code is minimal; actually in all implementations the _dynamic_start code passes on control to the old startup code, so we use an additional entry point instead of an additional startup file.

Detailed changes and fixes list:
compiler:
  always link to the dynamic loader (ld.so) when compiling shared libraries. Fixes crashes in the loader during shared library finalization on some Linuxes
  remove additional ENTRY() section in arm linker script
  select either _dynamic_start or _start as entry point depending on whether this is a static or dynamic executable
powerpc*:
  do not set System.isLibrary in startup code, it will be set during library initialization anyway
  trap in case of reaching code locations that should not be reached instead of looping (possibly endlessly)
powerpc:
  register atexit() function pointer if supplied to the executable and call it during shutdown
  correctly set argc/argv/envp in shared library code and return correctly to the caller after initialization
  pass on exitcode in shared library haltproc
  use the more recent exit_group system call if available for shutdown
powerpc64
  fix .ptrgl stub, do not set the environment register to the value of the GOT entry in the function descriptor
arm
  do not set System.isLibrary in startup code, it will be set during library initialization anyway
  reload exitcode to pass to shutdown
mips,mipsel,sparc
  added stubs to allow correct linking

git-svn-id: trunk@19036 -
2011-09-08 21:17:35 +00:00
pierre
3cc2b5e97b + Added default dynamic linker for mips CPU
git-svn-id: trunk@17889 -
2011-07-01 07:37:05 +00:00
Jonas Maebe
78c3e6b359 * always use crtbeginS.o/crtendS.o when generating PIC code, not just when
generating libraries for x86_64 (at least all Linux systems I checked
    have the S-variants of those files) (mantis #19501)

git-svn-id: trunk@17713 -
2011-06-10 14:17:20 +00:00
Jonas Maebe
1f61b5b30c * reverted the rtl patches from r14184, because they cause an endless
loop when attempting to terminate a process via the RTL compiled into
    a Linux shared library  (mantis #17383)
  * call FPC_LIB_EXIT (the internal/generic RTL finalisation routine) instead
    of FPC_SHARED_LIB_EXIT (the Linux-specific "process exit" code for shared
    libraries) as "fini" routine (fixes #14958 again after reverting r14184)

git-svn-id: trunk@16418 -
2010-11-24 15:33:29 +00:00
Jonas Maebe
356026f849 * use new_section() instead of tai_section.create() everywhere
- sort of reverted r14134, which is no longer required after the above
    change (new_section() inserts the alignment itself)
  * made the tai_section.create() constructor private so it cannot be
    called directly anymore

git-svn-id: trunk@15482 -
2010-06-26 10:50:14 +00:00
florian
c1f3d8dcaa * unified names of system_*/systems_* sets
git-svn-id: trunk@14566 -
2010-01-07 18:16:20 +00:00
florian
ee504ce31f * fixes fullcycle
git-svn-id: trunk@14373 -
2009-12-08 20:12:05 +00:00
florian
9e59c6dec7 * more mipsel code
git-svn-id: trunk@14340 -
2009-12-06 12:12:15 +00:00
florian
28ac4a8dda * several mips/mipsel related stuff fixed
* regenerated linux makefile to support mipsel

git-svn-id: trunk@14278 -
2009-11-27 15:10:56 +00:00
florian
44c6ff898b * mipsel compiler builds
git-svn-id: trunk@14249 -
2009-11-21 22:17:34 +00:00
florian
f54365db94 * adapted more fpc-mips stuff to trunk
git-svn-id: trunk@14230 -
2009-11-20 21:13:53 +00:00
Jonas Maebe
92ff07deaf * several fixes by Pierre Pede (parts of his patch to mantis #12492)
o fixed gprof under linux/i386
    o fixed pic-compilation of the linux/i386 rtl
    o initialisation of linux shared libraries is now possible with pic-code

git-svn-id: trunk@13703 -
2009-09-12 21:57:41 +00:00
Jonas Maebe
84cefb5eba * fixed dynamic linking of programs that only link with libc after r13584
git-svn-id: trunk@13587 -
2009-08-23 16:05:59 +00:00
Jonas Maebe
9a84dee059 * fixed static linking under Linux for ppc64; test still crashes under
linux/i386 and linux/x86_64 (but at least it links now, mantis #14265)

git-svn-id: trunk@13584 -
2009-08-23 11:53:00 +00:00
Jonas Maebe
5eb7a398e0 * add SIZEOF_HEADERS to the start address of the text section for ARMEL
(fix by thexception, mantis #14100)
  * changed hardcoded "+0x100" for the default linker script also into
    "+ SIZEOF_HEADERS"

git-svn-id: trunk@13418 -
2009-07-20 09:20:02 +00:00
florian
8f95bb12ac * fixed shared linker name for i386
* restored old shared linker search order as good as possible

git-svn-id: trunk@11558 -
2008-08-12 16:45:07 +00:00
florian
fe92758e53 * use ld-linux.so.3 in armel mode
git-svn-id: trunk@11150 -
2008-06-01 10:25:04 +00:00
florian
bcbc221191 * more reasonable defaults when no dyn. linker is found, resolves #10431
git-svn-id: trunk@11020 -
2008-05-20 21:06:12 +00:00
Jonas Maebe
99e1e85447 * fixed execution of finalization section of smart linked shared
libraries on linux (mantis #6822)
  * fixed execution of library finalization sections on darwin
    (previously only the finalization section of the library
     compilation unit itself was executed, now those of the units
     used by the library are also executed)

git-svn-id: trunk@10554 -
2008-03-24 22:19:21 +00:00
Jonas Maebe
150eda304b * factored unix exports handling from t_bsd and t_linux into expunix unit
(todo: at least solaris, maybe others)
  * changed the "exports" section handling:
    a) make everything private which is not exported (implemented for
       darwin and linux)
    b) for the exported symbols:
     - functions/procedures
      1) if no name or index is provided, and if the procedure has aliases
         defined via the public/export directives, then export the default
         mangled name and all defined aliases
      2) otherwise if no name is specified (but there is an index) then
        i) if the procedure is defined as cdecl/cppdecl/mwpascal, use the
           appropriately mangled version of the function name
       ii) otherwise export the name without any mangling(e.g. "exports
           proc1" -> proc1 is the exported name)
     - variables
      1) if no name is provided and the variable was specified as cvar,
         use the mangled name
      2) otherwise if no name is provided, export the name without any
         mangling
  -> initialization/finalization of shared libraries under Linux works
     again (mantis #7838)
  -> sharing symbols between shared library and main program works
     under Linux (mantis #9089)

git-svn-id: trunk@10551 -
2008-03-24 16:55:05 +00:00
Jonas Maebe
3eec0569be * fixed shared library initialisation for FPC-compiled libraries
when linked to FPC-compiled programs under linux/i386 which
    do not use libc + test (mantis #8730). Programs which do use
    libc and other linux targets have to be fixed in a similar
    way until we properly fix everything by not exporting
    any symbols at all from shared libraries by default (and
    only those appearing in the "exports" section).

    Finalisation does not work yet either for FPC-compiled
    programs on linux/anything.

git-svn-id: trunk@10495 -
2008-03-15 23:28:09 +00:00
michael
174de3eab1 Merged revisions 9693-10480 via svnmerge from
svn+ssh://svn.freepascal.org/FPC/svn/fpc/branches/resources

........
  r9694 | michael | 2008-01-09 21:31:18 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * Initial check-in
........
  r9695 | michael | 2008-01-09 21:35:58 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * New version from Giulio Bernardi
........
  r9697 | michael | 2008-01-09 21:41:54 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * Patch from Giulio Bernardi with resource support
........
  r9698 | michael | 2008-01-09 21:46:33 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * Patch from Giulio Bernardi to add more resource testing
........
  r9699 | michael | 2008-01-09 21:57:26 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * New tool from Giulio Bernardi
........
  r9700 | michael | 2008-01-09 21:58:23 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * New tool from Giulio Bernardi
........
  r9701 | michael | 2008-01-09 22:01:54 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * Added fcl-res
........
  r9702 | michael | 2008-01-09 22:01:58 +0100 (Wed, 09 Jan 2008) | 1 line
  
  * Added fcl-res
........
  r9703 | michael | 2008-01-10 08:54:26 +0100 (Thu, 10 Jan 2008) | 1 line
  
  * Fixed double code
........
  r9704 | jonas | 2008-01-10 10:59:20 +0100 (Thu, 10 Jan 2008) | 2 lines
  
    - removed duplicate code
........
  r9705 | jonas | 2008-01-10 11:25:21 +0100 (Thu, 10 Jan 2008) | 2 lines
  
    + added missing fcl-res dependencies
........
  r9706 | jonas | 2008-01-10 11:58:30 +0100 (Thu, 10 Jan 2008) | 2 lines
  
    + dependencies for fpintres and fpextres
........
  r9707 | yury | 2008-01-10 12:47:51 +0100 (Thu, 10 Jan 2008) | 3 lines
  
  * Fixed compilation of resource, which is included in a unit located in different folder than main source.
  * .res files must be copied to units output folder, otherwise .res files will not be found when only compiled units path is available and compiler does not know anything about sources folder.
  * Improved resource related error messages.
........
  r9708 | michael | 2008-01-10 12:52:13 +0100 (Thu, 10 Jan 2008) | 1 line
  
  * Removed double source after end.
........
  r9709 | michael | 2008-01-10 12:52:48 +0100 (Thu, 10 Jan 2008) | 1 line
  
  * No longer needed
........
  r9710 | tom_at_work | 2008-01-10 22:09:08 +0100 (Thu, 10 Jan 2008) | 1 line
  
  * properly align FPC_RESLOCATION so that linking does not fail on some architectures (e.g. ppc64)
........
  r9711 | tom_at_work | 2008-01-10 23:53:12 +0100 (Thu, 10 Jan 2008) | 1 line
  
  * fix splitting of 64 bit load/stores from/to unaligned memory locations into multiple load/stores, which in some cases generated wrong code
........
  r9712 | michael | 2008-01-11 11:00:08 +0100 (Fri, 11 Jan 2008) | 1 line
  
  * Fixed bug in BSS section on 64-bit platforms
........
  r9720 | giulio | 2008-01-12 10:02:04 +0100 (Sat, 12 Jan 2008) | 1 line
  
  Updated fcl-res documentation: occurrences of reslib changed to fcl-res.
........
  r9740 | giulio | 2008-01-13 19:36:44 +0100 (Sun, 13 Jan 2008) | 3 lines
  
   - Don't try to compile resources on systems with a non windows-like resource support.
   - Don't add the .or file to the list of object files if resource compiling failed.
........
  r10201 | giulio | 2008-02-04 11:35:44 +0100 (Mon, 04 Feb 2008) | 5 lines
  
  * resource compiling supported on OS/2 via wrc
  * CompileResourceFiles and CollectResourceFiles don't do target-specific checks anymore
  * refactored a bit
........
  r10389 | giulio | 2008-02-25 21:32:52 +0100 (Mon, 25 Feb 2008) | 2 lines
  
  Deleted test file which was committed by mistake
........
  r10472 | giulio | 2008-03-10 12:22:18 +0100 (Mon, 10 Mar 2008) | 2 lines
  
  changed define FPC_HAS_RESOURCES to FPC_HAS_WINLIKERESOURCES
........

git-svn-id: trunk@10481 -
2008-03-12 21:33:48 +00:00
peter
de918497ef * support -Xg under linux
git-svn-id: trunk@9811 -
2008-01-20 12:12:15 +00:00
florian
8a2ab85bc2 + armel support with FPC_ARMEL define
+ armel linker script

git-svn-id: trunk@9156 -
2007-11-07 20:45:27 +00:00
florian
3a630340be * fixed m68k compilation and put it in fullcycle
git-svn-id: trunk@8953 -
2007-10-27 11:24:50 +00:00
micha
89b5825029 * only use ld -T in case of cross-link (-XR), because not all platforms have complete link script yet
git-svn-id: trunk@8718 -
2007-10-01 21:10:51 +00:00
peter
9f0ca44c94 * new tf_smartlink_library flag
* use create_smartlink[_sections|_library] to check what to 
    do for smartlinking

git-svn-id: trunk@8715 -
2007-10-01 16:55:08 +00:00
micha
c3e587355d * fix default dynamic linker location for 64 bit targets in linux
git-svn-id: trunk@8707 -
2007-09-30 21:20:04 +00:00
florian
655ac519d4 * fixed compilation for x86-64
git-svn-id: trunk@8698 -
2007-09-30 15:30:00 +00:00
micha
0625040eba + add -XR switch for target root file system with libs (also used for C lib type detection)
git-svn-id: trunk@8695 -
2007-09-30 15:00:54 +00:00