Explorar el Código

* secrel32 relocation support required by dwarf2 under windows

git-svn-id: trunk@7172 -
peter hace 18 años
padre
commit
29ffdefacb

+ 1 - 0
compiler/aasmtai.pas

@@ -98,6 +98,7 @@ interface
           aitconst_uleb128bit,
           aitconst_uleb128bit,
           { win32 only }
           { win32 only }
           aitconst_rva_symbol,
           aitconst_rva_symbol,
+          aitconst_secrel32_symbol,
           { darwin only }
           { darwin only }
           aitconst_indirect_symbol
           aitconst_indirect_symbol
         );
         );

+ 5 - 2
compiler/aggas.pas

@@ -212,7 +212,7 @@ implementation
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
         #9'.fixme128'#9,#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.byte'#9,
         #9'.fixme128'#9,#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.byte'#9,
         #9'.sleb128'#9,#9'.uleb128'#9,
         #9'.sleb128'#9,#9'.uleb128'#9,
-        #9'.rva'#9,#9'.indirect_symbol'#9
+        #9'.rva'#9,#9'.secrel32'#9,#9'.indirect_symbol'#9
       );
       );
 
 
 {****************************************************************************}
 {****************************************************************************}
@@ -685,6 +685,7 @@ implementation
                  aitconst_16bit,
                  aitconst_16bit,
                  aitconst_8bit,
                  aitconst_8bit,
                  aitconst_rva_symbol,
                  aitconst_rva_symbol,
+                 aitconst_secrel32_symbol,
                  aitconst_indirect_symbol :
                  aitconst_indirect_symbol :
                    begin
                    begin
                      if (target_info.system in systems_darwin) and
                      if (target_info.system in systems_darwin) and
@@ -746,7 +747,9 @@ implementation
                        end;
                        end;
                       AsmLn;
                       AsmLn;
                    end;
                    end;
-                 end;
+                 else
+                   internalerror(200704251);
+               end;
              end;
              end;
 
 
            { the "and defined(FPC_HAS_TYPE_EXTENDED)" isn't optimal but currently the only solution
            { the "and defined(FPC_HAS_TYPE_EXTENDED)" isn't optimal but currently the only solution

+ 5 - 0
compiler/assemble.pas

@@ -1159,6 +1159,11 @@ Implementation
                        else
                        else
                          ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA);
                          ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA);
                      end;
                      end;
+                   aitconst_secrel32_symbol :
+                     begin
+                       { Required for DWARF2 support under Windows }
+                       ObjData.writereloc(Tai_const(hp).value,sizeof(longint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_SECREL32);
+                     end;
                    aitconst_uleb128bit,
                    aitconst_uleb128bit,
                    aitconst_sleb128bit :
                    aitconst_sleb128bit :
                      begin
                      begin

+ 21 - 11
compiler/dbgdwarf.pas

@@ -226,7 +226,8 @@ interface
         _use_64bit_headers: Boolean;
         _use_64bit_headers: Boolean;
         // set to ait_const32bit if use_64bit_headers is false, otherwise
         // set to ait_const32bit if use_64bit_headers is false, otherwise
         // to ait_const64bit
         // to ait_const64bit
-        offsetsymtype: taiconst_type;
+        offsetreltype,
+        offsetabstype : taiconst_type;
         // set if we generated any lineinfo at all. If not, we have to terminate
         // set if we generated any lineinfo at all. If not, we have to terminate
         // when insertmoduleinfo is called.
         // when insertmoduleinfo is called.
         generated_lineinfo: boolean;
         generated_lineinfo: boolean;
@@ -625,9 +626,18 @@ implementation
       begin
       begin
          _use_64bit_headers:=state;
          _use_64bit_headers:=state;
          if not(state) then
          if not(state) then
-           offsetsymtype:=aitconst_32bit
+           begin
+             if (target_info.system in system_windows+system_wince) then
+               offsetabstype:=aitconst_secrel32_symbol
+             else
+               offsetabstype:=aitconst_32bit;
+             offsetreltype:=aitconst_32bit;
+           end
          else
          else
-           offsetsymtype:=aitconst_64bit
+           begin
+             offsetreltype:=aitconst_64bit;
+             offsetabstype:=aitconst_64bit;
+           end;
       end;
       end;
 
 
 
 
@@ -944,7 +954,7 @@ implementation
         else
         else
           begin
           begin
             current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref4)));
             current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_ref4)));
