Browse Source

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://[email protected]/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 -

peter 19 years ago
parent
commit
785550d7e3
59 changed files with 3050 additions and 2506 deletions
  1. 41 648
      compiler/aasmbase.pas
  2. 29 29
      compiler/aasmtai.pas
  3. 25 22
      compiler/aggas.pas
  4. 4 4
      compiler/arm/aasmcpu.pas
  5. 188 246
      compiler/assemble.pas
  6. 133 61
      compiler/cclasses.pas
  7. 1 1
      compiler/cgobj.pas
  8. 3 0
      compiler/comphook.pas
  9. 10 4
      compiler/compiler.pas
  10. 5 0
      compiler/cstreams.pas
  11. 4 4
      compiler/cutils.pas
  12. 1 1
      compiler/dbgdwarf.pas
  13. 1 1
      compiler/dbgstabs.pas
  14. 9 6
      compiler/fmodule.pas
  15. 4 1
      compiler/fpcdefs.inc
  16. 3 100
      compiler/fppu.pas
  17. 1 3
      compiler/globals.pas
  18. 14 11
      compiler/i386/ag386nsm.pas
  19. 20 20
      compiler/i386/daopt386.pas
  20. 58 58
      compiler/i386/popt386.pas
  21. 231 58
      compiler/link.pas
  22. 1 1
      compiler/msg/errore.msg
  23. 1 1
      compiler/msgidx.inc
  24. 163 163
      compiler/msgtxt.inc
  25. 3 5
      compiler/ncgbas.pas
  26. 4 4
      compiler/ncgcon.pas
  27. 0 12
      compiler/ncgset.pas
  28. 1 1
      compiler/ncgutil.pas
  29. 0 2
      compiler/ncon.pas
  30. 949 91
      compiler/ogbase.pas
  31. 501 285
      compiler/ogcoff.pas
  32. 296 368
      compiler/ogelf.pas
  33. 9 9
      compiler/oglx.pas
  34. 37 21
      compiler/ogmap.pas
  35. 8 1
      compiler/options.pas
  36. 7 3
      compiler/owar.pas
  37. 30 9
      compiler/owbase.pas
  38. 11 3
      compiler/parser.pas
  39. 4 4
      compiler/pdecl.pas
  40. 5 5
      compiler/pdecobj.pas
  41. 31 31
      compiler/pdecsub.pas
  42. 56 57
      compiler/pdecvar.pas
  43. 37 23
      compiler/pmodules.pas
  44. 2 2
      compiler/powerpc/agppcgas.pas
  45. 2 2
      compiler/powerpc/agppcmpw.pas
  46. 1 1
      compiler/ppu.pas
  47. 1 1
      compiler/ptconst.pas
  48. 5 5
      compiler/ptype.pas
  49. 1 1
      compiler/raatt.pas
  50. 19 5
      compiler/symbase.pas
  51. 3 2
      compiler/symdef.pas
  52. 1 1
      compiler/symtable.pas
  53. 3 12
      compiler/symtype.pas
  54. 1 1
      compiler/systems/t_go32v2.pas
  55. 9 41
      compiler/systems/t_linux.pas
  56. 2 1
      compiler/systems/t_win.pas
  57. 2 0
      compiler/verbose.pas
  58. 51 46
      compiler/x86/aasmcpu.pas
  59. 8 8
      compiler/x86/agx86int.pas

+ 41 - 648
compiler/aasmbase.pas

@@ -37,21 +37,16 @@ interface
        ;
        ;
 
 
     type
     type
-       TAsmSection = class;
-       TAsmObjectData = class;
-
        TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
        TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
 
 
        TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL);
        TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL);
 
 
-       TAsmRelocationType = (RELOC_ABSOLUTE,RELOC_RELATIVE,RELOC_RVA);
-
-       TAsmSectionType=(sec_none,
-         sec_code,sec_data,sec_rodata,sec_bss,sec_threadvar,
-         { used for executable creation }
-         sec_common,
-         { custom section, no prefix }
-         sec_custom,
+       TAsmSectiontype=(sec_none,
+         sec_code,
+         sec_data,
+         sec_rodata,
+         sec_bss,
+         sec_threadvar,
          { used for darwin import stubs }
          { used for darwin import stubs }
          sec_stub,
          sec_stub,
          { stabs }
          { stabs }
@@ -71,42 +66,27 @@ interface
          sec_toc
          sec_toc
        );
        );
 
 
-       TAsmSectionOption = (aso_alloconly,aso_executable);
-       TAsmSectionOptions = set of TAsmSectionOption;
-
        TAsmSymbol = class(TNamedIndexItem)
        TAsmSymbol = class(TNamedIndexItem)
        private
        private
          { this need to be incremented with every symbol loading into the
          { this need to be incremented with every symbol loading into the
-           paasmoutput, thus in loadsym/loadref/const_symbol (PFV) }
+           taasmoutput with loadsym/loadref/const_symbol (PFV) }
          refs       : longint;
          refs       : longint;
        public
        public
-         defbind,
-         currbind   : TAsmsymbind;
+         bind       : TAsmsymbind;
          typ        : TAsmsymtype;
          typ        : TAsmsymtype;
-         { the next fields are filled in the binary writer }
-         section    : TAsmSection;
-         address,
-         size       : aint;
          { Alternate symbol which can be used for 'renaming' needed for
          { Alternate symbol which can be used for 'renaming' needed for
-           inlining }
-         altsymbol  : tasmsymbol;
-         { pointer to objectdata that is the owner of this symbol }
-         owner      : tasmobjectdata;
-         { Is the symbol in the used list }
-         inusedlist : boolean;
-         { assembler pass label is set, used for detecting multiple labels }
-         pass       : byte;
-         ppuidx     : longint;
+           asm inlining. Also used for external and common solving during linking }
+         altsymbol  : TAsmSymbol;
+         { Cached objsymbol }
+         cachedobjsymbol : TObject;
          constructor create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
          constructor create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
-         procedure reset;
          function  is_used:boolean;
          function  is_used:boolean;
          procedure increfs;
          procedure increfs;
          procedure decrefs;
          procedure decrefs;
          function getrefs: longint;
          function getrefs: longint;
-         procedure setaddress(_pass:byte;sec:TAsmSection;offset,len:aint);
        end;
        end;
 
 
-       { is the label only there for getting an address (e.g. for i/o
+       { is the label only there for getting an DataOffset (e.g. for i/o
          checks -> alt_addr) or is it a jump target (alt_jump), for debug
          checks -> alt_addr) or is it a jump target (alt_jump), for debug
          info alt_dbgline and alt_dbgfile }
          info alt_dbgline and alt_dbgfile }
        TAsmLabelType = (alt_jump,alt_addr,alt_data,alt_dbgline,alt_dbgfile,alt_dbgtype,alt_dbgframe);
        TAsmLabelType = (alt_jump,alt_addr,alt_data,alt_dbgline,alt_dbgfile,alt_dbgtype,alt_dbgframe);
@@ -120,101 +100,10 @@ interface
          function getname:string;override;
          function getname:string;override;
        end;
        end;
 
 
-       TAsmRelocation = class(TLinkedListItem)
-          address,
-          orgsize  : aint;  { original size of the symbol to relocate, required for COFF }
-          symbol   : TAsmSymbol;
-          section  : TAsmSection; { only used if symbol=nil }
-          typ      : TAsmRelocationType;
-          constructor CreateSymbol(Aaddress:aint;s:Tasmsymbol;Atyp:TAsmRelocationType);
-          constructor CreateSymbolSize(Aaddress:aint;s:Tasmsymbol;Aorgsize:aint;Atyp:TAsmRelocationType);
-          constructor CreateSection(Aaddress:aint;sec:TAsmSection;Atyp:TAsmRelocationType);
-       end;
-
-       TAsmSection = class(TNamedIndexItem)
-         owner      : TAsmObjectData;
-         secoptions : TAsmSectionOptions;
-         sectype    : TAsmSectionType;
-         secsymidx  : longint;   { index for the section in symtab }
-         addralign  : longint;   { alignment of the section }
-         { size of the data and in the file }
-         dataalignbytes : longint;
-         data      : TDynamicArray;
-         datasize,
-         datapos   : aint;
-         { size and position in memory }
-         memsize,
-         mempos    : aint;
-         { relocation }
-         relocations : TLinkedList;
-         constructor create(const Aname:string;Atype:TAsmSectionType;Aalign:longint;Aoptions:TAsmSectionOptions);virtual;
-         destructor  destroy;override;
-         function  write(const d;l:aint):aint;
-         function  writestr(const s:string):aint;
-         procedure writealign(l:longint);
-         function  aligneddatasize:aint;
-         procedure setdatapos(var dpos:aint);
-         procedure alignsection;
-         procedure alloc(l:aint);
-         procedure addsymreloc(ofs:aint;p:tasmsymbol;relative:TAsmRelocationType);
-         procedure addsectionreloc(ofs:aint;sec:TAsmSection;relative:TAsmRelocationType);
-         procedure fixuprelocs;virtual;
-       end;
-       TAsmSectionClass = class of TAsmSection;
-
-       TAsmObjectData = class(TLinkedListItem)
-       private
-         FName      : string[80];
-         FCurrSec   : TAsmSection;
-         { Sections will be stored in order in SectsIndex, this is at least
-           required for stabs debuginfo. The SectsDict is only used for lookups (PFV) }
-         FSectsDict   : TDictionary;
-         FSectsIndex  : TIndexArray;
-         FCAsmSection : TAsmSectionClass;
-         { Symbols that will be defined in this object file }
-         FSymbols   : TIndexArray;
-         { Special info sections that are written to during object generation }
-         FStabsRecSize : longint;
-         FStabsSec,
-         FStabStrSec : TAsmSection;
-         procedure section_reset(p:tnamedindexitem;arg:pointer);
-         procedure section_fixuprelocs(p:tnamedindexitem;arg:pointer);
-       protected
-         property StabsRecSize:longint read FStabsRecSize write FStabsRecSize;
-         property StabsSec:TAsmSection read FStabsSec write FStabsSec;
-         property StabStrSec:TAsmSection read FStabStrSec write FStabStrSec;
-         property CAsmSection:TAsmSectionClass read FCAsmSection write FCAsmSection;
-       public
-         constructor create(const n:string);virtual;
-         destructor  destroy;override;
-         function  sectionname(atype:tasmsectiontype;const aname:string):string;virtual;
-         function  createsection(atype:tasmsectiontype;const aname:string;aalign:longint;aoptions:TAsmSectionOptions):tasmsection;virtual;
-         procedure setsection(asec:tasmsection);
-         procedure alloc(len:aint);
-         procedure allocalign(len:longint);
-         procedure allocstab(p:pchar);
-         procedure allocsymbol(currpass:byte;p:tasmsymbol;len:aint);
-         procedure writebytes(var data;len:aint);
-         procedure writereloc(data,len:aint;p:tasmsymbol;relative:TAsmRelocationType);virtual;abstract;
-         procedure writesymbol(p:tasmsymbol);virtual;abstract;
-         procedure writestab(offset:aint;ps:tasmsymbol;nidx,nother,line:longint;p:pchar);virtual;abstract;
-         procedure beforealloc;virtual;
-         procedure beforewrite;virtual;
-         procedure afteralloc;virtual;
-         procedure afterwrite;virtual;
-         procedure resetsections;
-         procedure fixuprelocs;
-         property Name:string[80] read FName;
-         property CurrSec:TAsmSection read FCurrSec;
-         property Symbols:TindexArray read FSymbols;
-         property Sects:TIndexArray read FSectsIndex;
-       end;
-       TAsmObjectDataClass = class of TAsmObjectData;
-
        tasmsymbolidxarr = array[0..($7fffffff div sizeof(pointer))-1] of tasmsymbol;
        tasmsymbolidxarr = array[0..($7fffffff div sizeof(pointer))-1] of tasmsymbol;
        pasmsymbolidxarr = ^tasmsymbolidxarr;
        pasmsymbolidxarr = ^tasmsymbolidxarr;
 
 
-       TAsmLibraryData = class(TLinkedListItem)
+       TObjLibraryData = class(TLinkedListItem)
        private
        private
          nextaltnr   : longint;
          nextaltnr   : longint;
          nextlabelnr : array[Tasmlabeltype] of longint;
          nextlabelnr : array[Tasmlabeltype] of longint;
@@ -222,18 +111,12 @@ interface
          name,
          name,
          realname     : string[80];
          realname     : string[80];
          symbolsearch : tdictionary; { contains ALL assembler symbols }
          symbolsearch : tdictionary; { contains ALL assembler symbols }
-         usedasmsymbollist : tsinglelist;
-         { ppu }
-         asmsymbolppuidx : longint;
-         asmsymbolidx : pasmsymbolidxarr; { used for translating ppu index->asmsymbol }
+         AltSymbollist : tlist;
          constructor create(const n:string);
          constructor create(const n:string);
          destructor  destroy;override;
          destructor  destroy;override;
-         procedure Freeasmsymbolidx;
-         procedure DerefAsmsymbol(var s:tasmsymbol);
          { asmsymbol }
          { asmsymbol }
          function  newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:TAsmsymtype) : tasmsymbol;
          function  newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:TAsmsymtype) : tasmsymbol;
          function  getasmsymbol(const s : string) : tasmsymbol;
          function  getasmsymbol(const s : string) : tasmsymbol;
-         function  renameasmsymbol(const sold, snew : string):tasmsymbol;
          function  newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
          function  newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
          {# create a new assembler label }
          {# create a new assembler label }
          procedure getlabel(var l : tasmlabel;alt:tasmlabeltype);
          procedure getlabel(var l : tasmlabel;alt:tasmlabeltype);
@@ -244,15 +127,9 @@ interface
          { make l as a new label and flag is_data }
          { make l as a new label and flag is_data }
          procedure getdatalabel(var l : tasmlabel);
          procedure getdatalabel(var l : tasmlabel);
          {# return a label number }
          {# return a label number }
-         procedure CreateUsedAsmSymbolList;
-         procedure DestroyUsedAsmSymbolList;
-         procedure UsedAsmSymbolListInsert(p:tasmsymbol);
          { generate an alternative (duplicate) symbol }
          { generate an alternative (duplicate) symbol }
          procedure GenerateAltSymbol(p:tasmsymbol);
          procedure GenerateAltSymbol(p:tasmsymbol);
-         { reset alternative symbol information }
-         procedure UsedAsmSymbolListResetAltSym;
-         procedure UsedAsmSymbolListReset;
-         procedure UsedAsmSymbolListCheckUndefined;
+         procedure ResetAltSymbols;
        end;
        end;
 
 
     function LengthUleb128(a: aword) : byte;
     function LengthUleb128(a: aword) : byte;
@@ -263,7 +140,7 @@ interface
       asmlabeltypeprefix : array[tasmlabeltype] of char = ('j','a','d','l','f','t','c');
       asmlabeltypeprefix : array[tasmlabeltype] of char = ('j','a','d','l','f','t','c');
 
 
     var
     var
-      objectlibrary : tasmlibrarydata;
+      objectlibrary : TObjLibraryData;
 
 
 
 
 implementation
 implementation
@@ -329,31 +206,13 @@ implementation
     constructor tasmsymbol.create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
     constructor tasmsymbol.create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
       begin;
       begin;
         inherited createname(s);
         inherited createname(s);
-        reset;
-        defbind:=_bind;
+        bind:=_bind;
         typ:=_typ;
         typ:=_typ;
-        inusedlist:=false;
-        pass:=255;
-        ppuidx:=-1;
-        { mainly used to remove unused labels from the al_procedures }
+        { used to remove unused labels from the al_procedures }
         refs:=0;
         refs:=0;
       end;
       end;
 
 
 
 
-    procedure tasmsymbol.reset;
-      begin
-        { reset section info }
-        section:=nil;
-        address:=0;
-        size:=0;
-        indexnr:=-1;
-        pass:=255;
-        currbind:=AB_EXTERNAL;
-        altsymbol:=nil;
-{        taiowner:=nil;}
-      end;
-
-
     function tasmsymbol.is_used:boolean;
     function tasmsymbol.is_used:boolean;
       begin
       begin
         is_used:=(refs>0);
         is_used:=(refs>0);
@@ -380,24 +239,6 @@ implementation
       end;
       end;
 
 
 
 
-    procedure tasmsymbol.setaddress(_pass:byte;sec:TAsmSection;offset,len:aint);
-      begin
-        if (_pass=pass) then
-         begin
-           Message1(asmw_e_duplicate_label,name);
-           exit;
-         end;
-        pass:=_pass;
-        section:=sec;
-        address:=offset;
-        size:=len;
-        { when the bind was reset to External, set it back to the default
-          bind it got when defined }
-        if (currbind=AB_EXTERNAL) and (defbind<>AB_NONE) then
-         currbind:=defbind;
-      end;
-
-
 {*****************************************************************************
 {*****************************************************************************
                                  TAsmLabel
                                  TAsmLabel
 *****************************************************************************}
 *****************************************************************************}
@@ -430,356 +271,10 @@ implementation
 
 
 
 
 {****************************************************************************
 {****************************************************************************
-                              TAsmRelocation
+                                TObjLibraryData
 ****************************************************************************}
 ****************************************************************************}
 
 
-    constructor TAsmRelocation.CreateSymbol(Aaddress:aint;s:Tasmsymbol;Atyp:TAsmRelocationType);
-      begin
-        Address:=Aaddress;
-        Symbol:=s;
-        OrgSize:=0;
-        Section:=nil;
-        Typ:=Atyp;
-      end;
-
-
-    constructor TAsmRelocation.CreateSymbolSize(Aaddress:aint;s:Tasmsymbol;Aorgsize:aint;Atyp:TAsmRelocationType);
-      begin
-        Address:=Aaddress;
-        Symbol:=s;
-        OrgSize:=Aorgsize;
-        Section:=nil;
-        Typ:=Atyp;
-      end;
-
-
-    constructor TAsmRelocation.CreateSection(Aaddress:aint;sec:TAsmSection;Atyp:TAsmRelocationType);
-      begin
-        Address:=Aaddress;
-        Symbol:=nil;
-        OrgSize:=0;
-        Section:=sec;
-        Typ:=Atyp;
-      end;
-
-
-{****************************************************************************
-                              TAsmSection
-****************************************************************************}
-
-    constructor TAsmSection.create(const Aname:string;Atype:TAsmSectionType;Aalign:longint;Aoptions:TAsmSectionOptions);
-      begin
-        inherited createname(Aname);
-        sectype:=Atype;
-        name:=Aname;
-        secoptions:=Aoptions;
-        secsymidx:=0;
-        addralign:=Aalign;
-        { data }
-        datasize:=0;
-        datapos:=0;
-        if (aso_alloconly in aoptions) then
-         data:=nil
-        else
-         Data:=TDynamicArray.Create(8192);
-        { memory }
-        mempos:=0;
-        memsize:=0;
-        { relocation }
-        relocations:=TLinkedList.Create;
-      end;
-
-
-    destructor TAsmSection.destroy;
-      begin
-        if assigned(Data) then
-          Data.Free;
-        relocations.free;
-      end;
-
-
-    function TAsmSection.write(const d;l:aint):aint;
-      begin
-        write:=datasize;
-        if assigned(Data) then
-          Data.write(d,l);
-        inc(datasize,l);
-      end;
-
-
-    function TAsmSection.writestr(const s:string):aint;
-      begin
-        writestr:=datasize;
-        if assigned(Data) then
-          Data.write(s[1],length(s));
-        inc(datasize,length(s));
-      end;
-
-
-    procedure TAsmSection.writealign(l:longint);
-      var
-        i : longint;
-        empty : array[0..63] of char;
-      begin
-        { no alignment needed for 0 or 1 }
-        if l<=1 then
-         exit;
-        i:=datasize mod l;
-        if i>0 then
-         begin
-           if assigned(data) then
-            begin
-              fillchar(empty,sizeof(empty),0);
-              Data.write(empty,l-i);
-            end;
-           inc(datasize,l-i);
-         end;
-      end;
-
-
-    function TAsmSection.aligneddatasize:aint;
-      begin
-        aligneddatasize:=align(datasize,addralign);
-      end;
-
-
-    procedure TAsmSection.setdatapos(var dpos:aint);
-      var
-        alignedpos : aint;
-      begin
-        { get aligned datapos }
-        alignedpos:=align(dpos,addralign);
-        dataalignbytes:=alignedpos-dpos;
-        datapos:=alignedpos;
-        { update datapos }
-        dpos:=datapos+aligneddatasize;
-      end;
-
-
-    procedure TAsmSection.alignsection;
-      begin
-        writealign(addralign);
-      end;
-
-
-    procedure TAsmSection.alloc(l:aint);
-      begin
-        inc(datasize,l);
-      end;
-
-
-    procedure TAsmSection.addsymreloc(ofs:aint;p:tasmsymbol;relative:TAsmRelocationType);
-      var
-        r : TAsmRelocation;
-      begin
-        r:=TAsmRelocation.Create;
-        r.address:=ofs;
-        r.orgsize:=0;
-        r.symbol:=p;
-        r.section:=nil;
-        r.typ:=relative;
-        relocations.concat(r);
-      end;
-
-
-    procedure TAsmSection.addsectionreloc(ofs:aint;sec:TAsmSection;relative:TAsmRelocationType);
-      var
-        r : TAsmRelocation;
-      begin
-        r:=TAsmRelocation.Create;
-        r.address:=ofs;
-        r.symbol:=nil;
-        r.orgsize:=0;
-        r.section:=sec;
-        r.typ:=relative;
-        relocations.concat(r);
-      end;
-
-
-    procedure TAsmSection.fixuprelocs;
-      begin
-      end;
-
-
-{****************************************************************************
-                                TAsmObjectData
-****************************************************************************}
-
-    constructor TAsmObjectData.create(const n:string);
-      begin
-        inherited create;
-        FName:=n;
-        { sections, the SectsIndex owns the items, the FSectsDict
-          is only used for lookups }
-        FSectsDict:=tdictionary.create;
-        FSectsDict.noclear:=true;
-        FSectsIndex:=tindexarray.create(sectsgrow);
-        FStabsRecSize:=1;
-        FStabsSec:=nil;
-        FStabStrSec:=nil;
-        { symbols }
-        FSymbols:=tindexarray.create(symbolsgrow);
-        FSymbols.noclear:=true;
-        { section class type for creating of new sections }
-        FCAsmSection:=TAsmSection;
-      end;
-
-
-    destructor TAsmObjectData.destroy;
-      begin
-        FSectsDict.free;
-        FSectsIndex.free;
-        FSymbols.free;
-      end;
-
-
-    function TAsmObjectData.sectionname(atype:tasmsectiontype;const aname:string):string;
-      const
-        secnames : array[tasmsectiontype] of string[13] = ('',
-          'code','data','rodata','bss','threadvar',
-          'common',
-          'note',
-          'text',
-          'stab','stabstr',
-          'idata2','idata4','idata5','idata6','idata7','edata',
-          'eh_frame',
-          'debug_frame','debug_info','debug_line','debug_abbrev',
-          'fpc',
-          'toc'
-        );
-      begin
-        if aname<>'' then
-          result:=secnames[atype]+'.'+aname
-        else
-          result:=secnames[atype];
-      end;
-
-
-    function TAsmObjectData.createsection(atype:tasmsectiontype;const aname:string;aalign:longint;aoptions:TAsmSectionOptions):TAsmSection;
-      var
-        secname : string;
-      begin
-        secname:=sectionname(atype,aname);
-        result:=TasmSection(FSectsDict.search(secname));
-        if not assigned(result) then
-          begin
-{$warning TODO make alloconly configurable}
-            if atype=sec_bss then
-              include(aoptions,aso_alloconly);
-            result:=CAsmSection.create(secname,atype,aalign,aoptions);
-            FSectsDict.Insert(result);
-            FSectsIndex.Insert(result);
-            result.owner:=self;
-          end;
-        FCurrSec:=result;
-      end;
-
-
-    procedure TAsmObjectData.setsection(asec:tasmsection);
-      begin
-        if asec.owner<>self then
-          internalerror(200403041);
-        FCurrSec:=asec;
-      end;
-
-
-    procedure TAsmObjectData.writebytes(var data;len:aint);
-      begin
-        if not assigned(currsec) then
-          internalerror(200402251);
-        currsec.write(data,len);
-      end;
-
-
-    procedure TAsmObjectData.alloc(len:aint);
-      begin
-        if not assigned(currsec) then
-          internalerror(200402252);
-        currsec.alloc(len);
-      end;
-
-
-    procedure TAsmObjectData.allocalign(len:longint);
-      var
-        modulo : aint;
-      begin
-        if not assigned(currsec) then
-          internalerror(200402253);
-        modulo:=currsec.datasize mod len;
-        if modulo > 0 then
-          currsec.alloc(len-modulo);
-      end;
-
-
-    procedure TAsmObjectData.allocsymbol(currpass:byte;p:tasmsymbol;len:aint);
-      begin
-        p.setaddress(currpass,currsec,currsec.datasize,len);
-      end;
-
-
-    procedure TAsmObjectData.allocstab(p:pchar);
-      begin
-        if not(assigned(FStabsSec) and assigned(FStabStrSec)) then
-          internalerror(200402254);
-        FStabsSec.alloc(FStabsRecSize);
-        if assigned(p) and (p[0]<>#0) then
-          FStabStrSec.alloc(strlen(p)+1);
-      end;
-
-
-    procedure TAsmObjectData.section_reset(p:tnamedindexitem;arg:pointer);
-      begin
-        with tasmsection(p) do
-          begin
-            datasize:=0;
-            datapos:=0;
-          end;
-      end;
-
-
-    procedure TAsmObjectData.section_fixuprelocs(p:tnamedindexitem;arg:pointer);
-      begin
-        tasmsection(p).fixuprelocs;
-      end;
-
-
-    procedure TAsmObjectData.beforealloc;
-      begin
-      end;
-
-
-    procedure TAsmObjectData.beforewrite;
-      begin
-      end;
-
-
-    procedure TAsmObjectData.afteralloc;
-      begin
-      end;
-
-
-    procedure TAsmObjectData.afterwrite;
-      begin
-      end;
-
-
-    procedure TAsmObjectData.resetsections;
-      begin
-        FSectsDict.foreach(@section_reset,nil);
-      end;
-
-
-    procedure TAsmObjectData.fixuprelocs;
-      begin
-        FSectsDict.foreach(@section_fixuprelocs,nil);
-      end;
-
-
-{****************************************************************************
-                                TAsmLibraryData
-****************************************************************************}
-
-    constructor TAsmLibraryData.create(const n:string);
+    constructor TObjLibraryData.create(const n:string);
       var
       var
         alt : TAsmLabelType;
         alt : TAsmLabelType;
       begin
       begin
@@ -789,47 +284,22 @@ implementation
         { symbols }
         { symbols }
         symbolsearch:=tdictionary.create;
         symbolsearch:=tdictionary.create;
         symbolsearch.usehash;
         symbolsearch.usehash;
+        AltSymbollist:=TList.Create;
         { labels }
         { labels }
         nextaltnr:=1;
         nextaltnr:=1;
         for alt:=low(TAsmLabelType) to high(TAsmLabelType) do
         for alt:=low(TAsmLabelType) to high(TAsmLabelType) do
           nextlabelnr[alt]:=1;
           nextlabelnr[alt]:=1;
-        { ppu }
-        asmsymbolppuidx:=0;
-        asmsymbolidx:=nil;
       end;
       end;
 
 
 
 
-    destructor TAsmLibraryData.destroy;
+    destructor TObjLibraryData.destroy;
       begin
       begin
+        AltSymbollist.free;
         symbolsearch.free;
         symbolsearch.free;
-        Freeasmsymbolidx;
-      end;
-
-
-    procedure TAsmLibraryData.Freeasmsymbolidx;
-      begin
-        if assigned(asmsymbolidx) then
-         begin
-           Freemem(asmsymbolidx);
-           asmsymbolidx:=nil;
-         end;
-      end;
-
-
-    procedure TAsmLibraryData.DerefAsmsymbol(var s:tasmsymbol);
-      begin
-        if assigned(s) then
-         begin
-           if not assigned(asmsymbolidx) then
-             internalerror(200208072);
-           if (ptrint(pointer(s))<1) or (ptrint(pointer(s))>asmsymbolppuidx) then
-             internalerror(200208073);
-           s:=asmsymbolidx^[ptrint(pointer(s))-1];
-         end;
       end;
       end;
 
 
 
 
-    function TAsmLibraryData.newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
+    function TObjLibraryData.newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
       var
       var
         hp : tasmsymbol;
         hp : tasmsymbol;
       begin
       begin
@@ -847,7 +317,7 @@ implementation
              end;
              end;
            {$ENDIF}
            {$ENDIF}
            if (_bind<>AB_EXTERNAL) then
            if (_bind<>AB_EXTERNAL) then
-             hp.defbind:=_bind
+             hp.bind:=_bind
          end
          end
         else
         else
          begin
          begin
@@ -859,111 +329,34 @@ implementation
       end;
       end;
 
 
 
 
-    function TAsmLibraryData.getasmsymbol(const s : string) : tasmsymbol;
+    function TObjLibraryData.getasmsymbol(const s : string) : tasmsymbol;
       begin
       begin
         getasmsymbol:=tasmsymbol(symbolsearch.search(s));
         getasmsymbol:=tasmsymbol(symbolsearch.search(s));
       end;
       end;
 
 
 
 
-    function TAsmLibraryData.renameasmsymbol(const sold, snew : string):tasmsymbol;
-      begin
-        renameasmsymbol:=tasmsymbol(symbolsearch.rename(sold,snew));
-      end;
-
-
-    procedure TAsmLibraryData.CreateUsedAsmSymbolList;
-      begin
-        if assigned(usedasmsymbollist) then
-         internalerror(78455782);
-        usedasmsymbollist:=TSingleList.create;
-      end;
-
-
-    procedure TAsmLibraryData.DestroyUsedAsmSymbolList;
-      begin
-        usedasmsymbollist.destroy;
-        usedasmsymbollist:=nil;
-      end;
-
-
-    procedure TAsmLibraryData.UsedAsmSymbolListInsert(p:tasmsymbol);
-      begin
-        if not p.inusedlist then
-         usedasmsymbollist.insert(p);
-        p.inusedlist:=true;
-      end;
-
-
-    procedure TAsmLibraryData.GenerateAltSymbol(p:tasmsymbol);
+    procedure TObjLibraryData.GenerateAltSymbol(p:tasmsymbol);
       begin
       begin
         if not assigned(p.altsymbol) then
         if not assigned(p.altsymbol) then
          begin
          begin
-           p.altsymbol:=tasmsymbol.create(p.name+'_'+tostr(nextaltnr),p.defbind,p.typ);
+           p.altsymbol:=tasmsymbol.create(p.name+'_'+tostr(nextaltnr),p.bind,p.typ);
            symbolsearch.insert(p.altsymbol);
            symbolsearch.insert(p.altsymbol);
-           { add also the original sym to the usedasmsymbollist,
-             that list is used to reset the altsymbol }
-           if not p.inusedlist then
-            usedasmsymbollist.insert(p);
-           p.inusedlist:=true;
-         end;
-      end;
-
-
-    procedure TAsmLibraryData.UsedAsmSymbolListReset;
-      var
-        hp : tasmsymbol;
-      begin
-        hp:=tasmsymbol(usedasmsymbollist.first);
-        while assigned(hp) do
-         begin
-           with hp do
-            begin
-              reset;
-              inusedlist:=false;
-            end;
-           hp:=tasmsymbol(hp.listnext);
-         end;
-      end;
-
-
-    procedure TAsmLibraryData.UsedAsmSymbolListResetAltSym;
-      var
-        hp : tasmsymbol;
-      begin
-        hp:=tasmsymbol(usedasmsymbollist.first);
-        inc(nextaltnr);
-        while assigned(hp) do
-         begin
-           with hp do
-            begin
-              altsymbol:=nil;
-              inusedlist:=false;
-            end;
-           hp:=tasmsymbol(hp.listnext);
+           AltSymbollist.Add(p);
          end;
          end;
       end;
       end;
 
 
 
 
-    procedure TAsmLibraryData.UsedAsmSymbolListCheckUndefined;
+    procedure TObjLibraryData.ResetAltSymbols;
       var
       var
-        hp : tasmsymbol;
+        i  : longint;
       begin
       begin
-        hp:=tasmsymbol(usedasmsymbollist.first);
-        while assigned(hp) do
-         begin
-           with hp do
-            begin
-              if is_used and
-                 (section=nil) and
-                 not(currbind in [AB_EXTERNAL,AB_COMMON]) then
-               Message1(asmw_e_undefined_label,name);
-            end;
-           hp:=tasmsymbol(hp.listnext);
-         end;
+        for i:=0 to AltSymbollist.Count-1 do
+          tasmsymbol(AltSymbollist[i]).altsymbol:=nil;
+        AltSymbollist.Clear;
       end;
       end;
 
 
 
 
-    function  TAsmLibraryData.newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
+    function  TObjLibraryData.newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
       var
       var
         hp : tasmlabel;
         hp : tasmlabel;
       begin
       begin
@@ -976,14 +369,15 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TAsmLibraryData.getlabel(var l : tasmlabel;alt:tasmlabeltype);
+    procedure TObjLibraryData.getlabel(var l : tasmlabel;alt:tasmlabeltype);
       begin
       begin
         l:=tasmlabel.createlocal(nextlabelnr[alt],alt);
         l:=tasmlabel.createlocal(nextlabelnr[alt],alt);
         inc(nextlabelnr[alt]);
         inc(nextlabelnr[alt]);
         symbolsearch.insert(l);
         symbolsearch.insert(l);
       end;
       end;
 
 
-    procedure TAsmLibraryData.getjumplabel(var l : tasmlabel);
+
+    procedure TObjLibraryData.getjumplabel(var l : tasmlabel);
       begin
       begin
         l:=tasmlabel.createlocal(nextlabelnr[alt_jump],alt_jump);
         l:=tasmlabel.createlocal(nextlabelnr[alt_jump],alt_jump);
         inc(nextlabelnr[alt_jump]);
         inc(nextlabelnr[alt_jump]);
@@ -991,7 +385,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TAsmLibraryData.getdatalabel(var l : tasmlabel);
+    procedure TObjLibraryData.getdatalabel(var l : tasmlabel);
       begin
       begin
         l:=tasmlabel.createglobal(name,nextlabelnr[alt_data],alt_data);
         l:=tasmlabel.createglobal(name,nextlabelnr[alt_data],alt_data);
         inc(nextlabelnr[alt_data]);
         inc(nextlabelnr[alt_data]);
@@ -999,12 +393,11 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TAsmLibraryData.getaddrlabel(var l : tasmlabel);
+    procedure TObjLibraryData.getaddrlabel(var l : tasmlabel);
       begin
       begin
         l:=tasmlabel.createlocal(nextlabelnr[alt_addr],alt_addr);
         l:=tasmlabel.createlocal(nextlabelnr[alt_addr],alt_addr);
         inc(nextlabelnr[alt_addr]);
         inc(nextlabelnr[alt_addr]);
         symbolsearch.insert(l);
         symbolsearch.insert(l);
       end;
       end;
 
 
-
 end.
 end.

+ 29 - 29
compiler/aasmtai.pas

@@ -37,7 +37,7 @@ interface
        cpuinfo,cpubase,
        cpuinfo,cpubase,
        cgbase,cgutils,
        cgbase,cgutils,
        symtype,
        symtype,
-       aasmbase;
+       aasmbase,ogbase;
 
 
     type
     type
        { keep the number of elements in this enumeration less or equal than 32 as long
        { keep the number of elements in this enumeration less or equal than 32 as long
@@ -320,8 +320,8 @@ interface
        { Generates an assembler label }
        { Generates an assembler label }
        tai_label = class(tai)
        tai_label = class(tai)
           is_global : boolean;
           is_global : boolean;
-          l         : tasmlabel;
-          constructor Create(_l : tasmlabel);
+          labsym    : tasmlabel;
+          constructor Create(_labsym : tasmlabel);
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure derefimpl;override;
           procedure derefimpl;override;
@@ -340,11 +340,11 @@ interface
 
 
        { Generates a section / segment directive }
        { Generates a section / segment directive }
        tai_section = class(tai)
        tai_section = class(tai)
-          sectype : TAsmSectionType;
+          sectype : TAsmSectiontype;
           secalign : byte;
           secalign : byte;
           name    : pstring;
           name    : pstring;
-          sec     : TAsmSection; { used in binary writer }
-          constructor Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
+          sec     : TObjSection; { used in binary writer }
+          constructor Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte);
           destructor Destroy;override;
           destructor Destroy;override;
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
@@ -590,8 +590,8 @@ interface
            function spilling_get_operation_type(opnr: longint): topertype;virtual;
            function spilling_get_operation_type(opnr: longint): topertype;virtual;
            function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
            function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
 
 
-           function  Pass1(offset:longint):longint;virtual;abstract;
-           procedure Pass2(objdata:TAsmObjectdata);virtual;abstract;
+           function  Pass1(objdata:TObjData):longint;virtual;abstract;
+           procedure Pass2(objdata:TObjData);virtual;abstract;
         end;
         end;
         tai_cpu_class = class of tai_cpu_abstract;
         tai_cpu_class = class of tai_cpu_abstract;
 
 
@@ -695,9 +695,9 @@ interface
     function  maybe_smartlink_symbol:boolean;
     function  maybe_smartlink_symbol:boolean;
 
 
     procedure maybe_new_object_file(list:taasmoutput);
     procedure maybe_new_object_file(list:taasmoutput);
-    procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
+    procedure new_section(list:taasmoutput;Asectype:TAsmSectiontype;Aname:string;Aalign:byte);
     procedure section_symbol_start(list:taasmoutput;const Aname:string;Asymtyp:Tasmsymtype;
     procedure section_symbol_start(list:taasmoutput;const Aname:string;Asymtyp:Tasmsymtype;
-                                   Aglobal:boolean;Asectype:TAsmSectionType;Aalign:byte);
+                                   Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
     procedure section_symbol_end(list:taasmoutput;const Aname:string);
     procedure section_symbol_end(list:taasmoutput;const Aname:string);
 
 
     function ppuloadai(ppufile:tcompilerppufile):tai;
     function ppuloadai(ppufile:tcompilerppufile):tai;
@@ -782,7 +782,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
+    procedure new_section(list:taasmoutput;Asectype:TAsmSectiontype;Aname:string;Aalign:byte);
       begin
       begin
         list.concat(tai_section.create(Asectype,Aname,Aalign));
         list.concat(tai_section.create(Asectype,Aname,Aalign));
         list.concat(cai_align.create(Aalign));
         list.concat(cai_align.create(Aalign));
@@ -790,7 +790,7 @@ implementation
 
 
 
 
     procedure section_symbol_start(list:taasmoutput;const Aname:string;Asymtyp:Tasmsymtype;
     procedure section_symbol_start(list:taasmoutput;const Aname:string;Asymtyp:Tasmsymtype;
-                                   Aglobal:boolean;Asectype:TAsmSectionType;Aalign:byte);
+                                   Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
       begin
       begin
         maybe_new_object_file(list);
         maybe_new_object_file(list);
         list.concat(tai_section.create(Asectype,Aname,Aalign));
         list.concat(tai_section.create(Asectype,Aname,Aalign));
@@ -887,7 +887,7 @@ implementation
                              TAI_SECTION
                              TAI_SECTION
  ****************************************************************************}
  ****************************************************************************}
 
 
-    constructor tai_section.Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
+    constructor tai_section.Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte);
       begin
       begin
         inherited Create;
         inherited Create;
         typ:=ait_section;
         typ:=ait_section;
@@ -901,7 +901,7 @@ implementation
     constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
     constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
       begin
       begin
         inherited ppuload(t,ppufile);
         inherited ppuload(t,ppufile);
-        sectype:=tasmsectiontype(ppufile.getbyte);
+        sectype:=TAsmSectiontype(ppufile.getbyte);
         secalign:=ppufile.getbyte;
         secalign:=ppufile.getbyte;
         name:=stringdup(ppufile.getstring);
         name:=stringdup(ppufile.getstring);
         sec:=nil;
         sec:=nil;
@@ -974,7 +974,6 @@ implementation
 
 
     procedure tai_datablock.derefimpl;
     procedure tai_datablock.derefimpl;
       begin
       begin
-        objectlibrary.DerefAsmsymbol(sym);
       end;
       end;
 
 
 
 
@@ -988,20 +987,22 @@ implementation
          typ:=ait_symbol;
          typ:=ait_symbol;
          sym:=_sym;
          sym:=_sym;
          size:=siz;
          size:=siz;
-         sym.defbind:=AB_LOCAL;
+         sym.bind:=AB_LOCAL;
          is_global:=false;
          is_global:=false;
       end;
       end;
 
 
+
     constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
     constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
       begin
       begin
          inherited Create;
          inherited Create;
          typ:=ait_symbol;
          typ:=ait_symbol;
          sym:=_sym;
          sym:=_sym;
          size:=siz;
          size:=siz;
-         sym.defbind:=AB_GLOBAL;
+         sym.bind:=AB_GLOBAL;
          is_global:=true;
          is_global:=true;
       end;
       end;
 
 
+
     constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
     constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
       begin
       begin
          inherited Create;
          inherited Create;
@@ -1011,6 +1012,7 @@ implementation
          is_global:=false;
          is_global:=false;
       end;
       end;
 
 
+
     constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
     constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
       begin
       begin
          inherited Create;
          inherited Create;
@@ -1020,6 +1022,7 @@ implementation
          is_global:=true;
          is_global:=true;
       end;
       end;
 
 
+
     constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
     constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
       begin
       begin
         inherited ppuload(t,ppufile);
         inherited ppuload(t,ppufile);
@@ -1040,7 +1043,6 @@ implementation
 
 
     procedure tai_symbol.derefimpl;
     procedure tai_symbol.derefimpl;
       begin
       begin
-        objectlibrary.DerefAsmsymbol(sym);
       end;
       end;
 
 
 
 
@@ -1055,6 +1057,7 @@ implementation
          sym:=_sym;
          sym:=_sym;
       end;
       end;
 
 
+
     constructor tai_symbol_end.Createname(const _name : string);
     constructor tai_symbol_end.Createname(const _name : string);
       begin
       begin
          inherited Create;
          inherited Create;
@@ -1062,6 +1065,7 @@ implementation
          sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
          sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
       end;
       end;
 
 
+
     constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
     constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
       begin
       begin
         inherited ppuload(t,ppufile);
         inherited ppuload(t,ppufile);
@@ -1078,7 +1082,6 @@ implementation
 
 
     procedure tai_symbol_end.derefimpl;
     procedure tai_symbol_end.derefimpl;
       begin
       begin
-        objectlibrary.DerefAsmsymbol(sym);
       end;
       end;
 
 
 
 
@@ -1352,8 +1355,6 @@ implementation
 
 
     procedure tai_const.derefimpl;
     procedure tai_const.derefimpl;
       begin
       begin
-        objectlibrary.DerefAsmsymbol(sym);
-        objectlibrary.DerefAsmsymbol(endsym);
       end;
       end;
 
 
 
 
@@ -1599,20 +1600,20 @@ implementation
                                TAI_LABEL
                                TAI_LABEL
  ****************************************************************************}
  ****************************************************************************}
 
 
-    constructor tai_label.create(_l : tasmlabel);
+    constructor tai_label.create(_labsym : tasmlabel);
       begin
       begin
         inherited Create;
         inherited Create;
         typ:=ait_label;
         typ:=ait_label;
-        l:=_l;
-        l.is_set:=true;
-        is_global:=(l.defbind=AB_GLOBAL);
+        labsym:=_labsym;
+        labsym.is_set:=true;
+        is_global:=(labsym.bind=AB_GLOBAL);
       end;
       end;
 
 
 
 
     constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
     constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
       begin
       begin
         inherited ppuload(t,ppufile);
         inherited ppuload(t,ppufile);
-        l:=tasmlabel(ppufile.getasmsymbol);
+        labsym:=tasmlabel(ppufile.getasmsymbol);
         is_global:=boolean(ppufile.getbyte);
         is_global:=boolean(ppufile.getbyte);
       end;
       end;
 
 
@@ -1620,15 +1621,14 @@ implementation
     procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
     procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
       begin
       begin
         inherited ppuwrite(ppufile);
         inherited ppuwrite(ppufile);
-        ppufile.putasmsymbol(l);
+        ppufile.putasmsymbol(labsym);
         ppufile.putbyte(byte(is_global));
         ppufile.putbyte(byte(is_global));
       end;
       end;
 
 
 
 
     procedure tai_label.derefimpl;
     procedure tai_label.derefimpl;
       begin
       begin
-        objectlibrary.DerefAsmsymbol(tasmsymbol(l));
-        l.is_set:=true;
+        labsym.is_set:=true;
       end;
       end;
 
 
 
 

+ 25 - 22
compiler/aggas.pas

@@ -50,8 +50,8 @@ interface
       }
       }
       TGNUAssembler=class(texternalassembler)
       TGNUAssembler=class(texternalassembler)
       protected
       protected
-        function sectionname(atype:tasmsectiontype;const aname:string):string;virtual;
-        procedure WriteSection(atype:tasmsectiontype;const aname:string);
+        function sectionname(atype:TAsmSectiontype;const aname:string):string;virtual;
+        procedure WriteSection(atype:TAsmSectiontype;const aname:string);
         procedure WriteExtraHeader;virtual;
         procedure WriteExtraHeader;virtual;
         procedure WriteInstruction(hp: tai);  virtual; abstract;
         procedure WriteInstruction(hp: tai);  virtual; abstract;
       public
       public
@@ -76,7 +76,7 @@ implementation
       line_length = 70;
       line_length = 70;
 
 
     var
     var
-      CurrSecType  : TAsmSectionType; { last section type written }
+      CurrSecType  : TAsmSectiontype; { last section type written }
       lastfileinfo : tfileposinfo;
       lastfileinfo : tfileposinfo;
       infile,
       infile,
       lastinfile   : tinputfile;
       lastinfile   : tinputfile;
@@ -201,27 +201,33 @@ implementation
         result := target_asm.labelprefix+'$set$'+tostr(setcount);
         result := target_asm.labelprefix+'$set$'+tostr(setcount);
       end;
       end;
 
 
-    function TGNUAssembler.sectionname(atype:tasmsectiontype;const aname:string):string;
+    function TGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string):string;
       const
       const
