@@ -44,7 +44,7 @@ static constexpr char indent8[] = " "; // 8 spaces
4444static constexpr char indent16[] = " " ; // 16 spaces
4545
4646// 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,
4848 uint64_t size, uint64_t align) {
4949 if (ctx.arg .is64 )
5050 os << format (" %16llx %16llx %8llx %5lld " , vma, lma, size, align);
@@ -90,14 +90,14 @@ static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
9090// Demangling symbols (which is what toString() does) is slow, so
9191// we do that in batch using parallel-for.
9292static DenseMap<Symbol *, std::string>
93- getSymbolStrings (ArrayRef<Defined *> syms) {
93+ getSymbolStrings (Ctx &ctx, ArrayRef<Defined *> syms) {
9494 auto strs = std::make_unique<std::string[]>(syms.size ());
9595 parallelFor (0 , syms.size (), [&](size_t i) {
9696 raw_string_ostream os (strs[i]);
9797 OutputSection *osec = syms[i]->getOutputSection ();
9898 uint64_t vma = syms[i]->getVA ();
9999 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 );
101101 os << indent16 << toString (*syms[i]);
102102 });
103103
@@ -113,7 +113,7 @@ getSymbolStrings(ArrayRef<Defined *> syms) {
113113// .eh_frame tend to contain a lot of section pieces that are contiguous
114114// both in input file and output file. Such pieces are squashed before
115115// 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) {
117117 std::vector<EhSectionPiece> pieces;
118118
119119 auto add = [&](const EhSectionPiece &p) {
@@ -139,18 +139,18 @@ static void printEhFrame(raw_ostream &os, const EhFrameSection *sec) {
139139 // Print out section pieces.
140140 const OutputSection *osec = sec->getOutputSection ();
141141 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 ,
143143 p.size , 1 );
144144 os << indent8 << toString (p.sec ->file ) << " :(" << p.sec ->name << " +0x"
145145 << Twine::utohexstr (p.inputOff ) + " )\n " ;
146146 }
147147}
148148
149- static void writeMapFile (raw_fd_ostream &os) {
149+ static void writeMapFile (Ctx &ctx, raw_fd_ostream &os) {
150150 // Collect symbol info that we want to print out.
151151 std::vector<Defined *> syms = getSymbols ();
152152 SymbolMapTy sectionSyms = getSectionSyms (syms);
153- DenseMap<Symbol *, std::string> symStr = getSymbolStrings (syms);
153+ DenseMap<Symbol *, std::string> symStr = getSymbolStrings (ctx, syms);
154154
155155 // Print out the header line.
156156 int w = ctx.arg .is64 ? 16 : 8 ;
@@ -163,27 +163,28 @@ static void writeMapFile(raw_fd_ostream &os) {
163163 if (assign->provide && !assign->sym )
164164 continue ;
165165 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 );
167167 os << assign->commandString << ' \n ' ;
168168 continue ;
169169 }
170170 if (isa<SectionClassDesc>(cmd))
171171 continue ;
172172
173173 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 );
175176 os << osec->name << ' \n ' ;
176177
177178 // Dump symbols for each input section.
178179 for (SectionCommand *subCmd : osec->commands ) {
179180 if (auto *isd = dyn_cast<InputSectionDescription>(subCmd)) {
180181 for (InputSection *isec : isd->sections ) {
181182 if (auto *ehSec = dyn_cast<EhFrameSection>(isec)) {
182- printEhFrame (os, ehSec);
183+ printEhFrame (ctx, os, ehSec);
183184 continue ;
184185 }
185186
186- writeHeader (os, isec->getVA (), osec->getLMA () + isec->outSecOff ,
187+ writeHeader (ctx, os, isec->getVA (), osec->getLMA () + isec->outSecOff ,
187188 isec->getSize (), isec->addralign );
188189 os << indent8 << toString (isec) << ' \n ' ;
189190 for (Symbol *sym : llvm::make_first_range (sectionSyms[isec]))
@@ -193,7 +194,7 @@ static void writeMapFile(raw_fd_ostream &os) {
193194 }
194195
195196 if (auto *data = dyn_cast<ByteCommand>(subCmd)) {
196- writeHeader (os, osec->addr + data->offset ,
197+ writeHeader (ctx, os, osec->addr + data->offset ,
197198 osec->getLMA () + data->offset , data->size , 1 );
198199 os << indent8 << data->commandString << ' \n ' ;
199200 continue ;
@@ -202,7 +203,7 @@ static void writeMapFile(raw_fd_ostream &os) {
202203 if (auto *assign = dyn_cast<SymbolAssignment>(subCmd)) {
203204 if (assign->provide && !assign->sym )
204205 continue ;
205- writeHeader (os, assign->addr ,
206+ writeHeader (ctx, os, assign->addr ,
206207 osec->getLMA () + assign->addr - osec->getVA (0 ),
207208 assign->size , 1 );
208209 os << indent8 << assign->commandString << ' \n ' ;
@@ -223,7 +224,7 @@ static void writeMapFile(raw_fd_ostream &os) {
223224//
224225// In this case, strlen is defined by libc.so.6 and used by other two
225226// files.
226- static void writeCref (raw_fd_ostream &os) {
227+ static void writeCref (Ctx &ctx, raw_fd_ostream &os) {
227228 // Collect symbols and files.
228229 MapVector<Symbol *, SetVector<InputFile *>> map;
229230 for (ELFFileBase *file : ctx.objectFiles ) {
@@ -256,7 +257,7 @@ static void writeCref(raw_fd_ostream &os) {
256257 }
257258}
258259
259- void elf::writeMapAndCref () {
260+ void elf::writeMapAndCref (Ctx &ctx ) {
260261 if (ctx.arg .mapFile .empty () && !ctx.arg .cref )
261262 return ;
262263
@@ -272,7 +273,7 @@ void elf::writeMapAndCref() {
272273 }
273274
274275 if (!ctx.arg .mapFile .empty ())
275- writeMapFile (os);
276+ writeMapFile (ctx, os);
276277 if (ctx.arg .cref )
277- writeCref (os);
278+ writeCref (ctx, os);
278279}
0 commit comments