Prechádzať zdrojové kódy

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 rokov pred
rodič
commit
785550d7e3
59 zmenil súbory, kde vykonal 3050 pridanie a 2506 odobranie
  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
-       TAsmSection = class;
-       TAsmObjectData = class;
-
        TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
 
        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 }
          sec_stub,
          { stabs }
@@ -71,42 +66,27 @@ interface
          sec_toc
        );
 
-       TAsmSectionOption = (aso_alloconly,aso_executable);
-       TAsmSectionOptions = set of TAsmSectionOption;
-
        TAsmSymbol = class(TNamedIndexItem)
        private
          { 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;
        public
-         defbind,
-         currbind   : TAsmsymbind;
+         bind       : TAsmsymbind;
          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
-           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);
-         procedure reset;
          function  is_used:boolean;
          procedure increfs;
          procedure decrefs;
          function getrefs: longint;
-         procedure setaddress(_pass:byte;sec:TAsmSection;offset,len:aint);
        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
          info alt_dbgline and alt_dbgfile }
        TAsmLabelType = (alt_jump,alt_addr,alt_data,alt_dbgline,alt_dbgfile,alt_dbgtype,alt_dbgframe);
@@ -120,101 +100,10 @@ interface
          function getname:string;override;
        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;
        pasmsymbolidxarr = ^tasmsymbolidxarr;
 
-       TAsmLibraryData = class(TLinkedListItem)
+       TObjLibraryData = class(TLinkedListItem)
        private
          nextaltnr   : longint;
          nextlabelnr : array[Tasmlabeltype] of longint;
@@ -222,18 +111,12 @@ interface
          name,
          realname     : string[80];
          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);
          destructor  destroy;override;
-         procedure Freeasmsymbolidx;
-         procedure DerefAsmsymbol(var s:tasmsymbol);
          { asmsymbol }
          function  newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:TAsmsymtype) : tasmsymbol;
          function  getasmsymbol(const s : string) : tasmsymbol;
-         function  renameasmsymbol(const sold, snew : string):tasmsymbol;
          function  newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
          {# create a new assembler label }
          procedure getlabel(var l : tasmlabel;alt:tasmlabeltype);
@@ -244,15 +127,9 @@ interface
          { make l as a new label and flag is_data }
          procedure getdatalabel(var l : tasmlabel);
          {# return a label number }
-         procedure CreateUsedAsmSymbolList;
-         procedure DestroyUsedAsmSymbolList;
-         procedure UsedAsmSymbolListInsert(p:tasmsymbol);
          { generate an alternative (duplicate) symbol }
          procedure GenerateAltSymbol(p:tasmsymbol);
-         { reset alternative symbol information }
-         procedure UsedAsmSymbolListResetAltSym;
-         procedure UsedAsmSymbolListReset;
-         procedure UsedAsmSymbolListCheckUndefined;
+         procedure ResetAltSymbols;
        end;
 
     function LengthUleb128(a: aword) : byte;
@@ -263,7 +140,7 @@ interface
       asmlabeltypeprefix : array[tasmlabeltype] of char = ('j','a','d','l','f','t','c');
 
     var
-      objectlibrary : tasmlibrarydata;
+      objectlibrary : TObjLibraryData;
 
 
 implementation
@@ -329,31 +206,13 @@ implementation
     constructor tasmsymbol.create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
       begin;
         inherited createname(s);
-        reset;
-        defbind:=_bind;
+        bind:=_bind;
         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;
       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;
       begin
         is_used:=(refs>0);
@@ -380,24 +239,6 @@ implementation
       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
 *****************************************************************************}
@@ -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
         alt : TAsmLabelType;
       begin
@@ -789,47 +284,22 @@ implementation
         { symbols }
         symbolsearch:=tdictionary.create;
         symbolsearch.usehash;
+        AltSymbollist:=TList.Create;
         { labels }
         nextaltnr:=1;
         for alt:=low(TAsmLabelType) to high(TAsmLabelType) do
           nextlabelnr[alt]:=1;
-        { ppu }
-        asmsymbolppuidx:=0;
-        asmsymbolidx:=nil;
       end;
 
 
-    destructor TAsmLibraryData.destroy;
+    destructor TObjLibraryData.destroy;
       begin
+        AltSymbollist.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;
 
 
-    function TAsmLibraryData.newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
+    function TObjLibraryData.newasmsymbol(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
       var
         hp : tasmsymbol;
       begin
@@ -847,7 +317,7 @@ implementation
              end;
            {$ENDIF}
            if (_bind<>AB_EXTERNAL) then
-             hp.defbind:=_bind
+             hp.bind:=_bind
          end
         else
          begin
@@ -859,111 +329,34 @@ implementation
       end;
 
 
-    function TAsmLibraryData.getasmsymbol(const s : string) : tasmsymbol;
+    function TObjLibraryData.getasmsymbol(const s : string) : tasmsymbol;
       begin
         getasmsymbol:=tasmsymbol(symbolsearch.search(s));
       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
         if not assigned(p.altsymbol) then
          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);
-           { 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;
 
 
-    procedure TAsmLibraryData.UsedAsmSymbolListCheckUndefined;
+    procedure TObjLibraryData.ResetAltSymbols;
       var
-        hp : tasmsymbol;
+        i  : longint;
       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;
 
 
-    function  TAsmLibraryData.newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
+    function  TObjLibraryData.newasmlabel(nr:longint;alt:tasmlabeltype;is_global:boolean) : tasmlabel;
       var
         hp : tasmlabel;
       begin
@@ -976,14 +369,15 @@ implementation
       end;
 
 
-    procedure TAsmLibraryData.getlabel(var l : tasmlabel;alt:tasmlabeltype);
+    procedure TObjLibraryData.getlabel(var l : tasmlabel;alt:tasmlabeltype);
       begin
         l:=tasmlabel.createlocal(nextlabelnr[alt],alt);
         inc(nextlabelnr[alt]);
         symbolsearch.insert(l);
       end;
 
-    procedure TAsmLibraryData.getjumplabel(var l : tasmlabel);
+
+    procedure TObjLibraryData.getjumplabel(var l : tasmlabel);
       begin
         l:=tasmlabel.createlocal(nextlabelnr[alt_jump],alt_jump);
         inc(nextlabelnr[alt_jump]);
@@ -991,7 +385,7 @@ implementation
       end;
 
 
-    procedure TAsmLibraryData.getdatalabel(var l : tasmlabel);
+    procedure TObjLibraryData.getdatalabel(var l : tasmlabel);
       begin
         l:=tasmlabel.createglobal(name,nextlabelnr[alt_data],alt_data);
         inc(nextlabelnr[alt_data]);
@@ -999,12 +393,11 @@ implementation
       end;
 
 
-    procedure TAsmLibraryData.getaddrlabel(var l : tasmlabel);
+    procedure TObjLibraryData.getaddrlabel(var l : tasmlabel);
       begin
         l:=tasmlabel.createlocal(nextlabelnr[alt_addr],alt_addr);
         inc(nextlabelnr[alt_addr]);
         symbolsearch.insert(l);
       end;
 
-
 end.

+ 29 - 29
compiler/aasmtai.pas

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

+ 25 - 22
compiler/aggas.pas

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

+ 4 - 4
compiler/arm/aasmcpu.pas

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

+ 188 - 246
compiler/assemble.pas

@@ -131,21 +131,14 @@ interface
       end;
 
       TInternalAssembler=class(TAssembler)
-      public
-        constructor create(smart:boolean);override;
-        destructor  destroy;override;
-        procedure MakeObject;override;
-      protected
-        objectdata   : TAsmObjectData;
-        objectoutput : tobjectoutput;
       private
+        FCObjOutput : TObjOutputclass;
         { the aasmoutput lists that need to be processed }
         lists        : byte;
         list         : array[1..maxoutputlists] of TAAsmoutput;
         { current processing }
         currlistidx  : byte;
         currlist     : TAAsmoutput;
-        currpass     : byte;
         procedure convertstab(p:pchar);
         function  MaybeNextList(var hp:Tai):boolean;
         function  TreePass0(hp:Tai):Tai;
@@ -153,6 +146,14 @@ interface
         function  TreePass2(hp:Tai):Tai;
         procedure writetree;
         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;
 
     TAssemblerClass = class of TAssembler;
@@ -427,8 +428,6 @@ Implementation
 
 
     Function TExternalAssembler.DoAssemble:boolean;
-      var
-        s : TCmdStr;
       begin
         DoAssemble:=true;
         if DoPipe then
@@ -443,7 +442,7 @@ Implementation
            else
            Message1(exec_i_assembling,name);
          end;
-        
+
         if CallAssembler(FindAssembler,MakeCmdLine) then
          RemoveAsm
         else
@@ -668,10 +667,9 @@ Implementation
     constructor TInternalAssembler.create(smart:boolean);
       begin
         inherited create(smart);
-        objectoutput:=nil;
-        objectdata:=nil;
+        ObjOutput:=nil;
+        ObjData:=nil;
         SmartAsm:=smart;
-        currpass:=0;
       end;
 
 
@@ -684,8 +682,10 @@ Implementation
 {$ifdef MEMDEBUG}
         d := tmemdebug.create(name+' - agbin');
 {$endif}
-        objectdata.free;
-        objectoutput.free;
+        if assigned(ObjData) then
+          ObjData.free;
+        if assigned(ObjOutput) then
+          ObjOutput.free;
 {$ifdef MEMDEBUG}
         d.free;
 {$endif}
@@ -728,13 +728,13 @@ Implementation
           result:=(code=0);
         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
           hs        : string;
           len,
           code      : integer;
           pstart    : pchar;
-          sym       : tasmsymbol;
+          sym       : tobjsymbol;
           exprvalue : longint;
           gotmin,
           dosub     : boolean;
@@ -782,21 +782,16 @@ Implementation
                     internalerror(200509187);
                   move(pstart^,hs[1],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? }
                   if assigned(relocsym) then
                     begin
-                      if (relocsym.section<>sym.section) then
+                      if (relocsym.objsection<>sym.objsection) then
                         internalerror(2005091810);
                       relocsym:=nil;
                     end
                   else
-                    begin
-                      relocsym:=sym;
-                    end;
+                    relocsym:=sym;
                   exprvalue:=sym.address;
                 end;
               '+' :
@@ -828,7 +823,7 @@ Implementation
         nidx,
         nother,
         i         : longint;
-        relocsym  : tasmsymbol;
+        relocsym  : TObjSymbol;
         pstr,
         pcurr,
         pendquote : pchar;
@@ -856,8 +851,8 @@ Implementation
           pcurr:=p;
 
         { 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
           begin
             { Stabs format: nidx,nother,nline[,offset] }
@@ -881,7 +876,7 @@ Implementation
             if (nidx=N_Function) and
                (tf_use_function_relative_addresses in target_info.flags) then
               ofs:=0;
-            objectdata.writestab(ofs,relocsym,nidx,nother,nline,pstr);
+            ObjData.writestab(ofs,relocsym,byte(nidx),byte(nother),word(nline),pstr);
           end;
         if assigned(pendquote) then
           pendquote^:='"';
@@ -911,7 +906,7 @@ Implementation
 
     function TInternalAssembler.TreePass0(hp:Tai):Tai;
       var
-        l : longint;
+        objsym : TObjSymbol;
       begin
         while assigned(hp) do
          begin
@@ -921,52 +916,40 @@ Implementation
                  { always use the maximum fillsize in this pass to avoid possible
                    short jumps to become out of range }
                  Tai_align(hp).fillsize:=Tai_align(hp).aligntype;
-                 objectdata.alloc(Tai_align(hp).fillsize);
+                 ObjData.alloc(Tai_align(hp).fillsize);
                end;
              ait_datablock :
                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;
              ait_real_80bit :
-               objectdata.alloc(10);
+               ObjData.alloc(10);
              ait_real_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_real_32bit :
-               objectdata.alloc(4);
+               ObjData.alloc(4);
              ait_comp_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_const:
-               objectdata.alloc(tai_const(hp).size);
+               ObjData.alloc(tai_const(hp).size);
              ait_section:
                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;
              ait_symbol :
-               objectdata.allocsymbol(currpass,Tai_symbol(hp).sym,0);
+               ObjData.SymbolDefine(Tai_symbol(hp).sym);
              ait_label :
-               objectdata.allocsymbol(currpass,Tai_label(hp).l,0);
+               ObjData.SymbolDefine(Tai_label(hp).labsym);
              ait_string :
-               objectdata.alloc(Tai_string(hp).len);
+               ObjData.alloc(Tai_string(hp).len);
              ait_instruction :
                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 }
                  Taicpu(hp).resetpass2;
-                 objectdata.alloc(Taicpu(hp).Pass1(objectdata.currsec.datasize));
-{$endif arm}
+                 ObjData.alloc(Taicpu(hp).Pass1(ObjData));
                end;
              ait_cutobject :
                if SmartAsm then
@@ -981,8 +964,8 @@ Implementation
     function TInternalAssembler.TreePass1(hp:Tai):Tai;
       var
         InlineLevel,
-        l,
         i : longint;
+        objsym : TObjSymbol;
       begin
         inlinelevel:=0;
         while assigned(hp) do
@@ -991,51 +974,39 @@ Implementation
              ait_align :
                begin
                  { 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;
              ait_datablock :
                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);
-                 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;
              ait_real_80bit :
-               objectdata.alloc(10);
+               ObjData.alloc(10);
              ait_real_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_real_32bit :
-               objectdata.alloc(4);
+               ObjData.alloc(4);
              ait_comp_64bit :
-               objectdata.alloc(8);
+               ObjData.alloc(8);
              ait_const:
                begin
-                 objectdata.alloc(tai_const(hp).size);
+                 ObjData.alloc(tai_const(hp).size);
                  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
-                   objectlibrary.UsedAsmSymbolListInsert(Tai_const(hp).endsym);
+                   ObjData.SymbolRef(Tai_const(hp).endsym);
                end;
              ait_section:
                begin
                  { use cached value }
-                 objectdata.setsection(Tai_section(hp).sec);
+                 ObjData.setsection(Tai_section(hp).sec);
                end;
              ait_stab :
                begin
@@ -1045,45 +1016,18 @@ Implementation
              ait_function_name,
              ait_force_line : ;
              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 :
                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;
+             ait_label :
+               ObjData.SymbolDefine(Tai_label(hp).labsym);
              ait_string :
-               objectdata.alloc(Tai_string(hp).len);
+               ObjData.alloc(Tai_string(hp).len);
              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 :
                if SmartAsm then
                 break;
@@ -1103,11 +1047,12 @@ Implementation
       var
         fillbuffer : tfillbuffer;
         InlineLevel,
-        l  : longint;
         v  : int64;
 {$ifdef x86}
         co : comp;
 {$endif x86}
+        objsym,
+        objsymend : TObjSymbol;
       begin
         inlinelevel:=0;
         { main loop }
@@ -1116,47 +1061,41 @@ Implementation
            case hp.typ of
              ait_align :
                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
-                   objectdata.writebytes(Tai_align(hp).calculatefillbuf(fillbuffer)^,Tai_align(hp).fillsize);
+                   ObjData.alloc(Tai_align(hp).fillsize);
                end;
              ait_section :
                begin
                  { use cached value }
-                 objectdata.setsection(Tai_section(hp).sec);
+                 ObjData.setsection(Tai_section(hp).sec);
                end;
              ait_symbol :
                begin
-                 objectdata.writesymbol(Tai_symbol(hp).sym);
-                 objectoutput.exportsymbol(Tai_symbol(hp).sym);
+                 ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_symbol(hp).sym));
                end;
              ait_datablock :
                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;
              ait_real_80bit :
