Author: Lang Hames Date: 2025-02-08T16:19:53Z New Revision: 975fa93b5f3715215ac2c4c74e86f466349bc0de
URL: https://github.com/llvm/llvm-project/commit/975fa93b5f3715215ac2c4c74e86f466349bc0de DIFF: https://github.com/llvm/llvm-project/commit/975fa93b5f3715215ac2c4c74e86f466349bc0de.diff LOG: [JITLink] Add a jitlink::Symbol::getSection() convenience method. `Sym.getSection()` is equivalent to `Sym.getBlock().getSection()`. (cherry picked from commit 4a2a8ed70da7ec44f0aa9092595e5b0f81a7e841) Added: Modified: llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h llvm/lib/ExecutionEngine/JITLink/JITLink.cpp llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h llvm/lib/ExecutionEngine/JITLink/aarch32.cpp llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index 297e603164b2440..8f0dfea0c97ac0d 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -587,6 +587,9 @@ class Symbol { return static_cast<const Block &>(*Base); } + /// Return the Section for this Symbol (Symbol must be defined). + Section &getSection() const { return getBlock().getSection(); } + /// Returns the offset for this symbol within the underlying addressable. orc::ExecutorAddrDiff getOffset() const { return Offset; } @@ -1460,7 +1463,7 @@ class LinkGraph { A.setAddress(orc::ExecutorAddr()); } else { assert(Sym.isDefined() && "Sym is not a defined symbol"); - Section &Sec = Sym.getBlock().getSection(); + Section &Sec = Sym.getSection(); Sec.removeSymbol(Sym); Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false)); } @@ -1488,7 +1491,7 @@ class LinkGraph { Sym.setScope(Scope::Local); } else { assert(Sym.isDefined() && "Sym is not a defined symbol"); - Section &Sec = Sym.getBlock().getSection(); + Section &Sec = Sym.getSection(); Sec.removeSymbol(Sym); Sym.makeAbsolute(createAddressable(Address)); } @@ -1534,7 +1537,7 @@ class LinkGraph { transferDefinedSymbol(Symbol &Sym, Block &DestBlock, orc::ExecutorAddrDiff NewOffset, std::optional<orc::ExecutorAddrDiff> ExplicitNewSize) { - auto &OldSection = Sym.getBlock().getSection(); + auto &OldSection = Sym.getSection(); Sym.setBlock(DestBlock); Sym.setOffset(NewOffset); if (ExplicitNewSize) @@ -1622,7 +1625,7 @@ class LinkGraph { /// Removes defined symbols. Does not remove the underlying block. void removeDefinedSymbol(Symbol &Sym) { assert(Sym.isDefined() && "Sym is not a defined symbol"); - Sym.getBlock().getSection().removeSymbol(Sym); + Sym.getSection().removeSymbol(Sym); destroySymbol(Sym); } diff --git a/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp index 151f1b337087d12..8ceb08051e423e1 100644 --- a/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp @@ -221,8 +221,7 @@ class COFFLinkGraphLowering_x86_64 { } case EdgeKind_coff_x86_64::SecRel32: { E.setAddend(E.getAddend() - - getSectionStart(E.getTarget().getBlock().getSection()) - .getValue()); + getSectionStart(E.getTarget().getSection()).getValue()); E.setKind(x86_64::Pointer32); break; } diff --git a/llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h b/llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h index a2c0c13cdbf66b9..c306264b6da5d26 100644 --- a/llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h +++ b/llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h @@ -155,7 +155,7 @@ template <typename CURecTraits> class CompactUnwindManager { Edge *KeepAliveEdge = nullptr; for (auto &E : Fn.getBlock().edges_at(0)) { if (E.getKind() == Edge::KeepAlive && E.getTarget().isDefined() && - &E.getTarget().getBlock().getSection() == EHFrameSec) { + &E.getTarget().getSection() == EHFrameSec) { KeepAliveEdge = &E; break; } diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp index 6b77330bb764b34..e8ce9b2b9527d45 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp @@ -424,7 +424,7 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B, if (E.getTarget().hasName()) { ErrStream << "\"" << E.getTarget().getName() << "\""; } else - ErrStream << E.getTarget().getBlock().getSection().getName() << " + " + ErrStream << E.getTarget().getSection().getName() << " + " << formatv("{0:x}", E.getOffset()); ErrStream << " at address " << formatv("{0:x}", E.getTarget().getAddress()) << " is out of range of " << G.getEdgeKindName(E.getKind()) diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h index e5d05e6b1b7bfc6..0bf714d6fcdf3ce 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h @@ -162,7 +162,7 @@ template <typename LinkerImpl> class JITLinker : public JITLinkerBase { // If B is a block in a Standard or Finalize section then make sure // that no edges point to symbols in NoAlloc sections. assert((NoAllocSection || !E.getTarget().isDefined() || - E.getTarget().getBlock().getSection().getMemLifetime() != + E.getTarget().getSection().getMemLifetime() != orc::MemLifetime::NoAlloc) && "Block in allocated section has edge pointing to no-alloc " "section"); diff --git a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp index 7b255717f238383..01bb6e0403578bd 100644 --- a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp @@ -874,7 +874,7 @@ bool StubsManager_prev7::visitEdge(LinkGraph &G, Block *B, Edge &E) { LLVM_DEBUG({ dbgs() << " Using " << (UseThumb ? "Thumb" : "Arm") << " entrypoint " << *StubEntrypoint << " in " - << StubEntrypoint->getBlock().getSection().getName() << "\n"; + << StubEntrypoint->getSection().getName() << "\n"; }); E.setTarget(*StubEntrypoint); @@ -919,8 +919,8 @@ bool StubsManager_v7::visitEdge(LinkGraph &G, Block *B, Edge &E) { "Instruction set states of stub and relocation site should be equal"); LLVM_DEBUG({ dbgs() << " Using " << (MakeThumb ? "Thumb" : "Arm") << " entry " - << *StubSymbol << " in " - << StubSymbol->getBlock().getSection().getName() << "\n"; + << *StubSymbol << " in " << StubSymbol->getSection().getName() + << "\n"; }); E.setTarget(*StubSymbol); diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp index 7a970f3cccf4616..bc5b3bb538e39c6 100644 --- a/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp @@ -113,7 +113,7 @@ getCodeLoadRecord(const Symbol &Sym, std::atomic<uint64_t> &CodeIndex) { static std::optional<PerfJITDebugInfoRecord> getDebugInfoRecord(const Symbol &Sym, DWARFContext &DC) { - auto &Section = Sym.getBlock().getSection(); + auto &Section = Sym.getSection(); auto Addr = Sym.getAddress(); auto Size = Sym.getSize(); auto SAddr = object::SectionedAddress{Addr.getValue(), Section.getOrdinal()}; diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp index 9715a503629bf57..1f4557217cf246c 100644 --- a/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp @@ -63,7 +63,7 @@ static VTuneMethodBatch getMethodBatch(LinkGraph &G, bool EmitDebugInfo) { if (!EmitDebugInfo) continue; - auto &Section = Sym->getBlock().getSection(); + auto &Section = Sym->getSection(); auto Addr = Sym->getAddress(); auto SAddr = object::SectionedAddress{Addr.getValue(), Section.getOrdinal()}; diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index 44ae73671f5b15a..845990d965b16d3 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -1071,7 +1071,7 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo( for (auto *B : Sec.blocks()) for (auto &E : B->edges()) if (E.getTarget().isDefined() && - &E.getTarget().getBlock().getSection() == ObjCImageInfo) + &E.getTarget().getSection() == ObjCImageInfo) return make_error<StringError>(MachOObjCImageInfoSectionName + " is referenced within file " + G.getName(), diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp index fb60acddf7821e6..c76087349352820 100644 --- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp @@ -54,6 +54,36 @@ TEST(LinkGraphTest, AddressAccess) { EXPECT_EQ(B1.getFixupAddress(E1), B1Addr + 8) << "Incorrect fixup address"; } +TEST(LinkGraphTest, DefinedSymbolProperties) { + // Check that Section::empty behaves as expected. + LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(), + Triple("x86_64-apple-darwin"), SubtargetFeatures(), + getGenericEdgeKindName); + auto &Sec = + G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write); + auto &B = + G.createContentBlock(Sec, BlockContent, orc::ExecutorAddr(0x1000), 8, 0); + auto &S = G.addDefinedSymbol(B, 0, "sym", 4, Linkage::Strong, Scope::Default, + false, false); + + EXPECT_TRUE(S.hasName()); + EXPECT_EQ(*S.getName(), "sym"); + EXPECT_TRUE(S.isDefined()); + EXPECT_FALSE(S.isLive()); + EXPECT_FALSE(S.isCallable()); + EXPECT_FALSE(S.isExternal()); + EXPECT_FALSE(S.isAbsolute()); + EXPECT_EQ(&S.getBlock(), &B); + EXPECT_EQ(&S.getSection(), &Sec); + EXPECT_EQ(S.getOffset(), 0U); + EXPECT_EQ(S.getSize(), 4U); + EXPECT_EQ(S.getRange(), orc::ExecutorAddrRange(B.getAddress(), 4)); + EXPECT_EQ(S.getSymbolContent(), BlockContent.slice(0, 4)); + EXPECT_EQ(S.getLinkage(), Linkage::Strong); + EXPECT_EQ(S.getScope(), Scope::Default); + EXPECT_EQ(S.getTargetFlags(), 0U); +} + TEST(LinkGraphTest, SectionEmpty) { // Check that Section::empty behaves as expected. LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(), _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits