@@ -256,7 +256,7 @@ class MachOLinkGraphBuilder_arm64 : public MachOLinkGraphBuilder {
256
256
// If this is an Addend relocation then process it and move to the
257
257
// paired reloc.
258
258
259
- Addend = RI.r_symbolnum ;
259
+ Addend = SignExtend64 ( RI.r_symbolnum , 24 ) ;
260
260
261
261
if (RelItr == RelEnd)
262
262
return make_error<JITLinkError>(" Unpaired Addend reloc at " +
@@ -340,6 +340,11 @@ class MachOLinkGraphBuilder_arm64 : public MachOLinkGraphBuilder {
340
340
TargetSymbol = TargetSymbolOrErr->GraphSymbol ;
341
341
else
342
342
return TargetSymbolOrErr.takeError ();
343
+ uint32_t Instr = *(const ulittle32_t *)FixupContent;
344
+ uint32_t EncodedAddend = (Instr & 0x003FFC00 ) >> 10 ;
345
+ if (EncodedAddend != 0 )
346
+ return make_error<JITLinkError>(" GOTPAGEOFF12 target has non-zero "
347
+ " encoded addend" );
343
348
break ;
344
349
}
345
350
case GOTPageOffset12: {
@@ -524,23 +529,17 @@ class MachOJITLinker_arm64 : public JITLinker<MachOJITLinker_arm64> {
524
529
}
525
530
526
531
static unsigned getPageOffset12Shift (uint32_t Instr) {
527
- constexpr uint32_t LDRLiteralMask = 0x3ffffc00 ;
528
-
529
- // Check for a GPR LDR immediate with a zero embedded literal.
530
- // If found, the top two bits contain the shift.
531
- if ((Instr & LDRLiteralMask) == 0x39400000 )
532
- return Instr >> 30 ;
533
-
534
- // Check for a Neon LDR immediate of size 64-bit or less with a zero
535
- // embedded literal. If found, the top two bits contain the shift.
536
- if ((Instr & LDRLiteralMask) == 0x3d400000 )
537
- return Instr >> 30 ;
538
-
539
- // Check for a Neon LDR immediate of size 128-bit with a zero embedded
540
- // literal.
541
- constexpr uint32_t SizeBitsMask = 0xc0000000 ;
542
- if ((Instr & (LDRLiteralMask | SizeBitsMask)) == 0x3dc00000 )
543
- return 4 ;
532
+ constexpr uint32_t LoadStoreImm12Mask = 0x3b000000 ;
533
+ constexpr uint32_t Vec128Mask = 0x04800000 ;
534
+
535
+ if ((Instr & LoadStoreImm12Mask) == 0x39000000 ) {
536
+ uint32_t ImplicitShift = Instr >> 30 ;
537
+ if (ImplicitShift == 0 )
538
+ if ((Instr & Vec128Mask) == Vec128Mask)
539
+ ImplicitShift = 4 ;
540
+
541
+ return ImplicitShift;
542
+ }
544
543
545
544
return 0 ;
546
545
}
0 commit comments