-            current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetsymtype,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_info0'),sym));
+            current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_info0'),sym));
           end;
           end;
       end;
       end;
 
 
@@ -971,7 +981,7 @@ implementation
           { use append_labelentry_dataptr_rel instead }
           { use append_labelentry_dataptr_rel instead }
           internalerror(2007020210);
           internalerror(2007020210);
         append_labelentry_dataptr_common(attr);
         append_labelentry_dataptr_common(attr);
-        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetsymtype,sym))
+        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,sym))
       end;
       end;
 
 
 
 
@@ -984,7 +994,7 @@ implementation
           targets
           targets
         }
         }
         append_labelentry_dataptr_common(attr);
         append_labelentry_dataptr_common(attr);
-        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetsymtype,sym,endsym));
+        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,sym,endsym));
       end;
       end;
 
 
 
 
@@ -2150,7 +2160,7 @@ implementation
         current_asmdata.getlabel(lbl,alt_dbgfile);
         current_asmdata.getlabel(lbl,alt_dbgfile);
         if use_64bit_headers then
         if use_64bit_headers then
           linelist.concat(tai_const.create_32bit(longint($FFFFFFFF)));
           linelist.concat(tai_const.create_32bit(longint($FFFFFFFF)));
-        linelist.concat(tai_const.create_rel_sym(offsetsymtype,
+        linelist.concat(tai_const.create_rel_sym(offsetreltype,
           lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_line0')));
           lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_line0')));
         linelist.concat(tai_label.create(lbl));
         linelist.concat(tai_label.create(lbl));
 
 
@@ -2159,7 +2169,7 @@ implementation
 
 
         { header length }
         { header length }
         current_asmdata.getlabel(lbl,alt_dbgfile);
         current_asmdata.getlabel(lbl,alt_dbgfile);
-        linelist.concat(tai_const.create_rel_sym(offsetsymtype,
+        linelist.concat(tai_const.create_rel_sym(offsetreltype,
           lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'ehdebug_line0')));
           lbl,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'ehdebug_line0')));
         linelist.concat(tai_label.create(lbl));
         linelist.concat(tai_label.create(lbl));
 
 
@@ -2326,7 +2336,7 @@ implementation
         { size }
         { size }
         if use_64bit_headers then
         if use_64bit_headers then
           current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(longint($FFFFFFFF)));
           current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_32bit(longint($FFFFFFFF)));
-        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetsymtype,
+        current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
           lenstartlabel,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_info0')));
           lenstartlabel,current_asmdata.RefAsmSymbol(target_asm.labelprefix+'edebug_info0')));
 
 
         current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
         current_asmdata.asmlists[al_dwarf_info].concat(tai_label.create(lenstartlabel));
@@ -2334,10 +2344,10 @@ implementation
         current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(dwarf_version));
         current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_16bit(dwarf_version));
         { abbrev table (=relative from section start)}
         { abbrev table (=relative from section start)}
         if not(tf_dwarf_relative_addresses in target_info.flags) then
         if not(tf_dwarf_relative_addresses in target_info.flags) then
-          current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetsymtype,
+          current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_type_sym(offsetabstype,
             current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')))
             current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')))
         else
         else
-          current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetsymtype,
+          current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_rel_sym(offsetreltype,
             current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrevsection0'),
             current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrevsection0'),
             current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')));
             current_asmdata.RefAsmSymbol(target_asm.labelprefix+'debug_abbrev0')));
 
 

+ 4 - 1
compiler/i386/ag386nsm.pas

@@ -450,7 +450,7 @@ interface
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
         #9'FIXME_128BIT'#9,#9'FIXME_64BIT'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
         #9'FIXME_128BIT'#9,#9'FIXME_64BIT'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
         #9'FIXME_SLEB128BIT'#9,#9'FIXME_ULEB128BIT'#9,
         #9'FIXME_SLEB128BIT'#9,#9'FIXME_ULEB128BIT'#9,
