Commit Graph

1320 Commits

Author SHA1 Message Date
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
4b743a7a61 * IsLibrary is a byte-sized boolean, thus use stb instruction to set value
git-svn-id: trunk@19022 -
2011-09-07 21:57:37 +00:00
pierre
958425157f * Try to implement dllprt0 for linux powerpc processor
git-svn-id: trunk@19009 -
2011-09-07 12:53:50 +00:00
florian
b17a9385e5 * use generic first_int_to_real 64 bit values on sparc
* compile part of softfpu into the system unit as consequence of using the generic first_int_to_real

git-svn-id: trunk@18961 -
2011-09-03 19:58:32 +00:00
pierre
f0aa48b083 * Remove use of direct U_UNIT_NAME or TC_UNIT_NAME
symbols in assembler sources.
  Added to corresponding system variables or typed constants a
  public name 'operatingsystem_XXX' alias and used that alias in assembler
  source.

git-svn-id: trunk@18943 -
2011-09-02 12:51:48 +00:00
pierre
1c2a5f9819 + Update all Makefile's modified by
change in utils/fpcm/fpcmake.ini in prevous commit.

  Adapt also other files to that change:

  * compiler/globals.pas: Replace $FPCTARGET by os_string if
  tf_use_8_3 flag is set for target_info also.

  * tests/Makefile.fpc: Modify TEST_TARGETSUFFIX in the same way
  as TARGETSUFFIX was modified in previous commit.

  * tests/utils/dotest.pp:
    + New variable UseOSOnly, set to true if only target OS name
    should be used for subdirectories.

