* Allow @ and ? characters in imported function name when AS is used. It fixes bug #8391.

+ test.

git-svn-id: trunk@6669 -
This commit is contained in:
yury 2007-02-26 17:51:38 +00:00
parent e0729f1be1
commit 7547f3a0c0
6 changed files with 41 additions and 20 deletions

1
.gitattributes vendored
View File

@ -8049,6 +8049,7 @@ tests/webtbs/tw8264.pp svneol=native#text/plain
tests/webtbs/tw8304.pp svneol=native#text/plain
tests/webtbs/tw8312.pp svneol=native#text/plain
tests/webtbs/tw8321.pp svneol=native#text/plain
tests/webtbs/tw8391.pp svneol=native#text/plain
tests/webtbs/ub1873.pp svneol=native#text/plain
tests/webtbs/ub1883.pp svneol=native#text/plain
tests/webtbs/uw0555.pp svneol=native#text/plain

View File

@ -376,9 +376,11 @@ interface
private
FOrdNr : longint;
FIsVar : boolean;
FMangledName : string;
public
constructor create(AList:TFPHashObjectList;const AName:string;AOrdNr:longint;AIsVar:boolean);
property OrdNr: longint read FOrdNr;
property MangledName: string read FMangledName;
property IsVar: boolean read FIsVar;
end;
@ -1353,6 +1355,10 @@ implementation
inherited Create(AList, AName);
FOrdNr:=AOrdNr;
FIsVar:=AIsVar;
FMangledName:=AName;
{ Replace ? and @ in import name }
Replace(FMangledName,'?','$_q_$');
Replace(FMangledName,'@','$_a_$');
end;

View File