-               objectdata.writebytes(Tai_real_80bit(hp).value,10);
+               ObjData.writebytes(Tai_real_80bit(hp).value,10);
              ait_real_64bit :
-               objectdata.writebytes(Tai_real_64bit(hp).value,8);
+               ObjData.writebytes(Tai_real_64bit(hp).value,8);
              ait_real_32bit :
-               objectdata.writebytes(Tai_real_32bit(hp).value,4);
+               ObjData.writebytes(Tai_real_32bit(hp).value,4);
              ait_comp_64bit :
                begin
 {$ifdef x86}
                  co:=comp(Tai_comp_64bit(hp).value);
-                 objectdata.writebytes(co,8);
+                 ObjData.writebytes(co,8);
 {$endif x86}
                end;
              ait_string :
-               objectdata.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
+               ObjData.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
              ait_const :
                begin
                  case tai_const(hp).consttype of
@@ -1164,34 +1103,36 @@ Implementation
                    aitconst_32bit,
                    aitconst_16bit,
                    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 :
-                     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;
              ait_label :
                begin
-                 objectdata.writesymbol(Tai_label(hp).l);
                  { exporting shouldn't be necessary as labels are local,
                    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;
              ait_instruction :
-               Taicpu(hp).Pass2(objectdata);
+               Taicpu(hp).Pass2(ObjData);
              ait_stab :
                convertstab(Tai_stab(hp).str);
              ait_function_name,
@@ -1212,19 +1153,18 @@ Implementation
 
 
     procedure TInternalAssembler.writetree;
-      var
-        hp : Tai;
       label
         doexit;
+      var
+        hp : Tai;
       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 }
         currlistidx:=1;
         currlist:=list[currlistidx];
