+ Basic executable stack support in TExeOutput.

+ Two stubs (TExeOutput.Load_DynamicObject and TObjInput.CanReadObjData) to override in ELF linker.
+ Stop linking if errors were detected while loading object files.
* Changed TStaticLibrary to TObject. It is never looked up by name, so hashing is redundant; moreover its name has been changed to TCmdStr, which may be trimmed by TFPHashList. 

git-svn-id: trunk@21968 -
This commit is contained in:
sergei 2012-07-25 11:08:54 +00:00
parent 8703a15a83
commit 31d004e056
2 changed files with 29 additions and 10 deletions

View File

@ -93,7 +93,7 @@ interface
FCExeOutput : TExeOutputClass; FCExeOutput : TExeOutputClass;
FCObjInput : TObjInputClass; FCObjInput : TObjInputClass;
{ Libraries } { Libraries }
FStaticLibraryList : TFPHashObjectList; FStaticLibraryList : TFPObjectList;
FImportLibraryList : TFPHashObjectList; FImportLibraryList : TFPHashObjectList;
procedure Load_ReadObject(const para:TCmdStr); procedure Load_ReadObject(const para:TCmdStr);
procedure Load_ReadStaticLibrary(const para:TCmdStr); procedure Load_ReadStaticLibrary(const para:TCmdStr);
@ -112,7 +112,7 @@ interface
IsHandled : PBooleanArray; IsHandled : PBooleanArray;
property CObjInput:TObjInputClass read FCObjInput write FCObjInput; property CObjInput:TObjInputClass read FCObjInput write FCObjInput;
property CExeOutput:TExeOutputClass read FCExeOutput write FCExeOutput; property CExeOutput:TExeOutputClass read FCExeOutput write FCExeOutput;
property StaticLibraryList:TFPHashObjectList read FStaticLibraryList; property StaticLibraryList:TFPObjectList read FStaticLibraryList;
property ImportLibraryList:TFPHashObjectList read FImportLibraryList; property ImportLibraryList:TFPHashObjectList read FImportLibraryList;
procedure DefaultLinkScript;virtual;abstract; procedure DefaultLinkScript;virtual;abstract;
procedure ScriptAddGenericSections(secnames:string); procedure ScriptAddGenericSections(secnames:string);
@ -848,7 +848,7 @@ Implementation
begin begin
inherited Create; inherited Create;
linkscript:=TCmdStrList.Create; linkscript:=TCmdStrList.Create;
FStaticLibraryList:=TFPHashObjectList.Create(true); FStaticLibraryList:=TFPObjectList.Create(true);
FImportLibraryList:=TFPHashObjectList.Create(true); FImportLibraryList:=TFPHashObjectList.Create(true);
exemap:=nil; exemap:=nil;
exeoutput:=nil; exeoutput:=nil;
@ -960,7 +960,7 @@ Implementation
exit; exit;
Comment(V_Tried,'Opening library '+para); Comment(V_Tried,'Opening library '+para);
objreader:=TArObjectreader.create(para); objreader:=TArObjectreader.create(para);
TStaticLibrary.Create(StaticLibraryList,para,objreader,CObjInput); StaticLibraryList.Add(TStaticLibrary.Create(para,objreader,CObjInput));
end; end;
@ -1276,6 +1276,8 @@ Implementation
ParseScript_Handle; ParseScript_Handle;
{ Load .o files and resolve symbols } { Load .o files and resolve symbols }
ParseScript_Load; ParseScript_Load;
if ErrorCount>0 then
goto myexit;
exeoutput.ResolveSymbols(StaticLibraryList); exeoutput.ResolveSymbols(StaticLibraryList);
{ Generate symbols and code to do the importing } { Generate symbols and code to do the importing }
exeoutput.GenerateLibraryImports(ImportLibraryList); exeoutput.GenerateLibraryImports(ImportLibraryList);

View File

