Browse Source

+ ELF linker: load e_ident and e_flags from ELF header into properties of TElfObjData, necessary for targets that must be able to link together object files of different flavors.

git-svn-id: trunk@23821 -
sergei 12 years ago
parent
commit
6245bfd74f
2 changed files with 30 additions and 27 deletions
  1. 4 2
      compiler/elfbase.pas
  2. 26 25
      compiler/ogelf.pas

+ 4 - 2
compiler/elfbase.pas

@@ -219,9 +219,11 @@ interface
 
 
 
 
   type
   type
+    TElfIdent = array[0..15] of byte;
+
     { Structures which are written directly to the output file }
     { Structures which are written directly to the output file }
     TElf32header=record
     TElf32header=record
-      e_ident           : array[0..15] of byte;
+      e_ident           : TElfIdent;
       e_type            : word;
       e_type            : word;
       e_machine         : word;
       e_machine         : word;
       e_version         : longword;
       e_version         : longword;
@@ -284,7 +286,7 @@ interface
     end;
     end;
 
 
     telf64header=record
     telf64header=record
-      e_ident           : array[0..15] of byte;
+      e_ident           : TElfIdent;
       e_type            : word;
       e_type            : word;
       e_machine         : word;
       e_machine         : word;
       e_version         : longword;
       e_version         : longword;

+ 26 - 25
compiler/ogelf.pas

@@ -74,6 +74,8 @@ interface
 
 
        TElfObjData = class(TObjData)
        TElfObjData = class(TObjData)
        public
        public
+         ident: TElfIdent;
+         flags: longword;
          constructor create(const n:string);override;
          constructor create(const n:string);override;
          function  sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
          function  sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
          procedure CreateDebugSections;override;
          procedure CreateDebugSections;override;
@@ -119,7 +121,6 @@ interface
          FLoaded: PBoolean;
          FLoaded: PBoolean;
          shdrs: TElfsecheaderarray;
          shdrs: TElfsecheaderarray;
          nsects: longword;
          nsects: longword;
-         shentsize: longword;
          shoffset: aword;
          shoffset: aword;
          shstrndx: longword;
          shstrndx: longword;
          symtabndx: longword;
          symtabndx: longword;
@@ -133,7 +134,7 @@ interface
          symversions: PWord;
          symversions: PWord;
          dynobj: boolean;
          dynobj: boolean;
          verdefs: TFPHashObjectList;
          verdefs: TFPHashObjectList;
-         function LoadHeader:word;
+         function LoadHeader(out objdata:TObjData):boolean;
          procedure LoadSection(const shdr:TElfsechdr;index:longint;objdata:TObjData);
          procedure LoadSection(const shdr:TElfsechdr;index:longint;objdata:TObjData);
          procedure LoadRelocations(const secrec:TSectionRec);
          procedure LoadRelocations(const secrec:TSectionRec);
          procedure LoadSymbols(objdata:TObjData;count,locals:longword);
          procedure LoadSymbols(objdata:TObjData;count,locals:longword);
@@ -1567,11 +1568,11 @@ implementation
       end;
       end;
 
 
 
 
-    function TElfObjInput.LoadHeader:word;
+    function TElfObjInput.LoadHeader(out objdata:TObjData):boolean;
       var
       var
         header:TElfHeader;
         header:TElfHeader;
       begin
       begin
-        result:=ET_NONE;
+        result:=false;
         if not FReader.read(header,sizeof(header)) then
         if not FReader.read(header,sizeof(header)) then
           begin
           begin
             InputError('Can''t read ELF header');
             InputError('Can''t read ELF header');
@@ -1609,12 +1610,30 @@ implementation
             InputError('ELF file is for different CPU');
             InputError('ELF file is for different CPU');
             exit;
             exit;
           end;
           end;
+        if (header.e_type<>ET_REL) and (header.e_type<>ET_DYN) then
+          begin
+            InputError('Not a relocatable or dynamic ELF file');
+            exit;
+          end;
+        if header.e_shentsize<>sizeof(TElfsechdr) then
+          InternalError(2012062701);
 
 
         nsects:=header.e_shnum;
         nsects:=header.e_shnum;
-        shentsize:=header.e_shentsize;
+        dynobj:=(header.e_type=ET_DYN);
         shoffset:=header.e_shoff;
         shoffset:=header.e_shoff;
         shstrndx:=header.e_shstrndx;
         shstrndx:=header.e_shstrndx;
-        result:=header.e_type;
+
+        if dynobj then
+          begin
+            objdata:=TElfDynamicObjData.Create(InputFilename);
+            verdefs:=TElfDynamicObjData(objdata).versiondefs;
+          end
+        else
+          objdata:=CObjData.Create(InputFilename);
+
+        TElfObjData(objdata).ident:=header.e_ident;
+        TElfObjData(objdata).flags:=header.e_flags;
+        result:=true;
       end;
       end;
 
 
 
 
@@ -1659,26 +1678,8 @@ implementation
         InputFileName:=AReader.FileName;
         InputFileName:=AReader.FileName;
         result:=false;
         result:=false;
 
 
-        i:=LoadHeader;
-        if (i=ET_NONE) then    { error message already given in this case }
+        if not LoadHeader(objData) then
           exit;
           exit;
-        if (i<>ET_REL) and (i<>ET_DYN) then
-          begin
-            InputError('Not a relocatable or dynamic ELF file');
-            exit;
-          end;
-        dynobj:=(i=ET_DYN);
-
-        if shentsize<>sizeof(TElfsechdr) then
-          InternalError(2012062701);
-
-        if dynobj then
-          begin
-            objdata:=TElfDynamicObjData.Create(InputFilename);
-            verdefs:=TElfDynamicObjData(objdata).versiondefs;
-          end
-        else
-          objdata:=CObjData.Create(InputFilename);
 
 
         FSecTbl:=AllocMem(nsects*sizeof(TSectionRec));
         FSecTbl:=AllocMem(nsects*sizeof(TSectionRec));
         FLoaded:=AllocMem(nsects*sizeof(boolean));
         FLoaded:=AllocMem(nsects*sizeof(boolean));