Browse Source

* added alignment code for .bss
* stabs correct but externalbss disabled
would need a special treatment in writestabs

pierre 26 years ago
parent
commit
e9381eca00
3 changed files with 107 additions and 13 deletions
  1. 63 9
      compiler/ag386bin.pas
  2. 20 1
      compiler/og386.pas
  3. 24 3
      compiler/og386cff.pas

+ 63 - 9
compiler/ag386bin.pas

@@ -26,7 +26,7 @@
 unit ag386bin;
 
 {$define MULTIPASS}
-{$define EXTERNALBSS}
+{define EXTERNALBSS}
 
   interface
 
@@ -316,13 +316,14 @@ unit ag386bin;
     function ti386binasmlist.TreePass0(hp:pai):pai;
       var
         lastsec : tsection;
+        l : longint;
       begin
         while assigned(hp) do
          begin
            case hp^.typ of
              ait_align :
                begin
-                 if objectalloc^.sectionsize mod pai_align(hp)^.aligntype<>0 then
+                 if (objectalloc^.sectionsize mod pai_align(hp)^.aligntype)<>0 then
                    begin
                      pai_align(hp)^.fillsize:=pai_align(hp)^.aligntype-
                        (objectalloc^.sectionsize mod pai_align(hp)^.aligntype);
@@ -335,8 +336,20 @@ unit ag386bin;
                begin
 {$ifdef EXTERNALBSS}
                  if not pai_datablock(hp)^.is_global then
-                  objectalloc^.sectionalloc(pai_datablock(hp)^.size);
+                  begin
+                     l:=pai_datablock(hp)^.size;
+                     if l>2 then
+                       objectalloc^.sectionalign(4)
+                     else if l>1 then
+                       objectalloc^.sectionalign(2);
+                     objectalloc^.sectionalloc(pai_datablock(hp)^.size);
+                  end;
 {$else}
+                 l:=pai_datablock(hp)^.size;
+                 if l>2 then
+                   objectalloc^.sectionalign(4)
+                 else if l>1 then
+                   objectalloc^.sectionalign(2);
                  objectalloc^.sectionalloc(pai_datablock(hp)^.size);
 {$endif}
                end;
@@ -352,6 +365,12 @@ unit ag386bin;
                objectalloc^.sectionalloc(4);
              ait_real_80bit :
                objectalloc^.sectionalloc(10);
+             ait_comp :
+{$ifdef I386}
+               objectalloc^.sectionalloc(8);
+{$else not I386}
+               Message(asmw_f_comp_not_supported);
+{$endif I386}
              ait_const_rva,
              ait_const_symbol :
                objectalloc^.sectionalloc(4);
@@ -393,6 +412,8 @@ unit ag386bin;
 
 
     function ti386binasmlist.TreePass1(hp:pai):pai;
+      var
+        l : longint;
       begin
         while assigned(hp) do
          begin
@@ -410,7 +431,7 @@ unit ag386bin;
            case hp^.typ of
              ait_align :
                begin
-                 if objectalloc^.sectionsize mod pai_align(hp)^.aligntype<>0 then
+                 if (objectalloc^.sectionsize mod pai_align(hp)^.aligntype)<>0 then
                    begin
                      pai_align(hp)^.fillsize:=pai_align(hp)^.aligntype-
                        (objectalloc^.sectionsize mod pai_align(hp)^.aligntype);
@@ -431,16 +452,25 @@ unit ag386bin;
                   end
                  else
                   begin
+                    l:=pai_datablock(hp)^.size;
+                    if l>2 then
+                      objectalloc^.sectionalign(4)
+                    else if l>1 then
+                      objectalloc^.sectionalign(2);
                     pai_datablock(hp)^.sym^.typ:=AS_LOCAL;
                     pai_datablock(hp)^.sym^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,pai_datablock(hp)^.size);
+                    objectalloc^.sectionalloc(pai_datablock(hp)^.size);
                   end;
-                 if not pai_datablock(hp)^.is_global then
-                  objectalloc^.sectionalloc(pai_datablock(hp)^.size);
 {$else}
                  if pai_datablock(hp)^.is_global then
                   pai_datablock(hp)^.sym^.typ:=AS_GLOBAL
                  else
                   pai_datablock(hp)^.sym^.typ:=AS_LOCAL;
+                 l:=pai_datablock(hp)^.size;
+                 if l>2 then
+                   objectalloc^.sectionalign(4)
+                 else if l>1 then
+                   objectalloc^.sectionalign(2);
                  pai_datablock(hp)^.sym^.setaddress(objectalloc^.currsec,objectalloc^.sectionsize,pai_datablock(hp)^.size);
                  objectalloc^.sectionalloc(pai_datablock(hp)^.size);
 {$endif}
@@ -457,6 +487,12 @@ unit ag386bin;
                objectalloc^.sectionalloc(4);
              ait_real_80bit :
                objectalloc^.sectionalloc(10);
+             ait_comp :
+{$ifdef I386}
+               objectalloc^.sectionalloc(8);
+{$else not I386}
+               Message(asmw_f_comp_not_supported);
+{$endif I386}
              ait_const_rva,
              ait_const_symbol :
                objectalloc^.sectionalloc(4);
@@ -517,8 +553,6 @@ unit ag386bin;
                objectalloc^.sectionalloc(pai386(hp)^.Pass1(objectalloc^.sectionsize));
              ait_direct :
                Message(asmw_f_direct_not_supported);
-             ait_comp :
-               Message(asmw_f_comp_not_supported);
              ait_cut :
                break;
            end;
@@ -540,6 +574,9 @@ unit ag386bin;
         );
       var
         l,j : longint;
