mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 12:49:33 +02:00
* Fixed: import Address Table should contain the same data as Import Lookup Table.
* Perform import by name with index as hint, if both import name and import index are specified. * Fixed import by ordinal when external linker is used. * Fixed some warnings and notes. git-svn-id: trunk@9083 -
This commit is contained in:
parent
d9e0f078e1
commit
13d948c07b
@ -171,7 +171,7 @@ interface
|
||||
function resolve_unit(id:longint):tmodule;
|
||||
procedure allunitsused;
|
||||
procedure setmodulename(const s:string);
|
||||
procedure AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean);
|
||||
procedure AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
|
||||
property ImportLibraryList : TFPHashObjectList read FImportLibraryList;
|
||||
end;
|
||||
|
||||
@ -907,7 +907,7 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
procedure TModule.AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean);
|
||||
procedure TModule.AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
|
||||
var
|
||||
ImportLibrary : TImportLibrary;
|
||||
ImportSymbol : TFPHashObject;
|
||||
@ -917,7 +917,12 @@ implementation
|
||||
ImportLibrary:=TImportLibrary.Create(ImportLibraryList,libname);
|
||||
ImportSymbol:=TFPHashObject(ImportLibrary.ImportSymbolList.Find(symname));
|
||||
if not assigned(ImportSymbol) then
|
||||
ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,symname,OrdNr,isvar);
|
||||
begin
|
||||
if not ImportByOrdinalOnly then
|
||||
{ negative ordinal number indicates import by name with ordinal number as hint }
|
||||
OrdNr:=-OrdNr;
|
||||
ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,symname,OrdNr,isvar);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -2372,11 +2372,40 @@ const pemagic : array[0..3] of byte = (
|
||||
idata4label,
|
||||
idata5label,
|
||||
idata6label : TObjSymbol;
|
||||
ordint,
|
||||
emptyint : longint;
|
||||
secname,
|
||||
num : string;
|
||||
absordnr: word;
|
||||
|
||||
procedure WriteTableEntry;
|
||||
var
|
||||
ordint: dword;
|
||||
begin
|
||||
if AOrdNr <= 0 then
|
||||
begin
|
||||
{ import by name }
|
||||
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
{ import by ordinal }
|
||||
ordint:=AOrdNr;
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
begin
|
||||
internalobjdata.writebytes(ordint,sizeof(ordint));
|
||||
ordint:=$80000000;
|
||||
internalobjdata.writebytes(ordint,sizeof(ordint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
ordint:=ordint or $80000000;
|
||||
internalobjdata.writebytes(ordint,sizeof(ordint));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
result:=nil;
|
||||
emptyint:=0;
|
||||
@ -2403,6 +2432,7 @@ const pemagic : array[0..3] of byte = (
|
||||
num:=tostr(idatalabnr);
|
||||
idata6label:=internalobjdata.SymbolDefine('__imp_'+num,AB_LOCAL,AT_DATA);
|
||||
absordnr:=Abs(AOrdNr);
|
||||
{ write index hint }
|
||||
internalobjdata.writebytes(absordnr,2);
|
||||
if AOrdNr <= 0 then
|
||||
internalobjdata.writebytes(afuncname[1],length(afuncname));
|
||||
@ -2411,27 +2441,7 @@ const pemagic : array[0..3] of byte = (
|
||||
{ idata4, import lookup table }
|
||||
internalobjdata.SetSection(idata4objsection);
|
||||
idata4label:=internalobjdata.SymbolDefine('__imp_lookup_'+num,AB_LOCAL,AT_DATA);
|
||||
if AOrdNr <= 0 then
|
||||
begin
|
||||
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
ordint:=AOrdNr;
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
begin
|
||||
internalobjdata.writebytes(ordint,sizeof(ordint));
|
||||
ordint:=longint($80000000);
|
||||
internalobjdata.writebytes(ordint,sizeof(ordint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
ordint:=ordint or longint($80000000);
|
||||
internalobjdata.writebytes(ordint,sizeof(ordint));
|
||||
end;
|
||||
end;
|
||||
WriteTableEntry;
|
||||
{ idata5, import address table }
|
||||
internalobjdata.SetSection(idata5objsection);
|
||||
{ dummy back links }
|
||||
@ -2442,9 +2452,7 @@ const pemagic : array[0..3] of byte = (
|
||||
result:=internalobjdata.SymbolDefine(amangledname,AB_GLOBAL,AT_DATA)
|
||||
else
|
||||
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));
|
||||
WriteTableEntry;
|
||||
{ text, jmp }
|
||||
if not isvar then
|
||||
begin
|
||||
|
@ -824,7 +824,7 @@ implementation
|
||||
include(vs.varoptions,vo_is_external);
|
||||
vs.varregable := vr_none;
|
||||
if is_dll then
|
||||
current_module.AddExternalImport(dll_name,C_Name,0,true)
|
||||
current_module.AddExternalImport(dll_name,C_Name,0,true,false)
|
||||
else
|
||||
if tf_has_dllscanner in target_info.flags then
|
||||
current_module.dllscannerinputlist.Add(vs.mangledname,vs);
|
||||
|
@ -1620,7 +1620,7 @@ implementation
|
||||
|
||||
{ Import DLL specified? }
|
||||
if assigned(pd.import_dll) then
|
||||
current_module.AddExternalImport(pd.import_dll^,proc_get_importname(pd),pd.import_nr,false)
|
||||
current_module.AddExternalImport(pd.import_dll^,proc_get_importname(pd),pd.import_nr,false,pd.import_name=nil)
|
||||
else
|
||||
begin
|
||||
{ add import name to external list for DLL scanning }
|
||||
|
@ -113,6 +113,7 @@ implementation
|
||||
rescmd : '--include $INC -O coff -o $OBJ $RES';
|
||||
rcbin : 'windres';
|
||||
rccmd : '--include $INC -O res -o $RES $RC';
|
||||
resourcefileclass : nil;
|
||||
);
|
||||
|
||||
res_gnu_wince_windres_info : tresinfo =
|
||||
@ -122,8 +123,10 @@ implementation
|
||||
rescmd : '--include $INC -O coff -o $OBJ $RES';
|
||||
rcbin : 'windres';
|
||||
rccmd : '--include $INC -O res -o $RES $RC';
|
||||
resourcefileclass : nil;
|
||||
);
|
||||
|
||||
{$ifdef x86_64}
|
||||
res_win64_gorc_info : tresinfo =
|
||||
(
|
||||
id : res_win64_gorc;
|
||||
@ -131,7 +134,9 @@ implementation
|
||||
rescmd : '/machine x64 /nw /ni /o /fo $OBJ $RES';
|
||||
rcbin : 'gorc';
|
||||
rccmd : '/machine x64 /nw /ni /r /fo $RES $RC';
|
||||
resourcefileclass : nil;
|
||||
);
|
||||
{$endif x86_64}
|
||||
|
||||
|
||||
Procedure GlobalInitSysInitUnitName(Linker : TLinker);
|
||||
@ -301,6 +306,37 @@ implementation
|
||||
idata5objsection,
|
||||
idata6objsection,
|
||||
idata7objsection : TObjSection;
|
||||
absordnr: word;
|
||||
|
||||
procedure WriteTableEntry;
|
||||
var
|
||||
ordint: dword;
|
||||
begin
|
||||
if ordnr <= 0 then
|
||||
begin
|
||||
{ import by name }
|
||||
objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
objdata.writebytes(emptyint,sizeof(emptyint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
{ import by ordinal }
|
||||
ordint:=ordnr;
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
begin
|
||||
objdata.writebytes(ordint,sizeof(ordint));
|
||||
ordint:=$80000000;
|
||||
objdata.writebytes(ordint,sizeof(ordint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
ordint:=ordint or $80000000;
|
||||
objdata.writebytes(ordint,sizeof(ordint));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
objdata:=CreateObjData(cut_normal);
|
||||
if not isvar then
|
||||
@ -318,43 +354,23 @@ implementation
|
||||
objdata.SetSection(idata6objsection);
|
||||
inc(idatalabnr);
|
||||
idata6label:=objdata.SymbolDefine(asmprefix+'_'+tostr(idatalabnr),AB_LOCAL,AT_DATA);
|
||||
objdata.writebytes(ordnr,2);
|
||||
objdata.writebytes(afuncname[1],length(afuncname));
|
||||
absordnr:=Abs(ordnr);
|
||||
{ write index hint }
|
||||
objdata.writebytes(absordnr,2);
|
||||
if ordnr <= 0 then
|
||||
objdata.writebytes(afuncname[1],length(afuncname));
|
||||
objdata.writebytes(emptyint,1);
|
||||
objdata.writebytes(emptyint,align(objdata.CurrObjSec.size,2)-objdata.CurrObjSec.size);
|
||||
{ idata4, import lookup table }
|
||||
objdata.SetSection(idata4objsection);
|
||||
if mangledname<>'' then
|
||||
begin
|
||||
objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
objdata.writebytes(emptyint,sizeof(emptyint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
emptyint:=ordnr;
|
||||
if target_info.system=system_x86_64_win64 then
|
||||
begin
|
||||
objdata.writebytes(emptyint,sizeof(emptyint));
|
||||
emptyint:=longint($80000000);
|
||||
objdata.writebytes(emptyint,sizeof(emptyint));
|
||||
end
|
||||
else
|
||||
begin
|
||||
emptyint:=emptyint or longint($80000000);
|
||||
objdata.writebytes(emptyint,sizeof(emptyint));
|
||||
end;
|
||||
emptyint:=0;
|
||||
end;
|
||||
WriteTableEntry;
|
||||
{ idata5, import address table }
|
||||
objdata.SetSection(idata5objsection);
|
||||
if isvar then
|
||||
implabel:=objdata.SymbolDefine(mangledname,AB_GLOBAL,AT_DATA)
|
||||
else
|
||||
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));
|
||||
WriteTableEntry;
|
||||
{ text, jmp }
|
||||
if not isvar then
|
||||
begin
|
||||
@ -1710,7 +1726,7 @@ implementation
|
||||
ExtName:=current_module.dllscannerinputlist.NameOfIndex(i);
|
||||
if (ExtName=funcname) then
|
||||
begin
|
||||
current_module.AddExternalImport(dllname,funcname,0,false);
|
||||
current_module.AddExternalImport(dllname,funcname,0,false,false);
|
||||
importfound:=true;
|
||||
current_module.dllscannerinputlist.Delete(i);
|
||||
exit;
|
||||
@ -1747,9 +1763,11 @@ implementation
|
||||
****************************************************************************}
|
||||
|
||||
procedure TWinResourceFile.PostProcessResourcefile(const s : ansistring);
|
||||
{$ifdef arm}
|
||||
var
|
||||
f : file;
|
||||
w : word;
|
||||
{$endif arm}
|
||||
begin
|
||||
{$ifdef arm}
|
||||
assign(f,s);
|
||||
|
Loading…
Reference in New Issue
Block a user