瀏覽代碼

* TExeOutput.FixupRelocations method made virtual.
* TElfExeOutput.MemPos_Start split into four smaller methods.

git-svn-id: trunk@23684 -

sergei 12 年之前
父節點
當前提交
6484911f05
共有 2 個文件被更改,包括 39 次插入12 次删除
  1. 1 1
      compiler/ogbase.pas
  2. 38 11
      compiler/ogelf.pas

+ 1 - 1
compiler/ogbase.pas

@@ -556,7 +556,7 @@ interface
         procedure ResolveSymbols(StaticLibraryList:TFPObjectList);
         procedure ResolveSymbols(StaticLibraryList:TFPObjectList);
         procedure PrintMemoryMap;
         procedure PrintMemoryMap;
         procedure FixupSymbols;
         procedure FixupSymbols;
-        procedure FixupRelocations;
+        procedure FixupRelocations;virtual;
         procedure RemoveUnusedExeSymbols;
         procedure RemoveUnusedExeSymbols;
         procedure MergeStabs;
         procedure MergeStabs;
         procedure MarkEmptySections;
         procedure MarkEmptySections;

+ 38 - 11
compiler/ogelf.pas

@@ -241,7 +241,6 @@ interface
          hashobjsec: TElfObjSection;
          hashobjsec: TElfObjSection;
          neededlist: TFPHashList;
          neededlist: TFPHashList;
          dyncopysyms: TFPObjectList;
          dyncopysyms: TFPObjectList;
-         dynrelsize: aword;
 
 
          function AttachSection(objsec:TObjSection):TElfExeSection;
          function AttachSection(objsec:TObjSection):TElfExeSection;
          function CreateSegment(atype,aflags,aalign:longword):TElfSegment;
          function CreateSegment(atype,aflags,aalign:longword):TElfSegment;
@@ -255,6 +254,8 @@ interface
          procedure datapos_segment(seg:TElfSegment);
          procedure datapos_segment(seg:TElfSegment);
          procedure MapSectionsToSegments;
          procedure MapSectionsToSegments;
          procedure WriteStaticSymtable;
          procedure WriteStaticSymtable;
+         procedure WriteShstrtab;
+         procedure FixupSectionLinks;
          procedure InitDynlink;
          procedure InitDynlink;
        protected
        protected
          dynamiclink: boolean;
          dynamiclink: boolean;
@@ -272,6 +273,7 @@ interface
          tlsseg: TElfSegment;
          tlsseg: TElfSegment;
          relative_reloc_count: longint;
          relative_reloc_count: longint;
          gotsize: aword;
          gotsize: aword;
+         dynrelsize: aword;
          procedure PrepareGOT;virtual;
          procedure PrepareGOT;virtual;
          function AllocGOTSlot(objsym: TObjSymbol):boolean;virtual;
          function AllocGOTSlot(objsym: TObjSymbol):boolean;virtual;
          procedure CreateGOTSection;virtual;
          procedure CreateGOTSection;virtual;
@@ -287,6 +289,7 @@ interface
          procedure ReportRelocOverflow(reltyp:byte;objsec:TObjSection;ObjReloc:TObjRelocation);
          procedure ReportRelocOverflow(reltyp:byte;objsec:TObjSection;ObjReloc:TObjRelocation);
          procedure WriteDynTag(aTag:longword;aValue:longword);
          procedure WriteDynTag(aTag:longword;aValue:longword);
          procedure WriteDynTag(aTag:longword;aSection:TObjSection;aOffs:aword=0);
          procedure WriteDynTag(aTag:longword;aSection:TObjSection;aOffs:aword=0);
+         procedure Do_Mempos;virtual;
        public
        public
          constructor Create;override;
          constructor Create;override;
          destructor Destroy;override;
          destructor Destroy;override;
@@ -2494,14 +2497,10 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TElfExeOutput.MemPos_Start;
+    procedure TElfExeOutput.WriteShStrtab;
       var
       var
