* Asm readers: allow using procedure symbols in references, resolves #22376.

* rax86int.pas: reject RIP-relative references to locals/parameters.

git-svn-id: trunk@29087 -
This commit is contained in:
sergei 2014-11-17 05:34:55 +00:00
parent c53c4702b6
commit 475a9e1617
4 changed files with 44 additions and 6 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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;

View File

@ -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
tests/webtbs/tw22376.pp Normal file
View File

@ -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.