浏览代码

--- Merging r13696 through r13760 into '.':
U ide/fpusrscr.pas
U rtl/unix/video.pp
U rtl/i386/i386.inc
U rtl/win/wininc/defines.inc
U rtl/win/systhrd.inc
U rtl/linux/m68k/dllprt0.as
U rtl/linux/i386/syscall.inc
U rtl/linux/i386/dllprt0.as
U rtl/linux/i386/si_c.inc
U rtl/linux/i386/si_prc.inc
U rtl/linux/i386/si_c21.inc
U rtl/linux/i386/si_g.inc
U rtl/linux/i386/si_c21g.inc
U rtl/linux/i386/si_uc.inc
U rtl/linux/i386/si_dll.inc
U rtl/linux/x86_64/dllprt0.as
A tests/test/packages/hash/sha1test.pp
U tests/webtbs/tw12038.pp
U compiler/cclasses.pas
U compiler/symdef.pas
U compiler/ncon.pas
U compiler/ncgrtti.pas
U compiler/cgbase.pas
U compiler/pstatmnt.pas
U compiler/systems/t_linux.pas
U compiler/pass_1.pas
U compiler/x86/cgx86.pas
U compiler/x86/agx86att.pas
U compiler/x86/aasmcpu.pas
U compiler/aasmbase.pas
A packages/fcl-xml/tests/extras.pp
A packages/fcl-xml/tests/extras2.pp
--- Merging r13696 through r13760 into 'packages/fcl-xml/tests/README_DOM.txt':
U packages/fcl-xml/tests/README_DOM.txt
--- Merging r13696 through r13760 into '.':
U packages/fcl-xml/tests/domunit.pp
U packages/fcl-xml/src/xpath.pp
U packages/Makefile
U packages/gmp/src/gmp.pas
U packages/gmp/readme
U packages/fcl-db/src/base/db.pas
U packages/fcl-db/src/base/database.inc
U packages/sqlite/src/sqlite3.inc
U packages/fcl-web/src/custweb.pp
U packages/hash/fpmake.pp
U packages/hash/Makefile.fpc
A packages/hash/src/sha1.pp
U packages/hash/Makefile
U packages/hash/examples/Makefile.fpc
A packages/hash/examples/sha1test.pp
U packages/hash/examples/Makefile
U packages/Makefile.fpc
U packages/fcl-base/src/ascii85.pp
U packages/fcl-base/src/custapp.pp
U packages/chm/src/chmwriter.pas
U packages/chm/src/paslzx.pas
U packages/chm/src/chmreader.pas
--- Merging r13761 into '.':
U compiler/powerpc/agppcvasm.pas
U compiler/ppcgen/agppcgas.pas

git-svn-id: branches/objc@13762 -

Jonas Maebe 16 年之前
父节点
当前提交
d34276c575
共有 59 个文件被更改,包括 2255 次插入632 次删除
  1. 5 0
      .gitattributes
  2. 11 4
      compiler/aasmbase.pas
  3. 1 0
      compiler/cclasses.pas
  4. 2 1
      compiler/cgbase.pas
  5. 3 12
      compiler/ncgrtti.pas
  6. 16 4
      compiler/ncon.pas
  7. 9 9
      compiler/pass_1.pas
  8. 4 4
      compiler/powerpc/agppcvasm.pas
  9. 4 4
      compiler/ppcgen/agppcgas.pas
  10. 47 45
      compiler/pstatmnt.pas
  11. 5 0
      compiler/symdef.pas
  12. 2 2
      compiler/systems/t_linux.pas
  13. 1 1
      compiler/x86/aasmcpu.pas
  14. 1 1
      compiler/x86/agx86att.pas
  15. 57 11
      compiler/x86/cgx86.pas
  16. 10 0
      ide/fpusrscr.pas
  17. 80 18
      packages/Makefile
  18. 5 5
      packages/Makefile.fpc
  19. 3 3
      packages/chm/src/chmreader.pas
  20. 1 1
      packages/chm/src/chmwriter.pas
  21. 1 1
      packages/chm/src/paslzx.pas
  22. 1 1
      packages/fcl-base/src/ascii85.pp
  23. 2 0
      packages/fcl-base/src/custapp.pp
  24. 6 0
      packages/fcl-db/src/base/database.inc
  25. 2 1
      packages/fcl-db/src/base/db.pas
  26. 11 7
      packages/fcl-web/src/custweb.pp
  27. 6 0
      packages/fcl-xml/src/xpath.pp
  28. 9 4
      packages/fcl-xml/tests/README_DOM.txt
  29. 16 2
      packages/fcl-xml/tests/domunit.pp
  30. 123 0
      packages/fcl-xml/tests/extras.pp
  31. 313 0
      packages/fcl-xml/tests/extras2.pp
  32. 8 0
      packages/gmp/readme
  33. 3 0
      packages/gmp/src/gmp.pas
  34. 59 59
      packages/hash/Makefile
  35. 1 1
      packages/hash/Makefile.fpc
  36. 59 59
      packages/hash/examples/Makefile
  37. 1 1
      packages/hash/examples/Makefile.fpc
  38. 38 0
      packages/hash/examples/sha1test.pp
  39. 4 0
      packages/hash/fpmake.pp
  40. 305 0
      packages/hash/src/sha1.pp
  41. 20 21
      packages/sqlite/src/sqlite3.inc
  42. 12 0
      rtl/i386/i386.inc
  43. 7 3
      rtl/linux/i386/dllprt0.as
  44. 90 11
      rtl/linux/i386/si_c.inc
  45. 141 58
      rtl/linux/i386/si_c21.inc
  46. 197 89
      rtl/linux/i386/si_c21g.inc
  47. 37 44
      rtl/linux/i386/si_dll.inc
  48. 15 3
      rtl/linux/i386/si_g.inc
  49. 86 19
      rtl/linux/i386/si_prc.inc
  50. 116 53
      rtl/linux/i386/si_uc.inc
  51. 219 53
      rtl/linux/i386/syscall.inc
  52. 6 3
      rtl/linux/m68k/dllprt0.as
  53. 7 3
      rtl/linux/x86_64/dllprt0.as
  54. 19 3
      rtl/unix/video.pp
  55. 2 1
      rtl/win/systhrd.inc
  56. 1 1
      rtl/win/wininc/defines.inc
  57. 38 0
      tests/test/packages/hash/sha1test.pp
  58. 1 0
      tests/test/tobjc1.pp
  59. 6 6
      tests/webtbs/tw12038.pp

+ 5 - 0
.gitattributes

@@ -1995,6 +1995,8 @@ packages/fcl-xml/tests/README.txt svneol=native#text/plain
 packages/fcl-xml/tests/README_DOM.txt svneol=native#text/plain
 packages/fcl-xml/tests/api.xml svneol=native#text/plain
 packages/fcl-xml/tests/domunit.pp svneol=native#text/plain
+packages/fcl-xml/tests/extras.pp svneol=native#text/plain
+packages/fcl-xml/tests/extras2.pp svneol=native#text/plain
 packages/fcl-xml/tests/template.xml svneol=native#text/plain
 packages/fcl-xml/tests/testgen.pp svneol=native#text/plain
 packages/fcl-xml/tests/xmlts.pp svneol=native#text/plain
@@ -2896,10 +2898,12 @@ packages/hash/examples/Makefile.fpc svneol=native#text/plain
 packages/hash/examples/crctest.pas svneol=native#text/plain
 packages/hash/examples/md5.ref svneol=native#text/plain
 packages/hash/examples/mdtest.pas svneol=native#text/plain
+packages/hash/examples/sha1test.pp svneol=native#text/plain
 packages/hash/fpmake.pp svneol=native#text/plain
 packages/hash/src/crc.pas svneol=native#text/plain
 packages/hash/src/md5.pp svneol=native#text/plain
 packages/hash/src/ntlm.pas svneol=native#text/plain
+packages/hash/src/sha1.pp svneol=native#text/plain
 packages/hash/src/unixcrypt.pas svneol=native#text/plain
 packages/hash/src/uuid.pas svneol=native#text/plain
 packages/hermes/Makefile svneol=native#text/plain
@@ -8368,6 +8372,7 @@ tests/test/packages/fcl-db/tdb6.pp svneol=native#text/plain
 tests/test/packages/fcl-db/toolsunit.pas svneol=native#text/plain
 tests/test/packages/fcl-registry/tregistry1.pp svneol=native#text/plain
 tests/test/packages/fcl-xml/thtmlwriter.pp svneol=native#text/plain
+tests/test/packages/hash/sha1test.pp svneol=native#text/plain
 tests/test/packages/hash/tmdtest.pp svneol=native#text/plain
 tests/test/packages/webtbs/tw10045.pp svneol=native#text/plain
 tests/test/packages/webtbs/tw11142.pp svneol=native#text/plain

+ 11 - 4
compiler/aasmbase.pas

@@ -354,11 +354,18 @@ implementation
 *****************************************************************************}
 
     constructor TAsmLabel.Createlocal(AList:TFPHashObjectList;nr:longint;ltyp:TAsmLabelType);
+      var
+        asmtyp: TAsmsymtype;
       begin
-        if ltyp=alt_addr then
-          inherited Create(AList,target_asm.labelprefix+asmlabeltypeprefix[ltyp]+tostr(nr),AB_LOCAL,AT_ADDR)
-        else
-          inherited Create(AList,target_asm.labelprefix+asmlabeltypeprefix[ltyp]+tostr(nr),AB_LOCAL,AT_LABEL);
+        case ltyp of
+          alt_addr:
+            asmtyp:=AT_ADDR;
+          alt_data:
+            asmtyp:=AT_DATA;
+          else
+            asmtyp:=AT_LABEL;
+        end;
+        inherited Create(AList,target_asm.labelprefix+asmlabeltypeprefix[ltyp]+tostr(nr),AB_LOCAL,asmtyp);
         labelnr:=nr;
         labeltype:=ltyp;
         is_set:=false;

+ 1 - 0
compiler/cclasses.pas

@@ -2014,6 +2014,7 @@ end;
         while assigned(NewNode) do
          begin
            Next:=NewNode.Next;
+           prefetch(next.next);
            NewNode.Free;
            NewNode:=Next;
           end;

+ 2 - 1
compiler/cgbase.pas

@@ -68,7 +68,8 @@ interface
        trefaddr = (
          addr_no,
          addr_full,
-         addr_pic
+         addr_pic,
+         addr_pic_no_got
          {$IF defined(POWERPC) or defined(POWERPC64) or defined(SPARC)}
          ,
          addr_low,         // bits 48-63

+ 3 - 12
compiler/ncgrtti.pas

@@ -681,18 +681,9 @@ implementation
                { write parameter info. The parameters must be written in reverse order
                  if this method uses right to left parameter pushing! }
                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(def.maxparacount));
-{$ifdef i386}
-               if def.proccalloption in pushleftright_pocalls then
-                 begin
-                   for i:=0 to def.paras.count-1 do
-                     write_para(tparavarsym(def.paras[i]));
-                 end
-               else
-{$endif}
-                 begin
-                   for i:=def.paras.count-1 downto 0 do
-                     write_para(tparavarsym(def.paras[i]));
-                 end;
+
+               for i:=0 to def.paras.count-1 do
+                 write_para(tparavarsym(def.paras[i]));
 
                { write name of result type }
                write_rtti_name(def.returndef);

+ 16 - 4
compiler/ncon.pas

@@ -244,7 +244,6 @@ implementation
         pWideStringVal: pcompilerwidestring;
         ordValRecord: TConstExprInt;
       begin
-        get_string_value := '';
         if is_conststring_or_constcharnode(p) then
           begin
             if is_constcharnode(p) or is_constwidecharnode(p) then
@@ -277,7 +276,11 @@ implementation
                 if is_wide then
                   begin
                     if (tstringconstnode(p).cst_type in [cst_widestring, cst_unicodestring]) then
-                      get_string_value := tstringconstnode(p).value_str
+                      begin
+                        initwidestring(pWideStringVal);
+                        copywidestring(pcompilerwidestring(tstringconstnode(p).value_str), pWideStringVal);
+                        get_string_value := TConstString(pWideStringVal);
+                      end
                     else
                       { if string must be wide, but actually was parsed as usual }
                       begin
@@ -297,12 +300,21 @@ implementation
                         get_string_value := pCharVal;
                       end
                     else
-                      get_string_value := tstringconstnode(p).value_str;
+                      begin
+                        getmem(pCharVal, tstringconstnode(p).len + 1);
+                        move(tstringconstnode(p).value_str^, pCharVal^, tstringconstnode(p).len);
+                        pCharVal[tstringconstnode(p).len] := #0;
+                        get_string_value := pCharVal;
+                      end;
                   end;
               end;
           end
         else
-          Message(type_e_string_expr_expected);
+          begin
+            Message(type_e_string_expr_expected);
+            getmem(get_string_value, 1);
+            get_string_value[0] := #0;
+          end;
       end;
 
     function is_constresourcestringnode(p : tnode) : boolean;

+ 9 - 9
compiler/pass_1.pas

@@ -83,10 +83,10 @@ implementation
             begin
                node_changed:=true;
                p.free;
-               { run typecheckpass }
-               typecheckpass(hp);
                { switch to new node }
                p:=hp;
+               { run typecheckpass }
+               typecheckpass(p);
             end;
            current_settings.localswitches:=oldlocalswitches;
            current_filepos:=oldpos;
@@ -164,10 +164,10 @@ implementation
                  if assigned(hp) then
                   begin
                      p.free;
-                     { run typecheckpass }
-                     typecheckpass(hp);
                      { switch to new node }
                      p:=hp;
+                     { run typecheckpass }
+                     typecheckpass(p);
                   end;
                  if codegenerror then
                   begin
@@ -186,10 +186,10 @@ implementation
                  if assigned(hp) then
                   begin
                     p.free;
-                    { run firstpass }
-                    firstpass(hp);
                     { switch to new node }
-                    p:=hp;
+                    p := hp;
+                    { run firstpass }
+                    firstpass(p);
                   end
                  else
                    begin
@@ -199,8 +199,8 @@ implementation
                      if assigned(hp) then
                        begin
                          p.free;
-                         firstpass(hp);
-                         p:=hp;
+                         p := hp;
+                         firstpass(p);
                        end;
                    end;
                  if codegenerror then

+ 4 - 4
compiler/powerpc/agppcvasm.pas

@@ -66,13 +66,13 @@ unit agppcvasm;
 
 {$ifdef cpu64bitaddr}
     const
-      refaddr2str: array[trefaddr] of string[9] = ('', '', '', '@l', '@h', '@higher', '@highest', '@ha', '@highera', '@highesta');
+      refaddr2str: array[trefaddr] of string[9] = ('', '', '', '', '@l', '@h', '@higher', '@highest', '@ha', '@highera', '@highesta');
       verbose_refaddrs = [addr_low, addr_high, addr_higher, addr_highest, addr_higha, addr_highera, addr_highesta];
-      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','lo16', 'hi16', '@err', '@err', 'ha16', '@err', '@err');
+      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','','lo16', 'hi16', '@err', '@err', 'ha16', '@err', '@err');
 {$else cpu64bitaddr}
     const
-      refaddr2str: array[trefaddr] of string[3] = ('','','','@l','@h','@ha');
-      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','lo16','hi16','ha16');
+      refaddr2str: array[trefaddr] of string[3] = ('','','','','@l','@h','@ha');
+      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','','lo16','hi16','ha16');
       verbose_refaddrs = [addr_low,addr_high,addr_higha];
 {$endif cpu64bitaddr}
 

+ 4 - 4
compiler/ppcgen/agppcgas.pas

@@ -71,13 +71,13 @@ unit agppcgas;
 
 {$ifdef cpu64bitaddr}
     const
-      refaddr2str: array[trefaddr] of string[9] = ('', '', '', '@l', '@h', '@higher', '@highest', '@ha', '@highera', '@highesta');
+      refaddr2str: array[trefaddr] of string[9] = ('', '', '', '', '@l', '@h', '@higher', '@highest', '@ha', '@highera', '@highesta');
       verbose_refaddrs = [addr_low, addr_high, addr_higher, addr_highest, addr_higha, addr_highera, addr_highesta];
-      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','lo16', 'hi16', '@err', '@err', 'ha16', '@err', '@err');
+      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','','lo16', 'hi16', '@err', '@err', 'ha16', '@err', '@err');
 {$else cpu64bitaddr}
     const
-      refaddr2str: array[trefaddr] of string[3] = ('','','','@l','@h','@ha');
-      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','lo16','hi16','ha16');
+      refaddr2str: array[trefaddr] of string[3] = ('','','','','@l','@h','@ha');
+      refaddr2str_darwin: array[trefaddr] of string[4] = ('','','','','lo16','hi16','ha16');
       verbose_refaddrs = [addr_low,addr_high,addr_higha];
 {$endif cpu64bitaddr}
 

+ 47 - 45
compiler/pstatmnt.pas

@@ -187,60 +187,62 @@ implementation
              sl2:='';
              if (p.nodetype=rangen) then
                begin
