Browse Source

* also recognise non-GOT based RIP-relative address expressions as PIC

git-svn-id: trunk@16565 -
Jonas Maebe 14 years ago
parent
commit
709f1e8344
2 changed files with 7 additions and 1 deletions
  1. 1 1
      compiler/x86/rax86.pas
  2. 6 0
      compiler/x86/rax86att.pas

+ 1 - 1
compiler/x86/rax86.pas

@@ -230,7 +230,7 @@ begin
       if (cs_create_pic in current_settings.moduleswitches) and
       if (cs_create_pic in current_settings.moduleswitches) and
          assigned(opr.ref.symbol) and
          assigned(opr.ref.symbol) and
          not assigned(opr.ref.relsymbol) and
          not assigned(opr.ref.relsymbol) and
-         (opr.ref.refaddr<>addr_pic) then
+         not(opr.ref.refaddr in [addr_pic,addr_pic_no_got]) then
         begin
         begin
           if (opr.ref.symbol.name <> '_GLOBAL_OFFSET_TABLE_') then
           if (opr.ref.symbol.name <> '_GLOBAL_OFFSET_TABLE_') then
             begin 
             begin 

+ 6 - 0
compiler/x86/rax86att.pas

@@ -176,6 +176,12 @@ Implementation
                  ((oper.opr.typ=OPR_LOCAL) and (oper.opr.localsym.localloc.loc<>LOC_REGISTER)) then
                  ((oper.opr.typ=OPR_LOCAL) and (oper.opr.localsym.localloc.loc<>LOC_REGISTER)) then
                 message(asmr_e_cannot_index_relative_var);
                 message(asmr_e_cannot_index_relative_var);
               oper.opr.ref.base:=actasmregister;
               oper.opr.ref.base:=actasmregister;
+{$ifdef x86_64}
+              { non-GOT based RIP-relative accesses are also position-independent }
+              if (oper.opr.ref.base=NR_RIP) and
+                 (oper.opr.ref.refaddr<>addr_pic) then
+                oper.opr.ref.refaddr:=addr_pic_no_got;
+{$endif x86_64}
               Consume(AS_REGISTER);
               Consume(AS_REGISTER);
               { can either be a register or a right parenthesis }
               { can either be a register or a right parenthesis }
               { (reg)        }
               { (reg)        }