@ -240,6 +240,7 @@ interface
property CObjSection:TObjSectionClass read FCObjSection write FCObjSection; property CObjSection:TObjSectionClass read FCObjSection write FCObjSection;
public public
CurrPass : byte; CurrPass : byte;
ExecStack : boolean;
constructor create(const n:string);virtual; constructor create(const n:string);virtual;
destructor destroy;override; destructor destroy;override;
{ Sections } { Sections }
@ -312,6 +313,7 @@ interface
destructor destroy;override; destructor destroy;override;
function newObjData(const n:string):TObjData; function newObjData(const n:string):TObjData;
function ReadObjData(AReader:TObjectreader;Data:TObjData):boolean;virtual;abstract; function ReadObjData(AReader:TObjectreader;Data:TObjData):boolean;virtual;abstract;
class function CanReadObjData(AReader:TObjectreader):boolean;virtual;
procedure inputerror(const s : string); procedure inputerror(const s : string);
end; end;
TObjInputClass=class of TObjInput; TObjInputClass=class of TObjInput;
@ -368,12 +370,13 @@ interface
end; end;
TExeSectionClass=class of TExeSection; TExeSectionClass=class of TExeSection;
TStaticLibrary = class(TFPHashObject) TStaticLibrary = class(TObject)
private private
FName : TCmdStr;
FArReader : TObjectReader; FArReader : TObjectReader;
FObjInputClass : TObjInputClass; FObjInputClass : TObjInputClass;
public public
constructor create(AList:TFPHashObjectList;const AName:string;AReader:TObjectReader;AObjInputClass:TObjInputClass); constructor create(const AName:TCmdStr;AReader:TObjectReader;AObjInputClass:TObjInputClass);
destructor destroy;override; destructor destroy;override;
property ArReader:TObjectReader read FArReader; property ArReader:TObjectReader read FArReader;
property ObjInputClass:TObjInputClass read FObjInputClass; property ObjInputClass:TObjInputClass read FObjInputClass;
@ -444,6 +447,7 @@ interface
CurrDataPos : aword; CurrDataPos : aword;
MaxMemPos : qword; MaxMemPos : qword;
IsSharedLibrary : boolean; IsSharedLibrary : boolean;
ExecStack : boolean;
constructor create;virtual; constructor create;virtual;
destructor destroy;override; destructor destroy;override;
function FindExeSection(const aname:string):TExeSection; function FindExeSection(const aname:string):TExeSection;
@ -454,6 +458,7 @@ interface
procedure Load_ProvideSymbol(const aname:string);virtual; procedure Load_ProvideSymbol(const aname:string);virtual;
procedure Load_IsSharedLibrary; procedure Load_IsSharedLibrary;
procedure Load_ImageBase(const avalue:string); procedure Load_ImageBase(const avalue:string);
procedure Load_DynamicObject(ObjData:TObjData);virtual;
procedure Order_Start;virtual; procedure Order_Start;virtual;
procedure Order_End;virtual; procedure Order_End;virtual;
procedure Order_ExeSection(const aname:string);virtual; procedure Order_ExeSection(const aname:string);virtual;
@ -477,7 +482,7 @@ interface
procedure DataPos_Symbols;virtual; procedure DataPos_Symbols;virtual;
procedure BuildVTableTree(VTInheritList,VTEntryList:TFPObjectList); procedure BuildVTableTree(VTInheritList,VTEntryList:TFPObjectList);
procedure PackUnresolvedExeSymbols(const s:string); procedure PackUnresolvedExeSymbols(const s:string);
procedure ResolveSymbols(StaticLibraryList:TFPHashObjectList); procedure ResolveSymbols(StaticLibraryList:TFPObjectList);
procedure PrintMemoryMap; procedure PrintMemoryMap;
procedure FixupSymbols; procedure FixupSymbols;
procedure FixupRelocations; procedure FixupRelocations;
@ -1456,9 +1461,9 @@ implementation
TStaticLibrary TStaticLibrary
****************************************************************************} ****************************************************************************}
constructor TStaticLibrary.create(AList:TFPHashObjectList;const AName:string;AReader:TObjectReader;AObjInputClass:TObjInputClass); constructor TStaticLibrary.create(const AName:TCmdStr;AReader:TObjectReader;AObjInputClass:TObjInputClass);
begin begin
inherited create(AList,AName); FName:=AName;
FArReader:=AReader; FArReader:=AReader;
FObjInputClass:=AObjInputClass; FObjInputClass:=AObjInputClass;
end; end;
@ -1595,6 +1600,7 @@ implementation
if ObjData.classtype<>FCObjData then if ObjData.classtype<>FCObjData then
Comment(V_Error,'Invalid input object format for '+ObjData.name+' got '+ObjData.classname+' expected '+FCObjData.classname); Comment(V_Error,'Invalid input object format for '+ObjData.name+' got '+ObjData.classname+' expected '+FCObjData.classname);
ObjDataList.Add(ObjData); ObjDataList.Add(ObjData);
ExecStack:=ExecStack or ObjData.ExecStack;
end; end;
@ -1660,6 +1666,11 @@ implementation
end; end;
procedure TExeOutput.Load_DynamicObject(ObjData:TObjData);
begin
end;
procedure TExeOutput.Order_Start; procedure TExeOutput.Order_Start;
begin begin
end; end;
@ -2079,7 +2090,7 @@ implementation
end; end;
procedure TExeOutput.ResolveSymbols(StaticLibraryList:TFPHashObjectList); procedure TExeOutput.ResolveSymbols(StaticLibraryList:TFPObjectList);
var var
ObjData : TObjData; ObjData : TObjData;
exesym : TExeSymbol; exesym : TExeSymbol;
@ -2987,6 +2998,12 @@ implementation
end; end;
class function TObjInput.CanReadObjData(AReader:TObjectReader):boolean;
begin
result:=false;
end;
procedure TObjInput.ReadSectionContent(Data:TObjData); procedure TObjInput.ReadSectionContent(Data:TObjData);
var var
i: longint; i: longint;