-                  { type check for string case statements }
-                  if caseofstring and
-                    is_conststring_or_constcharnode(trangenode(p).left) and
-                    is_conststring_or_constcharnode(trangenode(p).right) then
-                  begin
-                    sl1 := get_string_value(trangenode(p).left, is_wide_or_unicode_string(casedef));
-                    sl2 := get_string_value(trangenode(p).right, is_wide_or_unicode_string(casedef));
-                    if (
-                      (is_wide_or_unicode_string(casedef) and (
-                        comparewidestrings(pcompilerwidestring(sl1), pcompilerwidestring(sl2)) > 0)) or
-                      ((not is_wide_or_unicode_string(casedef)) and (strcomp(sl1, sl2) > 0))) then
-                      CGMessage(parser_e_case_lower_less_than_upper_bound);
-                  end
-                  { type checking for ordinal case statements }
-                  else if (not caseofstring) and
-                    is_subequal(casedef, trangenode(p).left.resultdef) and
-                    is_subequal(casedef, trangenode(p).right.resultdef) then
-                    begin
-                      hl1:=get_ordinal_value(trangenode(p).left);
-                      hl2:=get_ordinal_value(trangenode(p).right);
-                      if hl1>hl2 then
-                        CGMessage(parser_e_case_lower_less_than_upper_bound);
-                      if not casedeferror then
+                 { type check for string case statements }
+                 if caseofstring and
+                   is_conststring_or_constcharnode(trangenode(p).left) and
+                   is_conststring_or_constcharnode(trangenode(p).right) then
+                 begin
+                   sl1 := get_string_value(trangenode(p).left, is_wide_or_unicode_string(casedef));
+                   sl2 := get_string_value(trangenode(p).right, is_wide_or_unicode_string(casedef));
+                   if (
+                     (is_wide_or_unicode_string(casedef) and (
+                       comparewidestrings(pcompilerwidestring(sl1), pcompilerwidestring(sl2)) > 0)) or
+                     ((not is_wide_or_unicode_string(casedef)) and (strcomp(sl1, sl2) > 0))) then
+                     CGMessage(parser_e_case_lower_less_than_upper_bound);
+                 end
+                 { type checking for ordinal case statements }
+                 else if (not caseofstring) and
+                   is_subequal(casedef, trangenode(p).left.resultdef) and
+                   is_subequal(casedef, trangenode(p).right.resultdef) then
+                   begin
+                     hl1:=get_ordinal_value(trangenode(p).left);
+                     hl2:=get_ordinal_value(trangenode(p).right);
+                     if hl1>hl2 then
+                       CGMessage(parser_e_case_lower_less_than_upper_bound);
+                     if not casedeferror then
                        begin
                          testrange(casedef,hl1,false);
                          testrange(casedef,hl2,false);
                        end;
-                    end
-                  else
-                    CGMessage(parser_e_case_mismatch);
+                   end
+                 else
+                   CGMessage(parser_e_case_mismatch);
 
-                  if caseofstring then
-                    casenode.addlabel(blockid,sl1,sl2,st2cst[tstringdef(casedef).stringtype])
-                  else
-                    casenode.addlabel(blockid,hl1,hl2);
+                 if caseofstring then
+                   casenode.addlabel(blockid,sl1,sl2,st2cst[tstringdef(casedef).stringtype])
+                 else
+                   casenode.addlabel(blockid,hl1,hl2);
                end
              else
                begin                
-                  { type check for string case statements }
-                  if (caseofstring and (not is_conststring_or_constcharnode(p))) or
-                  { type checking for ordinal case statements }
-                    ((not caseofstring) and (not is_subequal(casedef, p.resultdef))) then
-                    CGMessage(parser_e_case_mismatch);
+                 { type check for string case statements }
+                 if (caseofstring and (not is_conststring_or_constcharnode(p))) or
+                 { type checking for ordinal case statements }
+                   ((not caseofstring) and (not is_subequal(casedef, p.resultdef))) then
+                   CGMessage(parser_e_case_mismatch);
                   
-                  if caseofstring then begin
-                    sl1:=get_string_value(p, is_wide_or_unicode_string(casedef));
-                    casenode.addlabel(blockid,sl1,sl1,st2cst[tstringdef(casedef).stringtype]);
-                  end
-                  else begin
-                    hl1:=get_ordinal_value(p);
-                    if not casedeferror then
-                      testrange(casedef,hl1,false);
-                    casenode.addlabel(blockid,hl1,hl1);
-                  end;
+                 if caseofstring then
+                   begin
+                     sl1:=get_string_value(p, is_wide_or_unicode_string(casedef));
+                     casenode.addlabel(blockid,sl1,sl1,st2cst[tstringdef(casedef).stringtype]);
+                   end
+                 else
+                   begin
+                     hl1:=get_ordinal_value(p);
+                     if not casedeferror then
+                       testrange(casedef,hl1,false);
+                     casenode.addlabel(blockid,hl1,hl1);
+                   end;
                end;
              p.free;
              if token=_COMMA then

+ 5 - 0
compiler/symdef.pas

@@ -4616,6 +4616,11 @@ implementation
     function TImplementedInterface.getcopy:TImplementedInterface;
       begin
         Result:=TImplementedInterface.Create(nil);
+        {$warning: this is completely wrong on so many levels...}
+        { 1) the procdefs list will be freed once for each copy
+          2) since the procdefs list owns its elements, those will also be freed for each copy
+          3) idem for the name mappings
+        }
         Move(pointer(self)^,pointer(result)^,InstanceSize);
       end;
 

+ 2 - 2
compiler/systems/t_linux.pas

@@ -1074,8 +1074,8 @@ begin
 
  { Create some replacements }
  { note: linux does not use exportlib.initname/fininame due to the custom startup code }
-  InitStr:='-init FPC_LIB_START';
-  FiniStr:='-fini FPC_LIB_EXIT';
+  InitStr:='-init FPC_SHARED_LIB_START';
+  FiniStr:='-fini FPC_SHARED_LIB_EXIT';
   SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename^);
 
 { Call linker }

+ 1 - 1
compiler/x86/aasmcpu.pas

@@ -931,7 +931,7 @@ implementation
                   if (ref^.refaddr=addr_no)
 {$ifdef x86_64}
                      or (
-                         (ref^.refaddr=addr_pic) and
+                         (ref^.refaddr in [addr_pic,addr_pic_no_got]) and
                          (ref^.base<>NR_NO)
                         )
 {$endif x86_64}

+ 1 - 1
compiler/x86/agx86att.pas

@@ -162,7 +162,7 @@ interface
           top_reg :
             owner.AsmWrite(gas_regname(o.reg));
           top_ref :
-            if o.ref^.refaddr in [addr_no,addr_pic] then
+            if o.ref^.refaddr in [addr_no,addr_pic,addr_pic_no_got] then
               WriteReference(o.ref^)
             else
               begin

+ 57 - 11
compiler/x86/cgx86.pas

@@ -386,13 +386,41 @@ unit cgx86;
           begin
             if cs_create_pic in current_settings.moduleswitches then
               begin
-                reference_reset_symbol(href,ref.symbol,0,sizeof(pint));
-                hreg:=getaddressregister(list);
-                href.refaddr:=addr_pic;
-                href.base:=NR_RIP;
-                list.concat(taicpu.op_ref_reg(A_MOV,S_Q,href,hreg));
+                if (ref.symbol.bind=AB_LOCAL) and
+                   (ref.symbol.typ=AT_DATA) then
+                  begin
+                    { Local data symbols don't have to go via the GOT (and in
+                      case of darwin must not in some cases), but they still
+                      have to be addressed using PIC (RIP-relative).
+                    }
+                    { unfortunately, RIP-based addresses don't support an index }
+                    if (ref.base<>NR_NO) or
+                       (ref.index<>NR_NO) then
+                      begin
+                        reference_reset_symbol(href,ref.symbol,0,sizeof(pint));
+                        hreg:=getaddressregister(list);
+                        href.refaddr:=addr_pic_no_got;
+                        href.base:=NR_RIP;
+                        list.concat(taicpu.op_ref_reg(A_LEA,S_Q,href,hreg));
+                        ref.symbol:=nil;
+                      end
+                    else
+                      begin
+                        ref.refaddr:=addr_pic_no_got;
+                        hreg:=NR_NO;
+                        ref.base:=NR_RIP;
+                      end;
+                  end
+                else
+                  begin
+                    reference_reset_symbol(href,ref.symbol,0,sizeof(pint));
+                    hreg:=getaddressregister(list);
+                    href.refaddr:=addr_pic;
+                    href.base:=NR_RIP;
+                    list.concat(taicpu.op_ref_reg(A_MOV,S_Q,href,hreg));
 
-                ref.symbol:=nil;
+                    ref.symbol:=nil;
+                  end;
 
                 if ref.base=NR_NO then
                   ref.base:=hreg
@@ -408,17 +436,21 @@ unit cgx86;
                   end;
               end
             else
-              { Always use RIP relative symbol addressing for Windows targets. }
-              if (target_info.system in system_all_windows) and (ref.base<>NR_RIP) then
+              { Always use RIP relative symbol addressing for Windows and Darwin targets. }
+              if (target_info.system in (system_all_windows+[system_x86_64_darwin])) and (ref.base<>NR_RIP) then
                 begin
                   if (ref.refaddr=addr_no) and (ref.base=NR_NO) and (ref.index=NR_NO) then
-                    { Set RIP relative addressing for simple symbol references }
-                    ref.base:=NR_RIP
+                    begin
+                      { Set RIP relative addressing for simple symbol references }
+                      ref.base:=NR_RIP;
+                      ref.refaddr:=addr_pic_no_got
+                    end
                   else
                     begin
                       { Use temp register to load calculated 64-bit symbol address for complex references }
                       reference_reset_symbol(href,ref.symbol,0,sizeof(pint));
                       href.base:=NR_RIP;
+                      href.refaddr:=addr_pic_no_got;
                       hreg:=GetAddressRegister(list);
                       list.concat(taicpu.op_ref_reg(A_LEA,S_Q,href,hreg));
                       ref.symbol:=nil;
@@ -874,7 +906,11 @@ unit cgx86;
                            list.concat(Taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],tmpref,r));
                          end;
                       end
-                    else if (cs_create_pic in current_settings.moduleswitches) then
+                    else if (cs_create_pic in current_settings.moduleswitches)
+{$ifdef x86_64}
+                             and not((ref.symbol.bind=AB_LOCAL) and (ref.symbol.typ=AT_DATA))
+{$endif x86_64}
+                            then
                       begin
 {$ifdef x86_64}
                         reference_reset_symbol(tmpref,ref.symbol,0,ref.alignment);
@@ -891,6 +927,16 @@ unit cgx86;
                         if offset<>0 then
                           a_op_const_reg(list,OP_ADD,OS_ADDR,offset,r);
                       end
+{$ifdef x86_64}
+                    else if (target_info.system in (system_all_windows+[system_x86_64_darwin])) then
+                      begin
+                        { Win64 and Darwin/x86_64 always require RIP-relative addressing }
+                        tmpref:=ref;
+                        tmpref.base:=NR_RIP;
+                        tmpref.refaddr:=addr_pic_no_got;
+                        list.concat(Taicpu.op_ref_reg(A_LEA,S_Q,tmpref,r));
+                      end
+{$endif x86_64}
                     else
                       begin
                         tmpref:=ref;

+ 10 - 0
ide/fpusrscr.pas

@@ -24,6 +24,9 @@ uses
 {$ifdef Unix}
   baseunix,
   termio,
+{$ifdef linux}
+  linuxvcs,
+{$endif}
 {$endif}
   video,Objects;
 
@@ -755,10 +758,17 @@ begin
           Case ThisTTY[9] of
             '0'..'9' :
               begin { running Linux on native console or native-emulation }
+{$ifdef linux}
                 FName:='/dev/vcsa' + ThisTTY[9];
                 TTYFd:=fpOpen(FName, &666, O_RdWr); { open console }
+                if TTYFd = -1 then
+                begin
+                  if try_grab_vcsa then
+                    TTYFd:=fpOpen(FName, &666, O_RdWr); { try again }
+                end;
                 If TTYFd <>-1 Then
                   Console:=ttyLinux;
+{$endif}
               end;
          'v'  :  { check for (Free?)BSD native}
                 If (ThisTTY[10]>='0') and (ThisTTY[10]<='9') Then

+ 80 - 18
packages/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/14]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/20]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
@@ -265,19 +265,19 @@ UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
 endif
 PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph libc unixutil graph pxlib
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph libc unixutil graph pxlib
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv graph unzip gdbint
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick gdbint libpng mad tcl opengl gtk1 gtk2 librsvg a52 cdrom fpgtk openal fftw lua oggvorbis sdl openssl graph pcap httpd13 httpd20 httpd22 pxlib numlib winceunits cairo libxml
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick gdbint libpng mad tcl opengl gtk1 gtk2 librsvg a52 cdrom fpgtk openal fftw lua oggvorbis sdl openssl graph pcap httpd13 httpd20 httpd22 pxlib numlib winceunits cairo libxml gmp
 endif
 ifeq ($(FULL_TARGET),i386-os2)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv zlib libpng x11 tcl fpgtk rexx os2units gtk1 imlib
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib users iconvenc
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib users iconvenc gmp
 endif
 ifeq ($(FULL_TARGET),i386-beos)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib iconvenc
@@ -304,7 +304,7 @@ ifeq ($(FULL_TARGET),i386-wdosx)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc graph univint cocoaint sdl opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms  gnome1 httpd13 httpd20 httpd22 imlib opengles objcrtl
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc gmp graph univint cocoaint sdl opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms  gnome1 httpd13 httpd20 httpd22 imlib opengles objcrtl
 endif
 ifeq ($(FULL_TARGET),i386-emx)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv zlib libpng x11 tcl fpgtk rexx os2units gtk1 imlib