-        secnames : array[tasmsectiontype] of string[13] = ('',
+        secnames : array[TAsmSectiontype] of string[13] = ('',
+          '.text',
+          '.data',
 {$warning TODO .rodata not yet working}
 {$warning TODO .rodata not yet working}
-          '.text','.data','.data','.bss','.threadvar',
-          'common',
-          '.note',
+          '.data',
+          '.bss',
+          '.threadvar',
           '__TEXT', { stubs }
           '__TEXT', { stubs }
-          '.stab','.stabstr',
+          '.stab',
+          '.stabstr',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.eh_frame',
           '.eh_frame',
           '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
           '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
           'fpc.resptrs',
           'fpc.resptrs',
           '.toc'
           '.toc'
         );
         );
-        secnames_pic : array[tasmsectiontype] of string[13] = ('',
-          '.text','.data.rel','.data.rel','.bss','.threadvar',
-          'common',
-          '.note',
+        secnames_pic : array[TAsmSectiontype] of string[13] = ('',
+          '.text',
+          '.data.rel',
+          '.data.rel',
+          '.bss',
+          '.threadvar',
           '__TEXT', { stubs }
           '__TEXT', { stubs }
-          '.stab','.stabstr',
+          '.stab',
+          '.stabstr',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.eh_frame',
           '.eh_frame',
           '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
           '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
@@ -249,7 +255,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TGNUAssembler.WriteSection(atype:tasmsectiontype;const aname:string);
+    procedure TGNUAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
       var
       var
         s : string;
         s : string;
       begin
       begin
@@ -787,14 +793,14 @@ implementation
 
 
            ait_label :
            ait_label :
              begin
              begin
-               if (tai_label(hp).l.is_used) then
+               if (tai_label(hp).labsym.is_used) then
                 begin
                 begin
-                  if tai_label(hp).l.defbind=AB_GLOBAL then
+                  if tai_label(hp).labsym.bind=AB_GLOBAL then
                    begin
                    begin
                      AsmWrite('.globl'#9);
                      AsmWrite('.globl'#9);
-                     AsmWriteLn(tai_label(hp).l.name);
+                     AsmWriteLn(tai_label(hp).labsym.name);
                    end;
                    end;
-                  AsmWrite(tai_label(hp).l.name);
+                  AsmWrite(tai_label(hp).labsym.name);
                   AsmWriteLn(':');
                   AsmWriteLn(':');
                 end;
                 end;
              end;
              end;
@@ -843,9 +849,6 @@ implementation
                            AsmWriteLn(',' + sepChar + 'function');
                            AsmWriteLn(',' + sepChar + 'function');
                          end;
                          end;
                      end;
                      end;
-                   if (tf_needs_symbol_size in target_info.flags) and (tai_symbol(hp).sym.size > 0) then begin
-                     AsmWriteLn(#9'.size'#9 + tai_symbol(hp).sym.name + ', ' + tostr(tai_symbol(hp).sym.size));
-                   end;
                  end;
                  end;
                AsmWriteLn(tai_symbol(hp).sym.name + ':');
                AsmWriteLn(tai_symbol(hp).sym.name + ':');
              end;
              end;

+ 4 - 4
compiler/arm/aasmcpu.pas

@@ -199,7 +199,7 @@ uses
          function  CheckIfValid:boolean;
          function  CheckIfValid:boolean;
          function GetString:string;
          function GetString:string;
          function Pass1(offset:longint):longint;override;
          function Pass1(offset:longint):longint;override;
-         procedure Pass2(objdata:TAsmObjectdata);override;
+         procedure Pass2(objdata:TObjData);override;
       protected
       protected
          procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);override;
          procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);override;
          procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);override;
          procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);override;
@@ -215,7 +215,7 @@ uses
          procedure create_ot;
          procedure create_ot;
          function  Matches(p:PInsEntry):longint;
          function  Matches(p:PInsEntry):longint;
          function  calcsize(p:PInsEntry):shortint;
          function  calcsize(p:PInsEntry):shortint;
-         procedure gencode(objdata:TAsmObjectData);
+         procedure gencode(objdata:TObjData);
          function  NeedAddrPrefix(opidx:byte):boolean;
          function  NeedAddrPrefix(opidx:byte):boolean;
          procedure Swapoperands;
          procedure Swapoperands;
          function  FindInsentry:boolean;
          function  FindInsentry:boolean;
@@ -989,7 +989,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure taicpu.Pass2(objdata:TAsmObjectdata);
+    procedure taicpu.Pass2(objdata:TObjData);
       begin
       begin
         { error in pass1 ? }
         { error in pass1 ? }
         if insentry=nil then
         if insentry=nil then
@@ -1392,7 +1392,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure taicpu.gencode(objdata:TAsmObjectData);
+    procedure taicpu.gencode(objdata:TObjData);
       var
       var
         bytes : dword;
         bytes : dword;
         i_field : byte;
         i_field : byte;

+ 188 - 246
compiler/assemble.pas

@@ -131,21 +131,14 @@ interface
       end;
       end;
 
 
       TInternalAssembler=class(TAssembler)
       TInternalAssembler=class(TAssembler)
-      public
-        constructor create(smart:boolean);override;
-        destructor  destroy;override;
-        procedure MakeObject;override;
-      protected
-        objectdata   : TAsmObjectData;
-        objectoutput : tobjectoutput;
       private
       private
+        FCObjOutput : TObjOutputclass;
         { the aasmoutput lists that need to be processed }
         { the aasmoutput lists that need to be processed }
         lists        : byte;
         lists        : byte;
         list         : array[1..maxoutputlists] of TAAsmoutput;
         list         : array[1..maxoutputlists] of TAAsmoutput;
         { current processing }
         { current processing }
         currlistidx  : byte;
         currlistidx  : byte;
         currlist     : TAAsmoutput;
         currlist     : TAAsmoutput;
-        currpass     : byte;
         procedure convertstab(p:pchar);
         procedure convertstab(p:pchar);
         function  MaybeNextList(var hp:Tai):boolean;
         function  MaybeNextList(var hp:Tai):boolean;
         function  TreePass0(hp:Tai):Tai;
         function  TreePass0(hp:Tai):Tai;
@@ -153,6 +146,14 @@ interface
         function  TreePass2(hp:Tai):Tai;
         function  TreePass2(hp:Tai):Tai;
         procedure writetree;
         procedure writetree;
         procedure writetreesmart;
         procedure writetreesmart;
+      protected
+        ObjData   : TObjData;
+        ObjOutput : tObjOutput;
+        property CObjOutput:TObjOutputclass read FCObjOutput write FCObjOutput;
+      public
+        constructor create(smart:boolean);override;
+        destructor  destroy;override;
+        procedure MakeObject;override;
       end;
       end;
 
 
     TAssemblerClass = class of TAssembler;
     TAssemblerClass = class of TAssembler;
@@ -427,8 +428,6 @@ Implementation
 
 
 
 
     Function TExternalAssembler.DoAssemble:boolean;
     Function TExternalAssembler.DoAssemble:boolean;
-      var
-        s : TCmdStr;
       begin
       begin
         DoAssemble:=true;
         DoAssemble:=true;
         if DoPipe then
         if DoPipe then
@@ -443,7 +442,7 @@ Implementation
            else
            else
            Message1(exec_i_assembling,name);
            Message1(exec_i_assembling,name);
          end;
          end;
-        
+
         if CallAssembler(FindAssembler,MakeCmdLine) then
         if CallAssembler(FindAssembler,MakeCmdLine) then
          RemoveAsm
          RemoveAsm
         else
         else
@@ -668,10 +667,9 @@ Implementation
     constructor TInternalAssembler.create(smart:boolean);
     constructor TInternalAssembler.create(smart:boolean);
       begin
       begin
         inherited create(smart);
         inherited create(smart);
-        objectoutput:=nil;
-        objectdata:=nil;
+        ObjOutput:=nil;
+        ObjData:=nil;
         SmartAsm:=smart;
         SmartAsm:=smart;
-        currpass:=0;
       end;
       end;
 
 
 
 
@@ -684,8 +682,10 @@ Implementation
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
         d := tmemdebug.create(name+' - agbin');
         d := tmemdebug.create(name+' - agbin');
 {$endif}
 {$endif}
-        objectdata.free;
-        objectoutput.free;
+        if assigned(ObjData) then
+          ObjData.free;
+        if assigned(ObjOutput) then
+          ObjOutput.free;
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
         d.free;
         d.free;
 {$endif}
 {$endif}
@@ -728,13 +728,13 @@ Implementation
           result:=(code=0);
           result:=(code=0);
         end;
         end;
 
 
-        function consumeoffset(var p:pchar;out relocsym:tasmsymbol;out value:longint):boolean;
+        function consumeoffset(var p:pchar;out relocsym:tobjsymbol;out value:longint):boolean;
         var
         var
           hs        : string;
           hs        : string;
           len,
           len,
           code      : integer;
           code      : integer;
           pstart    : pchar;
           pstart    : pchar;
-          sym       : tasmsymbol;
+          sym       : tobjsymbol;
           exprvalue : longint;
           exprvalue : longint;
           gotmin,
           gotmin,
           dosub     : boolean;
           dosub     : boolean;
@@ -782,21 +782,16 @@ Implementation
                     internalerror(200509187);
                     internalerror(200509187);
                   move(pstart^,hs[1],len);
                   move(pstart^,hs[1],len);
                   hs[0]:=chr(len);
                   hs[0]:=chr(len);
-                  sym:=objectlibrary.newasmsymbol(hs,AB_EXTERNAL,AT_NONE);
-                  if not assigned(sym) then
-                    internalerror(200509188);
-                  objectlibrary.UsedAsmSymbolListInsert(sym);
+                  sym:=objdata.symbolref(hs);
                   { Second symbol? }
                   { Second symbol? }
                   if assigned(relocsym) then
                   if assigned(relocsym) then
                     begin
                     begin
-                      if (relocsym.section<>sym.section) then
+                      if (relocsym.objsection<>sym.objsection) then
                         internalerror(2005091810);
                         internalerror(2005091810);
                       relocsym:=nil;
                       relocsym:=nil;
                     end
                     end
                   else
                   else
-                    begin
-                      relocsym:=sym;
-                    end;
+                    relocsym:=sym;
                   exprvalue:=sym.address;
                   exprvalue:=sym.address;
                 end;
                 end;
               '+' :
               '+' :
@@ -828,7 +823,7 @@ Implementation
         nidx,
         nidx,
         nother,
         nother,
         i         : longint;
         i         : longint;
-        relocsym  : tasmsymbol;
+        relocsym  : TObjSymbol;
         pstr,
         pstr,
         pcurr,
         pcurr,
         pendquote : pchar;
         pendquote : pchar;
@@ -856,8 +851,8 @@ Implementation
           pcurr:=p;
           pcurr:=p;
 
 
         { When in pass 1 then only alloc and leave }
         { When in pass 1 then only alloc and leave }
-        if currpass=1 then
-          objectdata.allocstab(pstr)
+        if ObjData.currpass=1 then
+          ObjData.allocstab(pstr)
         else
         else
           begin
           begin
             { Stabs format: nidx,nother,nline[,offset] }
             { Stabs format: nidx,nother,nline[,offset] }
@@ -881,7 +876,7 @@ Implementation
             if (nidx=N_Function) and
             if (nidx=N_Function) and
                (tf_use_function_relative_addresses in target_info.flags) then
                (tf_use_function_relative_addresses in target_info.flags) then
               ofs:=0;
               ofs:=0;
-            objectdata.writestab(ofs,relocsym,nidx,nother,nline,pstr);
+            ObjData.writestab(ofs,relocsym,byte(nidx),byte(nother),word(nline),pstr);
           end;
           end;
         if assigned(pendquote) then
         if assigned(pendquote) then
           pendquote^:='"';
           pendquote^:='"';
@@ -911,7 +906,7 @@ Implementation
 
 
     function TInternalAssembler.TreePass0(hp:Tai):Tai;
     function TInternalAssembler.TreePass0(hp:Tai):Tai;
       var
       var
-        l : longint;
+        objsym : TObjSymbol;
       begin
       begin
         while assigned(hp) do
         while assigned(hp) do
          begin
          begin
@@ -921,52 +916,40 @@ Implementation
                  { always use the maximum fillsize in this pass to avoid possible
                  { always use the maximum fillsize in this pass to avoid possible
                    short jumps to become out of range }
                    short jumps to become out of range }
                  Tai_align(hp).fillsize:=Tai_align(hp).aligntype;
                  Tai_align(hp).fillsize:=Tai_align(hp).aligntype;
-                 objectdata.alloc(Tai_align(hp).fillsize);
+                 ObjData.alloc(Tai_align(hp).fillsize);
                end;
                end;
              ait_datablock :
              ait_datablock :
                begin
                begin
-                 l:=used_align(size_2_align(Tai_datablock(hp).size),0,objectdata.currsec.addralign);
-                 if SmartAsm or (not Tai_datablock(hp).is_global) then
-                   begin
-                     objectdata.allocalign(l);
-                     objectdata.alloc(Tai_datablock(hp).size);
-                   end;
+                 ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
+                 ObjData.SymbolDefine(Tai_datablock(hp).sym);
+                 ObjData.alloc(Tai_datablock(hp).size);
                end;
                end;
              ait_real_80bit :
              ait_real_80bit :
-               objectdata.alloc(10);
+               ObjData.alloc(10);
              ait_real_64bit :
              ait_real_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_real_32bit :
              ait_real_32bit :
-               objectdata.alloc(4);
+               ObjData.alloc(4);
              ait_comp_64bit :
              ait_comp_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_const:
              ait_const:
-               objectdata.alloc(tai_const(hp).size);
+               ObjData.alloc(tai_const(hp).size);
              ait_section:
              ait_section:
                begin
                begin
-                 objectdata.CreateSection(Tai_section(hp).sectype,Tai_section(hp).name^,Tai_section(hp).secalign,[]);
-                 Tai_section(hp).sec:=objectdata.CurrSec;
+                 ObjData.CreateSection(Tai_section(hp).sectype,Tai_section(hp).name^);
+                 Tai_section(hp).sec:=ObjData.CurrObjSec;
                end;
                end;
              ait_symbol :
              ait_symbol :
-               objectdata.allocsymbol(currpass,Tai_symbol(hp).sym,0);
+               ObjData.SymbolDefine(Tai_symbol(hp).sym);
              ait_label :
              ait_label :
-               objectdata.allocsymbol(currpass,Tai_label(hp).l,0);
+               ObjData.SymbolDefine(Tai_label(hp).labsym);
              ait_string :
              ait_string :
-               objectdata.alloc(Tai_string(hp).len);
+               ObjData.alloc(Tai_string(hp).len);
              ait_instruction :
              ait_instruction :
                begin
                begin
-{$ifdef i386}
-{$ifndef NOAG386BIN}
-                 { reset instructions which could change in pass 2 }
-                 Taicpu(hp).resetpass2;
-                 objectdata.alloc(Taicpu(hp).Pass1(objectdata.currsec.datasize));
-{$endif NOAG386BIN}
-{$endif i386}
-{$ifdef arm}
                  { reset instructions which could change in pass 2 }
                  { reset instructions which could change in pass 2 }
                  Taicpu(hp).resetpass2;
                  Taicpu(hp).resetpass2;
-                 objectdata.alloc(Taicpu(hp).Pass1(objectdata.currsec.datasize));
-{$endif arm}
+                 ObjData.alloc(Taicpu(hp).Pass1(ObjData));
                end;
                end;
              ait_cutobject :
              ait_cutobject :
                if SmartAsm then
                if SmartAsm then
@@ -981,8 +964,8 @@ Implementation
     function TInternalAssembler.TreePass1(hp:Tai):Tai;
     function TInternalAssembler.TreePass1(hp:Tai):Tai;
       var
       var
         InlineLevel,
         InlineLevel,
-        l,
         i : longint;
         i : longint;
+        objsym : TObjSymbol;
       begin
       begin
         inlinelevel:=0;
         inlinelevel:=0;
         while assigned(hp) do
         while assigned(hp) do
@@ -991,51 +974,39 @@ Implementation
              ait_align :
              ait_align :
                begin
                begin
                  { here we must determine the fillsize which is used in pass2 }
                  { here we must determine the fillsize which is used in pass2 }
-                 Tai_align(hp).fillsize:=align(objectdata.currsec.datasize,Tai_align(hp).aligntype)-
-                   objectdata.currsec.datasize;
-                 objectdata.alloc(Tai_align(hp).fillsize);
+                 Tai_align(hp).fillsize:=align(ObjData.CurrObjSec.Size,Tai_align(hp).aligntype)-
+                   ObjData.CurrObjSec.Size;
+                 ObjData.alloc(Tai_align(hp).fillsize);
                end;
                end;
              ait_datablock :
              ait_datablock :
                begin
                begin
-                 if not (objectdata.currsec.sectype in [sec_bss,sec_threadvar]) then
+                 if (oso_data in ObjData.CurrObjSec.secoptions) then
                    Message(asmw_e_alloc_data_only_in_bss);
                    Message(asmw_e_alloc_data_only_in_bss);
-                 l:=used_align(size_2_align(Tai_datablock(hp).size),0,objectdata.currsec.addralign);
-{                 if Tai_datablock(hp).is_global and
-                    not SmartAsm then
-                  begin}
-{                    objectdata.allocsymbol(currpass,Tai_datablock(hp).sym,Tai_datablock(hp).size);}
-                    { force to be common/external, must be after setaddress as that would
-                      set it to AB_GLOBAL }
-{                    Tai_datablock(hp).sym.currbind:=AB_COMMON;
-                  end
-                 else
-                  begin}
-                    objectdata.allocalign(l);
-                    objectdata.allocsymbol(currpass,Tai_datablock(hp).sym,Tai_datablock(hp).size);
-                    objectdata.alloc(Tai_datablock(hp).size);
-{                  end;}
-                 objectlibrary.UsedAsmSymbolListInsert(Tai_datablock(hp).sym);
+                 ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
+                 objsym:=ObjData.SymbolDefine(Tai_datablock(hp).sym);
+                 objsym.size:=Tai_datablock(hp).size;
+                 ObjData.alloc(Tai_datablock(hp).size);
                end;
                end;
              ait_real_80bit :
              ait_real_80bit :
-               objectdata.alloc(10);
+               ObjData.alloc(10);
              ait_real_64bit :
              ait_real_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_real_32bit :
              ait_real_32bit :
-               objectdata.alloc(4);
+               ObjData.alloc(4);
              ait_comp_64bit :
              ait_comp_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_const:
              ait_const:
                begin
                begin
-                 objectdata.alloc(tai_const(hp).size);
+                 ObjData.alloc(tai_const(hp).size);
                  if assigned(Tai_const(hp).sym) then
                  if assigned(Tai_const(hp).sym) then
-                   objectlibrary.UsedAsmSymbolListInsert(Tai_const(hp).sym);
+                   ObjData.SymbolRef(Tai_const(hp).sym);
                  if assigned(Tai_const(hp).endsym) then
                  if assigned(Tai_const(hp).endsym) then
-                   objectlibrary.UsedAsmSymbolListInsert(Tai_const(hp).endsym);
+                   ObjData.SymbolRef(Tai_const(hp).endsym);
                end;
                end;
              ait_section:
              ait_section:
                begin
                begin
                  { use cached value }
                  { use cached value }
-                 objectdata.setsection(Tai_section(hp).sec);
+                 ObjData.setsection(Tai_section(hp).sec);
                end;
                end;
              ait_stab :
              ait_stab :
                begin
                begin
@@ -1045,45 +1016,18 @@ Implementation
              ait_function_name,
              ait_function_name,
              ait_force_line : ;
              ait_force_line : ;
              ait_symbol :
              ait_symbol :
-               begin
-                 objectdata.allocsymbol(currpass,Tai_symbol(hp).sym,0);
-                 objectlibrary.UsedAsmSymbolListInsert(Tai_symbol(hp).sym);
-               end;
+               ObjData.SymbolDefine(Tai_symbol(hp).sym);
              ait_symbol_end :
              ait_symbol_end :
                begin
                begin
-                 if target_info.system in [system_i386_linux,system_i386_beos] then
-                  begin
-                    Tai_symbol_end(hp).sym.size:=objectdata.currsec.datasize-Tai_symbol_end(hp).sym.address;
-                    objectlibrary.UsedAsmSymbolListInsert(Tai_symbol_end(hp).sym);
-                  end;
-                end;
-             ait_label :
-               begin
-                 objectdata.allocsymbol(currpass,Tai_label(hp).l,0);
-                 objectlibrary.UsedAsmSymbolListInsert(Tai_label(hp).l);
+                 objsym:=ObjData.SymbolRef(Tai_symbol_end(hp).sym);
+                 objsym.size:=ObjData.CurrObjSec.Size-objsym.offset;
                end;
                end;
+             ait_label :
+               ObjData.SymbolDefine(Tai_label(hp).labsym);
              ait_string :
              ait_string :
-               objectdata.alloc(Tai_string(hp).len);
+               ObjData.alloc(Tai_string(hp).len);
              ait_instruction :
              ait_instruction :
-               begin
-                 objectdata.alloc(Taicpu(hp).Pass1(objectdata.currsec.datasize));
-                 { fixup the references }
-                 for i:=1 to Taicpu(hp).ops do
-                  begin
-                    with Taicpu(hp).oper[i-1]^ do
-                     begin
-                       case typ of
-                         top_ref :
-                           begin
-                             if assigned(ref^.symbol) then
-                              objectlibrary.UsedAsmSymbolListInsert(ref^.symbol);
-                             if assigned(ref^.relsymbol) then
-                              objectlibrary.UsedAsmSymbolListInsert(ref^.symbol);
-                           end;
-                       end;
-                     end;
-                  end;
-               end;
+               ObjData.alloc(Taicpu(hp).Pass1(ObjData));
              ait_cutobject :
              ait_cutobject :
                if SmartAsm then
                if SmartAsm then
                 break;
                 break;
@@ -1103,11 +1047,12 @@ Implementation
       var
       var
         fillbuffer : tfillbuffer;
         fillbuffer : tfillbuffer;
         InlineLevel,
         InlineLevel,
-        l  : longint;
         v  : int64;
         v  : int64;
 {$ifdef x86}
 {$ifdef x86}
         co : comp;
         co : comp;
 {$endif x86}
 {$endif x86}
+        objsym,
+        objsymend : TObjSymbol;
       begin
       begin
         inlinelevel:=0;
         inlinelevel:=0;
         { main loop }
         { main loop }
@@ -1116,47 +1061,41 @@ Implementation
            case hp.typ of
            case hp.typ of
              ait_align :
              ait_align :
                begin
                begin
-                 if objectdata.currsec.sectype in [sec_bss,sec_threadvar] then
-                   objectdata.alloc(Tai_align(hp).fillsize)
+                 if (oso_data in ObjData.CurrObjSec.secoptions) then
+                   ObjData.writebytes(Tai_align(hp).calculatefillbuf(fillbuffer)^,Tai_align(hp).fillsize)
                  else
                  else
-                   objectdata.writebytes(Tai_align(hp).calculatefillbuf(fillbuffer)^,Tai_align(hp).fillsize);
+                   ObjData.alloc(Tai_align(hp).fillsize);
                end;
                end;
              ait_section :
              ait_section :
                begin
                begin
                  { use cached value }
                  { use cached value }
-                 objectdata.setsection(Tai_section(hp).sec);
+                 ObjData.setsection(Tai_section(hp).sec);
                end;
                end;
              ait_symbol :
              ait_symbol :
                begin
                begin
-                 objectdata.writesymbol(Tai_symbol(hp).sym);
-                 objectoutput.exportsymbol(Tai_symbol(hp).sym);
+                 ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_symbol(hp).sym));
                end;
                end;
              ait_datablock :
              ait_datablock :
                begin
                begin