+{$ifdef I386}
+        co : comp;
+{$endif I386}
       begin
         { main loop }
         while assigned(hp) do
@@ -588,6 +625,11 @@ unit ag386bin;
                objectoutput^.writesymbol(pai_symbol(hp)^.sym);
              ait_datablock :
                begin
+                 l:=pai_datablock(hp)^.size;
+                 if l>2 then
+                   objectoutput^.writealign(4)
+                 else if l>1 then
+                   objectoutput^.writealign(2);
                  objectoutput^.writesymbol(pai_datablock(hp)^.sym);
 {$ifdef EXTERNALBSS}
                  if not pai_datablock(hp)^.is_global then
@@ -606,6 +648,13 @@ unit ag386bin;
                objectoutput^.writebytes(pai_single(hp)^.value,4);
              ait_real_80bit :
                objectoutput^.writebytes(pai_extended(hp)^.value,10);
+{$ifdef I386}
+             ait_comp :
+               begin
+                 co:=pai_comp(hp)^.value;
+                 objectoutput^.writebytes(co,8);
+               end;
+{$endif I386}
              ait_string :
                objectoutput^.writebytes(pai_string(hp)^.str^,pai_string(hp)^.len);
              ait_const_rva :
@@ -774,7 +823,12 @@ unit ag386bin;
 end.
 {
   $Log$
-  Revision 1.5  1999-05-06 09:05:07  peter
+  Revision 1.6  1999-05-07 00:36:58  pierre
+    * added alignment code for .bss
+    * stabs correct but externalbss disabled
+      would need a special treatment in writestabs
+
+  Revision 1.5  1999/05/06 09:05:07  peter
     * generic write_float and str_float
     * fixed constant float conversions
 

+ 20 - 1
compiler/og386.pas

@@ -49,6 +49,7 @@ unit og386;
          procedure setsection(sec:tsection);
          function  sectionsize:longint;
          procedure sectionalloc(l:longint);
+         procedure sectionalign(l:longint);
          procedure staballoc(p:pchar);
          procedure resetsections;
        end;
@@ -69,6 +70,7 @@ unit og386;
          procedure setsectionsizes(var s:tsecsize);virtual;
          procedure writebytes(var data;len:longint);virtual;
          procedure writealloc(len:longint);virtual;
+         procedure writealign(len:longint);virtual;
          procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
          procedure writesymbol(p:pasmsymbol);virtual;
          procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
@@ -119,6 +121,13 @@ unit og386;
       end;
 
 
+    procedure tobjectalloc.sectionalign(l:longint);
+      begin
+        if (secsize[currsec] mod l)<>0 then
+          inc(secsize[currsec],l-(secsize[currsec] mod l));
+      end;
+
+
     procedure tobjectalloc.staballoc(p:pchar);
       begin
         inc(secsize[sec_stab]);
@@ -245,6 +254,11 @@ unit og386;
         RunError(211);
       end;
 
+    procedure tobjectoutput.writealign(len:longint);
+      begin
+        RunError(211);
+      end;
+
    procedure tobjectoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);
       begin
         RunError(211);
@@ -253,7 +267,12 @@ unit og386;
 end.
 {
   $Log$
-  Revision 1.5  1999-05-05 22:21:57  peter
+  Revision 1.6  1999-05-07 00:36:56  pierre
+    * added alignment code for .bss
+    * stabs correct but externalbss disabled
+      would need a special treatment in writestabs
+
+  Revision 1.5  1999/05/05 22:21:57  peter
     * updated messages
 
   Revision 1.4  1999/05/05 17:34:30  peter

+ 24 - 3
compiler/og386cff.pas

@@ -128,6 +128,7 @@ unit og386cff;
          procedure setsectionsizes(var s:tsecsize);virtual;
          procedure writebytes(var data;len:longint);virtual;
          procedure writealloc(len:longint);virtual;
+         procedure writealign(len:longint);virtual;
          procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
          procedure writesymbol(p:pasmsymbol);virtual;
          procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
@@ -473,6 +474,17 @@ unit og386cff;
       end;
 
 
+    procedure tgenericcoffoutput.writealign(len:longint);
+      var modulo : longint;
+      begin
+        if not assigned(sects[currsec]) then
+         createsection(currsec);
+        modulo:=sects[currsec]^.len mod len;
+        if modulo > 0 then
+          sects[currsec]^.alloc(len-modulo);
+      end;
+
+
     procedure tgenericcoffoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
       var
         symaddr : longint;
@@ -537,9 +549,11 @@ unit og386cff;
         stab : coffstab;
         s : tsection;
       begin
+        { This is wrong because
+          sec_none is used only for external bss
         if section=sec_none then
          s:=currsec
-        else
+        else }
          s:=section;
         { local var can be at offset -1 !! PM }
         if reloc then
@@ -588,8 +602,10 @@ unit og386cff;
               else
                rel.sym:=r^.symbol^.idx+initsym;
             end
+           else if r^.section<>sec_none then
+            rel.sym:=2*sects[r^.section]^.secidx
            else
-            rel.sym:=2*sects[r^.section]^.secidx;
+            rel.sym:=0;
            case r^.relative of
              relative_true  : rel.relative:=$14;
              relative_false : rel.relative:=$6;
@@ -884,7 +900,12 @@ unit og386cff;
 end.
 {
   $Log$
-  Revision 1.3  1999-05-05 17:34:31  peter
+  Revision 1.4  1999-05-07 00:36:57  pierre
+    * added alignment code for .bss
+    * stabs correct but externalbss disabled
+      would need a special treatment in writestabs
+
+  Revision 1.3  1999/05/05 17:34:31  peter
     * output is more like as 2.9.1
     * stabs really working for go32v2