@@ -325,10 +325,10 @@ ifeq ($(FULL_TARGET),i386-symbian)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib users iconvenc
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib users iconvenc gmp
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib
@@ -349,7 +349,7 @@ ifeq ($(FULL_TARGET),m68k-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib
@@ -361,7 +361,7 @@ ifeq ($(FULL_TARGET),powerpc-macos)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc graph univint cocoaint sdl opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib objcrtl
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc gmp graph univint cocoaint sdl opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib objcrtl
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv opengl
@@ -370,7 +370,7 @@ ifeq ($(FULL_TARGET),powerpc-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib
@@ -382,13 +382,13 @@ ifeq ($(FULL_TARGET),sparc-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib users iconvenc
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib users iconvenc gmp
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc gmp opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick tcl opengl gtk1 fpgtk fftw sdl openssl cdrom httpd13 httpd20 httpd22 numlib
@@ -397,13 +397,13 @@ ifeq ($(FULL_TARGET),x86_64-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  palmunits
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc httpd13 httpd20 httpd22 opengles objcrtl
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc gmp httpd13 httpd20 httpd22 opengles objcrtl
 endif
 ifeq ($(FULL_TARGET),arm-wince)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  winceunits httpd22 fcl-web fastcgi tcl fftw unzip zlib sqlite mysql ibase postgres oracle odbc sdl openssl oggvorbis numlib
@@ -421,10 +421,10 @@ ifeq ($(FULL_TARGET),arm-symbian)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib graph
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp graph
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc gmp opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
@@ -433,7 +433,7 @@ ifeq ($(FULL_TARGET),avr-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib
+override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic  fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override TARGET_DIRS+=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
@@ -1618,6 +1618,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 TARGET_DIRS_LIBC=1
 TARGET_DIRS_UNIXUTIL=1
@@ -1711,6 +1712,7 @@ TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_WINCEUNITS=1
 TARGET_DIRS_CAIRO=1
 TARGET_DIRS_LIBXML=1
+TARGET_DIRS_GMP=1
 endif
 ifeq ($(FULL_TARGET),i386-os2)
 TARGET_DIRS_HASH=1
@@ -1812,6 +1814,7 @@ TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_USERS=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 endif
 ifeq ($(FULL_TARGET),i386-beos)
 TARGET_DIRS_HASH=1
@@ -2258,6 +2261,7 @@ TARGET_DIRS_PCAP=1
 TARGET_DIRS_OPENSSL=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 TARGET_DIRS_UNIVINT=1
 TARGET_DIRS_COCOAINT=1
@@ -2523,6 +2527,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
@@ -2593,6 +2598,7 @@ TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_USERS=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
 TARGET_DIRS_HASH=1
@@ -2898,6 +2904,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
@@ -3059,6 +3066,7 @@ TARGET_DIRS_PCAP=1
 TARGET_DIRS_OPENSSL=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 TARGET_DIRS_UNIVINT=1
 TARGET_DIRS_COCOAINT=1
@@ -3206,6 +3214,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
@@ -3438,6 +3447,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
@@ -3508,6 +3518,7 @@ TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_USERS=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 TARGET_DIRS_HASH=1
@@ -3557,6 +3568,7 @@ TARGET_DIRS_PCAP=1
 TARGET_DIRS_OPENSSL=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_OPENGL=1
 TARGET_DIRS_X11=1
 TARGET_DIRS_CAIRO=1
@@ -3722,6 +3734,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
@@ -3795,6 +3808,7 @@ TARGET_DIRS_PCAP=1
 TARGET_DIRS_OPENSSL=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_HTTPD13=1
 TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
@@ -4011,6 +4025,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_GRAPH=1
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
@@ -4061,6 +4076,7 @@ TARGET_DIRS_PCAP=1
 TARGET_DIRS_OPENSSL=1
 TARGET_DIRS_NUMLIB=1
 TARGET_DIRS_ICONVENC=1
+TARGET_DIRS_GMP=1
 TARGET_DIRS_OPENGL=1
 TARGET_DIRS_X11=1
 TARGET_DIRS_CAIRO=1
@@ -4201,6 +4217,7 @@ TARGET_DIRS_HTTPD20=1
 TARGET_DIRS_HTTPD22=1
 TARGET_DIRS_PXLIB=1
 TARGET_DIRS_NUMLIB=1
+TARGET_DIRS_GMP=1
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 TARGET_DIRS_HASH=1
@@ -7824,6 +7841,51 @@ numlib:
 	$(MAKE) -C numlib all
 .PHONY: numlib_all numlib_debug numlib_smart numlib_release numlib_units numlib_examples numlib_shared numlib_install numlib_sourceinstall numlib_exampleinstall numlib_distinstall numlib_zipinstall numlib_zipsourceinstall numlib_zipexampleinstall numlib_zipdistinstall numlib_clean numlib_distclean numlib_cleanall numlib_info numlib_makefiles numlib
 endif
+ifdef TARGET_DIRS_GMP
+gmp_all:
+	$(MAKE) -C gmp all
+gmp_debug:
+	$(MAKE) -C gmp debug
+gmp_smart:
+	$(MAKE) -C gmp smart
+gmp_release:
+	$(MAKE) -C gmp release
+gmp_units:
+	$(MAKE) -C gmp units
+gmp_examples:
+	$(MAKE) -C gmp examples
+gmp_shared:
+	$(MAKE) -C gmp shared
+gmp_install:
+	$(MAKE) -C gmp install
+gmp_sourceinstall:
+	$(MAKE) -C gmp sourceinstall
+gmp_exampleinstall:
+	$(MAKE) -C gmp exampleinstall
+gmp_distinstall:
+	$(MAKE) -C gmp distinstall
+gmp_zipinstall:
+	$(MAKE) -C gmp zipinstall
+gmp_zipsourceinstall:
+	$(MAKE) -C gmp zipsourceinstall
+gmp_zipexampleinstall:
+	$(MAKE) -C gmp zipexampleinstall
+gmp_zipdistinstall:
+	$(MAKE) -C gmp zipdistinstall
+gmp_clean:
+	$(MAKE) -C gmp clean
+gmp_distclean:
+	$(MAKE) -C gmp distclean
+gmp_cleanall:
+	$(MAKE) -C gmp cleanall
+gmp_info:
+	$(MAKE) -C gmp info
+gmp_makefiles:
+	$(MAKE) -C gmp makefiles
+gmp:
+	$(MAKE) -C gmp all
+.PHONY: gmp_all gmp_debug gmp_smart gmp_release gmp_units gmp_examples gmp_shared gmp_install gmp_sourceinstall gmp_exampleinstall gmp_distinstall gmp_zipinstall gmp_zipsourceinstall gmp_zipexampleinstall gmp_zipdistinstall gmp_clean gmp_distclean gmp_cleanall gmp_info gmp_makefiles gmp
+endif
 ifdef TARGET_DIRS_GRAPH
 graph_all:
 	$(MAKE) -C graph all

+ 5 - 5
packages/Makefile.fpc

@@ -4,7 +4,7 @@
 #
 
 [target]
-dirs=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic
+dirs=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic 
 dirs_linux_i386=libc unixutil graph pxlib
 dirs_i386_linux=graph
 dirs_x86_64_linux=graph
@@ -24,9 +24,9 @@ dirs_haiku=fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc pos
 dirs_freebsd=fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick \
                gdbint libpng x11 gdbm tcl syslog libcurl opengl cairo  bfd aspell svgalib \
                imlib utmp  fpgtk xforms fftw pcap ggi sdl openssl graph gnome1 gtk1 gtk2 librsvg httpd13 httpd20 httpd22 pxlib numlib \
-               users iconvenc
+               users iconvenc gmp
 dirs_darwin=fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc postgres sqlite pthreads imagemagick \
-                libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc
+                libpng gdbm tcl syslog libcurl bfd aspell utmp fftw pcap openssl numlib iconvenc gmp
 dirs_i386_darwin=graph univint cocoaint sdl opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms  gnome1 httpd13 httpd20 httpd22 imlib opengles objcrtl
 dirs_powerpc_darwin=graph univint cocoaint sdl opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib objcrtl
 dirs_x86_64_darwin=opengl x11 cairo gtk1 gtk2 librsvg fpgtk xforms gnome1 httpd13 httpd20 httpd22 imlib
@@ -44,10 +44,10 @@ dirs_openbsd=fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc
 dirs_linux=fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick \
                gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg \
                a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 \
-               imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib
+               imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp
 dirs_win32=fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick \
                gdbint libpng mad tcl opengl gtk1 gtk2 librsvg a52 cdrom fpgtk openal fftw lua \
-               oggvorbis sdl openssl graph pcap httpd13 httpd20 httpd22 pxlib numlib winceunits cairo libxml
+               oggvorbis sdl openssl graph pcap httpd13 httpd20 httpd22 pxlib numlib winceunits cairo libxml gmp
 dirs_win64=fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick \
                 tcl opengl gtk1 fpgtk fftw sdl openssl cdrom httpd13 httpd20 httpd22 numlib
 dirs_wince=winceunits httpd22 fcl-web fastcgi tcl fftw unzip zlib sqlite mysql ibase postgres oracle odbc sdl openssl oggvorbis numlib

+ 3 - 3
packages/chm/src/chmreader.pas

@@ -1081,7 +1081,7 @@ begin
       Exit;
     end;
     // if FirstBlock is odd (1,3,5,7 etc) we have to read the even block before it first.
-    if (FirstBlock <> 0) and (FirstBlock mod 2 > 0) then begin
+    if FirstBlock and 1 = 1 then begin
       fStream.Position := fHeaderSuffix.Offset + fCachedEntry.ContentOffset + (ResetTable[FirstBLock-1]);
       ReadCount := ResetTable[FirstBlock] - ResetTable[FirstBlock-1];
       BlockWriteLength:=BlockSize;
@@ -1131,7 +1131,7 @@ begin
       end;
       
       // if the next block is an even numbered block we have to reset the decompressor state
-      if (X < LastBlock) and (X mod 2 > 0) then LZXreset(LZXState);
+      if (X < LastBlock) and (X and 1 = 1) then LZXreset(LZXState);
 
     end;
     FreeMem(OutBuf);
@@ -1238,7 +1238,7 @@ AChm: TChmReader;
 AIndex: Integer;
 begin
   if not FileExists(AFileName) then exit;
-  AStream := TFileStream.Create(AFileName, fmOpenRead);
+  AStream := TFileStream.Create(AFileName, fmOpenRead, fmShareDenyWrite);
   AChm := TChmReader.Create(AStream, True);
   AIndex := AddObject(AFileName, AChm);
   fLastChm := AChm;

+ 1 - 1
packages/chm/src/chmwriter.pas

@@ -1200,7 +1200,7 @@ begin
       FreeAndNil(NextLevelItems);
 
   while NextLevelItems <> nil do
-  begin  WriteLn('Loop');
+  begin  
     CurrentLevelItems := NextLevelItems;
     NextLevelItems := TFPList.Create;
 

+ 1 - 1
packages/chm/src/paslzx.pas

@@ -593,7 +593,7 @@ begin
             i := bits.read(16, inpos);
             j := bits.read(16, inpos);
         end;
-        pState^.intel_filesize := (i shl 16) or j; ///* or 0 if not encoded */
+        pState^.intel_filesize := LongInt((i shl 16) or j); ///* or 0 if not encoded */
         pState^.header_read := 1;
     end;
 

+ 1 - 1
packages/fcl-base/src/ascii85.pp

@@ -76,8 +76,8 @@ type
   TASCII85EncoderStream = class(TOwnerStream)
   private
     FPos,
-    FCount,
     FTuple : Cardinal;
+    FCount,
     FWidth : Integer;
     FBoundary : Boolean;
   protected  

+ 2 - 0
packages/fcl-base/src/custapp.pp

@@ -80,6 +80,8 @@ Type
     Property StopOnException : Boolean Read FStopOnException Write FStopOnException;
   end;
 
+var CustomApplication : TCustomApplication = nil;
+
 Implementation
 
 {$if defined(darwin) and (defined(cpu386) or defined(cpupowerpc32))}

+ 6 - 0
packages/fcl-db/src/base/database.inc

@@ -119,6 +119,12 @@ begin
       TDBTransaction(FTransactions[i]).Database:=Nil;
 end;
 
+procedure TDatabase.SetParams(AValue: TStrings);
+begin
+  if AValue<>nil then
+    FParams.Assign(AValue);
+end;
+
 Function TDatabase.GetDataSetCount : Longint;
 
 begin

+ 2 - 1
packages/fcl-db/src/base/db.pas

@@ -1621,6 +1621,7 @@ type
     procedure UnRegisterTransaction(TA : TDBTransaction);
     procedure RemoveDataSets;
     procedure RemoveTransactions;
+    procedure SetParams(AValue: TStrings);
   protected
     Procedure CheckConnected;
     Procedure CheckDisConnected;
@@ -1647,7 +1648,7 @@ type
     property Connected: Boolean read FConnected write SetConnected;
     property DatabaseName: string read FDatabaseName write FDatabaseName;
     property KeepConnection: Boolean read FKeepConnection write FKeepConnection;
-    property Params : TStrings read FParams Write FParams;
+    property Params : TStrings read FParams Write SetParams;
   end;
 
 

+ 11 - 7
packages/fcl-web/src/custweb.pp

@@ -98,7 +98,8 @@ Type
     Procedure CreateForm(AClass : TComponentClass; Var Reference : TComponent);
     Procedure Initialize; override;
     Procedure ShowException(E: Exception);override;
-    Procedure handleRequest(ARequest : TRequest; AResponse : TResponse); virtual;
+    Procedure DoHandleRequest(ARequest : TRequest; AResponse : TResponse);
+    Procedure HandleRequest(ARequest : TRequest; AResponse : TResponse); virtual;
     Property HandleGetOnPost : Boolean Read FHandleGetOnPost Write FHandleGetOnPost;
     Property RedirectOnError : boolean Read FRedirectOnError Write FRedirectOnError;
     Property RedirectOnErrorURL : string Read FRedirectOnErrorURL Write FRedirectOnErrorURL;
@@ -134,12 +135,7 @@ begin
   while not Terminated do
     begin
     if WaitForRequest(ARequest,AResponse) then
-      begin
-      HandleRequest(ARequest,AResponse);
-      If Not AResponse.ContentSent then
-        AResponse.SendContent;
-      EndRequest(ARequest,AResponse);
-      end;
+      DoHandleRequest(ARequest,AResponse);
     end;
 end;
 
@@ -298,6 +294,14 @@ begin
     Result:=Nil;
 end;
 
+procedure TCustomWebApplication.DoHandleRequest(ARequest: TRequest; AResponse: TResponse);
+begin
+  HandleRequest(ARequest,AResponse);
+  If Not AResponse.ContentSent then
+    AResponse.SendContent;
+  EndRequest(ARequest,AResponse);
+end;
+
 constructor TCustomWebApplication.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);

+ 6 - 0
packages/fcl-xml/src/xpath.pp

@@ -523,8 +523,11 @@ var
   Code: Integer;
 begin
   Val(s, Result, Code);
+{$push}
+{$r-}
   if Code <> 0 then
     Result := NaN;
+{$pop}
 end;
 
 procedure TranslateWideString(var S: DOMString; const SrcPat, DstPat: DOMString);
@@ -758,7 +761,10 @@ begin
         opDivide:
           NumberResult := Op1 / Op2;
         opMod: if IsNan(Op1) or IsNan(Op2) then
+{$push}
+{$r-}
           NumberResult := NaN
+{$pop}
         else
           NumberResult := Trunc(Op1) mod Trunc(Op2);
       end;

+ 9 - 4
packages/fcl-xml/tests/README_DOM.txt

@@ -24,7 +24,11 @@ the following files:
 1) testgen.pp  - an utility for generating Pascal source from XML descriptions.
 2) api.xml     - database used by testgen.
 3) domunit.pp  - FPCUnit extensions required at runtime.
-4) README_DOM.txt - this file.
+4) extras.pp   - Additional tests, not present in w3.org testsuite.
+5) extras2.pp  - Some tests that are present in the testsuite, but converted/modified
+                 by hand because automatic conversion is not yet possible.
+6) README_DOM.txt - this file.
+
 
 To test the FCL DOM implementation, follow these steps:
 
@@ -73,9 +77,10 @@ other elements not yet known to testgen, will be skipped. The conversion may be
 by using -f commandline switch, but in this case the resulting Pascal unit will likely
 fail to compile.
  
-4) Now, pick up your preferred fpcunit test runner, include the generated units into
-its uses clause, and compile. During compilation, path to 'domunit.pp' should be added
-to the unit search paths.
+4) Now, pick up your preferred fpcunit test runner, add the generated units to its
+uses clause, and compile. You may as well add the suppied 'extras.pp' and 'extras2.pp'
+units. During compilation, path to 'domunit.pp' should be added to the unit search
+paths.
 
 5) During runtime, tests must be able to read test files which are located
 within CVS source tree ('files' subdirectory of each module directory). For this purpose,

+ 16 - 2
packages/fcl-xml/tests/domunit.pp

@@ -41,6 +41,7 @@ type
     procedure TearDown; override;
     procedure GC(obj: TObject);
     procedure Load(out doc; const uri: string);
+    procedure LoadStringData(out Doc; const data: string);
     function getResourceURI(const res: WideString): WideString;
     function ContentTypeIs(const t: string): Boolean;
     function GetImplementation: TDOMImplementation;
@@ -97,6 +98,7 @@ procedure TDOMTestBase.SetUp;
 begin
   FParser := TDOMParser.Create;
   FParser.Options.PreserveWhitespace := True;
+  //FParser.Options.ExpandEntities := True;
   FAutoFree := TObjectList.Create(True);
 end;
 
@@ -202,8 +204,7 @@ begin
       CheckFile(Base2, Result) then
         Exit;
   end;
-  if not CheckFile(Base, Result) then
-    Result := '';
+  CheckFile(Base, Result);
 end;
 
 function TDOMTestBase.getImplAttr(const name: string): Boolean;
@@ -315,5 +316,18 @@ begin
   result := '';
 end;
 
+procedure TDOMTestBase.LoadStringData(out Doc; const data: string);
+var
+  src: TXMLInputSource;
+begin
+  src := TXMLInputSource.Create(data);
+  try
+    FParser.Parse(src, TXMLDocument(Doc));
+    GC(Doc);
+  finally
+    src.Free;
+  end;
+end;
+
 end.
 

+ 123 - 0
packages/fcl-xml/tests/extras.pp

