Browse Source

* merged the OpenBSD 6.5 fixes

git-svn-id: branches/fixes_3_2@42213 -
nickysn 6 years ago
parent
commit
783273cf01

+ 0 - 2
.gitattributes

@@ -10143,7 +10143,6 @@ rtl/openbsd/Makefile.fpc svneol=native#text/plain
 rtl/openbsd/errno.inc svneol=native#text/plain
 rtl/openbsd/errno.inc svneol=native#text/plain
 rtl/openbsd/errnostr.inc svneol=native#text/plain
 rtl/openbsd/errnostr.inc svneol=native#text/plain
 rtl/openbsd/i386/bsyscall.inc svneol=native#text/plain
 rtl/openbsd/i386/bsyscall.inc svneol=native#text/plain
-rtl/openbsd/i386/cprt0.as svneol=native#text/plain
 rtl/openbsd/i386/openbsd_ident.inc svneol=native#text/plain
 rtl/openbsd/i386/openbsd_ident.inc svneol=native#text/plain
 rtl/openbsd/i386/prt0.as svneol=native#text/plain
 rtl/openbsd/i386/prt0.as svneol=native#text/plain
 rtl/openbsd/i386/si_c.inc svneol=native#text/plain
 rtl/openbsd/i386/si_c.inc svneol=native#text/plain
@@ -10178,7 +10177,6 @@ rtl/openbsd/unxconst.inc svneol=native#text/plain
 rtl/openbsd/unxfunc.inc svneol=native#text/plain
 rtl/openbsd/unxfunc.inc svneol=native#text/plain
 rtl/openbsd/unxsysc.inc svneol=native#text/plain
 rtl/openbsd/unxsysc.inc svneol=native#text/plain
 rtl/openbsd/x86_64/bsyscall.inc svneol=native#text/plain
 rtl/openbsd/x86_64/bsyscall.inc svneol=native#text/plain
-rtl/openbsd/x86_64/cprt0.as svneol=native#text/plain
 rtl/openbsd/x86_64/openbsd_ident.inc svneol=native#text/plain
 rtl/openbsd/x86_64/openbsd_ident.inc svneol=native#text/plain
 rtl/openbsd/x86_64/prt0.as svneol=native#text/plain
 rtl/openbsd/x86_64/prt0.as svneol=native#text/plain
 rtl/openbsd/x86_64/si_c.inc svneol=native#text/plain
 rtl/openbsd/x86_64/si_c.inc svneol=native#text/plain

+ 9 - 1
compiler/cfileutl.pas

@@ -1284,8 +1284,16 @@ end;
 
 
 
 
    function  FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
    function  FindExe(const bin:TCmdStr;allowcache:boolean;var foundfile:TCmdStr):boolean;
+     var
+       b : TCmdStr;
      begin
      begin
-       FindExe:=FindFileInExeLocations(ChangeFileExt(bin,source_info.exeext),allowcache,foundfile);
+       { change extension only on platforms that use an exe extension, otherwise on OpenBSD
+         'ld.bfd' gets converted to 'ld' }
+       if source_info.exeext<>'' then
+         b:=ChangeFileExt(bin,source_info.exeext)
+       else
+         b:=bin;
+       FindExe:=FindFileInExeLocations(b,allowcache,foundfile);
      end;
      end;
 
 
 
 

+ 12 - 2
compiler/link.pas

