Browse Source

+ x86_64 relocation support

git-svn-id: trunk@3105 -
florian 19 years ago
parent
commit
44f797e5bc
1 changed files with 49 additions and 1 deletions
  1. 49 1
      compiler/ogcoff.pas

+ 49 - 1
compiler/ogcoff.pas

@@ -327,7 +327,25 @@ implementation
        PE_DATADIR_IMPORTADDRESSTABLE = 12;
        PE_DATADIR_IMPORTADDRESSTABLE = 12;
        PE_DATADIR_DELAYIMPORT = 13;
        PE_DATADIR_DELAYIMPORT = 13;
 
 
-    type
+       IMAGE_REL_AMD64_ABSOLUTE    = $0000;  { Reference is absolute, no relocation is necessary }
+       IMAGE_REL_AMD64_ADDR64      = $0001;  { 64-bit address (VA). }
+       IMAGE_REL_AMD64_ADDR32      = $0002;  { 32-bit address (VA). }
+       IMAGE_REL_AMD64_ADDR32NB    = $0003;  { 32-bit address w/o image base (RVA). }
+       IMAGE_REL_AMD64_REL32       = $0004;  { 32-bit relative address from byte following reloc }
+       IMAGE_REL_AMD64_REL32_1     = $0005;  { 32-bit relative address from byte distance 1 from reloc }
+       IMAGE_REL_AMD64_REL32_2     = $0006;  { 32-bit relative address from byte distance 2 from reloc }
+       IMAGE_REL_AMD64_REL32_3     = $0007;  { 32-bit relative address from byte distance 3 from reloc }
+       IMAGE_REL_AMD64_REL32_4     = $0008;  { 32-bit relative address from byte distance 4 from reloc }
+       IMAGE_REL_AMD64_REL32_5     = $0009;  { 32-bit relative address from byte distance 5 from reloc }
+       IMAGE_REL_AMD64_SECTION     = $000A;  { Section index }
+       IMAGE_REL_AMD64_SECREL      = $000B;  { 32 bit offset from base of section containing target }
+       IMAGE_REL_AMD64_SECREL7     = $000C;  { 7 bit unsigned offset from base of section containing target }
+       IMAGE_REL_AMD64_TOKEN       = $000D;  { 32 bit metadata token }
+       IMAGE_REL_AMD64_SREL32      = $000E;  { 32 bit signed span-dependent value emitted into object }
+       IMAGE_REL_AMD64_PAIR        = $000F;
+       IMAGE_REL_AMD64_SSPAN32     = $0010;  { 32 bit signed span-dependent value applied at link time }
+
+       type
        { Structures which are written directly to the output file }
        { Structures which are written directly to the output file }
        coffheader=packed record
        coffheader=packed record
          mach   : word;
          mach   : word;
@@ -1108,6 +1126,7 @@ const win32stub : array[0..131] of byte=(
               else
               else
                rel.sym:=0;
                rel.sym:=0;
             end;
             end;
+{$ifdef i386}
            case r.typ of
            case r.typ of
              RELOC_RELATIVE :
              RELOC_RELATIVE :
                rel.reloctype:=$14;
                rel.reloctype:=$14;
@@ -1115,7 +1134,24 @@ const win32stub : array[0..131] of byte=(
                rel.reloctype:=$6;
                rel.reloctype:=$6;
              RELOC_RVA :
              RELOC_RVA :
                rel.reloctype:=$7;
                rel.reloctype:=$7;
+             else
+               internalerror(200604011);
+           end;
+{$endif i386}
+{$ifdef x86_64}
+           case r.typ of
+             RELOC_RELATIVE :
+               rel.reloctype:=IMAGE_REL_AMD64_REL32;
+             RELOC_ABSOLUTE32 :
+               rel.reloctype:=IMAGE_REL_AMD64_ADDR32;
+             RELOC_ABSOLUTE :
+               rel.reloctype:=IMAGE_REL_AMD64_ADDR64;
+             RELOC_RVA :
+               rel.reloctype:=IMAGE_REL_AMD64_ADDR32NB;
+             else
+               internalerror(200604012);
            end;
            end;
+{$endif x86_64}
            FWriter.write(rel,sizeof(rel));
            FWriter.write(rel,sizeof(rel));
            r:=TObjRelocation(r.next);
            r:=TObjRelocation(r.next);
          end;
          end;
@@ -1389,9 +1425,21 @@ const win32stub : array[0..131] of byte=(
          begin
          begin
            FReader.read(rel,sizeof(rel));
            FReader.read(rel,sizeof(rel));
            case rel.reloctype of
            case rel.reloctype of
+{$ifdef i386}
              $14 : rel_type:=RELOC_RELATIVE;
              $14 : rel_type:=RELOC_RELATIVE;
              $06 : rel_type:=RELOC_ABSOLUTE;
              $06 : rel_type:=RELOC_ABSOLUTE;
              $07 : rel_type:=RELOC_RVA;
              $07 : rel_type:=RELOC_RVA;
+{$endif i386}
+{$ifdef x86_64}
+             IMAGE_REL_AMD64_REL32:
+                 rel_type:=RELOC_RELATIVE;
+             IMAGE_REL_AMD64_ADDR32:
+               rel_type:=RELOC_ABSOLUTE32;
+             IMAGE_REL_AMD64_ADDR64:
+               rel_type:=RELOC_ABSOLUTE;
+             IMAGE_REL_AMD64_ADDR32NB:
+               rel_type:=RELOC_RVA;
+{$endif x86_64}
            else
            else
              begin
              begin
                InputError('Failed reading coff file, illegal reloctype $'+system.hexstr(rel.reloctype,4));
                InputError('Failed reading coff file, illegal reloctype $'+system.hexstr(rel.reloctype,4));