-                 l:=used_align(size_2_align(Tai_datablock(hp).size),0,objectdata.currsec.addralign);
-                 objectdata.writesymbol(Tai_datablock(hp).sym);
-                 objectoutput.exportsymbol(Tai_datablock(hp).sym);
-{                 if SmartAsm or (not Tai_datablock(hp).is_global) then
-                   begin}
-                     objectdata.allocalign(l);
-                     objectdata.alloc(Tai_datablock(hp).size);
-{                   end;}
+                 ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
+                 ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_datablock(hp).sym));
+                 ObjData.alloc(Tai_datablock(hp).size);
                end;
                end;
              ait_real_80bit :
              ait_real_80bit :
-               objectdata.writebytes(Tai_real_80bit(hp).value,10);
+               ObjData.writebytes(Tai_real_80bit(hp).value,10);
              ait_real_64bit :
              ait_real_64bit :
-               objectdata.writebytes(Tai_real_64bit(hp).value,8);
+               ObjData.writebytes(Tai_real_64bit(hp).value,8);
              ait_real_32bit :
              ait_real_32bit :
-               objectdata.writebytes(Tai_real_32bit(hp).value,4);
+               ObjData.writebytes(Tai_real_32bit(hp).value,4);
              ait_comp_64bit :
              ait_comp_64bit :
                begin
                begin
 {$ifdef x86}
 {$ifdef x86}
                  co:=comp(Tai_comp_64bit(hp).value);
                  co:=comp(Tai_comp_64bit(hp).value);
-                 objectdata.writebytes(co,8);
+                 ObjData.writebytes(co,8);
 {$endif x86}
 {$endif x86}
                end;
                end;
              ait_string :
              ait_string :
-               objectdata.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
+               ObjData.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
              ait_const :
              ait_const :
                begin
                begin
                  case tai_const(hp).consttype of
                  case tai_const(hp).consttype of
@@ -1164,34 +1103,36 @@ Implementation
                    aitconst_32bit,
                    aitconst_32bit,
                    aitconst_16bit,
                    aitconst_16bit,
                    aitconst_8bit :
                    aitconst_8bit :
-                     if assigned(tai_const(hp).sym) then
-                       begin
-                         if assigned(tai_const(hp).endsym) then
-                           begin
-                             if tai_const(hp).endsym.section<>tai_const(hp).sym.section then
-                               internalerror(200404124);
-                             v:=tai_const(hp).endsym.address-tai_const(hp).sym.address+Tai_const(hp).value;
-                             objectdata.writebytes(v,tai_const(hp).size);
-                           end
-                         else
-                           objectdata.writereloc(Tai_const(hp).value,Tai_const(hp).size,
-                                                 Tai_const(hp).sym,RELOC_ABSOLUTE);
-                       end
-                     else
-                       objectdata.writebytes(Tai_const(hp).value,tai_const(hp).size);
+                     begin
+                       if assigned(tai_const(hp).sym) then
+                         begin
+                           objsym:=Objdata.SymbolRef(tai_const(hp).sym);
+                           if assigned(tai_const(hp).endsym) then
+                             begin
+                               objsymend:=Objdata.SymbolRef(tai_const(hp).endsym);
+                               if objsymend.objsection<>objsym.objsection then
+                                 internalerror(200404124);
+                               v:=objsymend.address-objsym.address+Tai_const(hp).value;
+                               ObjData.writebytes(v,tai_const(hp).size);
+                             end
+                           else
+                             ObjData.writereloc(Tai_const(hp).value,Tai_const(hp).size,objsym,RELOC_ABSOLUTE);
+                         end
+                       else
+                         ObjData.writebytes(Tai_const(hp).value,tai_const(hp).size);
+                     end;
                    aitconst_rva_symbol :
                    aitconst_rva_symbol :
-                     objectdata.writereloc(Tai_const(hp).value,sizeof(aint),Tai_const(hp).sym,RELOC_RVA);
+                     ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA);
                  end;
                  end;
                end;
                end;
              ait_label :
              ait_label :
                begin
                begin
-                 objectdata.writesymbol(Tai_label(hp).l);
                  { exporting shouldn't be necessary as labels are local,
                  { exporting shouldn't be necessary as labels are local,
                    but it's better to be on the safe side (PFV) }
                    but it's better to be on the safe side (PFV) }
-                 objectoutput.exportsymbol(Tai_label(hp).l);
+                 ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_label(hp).labsym));
                end;
                end;
              ait_instruction :
              ait_instruction :
-               Taicpu(hp).Pass2(objectdata);
+               Taicpu(hp).Pass2(ObjData);
              ait_stab :
              ait_stab :
                convertstab(Tai_stab(hp).str);
                convertstab(Tai_stab(hp).str);
              ait_function_name,
              ait_function_name,
@@ -1212,19 +1153,18 @@ Implementation
 
 
 
 
     procedure TInternalAssembler.writetree;
     procedure TInternalAssembler.writetree;
-      var
-        hp : Tai;
       label
       label
         doexit;
         doexit;
+      var
+        hp : Tai;
       begin
       begin
-        objectdata:=objectoutput.newobjectdata(Objfile);
-        { reset the asmsymbol list }
-        objectlibrary.CreateUsedAsmsymbolList;
-
-      { Pass 0 }
-        currpass:=0;
-        objectdata.createsection(sec_code,'',0,[]);
-        objectdata.beforealloc;
+        ObjOutput:=CObjOutput.Create(false);
+        ObjData:=ObjOutput.newObjData(Objfile);
+
+        { Pass 0 }
+        ObjData.currpass:=0;
+        ObjData.createsection(sec_code,'');
+        ObjData.beforealloc;
         { start with list 1 }
         { start with list 1 }
         currlistidx:=1;
         currlistidx:=1;
         currlist:=list[currlistidx];
         currlist:=list[currlistidx];
@@ -1234,16 +1174,16 @@ Implementation
            hp:=TreePass0(hp);
            hp:=TreePass0(hp);
            MaybeNextList(hp);
            MaybeNextList(hp);
          end;
          end;
-        objectdata.afteralloc;
+        ObjData.afteralloc;
         { leave if errors have occured }
         { leave if errors have occured }
         if errorcount>0 then
         if errorcount>0 then
          goto doexit;
          goto doexit;
 
 
-      { Pass 1 }
-        currpass:=1;
-        objectdata.resetsections;
-        objectdata.beforealloc;
-        objectdata.createsection(sec_code,'',0,[]);
+        { Pass 1 }
+        ObjData.currpass:=1;
+        ObjData.resetsections;
+        ObjData.beforealloc;
+        ObjData.createsection(sec_code,'');
         { start with list 1 }
         { start with list 1 }
         currlistidx:=1;
         currlistidx:=1;
         currlist:=list[currlistidx];
         currlist:=list[currlistidx];
@@ -1253,20 +1193,18 @@ Implementation
            hp:=TreePass1(hp);
            hp:=TreePass1(hp);
            MaybeNextList(hp);
            MaybeNextList(hp);
          end;
          end;
-        objectdata.createsection(sec_code,'',0,[]);
-        objectdata.afteralloc;
-        { check for undefined labels and reset }
-        objectlibrary.UsedAsmSymbolListCheckUndefined;
+        ObjData.createsection(sec_code,'');
+        ObjData.afteralloc;
 
 
         { leave if errors have occured }
         { leave if errors have occured }
         if errorcount>0 then
         if errorcount>0 then
          goto doexit;
          goto doexit;
 
 
-      { Pass 2 }
-        currpass:=2;
-        objectdata.resetsections;
-        objectdata.beforewrite;
-        objectdata.createsection(sec_code,'',0,[]);
+        { Pass 2 }
+        ObjData.currpass:=2;
+        ObjData.resetsections;
+        ObjData.beforewrite;
+        ObjData.createsection(sec_code,'');
         { start with list 1 }
         { start with list 1 }
         currlistidx:=1;
         currlistidx:=1;
         currlist:=list[currlistidx];
         currlist:=list[currlistidx];
@@ -1276,35 +1214,32 @@ Implementation
            hp:=TreePass2(hp);
            hp:=TreePass2(hp);
            MaybeNextList(hp);
            MaybeNextList(hp);
          end;
          end;
