@@ -95,6 +95,10 @@ std::string lld::toString(const InputFile *f) {
9595 return (f->archiveName + " (" + path::filename (f->getName ()) + " )" ).str ();
9696}
9797
98+ std::string lld::toString (const Section &sec) {
99+ return (toString (sec.file ) + " :(" + sec.name + " )" ).str ();
100+ }
101+
98102SetVector<InputFile *> macho::inputFiles;
99103std::unique_ptr<TarWriter> macho::tar;
100104int InputFile::idCount = 0 ;
@@ -302,7 +306,7 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
302306 " is too large" );
303307 continue ;
304308 }
305- const Section §ion = *sections.back ();
309+ Section §ion = *sections.back ();
306310 uint32_t align = 1 << sec.align ;
307311 ArrayRef<uint8_t > data = {isZeroFill (sec.flags ) ? nullptr
308312 : buf + sec.offset ,
@@ -311,7 +315,7 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
311315 auto splitRecords = [&](int recordSize) -> void {
312316 if (data.empty ())
313317 return ;
314- Subsections &subsections = sections. back ()-> subsections ;
318+ Subsections &subsections = section. subsections ;
315319 subsections.reserve (data.size () / recordSize);
316320 for (uint64_t off = 0 ; off < data.size (); off += recordSize) {
317321 auto *isec = make<ConcatInputSection>(
@@ -336,11 +340,11 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
336340 } else {
337341 isec = make<WordLiteralInputSection>(section, data, align);
338342 }
339- sections. back ()-> subsections .push_back ({0 , isec});
343+ section. subsections .push_back ({0 , isec});
340344 } else if (auto recordSize = getRecordSize (segname, name)) {
341345 splitRecords (*recordSize);
342346 if (name == section_names::compactUnwind)
343- compactUnwindSection = sections. back () ;
347+ compactUnwindSection = §ion ;
344348 } else if (segname == segment_names::llvm) {
345349 if (config->callGraphProfileSort && name == section_names::cgProfile)
346350 checkError (parseCallGraph (data, callGraph));
@@ -359,7 +363,7 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
359363 // parsing their relocations unnecessarily.
360364 debugSections.push_back (isec);
361365 } else {
362- sections. back ()-> subsections .push_back ({0 , isec});
366+ section. subsections .push_back ({0 , isec});
363367 }
364368 }
365369 }
@@ -724,8 +728,7 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
724728 Subsections &subsections = sections[i]->subsections ;
725729 if (subsections.empty ())
726730 continue ;
727- InputSection *lastIsec = subsections.back ().isec ;
728- if (lastIsec->getName () == section_names::ehFrame) {
731+ if (sections[i]->name == section_names::ehFrame) {
729732 // __TEXT,__eh_frame only has symbols and SUBTRACTOR relocs when ld64 -r
730733 // adds local "EH_Frame1" and "func.eh". Ignore them because they have
731734 // gone unused by Mac OS since Snow Leopard (10.6), vintage 2009.
@@ -738,7 +741,7 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
738741 // Record-based sections have already been split into subsections during
739742 // parseSections(), so we simply need to match Symbols to the corresponding
740743 // subsection here.
741- if (getRecordSize (lastIsec-> getSegName (), lastIsec-> getName () )) {
744+ if (getRecordSize (sections[i]-> segname , sections[i]-> name )) {
742745 for (size_t j = 0 ; j < symbolIndices.size (); ++j) {
743746 uint32_t symIndex = symbolIndices[j];
744747 const NList &sym = nList[symIndex];
@@ -747,7 +750,7 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
747750 InputSection *isec =
748751 findContainingSubsection (*sections[i], &symbolOffset);
749752 if (symbolOffset != 0 ) {
750- error (toString (lastIsec ) + " : symbol " + name +
753+ error (toString (*sections[i] ) + " : symbol " + name +
751754 " at misaligned offset" );
752755 continue ;
753756 }
0 commit comments