mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 05:46:06 +00:00
[JITLink][MachO] Handle MachO section start/end symbols.
Transform section$start$<section-name> and section$end$<section-name> external symbols into defined symbols when a section named <section-name> is present. rdar://125357048 Coding my way home: 8.98112N, 79.52094W
This commit is contained in:
parent
94bbc18bb6
commit
c4d5881550
@ -127,6 +127,29 @@ identifyELFSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym) {
|
||||
return {};
|
||||
}
|
||||
|
||||
/// MachO section start/end symbol detection.
|
||||
inline SectionRangeSymbolDesc
|
||||
identifyMachOSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym) {
|
||||
constexpr StringRef StartSymbolPrefix = "section$start$";
|
||||
constexpr StringRef EndSymbolPrefix = "section$end$";
|
||||
|
||||
auto SymName = Sym.getName();
|
||||
if (SymName.starts_with(StartSymbolPrefix)) {
|
||||
auto [SegName, SecName] =
|
||||
SymName.drop_front(StartSymbolPrefix.size()).split('$');
|
||||
std::string SectionName = (SegName + "," + SecName).str();
|
||||
if (auto *Sec = G.findSectionByName(SectionName))
|
||||
return {*Sec, true};
|
||||
} else if (SymName.starts_with(EndSymbolPrefix)) {
|
||||
auto [SegName, SecName] =
|
||||
SymName.drop_front(EndSymbolPrefix.size()).split('$');
|
||||
std::string SectionName = (SegName + "," + SecName).str();
|
||||
if (auto *Sec = G.findSectionByName(SectionName))
|
||||
return {*Sec, false};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // end namespace jitlink
|
||||
} // end namespace llvm
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "llvm/ExecutionEngine/JITLink/DWARFRecordSectionSplitter.h"
|
||||
#include "llvm/ExecutionEngine/JITLink/aarch64.h"
|
||||
|
||||
#include "DefineExternalSectionStartAndEndSymbols.h"
|
||||
#include "MachOLinkGraphBuilder.h"
|
||||
|
||||
#define DEBUG_TYPE "jitlink"
|
||||
@ -593,6 +594,11 @@ void link_MachO_arm64(std::unique_ptr<LinkGraph> G,
|
||||
Config.PrePrunePasses.push_back(createEHFrameSplitterPass_MachO_arm64());
|
||||
Config.PrePrunePasses.push_back(createEHFrameEdgeFixerPass_MachO_arm64());
|
||||
|
||||
// Resolve any external section start / end symbols.
|
||||
Config.PostAllocationPasses.push_back(
|
||||
createDefineExternalSectionStartAndEndSymbolsPass(
|
||||
identifyMachOSectionStartAndEndSymbols));
|
||||
|
||||
// Add an in-place GOT/Stubs pass.
|
||||
Config.PostPrunePasses.push_back(buildTables_MachO_arm64);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "llvm/ExecutionEngine/JITLink/DWARFRecordSectionSplitter.h"
|
||||
#include "llvm/ExecutionEngine/JITLink/x86_64.h"
|
||||
|
||||
#include "DefineExternalSectionStartAndEndSymbols.h"
|
||||
#include "MachOLinkGraphBuilder.h"
|
||||
|
||||
#define DEBUG_TYPE "jitlink"
|
||||
@ -516,6 +517,11 @@ void link_MachO_x86_64(std::unique_ptr<LinkGraph> G,
|
||||
else
|
||||
Config.PrePrunePasses.push_back(markAllSymbolsLive);
|
||||
|
||||
// Resolve any external section start / end symbols.
|
||||
Config.PostAllocationPasses.push_back(
|
||||
createDefineExternalSectionStartAndEndSymbolsPass(
|
||||
identifyMachOSectionStartAndEndSymbols));
|
||||
|
||||
// Add an in-place GOT/Stubs pass.
|
||||
Config.PostPrunePasses.push_back(buildGOTAndStubs_MachO_x86_64);
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
# RUN: llvm-mc -triple=arm64-apple-darwin24 -filetype=obj -o %t.o %s
|
||||
# RUN: llvm-jitlink -noexec -check %s %t.o
|
||||
|
||||
# jitlink-check: *{8}_z = (*{8}_y) + 4
|
||||
|
||||
.section __TEXT,__text,regular,pure_instructions
|
||||
.globl _main
|
||||
.p2align 2
|
||||
_main:
|
||||
mov w0, #0
|
||||
ret
|
||||
|
||||
.section __DATA,__custom_section
|
||||
.globl _x
|
||||
.p2align 2, 0x0
|
||||
_x:
|
||||
.long 42
|
||||
|
||||
.section __DATA,__data
|
||||
.globl _y
|
||||
.p2align 3, 0x0
|
||||
_y:
|
||||
.quad section$start$__DATA$__custom_section
|
||||
|
||||
.globl _z
|
||||
.p2align 3, 0x0
|
||||
_z:
|
||||
.quad section$end$__DATA$__custom_section
|
||||
|
||||
.subsections_via_symbols
|
Loading…
x
Reference in New Issue
Block a user