-        objectdata.createsection(sec_code,'',0,[]);
-        objectdata.afterwrite;
+        ObjData.createsection(sec_code,'');
+        ObjData.afterwrite;
 
 
         { don't write the .o file if errors have occured }
         { don't write the .o file if errors have occured }
         if errorcount=0 then
         if errorcount=0 then
          begin
          begin
            { write objectfile }
            { write objectfile }
-           objectoutput.startobjectfile(ObjFile);
-           objectoutput.writeobjectfile(objectdata);
-           objectdata.free;
-           objectdata:=nil;
+           ObjOutput.startobjectfile(ObjFile);
+           ObjOutput.writeobjectfile(ObjData);
          end;
          end;
 
 
       doexit:
       doexit:
-        { reset the used symbols back, must be after the .o has been
-          written }
-        objectlibrary.UsedAsmsymbolListReset;
-        objectlibrary.DestroyUsedAsmsymbolList;
+        { Cleanup }
+        ObjData.free;
+        ObjData:=nil;
       end;
       end;
 
 
 
 
     procedure TInternalAssembler.writetreesmart;
     procedure TInternalAssembler.writetreesmart;
       var
       var
         hp : Tai;
         hp : Tai;
-        startsectype : TAsmSectionType;
+        startsectype : TAsmSectiontype;
         place: tcutplace;
         place: tcutplace;
       begin
       begin
         NextSmartName(cut_normal);
         NextSmartName(cut_normal);
-        objectdata:=objectoutput.newobjectdata(Objfile);
+        ObjOutput:=CObjOutput.Create(true);
         startsectype:=sec_code;
         startsectype:=sec_code;
 
 
         { start with list 1 }
         { start with list 1 }
@@ -1313,91 +1248,78 @@ Implementation
         hp:=Tai(currList.first);
         hp:=Tai(currList.first);
         while assigned(hp) do
         while assigned(hp) do
          begin
          begin
-         { reset the asmsymbol list }
-           objectlibrary.CreateUsedAsmSymbolList;
-
-         { Pass 0 }
-           currpass:=0;
-           objectdata.resetsections;
-           objectdata.beforealloc;
-           objectdata.createsection(startsectype,'',0,[]);
+           ObjData:=ObjOutput.newObjData(Objfile);
+
+           { Pass 0 }
+           ObjData.currpass:=0;
+           ObjData.resetsections;
+           ObjData.beforealloc;
+           ObjData.createsection(startsectype,'');
            TreePass0(hp);
            TreePass0(hp);
-           objectdata.afteralloc;
+           ObjData.afteralloc;
            { leave if errors have occured }
            { leave if errors have occured }
            if errorcount>0 then
            if errorcount>0 then
-            exit;
+             exit;
 
 
-         { Pass 1 }
-           currpass:=1;
-           objectdata.resetsections;
-           objectdata.beforealloc;
-           objectdata.createsection(startsectype,'',0,[]);
+           { Pass 1 }
+           ObjData.currpass:=1;
+           ObjData.resetsections;
+           ObjData.beforealloc;
+           ObjData.createsection(startsectype,'');
            TreePass1(hp);
            TreePass1(hp);
-           objectdata.afteralloc;
-           { check for undefined labels }
-           objectlibrary.UsedAsmSymbolListCheckUndefined;
+           ObjData.afteralloc;
 
 
            { leave if errors have occured }
            { leave if errors have occured }
            if errorcount>0 then
            if errorcount>0 then
-            exit;
-
-         { Pass 2 }
-           currpass:=2;
-           objectoutput.startobjectfile(Objfile);
-           objectdata.resetsections;
-           objectdata.beforewrite;
-           objectdata.createsection(startsectype,'',0,[]);
+             break;
+
+           { Pass 2 }
+           ObjData.currpass:=2;
+           ObjOutput.startobjectfile(Objfile);
+           ObjData.resetsections;
+           ObjData.beforewrite;
+           ObjData.createsection(startsectype,'');
            hp:=TreePass2(hp);
            hp:=TreePass2(hp);
-           { save section type for next loop, must be done before EndFileLineInfo
-             because that changes the section to sec_code }
-           startsectype:=objectdata.currsec.sectype;
-           objectdata.afterwrite;
+           ObjData.afterwrite;
+
            { leave if errors have occured }
            { leave if errors have occured }
            if errorcount>0 then
            if errorcount>0 then
-            exit;
+             break;
 
 
            { write the current objectfile }
            { write the current objectfile }
-           objectoutput.writeobjectfile(objectdata);
-           objectdata.free;
-           objectdata:=nil;
-
-           { reset the used symbols back, must be after the .o has been
-             written }
-           objectlibrary.UsedAsmsymbolListReset;
-           objectlibrary.DestroyUsedAsmsymbolList;
+           ObjOutput.writeobjectfile(ObjData);
+           ObjData.free;
+           ObjData:=nil;
 
 
            { end of lists? }
            { end of lists? }
            if not MaybeNextList(hp) then
            if not MaybeNextList(hp) then
-            break;
+             break;
 
 
            { we will start a new objectfile so reset everything }
            { we will start a new objectfile so reset everything }
            { The place can still change in the next while loop, so don't init }
            { The place can still change in the next while loop, so don't init }
            { the writer yet (JM)                                              }
            { the writer yet (JM)                                              }
            if (hp.typ=ait_cutobject) then
            if (hp.typ=ait_cutobject) then
-            place := Tai_cutobject(hp).place
+             place := Tai_cutobject(hp).place
            else
            else
-            place := cut_normal;
+             place := cut_normal;
 
 
            { avoid empty files }
            { avoid empty files }
+           startsectype:=sec_code;
            while assigned(hp) and
            while assigned(hp) and
                  (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cutobject]) do
                  (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cutobject]) do
             begin
             begin
               if Tai(hp).typ=ait_section then
               if Tai(hp).typ=ait_section then
-               startsectype:=Tai_section(hp).sectype
-              else if (Tai(hp).typ=ait_cutobject) then
-               place:=Tai_cutobject(hp).place;
+                startsectype:=Tai_section(hp).sectype;
+              if (Tai(hp).typ=ait_cutobject) then
+                place:=Tai_cutobject(hp).place;
               hp:=Tai(hp.next);
               hp:=Tai(hp.next);
             end;
             end;
-           { there is a problem if startsectype is sec_none !! PM }
-           if startsectype=sec_none then
-             startsectype:=sec_code;
 
 
            if not MaybeNextList(hp) then
            if not MaybeNextList(hp) then
              break;
              break;
 
 
            { start next objectfile }
            { start next objectfile }
            NextSmartName(place);
            NextSmartName(place);
-           objectdata:=objectoutput.newobjectdata(Objfile);
          end;
          end;
       end;
       end;
 
 
@@ -1406,6 +1328,9 @@ Implementation
 
 
     var to_do:set of Tasmlist;
     var to_do:set of Tasmlist;
         i:Tasmlist;
         i:Tasmlist;
+{$ifdef MEMDEBUG}
+        d : tmemdebug;
+{$endif}
 
 
         procedure addlist(p:TAAsmoutput);
         procedure addlist(p:TAAsmoutput);
         begin
         begin
@@ -1429,6 +1354,23 @@ Implementation
           writetreesmart
           writetreesmart
         else
         else
           writetree;
           writetree;
+
+(*
+        if assigned(objectlibrary) then
+          begin
+            if objectlibrary<>current_module.librarydata then
+              internalerror(200603013);
+{$ifdef MEMDEBUG}
+            d:=tmemdebug.create(modulename^+' - librarydata');
+{$endif}
+            objectlibrary.free;
+            objectlibrary:=nil;
+            current_module.librarydata:=nil;
+{$ifdef MEMDEBUG}
+            d.free;
+{$endif}
+          end;
+*)
       end;
       end;
 
 
 
 

+ 133 - 61
compiler/cclasses.pas

@@ -62,6 +62,9 @@ type
    TPointerList = array[0..MaxListSize - 1] of Pointer;
    TPointerList = array[0..MaxListSize - 1] of Pointer;
    TListSortCompare = function (Item1, Item2: Pointer): Integer;
    TListSortCompare = function (Item1, Item2: Pointer): Integer;
 
 
+   TListCallback = procedure(data,arg:pointer) of object;
+   TListStaticCallback = procedure(data,arg:pointer);
+
    TList = class(TObject)
    TList = class(TObject)
    private
    private
      FList: PPointerList;
      FList: PPointerList;
@@ -91,6 +94,8 @@ type
      function Remove(Item: Pointer): Integer;
      function Remove(Item: Pointer): Integer;
      procedure Pack;
      procedure Pack;
      procedure Sort(Compare: TListSortCompare);
      procedure Sort(Compare: TListSortCompare);
+     procedure foreach(proc2call:TListCallback;arg:pointer);
+     procedure foreach_static(proc2call:TListStaticCallback;arg:pointer);
      property Capacity: Integer read FCapacity write SetCapacity;
      property Capacity: Integer read FCapacity write SetCapacity;
      property Count: Integer read FCount write SetCount;
      property Count: Integer read FCount write SetCount;
      property Items[Index: Integer]: Pointer read Get write Put; default;
      property Items[Index: Integer]: Pointer read Get write Put; default;
@@ -200,6 +205,8 @@ type
           { concats an item }
           { concats an item }
           procedure ConcatItem(item:TStringListItem);
           procedure ConcatItem(item:TStringListItem);
           property Doubles:boolean read FDoubles write FDoubles;
           property Doubles:boolean read FDoubles write FDoubles;
+          procedure readstream(f:TCStream);
+          procedure writestream(f:TCStream);
        end;
        end;
 
 
 
 
@@ -222,8 +229,6 @@ type
          FLeft,
          FLeft,
          FRight      : TNamedIndexItem;
          FRight      : TNamedIndexItem;
          FSpeedValue : cardinal;
          FSpeedValue : cardinal;
-       { singleList }
-         FListNext   : TNamedIndexItem;
          FName       : Pstring;
          FName       : Pstring;
        protected
        protected
          function  GetName:string;virtual;
          function  GetName:string;virtual;
@@ -236,7 +241,6 @@ type
          property IndexNext:TNamedIndexItem read FIndexNext write FIndexNext;
          property IndexNext:TNamedIndexItem read FIndexNext write FIndexNext;
          property Name:string read GetName write SetName;
          property Name:string read GetName write SetName;
          property SpeedValue:cardinal read FSpeedValue;
          property SpeedValue:cardinal read FSpeedValue;
-         property ListNext:TNamedIndexItem read FListNext;
          property Left:TNamedIndexItem read FLeft write FLeft;
          property Left:TNamedIndexItem read FLeft write FLeft;
          property Right:TNamedIndexItem read FRight write FRight;
          property Right:TNamedIndexItem read FRight write FRight;
        end;
        end;
@@ -275,15 +279,6 @@ type
          property  Count:longint read FCount;
          property  Count:longint read FCount;
        end;
        end;
 
 
-       tsingleList=class
-         First,
-         last    : TNamedIndexItem;
-         constructor Create;
-         procedure reset;
-         procedure clear;
-         procedure insert(p:TNamedIndexItem);
-       end;
-
       tindexobjectarray=array[1..16000] of TNamedIndexItem;
       tindexobjectarray=array[1..16000] of TNamedIndexItem;
       pnamedindexobjectarray=^tindexobjectarray;
       pnamedindexobjectarray=^tindexobjectarray;
 
 
@@ -301,6 +296,7 @@ type
         procedure insert(p:TNamedIndexItem);
         procedure insert(p:TNamedIndexItem);
         procedure replace(oldp,newp:TNamedIndexItem);
         procedure replace(oldp,newp:TNamedIndexItem);
         function  search(nr:integer):TNamedIndexItem;
         function  search(nr:integer):TNamedIndexItem;
+        property  Items[Index: Integer]: TNamedIndexItem read Search; default;
       private
       private
         growsize,
         growsize,
         size  : integer;
         size  : integer;
@@ -747,6 +743,33 @@ begin
 end;
 end;
 
 
 
 
+    procedure TList.foreach(proc2call:TListCallback;arg:pointer);
+      var
+        i : longint;
+        p : pointer;
+      begin
+        For I:=0 To Count-1 Do
+          begin
+            p:=FList^[i];
+            if assigned(p) then
+              proc2call(p,arg);
+          end;
+      end;
+
+
+    procedure TList.foreach_static(proc2call:TListStaticCallback;arg:pointer);
+      var
+        i : longint;
+        p : pointer;
+      begin
+        For I:=0 To Count-1 Do
+          begin
+            p:=FList^[i];
+            if assigned(p) then
+              proc2call(p,arg);
+          end;
+      end;
+
 {****************************************************************************
 {****************************************************************************
                              TLinkedListItem
                              TLinkedListItem
  ****************************************************************************}
  ****************************************************************************}
@@ -1239,6 +1262,104 @@ end;
       end;
       end;
 
 
 
 
+    procedure TStringList.readstream(f:TCStream);
+      const
+        BufSize = 16384;
+      var
+        Hsp,
+        p,maxp,
+        Buf    : PChar;
+        Prev   : Char;
+        HsPos,
+        ReadLen,
+        BufPos,
+        BufEnd : Longint;
+        hs     : string;
+
+        procedure ReadBuf;
+        begin
+          if BufPos<BufEnd then
+            begin
+              Move(Buf[BufPos],Buf[0],BufEnd-BufPos);
+              Dec(BufEnd,BufPos);
+              BufPos:=0;
+            end;
+          ReadLen:=f.Read(buf[BufEnd],BufSize-BufEnd);
+          inc(BufEnd,ReadLen);
+        end;
+
+      begin
+        Getmem(Buf,Bufsize);
+        BufPos:=0;
+        BufEnd:=0;
+        HsPos:=1;
+        ReadBuf;
+        repeat
+          hsp:=@hs[hsPos];
+          p:=@Buf[BufPos];
+          maxp:=@Buf[BufEnd];
+          while (p<maxp) and not(P^ in [#10,#13]) do
+            begin
+              hsp^:=p^;
+              inc(p);
+              if hsp-@hs[1]<255 then
+                inc(hsp);
+            end;
+          inc(BufPos,maxp-p);
+          inc(HsPos,maxp-p);
+          prev:=p^;
+          inc(BufPos);
+          { no system uses #10#13 as line seperator (#10 = *nix, #13 = Mac, }
+          { #13#10 = Dos), so if we've got #10, we can safely exit          }
+          if (prev<>#10) then
+            begin
+              if (BufPos>=BufEnd) then
+                begin
+                  ReadBuf;
+                  if BufPos>=BufEnd then
+                    break;
+                end;
+              { is there also a #10 after it? }
+              if prev=#13 then
+                begin
+                  if (Buf[BufPos]=#10) then
+                    inc(BufPos);
+                  prev:=#10;
+                end;
+            end;
+          if prev=#10 then
+            begin
+              hs[0]:=char(hsp-@hs[1]);
+              Concat(hs);
+              HsPos:=1;
+            end;
+        until BufPos>=BufEnd;
+        hs[0]:=char(hsp-@hs[1]);
+        Concat(hs);
+        freemem(buf);
+      end;
+
+
+    procedure TStringList.writestream(f:TCStream);
+      var
+        Node : TStringListItem;
+        LineEnd : string[2];
+      begin
+        Case DefaultTextLineBreakStyle Of
+          tlbsLF: LineEnd := #10;
+          tlbsCRLF: LineEnd := #13#10;
+          tlbsCR: LineEnd := #13;
+        End;
+        Node:=tstringListItem(FFirst);
+        while assigned(Node) do
+          begin
+            f.Write(Node.FPStr^[1],Length(Node.FPStr^));
+            f.Write(LineEnd[1],length(LineEnd));
+            Node:=tstringListItem(Node.Next);
+          end;
+      end;
+
+
 {****************************************************************************
 {****************************************************************************
                                TNamedIndexItem
                                TNamedIndexItem
  ****************************************************************************}
  ****************************************************************************}
@@ -1253,8 +1374,6 @@ end;
         Fright:=nil;
         Fright:=nil;
         FName:=nil;
         FName:=nil;
         Fspeedvalue:=cardinal($ffffffff);
         Fspeedvalue:=cardinal($ffffffff);
-        { List }
-        FListNext:=nil;
       end;
       end;
 
 
     constructor TNamedIndexItem.Createname(const n:string);
     constructor TNamedIndexItem.Createname(const n:string);
@@ -1271,8 +1390,6 @@ end;
       {$else}
       {$else}
         FName:=stringdup(n);
         FName:=stringdup(n);
       {$endif}
       {$endif}
-        { List }
-        FListNext:=nil;
       end;
       end;
 
 
 
 
@@ -1869,51 +1986,6 @@ end;
         speedsearch:=nil;
         speedsearch:=nil;
       end;
       end;
 
 
-{****************************************************************************
-                               tsingleList
- ****************************************************************************}
-
-    constructor tsingleList.create;
-      begin
-        First:=nil;
-        last:=nil;
-      end;
-
-
-    procedure tsingleList.reset;
-      begin
-        First:=nil;
-        last:=nil;
-      end;
-
-
-    procedure tsingleList.clear;
-      var
-        hp,hp2 : TNamedIndexItem;
-      begin
-        hp:=First;
-        while assigned(hp) do
-         begin
-           hp2:=hp;
-           hp:=hp.FListNext;
-           hp2.free;
-         end;
-        First:=nil;
-        last:=nil;
-      end;
-
-
-    procedure tsingleList.insert(p:TNamedIndexItem);
-      begin
-        if not assigned(First) then
-         First:=p
-        else
-         last.FListNext:=p;
-        last:=p;
-        p.FListNext:=nil;
-      end;
-
-
 {****************************************************************************
 {****************************************************************************
                                tindexarray
                                tindexarray
  ****************************************************************************}
  ****************************************************************************}

+ 1 - 1
compiler/cgobj.pas

@@ -1718,7 +1718,7 @@ implementation
               { are valid for the todef                                      }
               { are valid for the todef                                      }
               begin
               begin
 {$ifopt Q+}
 {$ifopt Q+}
-{$defined overflowon}
+{$define overflowon}
 {$Q-}
 {$Q-}
 {$endif}
 {$endif}
                 if to_signed then
                 if to_signed then

+ 3 - 0
compiler/comphook.pas

@@ -31,6 +31,7 @@ uses
 {$ELSE}
 {$ELSE}
   globals,
   globals,
 {$ENDIF}
 {$ENDIF}
+  globtype,
   finput;
   finput;
 
 
 Const
 Const
@@ -77,6 +78,8 @@ type
   { Total Status }
   { Total Status }
     compiledlines : longint;  { the number of lines which are compiled }
     compiledlines : longint;  { the number of lines which are compiled }
     errorcount    : longint;  { number of generated errors }
     errorcount    : longint;  { number of generated errors }
+    codesize,
+    datasize      : aint;
   { program info }
   { program info }
     isexe,
     isexe,
     islibrary     : boolean;
     islibrary     : boolean;

+ 10 - 4
compiler/compiler.pas

@@ -64,14 +64,14 @@ unit compiler;
      {$fatal cannot define two CPU switches}
      {$fatal cannot define two CPU switches}
    {$endif}
    {$endif}
    {$endif}
    {$endif}
-   
+
    {$ifdef POWERPC64}
    {$ifdef POWERPC64}
    {$ifndef CPUOK}
    {$ifndef CPUOK}
    {$DEFINE CPUOK}
    {$DEFINE CPUOK}
    {$else}
    {$else}
      {$fatal cannot define two CPU switches}
      {$fatal cannot define two CPU switches}
    {$endif}
    {$endif}
-   {$endif}   
+   {$endif}
 
 
    {$ifdef ia64}
    {$ifdef ia64}
    {$ifndef CPUOK}
    {$ifndef CPUOK}
@@ -345,6 +345,8 @@ function Compile(const cmd:string):longint;
 
 
 var
 var
   starttime  : real;
   starttime  : real;
+  timestr    : string[20];
+  linkstr    : string[64];
 {$ifdef SHOWUSEDMEM}
 {$ifdef SHOWUSEDMEM}
   hstatus : TFPCHeapStatus;
   hstatus : TFPCHeapStatus;
 {$endif SHOWUSEDMEM}
 {$endif SHOWUSEDMEM}
@@ -380,8 +382,12 @@ begin
           starttime:=getrealtime-starttime;
           starttime:=getrealtime-starttime;
           if starttime<0 then
           if starttime<0 then
             starttime:=starttime+3600.0*24.0;
             starttime:=starttime+3600.0*24.0;
-          Message2(general_i_abslines_compiled,tostr(status.compiledlines),tostr(trunc(starttime))+
-            '.'+tostr(trunc(frac(starttime)*10)));
+          timestr:=tostr(trunc(starttime))+'.'+tostr(trunc(frac(starttime)*10));
+          if status.codesize<>-1 then
+            linkstr:=', '+tostr(status.codesize)+' bytes code, '+tostr(status.datasize)+' bytes data'
+          else
+            linkstr:='';
+          Message3(general_i_abslines_compiled,tostr(status.compiledlines),timestr,linkstr);
         end;
         end;
      finally
      finally
        { no message possible after this !!    }
        { no message possible after this !!    }

+ 5 - 0
compiler/cstreams.pas

@@ -349,6 +349,8 @@ implementation
 {****************************************************************************}
 {****************************************************************************}
 
 
 constructor TCFileStream.Create(const AFileName: string; Mode: Word);
 constructor TCFileStream.Create(const AFileName: string; Mode: Word);
+var
+  oldfilemode : byte;
 begin
 begin
   FFileName:=AFileName;
   FFileName:=AFileName;
   If Mode=fmcreate then
   If Mode=fmcreate then
@@ -361,11 +363,14 @@ begin
     end
     end
   else
   else
     begin
     begin
+      oldfilemode:=filemode;
+      filemode:=$40 or Mode;
       system.assign(FHandle,AFileName);
       system.assign(FHandle,AFileName);
       {$I-}
       {$I-}
        system.reset(FHandle,1);
        system.reset(FHandle,1);
       {$I+}
       {$I+}
       CStreamError:=IOResult;
       CStreamError:=IOResult;
+      filemode:=oldfilemode;
     end;
     end;
 end;
 end;
 
 

+ 4 - 4
compiler/cutils.pas

@@ -53,8 +53,8 @@ interface
     {# Return value @var(i) aligned on @var(a) boundary }
     {# Return value @var(i) aligned on @var(a) boundary }
     function align(i,a:longint):longint;{$ifdef USEINLINE}inline;{$endif}
     function align(i,a:longint):longint;{$ifdef USEINLINE}inline;{$endif}
 
 
-    function used_align(varalign,minalign,maxalign:longint):longint;
-    function size_2_align(len : longint) : longint;
+    function used_align(varalign,minalign,maxalign:shortint):shortint;
+    function size_2_align(len : longint) : shortint;
     procedure Replace(var s:string;s1:string;const s2:string);
     procedure Replace(var s:string;s1:string;const s2:string);
     procedure Replace(var s:AnsiString;s1:string;const s2:string);
     procedure Replace(var s:AnsiString;s1:string;const s2:string);
     procedure ReplaceCase(var s:string;const s1,s2:string);
     procedure ReplaceCase(var s:string;const s1,s2:string);
@@ -240,7 +240,7 @@ uses
       end;
       end;
 
 
 
 
-    function size_2_align(len : longint) : longint;
+    function size_2_align(len : longint) : shortint;
       begin
       begin
          if len>16 then
          if len>16 then
            size_2_align:=32
            size_2_align:=32
@@ -257,7 +257,7 @@ uses
       end;
       end;
 
 
 
 
-    function used_align(varalign,minalign,maxalign:longint):longint;
+    function used_align(varalign,minalign,maxalign:shortint):shortint;
       begin
       begin
         { varalign  : minimum alignment required for the variable
         { varalign  : minimum alignment required for the variable
           minalign  : Minimum alignment of this structure, 0 = undefined
           minalign  : Minimum alignment of this structure, 0 = undefined

+ 1 - 1
compiler/dbgdwarf.pas

@@ -1987,7 +1987,7 @@ implementation
         currfileinfo,
         currfileinfo,
         lastfileinfo : tfileposinfo;
         lastfileinfo : tfileposinfo;
         currfuncname : pstring;
         currfuncname : pstring;
-        currsectype  : tasmsectiontype;
+        currsectype  : TAsmSectiontype;
         hlabel       : tasmlabel;
         hlabel       : tasmlabel;
         hp : tai;
         hp : tai;
         infile : tinputfile;
         infile : tinputfile;

+ 1 - 1
compiler/dbgstabs.pas

@@ -1386,7 +1386,7 @@ implementation
         currfileinfo,
         currfileinfo,
         lastfileinfo : tfileposinfo;
         lastfileinfo : tfileposinfo;
         currfuncname : pstring;
         currfuncname : pstring;
-        currsectype  : tasmsectiontype;
+        currsectype  : TAsmSectiontype;
         hlabel       : tasmlabel;
         hlabel       : tasmlabel;
         hp : tai;
         hp : tai;
         infile : tinputfile;
         infile : tinputfile;

+ 9 - 6
compiler/fmodule.pas

@@ -154,7 +154,7 @@ interface
         locallibrarysearchpath : TSearchPathList;
         locallibrarysearchpath : TSearchPathList;
 
 
         asmprefix     : pstring;  { prefix for the smartlink asmfiles }
         asmprefix     : pstring;  { prefix for the smartlink asmfiles }
-        librarydata   : tasmlibrarydata;   { librarydata for this module }
+        librarydata   : TObjLibraryData;   { librarydata for this module }
         {create creates a new module which name is stored in 's'. LoadedFrom
         {create creates a new module which name is stored in 's'. LoadedFrom
         points to the module calling it. It is nil for the first compiled
         points to the module calling it. It is nil for the first compiled
         module. This allow inheritence of all path lists. MUST pay attention
         module. This allow inheritence of all path lists. MUST pay attention
@@ -454,7 +454,7 @@ implementation
         imports:=TLinkedList.Create;
         imports:=TLinkedList.Create;
         _exports:=TLinkedList.Create;
         _exports:=TLinkedList.Create;
         externals:=TLinkedList.Create;
         externals:=TLinkedList.Create;
-        librarydata:=tasmlibrarydata.create(realmodulename^);
+        librarydata:=TObjLibraryData.create(realmodulename^);
       end;
       end;
 
 
 
 
@@ -540,13 +540,16 @@ implementation
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
         d.free;
         d.free;
 {$endif}
 {$endif}
+        if assigned(librarydata) then
+          begin
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
-        d:=tmemdebug.create(modulename^+' - librarydata');
+            d:=tmemdebug.create(modulename^+' - librarydata');
 {$endif}
 {$endif}
-        librarydata.free;
+            librarydata.free;
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
-        d.free;
+            d.free;
 {$endif}
 {$endif}
+          end;
         stringdispose(modulename);
         stringdispose(modulename);
         inherited Destroy;
         inherited Destroy;
       end;
       end;
@@ -619,7 +622,7 @@ implementation
         sourcefiles.free;
         sourcefiles.free;
         sourcefiles:=tinputfilemanager.create;
         sourcefiles:=tinputfilemanager.create;
         librarydata.free;
         librarydata.free;
-        librarydata:=tasmlibrarydata.create(realmodulename^);
+        librarydata:=TObjLibraryData.create(realmodulename^);
         imports.free;
         imports.free;
         imports:=tlinkedlist.create;
         imports:=tlinkedlist.create;
         _exports.free;
         _exports.free;

+ 4 - 1
compiler/fpcdefs.inc

@@ -71,7 +71,7 @@
   {$define cpu64bit}
   {$define cpu64bit}
   {$define cpuflags}
   {$define cpuflags}
   {$define cputargethasfixedstack}
   {$define cputargethasfixedstack}
-  {$define cpumm}  
+  {$define cpumm}
   {$define cpurequiresproperalignment}
   {$define cpurequiresproperalignment}
 {$endif powerpc64}
 {$endif powerpc64}
 
 
@@ -91,3 +91,6 @@
 {$IFDEF MACOS}
 {$IFDEF MACOS}
 {$DEFINE MACOS_USE_FAKE_SYSUTILS}
 {$DEFINE MACOS_USE_FAKE_SYSUTILS}
 {$ENDIF MACOS}
 {$ENDIF MACOS}
+
+{ Use the internal linker by default }
+{ define INTERNALLINKER}

+ 3 - 100
compiler/fppu.pas

@@ -68,14 +68,11 @@ interface
           procedure writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
           procedure writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
           procedure writederefmap;
           procedure writederefmap;
           procedure writederefdata;
           procedure writederefdata;
-          procedure putasmsymbol_in_idx(s:tnamedindexitem;arg:pointer);
-          procedure writeasmsymbols;
           procedure readsourcefiles;
           procedure readsourcefiles;
           procedure readloadunit;
           procedure readloadunit;
           procedure readlinkcontainer(var p:tlinkcontainer);
           procedure readlinkcontainer(var p:tlinkcontainer);
           procedure readderefmap;
           procedure readderefmap;
           procedure readderefdata;
           procedure readderefdata;
-          procedure readasmsymbols;
 {$IFDEF MACRO_DIFF_HINT}
 {$IFDEF MACRO_DIFF_HINT}
           procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
           procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
           procedure writeusedmacros;
           procedure writeusedmacros;
@@ -571,52 +568,6 @@ uses
         ppufile.writeentry(ibderefdata);
         ppufile.writeentry(ibderefdata);
       end;
       end;
 
 
-
-    procedure tppumodule.putasmsymbol_in_idx(s:tnamedindexitem;arg:pointer);
-      begin
-        if tasmsymbol(s).ppuidx<>-1 then
-         librarydata.asmsymbolidx^[tasmsymbol(s).ppuidx-1]:=tasmsymbol(s);
-      end;
-
-
-    procedure tppumodule.writeasmsymbols;
-      var
-        s : tasmsymbol;
-        i : longint;
-        asmsymtype : byte;
-      begin
-        { get an ordered list of all symbols to put in the ppu }
-        getmem(librarydata.asmsymbolidx,librarydata.asmsymbolppuidx*sizeof(pointer));
-        fillchar(librarydata.asmsymbolidx^,librarydata.asmsymbolppuidx*sizeof(pointer),0);
-        librarydata.symbolsearch.foreach(@putasmsymbol_in_idx,nil);
-        { write the number of symbols }
-        ppufile.putlongint(librarydata.asmsymbolppuidx);
-        { write the symbols from the indexed list to the ppu }
-        for i:=1 to librarydata.asmsymbolppuidx do
-         begin
-           s:=librarydata.asmsymbolidx^[i-1];
-           if not assigned(s) then
-            internalerror(200208071);
-           if s.Classtype=tasmlabel then
-             asmsymtype:=2
-           else
-             asmsymtype:=1;
-           ppufile.putbyte(asmsymtype);
-           case asmsymtype of
-             1 :
-               ppufile.putstring(s.name);
-             2 :
-               begin
-                 ppufile.putbyte(byte(tasmlabel(s).labeltype));
-                 ppufile.putlongint(tasmlabel(s).labelnr);
-               end;
-           end;
-           ppufile.putbyte(byte(s.defbind));
-           ppufile.putbyte(byte(s.typ));
-         end;
-        ppufile.writeentry(ibasmsymbols);
-      end;
-
 {$IFDEF MACRO_DIFF_HINT}
 {$IFDEF MACRO_DIFF_HINT}
 
 
 {
 {
@@ -848,48 +799,6 @@ uses
       end;
       end;
 
 
 
 
-    procedure tppumodule.readasmsymbols;
-      var
-        labelnr,
-        i     : longint;
-        name  : string;
-        labeltype : tasmlabeltype;
-        bind  : TAsmSymBind;
-        typ   : TAsmSymType;
-        asmsymtype : byte;
-      begin
-        librarydata.asmsymbolppuidx:=ppufile.getlongint;
-        if librarydata.asmsymbolppuidx>0 then
-         begin
-           getmem(librarydata.asmsymbolidx,librarydata.asmsymbolppuidx*sizeof(pointer));
-           fillchar(librarydata.asmsymbolidx^,librarydata.asmsymbolppuidx*sizeof(pointer),0);
-           for i:=1 to librarydata.asmsymbolppuidx do
-            begin
-              asmsymtype:=ppufile.getbyte;
-              case asmsymtype of
-                1 :
-                  name:=ppufile.getstring;
-                2 :
-                  begin
-                    labeltype:=tasmlabeltype(ppufile.getbyte);
-                    labelnr:=ppufile.getlongint;
-                  end;
-                else
-                  internalerror(200208192);
-              end;
-              bind:=tasmsymbind(ppufile.getbyte);
-              typ:=tasmsymtype(ppufile.getbyte);
-              case asmsymtype of
-                1 :
-                 librarydata.asmsymbolidx^[i-1]:=librarydata.newasmsymbol(name,bind,typ);
-                2 :
-                 librarydata.asmsymbolidx^[i-1]:=librarydata.newasmlabel(labelnr,labeltype,(typ=AT_DATA));
-              end;
-            end;
-         end;
-      end;
-
-
     procedure tppumodule.load_interface;
     procedure tppumodule.load_interface;
       var
       var
         b : byte;
         b : byte;
@@ -959,7 +868,8 @@ uses
              ibloadunit :
              ibloadunit :
                readloadunit;
                readloadunit;
              ibasmsymbols :
              ibasmsymbols :
-               readasmsymbols;
+{$warning TODO Remove ibasmsymbols}
+               ;
              ibendimplementation :
              ibendimplementation :
                break;
                break;
            else
            else
@@ -1082,9 +992,6 @@ uses
          { write implementation uses }
          { write implementation uses }
          writeusedunit(false);
          writeusedunit(false);
 
 
-         { write asmsymbols }
-         writeasmsymbols;
-
          { end of implementation }
          { end of implementation }
          ppufile.writeentry(ibendimplementation);
          ppufile.writeentry(ibendimplementation);
 
 
@@ -1226,7 +1133,6 @@ uses
       var
       var
         pu           : tused_unit;
         pu           : tused_unit;
         load_refs    : boolean;
         load_refs    : boolean;
-        oldobjectlibrary : tasmlibrarydata;
       begin
       begin
         if current_module<>self then
         if current_module<>self then
          internalerror(200212284);
          internalerror(200212284);
@@ -1280,7 +1186,7 @@ uses
         interface_compiled:=true;
         interface_compiled:=true;
 
 
         { read the implementation part, containing
         { read the implementation part, containing
-          the implementation uses and objectdata }
+          the implementation uses and ObjData }
         in_interface:=false;
         in_interface:=false;
         load_implementation;
         load_implementation;
 
 
@@ -1316,12 +1222,9 @@ uses
           end;
           end;
 
 
         { we can now derefence all pointers to the implementation parts }
         { we can now derefence all pointers to the implementation parts }
-        oldobjectlibrary:=objectlibrary;
-        objectlibrary:=librarydata;
         tstoredsymtable(globalsymtable).derefimpl;
         tstoredsymtable(globalsymtable).derefimpl;
         if assigned(localsymtable) then
         if assigned(localsymtable) then
           tstoredsymtable(localsymtable).derefimpl;
           tstoredsymtable(localsymtable).derefimpl;
-        objectlibrary:=oldobjectlibrary;
 
 
         { load browser info if stored }
         { load browser info if stored }
         if ((flags and uf_has_browser)<>0) and load_refs then
         if ((flags and uf_has_browser)<>0) and load_refs then

+ 1 - 3
compiler/globals.pas

@@ -23,9 +23,6 @@ unit globals;
 
 
 {$i fpcdefs.inc}
 {$i fpcdefs.inc}
 
 
-{ Use the internal linker by default }
-{ define INTERNALLINKER}
-
 interface
 interface
 
 
     uses
     uses
@@ -182,6 +179,7 @@ interface
        UseDeffileForExports    : boolean;
        UseDeffileForExports    : boolean;
        UseDeffileForExportsSetExplicitly : boolean;
        UseDeffileForExportsSetExplicitly : boolean;
        GenerateImportSection,
        GenerateImportSection,
+       GenerateImportSectionSetExplicitly,
        RelocSection : boolean;
        RelocSection : boolean;
        RelocSectionSetExplicitly : boolean;
        RelocSectionSetExplicitly : boolean;
        LinkTypeSetExplicitly : boolean;
        LinkTypeSetExplicitly : boolean;

+ 14 - 11
compiler/i386/ag386nsm.pas

@@ -36,7 +36,7 @@ interface
         procedure WriteReference(var ref : treference);
         procedure WriteReference(var ref : treference);
         procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
         procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
         procedure WriteOper_jmp(const o:toper; op : tasmop);
         procedure WriteOper_jmp(const o:toper; op : tasmop);
-        procedure WriteSection(atype:tasmsectiontype;const aname:string);
+        procedure WriteSection(atype:TAsmSectiontype;const aname:string);
       public
       public
         procedure WriteTree(p:taasmoutput);override;
         procedure WriteTree(p:taasmoutput);override;
         procedure WriteAsmList;override;
         procedure WriteAsmList;override;
@@ -343,7 +343,7 @@ interface
 
 
 
 
     var
     var
-      LastSecType : TAsmSectionType;
+      LastSecType : TAsmSectiontype;
 
 
     const
     const
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
@@ -352,14 +352,17 @@ interface
         #9'RVA'#9,#9'FIXMEINDIRECT'#9
         #9'RVA'#9,#9'FIXMEINDIRECT'#9
       );
       );
 
 
-    procedure T386NasmAssembler.WriteSection(atype:tasmsectiontype;const aname:string);
+    procedure T386NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
       const
       const
-        secnames : array[tasmsectiontype] of string[13] = ('',
-          '.text','.data','.rodata','.bss','.tbss',
-          'common',
-          '.note',
+        secnames : array[TAsmSectiontype] of string[13] = ('',
           '.text',
           '.text',
-          '.stab','.stabstr',
+          '.data',
+          '.rodata',
+          '.bss',
+          '.tbss',
+          '.text',
+          '.stab',
+          '.stabstr',
           '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
           '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
           '.eh_frame',
           '.eh_frame',
           '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
           '.debug_frame','.debug_info','.debug_line','.debug_abbrev',
@@ -645,8 +648,8 @@ interface
 
 
            ait_label :
            ait_label :
              begin
              begin
-               if tai_label(hp).l.is_used then
-                AsmWriteLn(tai_label(hp).l.name+':');
+               if tai_label(hp).labsym.is_used then
+                AsmWriteLn(tai_label(hp).labsym.name+':');
              end;
              end;
 
 
            ait_symbol :
            ait_symbol :
@@ -779,7 +782,7 @@ interface
 
 
     procedure writeexternal(p:tnamedindexitem;arg:pointer);
     procedure writeexternal(p:tnamedindexitem;arg:pointer);
       begin
       begin
-        if tasmsymbol(p).defbind=AB_EXTERNAL then
+        if tasmsymbol(p).bind=AB_EXTERNAL then
          currentasmlist.AsmWriteln('EXTERN'#9+p.name);
          currentasmlist.AsmWriteln('EXTERN'#9+p.name);
       end;
       end;
 
 

+ 20 - 20
compiler/i386/daopt386.pas

@@ -507,7 +507,7 @@ begin
   while assigned(p) and
   while assigned(p) and
        (p.typ in SkipInstr + [ait_label,ait_align]) Do
        (p.typ in SkipInstr + [ait_label,ait_align]) Do
     if (p.typ <> ait_Label) or
     if (p.typ <> ait_Label) or
-       (tai_label(p).l <> l) then
+       (tai_label(p).labsym <> l) then
       GetNextInstruction(p, p)
       GetNextInstruction(p, p)
     else
     else
        begin
        begin
@@ -1090,7 +1090,7 @@ end;
 
 
 function labelCanBeSkipped(p: tai_label): boolean;
 function labelCanBeSkipped(p: tai_label): boolean;
 begin
 begin
-  labelCanBeSkipped := not(p.l.is_used) or (p.l.labeltype<>alt_jump);
+  labelCanBeSkipped := not(p.labsym.is_used) or (p.labsym.labeltype<>alt_jump);
 end;
 end;
 
 
 {******************* The Data Flow Analyzer functions ********************}
 {******************* The Data Flow Analyzer functions ********************}
@@ -1232,7 +1232,7 @@ begin
       if firstRemovedWasAlloc then
       if firstRemovedWasAlloc then
         begin
         begin
           hp := tai_regalloc.Alloc(reg,nil);
           hp := tai_regalloc.Alloc(reg,nil);
-          insertLLItem(asmL,start.previous,start,hp);        
+          insertLLItem(asmL,start.previous,start,hp);
         end;
         end;
       if lastRemovedWasDealloc then
       if lastRemovedWasDealloc then
         begin
         begin
@@ -2057,10 +2057,10 @@ begin
         if not labelcanbeskipped(tai_label(p)) then
         if not labelcanbeskipped(tai_label(p)) then
           begin
           begin
             labelfound := true;
             labelfound := true;
-             if (tai_Label(p).l.labelnr < lolab) then
-               lolab := tai_label(p).l.labelnr;
-             if (tai_Label(p).l.labelnr > hilab) then
-               hilab := tai_label(p).l.labelnr;
+             if (tai_Label(p).labsym.labelnr < lolab) then
+               lolab := tai_label(p).labsym.labelnr;
+             if (tai_Label(p).labsym.labelnr > hilab) then
+               hilab := tai_label(p).labsym.labelnr;
           end;
           end;
       prev := p;
       prev := p;
       getnextinstruction(p, p);
       getnextinstruction(p, p);
@@ -2086,7 +2086,7 @@ begin
       case p.typ of
       case p.typ of
         ait_label:
         ait_label:
           if not labelcanbeskipped(tai_label(p)) then
           if not labelcanbeskipped(tai_label(p)) then
-            labeltable^[tai_label(p).l.labelnr-lolab].taiobj := p;
+            labeltable^[tai_label(p).labsym.labelnr-lolab].taiobj := p;
 {$ifdef i386}
 {$ifdef i386}
         ait_regalloc:
         ait_regalloc:
           begin
           begin
@@ -2182,15 +2182,15 @@ begin
         ait_label:
         ait_label:
           begin
           begin
             if not labelcanbeskipped(tai_label(p)) then
             if not labelcanbeskipped(tai_label(p)) then
-              labeltable^[tai_label(p).l.labelnr-lolab].instrnr := nroftaiobjs
+              labeltable^[tai_label(p).labsym.labelnr-lolab].instrnr := nroftaiobjs
           end;
           end;
         ait_instruction:
         ait_instruction:
           begin
           begin
             if taicpu(p).is_jmp then
             if taicpu(p).is_jmp then
              begin
              begin
-               if (tasmlabel(taicpu(p).oper[0]^.sym).labelnr >= lolab) and
-                  (tasmlabel(taicpu(p).oper[0]^.sym).labelnr <= hilab) then
-                 inc(labeltable^[tasmlabel(taicpu(p).oper[0]^.sym).labelnr-lolab].refsfound);
+               if (tasmlabel(taicpu(p).oper[0]^.sym).labsymabelnr >= lolab) and
+                  (tasmlabel(taicpu(p).oper[0]^.sym).labsymabelnr <= hilab) then
+                 inc(labeltable^[tasmlabel(taicpu(p).oper[0]^.sym).labsymabelnr-lolab].refsfound);
              end;
              end;
           end;
           end;
 {        ait_instruction:
 {        ait_instruction:
@@ -2294,11 +2294,11 @@ begin
 {$else JumpAnal}
 {$else JumpAnal}
           begin
           begin
            if not labelCanBeSkipped(tai_label(p)) then
            if not labelCanBeSkipped(tai_label(p)) then
-             With LTable^[tai_Label(p).l^.labelnr-LoLab] Do
+             With LTable^[tai_Label(p).labsym^.labelnr-LoLab] Do
 {$ifDef AnalyzeLoops}
 {$ifDef AnalyzeLoops}
-              if (RefsFound = tai_Label(p).l^.RefCount)
+              if (RefsFound = tai_Label(p).labsym^.RefCount)
 {$else AnalyzeLoops}
 {$else AnalyzeLoops}
-              if (JmpsProcessed = tai_Label(p).l^.RefCount)
+              if (JmpsProcessed = tai_Label(p).labsym^.RefCount)
 {$endif AnalyzeLoops}
 {$endif AnalyzeLoops}
                 then
                 then
 {all jumps to this label have been found}
 {all jumps to this label have been found}
@@ -2345,11 +2345,11 @@ begin
                             while GetNextInstruction(hp, hp) and
                             while GetNextInstruction(hp, hp) and
                                   not((hp.typ = ait_instruction) and
                                   not((hp.typ = ait_instruction) and
                                       (taicpu(hp).is_jmp) and
                                       (taicpu(hp).is_jmp) and
-                                      (tasmlabel(taicpu(hp).oper[0]^.sym).labelnr = tai_Label(p).l^.labelnr)) and
+                                      (tasmlabel(taicpu(hp).oper[0]^.sym).labsymabelnr = tai_Label(p).labsym^.labelnr)) and
                                   not((hp.typ = ait_label) and
                                   not((hp.typ = ait_label) and
-                                      (LTable^[tai_Label(hp).l^.labelnr-LoLab].RefsFound
-                                       = tai_Label(hp).l^.RefCount) and
-                                      (LTable^[tai_Label(hp).l^.labelnr-LoLab].JmpsProcessed > 0)) Do
+                                      (LTable^[tai_Label(hp).labsym^.labelnr-LoLab].RefsFound
+                                       = tai_Label(hp).labsym^.RefCount) and
+                                      (LTable^[tai_Label(hp).labsym^.labelnr-LoLab].JmpsProcessed > 0)) Do
                               inc(Cnt);
                               inc(Cnt);
                             if (hp.typ = ait_label)
                             if (hp.typ = ait_label)
                               then
                               then
@@ -2396,7 +2396,7 @@ begin
                       con_invalid: typ := con_unknown;
                       con_invalid: typ := con_unknown;
                     end;
                     end;
 {$else JumpAnal}
 {$else JumpAnal}
-          With LTable^[tasmlabel(taicpu(p).oper[0]^.sym).labelnr-LoLab] Do
+          With LTable^[tasmlabel(taicpu(p).oper[0]^.sym).labsymabelnr-LoLab] Do
             if (RefsFound = tasmlabel(taicpu(p).oper[0]^.sym).RefCount) then
             if (RefsFound = tasmlabel(taicpu(p).oper[0]^.sym).RefCount) then
               begin
               begin
                 if (InstrCnt < InstrNr)
                 if (InstrCnt < InstrNr)

+ 58 - 58
compiler/i386/popt386.pas

@@ -342,13 +342,13 @@ begin
                     shl     const2, %reg
                     shl     const2, %reg
                     with const1 > const2 }
                     with const1 > const2 }
                       begin
                       begin
-                        taicpu(p).LoadConst(0,taicpu(p).oper[0]^.val-taicpu(hp1).oper[0]^.val);
+                        taicpu(p).loadConst(0,taicpu(p).oper[0]^.val-taicpu(hp1).oper[0]^.val);
                         taicpu(hp1).opcode := A_AND;
                         taicpu(hp1).opcode := A_AND;
                         l := (1 shl (taicpu(hp1).oper[0]^.val)) - 1;
                         l := (1 shl (taicpu(hp1).oper[0]^.val)) - 1;
                         case taicpu(p).opsize Of
                         case taicpu(p).opsize Of
-                          S_L: taicpu(hp1).LoadConst(0,l Xor aint($ffffffff));
-                          S_B: taicpu(hp1).LoadConst(0,l Xor $ff);
-                          S_W: taicpu(hp1).LoadConst(0,l Xor $ffff);
+                          S_L: taicpu(hp1).loadConst(0,l Xor aint($ffffffff));
+                          S_B: taicpu(hp1).loadConst(0,l Xor $ff);
+                          S_W: taicpu(hp1).loadConst(0,l Xor $ffff);
                         end;
                         end;
                       end
                       end
                     else if (taicpu(p).oper[0]^.val<taicpu(hp1).oper[0]^.val) and
                     else if (taicpu(p).oper[0]^.val<taicpu(hp1).oper[0]^.val) and
@@ -357,13 +357,13 @@ begin
                     shl     const2, %reg
                     shl     const2, %reg
                     with const1 < const2 }
                     with const1 < const2 }
                       begin
                       begin
-                        taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val-taicpu(p).oper[0]^.val);
+                        taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val-taicpu(p).oper[0]^.val);
                         taicpu(p).opcode := A_AND;
                         taicpu(p).opcode := A_AND;
                         l := (1 shl (taicpu(p).oper[0]^.val))-1;
                         l := (1 shl (taicpu(p).oper[0]^.val))-1;
                         case taicpu(p).opsize Of
                         case taicpu(p).opsize Of
-                          S_L: taicpu(p).LoadConst(0,l Xor aint($ffffffff));
-                          S_B: taicpu(p).LoadConst(0,l Xor $ff);
-                          S_W: taicpu(p).LoadConst(0,l Xor $ffff);
+                          S_L: taicpu(p).loadConst(0,l Xor aint($ffffffff));
+                          S_B: taicpu(p).loadConst(0,l Xor $ff);
+                          S_W: taicpu(p).loadConst(0,l Xor $ffff);
                         end;
                         end;
                       end
                       end
                     else
                     else
@@ -375,9 +375,9 @@ begin
                           taicpu(p).opcode := A_AND;
                           taicpu(p).opcode := A_AND;
                           l := (1 shl (taicpu(p).oper[0]^.val))-1;
                           l := (1 shl (taicpu(p).oper[0]^.val))-1;
                           case taicpu(p).opsize Of
                           case taicpu(p).opsize Of
-                            S_B: taicpu(p).LoadConst(0,l Xor $ff);
-                            S_W: taicpu(p).LoadConst(0,l Xor $ffff);
-                            S_L: taicpu(p).LoadConst(0,l Xor aint($ffffffff));
+                            S_B: taicpu(p).loadConst(0,l Xor $ff);
+                            S_W: taicpu(p).loadConst(0,l Xor $ffff);
+                            S_L: taicpu(p).loadConst(0,l Xor aint($ffffffff));
                           end;
                           end;
                           asml.remove(hp1);
                           asml.remove(hp1);
                           hp1.free;
                           hp1.free;
@@ -391,7 +391,7 @@ begin
                  { for the CSE. Will be changed back in pass 2              }
                  { for the CSE. Will be changed back in pass 2              }
                   begin
                   begin
                     taicpu(p).opcode := A_MOV;
                     taicpu(p).opcode := A_MOV;
-                    taicpu(p).loadconst(0,0);
+                    taicpu(p).loadConst(0,0);
                   end;
                   end;
             end;
             end;
           end;
           end;
@@ -461,7 +461,7 @@ var
          (tai(hp.next).typ = ait_label) then
          (tai(hp.next).typ = ait_label) then
         begin
         begin
           FindAnyLabel := true;
           FindAnyLabel := true;
-          l := tai_label(hp.next).l;
+          l := tai_label(hp.next).labsym;
         end
         end
     end;
     end;
 
 
@@ -544,7 +544,7 @@ var
           if (taicpu(hp1).oper[0]^.typ = top_reg) and
           if (taicpu(hp1).oper[0]^.typ = top_reg) and
              (taicpu(hp1).oper[0]^.reg = taicpu(p).oper[1]^.reg) then
              (taicpu(hp1).oper[0]^.reg = taicpu(p).oper[1]^.reg) then
             begin
             begin
-              taicpu(p).LoadConst(0,taicpu(p).oper[0]^.val+1);
+              taicpu(p).loadConst(0,taicpu(p).oper[0]^.val+1);
               asml.remove(hp1);
               asml.remove(hp1);
               hp1.free;
               hp1.free;
             end;
             end;
@@ -553,7 +553,7 @@ var
               (taicpu(hp1).oper[1]^.typ = top_reg) and
               (taicpu(hp1).oper[1]^.typ = top_reg) and
               (taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) then
               (taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) then
              begin
              begin
-               taicpu(p).LoadConst(0,taicpu(p).oper[0]^.val+taicpu(hp1).oper[0]^.val);
+               taicpu(p).loadConst(0,taicpu(p).oper[0]^.val+taicpu(hp1).oper[0]^.val);
                asml.remove(hp1);
                asml.remove(hp1);
                hp1.free;
                hp1.free;
              end;
              end;
@@ -562,7 +562,7 @@ var
               (taicpu(hp1).oper[1]^.typ = top_reg) and
               (taicpu(hp1).oper[1]^.typ = top_reg) and
               (taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) then
               (taicpu(hp1).oper[1]^.reg = taicpu(p).oper[1]^.reg) then
              begin
              begin
-               taicpu(p).LoadConst(0,taicpu(p).oper[0]^.val-taicpu(hp1).oper[0]^.val);
+               taicpu(p).loadConst(0,taicpu(p).oper[0]^.val-taicpu(hp1).oper[0]^.val);
                asml.remove(hp1);
                asml.remove(hp1);
                hp1.free;
                hp1.free;
                if (taicpu(p).oper[0]^.val = 0) then
                if (taicpu(p).oper[0]^.val = 0) then
@@ -628,7 +628,7 @@ begin
                             if taicpu(p).opcode=A_Jcc then
                             if taicpu(p).opcode=A_Jcc then
                               begin
                               begin
                                 taicpu(p).condition:=inverse_cond(taicpu(p).condition);
                                 taicpu(p).condition:=inverse_cond(taicpu(p).condition);
-                                tai_label(hp2).l.decrefs;
+                                tai_label(hp2).labsym.decrefs;
                                 taicpu(p).oper[0]^.ref^.symbol:=taicpu(hp1).oper[0]^.ref^.symbol;
                                 taicpu(p).oper[0]^.ref^.symbol:=taicpu(hp1).oper[0]^.ref^.symbol;
                                 { when free'ing hp1, the ref. isn't decresed, so we don't
                                 { when free'ing hp1, the ref. isn't decresed, so we don't
                                   increase it (FK)
                                   increase it (FK)
@@ -679,7 +679,7 @@ begin
                          (taicpu(p).oper[1]^.reg = taicpu(hp1).oper[1]^.reg) then
                          (taicpu(p).oper[1]^.reg = taicpu(hp1).oper[1]^.reg) then
     {change "and const1, reg; and const2, reg" to "and (const1 and const2), reg"}
     {change "and const1, reg; and const2, reg" to "and (const1 and const2), reg"}
                         begin
                         begin
-                          taicpu(p).LoadConst(0,taicpu(p).oper[0]^.val and taicpu(hp1).oper[0]^.val);
+                          taicpu(p).loadConst(0,taicpu(p).oper[0]^.val and taicpu(hp1).oper[0]^.val);
                           asml.remove(hp1);
                           asml.remove(hp1);
                           hp1.free;
                           hp1.free;
                         end
                         end
@@ -705,7 +705,7 @@ begin
                         S_W: v:=$8000;
                         S_W: v:=$8000;
                         S_L: v:=aint($80000000);
                         S_L: v:=aint($80000000);
                       end;
                       end;
-                      if (taicpu(p).oper[0]^.typ=Top_const) and 
+                      if (taicpu(p).oper[0]^.typ=Top_const) and
                          (taicpu(p).oper[0]^.val=v) and
                          (taicpu(p).oper[0]^.val=v) and
                          (Taicpu(p).oper[1]^.typ=top_reg) and
                          (Taicpu(p).oper[1]^.typ=top_reg) and
                          GetNextInstruction(p, hp1) and
                          GetNextInstruction(p, hp1) and
@@ -724,7 +724,7 @@ begin
                             Taicpu(hp1).condition:=C_NO;
                             Taicpu(hp1).condition:=C_NO;
                           continue;
                           continue;
                         end;
                         end;
-                      { 
+                      {
                       @@2:                              @@2:
                       @@2:                              @@2:
                         ....                              ....
                         ....                              ....
                         cmp operand1,0
                         cmp operand1,0
@@ -753,8 +753,8 @@ begin
                          FindLabel(tasmlabel(taicpu(hp1).oper[0]^.ref^.symbol),hp4) then
                          FindLabel(tasmlabel(taicpu(hp1).oper[0]^.ref^.symbol),hp4) then
                         begin
                         begin
                           taicpu(hp2).Opcode := A_SUB;
                           taicpu(hp2).Opcode := A_SUB;
-                          taicpu(hp2).Loadoper(1,taicpu(hp2).oper[0]^);
-                          taicpu(hp2).LoadConst(0,1);
+                          taicpu(hp2).loadoper(1,taicpu(hp2).oper[0]^);
+                          taicpu(hp2).loadConst(0,1);
                           taicpu(hp2).ops:=2;
                           taicpu(hp2).ops:=2;
                           taicpu(hp3).Opcode := A_Jcc;
                           taicpu(hp3).Opcode := A_Jcc;
                           case taicpu(hp1).condition of
                           case taicpu(hp1).condition of
@@ -922,7 +922,7 @@ begin
                                 else
                                 else
                                   begin
                                   begin
                                     taicpu(p).opcode := A_ADD;
                                     taicpu(p).opcode := A_ADD;
-                                    taicpu(p).loadconst(0,l);
+                                    taicpu(p).loadConst(0,l);
                                   end;
                                   end;
                               end;
                               end;
                     end;
                     end;
@@ -945,7 +945,7 @@ begin
                                 begin
                                 begin
                                   { change "mov %reg, %treg; mov %treg, y"
                                   { change "mov %reg, %treg; mov %treg, y"
                                     to "mov %reg, y" }
                                     to "mov %reg, y" }
-                                  taicpu(p).LoadOper(1,taicpu(hp1).oper[1]^);
+                                  taicpu(p).loadOper(1,taicpu(hp1).oper[1]^);
                                   asml.remove(hp1);
                                   asml.remove(hp1);
                                   hp1.free;
                                   hp1.free;
                                   continue;
                                   continue;
@@ -955,7 +955,7 @@ begin
                                 begin
                                 begin
                                   { change "mov mem, %treg; mov %treg, %reg"
                                   { change "mov mem, %treg; mov %treg, %reg"
                                     to "mov mem, %reg" }
                                     to "mov mem, %reg" }
-                                  taicpu(p).Loadoper(1,taicpu(hp1).oper[1]^);
+                                  taicpu(p).loadoper(1,taicpu(hp1).oper[1]^);
                                   asml.remove(hp1);
                                   asml.remove(hp1);
                                   hp1.free;
                                   hp1.free;
                                   continue;
                                   continue;
@@ -992,8 +992,8 @@ begin
                 { change "mov %reg1, %reg2; test/or %reg2, %reg2; jxx" to
                 { change "mov %reg1, %reg2; test/or %reg2, %reg2; jxx" to
                   "test %reg1, %reg1; jxx" }
                   "test %reg1, %reg1; jxx" }
                                     begin
                                     begin
-                                      taicpu(hp1).Loadoper(0,taicpu(p).oper[0]^);
-                                      taicpu(hp1).Loadoper(1,taicpu(p).oper[0]^);
+                                      taicpu(hp1).loadoper(0,taicpu(p).oper[0]^);
+                                      taicpu(hp1).loadoper(1,taicpu(p).oper[0]^);
                                       asml.remove(p);
                                       asml.remove(p);
                                       p.free;
                                       p.free;
                                       p := hp1;
                                       p := hp1;
@@ -1003,8 +1003,8 @@ begin
                 {change "mov %reg1, %reg2; test/or %reg2, %reg2" to
                 {change "mov %reg1, %reg2; test/or %reg2, %reg2" to
                   "mov %reg1, %reg2; test/or %reg1, %reg1"}
                   "mov %reg1, %reg2; test/or %reg1, %reg1"}
                                     begin
                                     begin
-                                      taicpu(hp1).Loadoper(0,taicpu(p).oper[0]^);
-                                      taicpu(hp1).Loadoper(1,taicpu(p).oper[0]^);
+                                      taicpu(hp1).loadoper(0,taicpu(p).oper[0]^);
+                                      taicpu(hp1).loadoper(1,taicpu(p).oper[0]^);
                                     end;
                                     end;
                               end
                               end
 {                              else
 {                              else
@@ -1126,7 +1126,7 @@ begin
                                 mov reg2, mem2}
                                 mov reg2, mem2}
                                       begin
                                       begin
                                         AllocRegBetween(asmL,taicpu(hp2).oper[1]^.reg,p,hp2,usedregs);
                                         AllocRegBetween(asmL,taicpu(hp2).oper[1]^.reg,p,hp2,usedregs);
-                                        taicpu(p).Loadoper(1,taicpu(hp2).oper[1]^);
+                                        taicpu(p).loadoper(1,taicpu(hp2).oper[1]^);
                                         taicpu(hp1).loadoper(0,taicpu(hp2).oper[1]^);
                                         taicpu(hp1).loadoper(0,taicpu(hp2).oper[1]^);
                                         asml.remove(hp2);
                                         asml.remove(hp2);
                                         hp2.free;
                                         hp2.free;
@@ -1151,10 +1151,10 @@ begin
                               mov reg1, reg2
                               mov reg1, reg2
                         }
                         }
                                         begin
                                         begin
-                                          taicpu(hp1).LoadRef(0,taicpu(p).oper[0]^.ref^);
-                                          taicpu(hp1).LoadReg(1,taicpu(hp2).oper[1]^.reg);
-                                          taicpu(hp2).LoadRef(1,taicpu(hp2).oper[0]^.ref^);
-                                          taicpu(hp2).LoadReg(0,taicpu(p).oper[1]^.reg);
+                                          taicpu(hp1).loadRef(0,taicpu(p).oper[0]^.ref^);
+                                          taicpu(hp1).loadReg(1,taicpu(hp2).oper[1]^.reg);
+                                          taicpu(hp2).loadRef(1,taicpu(hp2).oper[0]^.ref^);
+                                          taicpu(hp2).loadReg(0,taicpu(p).oper[1]^.reg);
                                           allocRegBetween(asmL,taicpu(p).oper[1]^.reg,p,hp2,usedregs);
                                           allocRegBetween(asmL,taicpu(p).oper[1]^.reg,p,hp2,usedregs);
                                           if (taicpu(p).oper[0]^.ref^.base <> NR_NO) and
                                           if (taicpu(p).oper[0]^.ref^.base <> NR_NO) and
                                              (getsupreg(taicpu(p).oper[0]^.ref^.base) in [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESI,RS_EDI]) then
                                              (getsupreg(taicpu(p).oper[0]^.ref^.base) in [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESI,RS_EDI]) then
@@ -1166,7 +1166,7 @@ begin
                                       else
                                       else
                                         if (taicpu(hp1).Oper[0]^.reg <> taicpu(hp2).Oper[1]^.reg) then
                                         if (taicpu(hp1).Oper[0]^.reg <> taicpu(hp2).Oper[1]^.reg) then
                                           begin
                                           begin
-                                            taicpu(hp2).LoadReg(0,taicpu(hp1).Oper[0]^.reg);
+                                            taicpu(hp2).loadReg(0,taicpu(hp1).Oper[0]^.reg);
                                             allocRegBetween(asmL,taicpu(p).oper[1]^.reg,p,hp2,usedregs);
                                             allocRegBetween(asmL,taicpu(p).oper[1]^.reg,p,hp2,usedregs);
                                           end
                                           end
                                         else
                                         else
@@ -1190,7 +1190,7 @@ begin
                               RefsEqual(TReference(taicpu(p).oper[0]^^),taicpu(hp1).oper[0]^^.ref^) and
                               RefsEqual(TReference(taicpu(p).oper[0]^^),taicpu(hp1).oper[0]^^.ref^) and
                               (taicpu(p).oper[1]^.reg<>taicpu(hp1).oper[0]^^.ref^.base) and
                               (taicpu(p).oper[1]^.reg<>taicpu(hp1).oper[0]^^.ref^.base) and
                               (taicpu(p).oper[1]^.reg<>taicpu(hp1).oper[0]^^.ref^.index) then
                               (taicpu(p).oper[1]^.reg<>taicpu(hp1).oper[0]^^.ref^.index) then
-                              taicpu(hp1).LoadReg(0,taicpu(p).oper[1]^.reg)
+                              taicpu(hp1).loadReg(0,taicpu(p).oper[1]^.reg)
                             else*)
                             else*)
                             {   movl const1,[mem1]
                             {   movl const1,[mem1]
                                 movl [mem1],reg1
                                 movl [mem1],reg1
@@ -1205,9 +1205,9 @@ begin
                                  RefsEqual(taicpu(hp1).oper[0]^.ref^,taicpu(p).oper[1]^.ref^) then
                                  RefsEqual(taicpu(hp1).oper[0]^.ref^,taicpu(p).oper[1]^.ref^) then
                                 begin
                                 begin
                                   allocregbetween(asml,taicpu(hp1).oper[1]^.reg,p,hp1,usedregs);
                                   allocregbetween(asml,taicpu(hp1).oper[1]^.reg,p,hp1,usedregs);
-                                  taicpu(hp1).LoadReg(0,taicpu(hp1).oper[1]^.reg);
-                                  taicpu(hp1).LoadRef(1,taicpu(p).oper[1]^.ref^);
-                                  taicpu(p).LoadReg(1,taicpu(hp1).oper[0]^.reg);
+                                  taicpu(hp1).loadReg(0,taicpu(hp1).oper[1]^.reg);
+                                  taicpu(hp1).loadRef(1,taicpu(p).oper[1]^.ref^);
+                                  taicpu(p).loadReg(1,taicpu(hp1).oper[0]^.reg);
                                 end
                                 end
                         end;
                         end;
                     end;
                     end;
@@ -1248,7 +1248,7 @@ begin
                                   begin
                                   begin
                                     taicpu(p).opcode := A_AND;
                                     taicpu(p).opcode := A_AND;
                                     taicpu(p).changeopsize(S_W);
                                     taicpu(p).changeopsize(S_W);
-                                    taicpu(p).LoadConst(0,$ff);
+                                    taicpu(p).loadConst(0,$ff);
                                   end
                                   end
                                 else if GetNextInstruction(p, hp1) and
                                 else if GetNextInstruction(p, hp1) and
                                      (tai(hp1).typ = ait_instruction) and
                                      (tai(hp1).typ = ait_instruction) and
@@ -1262,7 +1262,7 @@ begin
                                     taicpu(p).opcode := A_MOV;
                                     taicpu(p).opcode := A_MOV;
                                     taicpu(p).changeopsize(S_W);
                                     taicpu(p).changeopsize(S_W);
                                     setsubreg(taicpu(p).oper[0]^.reg,R_SUBW);
                                     setsubreg(taicpu(p).oper[0]^.reg,R_SUBW);
-                                    taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val and $ff);
+                                    taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val and $ff);
                                   end;
                                   end;
                               end;
                               end;
                             S_BL:
                             S_BL:
@@ -1273,7 +1273,7 @@ begin
                                   begin
                                   begin
                                     taicpu(p).opcode := A_AND;
                                     taicpu(p).opcode := A_AND;
                                     taicpu(p).changeopsize(S_L);
                                     taicpu(p).changeopsize(S_L);
-                                    taicpu(p).loadconst(0,$ff)
+                                    taicpu(p).loadConst(0,$ff)
                                   end
                                   end
                                 else if GetNextInstruction(p, hp1) and
                                 else if GetNextInstruction(p, hp1) and
                                     (tai(hp1).typ = ait_instruction) and
                                     (tai(hp1).typ = ait_instruction) and
@@ -1287,7 +1287,7 @@ begin
                                     taicpu(p).opcode := A_MOV;
                                     taicpu(p).opcode := A_MOV;
                                     taicpu(p).changeopsize(S_L);
                                     taicpu(p).changeopsize(S_L);
                                     setsubreg(taicpu(p).oper[0]^.reg,R_SUBWHOLE);
                                     setsubreg(taicpu(p).oper[0]^.reg,R_SUBWHOLE);
-                                    taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val and $ff);
+                                    taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val and $ff);
                                   end
                                   end
                               end;
                               end;
                             S_WL:
                             S_WL:
@@ -1298,7 +1298,7 @@ begin
                                   begin
                                   begin
                                     taicpu(p).opcode := A_AND;
                                     taicpu(p).opcode := A_AND;
                                     taicpu(p).changeopsize(S_L);
                                     taicpu(p).changeopsize(S_L);
-                                    taicpu(p).LoadConst(0,$ffff);
+                                    taicpu(p).loadConst(0,$ffff);
                                   end
                                   end
                                 else if GetNextInstruction(p, hp1) and
                                 else if GetNextInstruction(p, hp1) and
                                     (tai(hp1).typ = ait_instruction) and
                                     (tai(hp1).typ = ait_instruction) and
@@ -1312,7 +1312,7 @@ begin
                                     taicpu(p).opcode := A_MOV;
                                     taicpu(p).opcode := A_MOV;
                                     taicpu(p).changeopsize(S_L);
                                     taicpu(p).changeopsize(S_L);
                                     setsubreg(taicpu(p).oper[0]^.reg,R_SUBWHOLE);
                                     setsubreg(taicpu(p).oper[0]^.reg,R_SUBWHOLE);
-                                    taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val and $ffff);
+                                    taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val and $ffff);
                                   end;
                                   end;
                               end;
                               end;
                             end
                             end
@@ -1330,17 +1330,17 @@ begin
                                     S_BL:
                                     S_BL:
                                       begin
                                       begin
                                         taicpu(p).changeopsize(S_L);
                                         taicpu(p).changeopsize(S_L);
-                                        taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val and $ff);
+                                        taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val and $ff);
                                       end;
                                       end;
                                     S_WL:
                                     S_WL:
                                       begin
                                       begin
                                         taicpu(p).changeopsize(S_L);
                                         taicpu(p).changeopsize(S_L);
-                                        taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val and $ffff);
+                                        taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val and $ffff);
                                       end;
                                       end;
                                     S_BW:
                                     S_BW:
                                       begin
                                       begin
                                         taicpu(p).changeopsize(S_W);
                                         taicpu(p).changeopsize(S_W);
-                                        taicpu(hp1).LoadConst(0,taicpu(hp1).oper[0]^.val and $ff);
+                                        taicpu(hp1).loadConst(0,taicpu(hp1).oper[0]^.val and $ff);
                                       end;
                                       end;
                                   end;
                                   end;
                                 end;
                                 end;
@@ -1382,7 +1382,7 @@ begin
                                 taicpu(hp2).oper[1]^.typ:=top_none;
                                 taicpu(hp2).oper[1]^.typ:=top_none;
                                 taicpu(hp2).ops:=2;
                                 taicpu(hp2).ops:=2;
                                 taicpu(hp2).opcode := A_MOV;
                                 taicpu(hp2).opcode := A_MOV;
-                                taicpu(hp2).Loadoper(1,taicpu(hp1).oper[0]^);
+                                taicpu(hp2).loadoper(1,taicpu(hp1).oper[0]^);
                                 reference_reset(tmpref);
                                 reference_reset(tmpref);
                                 tmpRef.base.enum:=R_INTREGISTER;
                                 tmpRef.base.enum:=R_INTREGISTER;
                                 tmpRef.base.number:=NR_STACK_POINTER_REG;
                                 tmpRef.base.number:=NR_STACK_POINTER_REG;
@@ -1421,10 +1421,10 @@ begin
                               taicpu(p).oper[1]^.typ:=top_none;
                               taicpu(p).oper[1]^.typ:=top_none;
                               taicpu(p).ops:=2;
                               taicpu(p).ops:=2;
                               taicpu(p).opcode := A_MOV;
                               taicpu(p).opcode := A_MOV;
-                              taicpu(p).Loadoper(1,taicpu(p).oper[0]^);
+                              taicpu(p).loadoper(1,taicpu(p).oper[0]^);
                               reference_reset(tmpref);
                               reference_reset(tmpref);
                               TmpRef.base.enum := R_ESP;
                               TmpRef.base.enum := R_ESP;
-                              taicpu(p).LoadRef(0,TmpRef);
+                              taicpu(p).loadRef(0,TmpRef);
                               asml.remove(hp1);
                               asml.remove(hp1);
                               hp1.free;
                               hp1.free;
                             end;
                             end;
@@ -1442,7 +1442,7 @@ begin
                          (taicpu(hp1).opsize = S_W) then
                          (taicpu(hp1).opsize = S_W) then
                         begin
                         begin
                           taicpu(p).changeopsize(S_L);
                           taicpu(p).changeopsize(S_L);
-                          taicpu(p).LoadConst(0,taicpu(p).oper[0]^.val shl 16 + word(taicpu(hp1).oper[0]^.val));
+                          taicpu(p).loadConst(0,taicpu(p).oper[0]^.val shl 16 + word(taicpu(hp1).oper[0]^.val));
                           asml.remove(hp1);
                           asml.remove(hp1);
                           hp1.free;
                           hp1.free;
                         end;
                         end;
@@ -1578,7 +1578,7 @@ begin
                          (taicpu(hp1).oper[0]^.typ = top_ref) and
                          (taicpu(hp1).oper[0]^.typ = top_ref) and
                          RefsEqual(taicpu(hp1).oper[0]^.ref^, taicpu(p).oper[0]^.ref^) then
                          RefsEqual(taicpu(hp1).oper[0]^.ref^, taicpu(p).oper[0]^.ref^) then
                         begin
                         begin
-                          taicpu(p).LoadReg(0,taicpu(hp1).oper[1]^.reg);
+                          taicpu(p).loadReg(0,taicpu(hp1).oper[1]^.reg);
                           asml.remove(hp1);
                           asml.remove(hp1);
                           hp1.free;
                           hp1.free;
                         end
                         end
@@ -1898,9 +1898,9 @@ begin
                         begin
                         begin
                           case taicpu(hp1).opcode of
                           case taicpu(hp1).opcode of
                             A_INC,A_DEC:
                             A_INC,A_DEC:
-                              taicpu(hp1).LoadRef(0,taicpu(p).oper[0]^.ref^)
+                              taicpu(hp1).loadRef(0,taicpu(p).oper[0]^.ref^)
                             else
                             else
-                              taicpu(hp1).LoadRef(1,taicpu(p).oper[0]^.ref^);
+                              taicpu(hp1).loadRef(1,taicpu(p).oper[0]^.ref^);
                           end;
                           end;
                           asml.remove(p);
                           asml.remove(p);
                           asml.remove(hp2);
                           asml.remove(hp2);
@@ -1965,7 +1965,7 @@ See test/tgadint64 in the test suite.
                   { change "mov $0, %reg" into "xor %reg, %reg" }
                   { change "mov $0, %reg" into "xor %reg, %reg" }
                   begin
                   begin
                     taicpu(p).opcode := A_XOR;
                     taicpu(p).opcode := A_XOR;
-                    taicpu(p).LoadReg(0,taicpu(p).oper[1]^.reg);
+                    taicpu(p).loadReg(0,taicpu(p).oper[1]^.reg);
                   end;
                   end;
 *)
 *)
               A_MOVZX:
               A_MOVZX:
@@ -2061,8 +2061,8 @@ See test/tgadint64 in the test suite.
                                        A_DEC: taicpu(hp1).opcode := A_SUB;
                                        A_DEC: taicpu(hp1).opcode := A_SUB;
                                        A_INC: taicpu(hp1).opcode := A_ADD;
                                        A_INC: taicpu(hp1).opcode := A_ADD;
                                      end;
                                      end;
-                                     taicpu(hp1).Loadoper(1,taicpu(hp1).oper[0]^);
-                                     taicpu(hp1).LoadConst(0,1);
+                                     taicpu(hp1).loadoper(1,taicpu(hp1).oper[0]^);
+                                     taicpu(hp1).loadConst(0,1);
                                      taicpu(hp1).ops:=2;
                                      taicpu(hp1).ops:=2;
                                    end
                                    end
                                  end;
                                  end;

+ 231 - 58
compiler/link.pas

@@ -29,7 +29,8 @@ uses
   cclasses,
   cclasses,
   systems,
   systems,
   fmodule,
   fmodule,
-  globtype;
+  globtype,
+  ogbase;
 
 
 Type
 Type
     TLinkerInfo=record
     TLinkerInfo=record
@@ -43,6 +44,8 @@ Type
 
 
     TLinker = class(TAbstractLinker)
     TLinker = class(TAbstractLinker)
     public
     public
+       HasResources,
+       HasExports      : boolean;
        ObjectFiles,
        ObjectFiles,
        DLLFiles,
        DLLFiles,
        SharedLibFiles,
        SharedLibFiles,
@@ -74,7 +77,19 @@ Type
 
 
     TInternalLinker = class(TLinker)
     TInternalLinker = class(TLinker)
     private
     private
-       procedure readobj(const fn:string);
+       FCExeOutput : TExeOutputClass;
+       FCObjInput  : TObjInputClass;
+       procedure Load_ReadObject(const para:string);
+       procedure Load_ReadUnitObjects;
+       procedure ParseScript_Load;
+       procedure ParseScript_Order;
+       procedure ParseScript_CalcPos;
+       procedure PrintLinkerScript;
+    protected
+       property CObjInput:TObjInputClass read FCObjInput write FCObjInput;
+       property CExeOutput:TExeOutputClass read FCExeOutput write FCExeOutput;
+       procedure DefaultLinkScript;virtual;abstract;
+       linkscript : TStringList;
     public
     public
        Constructor Create;override;
        Constructor Create;override;
        Destructor Destroy;override;
        Destructor Destroy;override;
@@ -102,9 +117,9 @@ uses
   dos,
   dos,
 {$ENDIF USE_SYSUTILS}
 {$ENDIF USE_SYSUTILS}
   cutils,
   cutils,
-  script,globals,verbose,ppu,
+  script,globals,verbose,comphook,ppu,
   aasmbase,aasmtai,aasmcpu,
   aasmbase,aasmtai,aasmcpu,
-  ogbase,ogmap;
+  ogmap;
 
 
 type
 type
  TLinkerClass = class of Tlinker;
  TLinkerClass = class of Tlinker;
@@ -287,6 +302,10 @@ var
 begin
 begin
   with hp do
   with hp do
    begin
    begin
+     if (flags and uf_has_resourcefiles)<>0 then
+       HasResources:=true;
+     if (flags and uf_has_exports)<>0 then
+       HasExports:=true;
    { link unit files }
    { link unit files }
      if (flags and uf_no_link)=0 then
      if (flags and uf_no_link)=0 then
       begin
       begin
@@ -652,72 +671,226 @@ end;
                               TINTERNALLINKER
                               TINTERNALLINKER
 *****************************************************************************}
 *****************************************************************************}
 
 
-Constructor TInternalLinker.Create;
-begin
-  inherited Create;
-  exemap:=nil;
-  exeoutput:=nil;
-end;
+    Constructor TInternalLinker.Create;
+      begin
+        inherited Create;
+        linkscript:=TStringList.Create;
+        exemap:=nil;
+        exeoutput:=nil;
+        CObjInput:=TObjInput;
+      end;
 
 
 
 
-Destructor TInternalLinker.Destroy;
-begin
-  exeoutput.free;
-  exeoutput:=nil;
-  inherited destroy;
-end;
+    Destructor TInternalLinker.Destroy;
+      begin
+        linkscript.free;
+        exeoutput.free;
+        exeoutput:=nil;
+        inherited destroy;
+      end;
 
 
 
 
-procedure TInternalLinker.readobj(const fn:string);
-var
-  objdata  : TAsmObjectData;
-  objinput : tobjectinput;
-begin
-  Comment(V_Info,'Reading object '+fn);
-  objinput:=exeoutput.newobjectinput;
-  objdata:=objinput.newobjectdata(fn);
-  if objinput.readobjectfile(fn,objdata) then
-    exeoutput.addobjdata(objdata);
-  { release input object }
-  objinput.free;
-end;
+    procedure TInternalLinker.Load_ReadObject(const para:string);
+      var
+        objdata  : TObjData;
+        objinput : TObjinput;
+        fn       : string;
+      begin
+        fn:=FindObjectFile(para,'',false);
+        Comment(V_Tried,'Reading object '+fn);
+        objinput:=CObjInput.Create;
+        objdata:=objinput.newObjData(para);
+        if objinput.readobjectfile(fn,objdata) then
+          exeoutput.addobjdata(objdata);
+        { release input object }
+        objinput.free;
+      end;
 
 
 
 
-function TInternalLinker.MakeExecutable:boolean;
-var
-  s : string;
-begin
-  MakeExecutable:=false;
+    procedure TInternalLinker.Load_ReadUnitObjects;
+      var
+        s : string;
+      begin
+        while not ObjectFiles.Empty do
+          begin
+            s:=ObjectFiles.GetFirst;
+            if s<>'' then
+              Load_ReadObject(s);
+          end;
+      end;
+
 
 
-  { no support yet for libraries }
-  if (not StaticLibFiles.Empty) or
-     (not SharedLibFiles.Empty) then
-   internalerror(123456789);
+    procedure TInternalLinker.ParseScript_Load;
+      var
+        s,
+        para,
+        keyword : string;
+        hp : TStringListItem;
+      begin
+        exeoutput.Load_Start;
+        hp:=tstringlistitem(linkscript.first);
+        while assigned(hp) do
+          begin
+            s:=hp.str;
+            if (s='') or (s[1]='#') then
+              continue;
+            keyword:=Upper(GetToken(s,' '));
+            para:=GetToken(s,' ');
+            if keyword='SYMBOL' then
+              ExeOutput.Load_Symbol(para)
+            else if keyword='ENTRYNAME' then
+              ExeOutput.Load_EntryName(para)
+            else if keyword='READOBJECT' then
+              Load_ReadObject(para)
+            else if keyword='READUNITOBJECTS' then
+              Load_ReadUnitObjects;
+            hp:=tstringlistitem(hp.next);
+          end;
+      end;
 
 
-  if (cs_link_map in aktglobalswitches) then
-   exemap:=texemap.create(current_module.mapfilename^);
 
 
-  { read objects }
-  readobj(FindObjectFile('prt0','',false));
-  while not ObjectFiles.Empty do
-   begin
-     s:=ObjectFiles.GetFirst;
-     if s<>'' then
-      readobj(s);
-   end;
+    procedure TInternalLinker.ParseScript_Order;
+      var
+        s,
+        para,
+        keyword : string;
+        hp : TStringListItem;
+      begin
+        exeoutput.Order_Start;
+        hp:=tstringlistitem(linkscript.first);
+        while assigned(hp) do
+          begin
+            s:=hp.str;
+            if (s='') or (s[1]='#') then
+              continue;
+            keyword:=Upper(GetToken(s,' '));
+            para:=GetToken(s,' ');
+            if keyword='EXESECTION' then
+              ExeOutput.Order_ExeSection(para)
+            else if keyword='ENDEXESECTION' then
+              ExeOutput.Order_EndExeSection
+            else if keyword='OBJSECTION' then
+              ExeOutput.Order_ObjSection(para)
+            else if keyword='ZEROS' then
+              ExeOutput.Order_Zeros(para)
+            else if keyword='SYMBOL' then
+              ExeOutput.Order_Symbol(para)
+            else if keyword='STABS' then
+              ExeOutput.Order_Stabs;
+            hp:=tstringlistitem(hp.next);
+          end;
+      end;
 
 
-  { generate executable }
-  exeoutput.GenerateExecutable(current_module.exefilename^);
 
 
-  { close map }
-  if assigned(exemap) then
-   begin
-     exemap.free;
-     exemap:=nil;
-   end;
+    procedure TInternalLinker.ParseScript_CalcPos;
+      var
+        s,
+        para,
+        keyword : string;
+        hp : TStringListItem;
+      begin
+        exeoutput.CalcPos_Start;
+        hp:=tstringlistitem(linkscript.first);
+        while assigned(hp) do
+          begin
+            s:=hp.str;
+            if (s='') or (s[1]='#') then
+              continue;
+            keyword:=Upper(GetToken(s,' '));
+            para:=GetToken(s,' ');
+            if keyword='EXESECTION' then
+              ExeOutput.CalcPos_ExeSection(para)
+            else if keyword='ENDEXESECTION' then
+              ExeOutput.CalcPos_EndExeSection
+            else if keyword='HEADER' then
+              ExeOutput.CalcPos_Header
+            else if keyword='SYMBOLS' then
+              ExeOutput.CalcPos_Symbols;
+            hp:=tstringlistitem(hp.next);
+          end;
+      end;
 
 
-  MakeExecutable:=true;
-end;
+
+    procedure TInternalLinker.PrintLinkerScript;
+      var
+        hp : TStringListItem;
+      begin
+        if not assigned(exemap) then
+          exit;
+        exemap.Add('Used linker script');
+        exemap.Add('');
+        hp:=tstringlistitem(linkscript.first);
+        while assigned(hp) do
+          begin
+            exemap.Add(hp.str);
+            hp:=tstringlistitem(hp.next);
+          end;
+      end;
+
+
+    function TInternalLinker.MakeExecutable:boolean;
+      label
+        myexit;
+      var
+        s,s2 : string;
+      begin
+        MakeExecutable:=false;
+
+        Message1(exec_i_linking,current_module.exefilename^);
+
+{$warning TODO Load custom linker script}
+        DefaultLinkScript;
+
+        exeoutput:=CExeOutput.Create;
+
+        if (cs_link_map in aktglobalswitches) then
+          exemap:=texemap.create(current_module.mapfilename^);
+
+        PrintLinkerScript;
+
+        { Load .o files and resolve symbols }
+        ParseScript_Load;
+        if ErrorCount>0 then
+          goto myexit;
+        exeoutput.ResolveSymbols;
+        { DLL Linking }
+        While not DLLFiles.Empty do
+          begin
+            s:=DLLFiles.GetFirst;
+            if FindDLL(s,s2) then
+              exeoutput.ResolveExternals(s2)
+            else
+              Comment(V_Error,'DLL not found: '+s);
+          end;
+
+        { Create .exe sections and add .o sections }
+        ParseScript_Order;
+        exeoutput.RemoveEmptySections;
+        if ErrorCount>0 then
+          goto myexit;
+
+        { Calc positions in mem and file }
+        ParseScript_CalcPos;
+        exeoutput.FixupSymbols;
+        exeoutput.FixupRelocations;
+        exeoutput.PrintMemoryMap;
+
+        exeoutput.WriteExeFile(current_module.exefilename^);
+
+{$warning TODO fixed section names}
+        status.codesize:=exeoutput.findexesection('.text').size;
+        status.datasize:=exeoutput.findexesection('.data').size;
+
+      myexit:
+        { close map }
+        if assigned(exemap) then
+          begin
+            exemap.free;
+            exemap:=nil;
+          end;
+
+        MakeExecutable:=true;
+      end;
 
 
 
 
 {*****************************************************************************
 {*****************************************************************************

+ 1 - 1
compiler/msg/errore.msg

@@ -79,7 +79,7 @@ general_t_objectpath=01007_T_Using object path: $1
 % When the \var{-vt} switch is used, this line tells you where the compiler
 % When the \var{-vt} switch is used, this line tells you where the compiler
 % looks for object files you link in (files used in \var{\{\$L xxx\}} statements).
 % looks for object files you link in (files used in \var{\{\$L xxx\}} statements).
 % You can set this path with the \var{-Fo} option.
 % You can set this path with the \var{-Fo} option.
-general_i_abslines_compiled=01008_I_$1 Lines compiled, $2 sec
+general_i_abslines_compiled=01008_I_$1 Lines compiled, $2 sec$3
 % When the \var{-vi} switch is used, the compiler reports the number
 % When the \var{-vi} switch is used, the compiler reports the number
 % of lines compiled, and the time it took to compile them (real time,
 % of lines compiled, and the time it took to compile them (real time,
 % not program time).
 % not program time).

+ 1 - 1
compiler/msgidx.inc

@@ -669,7 +669,7 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 39751;
+  MsgTxtSize = 39753;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
     19,74,219,59,62,47,100,20,135,60,
     19,74,219,59,62,47,100,20,135,60,

File diff suppressed because it is too large
+ 163 - 163
compiler/msgtxt.inc


+ 3 - 5
compiler/ncgbas.pas

@@ -121,7 +121,7 @@ interface
       procedure ReLabel(var p:tasmsymbol);
       procedure ReLabel(var p:tasmsymbol);
         begin
         begin
           { Only relabel local tasmlabels }
           { Only relabel local tasmlabels }
-          if (p.defbind = AB_LOCAL) and
+          if (p.bind = AB_LOCAL) and
              (p is tasmlabel) then
              (p is tasmlabel) then
            begin
            begin
              if not assigned(p.altsymbol) then
              if not assigned(p.altsymbol) then
@@ -227,7 +227,6 @@ interface
 
 
          if (po_inline in current_procinfo.procdef.procoptions) then
          if (po_inline in current_procinfo.procdef.procoptions) then
            begin
            begin
-             objectlibrary.CreateUsedAsmSymbolList;
              hp:=tai(p_asm.first);
              hp:=tai(p_asm.first);
              while assigned(hp) do
              while assigned(hp) do
               begin
               begin
@@ -235,7 +234,7 @@ interface
                 skipnode:=false;
                 skipnode:=false;
                 case hp2.typ of
                 case hp2.typ of
                   ait_label :
                   ait_label :
-                     ReLabel(tasmsymbol(tai_label(hp2).l));
+                     ReLabel(tasmsymbol(tai_label(hp2).labsym));
                   ait_const :
                   ait_const :
                      begin
                      begin
                        if assigned(tai_const(hp2).sym) then
                        if assigned(tai_const(hp2).sym) then
@@ -284,8 +283,7 @@ interface
                 hp:=tai(hp.next);
                 hp:=tai(hp.next);
               end;
               end;
              { restore used symbols }
              { restore used symbols }
-             objectlibrary.UsedAsmSymbolListResetAltSym;
-             objectlibrary.DestroyUsedAsmSymbolList;
+             objectlibrary.ResetAltSymbols;
            end
            end
          else
          else
            begin
            begin

+ 4 - 4
compiler/ncgcon.pas

@@ -104,7 +104,7 @@ implementation
              while assigned(hp1) do
              while assigned(hp1) do
                begin
                begin
                   if hp1.typ=ait_label then
                   if hp1.typ=ait_label then
-                    lastlabel:=tai_label(hp1).l
+                    lastlabel:=tai_label(hp1).labsym
                   else
                   else
                     begin
                     begin
                        if (hp1.typ=realait) and (lastlabel<>nil) then
                        if (hp1.typ=realait) and (lastlabel<>nil) then
@@ -274,7 +274,7 @@ implementation
                     begin
                     begin
                        if hp1.typ=ait_label then
                        if hp1.typ=ait_label then
                          begin
                          begin
-                           lastlabel:=tai_label(hp1).l;
+                           lastlabel:=tai_label(hp1).labsym;
                            lastlabelhp:=hp1;
                            lastlabelhp:=hp1;
                          end
                          end
                        else
                        else
@@ -349,7 +349,7 @@ implementation
                                           assigned(hp2.previous.previous.previous) and
                                           assigned(hp2.previous.previous.previous) and
                                           (tai(hp2.previous.previous.previous).typ=ait_label) then
                                           (tai(hp2.previous.previous.previous).typ=ait_label) then
                                          begin
                                          begin
-                                           lastlabel:=tai_label(hp2.previous.previous.previous).l;
+                                           lastlabel:=tai_label(hp2.previous.previous.previous).labsym;
                                            same_string:=true;
                                            same_string:=true;
                                            j:=0;
                                            j:=0;
                                            if len>0 then
                                            if len>0 then
@@ -507,7 +507,7 @@ implementation
              while assigned(hp1) do
              while assigned(hp1) do
                begin
                begin
                   if hp1.typ=ait_label then
                   if hp1.typ=ait_label then
-                    lastlabel:=tai_label(hp1).l
+                    lastlabel:=tai_label(hp1).labsym
                   else
                   else
                     begin
                     begin
                       if (lastlabel<>nil) and
                       if (lastlabel<>nil) and

+ 0 - 12
compiler/ncgset.pas

@@ -669,18 +669,6 @@ implementation
       end;
       end;
 
 
 
 
-    procedure ReLabel(var p:tasmsymbol);
-      begin
-        if p.defbind = AB_LOCAL then
-         begin
-           if not assigned(p.altsymbol) then
-             objectlibrary.GenerateAltSymbol(p);
-           p:=p.altsymbol;
-           p.increfs;
-         end;
-      end;
-
-
     procedure tcgcasenode.pass_2;
     procedure tcgcasenode.pass_2;
       var
       var
          i : longint;
          i : longint;

+ 1 - 1
compiler/ncgutil.pas

@@ -1961,7 +1961,7 @@ implementation
         l,varalign : longint;
         l,varalign : longint;
         storefilepos : tfileposinfo;
         storefilepos : tfileposinfo;
         list : Taasmoutput;
         list : Taasmoutput;
-        sectype : Tasmsectiontype;
+        sectype : TAsmSectiontype;
       begin
       begin
         storefilepos:=aktfilepos;
         storefilepos:=aktfilepos;
         aktfilepos:=sym.fileinfo;
         aktfilepos:=sym.fileinfo;

+ 0 - 2
compiler/ncon.pas

@@ -302,7 +302,6 @@ implementation
       begin
       begin
         inherited derefimpl;
         inherited derefimpl;
         restype.resolve;
         restype.resolve;
-        objectlibrary.derefasmsymbol(tasmsymbol(lab_real));
       end;
       end;
 
 
 
 
@@ -612,7 +611,6 @@ implementation
     procedure tstringconstnode.derefimpl;
     procedure tstringconstnode.derefimpl;
       begin
       begin
         inherited derefimpl;
         inherited derefimpl;
-        objectlibrary.derefasmsymbol(tasmsymbol(lab_str));
       end;
       end;
 
 
 
 

File diff suppressed because it is too large
+ 949 - 91
compiler/ogbase.pas


File diff suppressed because it is too large
+ 501 - 285
compiler/ogcoff.pas


File diff suppressed because it is too large
+ 296 - 368
compiler/ogelf.pas


+ 9 - 9
compiler/oglx.pas

@@ -205,14 +205,14 @@ uses
         i         : longint;
         i         : longint;
         globalval : byte;
         globalval : byte;
         secrec    : coffsectionrec;
         secrec    : coffsectionrec;
-        objdata   : TAsmObjectData;
+        objdata   : TObjData;
         p         : tasmsymbol;
         p         : tasmsymbol;
         s         : string;}
         s         : string;}
       begin
       begin
-(*        objdata:=TAsmObjectData(objdatalist.first);
+(*        objdata:=TObjData(objdatalist.first);
         while assigned(objdata) do
         while assigned(objdata) do
          begin
          begin
-           with tcoffobjectdata(objdata) do
+           with tcoffObjData(objdata) do
             begin
             begin
               { The symbols used }
               { The symbols used }
               p:=Tasmsymbol(symbols.First);
               p:=Tasmsymbol(symbols.First);
@@ -249,20 +249,20 @@ uses
                  p:=tasmsymbol(p.indexnext);
                  p:=tasmsymbol(p.indexnext);
                end;
                end;
             end;
             end;
-           objdata:=TAsmObjectData(objdata.next);
+           objdata:=TObjData(objdata.next);
          end;*)
          end;*)
       end;
       end;
 
 
 
 
     procedure Tlxexeoutput.CalculateMemoryMap;
     procedure Tlxexeoutput.CalculateMemoryMap;
 {      var
 {      var
-        objdata : TAsmObjectData;
+        objdata : TObjData;
         secsymidx,
         secsymidx,
         mempos,
         mempos,
         datapos : longint;
         datapos : longint;
         sec     : TSection;
         sec     : TSection;
         sym     : tasmsymbol;
         sym     : tasmsymbol;
-        s       : TAsmSection;}
+        s       : TObjSection;}
       begin
       begin
 (*        { retrieve amount of sections }
 (*        { retrieve amount of sections }
         nsects:=0;
         nsects:=0;
@@ -282,7 +282,7 @@ uses
         if not win32 then
         if not win32 then
          inc(mempos,sizeof(go32v2stub)+$1000);
          inc(mempos,sizeof(go32v2stub)+$1000);
         { add sections }
         { add sections }
-        MapObjectdata(datapos,mempos);
+        MapObjData(datapos,mempos);
         { end symbol }
         { end symbol }
         AddGlobalSym('_etext',sections[sec_code].mempos+sections[sec_code].memsize);
         AddGlobalSym('_etext',sections[sec_code].mempos+sections[sec_code].memsize);
         AddGlobalSym('_edata',sections[sec_data].mempos+sections[sec_data].memsize);
         AddGlobalSym('_edata',sections[sec_data].mempos+sections[sec_data].memsize);
@@ -293,11 +293,11 @@ uses
         if not(cs_link_strip in aktglobalswitches) then
         if not(cs_link_strip in aktglobalswitches) then
          begin
          begin
            sympos:=datapos;
            sympos:=datapos;
-           objdata:=TAsmObjectData(objdatalist.first);
+           objdata:=TObjData(objdatalist.first);
            while assigned(objdata) do
            while assigned(objdata) do
             begin
             begin
               inc(nsyms,objdata.symbols.count);
               inc(nsyms,objdata.symbols.count);
-              objdata:=TAsmObjectData(objdata.next);
+              objdata:=TObjData(objdata.next);
             end;
             end;
          end;*)
          end;*)
       end;
       end;

+ 37 - 21
compiler/ogmap.pas

@@ -27,7 +27,7 @@ interface
 
 
     uses
     uses
        { common }
        { common }
-       cclasses,systems,
+       cclasses,globtype,systems,
        { object writer }
        { object writer }
        aasmbase,ogbase
        aasmbase,ogbase
        ;
        ;
@@ -36,16 +36,18 @@ interface
        texemap = class
        texemap = class
        private
        private
          t : text;
          t : text;
+         FImageBase : aint;
        public
        public
          constructor Create(const s:string);
          constructor Create(const s:string);
          destructor Destroy;override;
          destructor Destroy;override;
          procedure Add(const s:string);
          procedure Add(const s:string);
+         procedure AddHeader(const s:string);
          procedure AddCommonSymbolsHeader;
          procedure AddCommonSymbolsHeader;
-         procedure AddCommonSymbol(p:tasmsymbol);
-         procedure AddMemoryMapHeader;
+         procedure AddCommonSymbol(p:TObjSymbol);
+         procedure AddMemoryMapHeader(abase:aint);
          procedure AddMemoryMapExeSection(p:texesection);
          procedure AddMemoryMapExeSection(p:texesection);
-         procedure AddMemoryMapObjectSection(p:TAsmSection);
-         procedure AddMemoryMapSymbol(p:tasmsymbol);
+         procedure AddMemoryMapObjectSection(p:TObjSection);
+         procedure AddMemoryMapSymbol(p:TObjSymbol);
        end;
        end;
 
 
     var
     var
@@ -66,6 +68,7 @@ implementation
        begin
        begin
          Assign(t,FixFileName(s));
          Assign(t,FixFileName(s));
          Rewrite(t);
          Rewrite(t);
+         FImageBase:=0;
        end;
        end;
 
 
 
 
@@ -81,16 +84,22 @@ implementation
        end;
        end;
 
 
 
 
+     procedure TExeMap.AddHeader(const s:string);
+       begin
+         Add('');
+         Add(s);
+       end;
+
+
      procedure TExeMap.AddCommonSymbolsHeader;
      procedure TExeMap.AddCommonSymbolsHeader;
        begin
        begin
-         writeln(t,'');
-         writeln(t,'Allocating common symbols');
-         writeln(t,'Common symbol       size              file');
-         writeln(t,'');
+         AddHeader('Allocating common symbols');
+         Add('Common symbol       size              file');
+         Add('');
        end;
        end;
 
 
 
 
-     procedure TExeMap.AddCommonSymbol(p:tasmsymbol);
+     procedure TExeMap.AddCommonSymbol(p:TObjSymbol);
        var
        var
          s : string;
          s : string;
        begin
        begin
@@ -101,37 +110,44 @@ implementation
             writeln(t,p.name);
             writeln(t,p.name);
             s:='';
             s:='';
           end;
           end;
-         writeln(t,PadSpace(s,20)+'0x'+PadSpace(hexstr(p.size,1),16)+p.owner.name);
+         Add(PadSpace(s,20)+'0x'+PadSpace(hexstr(p.size,1),16)+p.objsection.objdata.name);
        end;
        end;
 
 
 
 
-     procedure TExeMap.AddMemoryMapHeader;
+     procedure TExeMap.AddMemoryMapHeader(abase:aint);
+       var
+         imagebasestr : string;
        begin
        begin
-         writeln(t,'');
-         writeln(t,'Memory map');
-         writeln(t,'');
+         FImageBase:=abase;
+         if FImageBase<>0 then
+           imagebasestr:=' (ImageBase='+HexStr(FImageBase,sizeof(aint)*2)+')'
+         else
+           imagebasestr:='';
+         AddHeader('Memory map'+imagebasestr);
+         Add('');
        end;
        end;
 
 
 
 
      procedure TExeMap.AddMemoryMapExeSection(p:texesection);
      procedure TExeMap.AddMemoryMapExeSection(p:texesection);
        begin
        begin
          { .text           0x000018a8     0xd958 }
          { .text           0x000018a8     0xd958 }
-         writeln(t,PadSpace(p.name,18)+PadSpace('0x'+HexStr(p.mempos,8),15)+'0x'+HexStr(p.memsize,1));
+         Add(PadSpace(p.name,18)+PadSpace('0x'+HexStr(p.mempos+Fimagebase,sizeof(aint)*2),12)+
+             '0x'+HexStr(p.size,sizeof(aint)));
        end;
        end;
 
 
 
 
-     procedure TExeMap.AddMemoryMapObjectSection(p:TAsmSection);
+     procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
        begin
        begin
          { .text           0x000018a8     0xd958     object.o }
          { .text           0x000018a8     0xd958     object.o }
-         writeln(t,' '+PadSpace(p.name,17)+PadSpace('0x'+HexStr(p.mempos,8),16)+
-                   '0x'+HexStr(p.memsize,1)+' '+p.owner.name);
+         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;
        end;
 
 
 
 
-     procedure TExeMap.AddMemoryMapSymbol(p:tasmsymbol);
+     procedure TExeMap.AddMemoryMapSymbol(p:TObjSymbol);
        begin
        begin
          {                 0x00001e30                setup_screens }
          {                 0x00001e30                setup_screens }
-         writeln(t,Space(18)+PadSpace('0x'+HexStr(p.address,8),26)+p.name);
+         Add(Space(18)+PadSpace('0x'+HexStr(p.address+Fimagebase,sizeof(aint)*2),26)+p.name);
        end;
        end;
 
 
 end.
 end.

+ 8 - 1
compiler/options.pas

@@ -104,7 +104,8 @@ procedure set_default_link_type;
 begin
 begin
   { win32 and wdosx need smartlinking by default to prevent including too much
   { win32 and wdosx need smartlinking by default to prevent including too much
     dll dependencies }
     dll dependencies }
-  if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
+  if not(cs_link_internal in initglobalswitches) and
+     (target_info.system in [system_i386_win32,system_i386_wdosx]) then
     begin
     begin
       def_system_macro('FPC_LINK_SMART');
       def_system_macro('FPC_LINK_SMART');
       undef_system_macro('FPC_LINK_STATIC');
       undef_system_macro('FPC_LINK_STATIC');
@@ -1131,6 +1132,7 @@ begin
                     'I':
                     'I':
                       begin
                       begin
                         GenerateImportSection:=not UnsetBool(More,j);
                         GenerateImportSection:=not UnsetBool(More,j);
+                        GenerateImportSectionSetExplicitly:=true;
                       end;
                       end;
                     'N':
                     'N':
                       begin
                       begin
@@ -2117,6 +2119,11 @@ begin
   if target_info.system=system_arm_wince then
   if target_info.system=system_arm_wince then
     include(initmoduleswitches,cs_fp_emulation);
     include(initmoduleswitches,cs_fp_emulation);
 
 
+  { By default don't create import section if we use the internal linker }
+  if not GenerateImportSectionSetExplicitly and
+     (cs_link_internal in aktglobalswitches) then
+    GenerateImportSection:=false;
+
   { Section smartlinking conflicts with import sections on Windows }
   { Section smartlinking conflicts with import sections on Windows }
   if GenerateImportSection and
   if GenerateImportSection and
      (target_info.system in [system_i386_win32]) then
      (target_info.system in [system_i386_win32]) then

+ 7 - 3
compiler/owar.pas

@@ -57,7 +57,7 @@ type
     objpos      : longint;
     objpos      : longint;
     objfn       : string;
     objfn       : string;
     timestamp   : string[12];
     timestamp   : string[12];
-    procedure createarhdr(fn:string;size:longint;const gid,uid,mode:string);
+    procedure createarhdr(fn:string;asize:longint;const gid,uid,mode:string);
     procedure writear;
     procedure writear;
   end;
   end;
 
 
@@ -140,7 +140,7 @@ begin
 end;
 end;
 
 
 
 
-procedure tarobjectwriter.createarhdr(fn:string;size:longint;const gid,uid,mode:string);
+procedure tarobjectwriter.createarhdr(fn:string;asize:longint;const gid,uid,mode:string);
 var
 var
   tmp : string[9];
   tmp : string[9];
   hfn : string;
   hfn : string;
@@ -167,7 +167,7 @@ begin
   { don't write a date if also no gid/uid/mode is specified }
   { don't write a date if also no gid/uid/mode is specified }
   if gid<>'' then
   if gid<>'' then
     move(timestamp[1],arhdr.date,sizeof(timestamp));
     move(timestamp[1],arhdr.date,sizeof(timestamp));
-  str(size,tmp);
+  str(asize,tmp);
   move(tmp[1],arhdr.size,length(tmp));
   move(tmp[1],arhdr.size,length(tmp));
   move(gid[1],arhdr.gid,length(gid));
   move(gid[1],arhdr.gid,length(gid));
   move(uid[1],arhdr.uid,length(uid));
   move(uid[1],arhdr.uid,length(uid));
@@ -182,6 +182,7 @@ begin
   objpos:=ardata.size;
   objpos:=ardata.size;
   ardata.seek(objpos + sizeof(tarhdr));
   ardata.seek(objpos + sizeof(tarhdr));
   createfile:=true;
   createfile:=true;
+  fobjsize:=0;
 end;
 end;
 
 
 
 
@@ -193,6 +194,7 @@ begin
 { write the header }
 { write the header }
   ardata.seek(objpos);
   ardata.seek(objpos);
   ardata.write(arhdr,sizeof(tarhdr));
   ardata.write(arhdr,sizeof(tarhdr));
+  fobjsize:=0;
 end;
 end;
 
 
 
 
@@ -209,6 +211,8 @@ end;
 
 
 procedure tarobjectwriter.write(const b;len:longint);
 procedure tarobjectwriter.write(const b;len:longint);
 begin
 begin
+  inc(fobjsize,len);
+  inc(fsize,len);
   ardata.write(b,len);
   ardata.write(b,len);
 end;
 end;
 
 

+ 30 - 9
compiler/owbase.pas

@@ -35,8 +35,10 @@ type
     opened : boolean;
     opened : boolean;
     buf    : pchar;
     buf    : pchar;
     bufidx : longint;
     bufidx : longint;
-    size   : longint;
     procedure writebuf;
     procedure writebuf;
+  protected
+    fsize,
+    fobjsize  : longint;
   public
   public
     constructor create;
     constructor create;
     destructor  destroy;override;
     destructor  destroy;override;
@@ -45,6 +47,9 @@ type
     procedure writesym(const sym:string);virtual;
     procedure writesym(const sym:string);virtual;
     procedure write(const b;len:longint);virtual;
     procedure write(const b;len:longint);virtual;
     procedure WriteZeros(l:longint);
     procedure WriteZeros(l:longint);
+    procedure writearray(a:TDynamicArray);
+    property Size:longint read FSize;
+    property ObjSize:longint read FObjSize;
   end;
   end;
 
 
   tobjectreader=class
   tobjectreader=class
@@ -61,7 +66,7 @@ type
     function  openfile(const fn:string):boolean;virtual;
     function  openfile(const fn:string):boolean;virtual;
     procedure closefile;virtual;
     procedure closefile;virtual;
     procedure seek(len:longint);
     procedure seek(len:longint);
-    function  read(var b;len:longint):boolean;virtual;
+    function  read(out b;len:longint):boolean;virtual;
     function  readarray(a:TDynamicArray;len:longint):boolean;
     function  readarray(a:TDynamicArray;len:longint):boolean;
   end;
   end;
 
 
@@ -83,7 +88,7 @@ begin
   getmem(buf,bufsize);
   getmem(buf,bufsize);
   bufidx:=0;
   bufidx:=0;
   opened:=false;
   opened:=false;
-  size:=0;
+  fsize:=0;
 end;
 end;
 
 
 
 
@@ -105,7 +110,8 @@ begin
        exit;
        exit;
     end;
     end;
   bufidx:=0;
   bufidx:=0;
-  size:=0;
+  fsize:=0;
+  fobjsize:=0;
   opened:=true;
   opened:=true;
   createfile:=true;
   createfile:=true;
 end;
 end;
@@ -123,7 +129,8 @@ begin
   if size=0 then
   if size=0 then
    RemoveFile(fn);
    RemoveFile(fn);
   opened:=false;
   opened:=false;
-  size:=0;
+  fsize:=0;
+  fobjsize:=0;
 end;
 end;
 
 
 
 
@@ -145,7 +152,8 @@ var
   left,
   left,
   idx : longint;
   idx : longint;
 begin
 begin
-  inc(size,len);
+  inc(fsize,len);
+  inc(fobjsize,len);
   p:=pchar(@b);
   p:=pchar(@b);
   idx:=0;
   idx:=0;
   while len>0 do
   while len>0 do
@@ -171,7 +179,7 @@ end;
 
 
 procedure tobjectwriter.WriteZeros(l:longint);
 procedure tobjectwriter.WriteZeros(l:longint);
 var
 var
-  empty : array[0..255] of byte;
+  empty : array[0..1023] of byte;
 begin
 begin
   if l>sizeof(empty) then
   if l>sizeof(empty) then
     internalerror(200404081);
     internalerror(200404081);
@@ -183,6 +191,19 @@ begin
 end;
 end;
 
 
 
 
+procedure tobjectwriter.writearray(a:TDynamicArray);
+var
+  hp : pdynamicblock;
+begin
+  hp:=a.firstblock;
+  while assigned(hp) do
+    begin
+      write(hp^.data,hp^.used);
+      hp:=hp^.next;
+    end;
+end;
+
+
 {****************************************************************************
 {****************************************************************************
                               TObjectReader
                               TObjectReader
 ****************************************************************************}
 ****************************************************************************}
@@ -210,7 +231,7 @@ begin
   f:=TCFileStream.Create(fn,fmOpenRead);
   f:=TCFileStream.Create(fn,fmOpenRead);
   if CStreamError<>0 then
   if CStreamError<>0 then
     begin
     begin
-       Message1(exec_e_cant_create_objectfile,fn);
+       Comment(V_Error,'Can''t open object file: '+fn);
        exit;
        exit;
     end;
     end;
   bufidx:=0;
   bufidx:=0;
@@ -245,7 +266,7 @@ begin
 end;
 end;
 
 
 
 
-function tobjectreader.read(var b;len:longint):boolean;
+function tobjectreader.read(out b;len:longint):boolean;
 var
 var
   p   : pchar;
   p   : pchar;
   left,
   left,

+ 11 - 3
compiler/parser.pas

@@ -140,8 +140,16 @@ implementation
          SetCompileModule(nil);
          SetCompileModule(nil);
 
 
          { unload units }
          { unload units }
-         loaded_units.free;
-         usedunits.free;
+         if assigned(loaded_units) then
+           begin
+             loaded_units.free;
+             loaded_units:=nil;
+           end;
+         if assigned(usedunits) then
+           begin
+             usedunits.free;
+             usedunits:=nil;
+           end;
 
 
          { if there was an error in the scanner, the scanner is
          { if there was an error in the scanner, the scanner is
            still assinged }
            still assinged }
@@ -311,7 +319,7 @@ implementation
         { asmlists }
         { asmlists }
           oldexprasmlist:Taasmoutput;
           oldexprasmlist:Taasmoutput;
           oldasmlist:array[Tasmlist] of Taasmoutput;
           oldasmlist:array[Tasmlist] of Taasmoutput;
-          oldobjectlibrary : tasmlibrarydata;
+          oldobjectlibrary : TObjLibraryData;
         { al_resourcestrings }
         { al_resourcestrings }
           Oldresourcestrings : tresourcestrings;
           Oldresourcestrings : tresourcestrings;
         { akt.. things }
         { akt.. things }

+ 4 - 4
compiler/pdecl.pas

@@ -368,16 +368,16 @@ implementation
     { reads a type declaration to the symbol table }
     { reads a type declaration to the symbol table }
     procedure type_dec;
     procedure type_dec;
 
 
-        function parse_generic_parameters:tsinglelist;
+        function parse_generic_parameters:tlist;
         var
         var
           generictype : ttypesym;
           generictype : ttypesym;
         begin
         begin
-          result:=tsinglelist.create;
+          result:=tlist.create;
           repeat
           repeat
             if token=_ID then
             if token=_ID then
               begin
               begin
                 generictype:=ttypesym.create(orgpattern,cundefinedtype);
                 generictype:=ttypesym.create(orgpattern,cundefinedtype);
-                result.insert(generictype);
+                result.add(generictype);
               end;
               end;
             consume(_ID);
             consume(_ID);
           until not try_to_consume(_COMMA) ;
           until not try_to_consume(_COMMA) ;
@@ -396,7 +396,7 @@ implementation
          isgeneric,
          isgeneric,
          isunique,
          isunique,
          istyperenaming : boolean;
          istyperenaming : boolean;
-         generictypelist : tsinglelist;
+         generictypelist : tlist;
          generictokenbuf : tdynamicarray;
          generictokenbuf : tdynamicarray;
       begin
       begin
          old_block_type:=block_type;
          old_block_type:=block_type;

+ 5 - 5
compiler/pdecobj.pas

@@ -30,7 +30,7 @@ interface
       globtype,symtype,symdef;
       globtype,symtype,symdef;
 
 
     { parses a object declaration }
     { parses a object declaration }
-    function object_dec(const n : stringid;genericdef:tstoreddef;genericlist:tsinglelist;fd : tobjectdef) : tdef;
+    function object_dec(const n : stringid;genericdef:tstoreddef;genericlist:tlist;fd : tobjectdef) : tdef;
 
 
 implementation
 implementation
 
 
@@ -50,7 +50,7 @@ implementation
       current_procinfo = 'error';
       current_procinfo = 'error';
 
 
 
 
-    function object_dec(const n : stringid;genericdef:tstoreddef;genericlist:tsinglelist;fd : tobjectdef) : tdef;
+    function object_dec(const n : stringid;genericdef:tstoreddef;genericlist:tlist;fd : tobjectdef) : tdef;
     { this function parses an object or class declaration }
     { this function parses an object or class declaration }
       var
       var
          there_is_a_destructor : boolean;
          there_is_a_destructor : boolean;
@@ -499,6 +499,7 @@ implementation
       var
       var
         pd : tprocdef;
         pd : tprocdef;
         dummysymoptions : tsymoptions;
         dummysymoptions : tsymoptions;
+        i : longint;
         generictype : ttypesym;
         generictype : ttypesym;
       begin
       begin
          old_object_option:=current_object_option;
          old_object_option:=current_object_option;
@@ -545,15 +546,14 @@ implementation
          aktobjectdef.genericdef:=genericdef;
          aktobjectdef.genericdef:=genericdef;
          if assigned(genericlist) then
          if assigned(genericlist) then
            begin
            begin
-             generictype:=ttypesym(genericlist.first);
-             while assigned(generictype) do
+             for i:=0 to genericlist.count-1 do
                begin
                begin
+                 generictype:=ttypesym(genericlist[i]);
                  if generictype.restype.def.deftype=undefineddef then
                  if generictype.restype.def.deftype=undefineddef then
                    include(aktobjectdef.defoptions,df_generic)
                    include(aktobjectdef.defoptions,df_generic)
                  else
                  else
                    include(aktobjectdef.defoptions,df_specialization);
                    include(aktobjectdef.defoptions,df_specialization);
                  symtablestack.top.insert(generictype);
                  symtablestack.top.insert(generictype);
-                 generictype:=ttypesym(generictype.listnext);
                end;
                end;
            end;
            end;
 
 

+ 31 - 31
compiler/pdecsub.pas

@@ -381,10 +381,11 @@ implementation
       type
       type
         tppv = (pv_none,pv_proc,pv_func);
         tppv = (pv_none,pv_proc,pv_func);
       var
       var
-        sc      : tsinglelist;
+        sc      : tlist;
         tt      : ttype;
         tt      : ttype;
         arrayelementtype : ttype;
         arrayelementtype : ttype;
         vs      : tparavarsym;
         vs      : tparavarsym;
+        i       : longint;
         srsym   : tsym;
         srsym   : tsym;
         pv      : tprocvardef;
         pv      : tprocvardef;
         varspez : Tvarspez;
         varspez : Tvarspez;
@@ -408,7 +409,7 @@ implementation
         { parsing a proc or procvar ? }
         { parsing a proc or procvar ? }
         currparast:=tparasymtable(pd.parast);
         currparast:=tparasymtable(pd.parast);
         { reset }
         { reset }
-        sc:=tsinglelist.create;
+        sc:=tlist.create;
         defaultrequired:=false;
         defaultrequired:=false;
         paranr:=0;
         paranr:=0;
         { the variables are always public }
         { the variables are always public }
@@ -452,13 +453,13 @@ implementation
           defaultvalue:=nil;
           defaultvalue:=nil;
           tt.reset;
           tt.reset;
           { read identifiers and insert with error type }
           { read identifiers and insert with error type }
-          sc.reset;
+          sc.clear;
           repeat
           repeat
             inc(paranr);
             inc(paranr);
             vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrortype,[]);
             vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrortype,[]);
             currparast.insert(vs);
             currparast.insert(vs);
             if assigned(vs.owner) then
             if assigned(vs.owner) then
-             sc.insert(vs)
+             sc.add(vs)
             else
             else
              vs.free;
              vs.free;
             consume(_ID);
             consume(_ID);
@@ -561,8 +562,8 @@ implementation
                  begin
                  begin
                    if try_to_consume(_EQUAL) then
                    if try_to_consume(_EQUAL) then
                     begin
                     begin
-                      vs:=tparavarsym(sc.first);
-                      if assigned(vs.listnext) then
+                      vs:=tparavarsym(sc[0]);
+                      if sc.count>1 then
                         Message(parser_e_default_value_only_one_para);
                         Message(parser_e_default_value_only_one_para);
                       { prefix 'def' to the parameter name }
                       { prefix 'def' to the parameter name }
                       defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
                       defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
@@ -589,32 +590,31 @@ implementation
              not(varspez in [vs_out,vs_var]) then
              not(varspez in [vs_out,vs_var]) then
             CGMessage(cg_e_file_must_call_by_reference);
             CGMessage(cg_e_file_must_call_by_reference);
 
 
-          vs:=tparavarsym(sc.first);
-          while assigned(vs) do
-           begin
-             { update varsym }
-             vs.vartype:=tt;
-             vs.defaultconstsym:=defaultvalue;
+          for i:=0 to sc.count-1 do
+            begin
+              vs:=tparavarsym(sc[i]);
+              { update varsym }
+              vs.vartype:=tt;
+              vs.defaultconstsym:=defaultvalue;
 
 
-             if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
-               begin
-                 if locationstr<>'' then
-                   begin
-                     if assigned(sc.first.listnext) then
-                       Message(parser_e_paraloc_only_one_para);
-                     if (paranr>1) and not(explicit_paraloc) then
-                       Message(parser_e_paraloc_all_paras);
-                     explicit_paraloc:=true;
-                     include(vs.varoptions,vo_has_explicit_paraloc);
-                     if not(paramanager.parseparaloc(vs,upper(locationstr))) then
-                       message(parser_e_illegal_explicit_paraloc);
-                   end
-                 else
-                   if explicit_paraloc then
-                     Message(parser_e_paraloc_all_paras);
-               end;
-             vs:=tparavarsym(vs.listnext);
-           end;
+              if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
+                begin
+                  if locationstr<>'' then
+                    begin
+                      if sc.count>1 then
+                        Message(parser_e_paraloc_only_one_para);
+                      if (paranr>1) and not(explicit_paraloc) then
+                        Message(parser_e_paraloc_all_paras);
+                      explicit_paraloc:=true;
+                      include(vs.varoptions,vo_has_explicit_paraloc);
+                      if not(paramanager.parseparaloc(vs,upper(locationstr))) then
+                        message(parser_e_illegal_explicit_paraloc);
+                    end
+                  else
+                    if explicit_paraloc then
+                      Message(parser_e_paraloc_all_paras);
+                end;
+            end;
         until not try_to_consume(_SEMICOLON);
         until not try_to_consume(_SEMICOLON);
 
 
         if explicit_paraloc then
         if explicit_paraloc then

+ 56 - 57
compiler/pdecvar.pas

@@ -214,8 +214,9 @@ implementation
          arraytype : ttype;
          arraytype : ttype;
          def : tdef;
          def : tdef;
          pt : tnode;
          pt : tnode;
-         sc : tsinglelist;
+         sc : tlist;
          paranr : word;
          paranr : word;
+         i      : longint;
          hreadparavs,
          hreadparavs,
          hparavs      : tparavarsym;
          hparavs      : tparavarsym;
          readprocdef,
          readprocdef,
@@ -251,7 +252,7 @@ implementation
                 Message(parser_e_cant_publish_that_property);
                 Message(parser_e_cant_publish_that_property);
               { create a list of the parameters }
               { create a list of the parameters }
               symtablestack.push(readprocdef.parast);
               symtablestack.push(readprocdef.parast);
-              sc:=tsinglelist.create;
+              sc:=tlist.create;
               inc(testcurobject);
               inc(testcurobject);
               repeat
               repeat
                 if try_to_consume(_VAR) then
                 if try_to_consume(_VAR) then
@@ -262,12 +263,12 @@ implementation
                   varspez:=vs_out
                   varspez:=vs_out
                 else
                 else
                   varspez:=vs_value;
                   varspez:=vs_value;
-                sc.reset;
+                sc.clear;
                 repeat
                 repeat
                   inc(paranr);
                   inc(paranr);
                   hreadparavs:=tparavarsym.create(orgpattern,10*paranr,varspez,generrortype,[]);
                   hreadparavs:=tparavarsym.create(orgpattern,10*paranr,varspez,generrortype,[]);
                   readprocdef.parast.insert(hreadparavs);
                   readprocdef.parast.insert(hreadparavs);
-                  sc.insert(hreadparavs);
+                  sc.add(hreadparavs);
                   consume(_ID);
                   consume(_ID);
                 until not try_to_consume(_COMMA);
                 until not try_to_consume(_COMMA);
                 if try_to_consume(_COLON) then
                 if try_to_consume(_COLON) then
@@ -286,14 +287,13 @@ implementation
                   end
                   end
                 else
                 else
                   tt:=cformaltype;
                   tt:=cformaltype;
-                hreadparavs:=tparavarsym(sc.first);
-                while assigned(hreadparavs) do
+                for i:=0 to sc.count-1 do
                   begin
                   begin
+                    hreadparavs:=tparavarsym(sc[i]);
                     hreadparavs.vartype:=tt;
                     hreadparavs.vartype:=tt;
                     { also update the writeprocdef }
                     { also update the writeprocdef }
                     hparavs:=tparavarsym.create(hreadparavs.realname,hreadparavs.paranr,vs_value,tt,[]);
                     hparavs:=tparavarsym.create(hreadparavs.realname,hreadparavs.paranr,vs_value,tt,[]);
                     writeprocdef.parast.insert(hparavs);
                     writeprocdef.parast.insert(hparavs);
-                    hreadparavs:=tparavarsym(hreadparavs.listnext);
                   end;
                   end;
               until not try_to_consume(_SEMICOLON);
               until not try_to_consume(_SEMICOLON);
               sc.free;
               sc.free;
@@ -586,13 +586,13 @@ implementation
 
 
     procedure read_var_decls(options:Tvar_dec_options);
     procedure read_var_decls(options:Tvar_dec_options);
 
 
-      procedure read_default_value(sc : tsinglelist;tt : ttype;is_threadvar : boolean);
+      procedure read_default_value(sc : tlist;tt : ttype;is_threadvar : boolean);
         var
         var
           vs : tabstractnormalvarsym;
           vs : tabstractnormalvarsym;
           tcsym : ttypedconstsym;
           tcsym : ttypedconstsym;
         begin
         begin
-          vs:=tabstractnormalvarsym(sc.first);
-          if assigned(vs.listnext) then
+          vs:=tabstractnormalvarsym(sc[0]);
+          if sc.count>1 then
              Message(parser_e_initialized_only_one_var);
              Message(parser_e_initialized_only_one_var);
           if is_threadvar then
           if is_threadvar then
              Message(parser_e_initialized_not_for_threadvar);
              Message(parser_e_initialized_not_for_threadvar);
@@ -619,7 +619,8 @@ implementation
         end;
         end;
 
 
       var
       var
-         sc : tsinglelist;
+         sc : tlist;
+         i  : longint;
          old_block_type : tblock_type;
          old_block_type : tblock_type;
          symdone : boolean;
          symdone : boolean;
          { to handle absolute }
          { to handle absolute }
@@ -647,14 +648,14 @@ implementation
          if not (token in [_ID,_CASE,_END]) then
          if not (token in [_ID,_CASE,_END]) then
            consume(_ID);
            consume(_ID);
          { read vars }
          { read vars }
-         sc:=tsinglelist.create;
+         sc:=tlist.create;
          while (token=_ID) do
          while (token=_ID) do
            begin
            begin
              sorg:=orgpattern;
              sorg:=orgpattern;
              semicoloneaten:=false;
              semicoloneaten:=false;
              hasdefaultvalue:=false;
              hasdefaultvalue:=false;
              symdone:=false;
              symdone:=false;
-             sc.reset;
+             sc.clear;
              repeat
              repeat
                if (token = _ID) then
                if (token = _ID) then
                  begin
                  begin
@@ -667,7 +668,7 @@ implementation
                      else
                      else
                        internalerror(200411064);
                        internalerror(200411064);
                    end;
                    end;
-                   sc.insert(vs);
+                   sc.add(vs);
                    symtablestack.top.insert(vs);
                    symtablestack.top.insert(vs);
                  end;
                  end;
                consume(_ID);
                consume(_ID);
@@ -695,8 +696,8 @@ implementation
 
 
              if is_gpc_name then
              if is_gpc_name then
                begin
                begin
-                  vs:=tabstractvarsym(sc.first);
-                  if assigned(vs.listnext) then
+                  vs:=tabstractvarsym(sc[0]);
+                  if sc.count>1 then
                     Message(parser_e_absolute_only_one_var);
                     Message(parser_e_absolute_only_one_var);
                   vs.vartype:=tt;
                   vs.vartype:=tt;
                   if vs.typ=globalvarsym then
                   if vs.typ=globalvarsym then
@@ -716,8 +717,8 @@ implementation
               begin
               begin
                 abssym:=nil;
                 abssym:=nil;
                 { only allowed for one var }
                 { only allowed for one var }
-                vs:=tabstractvarsym(sc.first);
-                if assigned(vs.listnext) then
+                vs:=tabstractvarsym(sc[0]);
+                if sc.count>1 then
                   Message(parser_e_absolute_only_one_var);
                   Message(parser_e_absolute_only_one_var);
                 { parse the rest }
                 { parse the rest }
                 pt:=expr;
                 pt:=expr;
@@ -863,8 +864,8 @@ implementation
                    ) then
                    ) then
                  begin
                  begin
                    { only allowed for one var }
                    { only allowed for one var }
-                   vs:=tabstractvarsym(sc.first);
-                   if assigned(vs.listnext) then
+                   vs:=tabstractvarsym(sc[0]);
+                   if sc.count>1 then
                      Message(parser_e_absolute_only_one_var);
                      Message(parser_e_absolute_only_one_var);
                    { set type of the var }
                    { set type of the var }
                    vs.vartype:=tt;
                    vs.vartype:=tt;
@@ -988,19 +989,18 @@ implementation
              { insert it in the symtable, if not done yet }
              { insert it in the symtable, if not done yet }
              if not symdone then
              if not symdone then
                begin
                begin
-                  vs:=tabstractvarsym(sc.first);
-                  while assigned(vs) do
-                    begin
-                       vs.vartype:=tt;
-                       { insert any additional hint directives }
-                       vs.symoptions := vs.symoptions + hintsymoptions;
-                       if vd_threadvar in options then
-                         include(vs.varoptions,vo_is_thread_var);
-                       { static data fields are inserted in the globalsymtable }
-                       if vs.typ=globalvarsym then
-                         insertbssdata(tglobalvarsym(vs));
-                       vs:=tabstractvarsym(vs.listnext);
-                    end;
+                 for i:=0 to sc.count-1 do
+                   begin
+                     vs:=tabstractvarsym(sc[i]);
+                     vs.vartype:=tt;
+                     { insert any additional hint directives }
+                     vs.symoptions := vs.symoptions + hintsymoptions;
+                     if vd_threadvar in options then
+                       include(vs.varoptions,vo_is_thread_var);
+                     { static data fields are inserted in the globalsymtable }
+                     if vs.typ=globalvarsym then
+                       insertbssdata(tglobalvarsym(vs));
+                   end;
                end;
                end;
            end;
            end;
          block_type:=old_block_type;
          block_type:=old_block_type;
@@ -1012,7 +1012,8 @@ implementation
 
 
     procedure read_record_fields(options:Tvar_dec_options);
     procedure read_record_fields(options:Tvar_dec_options);
       var
       var
-         sc : tsinglelist;
+         sc : tlist;
+         i  : longint;
          old_block_type : tblock_type;
          old_block_type : tblock_type;
          old_current_object_option : tsymoptions;
          old_current_object_option : tsymoptions;
          hs,sorg : string;
          hs,sorg : string;
@@ -1056,19 +1057,19 @@ implementation
          if not (token in [_ID,_CASE,_END]) then
          if not (token in [_ID,_CASE,_END]) then
           consume(_ID);
           consume(_ID);
          { read vars }
          { read vars }
-         sc:=tsinglelist.create;
+         sc:=tlist.create;
          while (token=_ID) and
          while (token=_ID) and
             not((vd_object in options) and
             not((vd_object in options) and
                 (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED,_STRICT])) do
                 (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED,_STRICT])) do
            begin
            begin
              sorg:=orgpattern;
              sorg:=orgpattern;
              semicoloneaten:=false;
              semicoloneaten:=false;