-        i,j: longint;
-        dynstrndx,dynsymndx: longword;
-        seg: TElfSegment;
+        i: longint;
         exesec: TElfExeSection;
         exesec: TElfExeSection;
-        objsec: TObjSection;
-        tempmempos: qword;
       begin
       begin
         { Remove any existing .shstrtab contents }
         { Remove any existing .shstrtab contents }
         if (shstrtabsect.size>0) then
         if (shstrtabsect.size>0) then
@@ -2511,8 +2510,6 @@ implementation
             shstrtabsect.SecOptions:=[oso_data];
             shstrtabsect.SecOptions:=[oso_data];
           end;
           end;
 
 
-        { Assign section indices and fill .shstrtab
-          List of sections cannot be modified after this point. }
         shstrtabsect.writezeros(1);
         shstrtabsect.writezeros(1);
         for i:=0 to ExeSectionList.Count-1 do
         for i:=0 to ExeSectionList.Count-1 do
           begin
           begin
@@ -2520,10 +2517,15 @@ implementation
             exesec.shstridx:=shstrtabsect.writestr(exesec.Name);
             exesec.shstridx:=shstrtabsect.writestr(exesec.Name);
             exesec.secshidx:=i+1;
             exesec.secshidx:=i+1;
           end;
           end;
+      end;
+
 
 
+    procedure TElfExeOutput.FixupSectionLinks;
+      var
+        dynstrndx,dynsymndx: longword;
+      begin
         if dynamiclink then
         if dynamiclink then
           begin
           begin
-            { fixup sh_link/sh_info members of various dynamic sections }
             dynstrndx:=TElfExeSection(dynsymtable.fstrsec.ExeSection).secshidx;
             dynstrndx:=TElfExeSection(dynsymtable.fstrsec.ExeSection).secshidx;
             dynsymndx:=TElfExeSection(dynsymtable.ExeSection).secshidx;
             dynsymndx:=TElfExeSection(dynsymtable.ExeSection).secshidx;
             TElfExeSection(hashobjsec.ExeSection).shlink:=dynsymndx;
             TElfExeSection(hashobjsec.ExeSection).shlink:=dynsymndx;
@@ -2548,8 +2550,17 @@ implementation
           end
           end
         else if assigned(ipltrelocsec) then
         else if assigned(ipltrelocsec) then
           TElfExeSection(ipltrelocsec.ExeSection).shinfo:=TElfExeSection(pltobjsec.ExeSection).secshidx;
           TElfExeSection(ipltrelocsec.ExeSection).shinfo:=TElfExeSection(pltobjsec.ExeSection).secshidx;
+      end;
 
 
-        { The actual layout }
+
+    procedure TElfExeOutput.Do_Mempos;
+      var
+        i,j: longint;
+        seg: TElfSegment;
+        exesec: TElfExeSection;
+        objsec: TObjSection;
+        tempmempos: qword;
+      begin
         if IsSharedLibrary then
         if IsSharedLibrary then
           CurrMemPos:=0
           CurrMemPos:=0
         else
         else
@@ -2598,6 +2609,22 @@ implementation
                 seg.MemSize:=exesec.MemPos+exesec.Size-seg.MemPos;
                 seg.MemSize:=exesec.MemPos+exesec.Size-seg.MemPos;
               end;
               end;
           end;
           end;
+      end;
+
+
+    procedure TElfExeOutput.MemPos_Start;
+      var
+        i: longint;
+      begin
+        { Assign section indices and fill .shstrtab
+          List of sections cannot be modified after this point. }
+        WriteShStrtab;
+
+        { fixup sh_link/sh_info members of various dynamic sections }
+        FixupSectionLinks;
+
+        { The actual layout }
+        Do_Mempos;
 
 
         if (not gotwritten) then
         if (not gotwritten) then
           begin
           begin