Browse Source

* fixed section index when not all sections are used

peter 26 years ago
parent
commit
116e172bbc
1 changed files with 28 additions and 25 deletions
  1. 28 25
      compiler/og386cff.pas

+ 28 - 25
compiler/og386cff.pas

@@ -69,7 +69,8 @@ unit og386cff;
 
 
     uses
     uses
        cobjects,
        cobjects,
-       og386,i386base,aasm;
+       systems,i386base,aasm,
+       og386;
 
 
     type
     type
        preloc = ^treloc;
        preloc = ^treloc;
@@ -85,7 +86,7 @@ unit og386cff;
        tsymbol = packed record
        tsymbol = packed record
          name    : string[8];
          name    : string[8];
          strpos  : longint;
          strpos  : longint;
-         section : longint;
+         section : tsection;
          value   : longint;
          value   : longint;
          typ     : TAsmsymtype;
          typ     : TAsmsymtype;
        end;
        end;
@@ -93,6 +94,7 @@ unit og386cff;
        pcoffsection = ^tcoffsection;
        pcoffsection = ^tcoffsection;
        tcoffsection = object
        tcoffsection = object
           index : tsection;
           index : tsection;
+          secidx : longint;
           data  : PDynamicArray;
           data  : PDynamicArray;
           len,
           len,
           pos,
           pos,
@@ -215,15 +217,6 @@ unit og386cff;
         end;
         end;
 
 
 
 
-      const
-        sec_2_str : array[tsection] of string[8]=('',
-          '.text','.data','.bss',
-          '.stab','.stabstr',
-          '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
-          ''
-        );
-
-
 {****************************************************************************
 {****************************************************************************
                                TSection
                                TSection
 ****************************************************************************}
 ****************************************************************************}
@@ -231,6 +224,7 @@ unit og386cff;
     constructor tcoffsection.init(sec:TSection;Aflags:longint);
     constructor tcoffsection.init(sec:TSection;Aflags:longint);
       begin
       begin
         index:=sec;
         index:=sec;
+        secidx:=0;
         flags:=AFlags;
         flags:=AFlags;
         relocHead:=nil;
         relocHead:=nil;
         relocTail:=@relocHead;
         relocTail:=@relocHead;
@@ -440,7 +434,7 @@ unit og386cff;
           of the symbol }
           of the symbol }
         if p^.typ in [AS_LOCAL,AS_GLOBAL] then
         if p^.typ in [AS_LOCAL,AS_GLOBAL] then
          begin
          begin
-           sym.section:=ord(p^.section);
+           sym.section:=p^.section;
            sym.value:=p^.address;
            sym.value:=p^.address;
          end;
          end;
         { update the asmsymbol index }
         { update the asmsymbol index }
@@ -581,12 +575,12 @@ unit og386cff;
            if assigned(r^.symbol) then
            if assigned(r^.symbol) then
             begin
             begin
               if (r^.symbol^.typ=AS_LOCAL) then
               if (r^.symbol^.typ=AS_LOCAL) then
-               rel.sym:=2*ord(r^.symbol^.section)
+               rel.sym:=2*sects[r^.symbol^.section]^.secidx
               else
               else
                rel.sym:=r^.symbol^.idx+initsym;
                rel.sym:=r^.symbol^.idx+initsym;
             end
             end
            else
            else
-            rel.sym:=2*ord(r^.section);
+            rel.sym:=2*sects[r^.section]^.secidx;
            case r^.relative of
            case r^.relative of
              relative_true  : rel.relative:=$14;
              relative_true  : rel.relative:=$14;
              relative_false : rel.relative:=$6;
              relative_false : rel.relative:=$6;
@@ -622,6 +616,7 @@ unit og386cff;
       var
       var
         filename : string[18];
         filename : string[18];
         sec : tsection;
         sec : tsection;
+        sectionval,
         i   : longint;
         i   : longint;
         globalval : byte;
         globalval : byte;
         secrec : coffsectionrec;
         secrec : coffsectionrec;
@@ -632,13 +627,12 @@ unit og386cff;
         fillchar(filename,sizeof(filename),0);
         fillchar(filename,sizeof(filename),0);
         filename:=SplitFileName(current_module^.mainsource^);
         filename:=SplitFileName(current_module^.mainsource^);
         writer^.write(filename[1],sizeof(filename)-1);
         writer^.write(filename[1],sizeof(filename)-1);
-        { The section records, with their auxiliaries }
-        i:=0;
+        { The section records, with their auxiliaries, also store the
+          symbol index }
         for sec:=low(tsection) to high(tsection) do
         for sec:=low(tsection) to high(tsection) do
          if assigned(sects[sec]) then
          if assigned(sects[sec]) then
           begin
           begin
