@@ -44,7 +44,7 @@ static constexpr char indent8[] = " "; // 8 spaces
44
44
static constexpr char indent16[] = " " ; // 16 spaces
45
45
46
46
// Print out the first three columns of a line.
47
- static void writeHeader (raw_ostream &os, uint64_t vma, uint64_t lma,
47
+ static void writeHeader (Ctx &ctx, raw_ostream &os, uint64_t vma, uint64_t lma,
48
48
uint64_t size, uint64_t align) {
49
49
if (ctx.arg .is64 )
50
50
os << format (" %16llx %16llx %8llx %5lld " , vma, lma, size, align);
@@ -90,14 +90,14 @@ static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
90
90
// Demangling symbols (which is what toString() does) is slow, so
91
91
// we do that in batch using parallel-for.
92
92
static DenseMap<Symbol *, std::string>
93
- getSymbolStrings (ArrayRef<Defined *> syms) {
93
+ getSymbolStrings (Ctx &ctx, ArrayRef<Defined *> syms) {
94
94
auto strs = std::make_unique<std::string[]>(syms.size ());
95
95
parallelFor (0 , syms.size (), [&](size_t i) {
96
96
raw_string_ostream os (strs[i]);
97
97
OutputSection *osec = syms[i]->getOutputSection ();
98
98
uint64_t vma = syms[i]->getVA ();
99
99
uint64_t lma = osec ? osec->getLMA () + vma - osec->getVA (0 ) : 0 ;
100
- writeHeader (os, vma, lma, syms[i]->getSize (), 1 );
100
+ writeHeader (ctx, os, vma, lma, syms[i]->getSize (), 1 );
101
101
os << indent16 << toString (*syms[i]);
102
102
});
103
103
@@ -113,7 +113,7 @@ getSymbolStrings(ArrayRef<Defined *> syms) {
113
113
// .eh_frame tend to contain a lot of section pieces that are contiguous
114
114
// both in input file and output file. Such pieces are squashed before
115
115
// being displayed to make output compact.
116
- static void printEhFrame (raw_ostream &os, const EhFrameSection *sec) {
116
+ static void printEhFrame (Ctx &ctx, raw_ostream &os, const EhFrameSection *sec) {
117
117
std::vector<EhSectionPiece> pieces;
118
118
119
119
auto add = [&](const EhSectionPiece &p) {
@@ -139,18 +139,18 @@ static void printEhFrame(raw_ostream &os, const EhFrameSection *sec) {
139
139
// Print out section pieces.
140
140
const OutputSection *osec = sec->getOutputSection ();
141
141
for (EhSectionPiece &p : pieces) {
142
- writeHeader (os, osec->addr + p.outputOff , osec->getLMA () + p.outputOff ,
142
+ writeHeader (ctx, os, osec->addr + p.outputOff , osec->getLMA () + p.outputOff ,
143
143
p.size , 1 );
144
144
os << indent8 << toString (p.sec ->file ) << " :(" << p.sec ->name << " +0x"
145
145
<< Twine::utohexstr (p.inputOff ) + " )\n " ;
146
146
}
147
147
}
148
148
149
- static void writeMapFile (raw_fd_ostream &os) {
149
+ static void writeMapFile (Ctx &ctx, raw_fd_ostream &os) {
150
150
// Collect symbol info that we want to print out.
151
151
std::vector<Defined *> syms = getSymbols ();
152
152
SymbolMapTy sectionSyms = getSectionSyms (syms);
153
- DenseMap<Symbol *, std::string> symStr = getSymbolStrings (syms);
153
+ DenseMap<Symbol *, std::string> symStr = getSymbolStrings (ctx, syms);
154
154
155
155
// Print out the header line.
156
156
int w = ctx.arg .is64 ? 16 : 8 ;
@@ -163,27 +163,28 @@ static void writeMapFile(raw_fd_ostream &os) {
163
163
if (assign->provide && !assign->sym )
164
164
continue ;
165
165
uint64_t lma = osec ? osec->getLMA () + assign->addr - osec->getVA (0 ) : 0 ;
166
- writeHeader (os, assign->addr , lma, assign->size , 1 );
166
+ writeHeader (ctx, os, assign->addr , lma, assign->size , 1 );
167
167
os << assign->commandString << ' \n ' ;
168
168
continue ;
169
169
}
170
170
if (isa<SectionClassDesc>(cmd))
171
171
continue ;
172
172
173
173
osec = &cast<OutputDesc>(cmd)->osec ;
174
- writeHeader (os, osec->addr , osec->getLMA (), osec->size , osec->addralign );
174
+ writeHeader (ctx, os, osec->addr , osec->getLMA (), osec->size ,
175
+ osec->addralign );
175
176
os << osec->name << ' \n ' ;
176
177
177
178
// Dump symbols for each input section.
178
179
for (SectionCommand *subCmd : osec->commands ) {
179
180
if (auto *isd = dyn_cast<InputSectionDescription>(subCmd)) {
180
181
for (InputSection *isec : isd->sections ) {
181
182
if (auto *ehSec = dyn_cast<EhFrameSection>(isec)) {
182
- printEhFrame (os, ehSec);
183
+ printEhFrame (ctx, os, ehSec);
183
184
continue ;
184
185
}
185
186
186
- writeHeader (os, isec->getVA (), osec->getLMA () + isec->outSecOff ,
187
+ writeHeader (ctx, os, isec->getVA (), osec->getLMA () + isec->outSecOff ,
187
188
isec->getSize (), isec->addralign );
188
189
os << indent8 << toString (isec) << ' \n ' ;
189
190
for (Symbol *sym : llvm::make_first_range (sectionSyms[isec]))
@@ -193,7 +194,7 @@ static void writeMapFile(raw_fd_ostream &os) {
193
194
}
194
195
195
196
if (auto *data = dyn_cast<ByteCommand>(subCmd)) {
196
- writeHeader (os, osec->addr + data->offset ,
197
+ writeHeader (ctx, os, osec->addr + data->offset ,
197
198
osec->getLMA () + data->offset , data->size , 1 );
198
199
os << indent8 << data->commandString << ' \n ' ;
199
200
continue ;
@@ -202,7 +203,7 @@ static void writeMapFile(raw_fd_ostream &os) {
202
203
if (auto *assign = dyn_cast<SymbolAssignment>(subCmd)) {
203
204
if (assign->provide && !assign->sym )
204
205
continue ;
205
- writeHeader (os, assign->addr ,
206
+ writeHeader (ctx, os, assign->addr ,
206
207
osec->getLMA () + assign->addr - osec->getVA (0 ),
207
208
assign->size , 1 );
208
209
os << indent8 << assign->commandString << ' \n ' ;
@@ -223,7 +224,7 @@ static void writeMapFile(raw_fd_ostream &os) {
223
224
//
224
225
// In this case, strlen is defined by libc.so.6 and used by other two
225
226
// files.
226
- static void writeCref (raw_fd_ostream &os) {
227
+ static void writeCref (Ctx &ctx, raw_fd_ostream &os) {
227
228
// Collect symbols and files.
228
229
MapVector<Symbol *, SetVector<InputFile *>> map;
229
230
for (ELFFileBase *file : ctx.objectFiles ) {
@@ -256,7 +257,7 @@ static void writeCref(raw_fd_ostream &os) {
256
257
}
257
258
}
258
259
259
- void elf::writeMapAndCref () {
260
+ void elf::writeMapAndCref (Ctx &ctx ) {
260
261
if (ctx.arg .mapFile .empty () && !ctx.arg .cref )
261
262
return ;
262
263
@@ -272,7 +273,7 @@ void elf::writeMapAndCref() {
272
273
}
273
274
274
275
if (!ctx.arg .mapFile .empty ())
275
- writeMapFile (os);
276
+ writeMapFile (ctx, os);
276
277
if (ctx.arg .cref )
277
- writeCref (os);
278
+ writeCref (ctx, os);
278
279
}
0 commit comments