@@ -0,0 +1,123 @@
+{**********************************************************************
+
+    This file is part of the Free Component Library (FCL)
+
+    DOM Test cases which are missing from w3.org test suite
+    Copyright (c) 2008 by Sergei Gorelkin, [email protected]
+
+    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.
+
+ **********************************************************************}
+unit extras;
+{$mode objfpc}{$H+}
+interface
+
+uses
+  SysUtils, Classes, DOM, xmlread, domunit, testregistry;
+
+implementation
+
+type
+  TDOMTestExtra = class(TDOMTestBase)
+  published
+    procedure attr_ownership01;
+    procedure attr_ownership02;
+    procedure attr_ownership03;
+    procedure attr_ownership04;
+  end;
+
+{ TDOMTestExtra }
+
+// verify that an attribute created by Element.SetAttribute()
+// has its OwnerElement assigned properly
+procedure TDOMTestExtra.attr_ownership01;
+var
+  doc: TDOMDocument;
+  el: TDOMElement;
+  attr: TDOMAttr;
+  attrOwner: TDOMElement;
+begin
+  LoadStringData(doc, '<doc/>');
+  el := doc.CreateElement('element1');
+  el.SetAttribute('newAttr', 'newValue');
+  attr := el.GetAttributeNode('newAttr');
+  AssertNotNull('attribute', attr);
+  attrOwner := attr.OwnerElement;
+  AssertEquals('ownerElement', el, attrOwner);
+  AssertTrue('specified', attr.Specified);
+end;
+
+// verify that an attribute created by Element.SetAttributeNS()
+// has its OwnerElement assigned properly
+procedure TDOMTestExtra.attr_ownership02;
+var
+  doc: TDOMDocument;
+  el: TDOMElement;
+  attr: TDOMAttr;
+  attrOwner: TDOMElement;
+begin
+  LoadStringData(doc, '<doc/>');
+  el := doc.CreateElement('element1');
+  el.SetAttributeNS('http://www.freepascal.org', 'fpc:newAttr', 'newValue');
+  attr := el.GetAttributeNodeNS('http://www.freepascal.org', 'newAttr');
+  AssertNotNull('attribute', attr);
+  attrOwner := attr.OwnerElement;
+  AssertEquals('ownerElement', el, attrOwner);
+  AssertTrue('specified', attr.Specified);
+end;
+
+// verify that NamedNodeMap.SetNamedItem() resets OwnerElement
+// of the attribute being replaced
+procedure TDOMTestExtra.attr_ownership03;
+var
+  doc: TDOMDocument;
+  el: TDOMElement;
+  attr, attr2: TDOMAttr;
+  retNode: TDOMNode;
+begin
+  LoadStringData(doc, '<doc/>');
+  el := doc.CreateElement('element1');
+  attr := doc.CreateAttribute('newAttr');
+  el.SetAttributeNode(attr);
+  AssertEquals('ownerElement_before', el, attr.OwnerElement);
+  attr2 := doc.CreateAttribute('newAttr');
+  retNode := el.Attributes.SetNamedItem(attr2);
+  AssertSame('retNode', attr, retNode);
+  AssertNull('ownerElement_after', attr.OwnerElement);
+  AssertEquals('ownerElement2', el, attr2.OwnerElement);
+end;
+
+// verify that NamedNodeMap.SetNamedItemNS() resets OwnerElement
+// of the attribute being replaced
+procedure TDOMTestExtra.attr_ownership04;
+var
+  doc: TDOMDocument;
+  el: TDOMElement;
+  attr, attr2: TDOMAttr;
+  retNode: TDOMNode;
+begin
+  LoadStringData(doc, '<doc/>');
+  el := doc.CreateElement('element1');
+  attr := doc.CreateAttributeNS('http://www.freepascal.org', 'fpc:newAttr');
+  el.SetAttributeNodeNS(attr);
+  AssertEquals('ownerElement_before', el, attr.OwnerElement);
+  attr2 := doc.CreateAttributeNS('http://www.freepascal.org', 'fpc:newAttr');
+  retNode := el.Attributes.SetNamedItemNS(attr2);
+  AssertSame('retNode', attr, retNode);
+  AssertNull('ownerElement_after', attr.OwnerElement);
+  AssertEquals('ownerElement2', el, attr2.OwnerElement);
+end;
+
+
+
+
+initialization
+  RegisterTest(TDOMTestExtra);
+
+end.
+

+ 313 - 0
packages/fcl-xml/tests/extras2.pp

