Sfoglia il codice sorgente

Merged revisions 9134,9176,9179,9182,9184,9193-9196,9199-9202,9204,9221-9222,9232,9241,9243,9251 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r9134 | jonas | 2007-11-04 19:33:07 +0100 (Sun, 04 Nov 2007) | 3 lines

* safeguard the nf_block_with_exit flag when simplifying blockn and
statementn + test

........
r9176 | jonas | 2007-11-10 19:22:37 +0100 (Sat, 10 Nov 2007) | 4 lines

* fixed ioctl for non-linux: the third parameter is "..." there rather
than a pointer. The interface still accepts a plain pointer for
backwards compatibility..

........
r9179 | jonas | 2007-11-10 19:32:38 +0100 (Sat, 10 Nov 2007) | 4 lines

* fixed IOCtl_TCGETS constant
- removed a bunch of linux/freebsd-specific constants (more left,
probably)

........
r9182 | jonas | 2007-11-10 20:57:01 +0100 (Sat, 10 Nov 2007) | 2 lines

* added missing size suffixes for several sse2 opcodes

........
r9184 | jonas | 2007-11-10 22:12:45 +0100 (Sat, 10 Nov 2007) | 4 lines

* import iconv routines as iconv_* rather than libiconv_* for darwin
as the 32 bit libraries export both variants, but the new 64 bit
ones on Mac OS X 10.5 only export iconv_*

........
r9193 | jonas | 2007-11-11 17:11:32 +0100 (Sun, 11 Nov 2007) | 2 lines

* don't use (non-volatile) ebx in assembler routine

........
r9194 | jonas | 2007-11-11 17:19:13 +0100 (Sun, 11 Nov 2007) | 3 lines

- removed ret as it breaks darwin (doesn't restore
stack alignment)

........
r9195 | jonas | 2007-11-11 17:24:05 +0100 (Sun, 11 Nov 2007) | 2 lines

* added nostackframe to fix running on darwin/i386

........
r9196 | jonas | 2007-11-11 17:27:24 +0100 (Sun, 11 Nov 2007) | 8 lines

o fixed darwin/i386 signal handling:
* fixed sigcontextrec definition
* work around missing Mac OS X support for reporting integer
division-by-zero as such (reported as generic SIGFPE)
* return from signal handler to HandleErrorFrame (just like
on ppc) instead of calling it (and fix up fpu and sse
status words when doing so)

........
r9199 | jonas | 2007-11-11 18:50:27 +0100 (Sun, 11 Nov 2007) | 2 lines

* changed x86_64 assembler code to PIC

........
r9200 | jonas | 2007-11-11 18:53:19 +0100 (Sun, 11 Nov 2007) | 3 lines

* don't test on darwin since not supported there for efficiency
reasons

........
r9201 | jonas | 2007-11-11 19:01:29 +0100 (Sun, 11 Nov 2007) | 4 lines

* all currently supported platforms require that single precision
parameters passed as C-style varargs are upgraded to double
precision

........
r9202 | jonas | 2007-11-11 20:10:34 +0100 (Sun, 11 Nov 2007) | 3 lines

* don't use libc round/trunc/cos/... if FPC_HAS_TYPE_EXTENDED, because
the imported routines only support double precision

........
r9204 | jonas | 2007-11-11 20:43:41 +0100 (Sun, 11 Nov 2007) | 5 lines

* use -x instead of -s for stripping executables on darwin (-s worked fine on 10.0,
was broken on 10.1, fixed in 10.2 and worked fine till 10.4, and has been
deprecated/removed in 10.5; conversely, -x has worked all the time, although it
results in slightly bigger binaries on platforms that also support -s)

........
r9221 | jonas | 2007-11-12 22:26:07 +0100 (Mon, 12 Nov 2007) | 2 lines

* actually assign result of strncmp to comparechar0 result

........
r9222 | jonas | 2007-11-12 23:06:39 +0100 (Mon, 12 Nov 2007) | 3 lines

* give generic IntbasiceventWaitFor a granularity of 50 rather than
500 miliseconds

........
r9232 | jonas | 2007-11-13 19:12:25 +0100 (Tue, 13 Nov 2007) | 3 lines

* fixed disabling of inlining procedures/functions with nested
procedures/functions

........
r9241 | jonas | 2007-11-13 21:19:06 +0100 (Tue, 13 Nov 2007) | 2 lines

* fixed test

........
r9243 | jonas | 2007-11-13 21:21:29 +0100 (Tue, 13 Nov 2007) | 6 lines

