@@ -240,10 +240,20 @@ Error createEmptyPointerSigningFunction(LinkGraph &G) {
240
240
// info encoded in the addend -- the only actually unknown quantity is the
241
241
// fixup location, and we can probably put constraints even on that.
242
242
size_t NumPtrAuthFixupLocations = 0 ;
243
- for (auto *B : G.blocks ())
244
- for (auto &E : B->edges ())
245
- NumPtrAuthFixupLocations +=
246
- E.getKind () == aarch64::Pointer64Authenticated;
243
+ for (auto &Sec : G.sections ()) {
244
+
245
+ // No-alloc sections can't have ptrauth edges. We don't need to error out
246
+ // here: applyFixup will catch these edges if any make it to the fixup
247
+ // stage.
248
+ if (Sec.getMemLifetime () == orc::MemLifetime::NoAlloc)
249
+ continue ;
250
+
251
+ for (auto *B : Sec.blocks ()) {
252
+ for (auto &E : B->edges ())
253
+ NumPtrAuthFixupLocations +=
254
+ E.getKind () == aarch64::Pointer64Authenticated;
255
+ }
256
+ }
247
257
248
258
constexpr size_t MaxPtrSignSeqLength =
249
259
4 + // To materialize the value to sign.
@@ -316,58 +326,65 @@ Error lowerPointer64AuthEdgesToSigningFunction(LinkGraph &G) {
316
326
return InstrWriter.writeInteger (Instr);
317
327
};
318
328
319
- for (auto *B : G.blocks ()) {
320
- for (auto &E : B->edges ()) {
321
- // We're only concerned with Pointer64Authenticated edges here.
322
- if (E.getKind () != aarch64::Pointer64Authenticated)
323
- continue ;
324
-
325
- uint64_t EncodedInfo = E.getAddend ();
326
- int32_t RealAddend = (uint32_t )(EncodedInfo & 0xffffffff );
327
- auto ValueToSign = E.getTarget ().getAddress () + RealAddend;
328
- if (!ValueToSign) {
329
- LLVM_DEBUG (dbgs () << " " << B->getFixupAddress (E) << " <- null\n " );
330
- E.setAddend (RealAddend);
331
- E.setKind (aarch64::Pointer64);
332
- continue ;
333
- }
329
+ for (auto &Sec : G.sections ()) {
330
+
331
+ if (Sec.getMemLifetime () == orc::MemLifetime::NoAlloc)
332
+ continue ;
334
333
335
- uint32_t InitialDiscriminator = (EncodedInfo >> 32 ) & 0xffff ;
336
- bool AddressDiversify = (EncodedInfo >> 48 ) & 0x1 ;
337
- uint32_t Key = (EncodedInfo >> 49 ) & 0x3 ;
338
- uint32_t HighBits = EncodedInfo >> 51 ;
339
-
340
- if (HighBits != 0x1000 )
341
- return make_error<JITLinkError>(
342
- " Pointer64Auth edge at " +
343
- formatv (" {0:x}" , B->getFixupAddress (E).getValue ()) +
344
- " has invalid encoded addend " + formatv (" {0:x}" , EncodedInfo));
345
-
346
- LLVM_DEBUG ({
347
- const char *const KeyNames[] = {" IA" , " IB" , " DA" , " DB" };
348
- dbgs () << " " << B->getFixupAddress (E) << " <- " << ValueToSign
349
- << " : key = " << KeyNames[Key] << " , discriminator = "
350
- << formatv (" {0:x4}" , InitialDiscriminator)
351
- << " , address diversified = "
352
- << (AddressDiversify ? " yes" : " no" ) << " \n " ;
353
- });
354
-
355
- // Materialize pointer value.
356
- cantFail (writeMovRegImm64Seq (AppendInstr, Reg1, ValueToSign.getValue ()));
357
-
358
- // Materialize fixup pointer.
359
- cantFail (writeMovRegImm64Seq (AppendInstr, Reg2,
360
- B->getFixupAddress (E).getValue ()));
361
-
362
- // Write signing instruction(s).
363
- cantFail (writePACSignSeq (AppendInstr, Reg1, ValueToSign, Reg2, Reg3, Key,
364
- InitialDiscriminator, AddressDiversify));
365
-
366
- // Store signed pointer.
367
- cantFail (writeStoreRegSeq (AppendInstr, Reg2, Reg1));
368
-
369
- // Replace edge with a keep-alive to preserve dependence info.
370
- E.setKind (Edge::KeepAlive);
334
+ for (auto *B : Sec.blocks ()) {
335
+ for (auto &E : B->edges ()) {
336
+ // We're only concerned with Pointer64Authenticated edges here.
337
+ if (E.getKind () != aarch64::Pointer64Authenticated)
338
+ continue ;
339
+
340
+ uint64_t EncodedInfo = E.getAddend ();
341
+ int32_t RealAddend = (uint32_t )(EncodedInfo & 0xffffffff );
342
+ auto ValueToSign = E.getTarget ().getAddress () + RealAddend;
343
+ if (!ValueToSign) {
344
+ LLVM_DEBUG (dbgs () << " " << B->getFixupAddress (E) << " <- null\n " );
345
+ E.setAddend (RealAddend);
346
+ E.setKind (aarch64::Pointer64);
347
+ continue ;
348
+ }
349
+
350
+ uint32_t InitialDiscriminator = (EncodedInfo >> 32 ) & 0xffff ;
351
+ bool AddressDiversify = (EncodedInfo >> 48 ) & 0x1 ;
352
+ uint32_t Key = (EncodedInfo >> 49 ) & 0x3 ;
353
+ uint32_t HighBits = EncodedInfo >> 51 ;
354
+
355
+ if (HighBits != 0x1000 )
356
+ return make_error<JITLinkError>(
357
+ " Pointer64Auth edge at " +
358
+ formatv (" {0:x}" , B->getFixupAddress (E).getValue ()) +
359
+ " has invalid encoded addend " + formatv (" {0:x}" , EncodedInfo));
360
+
361
+ LLVM_DEBUG ({
362
+ const char *const KeyNames[] = {" IA" , " IB" , " DA" , " DB" };
363
+ dbgs () << " " << B->getFixupAddress (E) << " <- " << ValueToSign
364
+ << " : key = " << KeyNames[Key] << " , discriminator = "
365
+ << formatv (" {0:x4}" , InitialDiscriminator)
366
+ << " , address diversified = "
367
+ << (AddressDiversify ? " yes" : " no" ) << " \n " ;
368
+ });
369
+
370
+ // Materialize pointer value.
371
+ cantFail (
372
+ writeMovRegImm64Seq (AppendInstr, Reg1, ValueToSign.getValue ()));
373
+
374
+ // Materialize fixup pointer.
375
+ cantFail (writeMovRegImm64Seq (AppendInstr, Reg2,
376
+ B->getFixupAddress (E).getValue ()));
377
+
378
+ // Write signing instruction(s).
379
+ cantFail (writePACSignSeq (AppendInstr, Reg1, ValueToSign, Reg2, Reg3,
380
+ Key, InitialDiscriminator, AddressDiversify));
381
+
382
+ // Store signed pointer.
383
+ cantFail (writeStoreRegSeq (AppendInstr, Reg2, Reg1));
384
+
385
+ // Replace edge with a keep-alive to preserve dependence info.
386
+ E.setKind (Edge::KeepAlive);
387
+ }
371
388
}
372
389
}
373
390
0 commit comments