@@ -0,0 +1,313 @@
+{**********************************************************************
+
+    This file is part of the Free Component Library (FCL)
+
+    Some DOM test cases adapted by hand (because automatic conversion
+    is not yet possible for them).
+    Copyright (c) 2001-2004 World Wide Web Consortium,
+    (Massachusetts Institute of Technology, Institut National de
+    Recherche en Informatique et en Automatique, Keio University). All
+    Rights Reserved.
+    Copyright (c) 2009 by Sergei Gorelkin, [email protected]
+
+    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.
+
+ **********************************************************************}
+
+unit extras2;
+{$mode objfpc}{$H+}
+interface
+
+uses
+  SysUtils, Classes, DOM, xmlread, xmlwrite, domunit, testregistry;
+
+implementation
+
+type
+  TDOMTestExtra2 = class(TDOMTestBase)
+  published
+    procedure ls3_canonicform08;
+    procedure ls3_canonicform09;
+    procedure ls3_canonicform10;
+    procedure ls3_canonicform11;
+    procedure ls3_DomWriterTest5;
+    procedure ls3_DomWriterTest6;
+  end;
+
+const
+// This is example #1 from c14n specs, but modified to comply with HTML grammar
+  canonicform01 =
+'<?xml version="1.0"?>'^M^J+
+^M^J+
+'<?xml-stylesheet   href="doc.xsl"'^M^J+
+'   type="text/xsl"   ?>'^M^J+
+^M^J+
+'<!DOCTYPE html SYSTEM "xhtml1-strict.dtd">'^M^J+
+'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>canonicalform01</title></head><body onload="parent.loadComplete()">'^M^J+
+'<p>Hello, world!<!-- Comment 1 --></p></body></html>'^M^J+
+^M^J+
+'<?pi-without-data     ?>'^M^J+
+^M^J+
+'<!-- Comment 2 -->'^M^J+
+^M^J+
+'<!-- Comment 3 -->'^M^J;
+
+  canonicform03 =
+'<!DOCTYPE html [<!ATTLIST acronym title CDATA "default">]>'^M^J+
+'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>canonicalform03</title></head><body onload="parent.loadComplete()">'^M^J+
+'   <br   />'^M^J+
+'   <br   ></br>'^M^J+
+'   <div   name = "elem3"   id="elem3"   />'^M^J+
+'   <div   name="elem4"   id="elem4"   ></div>'^M^J+
+'   <div a:attr="out" b:attr="sorted" name="all" class="I''m"'^M^J+
+'      xmlns:b="http://www.ietf.org"'^M^J+
+'      xmlns:a="http://www.w3.org"'^M^J+
+'      xmlns="http://example.org"/>'^M^J+
+'   <div xmlns="" xmlns:a="http://www.w3.org">'^M^J+
+'      <div xmlns="http://www.ietf.org">'^M^J+
+'         <div xmlns="" xmlns:a="http://www.w3.org">'^M^J+
+'            <acronym xmlns="" xmlns:a="http://www.ietf.org"/>'^M^J+
+'         </div>'^M^J+
+'      </div>'^M^J+
+'   </div>'^M^J+
+'</body></html>'^M^J;
+
+{ TDOMTestExtra }
+
+{ test canonical form with comments }
+procedure TDOMTestExtra2.ls3_canonicform08;
+var
+  doc: TDOMDocument;
+  node: TDOMNode;
+  nodeType: Integer;
+  nodeValue: DOMString;
+  length: Integer;
+begin
+// canonical form: PreserveWhitespace, Namespaces, NamespaceDeclarations = True;
+//                 Entities, CDSections = False;
+  FParser.Options.PreserveWhitespace := True;
+  FParser.Options.Namespaces := True;
+  LoadStringData(doc, canonicform01);
+  begin
+    node := TDOMNode(doc).firstChild;
+    nodeType := node.nodeType;
+    assertEquals('PIisFirstChild', 7, nodeType);
+    nodeValue := TDOMProcessingInstruction(node).data;
+    length := system.length(nodeValue);
+    assertEquals('piDataLength', 36, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('TextisSecondChild', 3, nodeType);
+    nodeValue := node.nodeValue;
+    length := system.length(nodeValue);
+    assertEquals('secondChildLength', 1, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('ElementisThirdChild', 1, nodeType);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('TextisFourthChild', 3, nodeType);
+    nodeValue := node.nodeValue;
+    length := system.length(nodeValue);
+    assertEquals('fourthChildLength', 1, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('PIisFifthChild', 7, nodeType);
+    nodeValue := TDOMProcessingInstruction(node).data;
+    assertEquals('trailingPIData', '', nodeValue);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('TextisSixthChild', 3, nodeType);
+    nodeValue := node.nodeValue;
+    length := system.length(nodeValue);
+    assertEquals('sixthChildLength', 1, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('CommentisSeventhChild', 8, nodeType);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('TextisEighthChild', 3, nodeType);
+    nodeValue := node.nodeValue;
+    length := system.length(nodeValue);
+    assertEquals('eighthChildLength', 1, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('CommentisNinthChild', 8, nodeType);
+    node := node.nextSibling;
+    assertNull('TenthIsNull', node);
+  end;
+end;
+
+{ test canonical form without comments }
+procedure TDOMTestExtra2.ls3_canonicform09;
+var
+  doc: TDOMDocument;
+  node: TDOMNode;
+  nodeType: Integer;
+  nodeValue: DOMString;
+  length: Integer;
+begin
+// canonical form: PreserveWhitespace, Namespaces, NamespaceDeclarations = True;
+//                 Entities, CDSections = False;
+  FParser.Options.PreserveWhitespace := True;
+  FParser.Options.Namespaces := True;
+  FParser.Options.IgnoreComments := True;
+  LoadStringData(doc, canonicform01);
+  begin
+    node := TDOMNode(doc).firstChild;
+    nodeType := node.nodeType;
+    assertEquals('PIisFirstChild', 7, nodeType);
+    nodeValue := TDOMProcessingInstruction(node).data;
+    length := system.length(nodeValue);
+    assertEquals('piDataLength', 36, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('TextisSecondChild', 3, nodeType);
+    nodeValue := node.nodeValue;
+    length := system.length(nodeValue);
+    assertEquals('secondChildLength', 1, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('ElementisThirdChild', 1, nodeType);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('TextisFourthChild', 3, nodeType);
+    nodeValue := node.nodeValue;
+    length := system.length(nodeValue);
+    assertEquals('fourthChildLength', 1, length);
+    node := node.nextSibling;
+    nodeType := node.nodeType;
+    assertEquals('PIisFifthChild', 7, nodeType);
+    nodeValue := TDOMProcessingInstruction(node).data;
+    assertEquals('trailingPIData', '', nodeValue);
+    node := node.nextSibling;
+    assertNull('SixthIsNull', node);
+  end;
+end;
+
+{ test removal of superfluous namespace declarations }
+procedure TDOMTestExtra2.ls3_canonicform10;
+var
+  doc: TDOMDocument;
+  divList: TDOMNodeList;
+  divEl: TDOMElement;
+  node: TDOMNode;
+begin
+  FParser.Options.PreserveWhitespace := True;
+  FParser.Options.Namespaces := True;
+  LoadStringData(doc, canonicform03);
+
+  divList := doc.getElementsByTagName('div');
+  TDOMNode(divEl) := divList[5];
+  node := divEl.getAttributeNode('xmlns');
+  assertNotNull('xmlnsPresent', node);
+  node := divEl.getAttributeNode('xmlns:a');
+  assertNull('xmlnsANotPresent', node);
+end;
+
+{ test that defaulted attributes are being replaced by 'normal' ones }
+procedure TDOMTestExtra2.ls3_canonicform11;
+var
+  doc: TDOMDocument;
+  elemList: TDOMNodeList;
+  elem: TDOMElement;
+  attr: TDOMAttr;
+  attrSpecified: Boolean;
+  attrValue: DOMString;
+begin
+  FParser.Options.PreserveWhitespace := True;
+  FParser.Options.Namespaces := True;
+  LoadStringData(doc, canonicform03);
+
+  elemList := doc.getElementsByTagName('acronym');
+  TDOMNode(elem) := elemList[0];
+  attr := elem.getAttributeNode('title');
+  assertNotNull('titlePresent', attr);
+  attrSpecified := attr.specified;
+  assertTrue('titleSpecified', attrSpecified);
+  attrValue := attr.nodeValue;
+  assertEquals('titleValue', 'default', attrValue);
+end;
+
+{ tests that namespace fixup is done while serializing }
+{ attribute has no prefix }
+procedure TDOMTestExtra2.ls3_DomWriterTest5;
+var
+  domImpl: TDOMImplementation;
+  origDoc: TDOMDocument;
+  parsedDoc: TDOMDocument;
+  docElem: TDOMElement;
+  stream: TStringStream;
+  docElemLocalName: DOMString;
+  docElemNS: DOMString;
+  attrValue: DOMString;
+const
+  namespaceURI = 'http://www.example.com/DOMWriterTest5';
+begin
+  FParser.Options.Namespaces := True;
+  domImpl := GetImplementation;
+  origDoc := domImpl.createDocument(namespaceURI, 'test', nil);
+  docElem := origDoc.documentElement;
+  docElem.setAttributeNS(namespaceURI, 'attr', 'test value');
+
+  stream := TStringStream.Create('');
+  GC(stream);
+  writeXML(origDoc, stream);
+
+  LoadStringData(parsedDoc, stream.DataString);
+
+  docElem := parsedDoc.documentElement;
+  docElemLocalName := docElem.localName;
+  assertEquals('docElemLocalName', 'test', docElemLocalName);
+  docElemNS := TDOMNode(docElem).namespaceURI;
+  assertEquals('docElemNS', namespaceURI, docElemNS);
+  attrValue := docElem.getAttributeNS(namespaceURI, 'attr');
+  assertEquals('properNSAttrValue', 'test value', attrValue);
+end;
+
+{ tests that namespace fixup is done while serializing }
+{ same as above, but using an attribute that has a prefix }
+procedure TDOMTestExtra2.ls3_DomWriterTest6;
+var
+  domImpl: TDOMImplementation;
+  origDoc: TDOMDocument;
+  parsedDoc: TDOMDocument;
+  docElem: TDOMElement;
+  stream: TStringStream;
+  docElemLocalName: DOMString;
+  docElemNS: DOMString;
+  attrValue: DOMString;
+const
+  namespaceURI = 'http://www.example.com/DOMWriterTest5';
+begin
+  FParser.Options.Namespaces := True;
+  domImpl := GetImplementation;
+  origDoc := domImpl.createDocument(namespaceURI, 'test', nil);
+  docElem := origDoc.documentElement;
+  docElem.setAttributeNS(namespaceURI, 'test:attr', 'test value');
+
+  stream := TStringStream.Create('');
+  GC(stream);
+  writeXML(origDoc, stream);
+
+  LoadStringData(parsedDoc, stream.DataString);
+
+  docElem := parsedDoc.documentElement;
+  docElemLocalName := docElem.localName;
+  assertEquals('docElemLocalName', 'test', docElemLocalName);
+  docElemNS := TDOMNode(docElem).namespaceURI;
+  assertEquals('docElemNS', namespaceURI, docElemNS);
+  attrValue := docElem.getAttributeNS(namespaceURI, 'attr');
+  assertEquals('properNSAttrValue', 'test value', attrValue);
+end;
+
+initialization
+  RegisterTest(TDOMTestExtra2);
+
+end.
+

+ 8 - 0
packages/gmp/readme

@@ -81,3 +81,11 @@ Readme for libgmp.tar.bz2 2009-09-06
   - FPC developers, you can do anything you see appropriate with the sources.
     Review, refactor and/or reject :-)
 
+= Windows
+
+I got the examples running under win32 by getting the mingw-dynamic package
+on
+
+http://cs.nyu.edu/exact/core/gmp/
+
+and then renaming it to gmp.dll

+ 3 - 0
packages/gmp/src/gmp.pas

@@ -23,6 +23,9 @@ unit gmp;
 {$define NO_GMP_GLOBVARS}
 {$endif}
 
+{$ifdef darwin}
+  {$linklib gmp.3}
+{$endif}
 { Unused symbols exported from GMP:
 
   Marked preliminary in GMP manual

+ 59 - 59
packages/hash/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/02]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/09/16]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
@@ -267,178 +267,178 @@ PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(F
 override PACKAGE_NAME=hash
 override PACKAGE_VERSION=2.5.1
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),avr-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_UNITS+=md5 crc ntlm uuid  unixcrypt
+override TARGET_UNITS+=md5 crc ntlm uuid sha1  unixcrypt
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
-override TARGET_UNITS+=md5 crc ntlm uuid
+override TARGET_UNITS+=md5 crc ntlm uuid sha1
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 override TARGET_EXAMPLEDIRS+=examples

+ 1 - 1
packages/hash/Makefile.fpc

@@ -7,7 +7,7 @@ name=hash
 version=2.5.1
 
 [target]
-units=md5 crc ntlm uuid
+units=md5 crc ntlm uuid sha1
 units_linux=unixcrypt
 exampledirs=examples
 

+ 59 - 59
packages/hash/examples/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/02]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/08/28]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
@@ -265,178 +265,178 @@ UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
 endif
 PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),avr-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
-override TARGET_PROGRAMS+=mdtest crctest
+override TARGET_PROGRAMS+=mdtest crctest sha1test
 endif
 override INSTALL_FPCPACKAGE=y
 ifdef REQUIRE_UNITSDIR

+ 1 - 1
packages/hash/examples/Makefile.fpc

@@ -3,7 +3,7 @@
 #
 
 [target]
-programs=mdtest crctest
+programs=mdtest crctest sha1test
 
 [require]
 packages=hash

+ 38 - 0
packages/hash/examples/sha1test.pp

@@ -0,0 +1,38 @@
+program sha1test;
+{$mode objfpc}{$h+}
+
+uses sha1;
+
+var
+  code: cardinal;
+  s, sdig: string;
+  i: integer;
+  ctx: TSHA1Context;
+  d: TSHA1Digest;
+begin
+  code := 0;
+  sdig := SHA1Print(SHA1String('abc'));
+  if sdig <> 'a9993e364706816aba3e25717850c26c9cd0d89d' then
+    code := code or 1;
+    
+  sdig := SHA1Print(SHA1String('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'));
+  if sdig <> '84983e441c3bd26ebaae4aa1f95129e5e54670f1' then
+    code := code or 2;
+
+  // SHA-1 of a million 'a' symbols
+  SetLength(s, 1000);
+  for i := 1 to 1000 do s[i] := 'a';
+  SHA1Init(ctx);
+  for i := 0 to 999 do
+    SHA1Update(ctx, PChar(s)^, 1000);
+  SHA1Final(ctx, d);
+  sdig := SHA1Print(d);
+  if sdig <> '34aa973cd4c4daa4f61eeb2bdbad27316534016f' then
+    code := code or 4;
+
+  if code = 0 then
+    writeln('Basic SHA-1 tests passed')
+  else
+    writeln('SHA-1 tests failed: ', code);
+  Halt(code);
+end.

+ 4 - 0
packages/hash/fpmake.pp

@@ -26,12 +26,16 @@ begin
 
     P.Version:='2.2.2-0';
     T:=P.Targets.AddUnit('src/md5.pp');
+    T:=P.Targets.AddUnit('src/sha1.pp');
     T:=P.Targets.AddUnit('src/crc.pas');
     T:=P.Targets.AddUnit('src/ntlm.pas');
+    T:=P.Targets.AddUnit('src/sha1.pas');
     T:=P.Targets.AddUnit('src/uuid.pas');
     T:=P.Targets.AddUnit('src/unixcrypt.pas');
       T.OSes:=[Linux];
     T:=P.Targets.AddExampleunit('examples/mdtest.pas');
+    T:=P.Targets.AddExampleunit('examples/crctest.pas');
+    T:=P.Targets.AddExampleunit('examples/sha1test.pas');
     // md5.ref
 {$ifndef ALLPACKAGES}
     Run;

+ 305 - 0
packages/hash/src/sha1.pp

@@ -0,0 +1,305 @@
+{
+    This file is part of the Free Pascal packages.
+    Copyright (c) 2009 by the Free Pascal development team
+
+    Implements a SHA-1 digest algorithm (RFC 3174)
+
+    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.
+
+ **********************************************************************}
+
+unit sha1;
+{$mode objfpc}{$h+}
+
+interface
+
+type
+  TSHA1Digest = array[0..19] of Byte;
+  
+  TSHA1Context = record
+    State: array[0..4] of Cardinal;
+    Buffer: array[0..63] of Byte;
+    BufCnt: PtrUInt;   { in current block, i.e. in range of 0..63 }
+    Length: QWord;     { total count of bytes processed }
+  end;
+
+{ core }  
+procedure SHA1Init(var ctx: TSHA1Context);
+procedure SHA1Update(var ctx: TSHA1Context; const Buf; BufLen: PtrUInt);
+procedure SHA1Final(var ctx: TSHA1Context; var Digest: TSHA1Digest);
+
+{ auxiliary }
+function SHA1String(const S: String): TSHA1Digest;
+function SHA1Buffer(const Buf; BufLen: PtrUInt): TSHA1Digest;
+function SHA1File(const Filename: String; const Bufsize: PtrUInt = 1024): TSHA1Digest;
+
+{ helpers }
+function SHA1Print(const Digest: TSHA1Digest): String;
+function SHA1Match(const Digest1, Digest2: TSHA1Digest): Boolean;
+
+implementation
+
+// inverts the bytes of (Count div 4) cardinals from source to target.
+procedure Invert(Source, Dest: Pointer; Count: PtrUInt);
+var
+  S: PByte;
+  T: PCardinal;
+  I: PtrUInt;
+begin
+  S := Source;
+  T := Dest;
+  for I := 1 to (Count div 4) do
+  begin
+    T^ := S[3] or (S[2] shl 8) or (S[1] shl 16) or (S[0] shl 24);
+    inc(S,4);
+    inc(T);
+  end;
+end;
+
+procedure SHA1Init(var ctx: TSHA1Context);
+begin
+  FillChar(ctx, sizeof(TSHA1Context), 0);
+  ctx.State[0] := $67452301;
+  ctx.State[1] := $efcdab89;
+  ctx.State[2] := $98badcfe;
+  ctx.State[3] := $10325476;
+  ctx.State[4] := $c3d2e1f0;
+end;
+
+const
+  K20 = $5A827999;
+  K40 = $6ED9EBA1;
+  K60 = $8F1BBCDC;
+  K80 = $CA62C1D6;
+  
+procedure SHA1Transform(var ctx: TSHA1Context; Buf: Pointer);
+var
+  A, B, C, D, E, T: Cardinal;
+  Data: array[0..15] of Cardinal;
+  i: Integer;
+begin
+  A := ctx.State[0];
+  B := ctx.State[1];
+  C := ctx.State[2];
+  D := ctx.State[3];
+  E := ctx.State[4];
+  Invert(Buf, @Data, 64);
+{$push}
+{$r-,q-}
+  i := 0;
+  repeat
+    T := (B and C) or (not B and D) + K20 + E;
+    E := D;
+    D := C;
+    C := rordword(B, 2);
+    B := A;
+    A := T + roldword(A, 5) + Data[i and 15];
+    Data[i and 15] := roldword(Data[i and 15] xor Data[(i+2) and 15] xor Data[(i+8) and 15] xor Data[(i+13) and 15], 1);
+    Inc(i);
+  until i > 19;
+  
+  repeat
+    T := (B xor C xor D) + K40 + E;
+    E := D;
+    D := C;
+    C := rordword(B, 2);
+    B := A;
+    A := T + roldword(A, 5) + Data[i and 15];
+    Data[i and 15] := roldword(Data[i and 15] xor Data[(i+2) and 15] xor Data[(i+8) and 15] xor Data[(i+13) and 15], 1);
+    Inc(i);
+  until i > 39;
+  
+  repeat
+    T := (B and C) or (B and D) or (C and D) + K60 + E;
+    E := D;
+    D := C;
+    C := rordword(B, 2);
+    B := A;
+    A := T + roldword(A, 5) + Data[i and 15];
+    Data[i and 15] := roldword(Data[i and 15] xor Data[(i+2) and 15] xor Data[(i+8) and 15] xor Data[(i+13) and 15], 1);
+    Inc(i);
+  until i > 59;  
+  
+  repeat
+    T := (B xor C xor D) + K80 + E;
+    E := D;
+    D := C;
+    C := rordword(B, 2);
+    B := A;
+    A := T + roldword(A, 5) + Data[i and 15];
+    Data[i and 15] := roldword(Data[i and 15] xor Data[(i+2) and 15] xor Data[(i+8) and 15] xor Data[(i+13) and 15], 1);
+    Inc(i);
+  until i > 79;  
+
+  Inc(ctx.State[0], A);
+  Inc(ctx.State[1], B);
+  Inc(ctx.State[2], C);
+  Inc(ctx.State[3], D);
+  Inc(ctx.State[4], E);
+{$pop}
+  Inc(ctx.Length,64);
+end;
+
+procedure SHA1Update(var ctx: TSHA1Context; const Buf; BufLen: PtrUInt);
+var
+  Src: PByte;
+  Num: PtrUInt;
+begin
+  if BufLen = 0 then
+    Exit;
+
+  Src := @Buf;
+  Num := 0;
+
+  // 1. Transform existing data in buffer
+  if ctx.BufCnt > 0 then
+  begin
+    // 1.1 Try to fill buffer up to block size
+    Num := 64 - ctx.BufCnt;
+    if Num > BufLen then
+      Num := BufLen;
+
+    Move(Src^, ctx.Buffer[ctx.BufCnt], Num);
+    Inc(ctx.BufCnt, Num);
+    Inc(Src, Num);
+
+    // 1.2 If buffer is filled, transform it
+    if ctx.BufCnt = 64 then
+    begin
+      SHA1Transform(ctx, @ctx.Buffer);
+      ctx.BufCnt := 0;
+    end;
+  end;
+
+  // 2. Transform input data in 64-byte blocks
+  Num := BufLen - Num;
+  while Num >= 64 do
+  begin
+    SHA1Transform(ctx, Src);
+    Inc(Src, 64);
+    Dec(Num, 64);
+  end;
+
+  // 3. If there's less than 64 bytes left, add it to buffer
+  if Num > 0 then
+  begin
+    ctx.BufCnt := Num;
+    Move(Src^, ctx.Buffer, Num);
+  end;
+end;
+
+const
+  PADDING: array[0..63] of Byte = 
+    ($80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+    );
+
+procedure SHA1Final(var ctx: TSHA1Context; var Digest: TSHA1Digest);
+var
+  Length: QWord;
+  Pads: Cardinal;
+begin
+  // 1. Compute length of the whole stream in bits
+  Length := 8 * (ctx.Length + ctx.BufCnt);
+
+  // 2. Append padding bits
+  if ctx.BufCnt >= 56 then
+    Pads := 120 - ctx.BufCnt
+  else
+    Pads := 56 - ctx.BufCnt;
+  SHA1Update(ctx, PADDING, Pads);
+
+  // 3. Append length of the stream (8 bytes)
+  Length := NtoBE(Length);
+  SHA1Update(ctx, Length, 8);
+
+  // 4. Invert state to digest
+  Invert(@ctx.State, @Digest, 20);
+  FillChar(ctx, sizeof(TSHA1Context), 0);  
+end;
+
+function SHA1String(const S: String): TSHA1Digest;
+var
+  Context: TSHA1Context;
+begin
+  SHA1Init(Context);
+  SHA1Update(Context, PChar(S)^, length(S));
+  SHA1Final(Context, Result);
+end;
+
+function SHA1Buffer(const Buf; BufLen: PtrUInt): TSHA1Digest;
+var
+  Context: TSHA1Context;
+begin
+  SHA1Init(Context);
+  SHA1Update(Context, buf, buflen);
+  SHA1Final(Context, Result);
+end;
+
+function SHA1File(const Filename: String; const Bufsize: PtrUInt): TSHA1Digest;
+var
+  F: File;
+  Buf: Pchar;
+  Context: TSHA1Context;
+  Count: Cardinal;
+  ofm: Longint;
+begin
+  SHA1Init(Context);
+
+  Assign(F, Filename);
+  {$i-}
+  ofm := FileMode;
+  FileMode := 0;
+  Reset(F, 1);
+  {$i+}
+
+  if IOResult = 0 then
+  begin
+    GetMem(Buf, BufSize);
+    repeat
+      BlockRead(F, Buf^, Bufsize, Count);
+      if Count > 0 then
+        SHA1Update(Context, Buf^, Count);
+    until Count < BufSize;
+    FreeMem(Buf, BufSize);
+    Close(F);
+  end;
+
+  SHA1Final(Context, Result);
+  FileMode := ofm;
+end;
+
+const
+  HexTbl: array[0..15] of char='0123456789abcdef';     // lowercase
+
+function SHA1Print(const Digest: TSHA1Digest): String;
+var
+  I: Integer;
+  P: PChar;
+begin
+  SetLength(Result, 40);
+  P := Pointer(Result);
+  for I := 0 to 19 do
+  begin
+    P[0] := HexTbl[(Digest[i] shr 4) and 15];
+    P[1] := HexTbl[Digest[i] and 15];
+    Inc(P,2);
+  end;
+end;
+
+function SHA1Match(const Digest1, Digest2: TSHA1Digest): Boolean;
+var
+  A: array[0..4] of Cardinal absolute Digest1;
+  B: array[0..4] of Cardinal absolute Digest2;
+begin
+  Result := (A[0] = B[0]) and (A[1] = B[1]) and (A[2] = B[2]) and (A[3] = B[3]) and (A[4] = B[4]);
+end;
+
+end.

+ 20 - 21
packages/sqlite/src/sqlite3.inc

@@ -1,4 +1,4 @@
-{$mode objfpc}
+{$mode objfpc}{$h+}
 
 {$ifdef BSD}
   {$linklib c}
@@ -5725,7 +5725,7 @@ procedure ReleaseSQLite;
 
 var
   SQLiteLibraryHandle: TLibHandle;
-  DefaultLibrary: String = Sqlite3Lib;
+  SQLiteDefaultLibrary: String = Sqlite3Lib;
 {$ENDIF LOAD_DYNAMICALLY}
 
 implementation
@@ -5912,46 +5912,45 @@ var
 
 function TryInitialiseSqlite(const LibraryName: string): Boolean;
 begin
-  Result := false;
-  if (RefCount=0) then
+  if InterlockedIncrement(RefCount) = 1 then
   begin
     SQLiteLibraryHandle := LoadLibrary(LibraryName);
-    Result := (SQLiteLibraryHandle <> nilhandle);
+    Result := (SQLiteLibraryHandle <> NilHandle);
     if not Result then
+    begin
+      RefCount := 0;
       Exit;
-    Inc(RefCount);
+    end;
     LoadedLibrary := LibraryName;
     LoadAddresses(SQLiteLibraryHandle);
-  end else begin
-    if (LoadedLibrary <> LibraryName) then
-      raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
-    Inc(RefCount);
+  end else
     Result := True;
-  end;
 end;
 
 procedure InitialiseSQLite;
 begin
-  InitialiseSQLite(DefaultLibrary);
+  InitialiseSQLite(SQLiteDefaultLibrary);
 end;
 
 procedure InitialiseSQLite(LibraryName: String);
 begin
+  if (LoadedLibrary <> '') and (LoadedLibrary <> LibraryName) then
+    raise EInoutError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
+
   if not TryInitialiseSQLIte(LibraryName) then
     raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
 end;
 
 procedure ReleaseSQLite;
 begin
-  if RefCount > 1 then
-    Dec(RefCount)
-  else
-    if UnloadLibrary(SQLiteLibraryHandle) then
-    begin
-      Dec(RefCount);
-      SQLiteLibraryHandle := NilHandle;
-      LoadedLibrary := '';
-    end;
+  if InterlockedDecrement(RefCount) <= 0 then
+  begin
+    if SQLiteLibraryHandle <> NilHandle then
+      UnloadLibrary(SQLiteLibraryHandle);
+    SQLiteLibraryHandle := NilHandle;
+    LoadedLibrary := '';
+    RefCount := 0;
+  end;
 end;
 
 {$ENDIF}

+ 12 - 0
rtl/i386/i386.inc

@@ -94,10 +94,12 @@ function mmx_support : boolean;
        mmx_support:=false;
   end;
 
+{$ifndef FPC_PIC}
 {$if not defined(FPC_SYSTEM_HAS_MOVE) and defined(REGCALL) }
 {$define USE_FASTMOVE}
 {$i fastmove.inc}
 {$endif FPC_SYSTEM_HAS_MOVE}
+{$endif FPC_PIC}
 
 procedure fpc_cpuinit;
   begin
@@ -1476,7 +1478,17 @@ asm
         jl      .Lj3596
 .Lj3603:
 // [104] If declocked(l^) then
+  {$ifdef FPC_PIC}
+	pushl	%ebx
+        call	fpc_geteipasebx
+        addl	$_GLOBAL_OFFSET_TABLE_,%ebx
+        movl	ismultithread@GOT(%ebx),%ebx
+        movl	(%ebx),%ebx
+        cmp	$0, %ebx
+	popl    %ebx
+  {$else FPC_PIC}
         cmpl    $0,ismultithread
+  {$endif FPC_PIC}
         jne     .Lj3610
         decl    (%edx)
         je      .Lj3620

+ 7 - 3
rtl/linux/i386/dllprt0.as

@@ -19,9 +19,9 @@
         .globl  _startlib
         .type   _startlib,@function
 _startlib:
-        .globl  FPC_LIB_START
-        .type   FPC_LIB_START,@function
-FPC_LIB_START:
+        .globl  FPC_SHARED_LIB_START
+        .type   FPC_SHARED_LIB_START,@function
+FPC_SHARED_LIB_START:
         pushl   %ebp
         movl    %esp,%ebp
 
@@ -47,6 +47,10 @@ FPC_LIB_START:
         .type   _haltproc,@function
 _haltproc:
 _haltproc2:             # GAS <= 2.15 bug: generates larger jump if a label is exported
+        .globl  FPC_SHARED_LIB_EXIT
+        .type   FPC_SHARED_LIB_EXIT,@function
+FPC_SHARED_LIB_EXIT:
+	call	lib_exit
         xorl    %eax,%eax
         incl    %eax                    /* eax=1, exit call */
         movzwl  operatingsystem_result,%ebx

+ 90 - 11
rtl/linux/i386/si_c.inc

@@ -46,6 +46,7 @@ procedure libc_setfpucw; external name '__setfpucw';
 procedure libc_start_main; external name '__libc_start_main';
 
 procedure PASCALMAIN; external name 'PASCALMAIN';
+Procedure fpc_geteipasebx;[external name 'fpc_geteipasebx'];
 
 {******************************************************************************
                           C library start/halt
@@ -53,38 +54,102 @@ procedure PASCALMAIN; external name 'PASCALMAIN';
 {$asmmode ATT}
 
 procedure _FPC_libc_start; assembler; nostackframe; public name '_start';
+var
+  _ebx: LongInt;
+  _ecx: LongInt;
+  _libc_init_proc: LongInt;
 asm
   { First locate the start of the environment variables }
   popl    %ecx                    { Get argc in ecx }
-  movl    %esp,%ebx               { Esp now points to the arguments }
+
+  {$ifdef FPC_PIC}
+        movl    %esp,_ebx               { Points to the arguments }
+        movl    %ecx,_ecx               
+  {$else FPC_PIC}
+        movl    %esp,%ebx               { Points to the arguments }
+  {$endif FPC_PIC}
+
   leal    4(%esp,%ecx,4),%eax     { The start of the environment is: esp+4*eax+8 }
   andl    $0xfffffff8,%esp        { Align stack }
 
-  movl    %eax,operatingsystem_parameter_envp    { Move the environment pointer }
-  movl    %ecx,operatingsystem_parameter_argc    { Move the argument counter    }
-  movl    %ebx,operatingsystem_parameter_argv    { Move the argument pointer    }
+  {$ifdef FPC_PIC}
+        pushl   %ecx
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  operatingsystem_parameter_envp@GOT(%ebx),%ecx
+        movl  %eax,(%ecx)
+        movl  libc_environ@GOT(%ebx),%ecx
+        movl  %eax,(%ecx)
+
+        pushl %eax
+        movl  operatingsystem_parameter_argc@GOT(%ebx),%ecx
+        movl  _ecx,%eax
+        movl  %eax,(%ecx)
+        movl  operatingsystem_parameter_argv@GOT(%ebx),%ecx
+        movl  _ebx,%eax
+        movl  %eax,(%ecx)
+	popl  %eax
+
+        popl  %ecx
+        movl  _ebx,%ebx
+  {$else FPC_PIC}
+	movl    %eax,operatingsystem_parameter_envp    { Move the environment pointer }
+	movl    %ecx,operatingsystem_parameter_argc    { Move the argument counter    }
+	movl    %ebx,operatingsystem_parameter_argv    { Move the argument pointer    }
+  	movl    %eax,libc_environ          { libc environ }
+  {$endif FPC_PIC}
 
-  movl    %eax,libc_environ          { libc environ }
 
   pushl   %eax
   pushl   %ebx
   pushl   %ecx
 
   call    libc_init             { init libc }
-  movzwl  libc_fpu_control,%eax
+
+  {$ifdef FPC_PIC}
+        pushl   %ecx
+  	pushl   %ebx
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  libc_init_proc@GOT(%ebx),%ecx
+	movl  (%ecx),%ecx
+	movl  %ecx,_libc_init_proc
+  	popl    %ebx
+        popl    %ecx
+  {$else FPC_PIC}
+	movzwl  libc_fpu_control,%eax
+  {$endif FPC_PIC}
+
+
   pushl   %eax
   call    libc_setfpucw
   popl    %eax
   pushl   $libc_fini_proc
   call    libc_atexit
   popl    %eax
-  call    libc_init_proc
+
+  {$ifdef FPC_PIC}
+	call    _libc_init_proc
+  {$else FPC_PIC}
+	call    libc_init_proc
+  {$endif FPC_PIC}
 
   popl    %eax
   popl    %eax
 
   { Save initial stackpointer }
-  movl    %esp,initialstkptr
+  {$ifdef FPC_PIC}
+        pushl   %ecx
+  	pushl   %ebx
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  initialstkptr@GOT(%ebx),%ecx
+	movl  %esp,(%ecx)
+  	popl    %ebx
+        popl    %ecx
+  {$else FPC_PIC}
+	movl    %esp,initialstkptr
+  {$endif FPC_PIC}
 
   xorl    %ebp,%ebp
   call    PASCALMAIN              { start the program }
@@ -93,12 +158,26 @@ end;
 procedure _FPC_libc_haltproc; assembler; nostackframe; public name '_haltproc';
 asm
 .Lhaltproc:
-{$if sizeof(ExitCode)=2}
+
+ {$ifdef FPC_PIC}
+  call    fpc_geteipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
   movzwl  ExitCode,%ebx
-{$else}
+ {$else}
   mov     ExitCode,%ebx
-{$endif}
+ {$endif}
+{$endif FPC_PIC}
+
   pushl   %ebx
+
   call    libc_exit
   xorl    %eax,%eax
   incl    %eax                    { eax=1, exit call }

+ 141 - 58
rtl/linux/i386/si_c21.inc

@@ -33,83 +33,166 @@
          argc <--- esp
 }
 
+{$asmmode att}
+
 var
-  libc21_fpc_ret, libc21_fpc_ret_ebx, libc21_fpc_ret_ebp: ptrint; { return address to libc }
+  dlexitproc: pointer; { atexit from loader }
 
-procedure libc_exit; external name '__libc_exit';
-procedure libc_init; external name '__libc_init';
-procedure libc_setfpucw; external name '__setfpucw';
 procedure libc_start_main; external name '__libc_start_main';
-
 procedure PASCALMAIN; external name 'PASCALMAIN';
 
+{ Some helpers }
+
+procedure _init_fini_dummy; compilerproc; nostackframe; assembler;
+asm
+  ret
+end; 
+
 {******************************************************************************
-                         glibc 2.1 library start/halt
+                       glibc 2.1 lib + profiling start/halt
  ******************************************************************************}
-{$asmmode ATT}
 
 procedure _FPC_libc21_start; assembler; nostackframe; public name '_start';
 asm
+  xorl    %ebp,%ebp
   { First locate the start of the environment variables }
 
-  popl    %esi
-  movl    %eax,%edi
+  popl    %ecx                    { Get argc in ecx }
 
-  movl    %esp,%ebx               { Points to the arguments }
-  movl    %esi,%eax
-  incl    %eax
-  shll    $2,%eax
-  addl    %esp,%eax
+  movl    %esp,%ebx               { Esp now points to the arguments }
+  leal    4(%esp,%ecx,4),%eax     { The start of the environment is: esp+4*eax+4 }
   andl    $0xfffffff8,%esp        { Align stack }
 
-  movl    %eax,operatingsystem_parameter_envp    { Move the environment pointer }
-  movl    %esi,operatingsystem_parameter_argc    { Move the argument counter    }
-  movl    %ebx,operatingsystem_parameter_argv    { Move the argument pointer    }
-
-  xorl    %ebp,%ebp
-  pushl   %edi
-  pushl   %esp
-  pushl   %edx
-  pushl   $.Lfini_dummy
-  pushl   $.Linit_dummy
-  pushl   %ebx
-  pushl   %esi
-  pushl   $.Lmain
-  call    libc_start_main
-.Linit_dummy:
-.Lfini_dummy:
-  ret
-
-{ fake main routine which will be run from libc }
-.Lmain:
-  { save return address }
-  popl    %eax
-  movl    %eax,libc21_fpc_ret
-  movl    %ebx,libc21_fpc_ret_ebx
-  movl    %ebp,libc21_fpc_ret_ebp
-  pushl   %eax
+  {$ifdef FPC_PIC}
+        pushl %edx
+        pushl %ebx
+        pushl %ecx
+	
+	call .Lpiclab
+.Lpiclab:
+        popl  %ebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+
+	movl  dlexitproc@GOT(%ebx),%ecx
+	movl  %edx,(%ecx)
+
+	movl  operatingsystem_parameter_envp@GOT(%ebx),%ecx
+	movl  %eax,(%ecx)
+
+	movl  operatingsystem_parameter_argc@GOT(%ebx),%edx
+	popl  %ecx
+	movl  %ecx,(%edx)
+
+	movl  operatingsystem_parameter_argv@GOT(%ebx),%edx
+	popl  %ebx
+	movl  %ebx,(%edx)
+	popl  %edx
+  {$else FPC_PIC}
+  	movl  %edx, dlexitproc
+  	movl  %eax,operatingsystem_parameter_envp
+  	movl  %ecx,operatingsystem_parameter_argc
+  	movl  %ebx,operatingsystem_parameter_argv
+  {$endif FPC_PIC}
 
   { Save initial stackpointer }
-  movl    %esp,initialstkptr
-
-  { start the program }
-  xorl    %ebp,%ebp
-  call    PASCALMAIN
-  hlt
+  {$ifdef FPC_PIC}
+        pushl %ebx
+        call  .Lpiclab2
+.Lpiclab2:
+        popl  %ebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+	movl  initialstkptr@GOT(%ebx),%ebx
+  	movl  %esp,(%ebx)
+	popl  %ebx
+  {$else FPC_PIC}
+  	movl    %esp,initialstkptr
+  {$endif FPC_PIC}
+
+        { int __libc_start_main(
+		int *(main) (int, char * *, char * *), 
+		int argc, 
+		char * * ubp_av, 
+		void (*init) (void), 
+		void (*fini) (void), 
+		void (*rtld_fini) (void), 
+		void (* stack_end)); } 
+
+        pushl %ebp   			{ padding }
+        pushl %esp   			{ stack_end }
+        pushl %edx   			{ function to be registered with
+                      			  atexit(), passed by loader }
+  	pushl $_init_fini_dummy
+  	pushl $_init_fini_dummy
+	pushl %ebx             		{ Push second argument: argv.  }
+	pushl %ecx             		{ Push first argument: argc.  }
+
+	pushl $PASCALMAIN
+
+  	call  libc_start_main
+	hlt
 end;
 
 procedure _FPC_libc21_haltproc; assembler; nostackframe; public name '_haltproc';
 asm
-{$if sizeof(ExitCode)=2}
-  movzwl  ExitCode,%eax
-{$else}
-  mov     ExitCode,%eax
-{$endif}
-
-  movl    libc21_fpc_ret,%edx         { return to libc }
-  movl    libc21_fpc_ret_ebp,%ebp
-  movl    libc21_fpc_ret_ebx,%ebx
-  push    %edx
-  ret
+.Lhaltproc:
+  {$ifdef FPC_PIC}
+        call  .Lpiclab
+.Lpiclab:
+        popl  %ebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  dlexitproc@GOT(%ebx),%eax
+        movl  (%eax),%eax
+  {$else FPC_PIC}
+        movl    dlexitproc,%eax
+  {$endif FPC_PIC}
+  testl   %eax,%eax
+  je      .Lnodlexitproc
+  call    *%eax
+.Lnodlexitproc:
+  movl    syscall_nr_exit_group,%eax
+
+{$ifdef FPC_PIC}
+  call    .Lpiclab2
+.Lpiclab2:
+  popl    %ebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
+  movzwl  ExitCode,%ebx
+ {$else}
+  mov     ExitCode,%ebx
+ {$endif}
+{$endif FPC_PIC}
+
+  int     $0x80
+  movl    syscall_nr_exit,%eax
+
+{$ifdef FPC_PIC}
+  call    .Lpiclab3
+.Lpiclab3:
+  popl    %ebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+
+ {$if sizeof(ExitCode)=2}
+  movzwl  ExitCode,%ebx
+ {$else}
+  mov     ExitCode,%ebx
+ {$endif}
+{$endif FPC_PIC}
+
+  int     $0x80
+  jmp     .Lhaltproc
 end;
-

+ 197 - 89
rtl/linux/i386/si_c21g.inc

@@ -33,116 +33,224 @@
          argc <--- esp
 }
 
-var
-  gmon_etext: longint; external name '_etext';
-  gmon_start: longint; external name '_start';
-  gmon_mcleanup: procedure; external name '_mcleanup';
-  libc21_fpc_ret, libc21_fpc_ret_ebx: ptrint; { return address to libc }
-  libc21_fpc_ret_esi, libc21_fpc_ret_edi: ptrint;
-  gmon_monstarted: longint = 0;
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2005 by Michael Van Canneyt, Peter Vreman,
+    & Daniel Mantione, members of the Free Pascal development team.
 
-procedure gmon_monstartup; external name 'monstartup';
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
 
-procedure libc_atexit; external name 'atexit';
-procedure libc_exit; external name '__libc_exit';
-procedure libc_init; external name '__libc_init';
-procedure libc_setfpucw; external name '__setfpucw';
-procedure libc_start_main; external name '__libc_start_main';
+    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.
+
+ **********************************************************************}
+
+{
+ Linux ELF startup code for Free Pascal
+
+
+ Stack layout at program start:
+
+         nil
+         envn
+         ....
+         ....           ENVIRONMENT VARIABLES
+         env1
+         env0
+         nil
+         argn
+         ....
+         ....           COMMAND LINE OPTIONS
+         arg1
+         arg0
+         argc <--- esp
+}
+
+{$asmmode att}
 
