@@ -1470,25 +1470,29 @@ void RewriteInstance::createPLTBinaryFunction(uint64_t TargetAddress,
1470
1470
setPLTSymbol (BF, Symbol->getName ());
1471
1471
}
1472
1472
1473
- void RewriteInstance::disassemblePLTSectionAArch64 (BinarySection &Section) {
1473
+ void RewriteInstance::disassemblePLTInstruction (const BinarySection &Section,
1474
+ uint64_t InstrOffset,
1475
+ MCInst &Instruction,
1476
+ uint64_t &InstrSize) {
1474
1477
const uint64_t SectionAddress = Section.getAddress ();
1475
1478
const uint64_t SectionSize = Section.getSize ();
1476
1479
StringRef PLTContents = Section.getContents ();
1477
1480
ArrayRef<uint8_t > PLTData (
1478
1481
reinterpret_cast <const uint8_t *>(PLTContents.data ()), SectionSize);
1479
1482
1480
- auto disassembleInstruction = [&](uint64_t InstrOffset, MCInst &Instruction,
1481
- uint64_t &InstrSize) {
1482
- const uint64_t InstrAddr = SectionAddress + InstrOffset;
1483
- if (!BC->DisAsm ->getInstruction (Instruction, InstrSize,
1484
- PLTData.slice (InstrOffset), InstrAddr,
1485
- nulls ())) {
1486
- errs () << " BOLT-ERROR: unable to disassemble instruction in PLT section "
1487
- << Section.getName () << " at offset 0x"
1488
- << Twine::utohexstr (InstrOffset) << ' \n ' ;
1489
- exit (1 );
1490
- }
1491
- };
1483
+ const uint64_t InstrAddr = SectionAddress + InstrOffset;
1484
+ if (!BC->DisAsm ->getInstruction (Instruction, InstrSize,
1485
+ PLTData.slice (InstrOffset), InstrAddr,
1486
+ nulls ())) {
1487
+ errs () << " BOLT-ERROR: unable to disassemble instruction in PLT section "
1488
+ << Section.getName () << formatv (" at offset {0:x}\n " , InstrOffset);
1489
+ exit (1 );
1490
+ }
1491
+ }
1492
+
1493
+ void RewriteInstance::disassemblePLTSectionAArch64 (BinarySection &Section) {
1494
+ const uint64_t SectionAddress = Section.getAddress ();
1495
+ const uint64_t SectionSize = Section.getSize ();
1492
1496
1493
1497
uint64_t InstrOffset = 0 ;
1494
1498
// Locate new plt entry
@@ -1500,7 +1504,7 @@ void RewriteInstance::disassemblePLTSectionAArch64(BinarySection &Section) {
1500
1504
uint64_t InstrSize;
1501
1505
// Loop through entry instructions
1502
1506
while (InstrOffset < SectionSize) {
1503
- disassembleInstruction ( InstrOffset, Instruction, InstrSize);
1507
+ disassemblePLTInstruction (Section, InstrOffset, Instruction, InstrSize);
1504
1508
EntrySize += InstrSize;
1505
1509
if (!BC->MIB ->isIndirectBranch (Instruction)) {
1506
1510
Instructions.emplace_back (Instruction);
@@ -1521,7 +1525,7 @@ void RewriteInstance::disassemblePLTSectionAArch64(BinarySection &Section) {
1521
1525
1522
1526
// Skip nops if any
1523
1527
while (InstrOffset < SectionSize) {
1524
- disassembleInstruction ( InstrOffset, Instruction, InstrSize);
1528
+ disassemblePLTInstruction (Section, InstrOffset, Instruction, InstrSize);
1525
1529
if (!BC->MIB ->isNoop (Instruction))
1526
1530
break ;
1527
1531
@@ -1578,29 +1582,13 @@ void RewriteInstance::disassemblePLTSectionX86(BinarySection &Section,
1578
1582
uint64_t EntrySize) {
1579
1583
const uint64_t SectionAddress = Section.getAddress ();
1580
1584
const uint64_t SectionSize = Section.getSize ();
1581
- StringRef PLTContents = Section.getContents ();
1582
- ArrayRef<uint8_t > PLTData (
1583
- reinterpret_cast <const uint8_t *>(PLTContents.data ()), SectionSize);
1584
-
1585
- auto disassembleInstruction = [&](uint64_t InstrOffset, MCInst &Instruction,
1586
- uint64_t &InstrSize) {
1587
- const uint64_t InstrAddr = SectionAddress + InstrOffset;
1588
- if (!BC->DisAsm ->getInstruction (Instruction, InstrSize,
1589
- PLTData.slice (InstrOffset), InstrAddr,
1590
- nulls ())) {
1591
- errs () << " BOLT-ERROR: unable to disassemble instruction in PLT section "
1592
- << Section.getName () << " at offset 0x"
1593
- << Twine::utohexstr (InstrOffset) << ' \n ' ;
1594
- exit (1 );
1595
- }
1596
- };
1597
1585
1598
1586
for (uint64_t EntryOffset = 0 ; EntryOffset + EntrySize <= SectionSize;
1599
1587
EntryOffset += EntrySize) {
1600
1588
MCInst Instruction;
1601
1589
uint64_t InstrSize, InstrOffset = EntryOffset;
1602
1590
while (InstrOffset < EntryOffset + EntrySize) {
1603
- disassembleInstruction ( InstrOffset, Instruction, InstrSize);
1591
+ disassemblePLTInstruction (Section, InstrOffset, Instruction, InstrSize);
1604
1592
// Check if the entry size needs adjustment.
1605
1593
if (EntryOffset == 0 && BC->MIB ->isTerminateBranch (Instruction) &&
1606
1594
EntrySize == 8 )
0 commit comments