Skip to content

Commit 4a2a8ed

Browse files
committed
[JITLink] Add a jitlink::Symbol::getSection() convenience method.
`Sym.getSection()` is equivalent to `Sym.getBlock().getSection()`.
1 parent accfbd4 commit 4a2a8ed

File tree

10 files changed

+47
-15
lines changed

10 files changed

+47
-15
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ class Symbol {
587587
return static_cast<const Block &>(*Base);
588588
}
589589

590+
/// Return the Section for this Symbol (Symbol must be defined).
591+
Section &getSection() const { return getBlock().getSection(); }
592+
590593
/// Returns the offset for this symbol within the underlying addressable.
591594
orc::ExecutorAddrDiff getOffset() const { return Offset; }
592595

@@ -1460,7 +1463,7 @@ class LinkGraph {
14601463
A.setAddress(orc::ExecutorAddr());
14611464
} else {
14621465
assert(Sym.isDefined() && "Sym is not a defined symbol");
1463-
Section &Sec = Sym.getBlock().getSection();
1466+
Section &Sec = Sym.getSection();
14641467
Sec.removeSymbol(Sym);
14651468
Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false));
14661469
}
@@ -1488,7 +1491,7 @@ class LinkGraph {
14881491
Sym.setScope(Scope::Local);
14891492
} else {
14901493
assert(Sym.isDefined() && "Sym is not a defined symbol");
1491-
Section &Sec = Sym.getBlock().getSection();
1494+
Section &Sec = Sym.getSection();
14921495
Sec.removeSymbol(Sym);
14931496
Sym.makeAbsolute(createAddressable(Address));
14941497
}
@@ -1534,7 +1537,7 @@ class LinkGraph {
15341537
transferDefinedSymbol(Symbol &Sym, Block &DestBlock,
15351538
orc::ExecutorAddrDiff NewOffset,
15361539
std::optional<orc::ExecutorAddrDiff> ExplicitNewSize) {
1537-
auto &OldSection = Sym.getBlock().getSection();
1540+
auto &OldSection = Sym.getSection();
15381541
Sym.setBlock(DestBlock);
15391542
Sym.setOffset(NewOffset);
15401543
if (ExplicitNewSize)
@@ -1622,7 +1625,7 @@ class LinkGraph {
16221625
/// Removes defined symbols. Does not remove the underlying block.
16231626
void removeDefinedSymbol(Symbol &Sym) {
16241627
assert(Sym.isDefined() && "Sym is not a defined symbol");
1625-
Sym.getBlock().getSection().removeSymbol(Sym);
1628+
Sym.getSection().removeSymbol(Sym);
16261629
destroySymbol(Sym);
16271630
}
16281631

llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ class COFFLinkGraphLowering_x86_64 {
221221
}
222222
case EdgeKind_coff_x86_64::SecRel32: {
223223
E.setAddend(E.getAddend() -
224-
getSectionStart(E.getTarget().getBlock().getSection())
225-
.getValue());
224+
getSectionStart(E.getTarget().getSection()).getValue());
226225
E.setKind(x86_64::Pointer32);
227226
break;
228227
}

llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ template <typename CURecTraits> class CompactUnwindManager {
155155
Edge *KeepAliveEdge = nullptr;
156156
for (auto &E : Fn.getBlock().edges_at(0)) {
157157
if (E.getKind() == Edge::KeepAlive && E.getTarget().isDefined() &&
158-
&E.getTarget().getBlock().getSection() == EHFrameSec) {
158+
&E.getTarget().getSection() == EHFrameSec) {
159159
KeepAliveEdge = &E;
160160
break;
161161
}

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
424424
if (E.getTarget().hasName()) {
425425
ErrStream << "\"" << E.getTarget().getName() << "\"";
426426
} else
427-
ErrStream << E.getTarget().getBlock().getSection().getName() << " + "
427+
ErrStream << E.getTarget().getSection().getName() << " + "
428428
<< formatv("{0:x}", E.getOffset());
429429
ErrStream << " at address " << formatv("{0:x}", E.getTarget().getAddress())
430430
<< " is out of range of " << G.getEdgeKindName(E.getKind())

llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ template <typename LinkerImpl> class JITLinker : public JITLinkerBase {
162162
// If B is a block in a Standard or Finalize section then make sure
163163
// that no edges point to symbols in NoAlloc sections.
164164
assert((NoAllocSection || !E.getTarget().isDefined() ||
165-
E.getTarget().getBlock().getSection().getMemLifetime() !=
165+
E.getTarget().getSection().getMemLifetime() !=
166166
orc::MemLifetime::NoAlloc) &&
167167
"Block in allocated section has edge pointing to no-alloc "
168168
"section");

llvm/lib/ExecutionEngine/JITLink/aarch32.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ bool StubsManager_prev7::visitEdge(LinkGraph &G, Block *B, Edge &E) {
874874
LLVM_DEBUG({
875875
dbgs() << " Using " << (UseThumb ? "Thumb" : "Arm") << " entrypoint "
876876
<< *StubEntrypoint << " in "
877-
<< StubEntrypoint->getBlock().getSection().getName() << "\n";
877+
<< StubEntrypoint->getSection().getName() << "\n";
878878
});
879879

880880
E.setTarget(*StubEntrypoint);
@@ -919,8 +919,8 @@ bool StubsManager_v7::visitEdge(LinkGraph &G, Block *B, Edge &E) {
919919
"Instruction set states of stub and relocation site should be equal");
920920
LLVM_DEBUG({
921921
dbgs() << " Using " << (MakeThumb ? "Thumb" : "Arm") << " entry "
922-
<< *StubSymbol << " in "
923-
<< StubSymbol->getBlock().getSection().getName() << "\n";
922+
<< *StubSymbol << " in " << StubSymbol->getSection().getName()
923+
<< "\n";
924924
});
925925

926926
E.setTarget(*StubSymbol);

llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ getCodeLoadRecord(const Symbol &Sym, std::atomic<uint64_t> &CodeIndex) {
113113

114114
static std::optional<PerfJITDebugInfoRecord>
115115
getDebugInfoRecord(const Symbol &Sym, DWARFContext &DC) {
116-
auto &Section = Sym.getBlock().getSection();
116+
auto &Section = Sym.getSection();
117117
auto Addr = Sym.getAddress();
118118
auto Size = Sym.getSize();
119119
auto SAddr = object::SectionedAddress{Addr.getValue(), Section.getOrdinal()};

llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static VTuneMethodBatch getMethodBatch(LinkGraph &G, bool EmitDebugInfo) {
6363
if (!EmitDebugInfo)
6464
continue;
6565

66-
auto &Section = Sym->getBlock().getSection();
66+
auto &Section = Sym->getSection();
6767
auto Addr = Sym->getAddress();
6868
auto SAddr =
6969
object::SectionedAddress{Addr.getValue(), Section.getOrdinal()};

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
10711071
for (auto *B : Sec.blocks())
10721072
for (auto &E : B->edges())
10731073
if (E.getTarget().isDefined() &&
1074-
&E.getTarget().getBlock().getSection() == ObjCImageInfo)
1074+
&E.getTarget().getSection() == ObjCImageInfo)
10751075
return make_error<StringError>(MachOObjCImageInfoSectionName +
10761076
" is referenced within file " +
10771077
G.getName(),

llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,36 @@ TEST(LinkGraphTest, AddressAccess) {
5454
EXPECT_EQ(B1.getFixupAddress(E1), B1Addr + 8) << "Incorrect fixup address";
5555
}
5656

57+
TEST(LinkGraphTest, DefinedSymbolProperties) {
58+
// Check that Section::empty behaves as expected.
59+
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
60+
Triple("x86_64-apple-darwin"), SubtargetFeatures(),
61+
getGenericEdgeKindName);
62+
auto &Sec =
63+
G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
64+
auto &B =
65+
G.createContentBlock(Sec, BlockContent, orc::ExecutorAddr(0x1000), 8, 0);
66+
auto &S = G.addDefinedSymbol(B, 0, "sym", 4, Linkage::Strong, Scope::Default,
67+
false, false);
68+
69+
EXPECT_TRUE(S.hasName());
70+
EXPECT_EQ(*S.getName(), "sym");
71+
EXPECT_TRUE(S.isDefined());
72+
EXPECT_FALSE(S.isLive());
73+
EXPECT_FALSE(S.isCallable());
74+
EXPECT_FALSE(S.isExternal());
75+
EXPECT_FALSE(S.isAbsolute());
76+
EXPECT_EQ(&S.getBlock(), &B);
77+
EXPECT_EQ(&S.getSection(), &Sec);
78+
EXPECT_EQ(S.getOffset(), 0U);
79+
EXPECT_EQ(S.getSize(), 4U);
80+
EXPECT_EQ(S.getRange(), orc::ExecutorAddrRange(B.getAddress(), 4));
81+
EXPECT_EQ(S.getSymbolContent(), BlockContent.slice(0, 4));
82+
EXPECT_EQ(S.getLinkage(), Linkage::Strong);
83+
EXPECT_EQ(S.getScope(), Scope::Default);
84+
EXPECT_EQ(S.getTargetFlags(), 0U);
85+
}
86+
5787
TEST(LinkGraphTest, SectionEmpty) {
5888
// Check that Section::empty behaves as expected.
5989
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),

0 commit comments

Comments
 (0)