Commit Graph

157 Commits

Author SHA1 Message Date
Jonas Maebe
05f6660a25 * set the correct dynamic linker for the ppc64 ELFv2 abi
* specify the correct linker emulation to use for ppc64 ELFv2 little endian
  * specify the correct default library directories to search for ELFv2 little
    endian

git-svn-id: trunk@30194 -
2015-03-14 18:35:19 +00:00
Jonas Maebe
3946971c73 * default to ppc64le/elfv2 when compiling on a ppc64le platform
* default to elfv2 abi when targeting ppc64le and no abi has been specified

git-svn-id: trunk@30193 -
2015-03-14 18:35:16 +00:00
marco
1b85962ef3 * put default libgcc path under if Dontlinkstdlibpath...
git-svn-id: trunk@29447 -
2015-01-12 10:34:39 +00:00
sergei
15ff2c1236 * m68k: Fixed name of ELF interpreter, and updated cprt0.as to somewhat working state. Now a "hello world" program using libc can be linked and launched, but anything more complex needs another round of fixing the parameter passing code, in order to get the stack properly balanced.
git-svn-id: trunk@28181 -
2014-07-07 20:08:50 +00:00
Jonas Maebe
ca446b4b2a - removed registration of x86_6432 target because it's not supported in any
way by the compiler (and furthermore it would have to be registerd in an
    the x86_64 compiler binary, not an i386 one) (mantis #25525)

git-svn-id: trunk@26460 -
2014-01-14 20:37:18 +00:00
florian
c357212b45 + search crt* files also in /usr/lib/x86_64-linux-gnu, multiarch supporting distros require this
git-svn-id: trunk@26158 -
2013-12-01 15:39:05 +00:00
sergei
38058505ba * Changed linking infrastructure to look like assembler one:
* Changed direct references to linker classes in TSystemInfo records to enumerated ids.
  * RegisterExtennalLinker and RegisterInternalLinker procedures replaced by single RegisterLinker procedure and moved to link.pas.
  - TAbstractLinker is no longer necessary, removed.

This change allows to register linker once per id, rather than once per target, and also allows TSystemInfo records to be read-only.

git-svn-id: trunk@25279 -
2013-08-18 12:01:21 +00:00
sergei
eec8129738 * TInternalLinker.Load_ReadStaticLibrary: exit if error has occurred while opening a static library or dynamic object, continuing can cause other errors/crashes in this case.
* t_linux.pas: use sysrootpath when specifying dynamic interpreter (for cross-linking).

git-svn-id: trunk@25277 -
2013-08-18 09:14:16 +00:00
sergei
1f8a67f552 + Property TObjSymbol.ObjData, allows to access owning TObjData for external/common symbols, i.e. ones with ObjSection=nil.
* For common symbols, report objdata of the original ObjSymbol, not of the resolving one, so the map file shows where it comes from.
+ TElfExeOutput.OrderOrphanSections method, handles object sections not mentioned in script similar to ld.
- t_linux.pas: removed sections that are not part of ld scripts, they are now handled by OrderOrphanSections.

git-svn-id: trunk@25184 -
2013-07-30 09:23:48 +00:00
sergei
dddc78514d * Internal ELF linker: for MIPS targets, place .got section after .data. This corresponds to behavior of ld, and reduces amount of processing when adding GOT slots for local symbols (which requires re-doing layout for all sections that come after .got)
git-svn-id: trunk@25154 -
2013-07-21 13:10:57 +00:00
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