What's the difference lazarus / 21-General ---------------------------------------------------------------------- freemind001 · 2023-04-29 07:54 between FpExit(0) and Halt(0) in linux? ---------------------------------------------------------------------- marcov · 2023-04-29 12:03 HALT will probably do fpexit(0) eventually, but will run unit finalization and exithandlers, which can be useful for flushing logs and the like. ---------------------------------------------------------------------- Warfley · 2023-04-29 12:41 As far as I know when calling Halt, somewhere down the line the System_exit will be called, which may or may not (depending on the platform) call fpexit, which itself calls the underlying libc functionality. I think in Linux this is not necessarily the case, because you can write Linux programs that do not link against the libc from looking into the code it links against an "_haltproc", but don't know what exactly that is. But for you as a user, it's better to use Halt, because it is 1. cross plattform, and so not linux specific code and 2., may do additional pascal specific stuff and 3. might not need to link against the libc ---------------------------------------------------------------------- marcov · 2023-04-29 12:51 Quote from: Warfley on April 29, 2023, 02:41:23 pmAs far as I know when calling Halt, somewhere down the line the System_exit will be called, which may or may not (depending on the platform) call fpexit, which itself calls the underlying libc functionality. _haltproc is defined in the startup code. The glibc linking version calls the glibc exit , the uclibc calls the uclibs exit, and the standalone version (prt) calls a FPC exit handler. After those respective exit handlers it calls the kernel EXIT syscall  in all cases, this is afaik a structure that is copied from the startup code. The exit in the startup code might only be a security, I don't suspect those exists to return. ---------------------------------------------------------------------- sketch · 2023-04-29 15:07 Code: [Select]procedure FpExit(status:longint);cdecl;external libc_nlm name '_exit'; procedure haltproc(e:longint);cdecl;external name '_haltproc'; Both are using an external C function. The external directive tells the compiler that the function resides in an external object file or library with the '_exit' or '_haltproc' name. Linux man 2 exit Quote       _exit() terminates the calling process "immediately".  Any open        file descriptors belonging to the process are closed.  Any        children of the process are inherited by init(1) (or by the        nearest "subreaper" process as defined through the use of the        prctl(2) PR_SET_CHILD_SUBREAPER operation).  The process's parent        is sent a SIGCHLD signal.        The value status & 0xFF is returned to the parent process as the        process's exit status, and can be collected by the parent using        one of the wait(2) family of calls. And in gprt0.as Code: [Select]_haltproc:         movq    operatingsystem_result@GOTPCREL(%rip),%rax         movzwl  (%rax),%eax        /* return to libc */         movq    ___fpc_ret_rbp@GOTPCREL(%rip),%rcx         movq    (%rcx),%rbp         movq    ___fpc_ret@GOTPCREL(%rip),%rcx         popq    %rdx         movq    (%rcx),%rdx         pushq    %rdx         ret         .size   _haltproc,.-_haltproc operatingsystem_result@GOTPCREL(%rip) is the GOT entry for the symbol operatingsystem_result, accessed with a RIP-relative addressing mode. The GOT entry is filled in by the dynamic linker (supporting symbol interposition), and holds the absolute address of the symbol operatingsystem_result, so mov operatingsystem_result@GOTPCREL(%rip), %rax loads &operatingsystem_result into RAX. ---------------------------------------------------------------------- marcov · 2023-04-29 15:13 gprt is only used for gmon profiling. the si_*.inc pascal files are the actually used runtime. ---------------------------------------------------------------------- PascalDragon · 2023-05-01 19:43 Quote from: sketch on April 29, 2023, 05:07:57 pmCode: [Select]procedure FpExit(status:longint);cdecl;external libc_nlm name '_exit'; procedure haltproc(e:longint);cdecl;external name '_haltproc'; Both are using an external C function. external name does not necessarily mean a C function. As you see in the code you posted below it can be an assembly function or any binary code that provides a suitable symbol.