fpc/compiler/ogmap.pas
peter 785550d7e3 Merged revisions 2669,2673,2677,2683,2696,2699-2702,2704,2708,2712-2715,2718,2722-2723,2728-2730,2740,2769 via svnmerge from
svn+ssh://peter@www.freepascal.org/FPC/svn/fpc/branches/linker/compiler

........
r2669 | peter | 2006-02-23 09:31:21 +0100 (Thu, 23 Feb 2006) | 2 lines

  * add compiler dir

........
r2673 | peter | 2006-02-23 17:08:56 +0100 (Thu, 23 Feb 2006) | 2 lines

  * enabled more code

........
r2677 | peter | 2006-02-24 17:46:29 +0100 (Fri, 24 Feb 2006) | 2 lines

  * pe stub and headers

........
r2683 | peter | 2006-02-25 23:13:24 +0100 (Sat, 25 Feb 2006) | 2 lines

  * section options cleanup

........
r2696 | peter | 2006-02-26 20:27:41 +0100 (Sun, 26 Feb 2006) | 2 lines

  * fixed typecasts

........
r2699 | peter | 2006-02-26 23:04:32 +0100 (Sun, 26 Feb 2006) | 2 lines

  * simple linking works

........
r2700 | peter | 2006-02-27 09:44:50 +0100 (Mon, 27 Feb 2006) | 2 lines

  * internal linker script

........
r2701 | peter | 2006-02-27 12:05:12 +0100 (Mon, 27 Feb 2006) | 2 lines

  * make elf working again

........
r2702 | peter | 2006-02-27 14:04:43 +0100 (Mon, 27 Feb 2006) | 3 lines

  * disable dwarf for smartlinking with .a
  * fix section start in new .a file

........
r2704 | peter | 2006-02-27 18:30:43 +0100 (Mon, 27 Feb 2006) | 2 lines

  * stab section fixes

........
r2708 | peter | 2006-02-28 19:29:17 +0100 (Tue, 28 Feb 2006) | 2 lines

  * basic work to merge stabs sections

........
r2712 | peter | 2006-02-28 23:17:48 +0100 (Tue, 28 Feb 2006) | 2 lines

  * unload tmodules before linking

........
r2713 | peter | 2006-02-28 23:18:51 +0100 (Tue, 28 Feb 2006) | 2 lines

  * fixed stabs linking

........
r2714 | peter | 2006-02-28 23:19:19 +0100 (Tue, 28 Feb 2006) | 2 lines

  * show code and data size

........
r2715 | peter | 2006-02-28 23:25:35 +0100 (Tue, 28 Feb 2006) | 2 lines

  * unload .stabs from objdata after it is merged

........
r2718 | peter | 2006-03-01 12:24:38 +0100 (Wed, 01 Mar 2006) | 3 lines

  * memsize/datasize cleanup
  * check for exports/resources when adding module to linker

........
r2722 | peter | 2006-03-03 09:12:20 +0100 (Fri, 03 Mar 2006) | 2 lines

  * new TObjSymbol splitted from TAsmSymbol

........
r2723 | peter | 2006-03-03 14:08:55 +0100 (Fri, 03 Mar 2006) | 2 lines

  * coff fixes after recent objsymbol changes

........
r2728 | peter | 2006-03-03 22:43:04 +0100 (Fri, 03 Mar 2006) | 2 lines

  * fixed coff writer

........
r2729 | peter | 2006-03-04 01:10:32 +0100 (Sat, 04 Mar 2006) | 2 lines

  * fix read-only opening

........
r2730 | peter | 2006-03-04 01:11:16 +0100 (Sat, 04 Mar 2006) | 2 lines

  * Read edata from DLLs, basic work

........
r2740 | peter | 2006-03-04 21:13:43 +0100 (Sat, 04 Mar 2006) | 3 lines

  * deletedef added
  * don't remove defs from index when we are already clearing everything

........
r2769 | peter | 2006-03-05 21:42:33 +0100 (Sun, 05 Mar 2006) | 4 lines

  * moved TObj classes to ogbase
  * ObjSection.SymbolRefs and SymbolDefines list
  * DLL importing

........

git-svn-id: trunk@2771 -
2006-03-05 21:10:37 +00:00

154 lines
4.1 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,18)+PadSpace('0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
'0x'+HexStr(p.size,sizeof(aint)));
end;
procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
begin
{ .text 0x000018a8 0xd958 object.o }
Add(' '+PadSpace(p.name,17)+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(18)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),26)+p.name);
end;
end.