Ver código fonte

--- Merging r41646 into '.':
U packages/opengl/src/gl.pp
U packages/opengl/src/glu.pp
U packages/opengl/src/glut.pp
--- Recording mergeinfo for merge of r41646 into '.':
U .
--- Merging r41647 into '.':
G packages/opengl/src/gl.pp
G packages/opengl/src/glu.pp
G packages/opengl/src/glut.pp
--- Recording mergeinfo for merge of r41647 into '.':
G .
--- Merging r41675 into '.':
U compiler/systems/i_bsd.pas
--- Recording mergeinfo for merge of r41675 into '.':
G .
--- Merging r41695 into '.':
A rtl/openbsd/si_impl.inc
U rtl/openbsd/si_intf.inc
U rtl/openbsd/si_prc.pp
U rtl/openbsd/x86_64/si_prc.inc
--- Recording mergeinfo for merge of r41695 into '.':
G .
--- Merging r41696 into '.':
U compiler/systems/t_bsd.pas
--- Recording mergeinfo for merge of r41696 into '.':
G .
--- Merging r41697 into '.':
G compiler/systems/t_bsd.pas
--- Recording mergeinfo for merge of r41697 into '.':
G .
--- Merging r41698 into '.':
G compiler/systems/t_bsd.pas
--- Recording mergeinfo for merge of r41698 into '.':
G .
--- Merging r41699 into '.':
G compiler/systems/t_bsd.pas
--- Recording mergeinfo for merge of r41699 into '.':
G .
--- Merging r41700 into '.':
G compiler/systems/t_bsd.pas
--- Recording mergeinfo for merge of r41700 into '.':
G .
--- Merging r41701 into '.':
U rtl/openbsd/si_impl.inc
G rtl/openbsd/si_intf.inc
G rtl/openbsd/x86_64/si_prc.inc
--- Recording mergeinfo for merge of r41701 into '.':
G .

# revisions: 41646,41647,41675,41695,41696,41697,41698,41699,41700,41701

git-svn-id: branches/fixes_3_2@41985 -

marco 6 anos atrás
pai
commit
046150ddeb

+ 1 - 0
.gitattributes

@@ -10124,6 +10124,7 @@ rtl/openbsd/rtldefs.inc svneol=native#text/plain
 rtl/openbsd/setsysnr.inc svneol=native#text/plain
 rtl/openbsd/si_c.pp svneol=native#text/plain
 rtl/openbsd/si_dll.pp svneol=native#text/plain
+rtl/openbsd/si_impl.inc svneol=native#text/plain
 rtl/openbsd/si_intf.inc svneol=native#text/plain
 rtl/openbsd/si_prc.pp svneol=native#text/plain
 rtl/openbsd/signal.inc svneol=native#text/plain

+ 1 - 1
compiler/systems/i_bsd.pas

@@ -326,7 +326,7 @@ unit i_bsd;
             system       : system_i386_OpenBSD;
             name         : 'OpenBSD for i386';
             shortname    : 'OpenBSD';
-            flags        : [tf_pic_uses_got,tf_under_development,tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources];
+            flags        : [tf_pic_default,tf_pic_uses_got,tf_under_development,tf_files_case_sensitive,tf_smartlink_sections,tf_has_winlike_resources];
             cpu          : cpu_i386;
             unit_env     : 'BSDUNITS';
             extradefines : 'UNIX;BSD;HASUNIX';

+ 84 - 47
compiler/systems/t_bsd.pas

@@ -60,6 +60,9 @@ implementation
     private
       LdSupportsNoResponseFile : boolean;
       LibrarySuffix : Char;
+      prtobj : string[80];
+      ReOrder : Boolean;
+      linklibc : boolean;
       Function  WriteResponseFile(isdll:boolean) : Boolean;
       function GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
       Function GetDarwinPrtobjName(isdll: boolean): TCmdStr;
@@ -73,6 +76,27 @@ implementation
     end;
 
 
