@@ -161,20 +161,6 @@ static uint64_t getSymSizeForMap(Defined *sym) {
161
161
return sym->size ;
162
162
}
163
163
164
- // Merges two vectors of input sections in order of their outSecOff values.
165
- // This approach creates a new (temporary) vector which is not ideal but the
166
- // ideal approach leads to a lot of code duplication.
167
- static std::vector<ConcatInputSection *>
168
- mergeOrderedInputs (ArrayRef<ConcatInputSection *> inputs1,
169
- ArrayRef<ConcatInputSection *> inputs2) {
170
- std::vector<ConcatInputSection *> vec (inputs1.size () + inputs2.size ());
171
- std::merge (inputs1.begin (), inputs1.end (), inputs2.begin (), inputs2.end (),
172
- vec.begin (), [](ConcatInputSection *a, ConcatInputSection *b) {
173
- return a->outSecOff < b->outSecOff ;
174
- });
175
- return vec;
176
- }
177
-
178
164
void macho::writeMapFile () {
179
165
if (config->mapFile .empty ())
180
166
return ;
@@ -217,15 +203,32 @@ void macho::writeMapFile() {
217
203
seg->name .str ().c_str (), osec->name .str ().c_str ());
218
204
}
219
205
220
- // Shared function to print an array of symbols.
221
- auto printIsecArrSyms = [&](const std::vector<ConcatInputSection *> &arr) {
222
- for (const ConcatInputSection *isec : arr) {
223
- for (Defined *sym : isec->symbols ) {
224
- if (!(isPrivateLabel (sym->getName ()) && getSymSizeForMap (sym) == 0 ))
225
- os << format (" 0x%08llX\t 0x%08llX\t [%3u] %s\n " , sym->getVA (),
226
- getSymSizeForMap (sym),
227
- readerToFileOrdinal[sym->getFile ()],
228
- sym->getName ().str ().data ());
206
+ // Helper lambda that prints all symbols from one ConcatInputSection.
207
+ auto printOne = [&](const ConcatInputSection *isec) {
208
+ for (Defined *sym : isec->symbols ) {
209
+ if (!(isPrivateLabel (sym->getName ()) && getSymSizeForMap (sym) == 0 )) {
210
+ os << format (" 0x%08llX\t 0x%08llX\t [%3u] %s\n " , sym->getVA (),
211
+ getSymSizeForMap (sym),
212
+ readerToFileOrdinal.lookup (sym->getFile ()),
213
+ sym->getName ().str ().data ());
214
+ }
215
+ }
216
+ };
217
+ // Shared function to print one or two arrays of ConcatInputSection in
218
+ // ascending outSecOff order. The second array is optional; if provided, we
219
+ // interleave the printing in sorted order without allocating a merged temp
220
+ // array.
221
+ auto printIsecArrSyms = [&](ArrayRef<ConcatInputSection *> arr1,
222
+ ArrayRef<ConcatInputSection *> arr2 = {}) {
223
+ // Print both arrays in sorted order, interleaving as necessary.
224
+ while (!arr1.empty () || !arr2.empty ()) {
225
+ if (!arr1.empty () && (arr2.empty () || arr1.front ()->outSecOff <=
226
+ arr2.front ()->outSecOff )) {
227
+ printOne (arr1.front ());
228
+ arr1 = arr1.drop_front ();
229
+ } else if (!arr2.empty ()) {
230
+ printOne (arr2.front ());
231
+ arr2 = arr2.drop_front ();
229
232
}
230
233
}
231
234
};
@@ -235,9 +238,7 @@ void macho::writeMapFile() {
235
238
for (const OutputSegment *seg : outputSegments) {
236
239
for (const OutputSection *osec : seg->getSections ()) {
237
240
if (auto *textOsec = dyn_cast<TextOutputSection>(osec)) {
238
- auto inputsAndThunks =
239
- mergeOrderedInputs (textOsec->inputs , textOsec->getThunks ());
240
- printIsecArrSyms (inputsAndThunks);
241
+ printIsecArrSyms (textOsec->inputs , textOsec->getThunks ());
241
242
} else if (auto *concatOsec = dyn_cast<ConcatOutputSection>(osec)) {
242
243
printIsecArrSyms (concatOsec->inputs );
243
244
} else if (osec == in.cStringSection || osec == in.objcMethnameSection ) {
0 commit comments