Pārlūkot izejas kodu

Merged revisions 1572-1575,1578-1580 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r1572 | florian | 2005-10-23 15:28:43 +0200 (So, 23 Okt 2005) | 2 lines

+ added missing make_simple_ref

........
r1573 | florian | 2005-10-23 15:37:08 +0200 (So, 23 Okt 2005) | 2 lines

* fixed exp to be pic safe

........
r1574 | florian | 2005-10-23 15:48:51 +0200 (So, 23 Okt 2005) | 2 lines

* made syscall.inc pic safe

........
r1575 | florian | 2005-10-23 16:01:08 +0200 (So, 23 Okt 2005) | 2 lines

* fixed typo in previous commit

........
r1578 | florian | 2005-10-23 16:47:09 +0200 (So, 23 Okt 2005) | 2 lines

+ plt support for x86_64

........
r1579 | florian | 2005-10-23 18:57:47 +0200 (So, 23 Okt 2005) | 2 lines

+ plt for export jmps

........
r1580 | florian | 2005-10-23 18:59:59 +0200 (So, 23 Okt 2005) | 2 lines

* fixed previous commit

........

git-svn-id: branches/fixes_2_0@1583 -

florian 20 gadi atpakaļ
vecāks
revīzija
c8ec0160bf

+ 22 - 4
compiler/systems/t_linux.pas

@@ -64,9 +64,10 @@ implementation
     cutils,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
-    fmodule,dos
-    ,aasmbase,aasmtai,aasmcpu,cpubase,cgobj
-    ,i_linux
+    fmodule,dos,
+    aasmbase,aasmtai,aasmcpu,cpubase,
+    cgbase,cgobj,cgutils,
+    i_linux
     ;
 
 {*****************************************************************************
@@ -156,6 +157,8 @@ end;
 procedure texportliblinux.generatelib;
 var
   hp2 : texported_item;
+  sym : tasmsymbol;
+  r : treference;
 begin
   new_section(codesegment,sec_code,'',0);
   hp2:=texported_item(current_module._exports.first);
@@ -171,7 +174,22 @@ begin
            { place jump in codesegment }
            codesegment.concat(tai_align.create(target_info.alignment.procalign));
            codeSegment.concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
-           cg.a_jmp_name(codesegment,tprocsym(hp2.sym).first_procdef.mangledname);
+           if (cs_create_pic in aktmoduleswitches) and
+             { other targets need to be checked how it works }
+             (target_info.system in [system_x86_64_linux]) then
+             begin
+{$ifdef x86_64}
+               sym:=objectlibrary.newasmsymbol(hp2.name^,AB_EXTERNAL,AT_FUNCTION);
+               reference_reset_symbol(r,sym,0);
+               if cs_create_pic in aktmoduleswitches then
+                 r.refaddr:=addr_pic
+               else
+                 r.refaddr:=addr_full;
+               codesegment.concat(taicpu.op_ref(A_JMP,S_NO,r));
+{$endif x86_64}
+             end
+           else
+             cg.a_jmp_name(codesegment,tprocsym(hp2.sym).first_procdef.mangledname);
            codeSegment.concat(Tai_symbol_end.Createname(hp2.name^));
          end;
       end

+ 2 - 0
compiler/x86/agx86att.pas

@@ -151,6 +151,8 @@ interface
               else
                 begin
                   AsmWrite(o.ref^.symbol.name);
+                  if o.ref^.refaddr=addr_pic then
+                    AsmWrite('@PLT');
                   if o.ref^.offset>0 then
                    AsmWrite('+'+tostr(o.ref^.offset))
                   else

+ 14 - 2
compiler/x86/cgx86.pas

@@ -504,8 +504,17 @@ unit cgx86;
 
 
     procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
+      var
+        sym : tasmsymbol;
+        r : treference;
       begin
-        list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION)));
+        sym:=objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION);
+        reference_reset_symbol(r,sym,0);
+        if cs_create_pic in aktmoduleswitches then
+          r.refaddr:=addr_pic
+        else
+          r.refaddr:=addr_full;
+        list.concat(taicpu.op_ref(A_CALL,S_NO,r));
       end;
 
 
@@ -887,7 +896,10 @@ unit cgx86;
           internalerror(200312215);
         case loc.loc of
           LOC_CREFERENCE,LOC_REFERENCE:
-            list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
+            begin
+              make_simple_ref(exprasmlist,loc.reference);
+              list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
+            end;
           LOC_CMMREGISTER,LOC_MMREGISTER:
             list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
           else

+ 63 - 16
rtl/linux/x86_64/syscall.inc

@@ -26,14 +26,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -52,14 +59,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -79,14 +93,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -107,14 +128,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -136,14 +164,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -166,14 +201,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -198,14 +240,21 @@ asm
   jnae .LSyscOK           { Jump to error handler if error.  }
   negq  %rax
   movq  %rax,%rdx
+{$ifdef FPC_PIC}
+  movq  fpc_threadvar_relocate_proc@GOTPCREL(%rip),%rax
+  movq  (%rax),%rax
+  movq  Errno@GOTPCREL(%rip),%rbx
+{$else FPC_PIC}
   movq  fpc_threadvar_relocate_proc,%rax
+  leaq  Errno,%rbx
+{$endif FPC_PIC}
   testq %rax,%rax
   jne   .LThread
-  movl  %edx,Errno+8
+  movl  %edx,8(%rbx)
   jmp   .LNoThread
 .LThread:
   pushq %rdx
-  movq  Errno,%rdi
+  movq  (%rbx),%rdi
   call  *%rax
   popq  %rdx
   movl  %edx,(%rax)
@@ -219,5 +268,3 @@ end;
 {$IFDEF SYS_LINUX}
   {$UNDEF SYSCALL_DEBUG}
 {$ENDIF SYS_LINUX}
-
-

+ 7 - 15
rtl/x86_64/math.inc

@@ -103,18 +103,19 @@
     {$define FPC_SYSTEM_HAS_EXP}
     function fpc_exp_real(d : ValReal) : ValReal;assembler;compilerproc;
        asm
+            subq        $16,%rsp
             // comes from DJ GPP
             fldt        d
             fldl2e
             fmulp       %st,%st(1)
-            fstcw      .LCW1
-            fstcw      .LCW2
-            andw        $0xf3ff,.LCW2
-            orw         $0x0400,.LCW2
-            fldcw      .LCW2
+            fstcw       -2(%rbp)
+            fstcw       -4(%rbp)
+            andw        $0xf3ff,-4(%rbp)
+            orw         $0x0400,-4(%rbp)
+            fldcw       -4(%rbp)
             fld         %st(0)
             frndint
-            fldcw      .LCW1
+            fldcw       -2(%rbp)
             fxch        %st(1)
             fsub        %st(1),%st
             f2xm1
@@ -122,15 +123,6 @@
             faddp       %st,%st(1)
             fscale
             fstp        %st(1)
-            jmp         .LCW3
-            // store some help data in the data segment
-        .data
-        .LCW1:
-            .word       0
-        .LCW2:
-            .word       0
-        .text
-        .LCW3:
       end;