mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 15:39:24 +01:00 
			
		
		
		
	http://svn.freepascal.org/svn/fpc/branches/linker/compiler ........ r2791 | peter | 2006-03-06 14:57:20 +0100 (Mon, 06 Mar 2006) | 3 lines * disable internal linker if -s is used * enable section smartlink by default for internal linker ........ r2792 | peter | 2006-03-06 14:58:23 +0100 (Mon, 06 Mar 2006) | 2 lines * support long sectionnames ........ r2793 | peter | 2006-03-06 15:04:12 +0100 (Mon, 06 Mar 2006) | 2 lines * register symbols in section also when reading .o files ........ r2798 | peter | 2006-03-07 10:08:07 +0100 (Tue, 07 Mar 2006) | 2 lines * symbolrefs need to be loaded from relocations when loading a .o ........ r2799 | peter | 2006-03-07 16:17:52 +0100 (Tue, 07 Mar 2006) | 3 lines * remove unreferenced sections * set stacksize in peopthaeder ........ r2800 | peter | 2006-03-07 17:02:46 +0100 (Tue, 07 Mar 2006) | 2 lines * objsection.fullname added ........ ........ r2807 | peter | 2006-03-08 08:18:04 +0100 (Wed, 08 Mar 2006) | 2 lines * powerpc64 fixes ........ r2808 | peter | 2006-03-08 08:35:53 +0100 (Wed, 08 Mar 2006) | 2 lines * register x86_64_pecoff ........ r2809 | peter | 2006-03-08 11:26:38 +0100 (Wed, 08 Mar 2006) | 2 lines * optimize and cleanup matches() ........ r2810 | peter | 2006-03-08 12:25:28 +0100 (Wed, 08 Mar 2006) | 2 lines * small tweak to readdata to copy values direct without calling move() ........ r2811 | peter | 2006-03-08 15:55:21 +0100 (Wed, 08 Mar 2006) | 2 lines * compile fix ........ ........ ........ ........ ........ ........ r2817 | peter | 2006-03-09 14:20:52 +0100 (Thu, 09 Mar 2006) | 2 lines * more readable with long secnames ........ ........ ........ ........ ........ ........ ........ ........ r2825 | peter | 2006-03-10 09:52:05 +0100 (Fri, 10 Mar 2006) | 2 lines * don't initialize/finalize external variables ........ r2829 | peter | 2006-03-10 10:58:08 +0100 (Fri, 10 Mar 2006) | 2 lines * merge 64bit assembler ........ r2830 | peter | 2006-03-10 12:25:08 +0100 (Fri, 10 Mar 2006) | 2 lines * TElfAssembler rename ........ r2833 | peter | 2006-03-10 15:22:27 +0100 (Fri, 10 Mar 2006) | 3 lines * support & prefix to force identifier parsing, used to access fields that have the names of a register ........ r2839 | peter | 2006-03-10 19:37:11 +0100 (Fri, 10 Mar 2006) | 2 lines * merge stabs section flags ........ r2898 | peter | 2006-03-12 23:18:18 +0100 (Sun, 12 Mar 2006) | 2 lines * reorder instructions for better first match ........ git-svn-id: trunk@2902 -
		
			
				
	
	
		
			162 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			162 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
{
 | 
						|
    Copyright (c) 2001-2002 by Peter Vreman
 | 
						|
 | 
						|
    Contains the class for generating a map file
 | 
						|
 | 
						|
    This program is free software; you can redistribute it and/or modify
 | 
						|
    it under the terms of the GNU General Public License as published by
 | 
						|
    the Free Software Foundation; either version 2 of the License, or
 | 
						|
    (at your option) any later version.
 | 
						|
 | 
						|
    This program is distributed in the hope that it will be useful,
 | 
						|
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						|
    GNU General Public License for more details.
 | 
						|
 | 
						|
    You should have received a copy of the GNU General Public License
 | 
						|
    along with this program; if not, write to the Free Software
 | 
						|
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
						|
 | 
						|
 ****************************************************************************
 | 
						|
}
 | 
						|
unit ogmap;
 | 
						|
 | 
						|
{$i fpcdefs.inc}
 | 
						|
 | 
						|
