+ implemented writing proper win16 dll import libraries

git-svn-id: trunk@31532 -
This commit is contained in:
nickysn 2015-09-05 13:45:23 +00:00
parent 049171c69c
commit 393d86a2e5
4 changed files with 70 additions and 17 deletions

View File

@ -136,6 +136,7 @@ interface
public public
constructor create(AWriter:TObjectWriter);override; constructor create(AWriter:TObjectWriter);override;
destructor Destroy;override; destructor Destroy;override;
procedure WriteDllImport(const dllname,afuncname,mangledname:string;ordnr:longint;isvar:boolean);
end; end;
{ TOmfObjInput } { TOmfObjInput }
@ -999,6 +1000,46 @@ implementation
inherited Destroy; inherited Destroy;
end; end;
procedure TOmfObjOutput.WriteDllImport(const dllname,afuncname,mangledname: string; ordnr: longint; isvar: boolean);
var
RawRecord: TOmfRawRecord;
Header: TOmfRecord_THEADR;
DllImport_COMENT: TOmfRecord_COMENT;
ModEnd: TOmfRecord_MODEND;
begin
{ write header record }
RawRecord:=TOmfRawRecord.Create;
Header:=TOmfRecord_THEADR.Create;
Header.ModuleName:=mangledname;
Header.EncodeTo(RawRecord);
RawRecord.WriteTo(FWriter);
Header.Free;
{ write IMPDEF record }
DllImport_COMENT:=TOmfRecord_COMENT.Create;
DllImport_COMENT.CommentClass:=CC_OmfExtension;
if ordnr <= 0 then
begin
if afuncname=mangledname then
DllImport_COMENT.CommentString:=#1#0+Chr(Length(mangledname))+mangledname+Chr(Length(dllname))+dllname+#0
else
DllImport_COMENT.CommentString:=#1#0+Chr(Length(mangledname))+mangledname+Chr(Length(dllname))+dllname+Chr(Length(afuncname))+afuncname;
end
else
DllImport_COMENT.CommentString:=#1#1+Chr(Length(mangledname))+mangledname+Chr(Length(dllname))+dllname+Chr(ordnr and $ff)+Chr((ordnr shr 8) and $ff);
DllImport_COMENT.EncodeTo(RawRecord);
RawRecord.WriteTo(FWriter);
DllImport_COMENT.Free;
{ write MODEND record }
ModEnd:=TOmfRecord_MODEND.Create;
ModEnd.EncodeTo(RawRecord);
RawRecord.WriteTo(FWriter);
ModEnd.Free;
RawRecord.Free;
end;
{**************************************************************************** {****************************************************************************
TOmfObjInput TOmfObjInput
****************************************************************************} ****************************************************************************}

View File

@ -64,6 +64,7 @@ type
function TryWriteDictionaryWithSize(nblocks: Byte): Boolean; function TryWriteDictionaryWithSize(nblocks: Byte): Boolean;
public public
constructor createAr(const Aarfn:string);override; constructor createAr(const Aarfn:string);override;
constructor createAr(const Aarfn:string;PageSize:Integer);
destructor destroy;override; destructor destroy;override;
function createfile(const fn:string):boolean;override; function createfile(const fn:string):boolean;override;
procedure closefile;override; procedure closefile;override;
@ -135,7 +136,12 @@ implementation
constructor TOmfLibObjectWriter.createAr(const Aarfn: string); constructor TOmfLibObjectWriter.createAr(const Aarfn: string);
begin begin
FPageSize:=512; createAr(Aarfn,512);
end;
constructor TOmfLibObjectWriter.createAr(const Aarfn: string;PageSize: Integer);
begin
FPageSize:=PageSize;
FLibName:=Aarfn; FLibName:=Aarfn;
FLibData:=TDynamicArray.Create(libbufsize); FLibData:=TDynamicArray.Create(libbufsize);
FDictionary:=TFPHashObjectList.Create; FDictionary:=TFPHashObjectList.Create;
@ -261,7 +267,7 @@ implementation
libf.Free; libf.Free;
end; end;
function TOmfLibObjectWriter.WriteDictionary: Byte; function TOmfLibObjectWriter.WriteDictionary: byte;
var var
nb: Byte; nb: Byte;
begin begin

View File

@ -64,8 +64,8 @@ unit i_win16;
staticClibext : '.a'; staticClibext : '.a';
staticClibprefix : 'lib'; staticClibprefix : 'lib';
sharedClibprefix : ''; sharedClibprefix : '';
importlibprefix : ''; importlibprefix : 'libimp';
importlibext : '.al'; importlibext : '.a';
Cprefix : '_'; Cprefix : '_';
newline : #13#10; newline : #13#10;
dirsep : '\'; dirsep : '\';

View File

@ -56,9 +56,6 @@ implementation
function MakeExecutable:boolean;override; function MakeExecutable:boolean;override;
end; end;
var
importlist: array of string;
{**************************************************************************** {****************************************************************************
TImportLibWin16 TImportLibWin16
****************************************************************************} ****************************************************************************}
@ -66,21 +63,36 @@ implementation
procedure TImportLibWin16.generatelib; procedure TImportLibWin16.generatelib;
var var
i: Integer; ObjWriter: TOmfLibObjectWriter;
j: Integer; ObjOutput: TOmfObjOutput;
i,j: Integer;
ImportLibrary: TImportLibrary; ImportLibrary: TImportLibrary;
ImportSymbol: TImportSymbol; ImportSymbol: TImportSymbol;
AsmPrefix: String;
procedure AddImport(const dllname,afuncname,mangledname:string;ordnr:longint;isvar:boolean);
begin begin
ObjOutput.startObjectfile(mangledname);
ObjOutput.WriteDllImport(dllname,afuncname,mangledname,ordnr,isvar);
ObjOutput.Writer.closefile;
end;
begin
AsmPrefix:='imp'+Lower(current_module.modulename^);
current_module.linkotherstaticlibs.add(current_module.importlibfilename,link_always);
ObjWriter:=TOmfLibObjectWriter.CreateAr(current_module.importlibfilename,32);
ObjOutput:=TOmfObjOutput.Create(ObjWriter);
for i:=0 to current_module.ImportLibraryList.Count-1 do for i:=0 to current_module.ImportLibraryList.Count-1 do
begin begin
ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]); ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
begin begin
ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]); ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
SetLength(importlist, Length(importlist)+1); AddImport(ImportLibrary.Name,ImportSymbol.Name,ImportSymbol.MangledName,ImportSymbol.OrdNr,ImportSymbol.IsVar);
WriteStr(importlist[high(importlist)],'import ',ImportSymbol.Name,' ',ImportLibrary.Name);
end; end;
end; end;
ObjOutput.Free;
ObjWriter.Free;
end; end;
@ -133,12 +145,6 @@ begin
LinkRes.Add('option map='+maybequoted(ChangeFileExt(current_module.exefilename,'.map'))); LinkRes.Add('option map='+maybequoted(ChangeFileExt(current_module.exefilename,'.map')));
LinkRes.Add('name ' + maybequoted(current_module.exefilename)); LinkRes.Add('name ' + maybequoted(current_module.exefilename));
{ LinkRes.Add('import InitTask KERNEL');
LinkRes.Add('import WaitEvent KERNEL');
LinkRes.Add('import InitApp USER');}
for i:=low(importlist) to high(importlist) do
LinkRes.Add(importlist[i]);
{ Write and Close response } { Write and Close response }
linkres.writetodisk; linkres.writetodisk;
LinkRes.Free; LinkRes.Free;