@@ -1234,16 +1174,16 @@ Implementation
            hp:=TreePass0(hp);
            MaybeNextList(hp);
          end;
-        objectdata.afteralloc;
+        ObjData.afteralloc;
         { leave if errors have occured }
         if errorcount>0 then
          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 }
         currlistidx:=1;
         currlist:=list[currlistidx];
@@ -1253,20 +1193,18 @@ Implementation
            hp:=TreePass1(hp);
            MaybeNextList(hp);
          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 }
         if errorcount>0 then
          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 }
         currlistidx:=1;
         currlist:=list[currlistidx];
@@ -1276,35 +1214,32 @@ Implementation
            hp:=TreePass2(hp);
            MaybeNextList(hp);
          end;
-        objectdata.createsection(sec_code,'',0,[]);
-        objectdata.afterwrite;
+        ObjData.createsection(sec_code,'');
+        ObjData.afterwrite;
 
         { don't write the .o file if errors have occured }
         if errorcount=0 then
          begin
            { write objectfile }
-           objectoutput.startobjectfile(ObjFile);
-           objectoutput.writeobjectfile(objectdata);
-           objectdata.free;
-           objectdata:=nil;
+           ObjOutput.startobjectfile(ObjFile);
+           ObjOutput.writeobjectfile(ObjData);
          end;
 
       doexit:
-        { reset the used symbols back, must be after the .o has been
-          written }
-        objectlibrary.UsedAsmsymbolListReset;
-        objectlibrary.DestroyUsedAsmsymbolList;
+        { Cleanup }
+        ObjData.free;
+        ObjData:=nil;
       end;
 
 
     procedure TInternalAssembler.writetreesmart;
       var
         hp : Tai;
-        startsectype : TAsmSectionType;
+        startsectype : TAsmSectiontype;
         place: tcutplace;
       begin
         NextSmartName(cut_normal);
-        objectdata:=objectoutput.newobjectdata(Objfile);
+        ObjOutput:=CObjOutput.Create(true);
         startsectype:=sec_code;
 
         { start with list 1 }
@@ -1313,91 +1248,78 @@ Implementation
         hp:=Tai(currList.first);
         while assigned(hp) do
          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);
-           objectdata.afteralloc;
+           ObjData.afteralloc;
            { leave if errors have occured }
            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);
-           objectdata.afteralloc;
-           { check for undefined labels }
-           objectlibrary.UsedAsmSymbolListCheckUndefined;
+           ObjData.afteralloc;
 
            { leave if errors have occured }
            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);
-           { 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 }
            if errorcount>0 then
-            exit;
+             break;
 
            { 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? }
            if not MaybeNextList(hp) then
-            break;
+             break;
 
            { we will start a new objectfile so reset everything }
            { The place can still change in the next while loop, so don't init }
            { the writer yet (JM)                                              }
            if (hp.typ=ait_cutobject) then
-            place := Tai_cutobject(hp).place
+             place := Tai_cutobject(hp).place
            else
-            place := cut_normal;
+             place := cut_normal;
 
            { avoid empty files }
+           startsectype:=sec_code;
            while assigned(hp) and
                  (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cutobject]) do
             begin
               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);
             end;
-           { there is a problem if startsectype is sec_none !! PM }
-           if startsectype=sec_none then
-             startsectype:=sec_code;
 
            if not MaybeNextList(hp) then
              break;
 
            { start next objectfile }
            NextSmartName(place);
-           objectdata:=objectoutput.newobjectdata(Objfile);
          end;
       end;
 
@@ -1406,6 +1328,9 @@ Implementation
 
     var to_do:set of Tasmlist;
         i:Tasmlist;
+{$ifdef MEMDEBUG}
+        d : tmemdebug;
+{$endif}
 
         procedure addlist(p:TAAsmoutput);
         begin
@@ -1429,6 +1354,23 @@ Implementation
           writetreesmart
         else
           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;
 
 

+ 133 - 61
compiler/cclasses.pas

@@ -62,6 +62,9 @@ type
    TPointerList = array[0..MaxListSize - 1] of Pointer;
    TListSortCompare = function (Item1, Item2: Pointer): Integer;
 
+   TListCallback = procedure(data,arg:pointer) of object;
+   TListStaticCallback = procedure(data,arg:pointer);
+
    TList = class(TObject)
    private
      FList: PPointerList;
@@ -91,6 +94,8 @@ type
      function Remove(Item: Pointer): Integer;
      procedure Pack;
      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 Count: Integer read FCount write SetCount;
      property Items[Index: Integer]: Pointer read Get write Put; default;
@@ -200,6 +205,8 @@ type
           { concats an item }
           procedure ConcatItem(item:TStringListItem);
           property Doubles:boolean read FDoubles write FDoubles;
+          procedure readstream(f:TCStream);
+          procedure writestream(f:TCStream);
        end;
 
 
@@ -222,8 +229,6 @@ type
          FLeft,
          FRight      : TNamedIndexItem;
          FSpeedValue : cardinal;
-       { singleList }
-         FListNext   : TNamedIndexItem;
          FName       : Pstring;
        protected
          function  GetName:string;virtual;
@@ -236,7 +241,6 @@ type
          property IndexNext:TNamedIndexItem read FIndexNext write FIndexNext;
          property Name:string read GetName write SetName;
          property SpeedValue:cardinal read FSpeedValue;
-         property ListNext:TNamedIndexItem read FListNext;
          property Left:TNamedIndexItem read FLeft write FLeft;
          property Right:TNamedIndexItem read FRight write FRight;
        end;
@@ -275,15 +279,6 @@ type
          property  Count:longint read FCount;
        end;
 