-             sc.reset;
+             sc.clear;
              repeat
              repeat
                if try_to_consume(_ID) then
                if try_to_consume(_ID) then
                  begin
                  begin
                    vs:=tfieldvarsym.create(orgpattern,vs_value,generrortype,[]);
                    vs:=tfieldvarsym.create(orgpattern,vs_value,generrortype,[]);
-                   sc.insert(vs);
+                   sc.add(vs);
                    recst.insert(vs);
                    recst.insert(vs);
                  end;
                  end;
              until not try_to_consume(_COMMA);
              until not try_to_consume(_COMMA);
@@ -1156,12 +1157,11 @@ implementation
                  Message(parser_e_cant_publish_that);
                  Message(parser_e_cant_publish_that);
                  exclude(current_object_option,sp_published);
                  exclude(current_object_option,sp_published);
                  { recover by changing access type to public }
                  { recover by changing access type to public }
-                 fieldvs:=tfieldvarsym(sc.first);
-                 while assigned (fieldvs) do
+                 for i:=0 to sc.count-1 do
                    begin
                    begin
+                     fieldvs:=tfieldvarsym(sc[i]);
                      exclude(fieldvs.symoptions,sp_published);
                      exclude(fieldvs.symoptions,sp_published);
                      include(fieldvs.symoptions,sp_public);
                      include(fieldvs.symoptions,sp_public);