git-svn-id: trunk@18228 -
2011-08-16 20:10:19 +00:00
florian
b5ebe6307f * fix got loading si_c32, resolves #19520 (still uses the call/pop approach because it is faster on modern CPUs)
git-svn-id: trunk@18224 -
2011-08-16 18:45:39 +00:00
marco
39d7bb511d * Regenned all makefiles before 2.6.x branching.
git-svn-id: trunk@18073 -
2011-08-03 13:41:52 +00:00
marco
2c00a2a0b3 * fixed FPC_USE_LIBC building for Linux and exception handling (mantis #13450)
- fixed a platform modifier in ipc.pp
   - fixed different layout sigaction record in libc. (field order)
   - fixed many bad use_libc fixes in linux. Most of these were only checked
      for compilation, not linking. (e.g. futex doesn't link)

git-svn-id: trunk@18042 -
2011-07-31 23:36:17 +00:00
marco
f411f08629 * declared external fpc_geteipasebx , with local suffix to avoid clashes.
Still not the whole potatoe though.
 

git-svn-id: trunk@17682 -
2011-06-07 15:12:31 +00:00
marco
cdb4975530 * killed fpc_geteipbasebx in the startup code, mantis #19504
git-svn-id: trunk@17680 -
2011-06-06 20:26:22 +00:00
marco
f34ffd02c9 * fix for 19114. Deal with empty arguments more graciously by quoting them.
git-svn-id: trunk@17272 -
2011-04-08 14:41:36 +00:00
florian
00768bea47 * fix compilation of dllprt0.as for older arm assemblers without push support
git-svn-id: trunk@17254 -
2011-04-05 19:42:36 +00:00
tom_at_work
b0bd6a13ec Fixed argc/argv/envp for arm/linux shared libraries. They are by default in registers a1/a2/a3 as per ABI: the first arguments when calling a method (in this case the FPC_SHARED_LIB_START) are passed via registers, not on the stack.
git-svn-id: trunk@17033 -
2011-02-27 17:22:29 +00:00
ivost
d4cde5eaa2 * added syscall_nr_futex = 142 for sparc architecture
git-svn-id: trunk@16994 -
2011-02-24 10:51:54 +00:00
tom_at_work
a8bf34d3fc Correctly return to caller in ARM/Linux shared library startup code instead of fall-through to system exit.
git-svn-id: trunk@16982 -
2011-02-23 09:41:19 +00:00
tom_at_work
56d30e7da0 Set up environment variables and call Pascal initialization in arm/linux shared library initialization
git-svn-id: trunk@16981 -
2011-02-22 22:32:44 +00:00
Jonas Maebe
0da9d36116 * fixed internal assembler for x86-64 so that it correctly handles
relocations for addr_pic_no_got references (do not go via the GOT)
  * fixed code generator so that it generates addr_pic_no_got references
    also for platforms that use the internal assembler (this will break linking
    of some tests that check static data > 2GB on Linux/x86-64, but they were
    already broken before as well because we don't use the "huge" x86-64
    execution model)
  * fixed x86-64 Linux syscall code to not expect GOT-based relocations for
    the system unit's errno variable (it's an implementation-only variable)

git-svn-id: trunk@16717 -
2011-01-06 09:28:25 +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
0cb2fa1baf + semtimedop() for Linux, marked as "platform" (last part of patch from
mantis #14075)

git-svn-id: trunk@16339 -
2010-11-13 18:37:43 +00:00
Jonas Maebe
36aa39cc38 o fixed several Linux ipc bugs, based on patch by Ruben Chaer/
Pablo Alfaro (mantis #14075, also fixes #13363):
    * ipc msgtyp is clong, not cint
    * TIPC_Perm and TSEMid_ds are different on 64 bit systems
    * fixed passing semun arguments (have to be passed by value, not reference)
    * fixed the order of parameters to msg* syscalls, and don't use
      TIPC_Kludge for msgrcv syscall (only for ipccall.inc variants)
    * use new operation variants on 64 bit platforms in ipccall.inc
  * introduced use kernel_mode/uid/gid_t types for use by the Linux ipc
    records
  * fixed type of TSEMid_ds.sem_base for Darwin
  * added {$packrecords c} to ipc unit, and {$packrecords 4} around
    certain structs for Darwin as in the C headers
  * fixed passing semun argument to semctl for libc platforms (by
    value, not reference)

git-svn-id: trunk@16336 -
2010-11-13 16:58:23 +00:00
florian
747b93b7ec + cpu unit for x86-64 containing a CAS128 implementation
git-svn-id: trunk@16284 -
2010-11-01 08:20:31 +00:00
tom_at_work
5f3aaf1e60 * minor changes to the startup code: use exit_group syscall to exit, minor cleanup
* add _haltproc symbol to shared library startup code

git-svn-id: trunk@16258 -
2010-10-29 19:58:51 +00:00
tom_at_work
7f9dedec99 Moved global variables from .text section to .bss in ppc/linux startup code, improves position independency
git-svn-id: trunk@16210 -
2010-10-23 20:07:36 +00:00
tom_at_work
9a969c18cd Startup files fixes for ppc/ppc64
* startup code in c/g/prt0.as does not contain .text references anymore
* fixed shared library startup code for ppc64: startup and shutdown code is properly called, making the tlibrary2 test succeed now

git-svn-id: trunk@16199 -
2010-10-22 23:19:23 +00:00
daniel
3307d98c40 - Revert micro-exe mode for now.
git-svn-id: trunk@16170 -
2010-10-15 16:49:48 +00:00
daniel
2139a229d3 + If no unit is used, no symbol inside the system unit is used,
and no language features requiring initialization are used,
    do not initialize units, but just configure the fpu and
    signal handlers.

git-svn-id: trunk@16124 -
2010-10-10 17:40:39 +00:00
daniel
f4ec65add8 - Remove unused variable fpustate.
git-svn-id: trunk@16123 -
2010-10-10 15:09:05 +00:00
mazen
b127fc154a * Fixed spell error revealed by lintian.
git-svn-id: trunk@16094 -
2010-10-06 20:33:57 +00:00
Jonas Maebe
eda7a8d672 * replaced the "quick exit" instruction sequences from the syscall variants
lacking "nostackframe" with branches to an exit label, because in that
    case the compiler-generated exit code must be executed to balance the
    stack (only done for EABI; should probably also be done for OABI, but
    I can't test that)

git-svn-id: trunk@16073 -
2010-10-01 15:06:57 +00:00
Jonas Maebe
8b0301409a + i386/iphonesim target for the new iPhoneSimulator in Xcode 3.2.4 and
later: the same as i386/darwin, except
      a) uses the non-fragile Objective-C ABI/runtime
      b) does not require stubs for direct calls/jumps (not required for
         i386/darwin under 10.6 and later either, but still generated
         there for backwards compatibility)
      c) only the same packages are enabled as for ARM/Darwin
      d) MacOSAll is compiled specifically for the iPhoneSimulator SDK
    This target also defines the symbol "darwin" apart from the target
    name "iphonesim" for source code compatibility reasons.