-       tsingleList=class
-         First,
-         last    : TNamedIndexItem;
-         constructor Create;
-         procedure reset;
-         procedure clear;
-         procedure insert(p:TNamedIndexItem);
-       end;
-
       tindexobjectarray=array[1..16000] of TNamedIndexItem;
       pnamedindexobjectarray=^tindexobjectarray;
 
@@ -301,6 +296,7 @@ type
         procedure insert(p:TNamedIndexItem);
         procedure replace(oldp,newp:TNamedIndexItem);
         function  search(nr:integer):TNamedIndexItem;
+        property  Items[Index: Integer]: TNamedIndexItem read Search; default;
       private
         growsize,
         size  : integer;
@@ -747,6 +743,33 @@ begin
 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
  ****************************************************************************}
@@ -1239,6 +1262,104 @@ 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
  ****************************************************************************}
@@ -1253,8 +1374,6 @@ end;
         Fright:=nil;
         FName:=nil;
         Fspeedvalue:=cardinal($ffffffff);
-        { List }
-        FListNext:=nil;
       end;
 
     constructor TNamedIndexItem.Createname(const n:string);
@@ -1271,8 +1390,6 @@ end;
       {$else}
         FName:=stringdup(n);
       {$endif}
-        { List }
-        FListNext:=nil;
       end;
 
 
@@ -1869,51 +1986,6 @@ end;
         speedsearch:=nil;
       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
  ****************************************************************************}

+ 1 - 1
compiler/cgobj.pas

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

+ 3 - 0
compiler/comphook.pas

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

+ 10 - 4
compiler/compiler.pas

@@ -64,14 +64,14 @@ unit compiler;
      {$fatal cannot define two CPU switches}
    {$endif}
    {$endif}
-   
+
    {$ifdef POWERPC64}
    {$ifndef CPUOK}
    {$DEFINE CPUOK}
    {$else}
      {$fatal cannot define two CPU switches}
    {$endif}
-   {$endif}   
+   {$endif}
 
    {$ifdef ia64}
    {$ifndef CPUOK}
@@ -345,6 +345,8 @@ function Compile(const cmd:string):longint;
 
 var
   starttime  : real;
+  timestr    : string[20];
+  linkstr    : string[64];
 {$ifdef SHOWUSEDMEM}
   hstatus : TFPCHeapStatus;
 {$endif SHOWUSEDMEM}
@@ -380,8 +382,12 @@ begin
           starttime:=getrealtime-starttime;
           if starttime<0 then
             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;
      finally
        { no message possible after this !!    }

+ 5 - 0
compiler/cstreams.pas

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

+ 4 - 4
compiler/cutils.pas

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

+ 1 - 1
compiler/dbgdwarf.pas

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

+ 1 - 1
compiler/dbgstabs.pas

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

+ 9 - 6
compiler/fmodule.pas

@@ -154,7 +154,7 @@ interface
         locallibrarysearchpath : TSearchPathList;
 
         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
         points to the module calling it. It is nil for the first compiled
         module. This allow inheritence of all path lists. MUST pay attention
@@ -454,7 +454,7 @@ implementation
         imports:=TLinkedList.Create;
         _exports:=TLinkedList.Create;
         externals:=TLinkedList.Create;
-        librarydata:=tasmlibrarydata.create(realmodulename^);
+        librarydata:=TObjLibraryData.create(realmodulename^);
       end;
 
 
@@ -540,13 +540,16 @@ implementation
 {$ifdef MEMDEBUG}
         d.free;
 {$endif}
+        if assigned(librarydata) then
+          begin
 {$ifdef MEMDEBUG}
-        d:=tmemdebug.create(modulename^+' - librarydata');
+            d:=tmemdebug.create(modulename^+' - librarydata');
 {$endif}
-        librarydata.free;
+            librarydata.free;
 {$ifdef MEMDEBUG}
-        d.free;
+            d.free;
 {$endif}
+          end;
         stringdispose(modulename);
         inherited Destroy;
       end;
@@ -619,7 +622,7 @@ implementation
         sourcefiles.free;
         sourcefiles:=tinputfilemanager.create;
         librarydata.free;
-        librarydata:=tasmlibrarydata.create(realmodulename^);
+        librarydata:=TObjLibraryData.create(realmodulename^);
         imports.free;
         imports:=tlinkedlist.create;
         _exports.free;

+ 4 - 1
compiler/fpcdefs.inc

@@ -71,7 +71,7 @@
   {$define cpu64bit}
   {$define cpuflags}
   {$define cputargethasfixedstack}
-  {$define cpumm}  
+  {$define cpumm}
   {$define cpurequiresproperalignment}
 {$endif powerpc64}
 
@@ -91,3 +91,6 @@
 {$IFDEF MACOS}
 {$DEFINE MACOS_USE_FAKE_SYSUTILS}
 {$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 writederefmap;
           procedure writederefdata;
-          procedure putasmsymbol_in_idx(s:tnamedindexitem;arg:pointer);
-          procedure writeasmsymbols;
           procedure readsourcefiles;
           procedure readloadunit;
           procedure readlinkcontainer(var p:tlinkcontainer);
           procedure readderefmap;
           procedure readderefdata;
-          procedure readasmsymbols;
 {$IFDEF MACRO_DIFF_HINT}
           procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
           procedure writeusedmacros;
@@ -571,52 +568,6 @@ uses
         ppufile.writeentry(ibderefdata);
       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}
 
 {
@@ -848,48 +799,6 @@ uses
       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;
       var
         b : byte;
@@ -959,7 +868,8 @@ uses
              ibloadunit :
                readloadunit;
              ibasmsymbols :
-               readasmsymbols;
+{$warning TODO Remove ibasmsymbols}
+               ;
              ibendimplementation :
                break;
            else
@@ -1082,9 +992,6 @@ uses
          { write implementation uses }
          writeusedunit(false);
 
-         { write asmsymbols }
-         writeasmsymbols;
-
          { end of implementation }
          ppufile.writeentry(ibendimplementation);
 
@@ -1226,7 +1133,6 @@ uses
       var
         pu           : tused_unit;
         load_refs    : boolean;
-        oldobjectlibrary : tasmlibrarydata;
       begin
         if current_module<>self then
          internalerror(200212284);
@@ -1280,7 +1186,7 @@ uses
         interface_compiled:=true;
 
         { read the implementation part, containing
-          the implementation uses and objectdata }
+          the implementation uses and ObjData }
         in_interface:=false;
         load_implementation;
 
