@@ -281,6 +281,14 @@ class BinaryFunction {
281281 // / goto labels.
282282 std::set<uint64_t > ExternallyReferencedOffsets;
283283
284+ // / Relocations from data sections targeting internals of this function, i.e.
285+ // / some code not at an entry point. These include, but are not limited to,
286+ // / jump table relocations and computed goto tables.
287+ // /
288+ // / Since relocations can be removed/deallocated, we store relocation offsets
289+ // / instead of pointers.
290+ DenseSet<uint64_t > InternalRefDataRelocations;
291+
284292 // / Offsets of indirect branches with unknown destinations.
285293 std::set<uint64_t > UnknownIndirectBranchOffsets;
286294
@@ -640,6 +648,20 @@ class BinaryFunction {
640648 Islands->CodeOffsets .emplace (Offset);
641649 }
642650
651+ // / Register a relocation from data section referencing code at a non-zero
652+ // / offset in this function.
653+ void registerInternalRefDataRelocation (uint64_t FuncOffset,
654+ uint64_t RelOffset) {
655+ assert (FuncOffset != 0 && " Relocation should reference function internals" );
656+ registerReferencedOffset (FuncOffset);
657+ InternalRefDataRelocations.insert (RelOffset);
658+ const MCSymbol *ReferencedSymbol =
659+ getOrCreateLocalLabel (getAddress () + FuncOffset);
660+
661+ // Track the symbol mapping since it's used in relocation handling.
662+ BC.setSymbolToFunctionMap (ReferencedSymbol, this );
663+ }
664+
643665 // / Register an internal offset in a function referenced from outside.
644666 void registerReferencedOffset (uint64_t Offset) {
645667 ExternallyReferencedOffsets.emplace (Offset);
@@ -1299,6 +1321,12 @@ class BinaryFunction {
12991321 void addRelocation (uint64_t Address, MCSymbol *Symbol, uint32_t RelType,
13001322 uint64_t Addend, uint64_t Value);
13011323
1324+ // / Return locations (offsets) of data section relocations targeting internals
1325+ // / of this functions.
1326+ const DenseSet<uint64_t > &getInternalRefDataRelocations () const {
1327+ return InternalRefDataRelocations;
1328+ }
1329+
13021330 // / Return the name of the section this function originated from.
13031331 std::optional<StringRef> getOriginSectionName () const {
13041332 if (!OriginSection)
0 commit comments