+function ModulesLinkToLibc:boolean;
+var
+  hp: tmodule;
+begin
+  { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
+    The former contains library names qualified with prefix and suffix (coming from
+    "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
+    directives). }
+  hp:=tmodule(loaded_units.first);
+  while assigned(hp) do
+    begin
+      result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
+      if result then break;
+      result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
+      if result then break;
+      result:=hp.linkothersharedlibs.find('c');
+      if result then break;
+      hp:=tmodule(hp.next);
+    end;
+end;
+
 
 {*****************************************************************************
                              TIMPORTLIBDARWIN
@@ -230,11 +254,67 @@ End;
 
 
 procedure TLinkerBSD.InitSysInitUnitName;
+var
+  cprtobj,
+  gprtobj,
+  si_cprt,
+  si_gprt : string[80];
 begin
   if target_info.system in systems_darwin then
-    SysInitUnit:='sysinit'
+    begin
+      { for darwin: always link dynamically against libc }
+      linklibc := true;
+      reorder:=reorderentries;
+      prtobj:='';
+      SysInitUnit:='sysinit';
+    end
   else
-    inherited InitSysInitUnitName;
+    begin
+      linklibc:=ModulesLinkToLibc;
+      if current_module.islibrary and
+         (target_info.system in systems_bsd) then
+        begin
+          prtobj:='dllprt0';
+          cprtobj:='dllprt0';
+          gprtobj:='dllprt0';
+          SysInitUnit:='si_dll';
+          si_cprt:='si_dll';
+          si_gprt:='si_dll';
+        end
+      else
+        begin
+          prtobj:='prt0';
+          cprtobj:='cprt0';
+          gprtobj:='gprt0';
+          SysInitUnit:='si_prc';
+          si_cprt:='si_c';
+          si_gprt:='si_g';
+        end;
+      // this one is a bit complex.
+      // Only reorder for now if -XL or -XO params are given
+      // or when -Xf.
+      reorder:= linklibc and
+                (
+                  ReorderEntries
+                   or
+                  (cs_link_pthread in current_settings.globalswitches));
+      if cs_profile in current_settings.moduleswitches then
+       begin
+         prtobj:=gprtobj;
+         SysInitUnit:=si_gprt;
+         AddSharedLibrary('c');
+         LibrarySuffix:='p';
+         linklibc:=true;
+       end
+      else
+       begin
+         if linklibc then
+           begin
+             prtobj:=cprtobj;
+             SysInitUnit:=si_cprt;
+           end;
+       end;
+    end;
 end;
 
 
@@ -392,16 +472,11 @@ Var
   linkres      : TLinkRes;
   FilesList    : TLinkRes;
   i            : longint;
-  cprtobj,
-  gprtobj,
-  prtobj       : string[80];
   HPath        : TCmdStrListItem;
   s,s1,s2      : TCmdStr;
-  linkdynamic,
-  linklibc     : boolean;
+  linkdynamic  : boolean;
   Fl1,Fl2      : Boolean;
   IsDarwin     : Boolean;
-  ReOrder      : Boolean;
 
 begin
   WriteResponseFile:=False;
@@ -411,47 +486,11 @@ begin
 { set special options for some targets }
   if not IsDarwin Then
     begin
-      if isdll and
-         (target_info.system in systems_bsd) then
-        begin
-          prtobj:='dllprt0';
-          cprtobj:='dllprt0';
-          gprtobj:='dllprt0';
-        end
-      else
-        begin
-          prtobj:='prt0';
-          cprtobj:='cprt0';
-          gprtobj:='gprt0';
-        end;
       linkdynamic:=not(SharedLibFiles.empty);
-      linklibc:=(SharedLibFiles.Find('c')<>nil);
-      // this one is a bit complex.
-      // Only reorder for now if -XL or -XO params are given
-      // or when -Xf.
-      reorder:= linklibc and
-                (
-                  ReorderEntries
-                   or
-                  (cs_link_pthread in current_settings.globalswitches));
-      if cs_profile in current_settings.moduleswitches then
-       begin
-         prtobj:=gprtobj;
-         AddSharedLibrary('c');
-         LibrarySuffix:='p';
-         linklibc:=true;
-       end
-      else
-       begin
-         if linklibc then
-          prtobj:=cprtobj;
-       end;
       // after this point addition of shared libs not allowed.
     end
   else
     begin
-      { for darwin: always link dynamically against libc }
-      linklibc := true;
 {$ifdef MACOSX104ORHIGHER}
       { not sure what this is for, but gcc always links against it }
       if not(cs_profile in current_settings.moduleswitches) then
@@ -459,8 +498,6 @@ begin
       else
         AddSharedLibrary('SystemStubs_profile');
 {$endif MACOSX104ORHIGHER}
-      reorder:=reorderentries;
-      prtobj:='';
     end;
 
   if reorder Then
@@ -571,7 +608,7 @@ begin
   if not LdSupportsNoResponseFile then
     LinkRes.Add('INPUT(');
   { add objectfiles, start with prt0 always }
-  if prtobj<>'' then
+  if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
    LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
   { try to add crti and crtbegin if linking to C }
   if linklibc and

+ 5 - 13
packages/opengl/src/gl.pp

@@ -2255,27 +2255,19 @@ initialization
   SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,exOverflow, exUnderflow, exPrecision]);
   {$endif}
 
-  {$IFDEF Windows}
+  {$if defined(Windows)}
   LoadOpenGL('opengl32.dll');
-  {$ELSE}
-  {$IFDEF OS2}
+  {$elseif defined(OS2)}
   LoadOpenGL('opengl.dll');
-  {$ELSE OS2}
-  {$ifdef darwin}
+  {$elseif defined(darwin)}
   LoadOpenGL('/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib');
-  {$ELSE}
-  {$IFDEF MorphOS}
+  {$elseif defined(MorphOS)}
   InitTinyGLLibrary;
-  {$ELSE}
-  {$ifdef haiku}
+  {$elseif defined(haiku) or defined(OpenBSD)}
   LoadOpenGL('libGL.so');
   {$else}
   LoadOpenGL('libGL.so.1');
   {$endif}
-  {$ENDIF}
-  {$endif}
-  {$ENDIF OS2}
-  {$ENDIF}
 
 finalization
 

+ 5 - 13
packages/opengl/src/glu.pp

