Browse Source

* ELF writer works now also with -g
* ELF writer is default again for linux

peter 25 years ago
parent
commit
8f20bd887d
4 changed files with 79 additions and 27 deletions
  1. 6 2
      compiler/aasm.pas
  2. 10 2
      compiler/globals.pas
  3. 57 21
      compiler/og386elf.pas
  4. 6 2
      compiler/systems.pas

+ 6 - 2
compiler/aasm.pas

@@ -1118,7 +1118,7 @@ uses
             begin
             begin
               if (refs>0) and
               if (refs>0) and
                  (section=Sec_none) and
                  (section=Sec_none) and
-                 (bind<>AB_EXTERNAL) then
+                 not(bind in [AB_EXTERNAL,AB_COMMON]) then
                Message1(asmw_e_undefined_label,name);
                Message1(asmw_e_undefined_label,name);
             end;
             end;
            hp:=pasmsymbol(hp^.next);
            hp:=pasmsymbol(hp^.next);
@@ -1180,7 +1180,11 @@ uses
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.7  2000-08-12 15:34:21  peter
+  Revision 1.8  2000-08-12 19:14:58  peter
+    * ELF writer works now also with -g
+    * ELF writer is default again for linux
+
+  Revision 1.7  2000/08/12 15:34:21  peter
     + usedasmsymbollist to check and reset only the used symbols (merged)
     + usedasmsymbollist to check and reset only the used symbols (merged)
 
 
   Revision 1.6  2000/08/09 19:49:44  peter
   Revision 1.6  2000/08/09 19:49:44  peter

+ 10 - 2
compiler/globals.pas

@@ -443,7 +443,11 @@ implementation
       return value <i> aligned <a> boundary
       return value <i> aligned <a> boundary
     }
     }
       begin
       begin
-        align:=(i+a-1) and not(a-1);
+        { for 0 and 1 no aligning is needed }
+        if a<=1 then
+         align:=i
+        else
+         align:=(i+a-1) and not(a-1);
       end;
       end;
 
 
 
 
@@ -1562,7 +1566,11 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.5  2000-08-12 15:30:44  peter
+  Revision 1.6  2000-08-12 19:14:58  peter
+    * ELF writer works now also with -g
+    * ELF writer is default again for linux
+
+  Revision 1.5  2000/08/12 15:30:44  peter
     * IDE patch for stream reading (merged)
     * IDE patch for stream reading (merged)
 
 
   Revision 1.4  2000/08/02 19:49:59  peter
   Revision 1.4  2000/08/02 19:49:59  peter

+ 57 - 21
compiler/og386elf.pas

@@ -81,7 +81,9 @@ unit og386elf;
           destructor  done;
           destructor  done;
           function  write(var d;l:longint):longint;
           function  write(var d;l:longint):longint;
           function  writestr(const s:string):longint;
           function  writestr(const s:string):longint;
-          procedure align(l:longint);
+          procedure writealign(l:longint);
+          function  aligneddatalen:longint;
+          procedure alignsection;
           procedure alloc(l:longint);
           procedure alloc(l:longint);
           procedure addsymreloc(ofs:longint;p:pasmsymbol;relative:relative_type);
           procedure addsymreloc(ofs:longint;p:pasmsymbol;relative:relative_type);
           procedure addsectionreloc(ofs:longint;sec:tsection;relative:relative_type);
           procedure addsectionreloc(ofs:longint;sec:tsection;relative:relative_type);
@@ -259,6 +261,17 @@ unit og386elf;
               AType:=SHT_NOBITS;
               AType:=SHT_NOBITS;
               AAlign:=4;
               AAlign:=4;
             end;
             end;
+          sec_stab :
+            begin
+              AType:=SHT_PROGBITS;
+              AAlign:=4;
+              Aentsize:=sizeof(telf32stab);
+            end;
+          sec_stabstr :
+            begin
+              AType:=SHT_STRTAB;
+              AAlign:=1;
+            end;
         end;
         end;
         initname(target_asm.secnames[sec],Atype,Aflags,0,0,Aalign,Aentsize);
         initname(target_asm.secnames[sec],Atype,Aflags,0,0,Aalign,Aentsize);
       end;
       end;
@@ -321,11 +334,14 @@ unit og386elf;
       end;
       end;
 
 
 
 
-    procedure telf32section.align(l:longint);
+    procedure telf32section.writealign(l:longint);
       var
       var
         i : longint;
         i : longint;
         empty : array[0..63] of char;
         empty : array[0..63] of char;
       begin
       begin
+        { no alignment needed for 0 or 1 }
+        if l<=1 then
+         exit;
         i:=datalen mod l;
         i:=datalen mod l;
         if i>0 then
         if i>0 then
          begin
          begin
@@ -339,6 +355,18 @@ unit og386elf;
       end;
       end;
 
 
 
 