@@ -1316,12 +1222,9 @@ uses
           end;
 
         { we can now derefence all pointers to the implementation parts }
-        oldobjectlibrary:=objectlibrary;
-        objectlibrary:=librarydata;
         tstoredsymtable(globalsymtable).derefimpl;
         if assigned(localsymtable) then
           tstoredsymtable(localsymtable).derefimpl;
-        objectlibrary:=oldobjectlibrary;
 
         { load browser info if stored }
         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}
 
-{ Use the internal linker by default }
-{ define INTERNALLINKER}
-
 interface
 
     uses
@@ -182,6 +179,7 @@ interface
        UseDeffileForExports    : boolean;
        UseDeffileForExportsSetExplicitly : boolean;
        GenerateImportSection,
+       GenerateImportSectionSetExplicitly,
        RelocSection : boolean;
        RelocSectionSetExplicitly : boolean;
        LinkTypeSetExplicitly : boolean;

+ 14 - 11
compiler/i386/ag386nsm.pas

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

+ 20 - 20
compiler/i386/daopt386.pas

@@ -507,7 +507,7 @@ begin
   while assigned(p) and
        (p.typ in SkipInstr + [ait_label,ait_align]) Do
     if (p.typ <> ait_Label) or
-       (tai_label(p).l <> l) then
+       (tai_label(p).labsym <> l) then
       GetNextInstruction(p, p)
     else
        begin
@@ -1090,7 +1090,7 @@ end;
 
 function labelCanBeSkipped(p: tai_label): boolean;
 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;
 
 {******************* The Data Flow Analyzer functions ********************}
@@ -1232,7 +1232,7 @@ begin
       if firstRemovedWasAlloc then
         begin
           hp := tai_regalloc.Alloc(reg,nil);
-          insertLLItem(asmL,start.previous,start,hp);        
+          insertLLItem(asmL,start.previous,start,hp);
         end;
       if lastRemovedWasDealloc then
         begin
@@ -2057,10 +2057,10 @@ begin
         if not labelcanbeskipped(tai_label(p)) then
           begin
             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;
       prev := p;
       getnextinstruction(p, p);
@@ -2086,7 +2086,7 @@ begin
       case p.typ of
         ait_label:
           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}
         ait_regalloc:
           begin
@@ -2182,15 +2182,15 @@ begin
         ait_label:
           begin
             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;
         ait_instruction:
           begin
             if taicpu(p).is_jmp then
              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;
 {        ait_instruction:
@@ -2294,11 +2294,11 @@ begin
 {$else JumpAnal}
           begin
            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}
-              if (RefsFound = tai_Label(p).l^.RefCount)
+              if (RefsFound = tai_Label(p).labsym^.RefCount)
 {$else AnalyzeLoops}
-              if (JmpsProcessed = tai_Label(p).l^.RefCount)
+              if (JmpsProcessed = tai_Label(p).labsym^.RefCount)
 {$endif AnalyzeLoops}
                 then
 {all jumps to this label have been found}