+{ Some helpers }
+
+{$ifdef FPC_PIC}
+function fpc0geteipasebx : pointer; compilerproc; nostackframe; assembler; 
+asm  
+  movl (%esp),%ebx  
+  ret  
+end;
+{$endif FPC_PIC}
+
+procedure _init_fini_dummy; compilerproc; nostackframe; assembler;
+asm
+  ret
+end;
+
+procedure gmon_mcleanup; cdecl; external name '_mcleanup';
+procedure gmon_monstartup (main,etext : pointer);cdecl;external name 'monstartup';
+
+procedure libc_start_main; external name '__libc_start_main';
 procedure PASCALMAIN; external name 'PASCALMAIN';
 
+var
+  dlexitproc: pointer; { atexit from loader }
+
+  gmon_start : record end;external name 'PASCALMAIN';
+  gmon_etext : record end;external name '_etext';
+
+  gmon_monstarted: longint = 0;
+
 {******************************************************************************
-                       glibc 2.1 lib + profiling start/halt
+                          Process start/halt
  ******************************************************************************}
-{$asmmode ATT}
 
-procedure _FPC_libc21_gprof_gmon_start; assembler; nostackframe;
-asm
-  pushl   %ebp
-  movl    gmon_monstarted,%eax
-  leal    0x1(%eax),%edx
-  movl    %esp,%ebp
-  movl    %edx,gmon_monstarted
-  testl   %eax,%eax
-  jnz     .Lnomonstart
-  pushl   $gmon_start
-  pushl   $gmon_etext                  { Initialize gmon }
-  call    gmon_monstartup
-  addl    $8,%esp
-  pushl   $gmon_mcleanup
-  call    libc_atexit
-  addl    $4,%esp
-.Lnomonstart:
-  movl   %ebp,%esp
-  popl   %ebp
-  ret
+procedure _FPC_libc21_gprof_gmon_start; public name '_FPC_libc21_gprof_gmon_start';
+begin
+  if gmon_monstarted=0 then
+  begin
+    inc(gmon_monstarted);
+    gmon_monstartup(@gmon_start,@gmon_etext);
+  end;
+  PASCALMAIN;
 end;
 
 procedure _FPC_libc21_gprof_start; assembler; nostackframe; public name '_start';
 asm
+  xorl    %ebp,%ebp
   { First locate the start of the environment variables }
-  popl    %esi
-  movl    %eax,%edi
-
-  movl    %esp,%ebx               { Points to the arguments }
-  movl    %esi,%eax
-  incl    %eax
-  shll    $2,%eax
-  addl    %esp,%eax
+
+  popl    %ecx                    { Get argc in ecx }
+
+  movl    %esp,%ebx               { Esp now points to the arguments }
+  leal    4(%esp,%ecx,4),%eax     { The start of the environment is: esp+4*eax+4 }
   andl    $0xfffffff8,%esp        { Align stack }
 
-  movl    %eax,operatingsystem_parameter_envp    { Move the environment pointer }
-  movl    %esi,operatingsystem_parameter_argc    { Move the argument counter    }
-  movl    %ebx,operatingsystem_parameter_argv    { Move the argument pointer    }
+  {$ifdef FPC_PIC}
+        pushl %edx
+        pushl %ebx
+        pushl %ecx
+	
+	call fpc0geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
 
-  movl    %edi,%eax
-  xorl    %ebp,%ebp
-  pushl   %eax
-  pushl   %esp
-  pushl   %edx
-  pushl   $.Lfini_dummy
-  pushl   $.Linit_dummy
-  pushl   %ebx
-  pushl   %esi
-  pushl   $.Lcmain
-  call    libc_start_main
-.Linit_dummy:
-.Lfini_dummy:
-  ret
+	movl  dlexitproc@GOT(%ebx),%ecx
+	movl  %edx,(%ecx)
+
+	movl  operatingsystem_parameter_envp@GOT(%ebx),%ecx
+	movl  %eax,(%ecx)
 
-{ fake main routine which will be run from libc }
-.Lcmain:
-  { save return address }
-  popl    %eax
-  movl    %eax,libc21_fpc_ret
-  movl    %ebx,libc21_fpc_ret_ebx
-  movl    %esi,libc21_fpc_ret_esi
-  movl    %edi,libc21_fpc_ret_edi
-  pushl   %eax
+	movl  operatingsystem_parameter_argc@GOT(%ebx),%edx
+	popl  %ecx
+	movl  %ecx,(%edx)
 
-  call    _FPC_libc21_gprof_gmon_start
+	movl  operatingsystem_parameter_argv@GOT(%ebx),%edx
+	popl  %ebx
+	movl  %ebx,(%edx)
+	popl  %edx
+  {$else FPC_PIC}
+  	movl  %edx, dlexitproc
+  	movl  %eax,operatingsystem_parameter_envp
+  	movl  %ecx,operatingsystem_parameter_argc
+  	movl  %ebx,operatingsystem_parameter_argv
+  {$endif FPC_PIC}
 
   { Save initial stackpointer }