interface
 | 
						|
 | 
						|
    uses
 | 
						|
       { common }
 | 
						|
       cclasses,globtype,systems,
 | 
						|
       { object writer }
 | 
						|
       aasmbase,ogbase
 | 
						|
       ;
 | 
						|
 | 
						|
    type
 | 
						|
       texemap = class
 | 
						|
       private
 | 
						|
         t : text;
 | 
						|
         FImageBase : aint;
 | 
						|
       public
 | 
						|
         constructor Create(const s:string);
 | 
						|
         destructor Destroy;override;
 | 
						|
         procedure Add(const s:string);
 | 
						|
         procedure AddHeader(const s:string);
 | 
						|
         procedure AddCommonSymbolsHeader;
 | 
						|
         procedure AddCommonSymbol(p:TObjSymbol);
 | 
						|
         procedure AddMemoryMapHeader(abase:aint);
 | 
						|
         procedure AddMemoryMapExeSection(p:texesection);
 | 
						|
         procedure AddMemoryMapObjectSection(p:TObjSection);
 | 
						|
         procedure AddMemoryMapSymbol(p:TObjSymbol);
 | 
						|
       end;
 | 
						|
 | 
						|
    var
 | 
						|
      exemap : texemap;
 | 
						|
 | 
						|
 | 
						|
implementation
 | 
						|
 | 
						|
    uses
 | 
						|
      cutils,globals,verbose;
 | 
						|
 | 
						|
 | 
						|
{****************************************************************************
 | 
						|
                                  TExeMap
 | 
						|
****************************************************************************}
 | 
						|
 | 
						|
     constructor TExeMap.Create(const s:string);
 | 
						|
       begin
 | 
						|
         Assign(t,FixFileName(s));
 | 
						|
         Rewrite(t);
 | 
						|
         FImageBase:=0;
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     destructor TExeMap.Destroy;
 | 
						|
       begin
 | 
						|
         Close(t);
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.Add(const s:string);
 | 
						|
       begin
 | 
						|
         writeln(t,s);
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddHeader(const s:string);
 | 
						|
       begin
 | 
						|
         Add('');
 | 
						|
         Add(s);
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddCommonSymbolsHeader;
 | 
						|
       begin
 | 
						|
         AddHeader('Allocating common symbols');
 | 
						|
         Add('Common symbol       size              file');
 | 
						|
         Add('');
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddCommonSymbol(p:TObjSymbol);
 | 
						|
       var
 | 
						|
         s : string;
 | 
						|
       begin
 | 
						|
         { Common symbol       size              file }
 | 
						|
         s:=p.name;
 | 
						|
         if length(s)>20 then
 | 
						|
          begin
 | 
						|
            writeln(t,p.name);
 | 
						|
            s:='';
 | 
						|
          end;
 | 
						|
         Add(PadSpace(s,20)+'0x'+PadSpace(hexstr(p.size,1),16)+p.objsection.objdata.name);
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddMemoryMapHeader(abase:aint);
 | 
						|
       var
 | 
						|
         imagebasestr : string;
 | 
						|
       begin
 | 
						|
         FImageBase:=abase;
 | 
						|
         if FImageBase<>0 then
 | 
						|
           imagebasestr:=' (ImageBase='+HexStr(FImageBase,sizeof(aint)*2)+')'
 | 
						|
         else
 | 
						|
           imagebasestr:='';
 | 
						|
         AddHeader('Memory map'+imagebasestr);
 | 
						|
         Add('');
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddMemoryMapExeSection(p:texesection);
 | 
						|
       begin
 | 
						|
         { .text           0x000018a8     0xd958 }
 | 
						|
         Add(PadSpace(p.name,19)+PadSpace(' 0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
 | 
						|
             ' 0x'+HexStr(p.size,sizeof(aint)));
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
 | 
						|
       var
 | 
						|
         secname : string;
 | 
						|
       begin
 | 
						|
         { .text           0x000018a8     0xd958     object.o }
 | 
						|
         secname:=p.name;
 | 
						|
         if Length(secname)>18 then
 | 
						|
           begin
 | 
						|
             Add(' '+secname);
 | 
						|
             secname:='';
 | 
						|
           end;
 | 
						|
         Add(' '+PadSpace(secname,18)+PadSpace(' 0x'+HexStr(p.mempos+FImageBase,sizeof(aint)*2),12)+
 | 
						|
             ' 0x'+HexStr(p.size,sizeof(aint))+' '+p.objdata.name);
 | 
						|
       end;
 | 
						|
 | 
						|
 | 
						|
     procedure TExeMap.AddMemoryMapSymbol(p:TObjSymbol);
 | 
						|
       begin
 | 
						|
         {                 0x00001e30                setup_screens }
 | 
						|
         Add(Space(20)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),25)+' '+p.name);
 | 
						|
       end;
 | 
						|
 | 
						|
end.
 |