-            inc(i);
-            write_symbol(sec_2_str[sec],-1,{sects[sec]^.pos}0,i,3,1);
+            write_symbol(target_asm.secnames[sec],-1,{sects[sec]^.pos}0,sects[sec]^.secidx,3,1);
             fillchar(secrec,sizeof(secrec),0);
             fillchar(secrec,sizeof(secrec),0);
             secrec.len:=sects[sec]^.len;
             secrec.len:=sects[sec]^.len;
             secrec.nrelocs:=sects[sec]^.nrelocs;
             secrec.nrelocs:=sects[sec]^.nrelocs;
@@ -653,14 +647,18 @@ unit og386cff;
              globalval:=3
              globalval:=3
            else
            else
              globalval:=2;
              globalval:=2;
-           write_symbol(sym.name,sym.strpos,sym.value,sym.section,globalval,0);
+           if assigned(sects[sym.section]) then
+             sectionval:=sects[sym.section]^.secidx
+           else
+             sectionval:=0;
+           write_symbol(sym.name,sym.strpos,sym.value,sectionval,globalval,0);
          end;
          end;
       end;
       end;
 
 
 
 
     procedure tgenericcoffoutput.writetodisk;
     procedure tgenericcoffoutput.writetodisk;
       var
       var
-        datapos,
+        datapos,secidx,
         nsects,pos,sympos,i,fillsize : longint;
         nsects,pos,sympos,i,fillsize : longint;
         sec    : tsection;
         sec    : tsection;
         header : coffheader;
         header : coffheader;
@@ -693,9 +691,12 @@ unit og386cff;
         pos:=0;
         pos:=0;
         initsym:=2; { 2 for the file }
         initsym:=2; { 2 for the file }
         { sections first }
         { sections first }
+        secidx:=0;
         for sec:=low(tsection) to high(tsection) do
         for sec:=low(tsection) to high(tsection) do
          if assigned(sects[sec]) then
          if assigned(sects[sec]) then
           begin
           begin
+            inc(secidx);
+            sects[sec]^.secidx:=secidx;
             sects[sec]^.pos:=pos;
             sects[sec]^.pos:=pos;
             sects[sec]^.datapos:=datapos;
             sects[sec]^.datapos:=datapos;
             inc(pos,sects[sec]^.len);
             inc(pos,sects[sec]^.len);
@@ -721,15 +722,14 @@ unit og386cff;
         header.nsects:=nsects;
         header.nsects:=nsects;
         header.sympos:=sympos;
         header.sympos:=sympos;
         header.syms:=syms^.count+initsym;
         header.syms:=syms^.count+initsym;
-        if not win32 then
-         header.flag:=$104;
+        header.flag:=$104;
         writer^.write(header,sizeof(header));
         writer^.write(header,sizeof(header));
       { Section headers }
       { Section headers }
         for sec:=low(tsection) to high(tsection) do
         for sec:=low(tsection) to high(tsection) do
          if assigned(sects[sec]) then
          if assigned(sects[sec]) then
           begin
           begin
             fillchar(sechdr,sizeof(sechdr),0);
             fillchar(sechdr,sizeof(sechdr),0);
-            move(sec_2_str[sec][1],sechdr.name,length(sec_2_str[sec]));
+            move(target_asm.secnames[sec][1],sechdr.name,length(target_asm.secnames[sec]));
             if not win32 then
             if not win32 then
               sechdr.vsize:=sects[sec]^.pos
               sechdr.vsize:=sects[sec]^.pos
             else if sec=sec_bss then
             else if sec=sec_bss then
@@ -817,7 +817,7 @@ unit og386cff;
 
 
     function twin32coffoutput.text_flags : longint;
     function twin32coffoutput.text_flags : longint;
       begin
       begin
-        text_flags:={ $60500020}$60300020{changed to get same as asw.exe (PM)};
+        text_flags:=$60000020; { same as as 2.9.1 }
       end;
       end;
 
 
     function twin32coffoutput.data_flags : longint;
     function twin32coffoutput.data_flags : longint;
@@ -839,7 +839,10 @@ unit og386cff;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.1  1999-05-01 13:24:24  peter
+  Revision 1.2  1999-05-02 22:36:35  peter
+    * fixed section index when not all sections are used
+
+  Revision 1.1  1999/05/01 13:24:24  peter
     * merged nasm compiler
     * merged nasm compiler
     * old asm moved to oldasm/
     * old asm moved to oldasm/