@@ -667,10 +667,20 @@ Implementation
         if cs_link_on_target in current_settings.globalswitches then
         if cs_link_on_target in current_settings.globalswitches then
           begin
           begin
             { If linking on target, don't add any path PM }
             { If linking on target, don't add any path PM }
-            FindUtil:=ChangeFileExt(s,target_info.exeext);
+            { change extension only on platforms that use an exe extension, otherwise on OpenBSD 'ld.bfd' gets
+              converted to 'ld' }
+            if target_info.exeext<>'' then
+              FindUtil:=ChangeFileExt(s,target_info.exeext)
+            else
+              FindUtil:=s;
             exit;
             exit;
           end;
           end;
-        UtilExe:=ChangeFileExt(s,source_info.exeext);
+        { change extension only on platforms that use an exe extension, otherwise on OpenBSD 'ld.bfd' gets converted
+          to 'ld' }
+        if source_info.exeext<>'' then
+          UtilExe:=ChangeFileExt(s,source_info.exeext)
+        else
+          UtilExe:=s;
         FoundBin:='';
         FoundBin:='';
         Found:=false;
         Found:=false;
         if utilsdirectory<>'' then
         if utilsdirectory<>'' then

+ 12 - 8
compiler/systems/t_bsd.pas

@@ -164,7 +164,11 @@ procedure TLinkerBSD.SetDefaultInfo;
 {
 {
   This will also detect which libc version will be used
   This will also detect which libc version will be used
 }
 }
+var
+  LdProgram: string='ld';
 begin
 begin
+  if target_info.system in systems_openbsd then
+    LdProgram:='ld.bfd';
   LibrarySuffix:=' ';
   LibrarySuffix:=' ';
   LdSupportsNoResponseFile := (target_info.system in ([system_m68k_netbsd]+systems_darwin));
   LdSupportsNoResponseFile := (target_info.system in ([system_m68k_netbsd]+systems_darwin));
   with Info do
   with Info do
@@ -173,8 +177,8 @@ begin
        begin
        begin
          if not(target_info.system in systems_darwin) then
          if not(target_info.system in systems_darwin) then
            begin
            begin
-             ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE $CATRES $FILELIST';
-             DllCmd[1]:='ld $TARGET $EMUL $OPT $MAP -shared -L. -o $EXE $CATRES $FILELIST'
+             ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE $CATRES $FILELIST';
+             DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $MAP -shared -L. -o $EXE $CATRES $FILELIST'
            end
            end
          else
          else
            begin
            begin
@@ -193,22 +197,22 @@ begin
                programs with problems that require Valgrind will have more
                programs with problems that require Valgrind will have more
                than 60KB of data (first 4KB of address space is always invalid)
                than 60KB of data (first 4KB of address space is always invalid)
              }
              }
-               ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
+               ExeCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
              if not(cs_gdb_valgrind in current_settings.globalswitches) then
              if not(cs_gdb_valgrind in current_settings.globalswitches) then
                ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
                ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
 {$else ndef cpu64bitaddr}
 {$else ndef cpu64bitaddr}
-             ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
+             ExeCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
 {$endif ndef cpu64bitaddr}
 {$endif ndef cpu64bitaddr}
              if (apptype<>app_bundle) then
              if (apptype<>app_bundle) then
-               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
+               DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
              else
              else
-               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
+               DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
            end
            end
        end
        end
      else
      else
        begin
        begin
-         ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP $MAP -L. -o $EXE $RES';
-         DllCmd[1]:='ld $TARGET $EMUL $OPT $INIT $FINI $SONAME $MAP -shared -L. -o $EXE $RES';
+         ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP $MAP -L. -o $EXE $RES';
+         DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $INIT $FINI $SONAME $MAP -shared -L. -o $EXE $RES';
        end;
        end;
      if not(target_info.system in systems_darwin) then
      if not(target_info.system in systems_darwin) then
        DllCmd[2]:='strip --strip-unneeded $EXE'
        DllCmd[2]:='strip --strip-unneeded $EXE'

+ 2 - 6
rtl/openbsd/Makefile

@@ -347,15 +347,13 @@ ifdef RELEASE
 override FPCOPT+=-Ur
 override FPCOPT+=-Ur
 endif
 endif
 CPU_UNITS=
 CPU_UNITS=
-SYSINIT_UNITS=
-LOADERS=prt0 cprt0
+SYSINIT_UNITS=si_prc si_c si_dll si_g
+LOADERS=prt0
 ifeq ($(ARCH),x86_64)
 ifeq ($(ARCH),x86_64)
 CPU_UNITS=x86 ports cpu
 CPU_UNITS=x86 ports cpu
-SYSINIT_UNITS=si_prc si_c si_dll si_g
 endif
 endif
 ifeq ($(ARCH),i386)
 ifeq ($(ARCH),i386)
 CPU_UNITS=x86 ports cpu mmx
 CPU_UNITS=x86 ports cpu mmx
-SYSINIT_UNITS=si_prc si_c si_dll si_g
 endif
 endif
 OBJPASDIR=$(RTL)/objpas
 OBJPASDIR=$(RTL)/objpas
 GRAPHDIR=$(INC)/graph
 GRAPHDIR=$(INC)/graph
@@ -3183,8 +3181,6 @@ SYSCPUDEPS=$(addprefix $(PROCINC)/,$(CPUINCNAMES))
 SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
 SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
 prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
 prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
 	$(AS) -o $(UNITTARGETDIRPREFIX)prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as
 	$(AS) -o $(UNITTARGETDIRPREFIX)prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as