-  movl    %esp,initialstkptr
+  {$ifdef FPC_PIC}
+        pushl %ebx
+        call  fpc0geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+	movl  initialstkptr@GOT(%ebx),%ebx
+  	movl  %esp,(%ebx)
+	popl  %ebx
+  {$else FPC_PIC}
+  	movl    %esp,initialstkptr
+  {$endif FPC_PIC}
 
-  { start the program }
-  call    PASCALMAIN
-  hlt
-end;
+        { int __libc_start_main(
+		int *(main) (int, char * *, char * *), 
+		int argc, 
+		char * * ubp_av, 
+		void (*init) (void), 
+		void (*fini) (void), 
+		void (*rtld_fini) (void), 
+		void (* stack_end)); } 
 
-procedure _FPC_libc21_gprof_haltproc; assembler; nostackframe; public name '_haltproc';
-asm
-{$if sizeof(ExitCode)=2}
-  movzwl  ExitCode,%eax
-{$else}
-  mov     ExitCode,%eax
-{$endif}
-
-  movl    libc21_fpc_ret,%edx         { return to libc }
-  movl    libc21_fpc_ret_ebx,%ebx
-  movl    libc21_fpc_ret_esi,%esi
-  movl    libc21_fpc_ret_edi,%edi
-  push    %edx
-  ret
+        pushl %ebp   			{ padding }
+        pushl %esp   			{ stack_end }
+        pushl %edx   			{ function to be registered with
+                      			  atexit(), passed by loader }
+        pushl $_init_fini_dummy
+        pushl $_init_fini_dummy
+        pushl %ebx                      { Push second argument: argv.  }
+        pushl %ecx                      { Push first argument: argc.  }
+
+        pushl $_FPC_libc21_gprof_gmon_start
+
+        call  libc_start_main
+	hlt
 end;
 
+procedure _FPC_libc21_gprof_haltproc(e:longint);cdecl;public name '_haltproc';
+begin
+  if gmon_monstarted=1 then
+  begin
+    dec(gmon_monstarted);
+    gmon_mcleanup;
+  end;
+  asm
+.Lhaltproc:
+  {$ifdef FPC_PIC}
+        call  fpc0geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  dlexitproc@GOT(%ebx),%eax
+        movl  (%eax),%eax
+  {$else FPC_PIC}
+        movl    dlexitproc,%eax
+  {$endif FPC_PIC}
+  testl   %eax,%eax
+  je      .Lnodlexitproc
+  call    *%eax
+.Lnodlexitproc:
+  movl    syscall_nr_exit_group,%eax
+
+{$ifdef FPC_PIC}
+  call    fpc0geteipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
+  movzwl  ExitCode,%ebx
+ {$else}
+  mov     ExitCode,%ebx
+ {$endif}
+{$endif FPC_PIC}
+
+  int     $0x80
+  movl    syscall_nr_exit,%eax
+
+{$ifdef FPC_PIC}
+  call    fpc0geteipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+
+ {$if sizeof(ExitCode)=2}
+  movzwl  ExitCode,%ebx
+ {$else}
+  mov     ExitCode,%ebx
+ {$endif}
+{$endif FPC_PIC}
+
+  int     $0x80
+  jmp     .Lhaltproc
+ end;
+end;

+ 37 - 44
rtl/linux/i386/si_dll.inc

@@ -35,18 +35,19 @@
 
 procedure PASCALMAIN; external name 'PASCALMAIN';
 
+function get1eipasebx : pointer; compilerproc; nostackframe; assembler; 
+asm  
+  movl (%esp),%ebx  
+  ret  
+end;
+
 {******************************************************************************
                         Shared library start/halt
  ******************************************************************************}
 {$asmmode ATT}
 
-procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name '_FPC_SHARED_LIB_START_LOCAL'; public name '_start';
+procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name 'FPC_SHARED_LIB_START'; public name '_start';
 begin
-  { we've to discuss about the use of this ;) }
-  asm
-    { Save initial stackpointer }
-    movl    %esp,initialstkptr
-  end;
 
   operatingsystem_parameter_argc:=argc;    { Copy the argument count      }
   operatingsystem_parameter_argv:=argv;    { Copy the argument pointer    }
@@ -54,53 +55,45 @@ begin
 
   IsLibrary:=true;
 
+  asm
+    { Save initial stackpointer }
+    {$ifdef FPC_PIC}
+        call  get1eipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  initialstkptr@GOT(%ebx),%ecx
+	movl  %esp,(%ecx)
+    {$else FPC_PIC}
+	movl    %esp,initialstkptr
+    {$endif FPC_PIC}
+  end;
+
   PASCALMAIN;
 end;
 
-{$ifndef VER2_0}
-
-{ this hack is needed so we can make the reference below to _FPC_shared_lib_start }
-{ local in compiler/systems/t_linux.pas                                           }
-procedure _FPC_SHARED_LIB_START_LOCAL(argc : dword;argv,envp : pointer); cdecl; external;
-
-procedure initdummy; assembler; nostackframe;
-label
-  FPC_LIB_START;
-asm
-.init
-  .align 16
-  .globl FPC_LIB_START
-//    .type FPC_LIB_START,@function
-FPC_LIB_START:
-{$ifdef FPC_PIC}
-  jmp	_FPC_SHARED_LIB_START_LOCAL@PLT
-{$else FPC_PIC}
-  jmp	_FPC_SHARED_LIB_START_LOCAL
-{$endif FPC_PIC}
-.text
-end;
-{$endif VER_2_0}
+Procedure lib_exit; external name 'FPC_LIB_EXIT';
 
-procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name '_haltproc';
+procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name 'FPC_SHARED_LIB_EXIT'; public name '_haltproc';
 asm
-{$ifdef FPC_PIC}
-  call    fpc_geteipasebx
-  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
-{$endif}
 .Lhaltproc:
-  xorl    %eax,%eax
-  incl    %eax                    { eax=1, exit call }
-{$ifdef FPC_PIC}
-  pushl   %ebx
+  call	  lib_exit
+ {$ifdef FPC_PIC}
+  call    get1eipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
   movl    ExitCode@GOT(%ebx),%ebx
-{$if sizeof(ExitCode)=2}
+ {$if sizeof(ExitCode)=2}
   movzwl  (%ebx),%ebx
-{$else}
+ {$else}
   mov     (%ebx),%ebx
-{$endif}
-{$endif}
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
+  movzwl  ExitCode,%ebx
+ {$else}
+  mov     ExitCode,%ebx
+ {$endif}
+{$endif FPC_PIC}
+  xorl    %eax,%eax
+  incl    %eax                    { eax=1, exit call }
   int     $0x80
   jmp     .Lhaltproc
-  popl    %ebx
 end;
-

+ 15 - 3
rtl/linux/i386/si_g.inc

@@ -90,11 +90,23 @@ end;
 procedure _FPC_proc_gprof_haltproc; assembler; nostackframe; public name '_haltproc';
 asm
 .Lhaltproc:
-{$if sizeof(ExitCode)=2}
+ {$ifdef FPC_PIC}
+  call    fpc_geteipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
   movzwl  ExitCode,%ebx
-{$else}
+ {$else}
   mov     ExitCode,%ebx
-{$endif}
+ {$endif}
+{$endif FPC_PIC}
+
   pushl   %ebx
   call    libc_exit     { call libc exit, this will  write the gmon.out }
   movl    syscall_nr_exit_group,%eax

+ 86 - 19
rtl/linux/i386/si_prc.inc

@@ -35,10 +35,16 @@
 
 procedure PASCALMAIN; external name 'PASCALMAIN';
 
+function fpc_geteipasebx : pointer; compilerproc; nostackframe; assembler;
+asm  
+  movl (%esp),%ebx  
+  ret  
+end;
+
 {******************************************************************************
                           Process start/halt
  ******************************************************************************}
-{$asmmode ATT}
+{$asmmode att}
 
 var
   dlexitproc: pointer;
@@ -46,27 +52,54 @@ var
 procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
 asm
   { First locate the start of the environment variables }
+
   popl    %ecx                    { Get argc in ecx }
+
   movl    %esp,%ebx               { Esp now points to the arguments }
   leal    4(%esp,%ecx,4),%eax     { The start of the environment is: esp+4*eax+4 }
   andl    $0xfffffff8,%esp        { Align stack }
 
-  movl    %eax,operatingsystem_parameter_envp
-  movl    %ecx,operatingsystem_parameter_argc
-  movl    %ebx,operatingsystem_parameter_argv
+  {$ifdef FPC_PIC}
+        pushl %ebx
+        pushl %ecx
+	
+	call fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+
+	movl  dlexitproc@GOT(%ebx),%ecx
+	movl  %edx,(%ecx)
+
+	movl  operatingsystem_parameter_envp@GOT(%ebx),%ecx
+	movl  %eax,(%ecx)
 
-  movl    %edx, dlexitproc
+	movl  operatingsystem_parameter_argc@GOT(%ebx),%edx
+	popl  %ecx
+	movl  %ecx,(%edx)
 
-  fninit                           { initialize fpu }
-  fwait
-  fldcw   Default8087CW
+	movl  operatingsystem_parameter_argv@GOT(%ebx),%edx
+	popl  %ebx
+	movl  %ebx,(%edx)
+  {$else FPC_PIC}
+  	movl  %edx, dlexitproc
+  	movl  %eax,operatingsystem_parameter_envp
+  	movl  %ecx,operatingsystem_parameter_argc
+  	movl  %ebx,operatingsystem_parameter_argv
+  {$endif FPC_PIC}
 
-  { Initialize gs for thread local storage }
-  // movw    %ds,%ax 
-  // movw    %ax,%gs
+  { Initialize FPU }
+  call SysResetFPU
 
   { Save initial stackpointer }
-  movl    %esp,initialstkptr
+  {$ifdef FPC_PIC}
+        pushl %ebx
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+	movl  initialstkptr@GOT(%ebx),%ebx
+  	movl  %esp,(%ebx)
+	popl  %ebx
+  {$else FPC_PIC}
+  	movl    %esp,initialstkptr
+  {$endif FPC_PIC}
 
   xorl    %ebp,%ebp
   call    PASCALMAIN
@@ -74,25 +107,59 @@ end;
 
 procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
 asm
+
 .Lhaltproc:
-  movl    dlexitproc,%eax
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+	movl  dlexitproc@GOT(%ebx),%eax
+	movl  (%eax),%eax
+  {$else FPC_PIC}
+  	movl    dlexitproc,%eax
+  {$endif FPC_PIC}
   testl   %eax,%eax
   je      .Lnodlexitproc
   call    *%eax
 .Lnodlexitproc:
   movl    syscall_nr_exit_group,%eax
-{$if sizeof(ExitCode)=2}  
+
+{$ifdef FPC_PIC}
+  call    fpc_geteipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
   movzwl  ExitCode,%ebx
-{$else}
+ {$else}
   mov     ExitCode,%ebx
-{$endif}
+ {$endif}
+{$endif FPC_PIC}
+
   int     $0x80
   movl    syscall_nr_exit,%eax
-{$if sizeof(ExitCode)=2}  
+
+{$ifdef FPC_PIC}
+  call    fpc_geteipasebx
+  addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+  movl    ExitCode@GOT(%ebx),%ebx
+ {$if sizeof(ExitCode)=2}
+  movzwl  (%ebx),%ebx
+ {$else}
+  mov     (%ebx),%ebx
+ {$endif}
+{$else FPC_PIC}
+ {$if sizeof(ExitCode)=2}
   movzwl  ExitCode,%ebx
-{$else}
+ {$else}
   mov     ExitCode,%ebx
-{$endif}
+ {$endif}
+{$endif FPC_PIC}
+
   int     $0x80
   jmp     .Lhaltproc
 end;

+ 116 - 53
rtl/linux/i386/si_uc.inc

@@ -40,75 +40,138 @@
 }
 
 
-procedure libc_init; external name '__uClibc_init';
-procedure libc_fini; external name '__uClibc_fini';
-procedure libc_exit; external name '_exit';
-procedure libc_main; external name '__uClibc_main';
+var
+  dlexitproc: pointer; { atexit from loader }
 
+procedure uclibc_init; external name '__uClibc_init';
+procedure uclibc_fini; external name '__uClibc_fini';
+procedure uclibc_exit; external name '_exit';
+procedure uclibc_main; external name '__uClibc_main';
 procedure PASCALMAIN; external name 'PASCALMAIN';
 
+{ Some helpers }
+
+{$ifdef FPC_PIC}
+function get3eipasebx : pointer; compilerproc; nostackframe; assembler; 
+asm  
+  movl (%esp),%ebx  
+  ret  
+end;
+{$endif FPC_PIC}
+
+procedure _init_fini_dummy; compilerproc; nostackframe; assembler;
+asm
+  ret
+end; 
+
 {******************************************************************************
-                          C library start/halt
+                       glibc 2.1 lib + profiling start/halt
  ******************************************************************************}
 {$asmmode ATT}
 
-procedure _FPC_libc_start; assembler; nostackframe; public name '_start';
+procedure _FPC_libc21_start; assembler; nostackframe; public name '_start';
 asm
-  xorl    %ebp,%ebp               { clear outer most frame for backtraces }
-  popl    %esi                    { Get argc in ecx }
-  movl    %esp,%ecx               { Esp now points to the arguments }
-  leal    4(%esp,%esi,4),%eax     { The start of the environment is: esp+4*eax+8 }
-  andl    $0xfffffff0,%esp        { Align stack }
-  pushl   %eax                    { push garbage, so we push 32 bytes in total }
-
-  movl    %eax,operatingsystem_parameter_envp    { save the environment pointer }
-  movl    %esi,operatingsystem_parameter_argc    { save the argument counter    }
-  movl    %ecx,operatingsystem_parameter_argv    { save the argument pointer    }
-  movl    %esp,initialstkptr                     { save initial stack pointer   }
-
-  pushl   %esp            { provide highest stack address to C library }
-  pushl   %edx            { push address of shared library finalization }
-
-{$ifdef PIC}
-  call    .L0
-.L0:
-  pop     %ebx
-  addl    $_GLOBAL_OFFSET_TABLE_+[.-.L0],%ebx
-
-  pushl   _fini@GOT(%ebx) { push address of entry points }
-  pushl   _init@GOT(%ebx)
-
-  pushl   %ecx            { push argv }                                 
-  pushl   %esi            { push argc }
-                                                                       
-  pushl   $PASCALMAIN     { push fpc main procedure }
-  call    libc_main       { let fpc main be called from libc startup }
-{$else}
-  pushl   $libc_fini      { push address of entry points }
-  pushl   $libc_init
-
-  pushl   %ecx            { push argv }
-  pushl   %esi            { push argc }
-
-  pushl   $PASCALMAIN     { push fpc main procedure }
-  call    libc_main       { let fpc main be called from libc startup }
-{$endif}
+  xorl    %ebp,%ebp
+  { First locate the start of the environment variables }
+
+  popl    %ecx                    { Get argc in ecx }
+
+  movl    %esp,%ebx               { Esp now points to the arguments }
+  leal    4(%esp,%ecx,4),%eax     { The start of the environment is: esp+4*eax+4 }
+  andl    $0xfffffff8,%esp        { Align stack }
+
+  {$ifdef FPC_PIC}
+        pushl %edx
+        pushl %ebx
+        pushl %ecx
+	
+	call get3eipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+
+	movl  dlexitproc@GOT(%ebx),%ecx 
+	movl  %edx,(%ecx)
+
+	movl  operatingsystem_parameter_envp@GOT(%ebx),%ecx
+	movl  %eax,(%ecx)
+
+	movl  operatingsystem_parameter_argc@GOT(%ebx),%edx
+	popl  %ecx
+	movl  %ecx,(%edx)
+
+	movl  operatingsystem_parameter_argv@GOT(%ebx),%edx
+	popl  %ebx
+	movl  %ebx,(%edx)
+	popl  %edx
+  {$else FPC_PIC}
+  	movl  %edx, dlexitproc
+  	movl  %eax,operatingsystem_parameter_envp
+  	movl  %ecx,operatingsystem_parameter_argc
+  	movl  %ebx,operatingsystem_parameter_argv
+  {$endif FPC_PIC}
+
+  { Save initial stackpointer }
+  {$ifdef FPC_PIC}
+        pushl %ebx
+        call  get3eipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+	movl  initialstkptr@GOT(%ebx),%ebx
+  	movl  %esp,(%ebx)
+	popl  %ebx
+  {$else FPC_PIC}
+  	movl    %esp,initialstkptr
+  {$endif FPC_PIC}
+
+        { int __libc_start_main(
+		int *(main) (int, char * *, char * *), 
+		int argc, 
+		char * * ubp_av, 
+		void (*init) (void), 
+		void (*fini) (void), 
+		void (*rtld_fini) (void), 
+		void (* stack_end)); } 
+
+        pushl %ebp   			{ padding }
+        pushl %esp   			{ stack_end }
+        pushl %edx   			{ function to be registered with
+                      			  atexit(), passed by loader }
+  	pushl $_init_fini_dummy
+  	pushl $_init_fini_dummy
+	pushl %ebx             		{ Push second argument: argv.  }
+	pushl %ecx             		{ Push first argument: argc.  }
+
+	pushl $PASCALMAIN
+
+  	call  uclibc_main
+	hlt
 end;
 
