@@ -230,6 +230,12 @@ class BinaryContext {
230230 // / Functions injected by BOLT
231231 std::vector<BinaryFunction *> InjectedBinaryFunctions;
232232
233+ // / Thunk functions.
234+ std::vector<BinaryFunction *> ThunkBinaryFunctions;
235+
236+ // / Function that precedes thunks in the binary.
237+ const BinaryFunction *ThunkLocation{nullptr };
238+
233239 // / Jump tables for all functions mapped by address.
234240 std::map<uint64_t , JumpTable *> JumpTables;
235241
@@ -435,7 +441,18 @@ class BinaryContext {
435441
436442 // / Return size of an entry for the given jump table \p Type.
437443 uint64_t getJumpTableEntrySize (JumpTable::JumpTableType Type) const {
438- return Type == JumpTable::JTT_PIC ? 4 : AsmInfo->getCodePointerSize ();
444+ switch (Type) {
445+ case JumpTable::JTT_X86_64_PIC4:
446+ return 4 ;
447+ case JumpTable::JTT_X86_64_ABS:
448+ return AsmInfo->getCodePointerSize ();
449+ case JumpTable::JTT_AARCH64_REL1:
450+ return 1 ;
451+ case JumpTable::JTT_AARCH64_REL2:
452+ return 2 ;
453+ case JumpTable::JTT_AARCH64_REL4:
454+ return 4 ;
455+ }
439456 }
440457
441458 // / Return JumpTable containing a given \p Address.
@@ -553,6 +570,16 @@ class BinaryContext {
553570 return InjectedBinaryFunctions;
554571 }
555572
573+ BinaryFunction *createThunkBinaryFunction (const std::string &Name);
574+
575+ std::vector<BinaryFunction *> &getThunkBinaryFunctions () {
576+ return ThunkBinaryFunctions;
577+ }
578+
579+ const BinaryFunction *getThunkLocation () const { return ThunkLocation; }
580+
581+ void setThunkLocation (const BinaryFunction *BF) { ThunkLocation = BF; }
582+
556583 // / Return vector with all functions, i.e. include functions from the input
557584 // / binary and functions created by BOLT.
558585 std::vector<BinaryFunction *> getAllBinaryFunctions ();
@@ -574,14 +601,13 @@ class BinaryContext {
574601 // / If \p NextJTAddress is different from zero, it is used as an upper
575602 // / bound for jump table memory layout.
576603 // /
577- // / Optionally, populate \p Address from jump table entries. The entries
578- // / could be partially populated if the jump table detection fails.
604+ // / If \p JT is set, populate it with jump table entries. The entries could be
605+ // / partially populated if the jump table detection fails.
579606 bool analyzeJumpTable (const uint64_t Address,
580607 const JumpTable::JumpTableType Type,
581608 const BinaryFunction &BF,
582609 const uint64_t NextJTAddress = 0 ,
583- JumpTable::AddressesType *EntriesAsAddress = nullptr ,
584- bool *HasEntryInFragment = nullptr ) const ;
610+ JumpTable *JT = nullptr ) const ;
585611
586612 // / After jump table locations are established, this function will populate
587613 // / their EntriesAsAddress based on memory contents.
@@ -1372,6 +1398,10 @@ class BinaryContext {
13721398 uint64_t
13731399 computeInstructionSize (const MCInst &Inst,
13741400 const MCCodeEmitter *Emitter = nullptr ) const {
1401+ // FIXME: hack for faster size computation on aarch64.
1402+ if (isAArch64 ())
1403+ return MIB->isPseudo (Inst) ? 0 : 4 ;
1404+
13751405 if (std::optional<uint32_t > Size = MIB->getSize (Inst))
13761406 return *Size;
13771407
0 commit comments