-cprt0$(OEXT) : $(CPU_TARGET)/cprt0.as
-	$(AS) -o $(UNITTARGETDIRPREFIX)cprt0$(OEXT) $(CPU_TARGET)/cprt0.as
 si_prc$(PPUEXT) : si_prc.pp si_intf.inc si_impl.inc $(ARCH)/openbsd_ident.inc $(ARCH)/si_prc.inc $(SYSTEMUNIT)$(PPUEXT)
 si_prc$(PPUEXT) : si_prc.pp si_intf.inc si_impl.inc $(ARCH)/openbsd_ident.inc $(ARCH)/si_prc.inc $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 	$(COMPILER) $<
 si_c$(PPUEXT) : si_c.pp si_intf.inc si_impl.inc $(ARCH)/openbsd_ident.inc $(ARCH)/si_c.inc $(SYSTEMUNIT)$(PPUEXT)
 si_c$(PPUEXT) : si_c.pp si_intf.inc si_impl.inc $(ARCH)/openbsd_ident.inc $(ARCH)/si_c.inc $(SYSTEMUNIT)$(PPUEXT)

+ 2 - 7
rtl/openbsd/Makefile.fpc

@@ -76,17 +76,15 @@ override FPCOPT+=-Ur
 endif
 endif
 
 
 CPU_UNITS=
 CPU_UNITS=
-SYSINIT_UNITS=
+SYSINIT_UNITS=si_prc si_c si_dll si_g
 
 
-LOADERS=prt0 cprt0
+LOADERS=prt0
 
 
 ifeq ($(ARCH),x86_64)
 ifeq ($(ARCH),x86_64)
 CPU_UNITS=x86 ports cpu
 CPU_UNITS=x86 ports cpu
-SYSINIT_UNITS=si_prc si_c si_dll si_g
 endif
 endif
 ifeq ($(ARCH),i386)
 ifeq ($(ARCH),i386)
 CPU_UNITS=x86 ports cpu mmx
 CPU_UNITS=x86 ports cpu mmx
-SYSINIT_UNITS=si_prc si_c si_dll si_g
 endif
 endif
 
 
 # Paths
 # Paths
@@ -128,9 +126,6 @@ SYSDEPS=$(SYSINCDEPS) $(SYSCPUDEPS)
 prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
 prt0$(OEXT) : $(CPU_TARGET)/$(PRT0).as
         $(AS) -o $(UNITTARGETDIRPREFIX)prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as
         $(AS) -o $(UNITTARGETDIRPREFIX)prt0$(OEXT) $(CPU_TARGET)/$(PRT0).as
 
 
-cprt0$(OEXT) : $(CPU_TARGET)/cprt0.as
-        $(AS) -o $(UNITTARGETDIRPREFIX)cprt0$(OEXT) $(CPU_TARGET)/cprt0.as
-
 
 
 #
 #
 # $(SYSINIT_UNITS) Units
 # $(SYSINIT_UNITS) Units

+ 0 - 206
rtl/openbsd/i386/cprt0.as

