+ 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
constructor create(AWriter:TObjectWriter);override;
destructor Destroy;override;
procedure WriteDllImport(const dllname,afuncname,mangledname:string;ordnr:longint;isvar:boolean);
end;
{ TOmfObjInput }
@ -999,6 +1000,46 @@ implementation
inherited Destroy;
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
****************************************************************************}

View File

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

View File

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

View File

@ -56,9 +56,6 @@ implementation
function MakeExecutable:boolean;override;
end;
var
importlist: array of string;
{****************************************************************************
TImportLibWin16
****************************************************************************}
@ -66,21 +63,36 @@ implementation
procedure TImportLibWin16.generatelib;
var
i: Integer;
j: Integer;
ObjWriter: TOmfLibObjectWriter;
ObjOutput: TOmfObjOutput;
i,j: Integer;
ImportLibrary: TImportLibrary;
ImportSymbol: TImportSymbol;
AsmPrefix: String;
procedure AddImport(const dllname,afuncname,mangledname:string;ordnr:longint;isvar:boolean);
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
begin
ImportLibrary:=TImportLibrary(current_module.ImportLibraryList[i]);
for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
begin
ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
SetLength(importlist, Length(importlist)+1);
WriteStr(importlist[high(importlist)],'import ',ImportSymbol.Name,' ',ImportLibrary.Name);
AddImport(ImportLibrary.Name,ImportSymbol.Name,ImportSymbol.MangledName,ImportSymbol.OrdNr,ImportSymbol.IsVar);
end;
end;
ObjOutput.Free;
ObjWriter.Free;
end;
@ -133,12 +145,6 @@ begin
LinkRes.Add('option map='+maybequoted(ChangeFileExt(current_module.exefilename,'.map')));
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 }
linkres.writetodisk;
LinkRes.Free;