-                     fieldvs:=tfieldvarsym(fieldvs.listnext);
                    end;
                    end;
                end
                end
              else
              else
@@ -1173,24 +1173,23 @@ implementation
                end;
                end;
 
 
              { update variable options }
              { update variable options }
-             fieldvs:=tfieldvarsym(sc.first);
-             while assigned(fieldvs) do
+             for i:=0 to sc.count-1 do
                begin
                begin
-                  fieldvs.vartype:=tt;
-                  { insert any additional hint directives }
-                  fieldvs.symoptions := fieldvs.symoptions + hintsymoptions;
-                  if (sp_static in current_object_option) then
-                    include(fieldvs.symoptions,sp_static);
-                  { static data fields are inserted in the globalsymtable }
-                  if (sp_static in current_object_option) then
-                    begin
-                       hstaticvs:=tglobalvarsym.create('$'+lower(symtablestack.top.name^)+'_'+fieldvs.name,vs_value,tt,[]);
-                       recst.defowner.owner.insert(hstaticvs);
-                       insertbssdata(hstaticvs);
-                    end
-                  else
-                    recst.addfield(fieldvs);
-                  fieldvs:=tfieldvarsym(fieldvs.listnext);
+                 fieldvs:=tfieldvarsym(sc[i]);
+                 fieldvs.vartype:=tt;
+                 { insert any additional hint directives }
+                 fieldvs.symoptions := fieldvs.symoptions + hintsymoptions;
+                 if (sp_static in current_object_option) then
+                   include(fieldvs.symoptions,sp_static);
+                 { static data fields are inserted in the globalsymtable }
+                 if (sp_static in current_object_option) then
+                   begin
+                      hstaticvs:=tglobalvarsym.create('$'+lower(symtablestack.top.name^)+'_'+fieldvs.name,vs_value,tt,[]);
+                      recst.defowner.owner.insert(hstaticvs);
+                      insertbssdata(hstaticvs);
+                   end
+                 else
+                   recst.addfield(fieldvs);
                end;
                end;
 
 
              { restore current_object_option, it can be changed for
              { restore current_object_option, it can be changed for

+ 37 - 23
compiler/pmodules.pas

@@ -135,11 +135,17 @@ implementation
 
 
     procedure create_dwarf;
     procedure create_dwarf;
       begin
       begin
-        asmlist[al_dwarf]:=taasmoutput.create;
+        { Dwarf conflicts with smartlinking in separate .a files }
+        if (cs_create_smart in aktmoduleswitches) and
+           not use_smartlink_section then
+          exit;
         { Call frame information }
         { Call frame information }
         if (tf_needs_dwarf_cfi in target_info.flags) and
         if (tf_needs_dwarf_cfi in target_info.flags) and
            (af_supports_dwarf in target_asm.flags) then
            (af_supports_dwarf in target_asm.flags) then
-          dwarfcfi.generate_code(asmlist[al_dwarf]);
+          begin
+            asmlist[al_dwarf]:=taasmoutput.create;
+            dwarfcfi.generate_code(asmlist[al_dwarf]);
+          end;
       end;
       end;
 
 
 
 
@@ -1438,27 +1444,35 @@ implementation
             exit;
             exit;
           end;
           end;
 
 
-         { create the executable when we are at level 1 }
-         if (compile_level=1) then
-          begin
-            { insert all .o files from all loaded units }
-            hp:=tmodule(loaded_units.first);
-            while assigned(hp) do
-             begin
-               linker.AddModuleFiles(hp);
-               hp:=tmodule(hp.next);
-             end;
-            { write .def file }
-            if (cs_link_deffile in aktglobalswitches) then
-             deffile.writefile;
-            { finally we can create a executable }
-            if (not current_module.is_unit) then
-             begin
-               if DLLSource then
-                 linker.MakeSharedLibrary
-               else
-                 linker.MakeExecutable;
-             end;
+         if (not current_module.is_unit) then
+           begin
+             { create the executable when we are at level 1 }
+             if (compile_level=1) then
+               begin
+                 { write .def file }
+                 if (cs_link_deffile in aktglobalswitches) then
+                  deffile.writefile;
+                 { insert all .o files from all loaded units and
+                   unload the units, we don't need them anymore.
+                   Keep the current_module because that is still needed }
+                 hp:=tmodule(loaded_units.first);
+                 while assigned(hp) do
+                  begin
+                    linker.AddModuleFiles(hp);
+                    hp2:=tmodule(hp.next);
+                    if hp<>current_module then
+                      begin
+                        loaded_units.remove(hp);
+                        hp.free;
+                      end;
+                    hp:=hp2;
+                  end;
+                 { finally we can create a executable }
+                 if DLLSource then
+                   linker.MakeSharedLibrary
+                 else
+                   linker.MakeExecutable;
+               end;
           end;
           end;
       end;
       end;
 
 

+ 2 - 2
compiler/powerpc/agppcgas.pas

@@ -38,7 +38,7 @@ unit agppcgas;
     type
     type
       PPPCGNUAssembler=^TPPCGNUAssembler;
       PPPCGNUAssembler=^TPPCGNUAssembler;
       TPPCGNUAssembler=class(TGNUassembler)
       TPPCGNUAssembler=class(TGNUassembler)
-        function sectionname(atype:tasmsectiontype;const aname:string):string;override;
+        function sectionname(atype:TAsmSectiontype;const aname:string):string;override;
         procedure WriteExtraHeader;override;
         procedure WriteExtraHeader;override;
         procedure WriteInstruction(hp : tai);override;
         procedure WriteInstruction(hp : tai);override;
        private
        private
@@ -102,7 +102,7 @@ unit agppcgas;
 
 
 
 
 
 
-    function TPPCGNUAssembler.sectionname(atype:tasmsectiontype;const aname:string):string;
+    function TPPCGNUAssembler.sectionname(atype:TAsmSectiontype;const aname:string):string;
       begin
       begin
         if (target_info.system = system_powerpc_darwin) then
         if (target_info.system = system_powerpc_darwin) then
           case atype of
           case atype of

+ 2 - 2
compiler/powerpc/agppcmpw.pas

@@ -67,7 +67,7 @@ interface
       const_storage_class = '';
       const_storage_class = '';
       var_storage_class = '';
       var_storage_class = '';
 
 
-      secnames : array[TAsmSectionType] of string[10] = (
+      secnames : array[TAsmSectiontype] of string[10] = (
         '',      {none}
         '',      {none}
         'csect', {code}
         'csect', {code}
         'csect', {data}
         'csect', {data}
@@ -662,7 +662,7 @@ interface
     end;
     end;
 
 
     var
     var
-      LasTSec : TAsmSectionType;
+      LasTSec : TAsmSectiontype;
       lastfileinfo : tfileposinfo;
       lastfileinfo : tfileposinfo;
       infile,
       infile,
       lastinfile   : tinputfile;
       lastinfile   : tinputfile;

+ 1 - 1
compiler/ppu.pas

@@ -121,7 +121,7 @@ const
   ibwidestringdef  = 56;
   ibwidestringdef  = 56;
   ibvariantdef     = 57;
   ibvariantdef     = 57;
   ibundefineddef   = 58;
   ibundefineddef   = 58;
-  {implementation/objectdata}
+  {implementation/ObjData}
   ibnodetree       = 80;
   ibnodetree       = 80;
   ibasmsymbols     = 81;
   ibasmsymbols     = 81;
 
 

+ 1 - 1
compiler/ptconst.pas

@@ -83,7 +83,7 @@ implementation
          error     : boolean;
          error     : boolean;
          old_block_type : tblock_type;
          old_block_type : tblock_type;
          storefilepos : tfileposinfo;
          storefilepos : tfileposinfo;
-         cursectype : TAsmSectionType;
+         cursectype : TAsmSectiontype;
          cural : tasmlist;
          cural : tasmlist;
          sizelabel : tasmlabel;
          sizelabel : tasmlabel;
 
 

+ 5 - 5
compiler/ptype.pas

@@ -41,7 +41,7 @@ interface
     { tdef }
     { tdef }
     procedure single_type(var tt:ttype;isforwarddef:boolean);
     procedure single_type(var tt:ttype;isforwarddef:boolean);
 
 
-    procedure read_named_type(var tt:ttype;const name : stringid;genericdef:tstoreddef;genericlist:tsinglelist;parseprocvardir:boolean);
+    procedure read_named_type(var tt:ttype;const name : stringid;genericdef:tstoreddef;genericlist:tlist;parseprocvardir:boolean);
     procedure read_anon_type(var tt : ttype;parseprocvardir:boolean);
     procedure read_anon_type(var tt : ttype;parseprocvardir:boolean);
 
 
     { reads a type definition }
     { reads a type definition }
@@ -80,7 +80,7 @@ implementation
         sym : tsym;
         sym : tsym;
         genericdef : tstoreddef;
         genericdef : tstoreddef;
         generictype : ttypesym;
         generictype : ttypesym;
-        generictypelist : tsinglelist;
+        generictypelist : tlist;
       begin
       begin
         { retrieve generic def that we are going to replace }
         { retrieve generic def that we are going to replace }
         genericdef:=tstoreddef(pt1.resulttype.def);
         genericdef:=tstoreddef(pt1.resulttype.def);
@@ -104,7 +104,7 @@ implementation
           the genericdef we need to have a new def }
           the genericdef we need to have a new def }
         err:=false;
         err:=false;
         first:=true;
         first:=true;
-        generictypelist:=tsinglelist.create;
+        generictypelist:=tlist.create;
         case genericdef.deftype of
         case genericdef.deftype of
           procdef :
           procdef :
             st:=genericdef.getsymtable(gs_para);
             st:=genericdef.getsymtable(gs_para);
@@ -129,7 +129,7 @@ implementation
                 if pt2.nodetype=typen then
                 if pt2.nodetype=typen then
                   begin
                   begin
                     generictype:=ttypesym.create(sym.realname,pt2.resulttype);
                     generictype:=ttypesym.create(sym.realname,pt2.resulttype);
-                    generictypelist.insert(generictype);
+                    generictypelist.add(generictype);
                   end
                   end
                 else
                 else
                   begin
                   begin
@@ -321,7 +321,7 @@ implementation
 
 
 
 
     { reads a type definition and returns a pointer to it }
     { reads a type definition and returns a pointer to it }
-    procedure read_named_type(var tt : ttype;const name : stringid;genericdef:tstoreddef;genericlist:tsinglelist;parseprocvardir:boolean);
+    procedure read_named_type(var tt : ttype;const name : stringid;genericdef:tstoreddef;genericlist:tlist;parseprocvardir:boolean);
       var
       var
         pt : tnode;
         pt : tnode;
         tt2 : ttype;
         tt2 : ttype;

+ 1 - 1
compiler/raatt.pas

@@ -948,7 +948,7 @@ unit raatt;
      Var
      Var
        hl         : tasmlabel;
        hl         : tasmlabel;
        commname   : string;
        commname   : string;
-       lasTSec    : TAsmSectionType;
+       lasTSec    : TAsmSectiontype;
        l1,l2      : longint;
        l1,l2      : longint;
      Begin
      Begin
        Message1(asmr_d_start_reading,'GNU AS');
        Message1(asmr_d_start_reading,'GNU AS');

+ 19 - 5
compiler/symbase.pas

@@ -84,8 +84,9 @@ interface
        psearchhasharray = ^tsearchhasharray;
        psearchhasharray = ^tsearchhasharray;
 
 
        tsymtable = class
        tsymtable = class
-{$ifdef EXTDEBUG}
        private
        private
+          clearing   : boolean;
+{$ifdef EXTDEBUG}
           procedure dumpsym(p : TNamedIndexItem;arg:pointer);
           procedure dumpsym(p : TNamedIndexItem;arg:pointer);
 {$endif EXTDEBUG}
 {$endif EXTDEBUG}
        public
        public
@@ -115,6 +116,7 @@ interface
           function  search(const s : stringid) : tsymentry;
           function  search(const s : stringid) : tsymentry;
           function  speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;virtual;
           function  speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;virtual;
           procedure insertdef(def:tdefentry);virtual;
           procedure insertdef(def:tdefentry);virtual;
+          procedure deletedef(def:tdefentry);virtual;
           function  iscurrentunit:boolean;virtual;
           function  iscurrentunit:boolean;virtual;
 {$ifdef EXTDEBUG}
 {$ifdef EXTDEBUG}
           procedure dump;
           procedure dump;
@@ -169,16 +171,15 @@ implementation
         { freeinstance decreases refcount }
         { freeinstance decreases refcount }
         if refcount>1 then
         if refcount>1 then
           exit;
           exit;
-        stringdispose(name);
-        stringdispose(realname);
-        symindex.destroy;
-        defindex.destroy;
         { symsearch can already be disposed or set to nil for withsymtable }
         { symsearch can already be disposed or set to nil for withsymtable }
         if assigned(symsearch) then
         if assigned(symsearch) then
          begin
          begin
            symsearch.destroy;
            symsearch.destroy;
            symsearch:=nil;
            symsearch:=nil;
          end;
          end;
+        clear;
+        stringdispose(name);
+        stringdispose(realname);
       end;
       end;
 
 
 
 
@@ -239,8 +240,10 @@ implementation
 
 
     procedure tsymtable.clear;
     procedure tsymtable.clear;
       begin
       begin
+         clearing:=true;
          symindex.clear;
          symindex.clear;
          defindex.clear;
          defindex.clear;
+         clearing:=false;
       end;
       end;
 
 
 
 
@@ -267,6 +270,17 @@ implementation
       end;
       end;
 
 
 
 
+    procedure tsymtable.deletedef(def:tdefentry);
+      begin
+        { if we are already clearing everything it will already
+          be deleted }
+        if clearing then
+          exit;
+        defindex.deleteindex(def);
+        def.owner:=nil;
+      end;
+
+
     procedure tsymtable.delete(sym:tsymentry);
     procedure tsymtable.delete(sym:tsymentry);
       begin
       begin
          sym.owner:=nil;
          sym.owner:=nil;

+ 3 - 2
compiler/symdef.pas

@@ -925,7 +925,7 @@ implementation
       begin
       begin
         { remove also index from symtable }
         { remove also index from symtable }
         if assigned(owner) then
         if assigned(owner) then
-          owner.defindex.deleteindex(self);
+          owner.deletedef(self);
         if assigned(generictokenbuf) then
         if assigned(generictokenbuf) then
           generictokenbuf.free;
           generictokenbuf.free;
         inherited destroy;
         inherited destroy;
@@ -2519,7 +2519,7 @@ implementation
              is_object(elementtype.def)) then
              is_object(elementtype.def)) then
            alignment:=elementtype.def.alignment
            alignment:=elementtype.def.alignment
          else
          else