@ -2290,7 +2290,7 @@ const pemagic : array[0..3] of byte = (
internalobjdata.writebytes(emptyint,sizeof(emptyint));
end;
function AddImport(const afuncname:string; AOrdNr:longint;isvar:boolean):TObjSymbol;
function AddImport(const afuncname,amangledname:string; AOrdNr:longint;isvar:boolean):TObjSymbol;
const
{$ifdef x86_64}
jmpopcode : array[0..2] of byte = (
@ -2327,7 +2327,7 @@ const pemagic : array[0..3] of byte = (
with internalobjdata do
begin
secname:=basedllname+'_i_'+afuncname;
secname:=basedllname+'_i_'+amangledname;
textobjsection:=createsection(sectionname(sec_code,secname,secorder_default),current_settings.alignment.procalign,sectiontype2options(sec_code) - [oso_keep]);
idata4objsection:=createsection(sec_idata4, secname);
idata5objsection:=createsection(sec_idata5, secname);
@ -2377,9 +2377,9 @@ const pemagic : array[0..3] of byte = (
internalobjdata.writereloc(0,0,idata2label,RELOC_NONE);
{ section data }
if isvar then
result:=internalobjdata.SymbolDefine(afuncname,AB_GLOBAL,AT_DATA)
result:=internalobjdata.SymbolDefine(amangledname,AB_GLOBAL,AT_DATA)
else
idata5label:=internalobjdata.SymbolDefine('__imp_'+afuncname,AB_LOCAL,AT_DATA);
idata5label:=internalobjdata.SymbolDefine('__imp_'+amangledname,AB_LOCAL,AT_DATA);
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
if target_info.system=system_x86_64_win64 then
internalobjdata.writebytes(emptyint,sizeof(emptyint));
@ -2387,7 +2387,7 @@ const pemagic : array[0..3] of byte = (
if not isvar then
begin
internalobjdata.SetSection(textobjsection);
result:=internalobjdata.SymbolDefine('_'+afuncname,AB_GLOBAL,AT_FUNCTION);
result:=internalobjdata.SymbolDefine('_'+amangledname,AB_GLOBAL,AT_FUNCTION);
internalobjdata.writebytes(jmpopcode,sizeof(jmpopcode));
internalobjdata.writereloc(0,sizeof(longint),idata5label,RELOC_ABSOLUTE32);
internalobjdata.writebytes(nopopcodes,align(internalobjdata.CurrObjSec.size,sizeof(nopopcodes))-internalobjdata.CurrObjSec.size);
@ -2411,13 +2411,13 @@ const pemagic : array[0..3] of byte = (
for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
begin
ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
exesym:=TExeSymbol(ExeSymbolList.Find(ImportSymbol.Name));
exesym:=TExeSymbol(ExeSymbolList.Find(ImportSymbol.MangledName));
if assigned(exesym) and
(exesym.State<>symstate_defined) then
begin
if not assigned(idata2objsection) then
StartImport(ImportLibrary.Name);
exesym.objsymbol:=AddImport(ImportSymbol.Name,ImportSymbol.OrdNr,ImportSymbol.IsVar);
exesym.objsymbol:=AddImport(ImportSymbol.Name,ImportSymbol.MangledName,ImportSymbol.OrdNr,ImportSymbol.IsVar);
exesym.State:=symstate_defined;
end;
end;

View File

@ -2180,7 +2180,12 @@ const
begin
s:=proc_get_importname(pd);
if s<>'' then
pd.setmangledname(s);
begin
{ Replace ? and @ in import name }
Replace(s,'?','$_q_$');
Replace(s,'@','$_a_$');
pd.setmangledname(s);
end;
end;
end
else

View File

@ -255,7 +255,7 @@ implementation
objdata.free;
end;
procedure AddImport(const afuncname:string;ordnr:longint;isvar:boolean);
procedure AddImport(const afuncname,mangledname:string;ordnr:longint;isvar:boolean);
const
{$ifdef x86_64}
jmpopcode : array[0..2] of byte = (
@ -311,7 +311,7 @@ implementation
objdata.writebytes(emptyint,align(objdata.CurrObjSec.size,2)-objdata.CurrObjSec.size);
{ idata4, import lookup table }
objdata.SetSection(idata4objsection);
if afuncname<>'' then
if mangledname<>'' then
begin
objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
if target_info.system=system_x86_64_win64 then
@ -336,9 +336,9 @@ implementation
{ idata5, import address table }
objdata.SetSection(idata5objsection);
if isvar then
implabel:=objdata.SymbolDefine(afuncname,AB_GLOBAL,AT_DATA)
implabel:=objdata.SymbolDefine(mangledname,AB_GLOBAL,AT_DATA)
else
idata5label:=objdata.SymbolDefine(asmprefix+'_'+afuncname,AB_LOCAL,AT_DATA);
idata5label:=objdata.SymbolDefine(asmprefix+'_'+mangledname,AB_LOCAL,AT_DATA);
objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
if target_info.system=system_x86_64_win64 then
objdata.writebytes(emptyint,sizeof(emptyint));
@ -346,8 +346,8 @@ implementation
if not isvar then
begin
objdata.SetSection(textobjsection);
if afuncname <> '' then
implabel:=objdata.SymbolDefine(afuncname,AB_GLOBAL,AT_FUNCTION)
if mangledname <> '' then
implabel:=objdata.SymbolDefine(mangledname,AB_GLOBAL,AT_FUNCTION)
else
implabel:=objdata.SymbolDefine(basedllname+'_index_'+tostr(ordnr),AB_GLOBAL,AT_FUNCTION);
objdata.writebytes(jmpopcode,sizeof(jmpopcode));
@ -378,7 +378,7 @@ implementation
for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
begin
ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
AddImport(ImportSymbol.Name,ImportSymbol.OrdNr,ImportSymbol.IsVar);
AddImport(ImportSymbol.Name,ImportSymbol.MangledName,ImportSymbol.OrdNr,ImportSymbol.IsVar);
end;
EndImport;
end;
@ -489,7 +489,7 @@ implementation
{ place jump in al_procedures }
new_section(current_asmdata.asmlists[al_imports],sec_code,'',0);
if ImportSymbol.Name <> '' then
current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.Name,AT_FUNCTION,0))
current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.MangledName,AT_FUNCTION,0))
else
current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ExtractFileName(ImportLibrary.Name)+'_index_'+tostr(ImportSymbol.ordnr),AT_FUNCTION,0));
current_asmdata.asmlists[al_imports].concat(tai_function_name.create(''));
@ -510,14 +510,14 @@ implementation
new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0);
if (cs_debuginfo in current_settings.moduleswitches) then
begin
if ImportSymbol.Name<>'' then
if ImportSymbol.MangledName<>'' then
begin
importname:='__imp_'+ImportSymbol.Name;
importname:='__imp_'+ImportSymbol.MangledName;
suffix:=0;
while assigned(current_asmdata.getasmsymbol(importname)) do
begin
inc(suffix);
importname:='__imp_'+ImportSymbol.Name+'_'+tostr(suffix);
importname:='__imp_'+ImportSymbol.MangledName+'_'+tostr(suffix);
end;
current_asmdata.asmlists[al_imports].concat(tai_symbol.createname(importname,AT_FUNCTION,4));
end
@ -536,7 +536,7 @@ implementation
current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l4));
end
else
current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.Name,AT_DATA,0));
current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(ImportSymbol.MangledName,AT_DATA,0));
current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(TAsmLabel(Importlabels[j])));
if target_info.system=system_x86_64_win64 then
current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0));

9
tests/webtbs/tw8391.pp Normal file
View File

@ -0,0 +1,9 @@
{ %norun }
{ %target=win32,wince }
{ %opt=-Aas }
Procedure InternalName; CDecl; External 'thedll' name '?ExternalName@Tralala';
Begin
InternalName;
End.