@@ -67,27 +67,19 @@ uses
   GL;
 
 Const
-{$IFDEF Windows}
+{$if defined(Windows)}
   GLU_Lib = 'glu32.dll';
-{$ELSE}
-{$IFDEF OS2}
+{$elseif defined(OS2)}
   GLU_Lib = 'opengl.dll';
-{$ELSE OS2}
-{$ifdef darwin}
+{$elseif defined(darwin)}
   GLU_LIB =  '/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib';
-{$else}
-{$IFDEF haiku}
+{$elseif defined(haiku) or defined(OpenBSD)}
   GLU_LIB = 'libGLU.so';
-{$ELSE}
-{$ifdef MorphOS}
+{$elseif defined(MorphOS)}
   GLU_LIB = 'tinygl.library';
 {$else}
   GLU_LIB = 'libGLU.so.1';
 {$endif}
-{$ENDIF}
-{$ENDIF}
-{$ENDIF OS2}
-{$endif}
                               
 type
   TViewPortArray = array [0..3] of GLint;

+ 7 - 13
packages/opengl/src/glut.pp

@@ -759,25 +759,19 @@ end;
 
 initialization
 
-  {$IFDEF Windows}
+  {$if defined(Windows)}
   LoadGlut('glut32.dll');
-  {$ELSE}
-  {$IFDEF OS2}
+  {$elseif defined(OS2)}
   LoadGlut('glut.dll');
-  {$ELSE OS2}
-  {$ifdef darwin}
+  {$elseif defined(darwin)}
   LoadGlut('/System/Library/Frameworks/GLUT.framework/GLUT');
-  {$else}
-  {$IFDEF haiku}
+  {$elseif defined(haiku) or defined(OpenBSD)}
   LoadGlut('libglut.so');
-  {$ELSE}
-  {$IFNDEF MORPHOS}
+  {$elseif defined(MORPHOS)}
+  {nothing}
+  {$else}
   LoadGlut('libglut.so.3');
-  {$ENDIF}
-  {$ENDIF}
   {$endif}
-  {$ENDIF OS2}
-  {$ENDIF}
 
 finalization
 

+ 18 - 0
rtl/openbsd/si_impl.inc

@@ -0,0 +1,18 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2015 by Sven Barth, member of the Free Pascal development
+    team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+procedure PascalMain; external name 'PASCALMAIN';
+
+var
+  operatingsystem_result: longint; external name 'operatingsystem_result';

+ 3 - 0
rtl/openbsd/si_intf.inc

@@ -20,3 +20,6 @@ var
   operatingsystem_parameter_envp: ppchar; public name 'operatingsystem_parameter_envp';
   operatingsystem_parameter_argc: longint; public name 'operatingsystem_parameter_argc';
   operatingsystem_parameter_argv: ppchar; public name 'operatingsystem_parameter_argv';
+  environ: ppchar; public name 'environ';
+  __progname: pchar = ''; public name '__progname';
+  __progname_storage: array [0..255] of char; public name '__progname_storage';

+ 1 - 0
rtl/openbsd/si_prc.pp

@@ -23,6 +23,7 @@ interface
 
 implementation
 
+{$i si_impl.inc}
 {$i si_prc.inc}
 
 end.

+ 148 - 0
rtl/openbsd/x86_64/si_prc.inc

@@ -14,4 +14,152 @@
 
  **********************************************************************}
 
+{$asmmode gas}
 
+procedure _FPC_proc___start; forward;
+
+procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
+  asm
+    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    $0xFFFFFFFFFFFFFFF0,%rsp
+    addq    $8,%rsp
+    jmp     _FPC_proc___start
+  end;
+
+procedure _FPC_proc_haltproc; forward;
+function _strrchr(str: PChar; character: LongInt): PChar; forward;
+
+procedure _FPC_proc___start; assembler; nostackframe; public name '___start';
+  asm
+    pushq   %rbp
+    movq    %rsp, %rbp
+    subq    $64, %rsp
+    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:
+    // movl    $_mcleanup, %edi
+    // call    atexit
+    // movl    $_etext, %eax
+    // movq    %rax, %rsi
+    // movl    $_eprol, %eax
+    // movq    %rax, %rdi
+    // call    monstartup
+    // 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    PASCALMAIN
+    // movl    %eax, %edi
+    // call    exit
+    jmp     _FPC_proc_haltproc
+  end;
+
+procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
+  asm
+    movq    $1,%rax
+    movl    operatingsystem_result(%rip),%ebx
+    pushq   %rbx
+    call    .Lactualsyscall
+    addq    $8,%rsp
+    jmp     _FPC_proc_haltproc
+
+.Lactualsyscall:
+    int     $0x80
+    jb      .LErrorcode
+    xor     %rbx,%rbx
+    ret
+.LErrorcode:
+    movq    %rax,%rbx
+    movq    $-1,%rax
+  end;
+
+function _strrchr(str: PChar; character: LongInt): PChar; assembler; nostackframe; public name '_strrchr';
+  asm
+    pushq   %rbp
+    movq    %rsp, %rbp
+    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
+  end;