@@ -2345,11 +2345,11 @@ begin
                             while GetNextInstruction(hp, hp) and
                                   not((hp.typ = ait_instruction) 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
-                                      (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);
                             if (hp.typ = ait_label)
                               then
@@ -2396,7 +2396,7 @@ begin
                       con_invalid: typ := con_unknown;
                     end;
 {$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
               begin
                 if (InstrCnt < InstrNr)

+ 58 - 58
compiler/i386/popt386.pas

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

+ 231 - 58
compiler/link.pas

@@ -29,7 +29,8 @@ uses
   cclasses,
   systems,
   fmodule,
-  globtype;
+  globtype,
+  ogbase;
 
 Type
     TLinkerInfo=record
@@ -43,6 +44,8 @@ Type
 
     TLinker = class(TAbstractLinker)
     public
+       HasResources,
+       HasExports      : boolean;
        ObjectFiles,
        DLLFiles,
        SharedLibFiles,
@@ -74,7 +77,19 @@ Type
 
     TInternalLinker = class(TLinker)
     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
        Constructor Create;override;
        Destructor Destroy;override;
@@ -102,9 +117,9 @@ uses
   dos,
 {$ENDIF USE_SYSUTILS}
   cutils,
-  script,globals,verbose,ppu,
+  script,globals,verbose,comphook,ppu,
   aasmbase,aasmtai,aasmcpu,
-  ogbase,ogmap;
+  ogmap;
 
 type
  TLinkerClass = class of Tlinker;
@@ -287,6 +302,10 @@ var
 begin
   with hp do
    begin
+     if (flags and uf_has_resourcefiles)<>0 then
+       HasResources:=true;
+     if (flags and uf_has_exports)<>0 then
+       HasExports:=true;
    { link unit files }
      if (flags and uf_no_link)=0 then
       begin
@@ -652,72 +671,226 @@ end;
                               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
 % looks for object files you link in (files used in \var{\{\$L xxx\}} statements).
 % 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
 % of lines compiled, and the time it took to compile them (real time,
 % not program time).

+ 1 - 1
compiler/msgidx.inc

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

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 163 - 163
compiler/msgtxt.inc


+ 3 - 5
compiler/ncgbas.pas

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

+ 4 - 4
compiler/ncgcon.pas

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

+ 0 - 12
compiler/ncgset.pas

@@ -669,18 +669,6 @@ implementation
       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;
       var
          i : longint;

+ 1 - 1
compiler/ncgutil.pas

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

+ 0 - 2
compiler/ncon.pas

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

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 949 - 91
compiler/ogbase.pas


Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 501 - 285
compiler/ogcoff.pas


Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 296 - 368
compiler/ogelf.pas


+ 9 - 9
compiler/oglx.pas

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

+ 37 - 21
compiler/ogmap.pas

@@ -27,7 +27,7 @@ interface
 
     uses
        { common }
-       cclasses,systems,
+       cclasses,globtype,systems,
        { object writer }
        aasmbase,ogbase
        ;
@@ -36,16 +36,18 @@ interface
        texemap = class
        private
          t : text;
+         FImageBase : aint;
        public
          constructor Create(const s:string);
          destructor Destroy;override;
          procedure Add(const s:string);
+         procedure AddHeader(const s:string);
          procedure AddCommonSymbolsHeader;
-         procedure AddCommonSymbol(p:tasmsymbol);
-         procedure AddMemoryMapHeader;
+         procedure AddCommonSymbol(p:TObjSymbol);
+         procedure AddMemoryMapHeader(abase:aint);
          procedure AddMemoryMapExeSection(p:texesection);
-         procedure AddMemoryMapObjectSection(p:TAsmSection);
-         procedure AddMemoryMapSymbol(p:tasmsymbol);
+         procedure AddMemoryMapObjectSection(p:TObjSection);
+         procedure AddMemoryMapSymbol(p:TObjSymbol);
        end;
 
     var
@@ -66,6 +68,7 @@ implementation
        begin
          Assign(t,FixFileName(s));
          Rewrite(t);
+         FImageBase:=0;
        end;
 
 
@@ -81,16 +84,22 @@ implementation
        end;
 
 
+     procedure TExeMap.AddHeader(const s:string);
+       begin
+         Add('');
+         Add(s);
+       end;
+
+
      procedure TExeMap.AddCommonSymbolsHeader;
        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;
 
 
-     procedure TExeMap.AddCommonSymbol(p:tasmsymbol);
+     procedure TExeMap.AddCommonSymbol(p:TObjSymbol);
        var
          s : string;
        begin
@@ -101,37 +110,44 @@ implementation
             writeln(t,p.name);
             s:='';
           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;
 
 
-     procedure TExeMap.AddMemoryMapHeader;
+     procedure TExeMap.AddMemoryMapHeader(abase:aint);
+       var
+         imagebasestr : string;
        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;
 
 
      procedure TExeMap.AddMemoryMapExeSection(p:texesection);
        begin
          { .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;
 
 
-     procedure TExeMap.AddMemoryMapObjectSection(p:TAsmSection);
+     procedure TExeMap.AddMemoryMapObjectSection(p:TObjSection);
        begin
          { .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;
 
 
-     procedure TExeMap.AddMemoryMapSymbol(p:tasmsymbol);
+     procedure TExeMap.AddMemoryMapSymbol(p:TObjSymbol);
        begin
          {                 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.

+ 8 - 1
compiler/options.pas

@@ -104,7 +104,8 @@ procedure set_default_link_type;
 begin
   { win32 and wdosx need smartlinking by default to prevent including too much
     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
       def_system_macro('FPC_LINK_SMART');
       undef_system_macro('FPC_LINK_STATIC');
@@ -1131,6 +1132,7 @@ begin
                     'I':
                       begin
                         GenerateImportSection:=not UnsetBool(More,j);
+                        GenerateImportSectionSetExplicitly:=true;
                       end;
                     'N':
                       begin
@@ -2117,6 +2119,11 @@ begin
   if target_info.system=system_arm_wince then
     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 }
   if GenerateImportSection and
      (target_info.system in [system_i386_win32]) then

+ 7 - 3
compiler/owar.pas

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

+ 30 - 9
compiler/owbase.pas

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

+ 11 - 3
compiler/parser.pas

@@ -140,8 +140,16 @@ implementation
          SetCompileModule(nil);
 
          { 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
            still assinged }
@@ -311,7 +319,7 @@ implementation
         { asmlists }
           oldexprasmlist:Taasmoutput;
           oldasmlist:array[Tasmlist] of Taasmoutput;
-          oldobjectlibrary : tasmlibrarydata;
+          oldobjectlibrary : TObjLibraryData;
         { al_resourcestrings }
           Oldresourcestrings : tresourcestrings;
         { akt.. things }

+ 4 - 4
compiler/pdecl.pas

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

+ 5 - 5
compiler/pdecobj.pas

@@ -30,7 +30,7 @@ interface
       globtype,symtype,symdef;
 
     { 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
 
@@ -50,7 +50,7 @@ implementation
       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 }
       var
          there_is_a_destructor : boolean;
@@ -499,6 +499,7 @@ implementation
       var
         pd : tprocdef;
         dummysymoptions : tsymoptions;
+        i : longint;
         generictype : ttypesym;
       begin
          old_object_option:=current_object_option;
@@ -545,15 +546,14 @@ implementation
          aktobjectdef.genericdef:=genericdef;
          if assigned(genericlist) then
            begin
-             generictype:=ttypesym(genericlist.first);
-             while assigned(generictype) do
+             for i:=0 to genericlist.count-1 do
                begin
+                 generictype:=ttypesym(genericlist[i]);
                  if generictype.restype.def.deftype=undefineddef then
                    include(aktobjectdef.defoptions,df_generic)
                  else
                    include(aktobjectdef.defoptions,df_specialization);
                  symtablestack.top.insert(generictype);
-                 generictype:=ttypesym(generictype.listnext);
                end;
            end;
 

+ 31 - 31
compiler/pdecsub.pas

@@ -381,10 +381,11 @@ implementation
       type
         tppv = (pv_none,pv_proc,pv_func);
       var
-        sc      : tsinglelist;
+        sc      : tlist;
         tt      : ttype;
         arrayelementtype : ttype;
         vs      : tparavarsym;
+        i       : longint;
         srsym   : tsym;
         pv      : tprocvardef;
         varspez : Tvarspez;
@@ -408,7 +409,7 @@ implementation
         { parsing a proc or procvar ? }
         currparast:=tparasymtable(pd.parast);
         { reset }
-        sc:=tsinglelist.create;
+        sc:=tlist.create;
         defaultrequired:=false;
         paranr:=0;
         { the variables are always public }
@@ -452,13 +453,13 @@ implementation
           defaultvalue:=nil;
           tt.reset;
           { read identifiers and insert with error type }
-          sc.reset;
+          sc.clear;
           repeat
             inc(paranr);
             vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrortype,[]);
             currparast.insert(vs);
             if assigned(vs.owner) then
-             sc.insert(vs)
+             sc.add(vs)
             else
              vs.free;
             consume(_ID);
@@ -561,8 +562,8 @@ implementation
                  begin
                    if try_to_consume(_EQUAL) then
                     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);
                       { prefix 'def' to the parameter name }
                       defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
@@ -589,32 +590,31 @@ implementation
              not(varspez in [vs_out,vs_var]) then
             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);
 
         if explicit_paraloc then

+ 56 - 57
compiler/pdecvar.pas

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

+ 37 - 23
compiler/pmodules.pas

@@ -135,11 +135,17 @@ implementation
 
     procedure create_dwarf;
       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 }
         if (tf_needs_dwarf_cfi in target_info.flags) and
            (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;
 
 
@@ -1438,27 +1444,35 @@ implementation
             exit;
           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;
 

+ 2 - 2
compiler/powerpc/agppcgas.pas

@@ -38,7 +38,7 @@ unit agppcgas;
     type
       PPPCGNUAssembler=^TPPCGNUAssembler;
       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 WriteInstruction(hp : tai);override;
        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
         if (target_info.system = system_powerpc_darwin) then
           case atype of

+ 2 - 2
compiler/powerpc/agppcmpw.pas

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

+ 1 - 1
compiler/ppu.pas

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

+ 1 - 1
compiler/ptconst.pas

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

+ 5 - 5
compiler/ptype.pas

@@ -41,7 +41,7 @@ interface
     { tdef }
     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);
 
     { reads a type definition }
@@ -80,7 +80,7 @@ implementation
         sym : tsym;
         genericdef : tstoreddef;
         generictype : ttypesym;
-        generictypelist : tsinglelist;
+        generictypelist : tlist;
       begin
         { retrieve generic def that we are going to replace }
         genericdef:=tstoreddef(pt1.resulttype.def);
@@ -104,7 +104,7 @@ implementation
           the genericdef we need to have a new def }
         err:=false;
         first:=true;