-           alignment:=elesize;
+           alignment:=size_2_align(elesize);
       end;
       end;
 
 
 
 
@@ -5029,6 +5029,7 @@ implementation
 ****************************************************************************}
 ****************************************************************************}
     type
     type
       tnamemap = class(TNamedIndexItem)
       tnamemap = class(TNamedIndexItem)
+        listnext : TNamedIndexItem;
         newname: pstring;
         newname: pstring;
         constructor create(const aname, anewname: string);
         constructor create(const aname, anewname: string);
         destructor  destroy; override;
         destructor  destroy; override;

+ 1 - 1
compiler/symtable.pas

@@ -904,7 +904,7 @@ implementation
         l      : aint;
         l      : aint;
         varalignrecord,
         varalignrecord,
         varalignfield,
         varalignfield,
-        varalign : longint;
+        varalign : shortint;
         vardef : tdef;
         vardef : tdef;
       begin
       begin
         if (sym.owner<>self) then
         if (sym.owner<>self) then

+ 3 - 12
compiler/symtype.pas

@@ -1257,7 +1257,8 @@ implementation
 
 
     function  tcompilerppufile.getasmsymbol:tasmsymbol;
     function  tcompilerppufile.getasmsymbol:tasmsymbol;
       begin
       begin
-        getasmsymbol:=tasmsymbol(pointer(ptrint(getlongint)));
+        getlongint;
+        getasmsymbol:=nil;
       end;
       end;
 
 
 
 