-        #9'RVA'#9,#9'FIXMEINDIRECT'#9
+        #9'RVA'#9,#9'SECREL32'#9,#9'FIXMEINDIRECT'#9
       );
       );
 
 
     procedure T386NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
     procedure T386NasmAssembler.WriteSection(atype:TAsmSectiontype;const aname:string);
@@ -651,6 +651,7 @@ interface
                  aitconst_16bit,
                  aitconst_16bit,
                  aitconst_8bit,
                  aitconst_8bit,
                  aitconst_rva_symbol,
                  aitconst_rva_symbol,
+                 aitconst_secrel32_symbol,
                  aitconst_indirect_symbol :
                  aitconst_indirect_symbol :
                    begin
                    begin
                      AsmWrite(ait_const2str[tai_const(hp).consttype]);
                      AsmWrite(ait_const2str[tai_const(hp).consttype]);
@@ -685,6 +686,8 @@ interface
                      until false;
                      until false;
                      AsmLn;
                      AsmLn;
                    end;
                    end;
+                 else
+                   internalerror(200704252);
                end;
                end;
              end;
              end;
 
 

+ 2 - 0
compiler/ogbase.pas

@@ -66,6 +66,8 @@ interface
          RELOC_RELATIVE,
          RELOC_RELATIVE,
          { PECoff (Windows) RVA relocation }
          { PECoff (Windows) RVA relocation }
          RELOC_RVA,
          RELOC_RVA,
+         { PECoff (Windows) section relocation, required by DWARF2 debug info }
+         RELOC_SECREL32,
          { Generate a 0 value at the place of the relocation,
          { Generate a 0 value at the place of the relocation,
            this is used to remove unused vtable entries }
            this is used to remove unused vtable entries }
          RELOC_ZERO,
          RELOC_ZERO,

+ 28 - 9
compiler/ogcoff.pas

@@ -425,9 +425,13 @@ implementation
        IMAGE_REL_ARM_SECTION       = $000E;     { Section table index }
        IMAGE_REL_ARM_SECTION       = $000E;     { Section table index }
        IMAGE_REL_ARM_SECREL        = $000F;     { Offset within section }
        IMAGE_REL_ARM_SECREL        = $000F;     { Offset within section }
 {$endif arm}
 {$endif arm}
-       R_DIR32 = 6;
-       R_IMAGEBASE = 7;
-       R_PCRLONG = 20;
+
+{$ifdef i386}
+       IMAGE_REL_I386_DIR32 = 6;
+       IMAGE_REL_I386_IMAGEBASE = 7;
+       IMAGE_REL_I386_SECREL32 = 11;
+       IMAGE_REL_I386_PCRLONG = 20;
+{$endif i386}
 
 
        { .reloc section fixup types }
        { .reloc section fixup types }
        IMAGE_REL_BASED_HIGHLOW     = 3;  { Applies the delta to the 32-bit field at Offset. }
        IMAGE_REL_BASED_HIGHLOW     = 3;  { Applies the delta to the 32-bit field at Offset. }