* truncate constant shortstrings at the callee side if they are passed
to a value parameter with a shorter length, and if they would not be
implicitly passed by reference (if they are passed by reference, then
the callee will perform a shortstring assign which will do the length
truncation). Fixes tarray3 on x86_64

........
r9251 | jonas | 2007-11-14 20:40:28 +0100 (Wed, 14 Nov 2007) | 3 lines

* added missing tcasenode.derefnode override to process all the
case-blocks and the else-block

........

git-svn-id: branches/fixes_2_2@9266 -

Jonas Maebe 18 anni fa
parent
commit
c5de52c373

+ 2 - 0
.gitattributes

@@ -5443,6 +5443,7 @@ rtl/unix/ipc.pp svneol=native#text/plain
 rtl/unix/ipccdecl.inc svneol=native#text/plain
 rtl/unix/keyboard.pp svneol=native#text/plain
 rtl/unix/mouse.pp svneol=native#text/plain
+rtl/unix/oscdecl.inc svneol=native#text/plain
 rtl/unix/oscdeclh.inc svneol=native#text/plain
 rtl/unix/ports.pp svneol=native#text/plain
 rtl/unix/printer.pp svneol=native#text/plain
@@ -6956,6 +6957,7 @@ tests/test/tindex.pp svneol=native#text/plain
 tests/test/tinivar.pp svneol=native#text/plain
 tests/test/tinlin64.pp svneol=native#text/plain
 tests/test/tinline1.pp svneol=native#text/plain
+tests/test/tinline10.pp svneol=native#text/plain
 tests/test/tinline2.pp svneol=native#text/plain
 tests/test/tinline3.pp svneol=native#text/plain
 tests/test/tinline4.pp svneol=native#text/plain

+ 9 - 9
compiler/i386/i386atts.inc

@@ -413,7 +413,10 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
+attsufINT,
+attsufINT,
 attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
@@ -477,6 +480,7 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
@@ -523,18 +527,14 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
+attsufINT,
 attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
@@ -599,6 +599,6 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
-attsufNONE,
-attsufNONE
+attsufINT,
+attsufINT
 );

+ 23 - 1
compiler/nbas.pas

@@ -216,7 +216,7 @@ implementation
       verbose,globals,systems,
       symconst,symdef,defutil,defcmp,
       pass_1,
-      nld,ncal,nflw,
+      nutils,nld,ncal,nflw,
       procinfo
       ;
 
@@ -317,6 +317,21 @@ implementation
       end;
 
 
+    function is_exit_statement(var n: tnode; arg: pointer): foreachnoderesult;
+      begin
+        if (n.nodetype<>exitn) then
+          result:=fen_false
+        else
+          result:=fen_norecurse_true;
+      end;
+
+
+    function no_exit_statement_in_block(n: tnode): boolean;
+      begin
+        result:=not foreachnodestatic(n,@is_exit_statement,nil);
+      end;
+
+
     function tstatementnode.simplify : tnode;
       begin
         result:=nil;