+    function telf32section.aligneddatalen:longint;
+      begin
+        aligneddatalen:=align(datalen,addralign);
+      end;
+
+
+    procedure telf32section.alignsection;
+      begin
+        writealign(addralign);
+      end;
+
+
     procedure telf32section.alloc(l:longint);
     procedure telf32section.alloc(l:longint);
       begin
       begin
         if assigned(Data) then
         if assigned(Data) then
@@ -476,9 +504,6 @@ unit og386elf;
         if (p^.section<>sec_none) and not(assigned(sects[p^.section])) then
         if (p^.section<>sec_none) and not(assigned(sects[p^.section])) then
           createsection(p^.section);
           createsection(p^.section);
         FillChar(sym,sizeof(sym),0);
         FillChar(sym,sizeof(sym),0);
-        { symbolname, write the #0 separate to overcome 255+1 char not possible }
-        sym.name:=strtabsect^.writestr(p^.name);
-        strtabsect^.writestr(#0);
         sym.size:=p^.size;
         sym.size:=p^.size;
         sym.bind:=p^.bind;
         sym.bind:=p^.bind;
         sym.typ:=p^.typ;
         sym.typ:=p^.typ;
@@ -499,8 +524,14 @@ unit og386elf;
         { update the asmsymbol index }
         { update the asmsymbol index }
         p^.idx:=syms^.count;
         p^.idx:=syms^.count;
         { store the symbol, but not the local ones (PM) }
         { store the symbol, but not the local ones (PM) }
-        if (sym.bind<>AB_LOCAL) {or (copy(p^.name,1,2)<>'.L')} then
-          syms^.write(sym,1);
+        if (sym.bind<>AB_LOCAL) then
+         begin
+           { symbolname, write the #0 separate to overcome 255+1 char not possible }
+           sym.name:=strtabsect^.writestr(p^.name);
+           strtabsect^.writestr(#0);
+           { symbol }
+           syms^.write(sym,1);
+         end;
         { make the exported syms known to the objectwriter
         { make the exported syms known to the objectwriter
           (needed for .a generation) }
           (needed for .a generation) }
         if (sym.bind in [AB_GLOBAL,AB_COMMON]) then
         if (sym.bind in [AB_GLOBAL,AB_COMMON]) then
@@ -525,7 +556,8 @@ unit og386elf;
 
 
 
 
     procedure telf32output.writealign(len:longint);
     procedure telf32output.writealign(len:longint);
-      var modulo : longint;
+      var
+        modulo : longint;
       begin
       begin
         if not assigned(sects[currsec]) then
         if not assigned(sects[currsec]) then
          createsection(currsec);
          createsection(currsec);
@@ -895,17 +927,17 @@ unit og386elf;
           begin
           begin
             sects[sec]^.datapos:=datapos;
             sects[sec]^.datapos:=datapos;
             if assigned(sects[sec]^.data) then
             if assigned(sects[sec]^.data) then
-              inc(datapos,align(sects[sec]^.datalen,4));
+              inc(datapos,sects[sec]^.aligneddatalen);
           end;
           end;
         { shstrtab }
         { shstrtab }
         shstrtabsect^.datapos:=datapos;
         shstrtabsect^.datapos:=datapos;
-        inc(datapos,align(shstrtabsect^.datalen,4));
+        inc(datapos,shstrtabsect^.aligneddatalen);
         { section headers }
         { section headers }
         shoffset:=datapos;
         shoffset:=datapos;
         inc(datapos,nsects*sizeof(telf32sechdr));
         inc(datapos,nsects*sizeof(telf32sechdr));
         { symtab }
         { symtab }
         symtabsect^.datapos:=datapos;
         symtabsect^.datapos:=datapos;
-        inc(datapos,align(symtabsect^.datalen,4));
+        inc(datapos,symtabsect^.aligneddatalen);
         { strtab }
         { strtab }
         strtabsect^.datapos:=datapos;
         strtabsect^.datapos:=datapos;
         inc(datapos,align(strtabsect^.datalen,4));
         inc(datapos,align(strtabsect^.datalen,4));
@@ -915,7 +947,7 @@ unit og386elf;
             assigned(sects[sec]^.relocsect) then
             assigned(sects[sec]^.relocsect) then
           begin
           begin
             sects[sec]^.relocsect^.datapos:=datapos;
             sects[sec]^.relocsect^.datapos:=datapos;
-            inc(datapos,align(sects[sec]^.relocsect^.datalen,4));
+            inc(datapos,sects[sec]^.relocsect^.aligneddatalen);
           end;
           end;
       { Write ELF Header }
       { Write ELF Header }
         fillchar(header,sizeof(header),0);
         fillchar(header,sizeof(header),0);
@@ -940,19 +972,19 @@ unit og386elf;
           begin
           begin
             { For the stab section we need an HdrSym which can now be
             { For the stab section we need an HdrSym which can now be
                 calculated more easily }
                 calculated more easily }
-              if sec=sec_stab then
-               begin
+            if sec=sec_stab then
+             begin
                pelf32stab(sects[sec_stab]^.data^.data)^.nvalue:=sects[sec_stabstr]^.datalen;
                pelf32stab(sects[sec_stab]^.data^.data)^.nvalue:=sects[sec_stabstr]^.datalen;
                pelf32stab(sects[sec_stab]^.data^.data)^.strpos:=1;
                pelf32stab(sects[sec_stab]^.data^.data)^.strpos:=1;
                pelf32stab(sects[sec_stab]^.data^.data)^.ndesc:=
                pelf32stab(sects[sec_stab]^.data^.data)^.ndesc:=
                  (sects[sec_stab]^.datalen div sizeof(telf32stab))-1{+1 according to gas output PM};
                  (sects[sec_stab]^.datalen div sizeof(telf32stab))-1{+1 according to gas output PM};
              end;
              end;
             { save the original section length }
             { save the original section length }
-            sects[sec]^.align(4);
+            sects[sec]^.alignsection;
             writer^.write(sects[sec]^.data^.data^,sects[sec]^.data^.usedsize);
             writer^.write(sects[sec]^.data^.data^,sects[sec]^.data^.usedsize);
           end;
           end;
       { .shstrtab }
       { .shstrtab }
-        shstrtabsect^.align(4);
+        shstrtabsect^.alignsection;
         writer^.write(shstrtabsect^.data^.data^,shstrtabsect^.data^.usedsize);
         writer^.write(shstrtabsect^.data^.data^,shstrtabsect^.data^.usedsize);
       { section headers, start with an empty header for sh_undef }
       { section headers, start with an empty header for sh_undef }
         writer^.write(empty,sizeof(telf32sechdr));
         writer^.write(empty,sizeof(telf32sechdr));
@@ -967,26 +999,30 @@ unit og386elf;
         writesectionheader(symtabsect);
         writesectionheader(symtabsect);
         writesectionheader(strtabsect);
         writesectionheader(strtabsect);
       { .symtab }
       { .symtab }
-        symtabsect^.align(4);
+        symtabsect^.alignsection;
         writer^.write(symtabsect^.data^.data^,symtabsect^.data^.usedsize);
         writer^.write(symtabsect^.data^.data^,symtabsect^.data^.usedsize);
       { .strtab }
       { .strtab }
-        strtabsect^.align(4);
+        strtabsect^.writealign(4);
         writer^.write(strtabsect^.data^.data^,strtabsect^.data^.usedsize);
         writer^.write(strtabsect^.data^.data^,strtabsect^.data^.usedsize);
       { .rel sections }
       { .rel sections }
         for sec:=low(tsection) to high(tsection) do
         for sec:=low(tsection) to high(tsection) do
          if assigned(sects[sec]) and
          if assigned(sects[sec]) and
             assigned(sects[sec]^.relocsect) then
             assigned(sects[sec]^.relocsect) then
           begin
           begin
-            sects[sec]^.relocsect^.align(4);
+            sects[sec]^.relocsect^.alignsection;
             writer^.write(sects[sec]^.relocsect^.data^.data^,sects[sec]^.relocsect^.data^.usedsize);
             writer^.write(sects[sec]^.relocsect^.data^.data^,sects[sec]^.relocsect^.data^.usedsize);
           end;
           end;
-        end;
+      end;
 
 
 
 
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2000-07-13 12:08:26  michael
+  Revision 1.4  2000-08-12 19:14:58  peter
+    * ELF writer works now also with -g
+    * ELF writer is default again for linux
+
+  Revision 1.3  2000/07/13 12:08:26  michael
   + patched to 1.1.0 with former 1.09patch from peter
   + patched to 1.1.0 with former 1.09patch from peter
 
 
   Revision 1.2  2000/07/13 11:32:43  michael
   Revision 1.2  2000/07/13 11:32:43  michael

+ 6 - 2
compiler/systems.pas

@@ -1049,7 +1049,7 @@ implementation
             resobjext   : '.or';
             resobjext   : '.or';
             exeext      : '';
             exeext      : '';
             os          : os_i386_Linux;
             os          : os_i386_Linux;
-            assem       : as_i386_as;
+            assem       : as_i386_elf;
             assemsrc    : as_i386_as;
             assemsrc    : as_i386_as;
             ar          : ar_i386_ar;
             ar          : ar_i386_ar;
             res         : res_none;
             res         : res_none;
@@ -1660,7 +1660,11 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.4  2000-07-14 21:29:38  michael
+  Revision 1.5  2000-08-12 19:14:59  peter
+    * ELF writer works now also with -g
+    * ELF writer is default again for linux
+
+  Revision 1.4  2000/07/14 21:29:38  michael
   * Back to external assembler till peter fixes gdb
   * Back to external assembler till peter fixes gdb
 
 
   Revision 1.3  2000/07/13 12:08:28  michael
   Revision 1.3  2000/07/13 12:08:28  michael