llvm.org GIT mirror llvm / 9a13839
[JITLink] Add an option to dump relocated section content. The -dump-relocated-section-content option will dump the contents of each section after relocations are applied, and before any checks are run or code executed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358863 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 5 months ago
1 changed file(s) with 82 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
8686 cl::init(false));
8787
8888 static cl::opt ShowSizes(
89 "show-sizes",
90 cl::desc("Show sizes: pre- and post-dead stripping, and allocations"),
91 cl::init(false));
89 "show-sizes",
90 cl::desc("Show sizes pre- and post-dead stripping, and allocations"),
91 cl::init(false));
92
93 static cl::opt ShowRelocatedSectionContents(
94 "show-relocated-section-contents",
95 cl::desc("show section contents after fixups have been applied"),
96 cl::init(false));
9297
9398 ExitOnError ExitOnErr;
9499
136141 else
137142 TotalSize += DA->getContent().size();
138143 return TotalSize;
144 }
145
146 static void dumpSectionContents(raw_ostream &OS, AtomGraph &G) {
147 constexpr JITTargetAddress DumpWidth = 16;
148 static_assert(isPowerOf2_64(DumpWidth), "DumpWidth must be a power of two");
149
150 // Put sections in address order.
151 std::vector
Sections;
152 for (auto &S : G.sections())
153 Sections.push_back(&S);
154
155 std::sort(Sections.begin(), Sections.end(),
156 [](const Section *LHS, const Section *RHS) {
157 if (LHS->atoms_empty() && RHS->atoms_empty())
158 return false;
159 if (LHS->atoms_empty())
160 return false;
161 if (RHS->atoms_empty())
162 return true;
163 return (*LHS->atoms().begin())->getAddress() <
164 (*RHS->atoms().begin())->getAddress();
165 });
166
167 for (auto *S : Sections) {
168 OS << S->getName() << " content:";
169 if (S->atoms_empty()) {
170 OS << "\n section empty\n";
171 continue;
172 }
173
174 // Sort atoms into order, then render.
175 std::vector Atoms(S->atoms().begin(), S->atoms().end());
176 std::sort(Atoms.begin(), Atoms.end(),
177 [](const DefinedAtom *LHS, const DefinedAtom *RHS) {
178 return LHS->getAddress() < RHS->getAddress();
179 });
180
181 JITTargetAddress NextAddr = Atoms.front()->getAddress() & ~(DumpWidth - 1);
182 for (auto *DA : Atoms) {
183 bool IsZeroFill = DA->isZeroFill();
184 JITTargetAddress AtomStart = DA->getAddress();
185 JITTargetAddress AtomSize =
186 IsZeroFill ? DA->getZeroFillSize() : DA->getContent().size();
187 JITTargetAddress AtomEnd = AtomStart + AtomSize;
188 const uint8_t *AtomData =
189 IsZeroFill ? nullptr : DA->getContent().bytes_begin();
190
191 // Pad any space before the atom starts.
192 while (NextAddr != AtomStart) {
193 if (NextAddr % DumpWidth == 0)
194 OS << formatv("\n{0:x16}:", NextAddr);
195 OS << " ";
196 ++NextAddr;
197 }
198
199 // Render the atom content.
200 while (NextAddr != AtomEnd) {
201 if (NextAddr % DumpWidth == 0)
202 OS << formatv("\n{0:x16}:", NextAddr);
203 if (IsZeroFill)
204 OS << " 00";
205 else
206 OS << formatv(" {0:x-2}", AtomData[NextAddr - AtomStart]);
207 ++NextAddr;
208 }
209 }
210 OS << "\n";
211 }
139212 }
140213
141214 Session::Session(Triple TT)
180253 });
181254 }
182255
256 if (ShowRelocatedSectionContents)
257 PassConfig.PostFixupPasses.push_back([](AtomGraph &G) -> Error {
258 outs() << "Relocated section contents for " << G.getName() << ":\n";
259 dumpSectionContents(outs(), G);
260 return Error::success();
261 });
183262 }
184263
185264 Expected Session::findFileInfo(StringRef FileName) {