@@ -884,13 +884,14 @@ void CompileResult::applyRelocs(unsigned char* block1, ULONG blocksize1, void* o
884
884
continue ;
885
885
886
886
// Now do all-platform relocations.
887
-
888
- switch (tmp.fRelocType )
887
+ if (tmp.fRelocType == IMAGE_REL_BASED_REL32)
889
888
{
890
- case IMAGE_REL_BASED_REL32:
889
+ DWORDLONG fixupLocation = tmp.location + tmp.slotNum ;
890
+
891
+ size_t address = section_begin + (size_t )fixupLocation - (size_t )originalAddr;
892
+ if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
891
893
{
892
894
DWORDLONG target = tmp.target + tmp.addlDelta ;
893
- DWORDLONG fixupLocation = tmp.location + tmp.slotNum ;
894
895
DWORDLONG baseAddr = fixupLocation + sizeof (INT32);
895
896
INT64 delta = (INT64)(target - baseAddr);
896
897
@@ -899,13 +900,12 @@ void CompileResult::applyRelocs(unsigned char* block1, ULONG blocksize1, void* o
899
900
if (delta != (INT64)(int )delta)
900
901
{
901
902
// This isn't going to fit in a signed 32-bit address. Use something that will fit,
902
- // since we assume that original compilation fit fine. This is only an issue for
903
- // 32-bit offsets on 64-bit targets.
903
+ // since we assume that original compilation fit fine.
904
+ // This is only an issue for 32-bit offsets on 64-bit targets.
904
905
target = (DWORDLONG)originalAddr + (DWORDLONG)blocksize1;
905
906
INT64 newdelta = (INT64)(target - baseAddr);
906
907
907
- LogDebug (" REL32 overflow. Mapping target to %016llX. Mapping delta: %016llX => %016llX" , target,
908
- delta, newdelta);
908
+ LogDebug (" REL32 overflow. Mapping target to %016llX. Mapping delta: %016llX => %016llX" , target, delta, newdelta);
909
909
910
910
delta = newdelta;
911
911
}
@@ -916,32 +916,29 @@ void CompileResult::applyRelocs(unsigned char* block1, ULONG blocksize1, void* o
916
916
LogError (" REL32 relocation overflows field! delta=0x%016llX" , delta);
917
917
}
918
918
919
- // Write 32-bits into location
920
- size_t address = section_begin + (size_t )fixupLocation - (size_t )originalAddr;
921
- if ((section_begin <= address) && (address < section_end)) // A reloc for our section?
919
+ if (targetArch == SPMI_TARGET_ARCHITECTURE_AMD64)
922
920
{
923
- if (targetArch == SPMI_TARGET_ARCHITECTURE_AMD64)
924
- {
925
- // During an actual compile, recordRelocation() will be called before the compile
926
- // is actually finished, and it will write the relative offset into the fixupLocation.
927
- // Then, emitEndCodeGen() will patch forward jumps by subtracting any adjustment due
928
- // to overestimation of instruction sizes. Because we're applying the relocs after the
929
- // compile has finished, we need to reverse that: i.e. add in the (negative) adjustment
930
- // that's now in the fixupLocation.
931
- INT32 adjustment = *(INT32*)address;
932
- delta += adjustment;
933
- }
934
-
935
- LogDebug (" fixupLoc-%016llX (@%p) : %08X => %08X" , fixupLocation, address, *(DWORD*)address,
936
- delta);
937
- *(DWORD*)address = (DWORD)delta;
921
+ // During an actual compile, recordRelocation() will be called before the compile
922
+ // is actually finished, and it will write the relative offset into the fixupLocation.
923
+ // Then, emitEndCodeGen() will patch forward jumps by subtracting any adjustment due
924
+ // to overestimation of instruction sizes. Because we're applying the relocs after the
925
+ // compile has finished, we need to reverse that: i.e. add in the (negative) adjustment
926
+ // that's now in the fixupLocation.
927
+ INT32 adjustment = *(INT32*)address;
928
+ delta += adjustment;
938
929
}
930
+
931
+ // Write 32-bits into location
932
+ LogDebug (" fixupLoc-%016llX (@%p) : %08X => %08X" , fixupLocation, address, *(DWORD*)address, delta);
933
+ *(DWORD*)address = (DWORD)delta;
939
934
}
940
- break ;
941
935
942
- default :
943
- LogError (" Unknown reloc type %u" , tmp.fRelocType );
944
- break ;
936
+ wasRelocHandled = true ;
937
+ }
938
+
939
+ if (!wasRelocHandled)
940
+ {
941
+ LogError (" Unknown reloc type %u" , tmp.fRelocType );
945
942
}
946
943
}
947
944
}
0 commit comments