瀏覽代碼

* Asm readers: allow using procedure symbols in references, resolves #22376.
* rax86int.pas: reject RIP-relative references to locals/parameters.

git-svn-id: trunk@29087 -

sergei 10 年之前
父節點
當前提交
475a9e1617
共有 4 個文件被更改,包括 44 次插入6 次删除
  1. 1 0
      .gitattributes
  2. 12 6
      compiler/rautils.pas
  3. 5 0
      compiler/x86/rax86int.pas
  4. 26 0
      tests/webtbs/tw22376.pp

+ 1 - 0
.gitattributes

@@ -13885,6 +13885,7 @@ tests/webtbs/tw22329.pp svneol=native#text/pascal
 tests/webtbs/tw2233.pp svneol=native#text/plain
 tests/webtbs/tw22331.pp svneol=native#text/plain
 tests/webtbs/tw22344.pp svneol=native#text/plain
+tests/webtbs/tw22376.pp svneol=native#text/plain
 tests/webtbs/tw2242.pp svneol=native#text/plain
 tests/webtbs/tw22427.pp svneol=native#text/pascal
 tests/webtbs/tw22428.pp svneol=native#text/pascal

+ 12 - 6
compiler/rautils.pas

@@ -897,14 +897,20 @@ Begin
       end;
     procsym :
       begin
-        if opr.typ<>OPR_NONE then
-          Message(asmr_e_invalid_operand_type);
         if Tprocsym(sym).ProcdefList.Count>1 then
           Message(asmr_w_calling_overload_func);
-        l:=opr.ref.offset;
-        opr.typ:=OPR_SYMBOL;
-        opr.symbol:=current_asmdata.RefAsmSymbol(tprocdef(tprocsym(sym).ProcdefList[0]).mangledname);
-        opr.symofs:=l;
+        case opr.typ of
+          OPR_REFERENCE:
+            opr.ref.symbol:=current_asmdata.RefAsmSymbol(tprocdef(tprocsym(sym).ProcdefList[0]).mangledname);
+          OPR_NONE:
+            begin
+              opr.typ:=OPR_SYMBOL;
+              opr.symbol:=current_asmdata.RefAsmSymbol(tprocdef(tprocsym(sym).ProcdefList[0]).mangledname);
+              opr.symofs:=0;
+            end;
+        else
+          Message(asmr_e_invalid_operand_type);
+        end;
         hasvar:=true;
         SetupVar:=TRUE;
         Exit;

+ 5 - 0
compiler/x86/rax86int.pas

@@ -1420,6 +1420,11 @@ Unit Rax86int;
                     begin
                       if (oper.opr.localindexreg<>NR_NO) then
                         Message(asmr_e_multiple_index);
+{$ifdef x86_64}
+                      { Locals/parameters cannot be accessed RIP-relative. Need a dedicated error message here? }
+                      if (hreg=NR_RIP) then
+                        Message(asmr_e_no_local_or_para_allowed);
+{$endif x86_64}
                       oper.opr.localindexreg:=hreg;
                       if scale<>0 then
                         begin

+ 26 - 0
tests/webtbs/tw22376.pp

@@ -0,0 +1,26 @@
+{ %cpu=i386,x86_64 }
+{ %opt=-Cg- }
+{$mode objfpc}
+{$asmmode intel}
+
+
+function bar: integer;
+begin
+  result:=$12345678;
+end;
+
+function foo: pointer; assembler; nostackframe;
+asm
+{$ifdef x86_64}
+        lea  rax,[bar+rip]
+{$else}
+        lea  eax,[bar]
+{$endif}
+end;
+
+
+begin
+  if (foo<>pointer(@bar)) then
+    halt(1);
+end.
+