@@ -1,206 +0,0 @@
-	.section ".note.openbsd.ident", "a"
-	.p2align 2
-	.long	8
-	.long	4
-	.long	1
-	.ascii "OpenBSD\0"
-	.long	0
-	.previous
-	.file	"crt0.c"
-gcc2_compiled.:
-.data
-	.align 32
-	.type	 rcsid , @object
-	.size	rcsid , 58
-rcsid:
-	.string	"$OpenBSD: crt0.c,v 1.11 2003/06/27 22:30:38 deraadt Exp $"
-.globl __progname
-.section	.rodata
-.LC0:
-	.string	""
-.data
-	.align 4
-	.type	 __progname , @object
-	.size	__progname , 4
-__progname:
-	.long .LC0
-.global __progname_storage
-	.type __progname_storage, @ object
-	.size  __progname_storage, 256
-
-        .align  4
-___fpucw:
-        .long   0x1332
-
-        .globl  ___fpc_brk_addr         /* heap management */
-        .type   ___fpc_brk_addr,@object
-        .size   ___fpc_brk_addr,4
-___fpc_brk_addr:
-        .long   0
-
-#APP
-	
-	.text
-	.align  4
-	.globl  __start
-	.globl  _start
-_start:
-__start:
-	pushl	%ebx			#ps_strings
-	pushl   %ecx                    # obj
-	pushl   %edx                    # cleanup
-	movl    12(%esp),%eax
-	leal    20(%esp,%eax,4),%ecx
-	leal    16(%esp),%edx
-	pushl   %ecx
-	pushl   %edx
-	pushl   %eax
-	call    ___start
-
-#NO_APP
-.text
-	.align 4
-.globl ___start
-	.type	___start , @function
-___start:
-	pushl %ebp
-	movl %esp,%ebp
-	subl $16,%esp
-	pushl %esi
-	pushl %ebx
-	call fpc_geteipasecx
-	addl $_GLOBAL_OFFSET_TABLE_,%ecx
-	movl %ecx,%edi
-	movl 12(%ebp),%esi
-	movl 16(%ebp),%eax
-	movl environ@GOT(%edi),%ecx
-	movl %eax,(%ecx)
-	movl operatingsystem_parameter_envp@GOT(%edi),%ecx
-	movl %eax,(%ecx)
-	movl (%esi),%ebx
-	testl %ebx,%ebx
-	je .L3
-	addl $-8,%esp
-	pushl $47
-	pushl %ebx
-	call _strrchr
-	movl __progname@GOT(%edi),%ecx
-	movl %eax,(%ecx)
-	addl $16,%esp
-	testl %eax,%eax
-	jne .L4
-	movl %ebx,(%ecx)
-	jmp .L5
-	.p2align 4,,7
-.L4:
-	incl %eax
-	movl %eax,(%ecx)
-.L5:
-	movl __progname_storage@GOT(%edi),%edx
-	jmp .L12
-	.p2align 4,,7
-.L9:
-	movb (%eax),%al
-	movb %al,(%edx)
-	movl __progname@GOT(%edi),%ecx
-	incl (%ecx)
-	incl %edx
-.L12:
-	movl __progname@GOT(%edi),%ecx
-	movl (%ecx),%eax
-	cmpb $0,(%eax)
-	je .L7
-	movl __progname_storage@GOT(%edi),%ecx
-	addl $255,%ecx
-	cmpl %ecx,%edx
-	jb .L9
-.L7:
-	movb $0,(%edx)
-	pushl %eax
-	movl __progname_storage@GOT(%edi),%eax
-	movl __progname@GOT(%edi),%ecx
-	movl %eax,(%ecx)
-	popl %eax
-.L3:
-#	call __init
-	subl $16,%esp
-	pushl %eax
-	movl 8(%ebp),%eax
-	movl operatingsystem_parameter_argc@GOT(%edi),%ecx
-	movl %eax,(%ecx)
-	movl operatingsystem_parameter_argv@GOT(%edi),%ecx
-	movl %esi,(%ecx)
-	popl %eax
-#	pushl environ
-#	pushl %esi
-#	pushl 8(%ebp)
-	movl ___fpucw@GOT(%edi),%ecx
-	finit
-	fwait
-	fldcw (%ecx)
-	xorl  %ebp,%ebp
-	call main
-	pushl %eax
-	call exit@PLT
-        .p2align 2,0x90
-
-.globl _haltproc
-.type _haltproc,@function
-
-_haltproc:
-           call fpc_geteipasebx
-           addl $_GLOBAL_OFFSET_TABLE_,%ebx
-           movl operatingsystem_result@GOT(%ebx),%ebx
-           movzwl (%ebx),%ebx
-           pushl %ebx
-           mov $1,%eax
-           call .Lactualsyscall
-           addl  $4,%esp
-           jmp   _haltproc
-
-.Lactualsyscall:
-         int $0x80
-         jb .LErrorcode
-         xor %ebx,%ebx
-         ret
-.LErrorcode:
-         mov %eax,%ebx
-         mov $-1,%eax
-         ret
-        .p2align 2,0x90
-.Lfe1:
-
-	.size	___start , . - ___start
-	.align 4
-	.type	_strrchr , @function
-_strrchr:
-	pushl %ebp
-	movl %esp,%ebp
-	pushl %ebx
-	movl 8(%ebp),%eax
-	movb 12(%ebp),%bl
-	xorl %ecx,%ecx
-	.p2align 4,,7
-.L14:
-	movb (%eax),%dl
-	cmpb %bl,%dl
-	jne .L17
-	movl %eax,%ecx
-.L17:
-	testb %dl,%dl
-	je .L16
-	incl %eax
-	jmp .L14
-	.p2align 4,,7
-.L16:
-	movl %ecx,%eax
-	popl %ebx
-	leave
-	ret
-	.size	_strrchr , . - _strrchr
-	.comm	environ,4,4
-	.comm	__progname_storage,256,32
-        .comm   operatingsystem_parameter_envp,4,4
-        .comm   operatingsystem_parameter_argc,4,4
-        .comm   operatingsystem_parameter_argv,4,4
-

