: Obj(Obj),
G(std::make_unique<LinkGraph>(
std::string(Obj.getFileName()), std::move(TT), getPointerSize(Obj),
- getEndianness(Obj), std::move(GetEdgeKindName))) {}
+ getEndianness(Obj), std::move(GetEdgeKindName))) {
+ auto &MachHeader = Obj.getHeader64();
+ SubsectionsViaSymbols = MachHeader.flags & MachO::MH_SUBSECTIONS_VIA_SYMBOLS;
+}
void MachOLinkGraphBuilder::addCustomSectionParser(
StringRef SectionName, SectionParserFunction Parser) {
}
// Visit section symbols in order by popping off the reverse-sorted stack,
- // building blocks for each alt-entry chain and creating symbols as we go.
+ // building graph symbols as we go.
+ //
+ // If MH_SUBSECTIONS_VIA_SYMBOLS is set we'll build a block for each
+ // alt-entry chain.
+ //
+ // If MH_SUBSECTIONS_VIA_SYMBOLS is not set then we'll just build one block
+ // for the whole section.
while (!SecNSymStack.empty()) {
SmallVector<NormalizedSymbol *, 8> BlockSyms;
+ // Get the symbols in this alt-entry chain, or the whole section (if
+ // !SubsectionsViaSymbols).
BlockSyms.push_back(SecNSymStack.back());
SecNSymStack.pop_back();
while (!SecNSymStack.empty() &&
(isAltEntry(*SecNSymStack.back()) ||
- SecNSymStack.back()->Value == BlockSyms.back()->Value)) {
+ SecNSymStack.back()->Value == BlockSyms.back()->Value ||
+ !SubsectionsViaSymbols)) {
BlockSyms.push_back(SecNSymStack.back());
SecNSymStack.pop_back();
}
--- /dev/null
+# The assembly below does NOT include the usual .subsections_via_symbols
+# directive. Check that when the directive is absent we only create one block
+# to cover the whole data section.
+#
+# REQUIRES: asserts
+# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s
+# RUN: llvm-jitlink -debug-only=jitlink -noexec %t 2>&1 | FileCheck %s
+
+# CHECK: Creating graph symbols...
+# CHECK: Graphifying regular section __DATA,__data...
+# CHECK-NEXT: Creating block {{.*}} with 2 symbol(s)...
+# CHECK-NEXT: 0x0000000000000004 -- 0x0000000000000008: _b
+# CHECK-NEXT: 0x0000000000000000 -- 0x0000000000000008: _main
+
+ .section __DATA,__data
+ .p2align 2
+ .globl _main
+_main:
+ .long 1
+_b:
+ .long 2