Browse Source

+ append a TIS trailer after the debug ELF (this helps the watcom debugger find
the beginning of the ELF debug image)

git-svn-id: trunk@39229 -

nickysn 7 years ago
parent
commit
84b5265312
1 changed files with 48 additions and 1 deletions
  1. 48 1
      compiler/ogomf.pas

+ 48 - 1
compiler/ogomf.pas

@@ -347,6 +347,34 @@ implementation
       $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,
       $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,
       $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20);
       $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20);
 
 
+{****************************************************************************
+                                TTISTrailer
+****************************************************************************}
+
+    const
+      TIS_TRAILER_SIGNATURE: array[1..4] of char='TIS'#0;
+      TIS_TRAILER_VENDOR_TIS=0;
+      TIS_TRAILER_TYPE_TIS_DWARF=0;
+
+    type
+      TTISTrailer=record
+        tis_signature: array[1..4] of char;
+        tis_vendor,
+        tis_type,
+        tis_size: LongWord;
+      end;
+
+    procedure MayBeSwapTISTrailer(var h: TTISTrailer);
+      begin
+        if source_info.endian<>target_info.endian then
+          with h do
+            begin
+              tis_vendor:=swapendian(tis_vendor);
+              tis_type:=swapendian(tis_type);
+              tis_size:=swapendian(tis_size);
+            end;
+      end;
+
 {****************************************************************************
 {****************************************************************************
                                 TOmfObjSymbol
                                 TOmfObjSymbol
 ****************************************************************************}
 ****************************************************************************}
@@ -2647,12 +2675,16 @@ implementation
         elfsections_count: Word;
         elfsections_count: Word;
         elfsechdrs: array of TElf32sechdr;
         elfsechdrs: array of TElf32sechdr;
         shstrndx: Word;
         shstrndx: Word;
-        next_section_ofs: LongWord;
+        next_section_ofs, elf_start_pos, elf_end_pos: LongWord;
         ElfHeader: TElf32header;
         ElfHeader: TElf32header;
         shstrtabsect_data: TDynamicArray=Nil;
         shstrtabsect_data: TDynamicArray=Nil;
         I, elfsecidx, J: Integer;
         I, elfsecidx, J: Integer;
         ObjSec: TOmfObjSection;
         ObjSec: TOmfObjSection;
+        tis_trailer: TTISTrailer;
       begin
       begin
+        { mark the offset of the start of the ELF image }
+        elf_start_pos:=Writer.Size;
+
         { count the debug sections }
         { count the debug sections }
         debugsections_count:=0;
         debugsections_count:=0;
         for I:=0 to ExeSectionList.Count-1 do
         for I:=0 to ExeSectionList.Count-1 do
@@ -2760,6 +2792,21 @@ implementation
         { write .shstrtab section data }
         { write .shstrtab section data }
         Writer.writearray(shstrtabsect_data);
         Writer.writearray(shstrtabsect_data);
 
 
+        { mark the offset past the end of the ELF image }
+        elf_end_pos:=Writer.Size;
+
+        { write TIS trailer (not part of the ELF image) }
+        FillChar(tis_trailer,sizeof(tis_trailer),0);
+        with tis_trailer do
+          begin
+            tis_signature:=TIS_TRAILER_SIGNATURE;
+            tis_vendor:=TIS_TRAILER_VENDOR_TIS;
+            tis_type:=TIS_TRAILER_TYPE_TIS_DWARF;
+            tis_size:=(elf_end_pos-elf_start_pos)+sizeof(tis_trailer);
+          end;
+        MayBeSwapTISTrailer(tis_trailer);
+        Writer.write(tis_trailer,sizeof(tis_trailer));
+
         Result:=True;
         Result:=True;
 cleanup:
 cleanup:
         shstrtabsect_data.Free;
         shstrtabsect_data.Free;