LLVM: lib/ExecutionEngine/JITLink/DefineExternalSectionStartAndEndSymbols.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_EXECUTIONENGINE_JITLINK_DEFINEEXTERNALSECTIONSTARTANDENDSYMBOLS_H

16#define LLVM_EXECUTIONENGINE_JITLINK_DEFINEEXTERNALSECTIONSTARTANDENDSYMBOLS_H

17

20

21#define DEBUG_TYPE "jitlink"

22

23namespace llvm {

24namespace jitlink {

25

33

34

35

36template

38public:

41

43

44

45

46 std::vector<Symbol *> Externals(G.external_symbols().begin(),

47 G.external_symbols().end());

48

49 for (auto *Sym : Externals) {

51 if (D.Sec) {

52 auto &SR = getSectionRange(*D.Sec);

53 if (D.IsStart) {

54 if (SR.empty())

56 else

57 G.makeDefined(*Sym, *SR.getFirstBlock(), 0, 0, Linkage::Strong,

59 } else {

60 if (SR.empty())

62 else

63 G.makeDefined(*Sym, *SR.getLastBlock(),

66 }

67 }

68 }

70 }

71

72private:

74 return SectionRanges.try_emplace(&Sec, Sec).first->second;

75 }

76

78 SymbolIdentifierFunction F;

79};

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100template

101DefineExternalSectionStartAndEndSymbols

103 SymbolIdentifierFunction &&F) {

105 std::forward(F));

106}

107

108

109inline SectionRangeSymbolDesc

111 constexpr StringRef StartSymbolPrefix = "__start_";

112 constexpr StringRef EndSymbolPrefix = "__stop_";

113

114 auto SymName = Sym.getName();

115 if ((*SymName).starts_with(StartSymbolPrefix)) {

116 if (auto *Sec = G.findSectionByName(

117 (*SymName).drop_front(StartSymbolPrefix.size())))

118 return {*Sec, true};

119 } else if ((*SymName).starts_with(EndSymbolPrefix)) {

120 if (auto *Sec =

121 G.findSectionByName((*SymName).drop_front(EndSymbolPrefix.size())))

122 return {*Sec, false};

123 }

124 return {};

125}

126

127

128inline SectionRangeSymbolDesc

130 constexpr StringRef StartSymbolPrefix = "section$start$";

131 constexpr StringRef EndSymbolPrefix = "section$end$";

132

133 auto SymName = Sym.getName();

134 if ((*SymName).starts_with(StartSymbolPrefix)) {

135 auto [SegName, SecName] =

136 (*SymName).drop_front(StartSymbolPrefix.size()).split('$');

137 std::string SectionName = (SegName + "," + SecName).str();

138 if (auto *Sec = G.findSectionByName(SectionName))

139 return {*Sec, true};

140 } else if ((*SymName).starts_with(EndSymbolPrefix)) {

141 auto [SegName, SecName] =

142 (*SymName).drop_front(EndSymbolPrefix.size()).split('$');

143 std::string SectionName = (SegName + "," + SecName).str();

144 if (auto *Sec = G.findSectionByName(SectionName))

145 return {*Sec, false};

146 }

147 return {};

148}

149

150}

151}

152

153#undef DEBUG_TYPE

154

155#endif

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

StringRef - Represent a constant reference to a string, i.e.

constexpr size_t size() const

size - Get the string size.

Pass implementation for the createDefineExternalSectionStartAndEndSymbols function.

Definition DefineExternalSectionStartAndEndSymbols.h:37

DefineExternalSectionStartAndEndSymbols(SymbolIdentifierFunction F)

Definition DefineExternalSectionStartAndEndSymbols.h:39

Error operator()(LinkGraph &G)

Definition DefineExternalSectionStartAndEndSymbols.h:42

Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...

Represents an object file section.

const orc::SymbolStringPtr & getName() const

Returns the name of this symbol (empty if the symbol is anonymous).

Represents an address in the executor process.

SectionRangeSymbolDesc identifyELFSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym)

ELF section start/end symbol detection.

Definition DefineExternalSectionStartAndEndSymbols.h:110

DefineExternalSectionStartAndEndSymbols< SymbolIdentifierFunction > createDefineExternalSectionStartAndEndSymbolsPass(SymbolIdentifierFunction &&F)

Returns a JITLink pass (as a function class) that uses the given symbol identification function to id...

Definition DefineExternalSectionStartAndEndSymbols.h:102

SectionRangeSymbolDesc identifyMachOSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym)

MachO section start/end symbol detection.

Definition DefineExternalSectionStartAndEndSymbols.h:129

This is an optimization pass for GlobalISel generic memory operations.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.

SectionRangeSymbolDesc()=default

bool IsStart

Definition DefineExternalSectionStartAndEndSymbols.h:31

SectionRangeSymbolDesc(Section &Sec, bool IsStart)

Definition DefineExternalSectionStartAndEndSymbols.h:28

Section * Sec

Definition DefineExternalSectionStartAndEndSymbols.h:30