@@ -205,7 +205,8 @@ patch_32(unsigned char *location, uint64_t value)
205205 uint32_t * loc32 = (uint32_t * )location ;
206206 // Check that we're not out of range of 32 unsigned bits:
207207 assert (value < (1ULL << 32 ));
208- * loc32 = (uint32_t )value ;
208+ uint32_t final_value = (uint32_t )value ;
209+ memcpy (location , & final_value , sizeof (final_value ));
209210}
210211
211212// 32-bit relative address.
@@ -217,15 +218,16 @@ patch_32r(unsigned char *location, uint64_t value)
217218 // Check that we're not out of range of 32 signed bits:
218219 assert ((int64_t )value >= - (1LL << 31 ));
219220 assert ((int64_t )value < (1LL << 31 ));
220- * loc32 = (uint32_t )value ;
221+ uint32_t final_value = (uint32_t )value ;
222+ memcpy (location , & final_value , sizeof (final_value ));
221223}
222224
223225// 64-bit absolute address.
224226void
225227patch_64 (unsigned char * location , uint64_t value )
226228{
227229 uint64_t * loc64 = (uint64_t * )location ;
228- * loc64 = value ;
230+ memcpy ( location , & value , sizeof ( value )) ;
229231}
230232
231233// 12-bit low part of an absolute address. Pairs nicely with patch_aarch64_21r
@@ -393,7 +395,10 @@ patch_x86_64_32rx(unsigned char *location, uint64_t value)
393395{
394396 uint8_t * loc8 = (uint8_t * )location ;
395397 // Try to relax the GOT load into an immediate value:
396- uint64_t relaxed = * (uint64_t * )(value + 4 ) - 4 ;
398+ uint64_t relaxed ;
399+ memcpy (& relaxed , (void * )(value + 4 ), sizeof (relaxed ));
400+ relaxed -= 4 ;
401+
397402 if ((int64_t )relaxed - (int64_t )location >= - (1LL << 31 ) &&
398403 (int64_t )relaxed - (int64_t )location + 1 < (1LL << 31 ))
399404 {
0 commit comments