git-svn-id: trunk@16065 -
2010-09-29 21:56:47 +00:00
Jonas Maebe
84cc38f4af * moved {$asmmode att} to top of file (mantis #17377)
git-svn-id: trunk@15961 -
2010-09-09 19:46:59 +00:00
florian
ac51f535ae * support of data > 2 GB on x86_64-linux with PIC by picifing the startup code, resolves #17236
* fixed some small issues in the startup files

git-svn-id: trunk@15907 -
2010-08-25 19:43:29 +00:00
Jonas Maebe
d8032f6366 - disabled modify_ldt for non-x86 platforms, since it does not exist there
(mantis #17100)
  * also use a syscall to call modify_ldt when FPC_USE_LIBC is defined,
    because it's not exported as a function from libc

git-svn-id: trunk@15838 -
2010-08-17 21:34:09 +00:00
florian
7dc4b6ecc1 + adds mcount calls to syscall assembler helpers for i386 and x86-64, resolves #17140
git-svn-id: trunk@15812 -
2010-08-15 09:11:06 +00:00
daniel
da77c0c190 + Add libc version of futex
git-svn-id: trunk@15811 -
2010-08-14 19:34:05 +00:00
daniel
6f2b097d63 + Add futex
git-svn-id: trunk@15747 -
2010-08-08 14:24:46 +00:00
florian
786c4e206f * enables compilation of iso7185 unit on all targets
git-svn-id: trunk@15730 -
2010-08-06 17:45:42 +00:00
daniel
1009a84e25 + Add modify_ldt to linux unit
+ Add sched_yield to linux unit
  - Remove clone for m68k from linux unit (unimplemented assembler section)
  + Add fpsigtimedwait to baseunix unit

git-svn-id: trunk@15602 -
2010-07-18 21:53:26 +00:00
joost
3e165e2dcf * Fixed compilation on Linux after r15557
git-svn-id: trunk@15560 -
2010-07-12 21:38:55 +00:00
florian
3668be7ee4 * minimal implementation by Benjamin 'BeRo' Rosseaux
git-svn-id: trunk@15484 -
2010-06-27 11:07:35 +00:00
florian
5692c9e787 * tabs by spaces replaced
git-svn-id: trunk@15483 -
2010-06-27 11:04:27 +00:00
micha
87ef559542 * rtl: fix i386-linux uclibc atexit functionality (call exit instead of _exit)
git-svn-id: trunk@15110 -
2010-04-03 13:18:10 +00:00
marco
30207d73ea * epoll_oneshot constant, mantis 15732
git-svn-id: trunk@14931 -
2010-02-20 22:24:01 +00:00
Jonas Maebe
d2a7a4c627 * fixed signal return trampolines for ARM EABI (mantis #15803)
git-svn-id: trunk@14922 -
2010-02-18 20:53:28 +00:00
marco
b8d5a8f44c * Linux specific time_t fixes. Also tested with -dFPC_USE_LIBC and more problem fixed.
git-svn-id: trunk@14586 -
2010-01-09 22:02:36 +00:00
marco
5d87461507 * moves the alias "TTime = time_t" from ptypes.inc to unixtype.pp.
This means it is not aliased in the body of the system unit (which causes
  trouble with the delphi type of the same name), but baseunix/unix/unixtype
  will containue to export the type.

git-svn-id: trunk@14584 -
2010-01-09 16:05:42 +00:00
florian
1d1e62fcd0 * .lpi version update
git-svn-id: trunk@14522 -
2010-01-02 15:54:39 +00:00
florian
b42b96752c * linux rtl contains target cpu specific files
git-svn-id: trunk@14480 -
2009-12-26 20:41:26 +00:00
florian
9e59c6dec7 * more mipsel code
git-svn-id: trunk@14340 -
2009-12-06 12:12:15 +00:00