@@ -818,6 +822,13 @@ const pemagic : array[0..3] of byte = (
 {$endif arm}
 {$endif arm}
                     inc(address,relocval);
                     inc(address,relocval);
                 end;
                 end;
+              RELOC_SECREL32 :
+                begin
+                  { fixup address when the symbol was known in defined object }
+                  if (relocsec.objdata=objdata) then
+                    dec(address,TCoffObjSection(relocsec).mempos);
+                  inc(address,relocval);
+                end;
 {$ifdef arm}
 {$ifdef arm}
               RELOC_RELATIVE_24:
               RELOC_RELATIVE_24:
                 begin
                 begin
@@ -1174,14 +1185,18 @@ const pemagic : array[0..3] of byte = (
 
 
               RELOC_RVA :
               RELOC_RVA :
                 rel.reloctype:=IMAGE_REL_ARM_ADDR32NB;
                 rel.reloctype:=IMAGE_REL_ARM_ADDR32NB;
+              RELOC_SECREL32 :
+                rel.reloctype:=IMAGE_REL_ARM_SECREL;
 {$endif arm}
 {$endif arm}
 {$ifdef i386}
 {$ifdef i386}
               RELOC_RELATIVE :
               RELOC_RELATIVE :
-                rel.reloctype:=R_PCRLONG;
+                rel.reloctype:=IMAGE_REL_I386_PCRLONG;
               RELOC_ABSOLUTE :
               RELOC_ABSOLUTE :
-                rel.reloctype:=R_DIR32;
+                rel.reloctype:=IMAGE_REL_I386_DIR32;
               RELOC_RVA :
               RELOC_RVA :
-                rel.reloctype:=R_IMAGEBASE;
+                rel.reloctype:=IMAGE_REL_I386_IMAGEBASE;
+              RELOC_SECREL32 :
+                rel.reloctype:=IMAGE_REL_I386_SECREL32;
 {$endif i386}
 {$endif i386}
 {$ifdef x86_64}
 {$ifdef x86_64}
               RELOC_RELATIVE :
               RELOC_RELATIVE :
@@ -1202,6 +1217,8 @@ const pemagic : array[0..3] of byte = (
                 rel.reloctype:=IMAGE_REL_AMD64_REL32_4;
                 rel.reloctype:=IMAGE_REL_AMD64_REL32_4;
               RELOC_RELATIVE_5 :
               RELOC_RELATIVE_5 :
                 rel.reloctype:=IMAGE_REL_AMD64_REL32_5;
                 rel.reloctype:=IMAGE_REL_AMD64_REL32_5;
+              RELOC_SECREL32 :
+                rel.reloctype:=IMAGE_REL_AMD64_SECREL;
 {$endif x86_64}
 {$endif x86_64}
               else
               else
                 internalerror(200603312);
                 internalerror(200603312);
@@ -1497,12 +1514,14 @@ const pemagic : array[0..3] of byte = (
                rel_type:=RELOC_RELATIVE_24;
                rel_type:=RELOC_RELATIVE_24;
 {$endif arm}
 {$endif arm}
 {$ifdef i386}
 {$ifdef i386}
-             R_PCRLONG :
+             IMAGE_REL_I386_PCRLONG :
                rel_type:=RELOC_RELATIVE;
                rel_type:=RELOC_RELATIVE;
-             R_DIR32 :
+             IMAGE_REL_I386_DIR32 :
                rel_type:=RELOC_ABSOLUTE;
                rel_type:=RELOC_ABSOLUTE;
-             R_IMAGEBASE :
+             IMAGE_REL_I386_IMAGEBASE :
                rel_type:=RELOC_RVA;
                rel_type:=RELOC_RVA;
+             IMAGE_REL_I386_SECREL32 :
+               rel_type:=RELOC_SECREL32;
 {$endif i386}
 {$endif i386}
 {$ifdef x86_64}
 {$ifdef x86_64}
              IMAGE_REL_AMD64_REL32:
              IMAGE_REL_AMD64_REL32:

+ 4 - 1
compiler/x86/agx86int.pas

@@ -351,7 +351,7 @@ implementation
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
       ait_const2str : array[aitconst_128bit..aitconst_indirect_symbol] of string[20]=(
         #9''#9,#9'DQ'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
         #9''#9,#9'DQ'#9,#9'DD'#9,#9'DW'#9,#9'DB'#9,
         #9'FIXMESLEB',#9'FIXEMEULEB',
         #9'FIXMESLEB',#9'FIXEMEULEB',
-        #9'DD RVA'#9,#9'FIXMEINDIRECT'#9
+        #9'DD RVA'#9,#9'DD SECREL32'#9,#9'FIXMEINDIRECT'#9
       );
       );
 
 
     Function PadTabs(const p:string;addch:char):string;
     Function PadTabs(const p:string;addch:char):string;
@@ -527,6 +527,7 @@ implementation
                  aitconst_16bit,
                  aitconst_16bit,
                  aitconst_8bit,
                  aitconst_8bit,
                  aitconst_rva_symbol,
                  aitconst_rva_symbol,
+                 aitconst_secrel32_symbol,
                  aitconst_indirect_symbol :
                  aitconst_indirect_symbol :
                    begin
                    begin
                      AsmWrite(ait_const2str[consttype]);
                      AsmWrite(ait_const2str[consttype]);
@@ -554,6 +555,8 @@ implementation
                      until false;
                      until false;
                      AsmLn;
                      AsmLn;
                    end;
                    end;
+                 else
+                   internalerror(200704253);
                end;
                end;
              end;
              end;