@@ -1418,17 +1419,7 @@ implementation
 
 
     procedure tcompilerppufile.putasmsymbol(s:tasmsymbol);
     procedure tcompilerppufile.putasmsymbol(s:tasmsymbol);
       begin
       begin
-        if assigned(s) then
-         begin
-           if s.ppuidx=-1 then
-            begin
-              inc(objectlibrary.asmsymbolppuidx);
-              s.ppuidx:=objectlibrary.asmsymbolppuidx;
-            end;
-           putlongint(s.ppuidx);
-         end
-        else
-         putlongint(0);
+        putlongint(0);
       end;
       end;
 
 
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}

+ 1 - 1
compiler/systems/t_go32v2.pas

@@ -357,6 +357,6 @@ end;
 
 
 initialization
 initialization
   RegisterExternalLinker(system_i386_go32v2_info,TLinkerGo32v2);
   RegisterExternalLinker(system_i386_go32v2_info,TLinkerGo32v2);
-  RegisterInternalLinker(system_i386_go32v2_info,TCoffLinker);
+  RegisterInternalLinker(system_i386_go32v2_info,TDJCoffLinker);
   RegisterTarget(system_i386_go32v2_info);
   RegisterTarget(system_i386_go32v2_info);
 end.
 end.

+ 9 - 41
compiler/systems/t_linux.pas

@@ -463,7 +463,7 @@ begin
   linkres.add('ENTRY(_start)');
   linkres.add('ENTRY(_start)');
 
 
   {Sections.}
   {Sections.}
-{
+{$ifdef OwnLDScript}
   commented out because it cause problems on several machines with different ld versions (FK)
   commented out because it cause problems on several machines with different ld versions (FK)
   linkres.add('SECTIONS');
   linkres.add('SECTIONS');
   linkres.add('{');
   linkres.add('{');
@@ -561,7 +561,7 @@ begin
   linkres.add('  .stab          0 : { *(.stab) }');
   linkres.add('  .stab          0 : { *(.stab) }');
   linkres.add('  .stabstr       0 : { *(.stabstr) }');
   linkres.add('  .stabstr       0 : { *(.stabstr) }');
   linkres.add('}');
   linkres.add('}');
-}
+{$endif OwnLDScript}
 
 
 { Write and Close response }
 { Write and Close response }
   LinkRes.writetodisk;
   LinkRes.writetodisk;
@@ -571,23 +571,6 @@ begin
 end;
 end;
 
 
 
 
-function contains_exports : boolean;
-  var
-    hp : tused_unit;
-  begin
-    result:=((current_module.flags and uf_has_exports)=uf_has_exports);
-    if not result then
-      begin
-      hp:=tused_unit(usedunits.first);
-      While Assigned(hp) and not result do
-        begin
-          result:=((hp.u.flags and uf_has_exports)=uf_has_exports);
-          hp:=tused_unit(hp.next);
-        end;
-      end;
-  end;
-
-
 function TLinkerLinux.MakeExecutable:boolean;
 function TLinkerLinux.MakeExecutable:boolean;
 var
 var
   binstr : String;
   binstr : String;
@@ -636,7 +619,7 @@ begin
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
 
 
   { create dynamic symbol table? }
   { create dynamic symbol table? }
-  if contains_exports then
+  if HasExports then
     cmdstr:=cmdstr+' -E';
     cmdstr:=cmdstr+' -E';
 
 
   success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
   success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false);
@@ -701,32 +684,17 @@ begin
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
 end;
 end;
 
 
-function tlinkerLinux.postprocessexecutable(const fn : string;isdll:boolean):boolean;
 
 
-Var
+function tlinkerLinux.postprocessexecutable(const fn : string;isdll:boolean):boolean;
+var
   cmdstr: string;
   cmdstr: string;
-  found : boolean;
-  hp    : tused_unit;
-
 begin
 begin
-  postprocessexecutable:=True;
-  if target_res.id=res_elf then
+  result:=True;
+  if HasResources and
+     (target_res.id=res_elf) then
     begin
     begin
-    found:=((current_module.flags and uf_has_resourcefiles)=uf_has_resourcefiles);
-    if not found then
-      begin
-      hp:=tused_unit(usedunits.first);
-      While Assigned(hp) and not Found do
-        begin
-        Found:=((hp.u.flags and uf_has_resourcefiles)=uf_has_resourcefiles);
-        hp:=tused_unit(hp.next);
-        end;
-      end;
-    if found then
-      begin
       cmdstr:=' -f -i '+maybequoted(fn);
       cmdstr:=' -f -i '+maybequoted(fn);
-      postprocessexecutable:=DoExec(FindUtil(utilsprefix+'fpcres'),cmdstr,false,false);
-      end;
+      result:=DoExec(FindUtil(utilsprefix+'fpcres'),cmdstr,false,false);
     end;
     end;
 end;
 end;
 
 

+ 2 - 1
compiler/systems/t_win.pas

@@ -31,7 +31,7 @@ interface
        symconst,symdef,symsym,
        symconst,symdef,symsym,
        script,gendef,
        script,gendef,
        cpubase,
        cpubase,
-       import,export,link,cgobj,i_win;
+       import,export,link,cgobj,i_win,ogcoff;
 
 
 
 
   const
   const
@@ -1662,6 +1662,7 @@ function tDLLScannerWin32.scan(const binname:string):longbool;
 initialization
 initialization
 {$ifdef i386}
 {$ifdef i386}
   RegisterExternalLinker(system_i386_win32_info,TLinkerWin32);
   RegisterExternalLinker(system_i386_win32_info,TLinkerWin32);
+  RegisterInternalLinker(system_i386_win32_info,TPECoffLinker);
   RegisterImport(system_i386_win32,TImportLibWin32);
   RegisterImport(system_i386_win32,TImportLibWin32);
   RegisterExport(system_i386_win32,TExportLibWin32);
   RegisterExport(system_i386_win32,TExportLibWin32);
   RegisterDLLScanner(system_i386_win32,TDLLScannerWin32);
   RegisterDLLScanner(system_i386_win32,TDLLScannerWin32);

+ 2 - 0
compiler/verbose.pas

@@ -799,6 +799,8 @@ var
         FillChar(Status,sizeof(TCompilerStatus),0);
         FillChar(Status,sizeof(TCompilerStatus),0);
         status.verbosity:=V_Default;
         status.verbosity:=V_Default;
         Status.MaxErrorCount:=50;
         Status.MaxErrorCount:=50;
+        Status.codesize:=-1;
+        Status.datasize:=-1;
         Loadprefixes;
         Loadprefixes;
         lastfileidx:=-1;
         lastfileidx:=-1;
         lastmoduleidx:=-1;
         lastmoduleidx:=-1;

+ 51 - 46
compiler/x86/aasmcpu.pas

@@ -34,7 +34,8 @@ interface
       cpubase,
       cpubase,
       cgbase,cgutils,
       cgbase,cgutils,
       symtype,
       symtype,
-      aasmbase,aasmtai;
+      aasmbase,aasmtai,
+      ogbase;
 
 
     const
     const
       { "mov reg,reg" source operand number }
       { "mov reg,reg" source operand number }
@@ -238,8 +239,8 @@ interface
          procedure ResetPass1;
          procedure ResetPass1;
          procedure ResetPass2;
          procedure ResetPass2;
          function  CheckIfValid:boolean;
          function  CheckIfValid:boolean;
-         function  Pass1(offset:longint):longint;override;
-         procedure Pass2(objdata:TAsmObjectdata);override;
+         function  Pass1(objdata:TObjData):longint;override;
+         procedure Pass2(objdata:TObjData);override;
          procedure SetOperandOrder(order:TOperandOrder);
          procedure SetOperandOrder(order:TOperandOrder);
          function is_same_reg_move(regtype: Tregistertype):boolean;override;
          function is_same_reg_move(regtype: Tregistertype):boolean;override;
          { register spilling code }
          { register spilling code }
@@ -256,13 +257,13 @@ interface
          LastInsOffset : longint; { need to be public to be reset }
          LastInsOffset : longint; { need to be public to be reset }
          insentry  : PInsEntry;
          insentry  : PInsEntry;
          function  InsEnd:longint;
          function  InsEnd:longint;
-         procedure create_ot;
+         procedure create_ot(objdata:TObjData);
          function  Matches(p:PInsEntry):longint;
          function  Matches(p:PInsEntry):longint;
          function  calcsize(p:PInsEntry):shortint;
          function  calcsize(p:PInsEntry):shortint;
-         procedure gencode(objdata:TAsmObjectData);
+         procedure gencode(objdata:TObjData);
          function  NeedAddrPrefix(opidx:byte):boolean;
          function  NeedAddrPrefix(opidx:byte):boolean;
          procedure Swapoperands;
          procedure Swapoperands;
-         function  FindInsentry:boolean;
+         function  FindInsentry(objdata:TObjData):boolean;
     {$endif NOAG386BIN}
     {$endif NOAG386BIN}
       end;
       end;
 
 
@@ -906,10 +907,6 @@ implementation
         case o.typ of
         case o.typ of
           top_ref :
           top_ref :
             begin
             begin
-              if assigned(o.ref^.symbol) then
-                objectlibrary.derefasmsymbol(o.ref^.symbol);
-              if assigned(o.ref^.relsymbol) then
-                objectlibrary.derefasmsymbol(o.ref^.relsymbol);
             end;
             end;
           top_local :
           top_local :
             o.localoper^.localsym:=tlocalvarsym(o.localoper^.localsymderef.resolve);
             o.localoper^.localsym:=tlocalvarsym(o.localoper^.localsymderef.resolve);
@@ -987,12 +984,13 @@ implementation
         sib   : byte;
         sib   : byte;
       end;
       end;
 
 
-    procedure taicpu.create_ot;
+    procedure taicpu.create_ot(objdata:TObjData);
       {
       {
         this function will also fix some other fields which only needs to be once
         this function will also fix some other fields which only needs to be once
       }
       }
       var
       var
         i,l,relsize : longint;
         i,l,relsize : longint;
+        currsym : TObjSymbol;
       begin
       begin
         if ops=0 then
         if ops=0 then
          exit;
          exit;
@@ -1025,26 +1023,32 @@ implementation
                     end
                     end
                   else
                   else
                     begin
                     begin
-                      l:=ref^.offset;
-                      if assigned(ref^.symbol) then
-                       inc(l,ref^.symbol.address);
-                      { when it is a forward jump we need to compensate the
-                        offset of the instruction since the previous time,
-                        because the symbol address is then still using the
-                        'old-style' addressing.
-                        For backwards jumps this is not required because the
-                        address of the symbol is already adjusted to the
-                        new offset }
-                      if (l>InsOffset) and (LastInsOffset<>-1) then
-                        inc(l,InsOffset-LastInsOffset);
-                      { instruction size will then always become 2 (PFV) }
-                      relsize:=(InsOffset+2)-l;
-                      if (not assigned(ref^.symbol) or
-                          ((ref^.symbol.currbind<>AB_EXTERNAL) and (ref^.symbol.address<>0))) and
-                         (relsize>=-128) and (relsize<=127) then
-                       ot:=OT_IMM32 or OT_SHORT
+                      if assigned(objdata) then
+                        begin
+                          currsym:=objdata.symbolref(ref^.symbol);
+                          l:=ref^.offset;
+                          if assigned(currsym) then
+                            inc(l,currsym.address);
+                          { when it is a forward jump we need to compensate the
+                            offset of the instruction since the previous time,
+                            because the symbol address is then still using the
+                            'old-style' addressing.
+                            For backwards jumps this is not required because the
+                            address of the symbol is already adjusted to the
+                            new offset }
+                          if (l>InsOffset) and (LastInsOffset<>-1) then
+                            inc(l,InsOffset-LastInsOffset);
+                          { instruction size will then always become 2 (PFV) }
+                          relsize:=(InsOffset+2)-l;
+                          if (not assigned(currsym) or
+                              ((currsym.bind<>AB_EXTERNAL) and (currsym.address<>0))) and
+                             (relsize>=-128) and (relsize<=127) then
+                            ot:=OT_IMM32 or OT_SHORT
+                          else
+                            ot:=OT_IMM32 or OT_NEAR;
+                        end
                       else
                       else
-                       ot:=OT_IMM32 or OT_NEAR;
+                        ot:=OT_IMM32 or OT_NEAR;
                     end;
                     end;
                 end;
                 end;
               top_local :
               top_local :
@@ -1233,11 +1237,11 @@ implementation
 
 
     function taicpu.CheckIfValid:boolean;
     function taicpu.CheckIfValid:boolean;
       begin
       begin
-        result:=FindInsEntry;
+        result:=FindInsEntry(nil);
       end;
       end;
 
 
 
 
-    function taicpu.FindInsentry:boolean;
+    function taicpu.FindInsentry(objdata:TObjData):boolean;
       var
       var
         i : longint;
         i : longint;
       begin
       begin
@@ -1249,7 +1253,7 @@ implementation
            { We need intel style operands }
            { We need intel style operands }
            SetOperandOrder(op_intel);
            SetOperandOrder(op_intel);
            { create the .ot fields }
            { create the .ot fields }
-           create_ot;
+           create_ot(objdata);
            { set the file postion }
            { set the file postion }
            aktfilepos:=fileinfo;
            aktfilepos:=fileinfo;
          end
          end
@@ -1285,18 +1289,18 @@ implementation
       end;
       end;
 
 
 
 
-    function taicpu.Pass1(offset:longint):longint;
+    function taicpu.Pass1(objdata:TObjData):longint;
       begin
       begin
         Pass1:=0;
         Pass1:=0;
         { Save the old offset and set the new offset }
         { Save the old offset and set the new offset }
-        InsOffset:=Offset;
+        InsOffset:=ObjData.CurrObjSec.Size;
         { Error? }
         { Error? }
         if (Insentry=nil) and (InsSize=-1) then
         if (Insentry=nil) and (InsSize=-1) then
           exit;
           exit;
         { set the file postion }
         { set the file postion }
         aktfilepos:=fileinfo;
         aktfilepos:=fileinfo;
         { Get InsEntry }
         { Get InsEntry }
-        if FindInsEntry then
+        if FindInsEntry(ObjData) then
          begin
          begin
            { Calculate instruction size }
            { Calculate instruction size }
            InsSize:=calcsize(insentry);
            InsSize:=calcsize(insentry);
@@ -1332,7 +1336,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure taicpu.Pass2(objdata:TAsmObjectData);
+    procedure taicpu.Pass2(objdata:TObjData);
       var
       var
         c : longint;
         c : longint;
       begin
       begin
@@ -1633,7 +1637,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure taicpu.GenCode(objdata:TAsmObjectData);
+    procedure taicpu.GenCode(objdata:TObjData);
       {
       {
        * the actual codes (C syntax, i.e. octal):
        * the actual codes (C syntax, i.e. octal):
        * \0            - terminates the code. (Unless it's a literal of course.)
        * \0            - terminates the code. (Unless it's a literal of course.)
@@ -1683,7 +1687,7 @@ implementation
 
 
       var
       var
         currval : longint;
         currval : longint;
-        currsym : tasmsymbol;
+        currsym : tobjsymbol;
 
 
         procedure getvalsym(opidx:longint);
         procedure getvalsym(opidx:longint);
         begin
         begin
@@ -1691,7 +1695,7 @@ implementation
             top_ref :
             top_ref :
               begin
               begin
                 currval:=oper[opidx]^.ref^.offset;
                 currval:=oper[opidx]^.ref^.offset;
-                currsym:=oper[opidx]^.ref^.symbol;
+                currsym:=ObjData.symbolref(oper[opidx]^.ref^.symbol);
               end;
               end;
             top_const :
             top_const :
               begin
               begin
@@ -1717,11 +1721,9 @@ implementation
         data,s,opidx : longint;
         data,s,opidx : longint;
         ea_data : ea;
         ea_data : ea;
       begin
       begin
-{$ifdef EXTDEBUG}
         { safety check }
         { safety check }
-        if objdata.currsec.datasize<>insoffset then
-         internalerror(200130121);
-{$endif EXTDEBUG}
+        if objdata.currobjsec.size<>insoffset then
+          internalerror(200130121);
         { load data to write }
         { load data to write }
         codes:=insentry^.code;
         codes:=insentry^.code;
         { Force word push/pop for registers }
         { Force word push/pop for registers }
@@ -1956,7 +1958,10 @@ implementation
                      1 :
                      1 :
                        begin
                        begin
                          if (oper[opidx]^.ot and OT_MEMORY)=OT_MEMORY then
                          if (oper[opidx]^.ot and OT_MEMORY)=OT_MEMORY then
-                          objdata.writereloc(oper[opidx]^.ref^.offset,1,oper[opidx]^.ref^.symbol,RELOC_ABSOLUTE)
+                           begin
+                             currsym:=objdata.symbolref(oper[opidx]^.ref^.symbol);
+                             objdata.writereloc(oper[opidx]^.ref^.offset,1,currsym,RELOC_ABSOLUTE)
+                           end
                          else
                          else
                           begin
                           begin
                             bytes[0]:=oper[opidx]^.ref^.offset;
                             bytes[0]:=oper[opidx]^.ref^.offset;
@@ -1967,7 +1972,7 @@ implementation
                      2,4 :
                      2,4 :
                        begin
                        begin
                          objdata.writereloc(oper[opidx]^.ref^.offset,ea_data.bytes,
                          objdata.writereloc(oper[opidx]^.ref^.offset,ea_data.bytes,
-                           oper[opidx]^.ref^.symbol,RELOC_ABSOLUTE);
+                           objdata.symbolref(oper[opidx]^.ref^.symbol),RELOC_ABSOLUTE);
                          inc(s,ea_data.bytes);
                          inc(s,ea_data.bytes);
                        end;
                        end;
                    end;
                    end;

+ 8 - 8
compiler/x86/agx86int.pas

@@ -58,9 +58,9 @@ implementation
     const
     const
       line_length = 70;
       line_length = 70;
 
 
-      secnames : array[TAsmSectionType] of string[4] = ('',
+      secnames : array[TAsmSectiontype] of string[4] = ('',
         'CODE','DATA','DATA','BSS','',
         'CODE','DATA','DATA','BSS','',
-        '','','','','','','',
+        '','','','','',
         '','','','',
         '','','','',
         '',
         '',
         '','','','',
         '','','','',
@@ -68,9 +68,9 @@ implementation
 	''
 	''
       );
       );
 
 
-      secnamesml64 : array[TAsmSectionType] of string[7] = ('',
+      secnamesml64 : array[TAsmSectiontype] of string[7] = ('',
         '_TEXT','_DATE','_DATA','_BSS','',
         '_TEXT','_DATE','_DATA','_BSS','',
-        '','','','','',
+        '','','',
         'idata$2','idata$4','idata$5','idata$6','idata$7','edata',
         'idata$2','idata$4','idata$5','idata$6','idata$7','edata',
         '',
         '',
         '','','','',
         '','','','',
@@ -343,7 +343,7 @@ implementation
 
 
 
 
     var
     var
-      LasTSectype : TAsmSectionType;
+      LasTSectype : TAsmSectiontype;
       lastfileinfo : tfileposinfo;
       lastfileinfo : tfileposinfo;
       infile,
       infile,
       lastinfile   : tinputfile;
       lastinfile   : tinputfile;
@@ -644,9 +644,9 @@ implementation
              end;
              end;
            ait_label :
            ait_label :
              begin
              begin
-               if tai_label(hp).l.is_used then
+               if tai_label(hp).labsym.is_used then
                 begin
                 begin
-                  AsmWrite(tai_label(hp).l.name);
+                  AsmWrite(tai_label(hp).labsym.name);
                   if assigned(hp.next) and not(tai(hp.next).typ in
                   if assigned(hp.next) and not(tai(hp.next).typ in
                      [ait_const,
                      [ait_const,
                       ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
                       ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
@@ -826,7 +826,7 @@ implementation
 
 
     procedure writeexternal(p:tnamedindexitem;arg:pointer);
     procedure writeexternal(p:tnamedindexitem;arg:pointer);
       begin
       begin
-        if tasmsymbol(p).defbind=AB_EXTERNAL then
+        if tasmsymbol(p).bind=AB_EXTERNAL then
           begin
           begin
             case target_asm.id of
             case target_asm.id of
               as_i386_masm,as_i386_wasm:
               as_i386_masm,as_i386_wasm:

Some files were not shown because too many files changed in this diff