@@ -355,7 +370,12 @@ implementation
 
         { if the current statement contains a block with one statement, }
         { replace the current statement with that block's statement     }
+        { (but only if the block does not have nf_block_with_exit set   }
+        {  or has no exit statement, because otherwise it needs an own  }
+        {  exit label, see tests/test/tinline10)                        }
         if (left.nodetype = blockn) and
+           (not(nf_block_with_exit in left.flags) or
+            no_exit_statement_in_block(left)) and
            assigned(tblocknode(left).left) and
            not assigned(tstatementnode(tblocknode(left).left).right) then
           begin
@@ -465,6 +485,8 @@ implementation
           begin
             result:=tstatementnode(left).left;
             tstatementnode(left).left:=nil;
+            { make sure the nf_block_with_exit flag is safeguarded }
+            result.flags:=result.flags+(flags * [nf_block_with_exit]);
             exit;
           end;
       end;

+ 31 - 2
compiler/ncal.pas

@@ -809,7 +809,10 @@ implementation
     procedure tcallparanode.insert_typeconv(do_count : boolean);
       var
         olddef  : tdef;
-        hp       : tnode;
+        hp      : tnode;
+        block : tblocknode;
+        statements : tstatementnode;
+        temp : ttempcreatenode;
 {$ifdef extdebug}
         store_count_ref : boolean;
 {$endif def extdebug}
@@ -924,7 +927,33 @@ implementation
                       else
                        begin
                          check_ranges(left.fileinfo,left,parasym.vardef);
-                         inserttypeconv(left,parasym.vardef);
+                         { truncate shortstring value parameters at the caller side if }
+                         { they are passed by value (if passed by reference, then the  }
+                         { callee will truncate when copying in the string)            }
+                         { This happens e.g. on x86_64 for small strings               }
+                         if (parasym.varspez=vs_value) and
+                            not paramanager.push_addr_param(parasym.varspez,parasym.vardef,
+                                  aktcallnode.procdefinition.proccalloption) and
+                            (tstringdef(parasym.vardef).len<tstringdef(left.resultdef).len) then
+                           begin
+                             block:=internalstatements(statements);
+                             { temp for the new string }
+                             temp:=ctempcreatenode.create(parasym.vardef,parasym.vardef.size,
+                               tt_persistent,true);
+                             addstatement(statements,temp);
+                             { assign parameter to temp }
+                             addstatement(statements,cassignmentnode.create(ctemprefnode.create(temp),left));
+                             left:=nil;
+                             { release temp after next use }
+                             addstatement(statements,ctempdeletenode.create_normal_temp(temp));
+                             addstatement(statements,ctemprefnode.create(temp));
+                             typecheckpass(block);
+                             left:=block;
+                           end
+                         else
+                           { type conversions perform no truncation for constant strings, }
+                           { which is TP/Delphi compatible                                }
+                           inserttypeconv(left,parasym.vardef);
                        end;
                       if codegenerror then
                         begin

+ 1 - 3
compiler/ncnv.pas

@@ -600,9 +600,7 @@ implementation
                   if is_constrealnode(p) and
                      not(nf_explicit in p.flags) then
                     MessagePos(p.fileinfo,type_w_double_c_varargs);
-                  if (tfloatdef(p.resultdef).floattype in [{$ifndef x86_64}s32real,{$endif}s64currency]) or
-                    { win64 requires the double type cast for singles as well }
-                     ((tfloatdef(p.resultdef).floattype=s32real) and (target_info.system=system_x86_64_win64)) or
+                  if (tfloatdef(p.resultdef).floattype in [s32real,s64currency]) or
                      (is_constrealnode(p) and
                       not(nf_explicit in p.flags)) then
                     p:=ctypeconvnode.create(p,s64floattype);

+ 13 - 0
compiler/nset.pas

@@ -82,6 +82,7 @@ interface
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure buildderefimpl;override;
           procedure derefimpl;override;
+          procedure derefnode;override;
           function dogetcopy : tnode;override;
           procedure insertintolist(l : tnodelist);override;
           function pass_typecheck:tnode;override;
@@ -596,6 +597,18 @@ implementation
       end;
 
 
+    procedure tcasenode.derefnode;
+      var
+        i : integer;
+      begin
+        inherited derefnode;
+        if assigned(elseblock) then
+          elseblock.derefnode;
+        for i:=0 to blocks.count-1 do
+          pcaseblock(blocks[i])^.statement.derefnode;
+      end;
+
+
     function tcasenode.pass_typecheck : tnode;
       begin
         result:=nil;

+ 1 - 1
compiler/psub.pas

@@ -1417,7 +1417,7 @@ implementation
                   begin
                     Message1(parser_w_not_supported_for_inline,'nested procedures');
                     Message(parser_w_inlining_disabled);
-                    current_procinfo.procdef.proccalloption:=pocall_default;
+                    exclude(current_procinfo.procdef.procoptions,po_inline);
                   end;
               end;
             if not(df_generic in current_procinfo.procdef.defoptions) then

+ 4 - 1
compiler/systems/t_bsd.pas

@@ -588,7 +588,10 @@ begin
         StaticStr:='-static';
     end;
   if (cs_link_strip in current_settings.globalswitches) then
-    StripStr:='-s';
+    if (target_info.system in systems_darwin) then
+      StripStr:='-x'
+    else
+      StripStr:='-s';
 
   if (cs_link_smart in current_settings.globalswitches) and
      (tf_smartlink_sections in target_info.flags) then

+ 9 - 9
compiler/x86/x86ins.dat

@@ -2295,12 +2295,12 @@ xmmreg,mmxreg         \323\331\2\x0F\x2A\110          KATMAI,SSE,MMX
 mmxreg,mem            \301\331\2\x0F\x2D\110          KATMAI,SSE,MMX
 mmxreg,xmmreg         \323\331\2\x0F\x2D\110          KATMAI,SSE,MMX
 
-[CVTSI2SS]
+[CVTSI2SS,cvtsi2ssX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
 xmmreg,mem            \333\301\321\2\x0F\x2A\110      KATMAI,SSE
 xmmreg,reg32|64       \333\323\321\2\x0F\x2A\110      KATMAI,SSE
 
-[CVTSS2SI]
+[CVTSS2SI,cvtss2siX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
 reg32|64,mem          \333\301\320\2\x0F\x2D\110      KATMAI,SSE
 reg32|64,xmmreg       \333\323\320\2\x0F\x2D\110      KATMAI,SSE
@@ -2310,7 +2310,7 @@ reg32|64,xmmreg       \333\323\320\2\x0F\x2D\110      KATMAI,SSE
 mmxreg,mem            \301\331\2\x0F\x2C\110          KATMAI,SSE,MMX
 mmxreg,xmmreg         \323\331\2\x0F\x2C\110          KATMAI,SSE,MMX
 
-[CVTTSS2SI]
+[CVTTSS2SI,cvttss2siX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
 reg32|64,mem          \333\301\320\2\x0F\x2C\110      KATMAI,SSE
 reg32|64,xmmreg       \333\323\320\2\x0F\x2C\110      KATMAI,SSE
@@ -2660,7 +2660,7 @@ mem                     \300\323\2\x0F\xAE\207            WILLAMETTE,SSE2
 (Ch_All, Ch_None, Ch_None)
 mem,xmmreg              \1\x66\300\323\2\x0F\xE7\101        WILLAMETTE,SSE2,SM
 
-[MOVNTI]
+[MOVNTI,movntiX]
 (Ch_All, Ch_None, Ch_None)
 mem,reg32|64            \300\320\2\x0F\xC3\101        WILLAMETTE,SSE2,SM
 
@@ -2907,7 +2907,7 @@ xmmreg,mem              \301\1\x66\323\2\x0F\x5B\110    WILLAMETTE,SSE2,SM
 xmmreg,xmmreg           \323\2\x0F\x5A\110                  WILLAMETTE,SSE2
 xmmreg,mem              \301\323\2\x0F\x5A\110          WILLAMETTE,SSE2
 
-[CVTSD2SI]
+[CVTSD2SI,cvtsd2siX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
 reg32|64,xmmreg         \1\xF2\320\2\x0F\x2D\110        WILLAMETTE,SSE2
 reg32|64,mem            \301\1\xF2\320\2\x0F\x2D\110    WILLAMETTE,SSE2
@@ -2917,7 +2917,7 @@ reg32|64,mem            \301\1\xF2\320\2\x0F\x2D\110    WILLAMETTE,SSE2
 xmmreg,xmmreg           \1\xF2\323\2\x0F\x5A\110              WILLAMETTE,SSE2
 xmmreg,mem              \301\1\xF2\323\2\x0F\x5A\110    WILLAMETTE,SSE2
 
-[CVTSI2SD]
+[CVTSI2SD,cvtsi2sdX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
 xmmreg,reg32|64         \1\xF2\321\2\x0F\x2A\110        WILLAMETTE,SSE2
 xmmreg,mem              \301\1\xF2\321\2\x0F\x2A\110    WILLAMETTE,SSE2
@@ -2942,7 +2942,7 @@ xmmreg,mem              \301\1\x66\323\2\x0F\xE6\110    WILLAMETTE,SSE2,SM
 xmmreg,xmmreg           \333\323\2\x0F\x5B\110          WILLAMETTE,SSE2
 xmmreg,mem              \333\301\2\x0F\x5B\110          WILLAMETTE,SSE2,SM
 
-[CVTTSD2SI]
+[CVTTSD2SI,cvttsd2siX]
 (Ch_Wop2, Ch_Rop1, Ch_None)
 reg32|64,xmmreg         \1\xF2\320\2\x0F\x2C\110        WILLAMETTE,SSE2
 reg32|64,mem            \301\1\xF2\320\2\x0F\x2C\110    WILLAMETTE,SSE2
@@ -3271,12 +3271,12 @@ xmmreg,xmmreg           \110\334\76\2\x0F\x79\77                        SSE4
 xmmreg,imm,imm          \200\336\76\2\x0F\x78\77\375\21\375\22          SSE4,SB
 xmmreg,xmmreg           \110\336\76\2\x0F\x79\77                        SSE4
 
-[LZCNT]
+[LZCNT,lzcntX]
 (Ch_All, Ch_None, Ch_None)
 reg16,regmem            \110\320\333\301\76\2\x0F\xBD\77                386,SM,SSE4
 reg32|64,regmem         \110\321\333\301\76\2\x0F\xBD\77                386,SM,SSE4
 
-[POPCNT]
+[POPCNT,popcntX]
 (Ch_All, Ch_None, Ch_None)
 reg16,regmem            \110\320\333\301\76\2\x0F\xB8\77                386,SM,SSE4
 reg32|64,regmem         \110\321\333\301\76\2\x0F\xB8\77                386,SM,SSE4

+ 9 - 9
compiler/x86_64/x8664ats.inc

@@ -413,7 +413,10 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
+attsufINT,
+attsufINT,
 attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
@@ -477,6 +480,7 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
@@ -523,18 +527,14 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
+attsufINT,
 attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
-attsufNONE,
+attsufINT,
 attsufNONE,
 attsufNONE,
 attsufNONE,
@@ -599,6 +599,6 @@ attsufNONE,
 attsufNONE,
 attsufNONE,
 attsufNONE,
-attsufNONE,
-attsufNONE
+attsufINT,
+attsufINT
 );

+ 1 - 0
rtl/beos/sysos.inc

@@ -65,6 +65,7 @@ end;
 {$ifdef FPC_USE_LIBC}
   {$Linklib c}
   {$i oscdeclh.inc}
+  {$i oscdecl.inc}
 {$else}
   {$I syscallh.inc}
   {$I syscall.inc}

+ 1 - 0
rtl/bsd/sysos.inc

@@ -84,6 +84,7 @@ end;
 {$ifdef FPC_USE_LIBC}
   {$Linklib c}
   {$i oscdeclh.inc}
+  {$i oscdecl.inc}
 {$else}
   {$I syscallh.inc}
   {$I syscall.inc}

+ 18 - 8
rtl/darwin/i386/sig_cpu.inc

@@ -603,16 +603,26 @@
 
 *)
 
+    tdarwin_stack_t = record
+        ss_sp    : pchar;        { signal stack base }
+        ss_size  : clong;         { signal stack length }
+        ss_flags : cint;         { SA_DISABLE and/or SA_ONSTACK }
+    end;
+
     mcontext_t = record
       es: i386_exception_state_t;
-      ss: i386_thread_state_t;
+      ts: i386_thread_state_t;
       fs: i386_float_state_t;
     end;
 
-   psigcontext = ^sigcontextrec;
-   psigcontextrec = ^sigcontextrec;
-   sigcontextrec = record
-     sc_onstack: cint;
-     sc_mask: cint;
-     ts: i386_thread_state;
-   end;
+     psigcontext = ^sigcontextrec;
+     psigcontextrec = ^sigcontextrec;
+     sigcontextrec = record
+        uc_onstack : cint;
+        uc_sigmask : sigset_t;        { signal mask used by this context }
+        uc_stack   : tdarwin_stack_t; { stack used by this context }
+        uc_link    : psigcontextrec;  { pointer to resuming context }
+        uc_mcsize  : size_t;          { size of the machine context passed in }
+        uc_mcontext: ^mcontext_t;      { machine specific context }
+     end;
+

+ 39 - 8
rtl/darwin/i386/sighnd.inc

@@ -16,6 +16,7 @@
 procedure SignalToRunerror(Sig: cint; info : psiginfo; SigContext:PSigContext); cdecl;
 
 var
+  p: pbyte;
   res : word;
 
 begin
@@ -31,15 +32,35 @@ begin
           FPE_FLTRES,             { floating point inexact result }
           FPE_FLTINV : Res:=207;  { invalid floating point operation }
           Else
-            Res:=207; { coprocessor error }
+            begin
+              { Assume that if an integer divide was executed, the }
+              { error was a divide-by-zero (FPE_INTDIV is not      }
+              { implemented as of 10.5.0)                          }
+              p:=pbyte(sigcontext^.uc_mcontext^.ts.eip);
+              if assigned(p) then
+                begin
+                  { skip some prefix bytes }
+                  while (p^ in [$66,$67]) do
+                    inc(p);
+                  if (p^ in [$f6,$f7]) and
+                     (((p+1)^ and (%110 shl 3)) = (%110 shl 3)) then
+                    Res:=200
+                  else
+                    Res:=207; { coprocessor error }
+                end
+              else
+                Res:=207;
+            end;
         end;
-        { the following is true on ppc, but fortunately not on x86 }
-        { FPU exceptions are completely disabled by the kernel if one occurred, it  }
-        { seems this is necessary to be able to return to user mode. They can be    }
-        { enabled by executing a sigreturn, however then the exception is triggered }
-        { triggered again immediately if we don't turn off the "exception occurred" }
-        { flags in fpscr                                                            }
+        { make sure any fpu operations won't trigger new exceptions in handler }
         sysResetFPU;
+        { Now clear exception flags in the context }
+        { perform an fnclex: clear exception and busy flags }
+        sigcontext^.uc_mcontext^.fs.fpu_fsw.flag0:=
+          sigcontext^.uc_mcontext^.fs.fpu_fsw.flag0 and (not(%11111111) and not(1 shl 15));
+        { also clear sse exception flags }
+        sigcontext^.uc_mcontext^.fs.fpu_mxcsr:=
+          sigcontext^.uc_mcontext^.fs.fpu_mxcsr and not(%111111)
       end;
     SIGILL,
     SIGBUS,
@@ -51,6 +72,16 @@ begin
   {$endif }
 
   if (res <> 0) then
-    HandleErrorAddrFrame(res,pointer(sigcontext^.ts.eip),pointer(sigcontext^.ts.ebp));
+    begin
+      { assume regcall calling convention is the default }
+      sigcontext^.uc_mcontext^.ts.eax:=res;
+      sigcontext^.uc_mcontext^.ts.edx:=sigcontext^.uc_mcontext^.ts.eip;
+      sigcontext^.uc_mcontext^.ts.ecx:=sigcontext^.uc_mcontext^.ts.ebp;
+      { the ABI expects the stack pointer to be 4 bytes off alignment }
+      { due to the return address which has been pushed               }
+      dec(sigcontext^.uc_mcontext^.ts.esp,sizeof(pointer));
+      { return to run time error handler }
+      sigcontext^.uc_mcontext^.ts.eip:=ptruint(@HandleErrorAddrFrame);
+    end;
 end;
 

+ 1 - 32
rtl/darwin/unxconst.inc

@@ -71,36 +71,5 @@ Const
   STAT_IWUSR = STAT_IWOTH shl 6;
   STAT_IXUSR = STAT_IXOTH shl 6;
 
-  { Constants to test the type of filesystem }
-  fs_old_ext2 = $ef51;
-  fs_ext2     = $ef53;
-  fs_ext      = $137d;
-  fs_iso      = $9660;
-  fs_minix    = $137f;
-  fs_minix_30 = $138f;
-  fs_minux_V2 = $2468;
-  fs_msdos    = $4d44;
-  fs_nfs      = $6969;
-  fs_proc     = $9fa0;
-  fs_xia      = $012FD16D;
-
   {Constansts Termios/Ioctl (used in Do_IsDevice) }
-  IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
-
-  {Checked for BSD using Linuxthreads port}
-  { cloning flags }
-  CSIGNAL       = $000000ff; // signal mask to be sent at exit
-  CLONE_VM      = $00000100; // set if VM shared between processes
-  CLONE_FS      = $00000200; // set if fs info shared between processes
-  CLONE_FILES   = $00000400; // set if open files shared between processes
-  CLONE_SIGHAND = $00000800; // set if signal handlers shared
-  CLONE_PID     = $00001000; // set if pid shared
-
-  ITimer_Real    =0;
-  ITimer_Virtual =1;
-  ITimer_Prof    =2;
-
-type
-  TCloneFunc=function(args:pointer):longint;cdecl;
-
-
+  IOCtl_TCGETS=$40000000+$2C7400+19; // TCGETS is also in termios.inc (as TIOCGETA), but the sysunix needs only this

+ 1 - 1
rtl/inc/cgeneric.inc

@@ -98,7 +98,7 @@ function CompareChar0(Const buf1,buf2;len:sizeint):sizeint;{$ifdef SYSTEMINLINE}
 begin
   if len <= 0 then
     exit(0);
-  strncmp_comparechar0(buf1,buf2,len);
+  CompareChar0:=strncmp_comparechar0(buf1,buf2,len);
 end;
 
 {$endif not FPC_SYSTEM_HAS_COMPARECHAR0}

+ 4 - 2
rtl/inc/cgenmath.inc

@@ -14,7 +14,9 @@
  **********************************************************************}
 
 { for 80x86, we can easily write the optimal inline code }
-{$ifndef cpui386}
+{ Furthermore, the routines below only go up to double   }
+{ precision and we need extended precision if supported  }
+{$ifndef FPC_HAS_TYPE_EXTENDED}
 
 {$ifndef SOLARIS}
 
@@ -162,5 +164,5 @@
     end;
 {$endif}
 
-{$endif not i386}
+{$endif not FPC_HAS_TYPE_EXTENDED}
 

+ 1 - 0
rtl/linux/sysos.inc

@@ -61,6 +61,7 @@ end;
 {$ifdef FPC_USE_LIBC}
   {$Linklib c}
   {$i oscdeclh.inc}
+  {$i oscdecl.inc}
 {$else}
   {$I syscallh.inc}
   {$I syscall.inc}

+ 1 - 0
rtl/solaris/sysos.inc

@@ -40,6 +40,7 @@ end;
 
 {$Linklib c}
 {$i oscdeclh.inc}
+{$i oscdecl.inc}
 
 {*****************************************************************************
                             Error conversion

+ 3 - 1
rtl/unix/baseunix.pp

@@ -76,7 +76,9 @@ Uses Sysctl;
 {$I gensigset.inc}     // general sigset funcs implementation.
 {$I genfdset.inc}      // general fdset funcs.
 
-{$ifndef FPC_USE_LIBC}
+{$ifdef FPC_USE_LIBC}
+  {$i oscdecl.inc}        // implementation of wrappers in oscdeclh.inc
+{$else}
   {$i syscallh.inc}       // do_syscall declarations themselves
   {$i sysnr.inc}          // syscall numbers.
   {$i bsyscall.inc}       // cpu specific syscalls

+ 6 - 6
rtl/unix/cthreads.pp

@@ -869,16 +869,16 @@ begin
         result := wrError;
 {$else}
       timespec.tv_sec:=0;
-      { 500 miliseconds or less -> wait once for this duration }
-      if (timeout <= 500) then
+      { 50 miliseconds or less -> wait once for this duration }
+      if (timeout <= 50) then
         loopcnt:=1
-      { otherwise wake up every 500 msecs to check   }
+      { otherwise wake up every 50 msecs to check    }
       { (we'll wait a little longer in total because }
       {  we don't take into account the overhead)    }
       else
         begin
-          loopcnt := timeout div 500;
-          timespec.tv_nsec:=500*1000000;
+          loopcnt := timeout div 50;
+          timespec.tv_nsec:=50*1000000;
         end;
       result := wrTimeOut;
       nanores := 0;
@@ -887,7 +887,7 @@ begin
         begin
           { in the last iteration, wait for the amount of time left }
           if (i = loopcnt) then
-            timespec.tv_nsec:=(timeout mod 500) * 1000000;
+            timespec.tv_nsec:=(timeout mod 50) * 1000000;
           timetemp:=timespec;
           lastloop:=false;
           { every time our sleep is interrupted for whatever reason, }

+ 2 - 2
rtl/unix/cwstring.pp

@@ -104,8 +104,8 @@ type
 {$ifndef beos}
 function nl_langinfo(__item:nl_item):pchar;cdecl;external libiconvname name 'nl_langinfo';
 {$endif}
-{ $ ifndef bsd}
-{$if not defined(bsd) and not defined(beos)}
+
+{$if (not defined(bsd) and not defined(beos)) or defined(darwin)}
 function iconv_open(__tocode:pchar; __fromcode:pchar):iconv_t;cdecl;external libiconvname name 'iconv_open';
 function iconv(__cd:iconv_t; __inbuf:ppchar; __inbytesleft:psize_t; __outbuf:ppchar; __outbytesleft:psize_t):size_t;cdecl;external libiconvname name 'iconv';
 function iconv_close(__cd:iconv_t):cint;cdecl;external libiconvname name 'iconv_close';

+ 27 - 0
rtl/unix/oscdecl.inc

@@ -0,0 +1,27 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2007 by the Free Pascal development team
+    
+    This file should become an alternative to the syscalls in due time,
+    to import the base calls from libc.
+    Be very careful though. Kernel types and libc types are often not the
+    same on Linux.
+    
+    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.
+                                              
+ ***********************************************************************}
+
+{$if defined(bsd) or defined(solaris)}
+function  real_FpIOCtl   (Handle:cint;Ndx: TIOCtlRequest):cint; cdecl; varargs; external clib name 'ioctl';
+
+function  FpIOCtl   (Handle:cint;Ndx: TIOCtlRequest;Data: Pointer):cint;
+begin
+  FpIOCtl:=real_FpIOCtl(Handle, Ndx, Data);
+end;
+{$endif bsd or solaris}
+

+ 8 - 1
rtl/unix/oscdeclh.inc

@@ -1,6 +1,6 @@
 {
     This file is part of the Free Pascal run time library.
-    Copyright (c) 2001 by Free Pascal development team
+    Copyright (c) 2001 by the Free Pascal development team
 
     This file should become an alternative to the syscalls in due time,
     to import the base calls from libc.
@@ -74,7 +74,14 @@ const
     procedure FpExit    (status : cint); cdecl; external clib name '_exit';
     function  fpmmap    (addr:pointer;len:size_t;prot:cint;flags:cint;fd:cint;ofs:off_t):pointer; cdecl; external clib name 'mmap'+suffix64bit;
     function  fpmunmap  (addr:pointer;len:size_t):cint; cdecl; external clib name 'munmap';
+{$if defined(bsd) or defined(solaris)}
+    { The BSD/Solaris version has "..." as third parameter -> wrap for }
+    { interface compatibility with Linux                               }
+    function  FpIOCtl   (Handle:cint;Ndx: TIOCtlRequest;Data: Pointer):cint;
+                                         {$ifdef FPC_IS_SYSTEM}forward;{$endif}
+{$else bsd or solaris}
     function  FpIOCtl   (Handle:cint;Ndx: TIOCtlRequest;Data: Pointer):cint; cdecl; external clib name 'ioctl';
+{$endif bsd or solaris}
 {$ifdef beos}
     Function  FPSelect  (N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint; cdecl; external 'net' name 'select';
 {$else}

+ 3 - 2
tests/tbs/tb0193.pp

@@ -4,14 +4,15 @@
 var
   stacksize : ptrint;external name '__stklen';
 
-function getstacksize:longint;assembler;
+function getstacksize:ptrint;assembler;
 asm
 {$ifdef CPUI386}
         movl    stacksize,%eax
 end ['EAX'];
 {$endif CPUI386}
 {$ifdef CPUX86_64}
-        movl    stacksize,%eax
+        movq    stacksize@GOTPCREL(%rip),%rax
+        movq    (%rax),%rax
 end ['EAX'];
 {$endif CPUX86_64}
 {$ifdef CPU68K}

+ 4 - 0
tests/tbs/tb0528.pp

@@ -1,4 +1,8 @@
 {%CPU=x86_64,powerpc64}
+{%skiptarget=darwin}
+
+{ darwin limits statically declared data structures to 32 bit for efficiency reasons }
+
 program tb0528;
 
 {This program tests if huge arrays work on 64-bit systems. I got the idea

+ 30 - 0
tests/test/tinline10.pp

@@ -0,0 +1,30 @@
+{$inline on}
+
+type
+  tr = record
+    l: longint;
+  end;
+  pr = ^tr;
+
+procedure test(r: pr); inline;
+begin
+  with r^ do
+    begin
+      l:=5;
+      exit;
+    end;
+end;
+
+function f: longint;
+var
+  r: tr;
+begin
+  f:=1;
+  test(@r);
+  f:=2;
+end;
+
+begin
+  if (f <> 2) then
+    halt(1);
+end.  

+ 3 - 3
tests/webtbs/tw0797a.pp

@@ -10,11 +10,11 @@ var
   var
     i : longint;
   asm
-    movl j,%ebx
-    movl (%ebx),%eax
+    movl j,%ecx
+    movl (%ecx),%eax
     movl $5,i
     addl i,%eax
-    movl %eax,(%ebx)
+    movl %eax,(%ecx)
   end;
 
 begin

+ 3 - 1
tests/webtbs/tw6767.pp

@@ -14,5 +14,7 @@ begin
   HaltOnNotReleased := true;
   CheckThread := TCheckConnThread.Create(false);
   CheckThread.Terminate;
-  CheckThread.Waitfor;
+  { not really clean, but waitfor is not possible since the thread may }
+  { already have freed itself                                          }
+  sleep(500);
 end.

+ 2 - 2
tests/webtbs/tw8153.pp

@@ -11,7 +11,7 @@ type
     procedure testatt; virtual;
   end;
 
-procedure tc.testintel; assembler;
+procedure tc.testintel; assembler; nostackframe;
 asm
   mov ecx,[eax]
   jmp [ecx + vmtoffset tc.v]
@@ -19,7 +19,7 @@ end;
 
 {$asmmode att}
 
-procedure tc.testatt; assembler;
+procedure tc.testatt; assembler; nostackframe;
 asm
   movl (%eax),%ecx
   jmpl +vmtoffset tc.v(%ecx)

+ 0 - 1
tests/webtbs/tw8195a.pp

@@ -76,7 +76,6 @@ end;
 function LabelOFFSET: Integer;
 asm
   mov eax, OFFSET @@Exit
-  ret
  @@Exit:
 end;