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