-        generictypelist:=tsinglelist.create;
+        generictypelist:=tlist.create;
         case genericdef.deftype of
           procdef :
             st:=genericdef.getsymtable(gs_para);
@@ -129,7 +129,7 @@ implementation
                 if pt2.nodetype=typen then
                   begin
                     generictype:=ttypesym.create(sym.realname,pt2.resulttype);
-                    generictypelist.insert(generictype);
+                    generictypelist.add(generictype);
                   end
                 else
                   begin
@@ -321,7 +321,7 @@ implementation
 
 
     { 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
         pt : tnode;
         tt2 : ttype;

+ 1 - 1
compiler/raatt.pas

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

+ 19 - 5
compiler/symbase.pas

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

+ 3 - 2
compiler/symdef.pas

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

+ 1 - 1
compiler/symtable.pas

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

+ 3 - 12
compiler/symtype.pas

@@ -1257,7 +1257,8 @@ implementation
 
     function  tcompilerppufile.getasmsymbol:tasmsymbol;
       begin
-        getasmsymbol:=tasmsymbol(pointer(ptrint(getlongint)));
+        getlongint;
+        getasmsymbol:=nil;
       end;
 
 
@@ -1418,17 +1419,7 @@ implementation
 
     procedure tcompilerppufile.putasmsymbol(s:tasmsymbol);
       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;
 
 {$ifdef MEMDEBUG}

+ 1 - 1
compiler/systems/t_go32v2.pas

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

+ 9 - 41
compiler/systems/t_linux.pas

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

+ 2 - 1
compiler/systems/t_win.pas

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

+ 2 - 0
compiler/verbose.pas

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

+ 51 - 46
compiler/x86/aasmcpu.pas

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

+ 8 - 8
compiler/x86/agx86int.pas

@@ -58,9 +58,9 @@ implementation
     const
       line_length = 70;
 
-      secnames : array[TAsmSectionType] of string[4] = ('',
+      secnames : array[TAsmSectiontype] of string[4] = ('',
         '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','',
-        '','','','','',
+        '','','',
         'idata$2','idata$4','idata$5','idata$6','idata$7','edata',
         '',
         '','','','',
@@ -343,7 +343,7 @@ implementation
 
 
     var
-      LasTSectype : TAsmSectionType;
+      LasTSectype : TAsmSectiontype;
       lastfileinfo : tfileposinfo;
       infile,
       lastinfile   : tinputfile;
@@ -644,9 +644,9 @@ implementation
              end;
            ait_label :
              begin
-               if tai_label(hp).l.is_used then
+               if tai_label(hp).labsym.is_used then
                 begin
-                  AsmWrite(tai_label(hp).l.name);
+                  AsmWrite(tai_label(hp).labsym.name);
                   if assigned(hp.next) and not(tai(hp.next).typ in
                      [ait_const,
                       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);
       begin
-        if tasmsymbol(p).defbind=AB_EXTERNAL then
+        if tasmsymbol(p).bind=AB_EXTERNAL then
           begin
             case target_asm.id of
               as_i386_masm,as_i386_wasm:

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov