@@ -1088,6 +1088,17 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
1088
1088
let dest = dest. to_ptr ( ) ?;
1089
1089
self . check_relocation_edges ( src, size) ?;
1090
1090
1091
+ // first copy the relocations to a temporary buffer, because
1092
+ // `get_bytes_mut` will clear the relocations, which is correct,
1093
+ // since we don't want to keep any relocations at the target.
1094
+
1095
+ let relocations: Vec < _ > = self . relocations ( src, size) ?
1096
+ . map ( |( & offset, & alloc_id) | {
1097
+ // Update relocation offsets for the new positions in the destination allocation.
1098
+ ( offset + dest. offset - src. offset , alloc_id)
1099
+ } )
1100
+ . collect ( ) ;
1101
+
1091
1102
let src_bytes = self . get_bytes_unchecked ( src, size, align) ?. as_ptr ( ) ;
1092
1103
let dest_bytes = self . get_bytes_mut ( dest, size, align) ?. as_mut_ptr ( ) ;
1093
1104
@@ -1113,7 +1124,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
1113
1124
}
1114
1125
1115
1126
self . copy_undef_mask ( src, dest, size) ?;
1116
- self . copy_relocations ( src, dest, size) ?;
1127
+ // copy back the relocations
1128
+ self . get_mut ( dest. alloc_id ) ?. relocations . extend ( relocations) ;
1117
1129
1118
1130
Ok ( ( ) )
1119
1131
}
@@ -1388,22 +1400,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
1388
1400
}
1389
1401
Ok ( ( ) )
1390
1402
}
1391
-
1392
- fn copy_relocations (
1393
- & mut self ,
1394
- src : MemoryPointer ,
1395
- dest : MemoryPointer ,
1396
- size : u64 ,
1397
- ) -> EvalResult < ' tcx > {
1398
- let relocations: Vec < _ > = self . relocations ( src, size) ?
1399
- . map ( |( & offset, & alloc_id) | {
1400
- // Update relocation offsets for the new positions in the destination allocation.
1401
- ( offset + dest. offset - src. offset , alloc_id)
1402
- } )
1403
- . collect ( ) ;
1404
- self . get_mut ( dest. alloc_id ) ?. relocations . extend ( relocations) ;
1405
- Ok ( ( ) )
1406
- }
1407
1403
}
1408
1404
1409
1405
/// Undefined bytes
0 commit comments