-procedure _FPC_libc_haltproc; assembler; nostackframe; public name '_haltproc';
+procedure _FPC_libc21_haltproc; assembler; nostackframe; public name '_haltproc';
 asm
 .Lhaltproc:
-{$if sizeof(ExitCode)=2}
-  movzwl  ExitCode,%ebx
-{$else}
-  mov     ExitCode,%ebx
-{$endif}
+
+  {$ifdef FPC_PIC}
+        call    get3eipasebx
+        addl    $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl    ExitCode@GOT(%ebx),%ebx
+    {$if sizeof(ExitCode)=2}
+        movzwl  (%ebx),%ebx
+    {$else}
+        mov     (%ebx),%ebx
+    {$endif}
+  {$else FPC_PIC}
+    {$if sizeof(ExitCode)=2}
+        movzwl  ExitCode,%ebx
+    {$else}
+        mov     ExitCode,%ebx
+    {$endif}
+  {$endif FPC_PIC}
+
   pushl   %ebx
-  call    libc_exit
+  call    uclibc_exit
   xorl    %eax,%eax
   incl    %eax                    { eax=1, exit call }
   popl    %ebx
   int     $0x80
   jmp     .Lhaltproc
-end;
 
+end;

+ 219 - 53
rtl/linux/i386/syscall.inc

@@ -77,17 +77,34 @@ end;
 
 Procedure fpc_geteipasebx;[external name 'fpc_geteipasebx'];
 
-function FpSysCall(sysnr:TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL0'];
+function FpSysCall(sysnr:TSysParam):TSysResult; assembler; register;  [public,alias:'FPC_SYSCALL0'];
 { Var sysnr located in register eax }
 asm
-//      movl  sysnr,%eax
-        cmp  $0, sysenter_supported
-        jne  .LSysEnter
-        int $0x80
+        push  %ebx
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
+        cmp   $0, sysenter_supported
+  {$endif FPC_PIC}
+        jne   .LSysEnter
+        int   $0x80
         jmp   .LTail
   .LSysEnter:
-        call psysinfo
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+	call  *%ecx
+  {$else FPC_PIC}
+        call  psysinfo
+  {$endif FPC_PIC}
   .LTail:
+	pop   %ecx
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax
@@ -96,21 +113,40 @@ asm
   .LSyscOK:
 end;
 
+
 function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler; register; [public,alias:'FPC_SYSCALL1'];
 { Var sysnr located in register eax
   Var param1 located in register edx }
 asm
-        movl  %ebx,%ecx
-//      movl  sysnr,%eax
-        movl  %edx,%ebx
+        push  %ebx
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
         cmp   $0, sysenter_supported
+  {$endif FPC_PIC}
+
         jne   .LSysEnter
+        movl  %edx,%ebx		// param1
         int   $0x80
         jmp   .LTail
   .LSysEnter:
-        call psysinfo
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        movl  %edx,%ebx		// param1
+	call  *%ecx
+  {$else FPC_PIC}
+        movl  %edx,%ebx		// param1
+        call  psysinfo
+  {$endif FPC_PIC}
   .LTail:
-        movl  %ecx,%ebx
+	pop   %ecx
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax
@@ -125,17 +161,37 @@ function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler; regis
   Var param2 located in register ecx }
 asm
         push  %ebx
-//      movl  sysnr,%eax
-        movl  %edx,%ebx
-//      movl  param2,%ecx
+        push  %edx
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
         cmp   $0, sysenter_supported
+  {$endif FPC_PIC}
         jne   .LSysEnter
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
         int   $0x80
         jmp   .LTail
   .LSysEnter:
-        call psysinfo
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  %edx,%ebx		// param1
+        movl  (%ecx),%edx
+	pop   %ecx		// param2
+	call  *%edx
+  {$else FPC_PIC}
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        call  psysinfo
+  {$endif FPC_PIC}
   .LTail:
-        pop   %ebx
+	pop   %edx
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax
@@ -149,20 +205,45 @@ function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;
   Var param1 located in register edx
   Var param2 located in register ecx
   Var param3 located at ebp+20 }
+var
+  _psysinfo: LongWord;
 asm
         push  %ebx
-//      movl  sysnr,%eax
-        movl  %edx,%ebx
-//      movl  param2,%ecx
-        movl  param3,%edx
+        push  %edx
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
         cmp   $0, sysenter_supported
+  {$endif FPC_PIC}
         jne   .LSysEnter
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
         int   $0x80
         jmp   .LTail
   .LSysEnter:
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        movl  %ecx,_psysinfo
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        call  _psysinfo 
+  {$else FPC_PIC}
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
         call psysinfo
+  {$endif FPC_PIC}
   .LTail:
-        pop   %ebx
+	pop   %edx
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax
@@ -177,23 +258,48 @@ function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; asse
   Var param2 located in register ecx
   Var param3 located at ebp+20
   Var param4 located at ebp+16 }
+var
+  _psysinfo: LongWord;
 asm
         push  %ebx
         push  %esi
-//      movl  sysnr,%eax
-        movl  %edx,%ebx
-//      movl  param2,%ecx
-        movl  param3,%edx
-        movl  param4,%esi
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
         cmp   $0, sysenter_supported
-        jne   .LSysEnter
+  {$endif FPC_PIC}
+        jne  .LSysEnter
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
         int   $0x80
-        jmp  .LTail
+        jmp   .LTail
   .LSysEnter:
-        call psysinfo
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        movl  %ecx,_psysinfo
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+        call  _psysinfo 
+  {$else FPC_PIC}
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+        call  psysinfo
+  {$endif FPC_PIC}
   .LTail:
-        pop   %esi
-        pop   %ebx
+  	pop   %esi
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax
@@ -209,26 +315,55 @@ function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysRes
   Var param3 located at ebp+20
   Var param4 located at ebp+16
   Var param5 located at ebp+12 }
+var
+  _psysinfo: LongWord;
 asm
         push  %ebx
+        push  %edx
         push  %esi
         push  %edi
-//      movl  sysnr,%eax
-        movl  %edx,%ebx
-//      movl  param2,%ecx
-        movl  param3,%edx
-        movl  param4,%esi
-        movl  param5,%edi
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
         cmp   $0, sysenter_supported
+  {$endif FPC_PIC}
         jne   .LSysEnter
-        int   $0x80
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+	movl  param5,%edi	// param5
+        int $0x80
         jmp   .LTail
   .LSysEnter:
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        movl  %ecx,_psysinfo
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+	movl  param5,%edi	// param5
+        call  _psysinfo 
+  {$else FPC_PIC}
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+	movl  param5,%edi	// param5
         call psysinfo
+  {$endif FPC_PIC}
   .LTail:
-        pop   %edi
-        pop   %esi
-        pop   %ebx
+  	pop   %edi
+  	pop   %esi
+	pop   %edx
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax
@@ -245,29 +380,60 @@ function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6: TSysParam):T
   Var param4 located at ebp+16
   Var param5 located at ebp+12
   Var param6 located at ebp+8 }
+var
+  _psysinfo: LongWord;
 asm
         push  %ebx
+	push  %edx
         push  %esi
         push  %edi
-        push  %ebp
-//      movl  sysnr,%eax
-        movl  %edx,%ebx
-//      movl  param2,%ecx
-        movl  param3,%edx
-        movl  param4,%esi
-        movl  param5,%edi
-        movl  param6,%ebp
+	push  %ebp
+        push  %ecx
+  {$ifdef FPC_PIC}
+        call  fpc_geteipasebx
+        addl  $_GLOBAL_OFFSET_TABLE_,%ebx
+        movl  sysenter_supported@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        cmp   $0, %ecx
+  {$else FPC_PIC}
         cmp   $0, sysenter_supported
+  {$endif FPC_PIC}
         jne   .LSysEnter
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+	movl  param5,%edi	// param5
+	movl  param6,%ebp	// param6
         int   $0x80
         jmp   .LTail
   .LSysEnter:
+  {$ifdef FPC_PIC}
+        movl  psysinfo@GOT(%ebx),%ecx
+        movl  (%ecx),%ecx
+        movl  %ecx,_psysinfo
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+	movl  param5,%edi	// param5
+	movl  param6,%ebp	// param6
+        call  _psysinfo 
+  {$else FPC_PIC}
+        movl  %edx,%ebx		// param1
+	pop   %ecx		// param2
+        movl  param3,%edx	// param3
+        movl  param4,%esi	// param4
+	movl  param5,%edi	// param5
+	movl  param6,%ebp	// param6
         call psysinfo
+  {$endif FPC_PIC}
   .LTail:
-        pop   %ebp
-        pop   %edi
-        pop   %esi
-        pop   %ebx
+	pop   %ebp
+  	pop   %edi
+  	pop   %esi
+	pop   %edx
+	pop   %ebx
         cmpl  $-4095,%eax
         jb    .LSyscOK
         negl  %eax

+ 6 - 3
rtl/linux/m68k/dllprt0.as

@@ -19,9 +19,9 @@
         .globl  _startlib
         .type   _startlib,@function
 _startlib:
-        .globl  FPC_LIB_START
-        .type   FPC_LIB_START,@function
-FPC_LIB_START:
+        .globl  FPC_SHARED_LIB_START
+        .type   FPC_SHARED_LIB_START,@function
+FPC_SHARED_LIB_START:
 |
 |       The args and envs are not tested yet
 |
@@ -36,6 +36,9 @@ FPC_LIB_START:
         .globl  _haltproc
         .type   _haltproc,@function
 haltproc:
+        .globl  FPC_SHARED_LIB_EXIT
+        .type   FPC_SHARED_LIB_EXIT,@function
+FPC_SHARED_LIB_EXIT:
         moveq.l   #1,%d0
         move.w    U_SYSLINUX_EXITCODE,%d1
         trap      #0

+ 7 - 3
rtl/linux/x86_64/dllprt0.as

@@ -35,9 +35,9 @@
 */
 .section .init
 	.align 16
-	.globl FPC_LIB_START
-	.type FPC_LIB_START,@function
-FPC_LIB_START:
+	.globl FPC_SHARED_LIB_START
+	.type FPC_SHARED_LIB_START,@function
+FPC_SHARED_LIB_START:
 	jmp	_startlib@PLT
 
         .text
@@ -68,6 +68,10 @@ _startlib:
         .globl  _haltproc
         .type   _haltproc,@function
 _haltproc:
+	.globl FPC_SHARED_LIB_EXIT
+	.type FPC_SHARED_LIB_EXIT,@function
+FPC_SHARED_LIB_EXIT:
+	call	FPC_LIB_EXIT@PLT
         movl    $231,%eax                 /* exit_group call */
         movq    operatingsystem_result@GOTPCREL(%rip),%rbx
         movzwl  (%rbx),%edi

+ 19 - 3
rtl/unix/video.pp

@@ -1078,7 +1078,7 @@ begin
      if UTF8Enabled then
        external_codepage:=utf8;
    {$ifdef linux}
-     if vcs_device>=0 then
+     if (vcs_device>=0) and (external_codepage<>utf8) then
        begin
          str(vcs_device,s);
          fname:='/dev/vcsa'+s;
@@ -1116,14 +1116,24 @@ begin
          cur_term_strings:=terminal_data[i];
     if cur_term_strings=@term_codes_xterm then
     begin
+      {$ifdef haiku}
+      TerminalSupportsBold := true;
+      TerminalSupportsHighIntensityColors := false;
+      {$else}
       TerminalSupportsBold := false;
       TerminalSupportsHighIntensityColors := true;
+      {$endif}
     end
     else
     begin
       TerminalSupportsBold := true;
       TerminalSupportsHighIntensityColors := false;
     end;
+    if cur_term_strings=@term_codes_beos then
+    begin
+      TerminalSupportsBold := false;
+      TerminalSupportsHighIntensityColors := false;      
+    end;  
     if cur_term_strings=@term_codes_freebsd then
       console:=ttyFreeBSD;
 {$ifdef linux}
@@ -1231,8 +1241,14 @@ begin
        begin
          {Executed in case ttylinux is false (i.e. no vcsa), but
           TERM=linux.}
-         {Enable the character set set through setfont}
-         fpwrite(stdoutputhandle,font_custom,3);
+
+         { if we're in utf8 mode, we didn't change the font, so
+           no need to restore anything }
+         if external_codepage<>utf8 then
+         begin
+           {Enable the character set set through setfont}
+           fpwrite(stdoutputhandle,font_custom,3);
+         end;
        end;
 {$ifdef linux}
    end;

+ 2 - 1
rtl/win/systhrd.inc

@@ -107,7 +107,8 @@ CONST
       begin	    
 {$ifdef dummy}
         { it least in the on windows 7 x64, this still doesn't not work, fs:(0x2c) is
-          self referencing on this system (FK) }
+          self referencing on this system (FK) 
+          MVC: It also does not work on Windows Vista 32-bit, Home Premium, SP 1. Results in a crash}
         asm
           movl TLSKey,%edx
           movl %fs:(0x2c),%eax

+ 1 - 1
rtl/win/wininc/defines.inc

@@ -2830,7 +2830,7 @@ Type
      TPM_VERTICAL    = $40;
      TPM_TOPALIGN    = 0;
      TPM_VCENTERALIGN= $10;
-     TPM_BOOTOMALIGN = $20;
+     TPM_BOTTOMALIGN = $20;
      TPM_NONOTIFY    = $80;
      TPM_RETURNCMD   = $100;
      TPM_RECURSE         = $0001;

+ 38 - 0
tests/test/packages/hash/sha1test.pp

@@ -0,0 +1,38 @@
+program sha1test;
+{$mode objfpc}{$h+}
+
+uses sha1;
+
+var
+  code: cardinal;
+  s, sdig: string;
+  i: integer;
+  ctx: TSHA1Context;
+  d: TSHA1Digest;
+begin
+  code := 0;
+  sdig := SHA1Print(SHA1String('abc'));
+  if sdig <> 'a9993e364706816aba3e25717850c26c9cd0d89d' then
+    code := code or 1;
+    
+  sdig := SHA1Print(SHA1String('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'));
+  if sdig <> '84983e441c3bd26ebaae4aa1f95129e5e54670f1' then
+    code := code or 2;
+
+  // SHA-1 of a million 'a' symbols
+  SetLength(s, 1000);
+  for i := 1 to 1000 do s[i] := 'a';
+  SHA1Init(ctx);
+  for i := 0 to 999 do
+    SHA1Update(ctx, PChar(s)^, 1000);
+  SHA1Final(ctx, d);
+  sdig := SHA1Print(d);
+  if sdig <> '34aa973cd4c4daa4f61eeb2bdbad27316534016f' then
+    code := code or 4;
+
+  if code = 0 then
+    writeln('Basic SHA-1 tests passed')
+  else
+    writeln('SHA-1 tests failed: ', code);
+  Halt(code);
+end.

+ 1 - 0
tests/test/tobjc1.pp

@@ -9,6 +9,7 @@ var
 begin
   a:=NSObject(NSObject(NSObject.alloc).init);
   if a.respondstoselector_(objcselector('isKindOfClass:')) then
+
     writeln('ok string selector!')
   else
     halt(1);

+ 6 - 6
tests/webtbs/tw12038.pp

@@ -1,4 +1,4 @@
-{$M+}
+{$M+}
 program RTTI132;
 
 {$IFDEF FPC}
@@ -357,11 +357,11 @@ end;
 const
   expectedresults: array[0..6] of ansistring = (
     '',
-    'function (out Out1: Int64; const P: Pointer; var array of reference ?Array1: AnsiString): Int64 of object;',
-    'procedure (const adresse ?Component4: TComponent; adresse ?out Component3: TComponent; var adresse ?Component2: TComponent; adresse ?Component1: TComponent) of object;',
-    'function (array of reference ?out D: Byte; var array of reference ?C: Byte; const array of reference ?B: Byte; array of reference ?A: Byte): TComponent of object;',
-    'function (const A: LongInt; var S: AnsiString): Int64 of object;',
-    'function (Six: LongInt; array of reference ?Five: Byte; Four: PInteger; adresse ?out Three: TMyObject; var Two: LongInt; const A: AnsiString): AnsiString of object;',
+    'function (var array of reference ?Array1: AnsiString; const P: Pointer; out Out1: Int64): Int64 of object;',
+    'procedure (adresse ?Component1: TComponent; var adresse ?Component2: TComponent; adresse ?out Component3: TComponent; const adresse ?Component4: TComponent) of object;',
+    'function (array of reference ?A: Byte; const array of reference ?B: Byte; var array of reference ?C: Byte; array of reference ?out D: Byte): TComponent of object;',
+    'function (var S: AnsiString; const A: LongInt): Int64 of object;',
+    'function (const A: AnsiString; var Two: LongInt; adresse ?out Three: TMyObject; Four: PInteger; array of reference ?Five: Byte; Six: LongInt): AnsiString of object;',
     'procedure (var S: AnsiString) of object;'
     );
 begin