+ 7 - 6
rtl/openbsd/i386/prt0.as

@@ -42,15 +42,16 @@ ___fpc_brk_addr:
 	.globl  _start
 	.globl  _start
 _start:
 _start:
 __start:
 __start:
-	pushl	%ebx			#ps_strings
-	pushl   %ecx                    # obj
-	pushl   %edx                    # cleanup
-	movl    12(%esp),%eax
-	leal    20(%esp,%eax,4),%ecx
-	leal    16(%esp),%edx
+	movl    %esp,%ebp
+	andl    $~15,%esp
+	pushl   %edx
+	movl    0(%ebp),%eax
+	leal    8(%ebp,%eax,4),%ecx
+	leal    4(%ebp),%edx
 	pushl   %ecx
 	pushl   %ecx
 	pushl   %edx
 	pushl   %edx
 	pushl   %eax
 	pushl   %eax
+	xorl    %ebp,%ebp
 	call    ___start
 	call    ___start
 
 
 #NO_APP
 #NO_APP

+ 14 - 10
rtl/openbsd/i386/si_c.inc

@@ -18,31 +18,35 @@
 
 
 procedure __init; cdecl; external name '__init';
 procedure __init; cdecl; external name '__init';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
+function _csu_finish(_argv: PPChar; _envp: PPChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
 
 
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
   asm
   asm
-    pushl   %ebx                    { ps_strings }
-    pushl   %ecx                    { obj }
-    pushl   %edx                    { cleanup }
-    movl    12(%esp),%eax
-    leal    20(%esp,%eax,4),%ecx
-    leal    16(%esp),%edx
+    movl    %esp,%ebp
+    andl    $0xFFFFFFF0,%esp
+    pushl   %edx
+    movl    0(%ebp),%eax
+    leal    8(%ebp,%eax,4),%ecx
+    leal    4(%ebp),%edx
     pushl   %ecx
     pushl   %ecx
     pushl   %edx
     pushl   %edx
     pushl   %eax
     pushl   %eax
+    xorl    %ebp,%ebp
     call    _FPC_proc___start
     call    _FPC_proc___start
   end;
   end;
 
 
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
   var
   var
     I: SizeUInt;
     I: SizeUInt;
+    environp: PPPChar;
   begin
   begin
-    environ:=envp;
-    operatingsystem_parameter_envp:=envp;
+    environp:=_csu_finish(argv, envp, cleanup);
+    environ:=environp^;
+    operatingsystem_parameter_envp:=environ;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argv:=argv;
     operatingsystem_parameter_argv:=argv;
     if argv[0]<>nil then
     if argv[0]<>nil then

+ 14 - 10
rtl/openbsd/i386/si_g.inc

@@ -25,31 +25,35 @@ function atexit(proc: TCdeclProcedure): cint; cdecl; external name 'atexit';
 procedure _monstartup(lowpc, highpc: u_long); cdecl; external name '_monstartup';
 procedure _monstartup(lowpc, highpc: u_long); cdecl; external name '_monstartup';
 procedure __init; cdecl; external name '__init';
 procedure __init; cdecl; external name '__init';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
+function _csu_finish(_argv: PPChar; _envp: PPChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
 
 
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
   asm
   asm
-    pushl   %ebx                    { ps_strings }
-    pushl   %ecx                    { obj }
-    pushl   %edx                    { cleanup }
-    movl    12(%esp),%eax
-    leal    20(%esp,%eax,4),%ecx
-    leal    16(%esp),%edx
+    movl    %esp,%ebp
+    andl    $0xFFFFFFF0,%esp
+    pushl   %edx
+    movl    0(%ebp),%eax
+    leal    8(%ebp,%eax,4),%ecx
+    leal    4(%ebp),%edx
     pushl   %ecx
     pushl   %ecx
     pushl   %edx
     pushl   %edx
     pushl   %eax
     pushl   %eax
+    xorl    %ebp,%ebp
     call    _FPC_proc___start
     call    _FPC_proc___start
   end;
   end;
 
 
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
   var
   var
     I: SizeUInt;
     I: SizeUInt;
+    environp: PPPChar;
   begin
   begin
-    environ:=envp;
-    operatingsystem_parameter_envp:=envp;
+    environp:=_csu_finish(argv, envp, cleanup);
+    environ:=environp^;
+    operatingsystem_parameter_envp:=environ;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argv:=argv;
     operatingsystem_parameter_argv:=argv;
     if argv[0]<>nil then
     if argv[0]<>nil then

+ 9 - 8
rtl/openbsd/i386/si_prc.inc

@@ -16,26 +16,27 @@
 
 
 {$asmmode att}
 {$asmmode att}
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
 
 
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
   asm
   asm
-    pushl   %ebx                    { ps_strings }
-    pushl   %ecx                    { obj }
-    pushl   %edx                    { cleanup }
-    movl    12(%esp),%eax
-    leal    20(%esp,%eax,4),%ecx
-    leal    16(%esp),%edx
+    movl    %esp,%ebp
+    andl    $0xFFFFFFF0,%esp
+    pushl   %edx
+    movl    0(%ebp),%eax
+    leal    8(%ebp,%eax,4),%ecx
+    leal    4(%ebp),%edx
     pushl   %ecx
     pushl   %ecx
     pushl   %edx
     pushl   %edx
     pushl   %eax
     pushl   %eax
+    xorl    %ebp,%ebp
     call    _FPC_proc___start
     call    _FPC_proc___start
   end;
   end;
 
 
 procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
 procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
   var
   var
     I: SizeUInt;
     I: SizeUInt;
   begin
   begin

+ 0 - 244
rtl/openbsd/x86_64/cprt0.as

@@ -1,244 +0,0 @@
-	.section ".note.openbsd.ident", "a"
-	.p2align 2
-	.long	8
-	.long	4
-	.long	1
-	.ascii "OpenBSD\0"
-	.long	0
-	.previous
-	.file	"crt0.c"
-	.globl	__progname
-	.section	.rodata
-.LC0:
-	.string	""
-	.data
-	.align 8
-	.type	__progname, @object
-	.size	__progname, 8
-__progname:
-	.quad	.LC0
-#APP
-	 .text				
-	.align	8			
-	.globl	__start			
-	.globl	_start			
-_start:					
-__start:				
-	movq	%rbx,%r9		
-	movq	%rcx,%r8		
-	movq	%rdx,%rcx		
-	movq	(%rsp),%rdi		
-	leaq	16(%rsp,%rdi,8),%rdx	
-	leaq	8(%rsp),%rsi		
-	subq	$8,%rsp			
-	andq	$~15,%rsp		
-	addq	$8,%rsp			
-	jmp	___start		
-
-#NO_APP
-	.text
-	.globl	___start
-	.type	___start, @function
-___start:
-.LFB9:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	subq	$64, %rsp
-.LCFI2:
-	movl	%edi, -20(%rbp)
-	movq	%rsi, -32(%rbp)
-	movq	%rdx, -40(%rbp)
-	movq	%rcx, -48(%rbp)
-	movq	%r8, -56(%rbp)
-	movq	%r9, -64(%rbp)
-	movq	-40(%rbp), %rax
-	movq	%rax, environ(%rip)
-	movq    %rax,operatingsystem_parameter_envp(%rip)
-	movq	-32(%rbp), %rax
-	movq	(%rax), %rax
-	movq	%rax, -8(%rbp)
-	cmpq	$0, -8(%rbp)
-	je	.L2
-	movq	-8(%rbp), %rdi
-	movl	$47, %esi
-	call	_strrchr
-	movq	%rax, __progname(%rip)
-	movq	__progname(%rip), %rax
-	testq	%rax, %rax
-	jne	.L4
-	movq	-8(%rbp), %rax
-	movq	%rax, __progname(%rip)
-	jmp	.L6
-.L4:
-	movq	__progname(%rip), %rax
-	addq	$1, %rax
-	movq	%rax, __progname(%rip)
-.L6:
-	leaq	__progname_storage(%rip), %rax
-	movq	%rax, -16(%rbp)
-	jmp	.L7
-.L8:
-	movq	__progname(%rip), %rcx
-	movzbl	(%rcx), %edx
-	movq	-16(%rbp), %rax
-	movb	%dl, (%rax)
-	addq	$1, -16(%rbp)
-	leaq	1(%rcx), %rax
-	movq	%rax, __progname(%rip)
-.L7:
-	movq	__progname(%rip), %rax
-	movzbl	(%rax), %eax
-	testb	%al, %al
-	je	.L9
-	leaq	__progname_storage+255(%rip), %rax
-	cmpq	%rax, -16(%rbp)
-	jb	.L8
-.L9:
-	leaq	__progname_storage(%rip), %rax
-	movq	%rax, __progname(%rip)
-	movq	-16(%rbp), %rax
-	movb	$0, (%rax)
-.L2:
-	movq	_mcleanup@GOTPCREL(%rip), %rdi
-	call	atexit
-	movq	_etext@GOTPCREL(%rip), %rsi
-	leaq	_eprol(%rip), %rdi
-	call	monstartup@plt
-	movl	$0, %eax
-	call	_init
-	movq	environ(%rip), %rdx
-	movq	-32(%rbp), %rsi
-	movl	-20(%rbp), %edi
-	movq    %rdi,operatingsystem_parameter_argc(%rip)
-	movq    %rsi,operatingsystem_parameter_argv(%rip)
-	movl	$0, %eax
-	call	main
-	# movl	%eax, %edi
-	# call	exit
-	jmp _haltproc
-        .p2align 2,0x90
-
-.globl _haltproc
-.type _haltproc,@function
-
-_haltproc:
-           movq $1,%rax
-           movzwq operatingsystem_result(%rip),%rbx
-           pushq   %rbx
-           call .Lactualsyscall
-           addq  $8,%rsp
-           jmp   _haltproc
-
-.Lactualsyscall:
-         int $0x80
-         jb .LErrorcode
-         xor %rbx,%rbx
-         ret
-.LErrorcode:
-         movq  %rax,%rbx
-         movq  $-1,%rax
-.LFE9:
-	.size	___start, .-___start
-	.type	_strrchr, @function
-_strrchr:
-.LFB10:
-	pushq	%rbp
-.LCFI3:
-	movq	%rsp, %rbp
-.LCFI4:
-	movq	%rdi, -24(%rbp)
-	movb	%sil, -25(%rbp)
-	movq	$0, -8(%rbp)
-.L13:
-	movq	-24(%rbp), %rdx
-	movzbl	(%rdx), %eax
-	cmpb	-25(%rbp), %al
-	jne	.L14
-	movq	-24(%rbp), %rax
-	movq	%rax, -8(%rbp)
-.L14:
-	movq	-24(%rbp), %rdx
-	movzbl	(%rdx), %eax
-	testb	%al, %al
-	jne	.L16
-	movq	-8(%rbp), %rax
-	movq	%rax, -16(%rbp)
-	jmp	.L12
-.L16:
-	addq	$1, -24(%rbp)
-	jmp	.L13
-.L12:
-	movq	-16(%rbp), %rax
-	leave
-	ret
-.LFE10:
-	.size	_strrchr, .-_strrchr
-#APP
-	  .text
-	_eprol:
-#NO_APP
-	.comm	environ,8,8
-	.comm	__progname_storage,256,32
-        .comm   operatingsystem_parameter_envp,8,8
-        .comm   operatingsystem_parameter_argc,8,8
-        .comm   operatingsystem_parameter_argv,8,8
-	.section	.eh_frame,"a",@unwind
-.Lframe1:
-	.long	.LECIE1-.LSCIE1
-.LSCIE1:
-	.long	0x0
-	.byte	0x1
-	.string	"zR"
-	.uleb128 0x1
-	.sleb128 -8
-	.byte	0x10
-	.uleb128 0x1
-	.byte	0x3
-	.byte	0xc
-	.uleb128 0x7
-	.uleb128 0x8
-	.byte	0x90
-	.uleb128 0x1
-	.align 8
-.LECIE1:
-.LSFDE1:
-	.long	.LEFDE1-.LASFDE1
-.LASFDE1:
-	.long	.LASFDE1-.Lframe1
-	.long	.LFB9-.
-	.long	.LFE9-.LFB9
-	.uleb128 0x0
-	.byte	0x4
-	.long	.LCFI0-.LFB9
-	.byte	0xe
-	.uleb128 0x10
-	.byte	0x86
-	.uleb128 0x2
-	.byte	0x4
-	.long	.LCFI1-.LCFI0
-	.byte	0xd
-	.uleb128 0x6
-	.align 8
-.LEFDE1:
-.LSFDE3:
-	.long	.LEFDE3-.LASFDE3
-.LASFDE3:
-	.long	.LASFDE3-.Lframe1
-	.long	.LFB10-.
-	.long	.LFE10-.LFB10
-	.uleb128 0x0
-	.byte	0x4
-	.long	.LCFI3-.LFB10
-	.byte	0xe
-	.uleb128 0x10
-	.byte	0x86
-	.uleb128 0x2
-	.byte	0x4
-	.long	.LCFI4-.LCFI3
-	.byte	0xd
-	.uleb128 0x6
-	.align 8
-.LEFDE3:
-	.ident	"GCC: (GNU) 4.2.1 20070719 "

+ 0 - 2
rtl/openbsd/x86_64/prt0.as

@@ -24,8 +24,6 @@ __progname:
 	.globl	_start			
 	.globl	_start			
 _start:					
 _start:					
 __start:				
 __start:				
-	movq	%rbx,%r9		
-	movq	%rcx,%r8		
 	movq	%rdx,%rcx		
 	movq	%rdx,%rcx		
 	movq	(%rsp),%rdi		
 	movq	(%rsp),%rdi		
 	leaq	16(%rsp,%rdi,8),%rdx	
 	leaq	16(%rsp,%rdi,8),%rdx	

+ 7 - 6
rtl/openbsd/x86_64/si_c.inc

@@ -18,13 +18,12 @@
 
 
 procedure __init; cdecl; external name '__init';
 procedure __init; cdecl; external name '__init';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
+function _csu_finish(_argv: PPChar; _envp: PPChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
 
 
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
   asm
   asm
-    movq    %rbx,%r9
-    movq    %rcx,%r8
     movq    %rdx,%rcx
     movq    %rdx,%rcx
     movq    (%rsp),%rdi
     movq    (%rsp),%rdi
     leaq    16(%rsp,%rdi,8),%rdx
     leaq    16(%rsp,%rdi,8),%rdx
@@ -37,12 +36,14 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public
 
 
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
   var
   var
     I: SizeUInt;
     I: SizeUInt;
+    environp: PPPChar;
   begin
   begin
-    environ:=envp;
-    operatingsystem_parameter_envp:=envp;
+    environp:=_csu_finish(argv, envp, cleanup);
+    environ:=environp^;
+    operatingsystem_parameter_envp:=environ;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argv:=argv;
     operatingsystem_parameter_argv:=argv;
     if argv[0]<>nil then
     if argv[0]<>nil then

+ 7 - 6
rtl/openbsd/x86_64/si_g.inc

@@ -25,13 +25,12 @@ function atexit(proc: TCdeclProcedure): cint; cdecl; external name 'atexit';
 procedure _monstartup(lowpc, highpc: u_long); cdecl; external name '_monstartup';
 procedure _monstartup(lowpc, highpc: u_long); cdecl; external name '_monstartup';
 procedure __init; cdecl; external name '__init';
 procedure __init; cdecl; external name '__init';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
 procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
+function _csu_finish(_argv: PPChar; _envp: PPChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
 
 
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
   asm
   asm
-    movq    %rbx,%r9
-    movq    %rcx,%r8
     movq    %rdx,%rcx
     movq    %rdx,%rcx
     movq    (%rsp),%rdi
     movq    (%rsp),%rdi
     leaq    16(%rsp,%rdi,8),%rdx
     leaq    16(%rsp,%rdi,8),%rdx
@@ -44,12 +43,14 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public
 
 
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
   var
   var
     I: SizeUInt;
     I: SizeUInt;
+    environp: PPPChar;
   begin
   begin
-    environ:=envp;
-    operatingsystem_parameter_envp:=envp;
+    environp:=_csu_finish(argv, envp, cleanup);
+    environ:=environp^;
+    operatingsystem_parameter_envp:=environ;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argc:=argc;
     operatingsystem_parameter_argv:=argv;
     operatingsystem_parameter_argv:=argv;
     if argv[0]<>nil then
     if argv[0]<>nil then

+ 2 - 4
rtl/openbsd/x86_64/si_prc.inc

@@ -16,12 +16,10 @@
 
 
 {$asmmode gas}
 {$asmmode gas}
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); forward;
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); forward;
 
 
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
   asm
   asm
-    movq    %rbx,%r9
-    movq    %rcx,%r8
     movq    %rdx,%rcx
     movq    %rdx,%rcx
     movq    (%rsp),%rdi
     movq    (%rsp),%rdi
     leaq    16(%rsp,%rdi,8),%rdx
     leaq    16(%rsp,%rdi,8),%rdx
@@ -35,7 +33,7 @@ procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public
 procedure _FPC_proc_haltproc; cdecl; forward;
 procedure _FPC_proc_haltproc; cdecl; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 function _strrchr(str: PChar; character: LongInt): PChar; forward;
 
 
-procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord);
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure);
   var
   var
     I: SizeUInt;
     I: SizeUInt;
   begin
   begin