@@ -68,8 +68,7 @@ std::string lld::toString(const InputFile *f) {
6868
6969const ELFSyncStream &elf::operator <<(const ELFSyncStream &s,
7070 const InputFile *f) {
71- s << toString (f);
72- return s;
71+ return s << toString (f);
7372}
7473
7574static ELFKind getELFKind (MemoryBufferRef mb, StringRef archiveName) {
@@ -80,9 +79,9 @@ static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
8079 auto report = [&](StringRef msg) {
8180 StringRef filename = mb.getBufferIdentifier ();
8281 if (archiveName.empty ())
83- fatal ( filename + " : " + msg) ;
82+ Fatal (ctx) << filename << " : " << msg;
8483 else
85- fatal ( archiveName + " (" + filename + " ): " + msg) ;
84+ Fatal (ctx) << archiveName << " (" << filename << " ): " << msg;
8685 };
8786
8887 if (!mb.getBuffer ().starts_with (ElfMagic))
@@ -573,7 +572,7 @@ template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
573572
574573 ArrayRef<Elf_Sym> eSyms = CHECK (obj.symbols (symtabSec), this );
575574 if (firstGlobal == 0 || firstGlobal > eSyms.size ())
576- fatal ( toString ( this ) + " : invalid sh_info in symbol table" ) ;
575+ Fatal (ctx) << this << " : invalid sh_info in symbol table" ;
577576
578577 elfSyms = reinterpret_cast <const void *>(eSyms.data ());
579578 numELFSyms = uint32_t (eSyms.size ());
@@ -666,11 +665,11 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
666665 ArrayRef<Elf_Word> entries =
667666 CHECK (obj.template getSectionContentsAsArray <Elf_Word>(sec), this );
668667 if (entries.empty ())
669- fatal ( toString ( this ) + " : empty SHT_GROUP" ) ;
668+ Fatal (ctx) << this << " : empty SHT_GROUP" ;
670669
671670 Elf_Word flag = entries[0 ];
672671 if (flag && flag != GRP_COMDAT)
673- fatal ( toString ( this ) + " : unsupported SHT_GROUP format" ) ;
672+ Fatal (ctx) << this << " : unsupported SHT_GROUP format" ;
674673
675674 bool keepGroup = (flag & GRP_COMDAT) == 0 || ignoreComdats ||
676675 ctx.symtab ->comdatGroups
@@ -686,8 +685,8 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
686685 // Otherwise, discard group members.
687686 for (uint32_t secIndex : entries.slice (1 )) {
688687 if (secIndex >= size)
689- fatal ( toString ( this ) +
690- " : invalid section index in group: " + Twine (secIndex) );
688+ Fatal (ctx) << this
689+ << " : invalid section index in group: " << Twine (secIndex);
691690 this ->sections [secIndex] = &InputSection::discarded;
692691 }
693692 }
@@ -704,7 +703,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
704703 const Elf_Shdr &sec) {
705704 typename ELFT::SymRange symbols = this ->getELFSyms <ELFT>();
706705 if (sec.sh_info >= symbols.size ())
707- fatal ( toString ( this ) + " : invalid symbol index" ) ;
706+ Fatal (ctx) << this << " : invalid symbol index" ;
708707 const typename ELFT::Sym &sym = symbols[sec.sh_info ];
709708 return CHECK (sym.getName (this ->stringTable ), this );
710709}
@@ -742,13 +741,13 @@ bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec, StringRef name) {
742741 if (entSize == 0 )
743742 return false ;
744743 if (sec.sh_size % entSize)
745- fatal ( toString ( this ) + " :(" + name + " ): SHF_MERGE section size (" +
746- Twine (sec.sh_size ) + " ) must be a multiple of sh_entsize (" +
747- Twine (entSize) + " )" ) ;
744+ Fatal (ctx) << this << " :(" << name << " ): SHF_MERGE section size ("
745+ << Twine (sec.sh_size ) << " ) must be a multiple of sh_entsize ("
746+ << Twine (entSize) << " )" ;
748747
749748 if (sec.sh_flags & SHF_WRITE)
750- fatal ( toString ( this ) + " :(" + name +
751- " ): writable SHF_MERGE section is not supported" ) ;
749+ Fatal (ctx) << this << " :(" << name
750+ << " ): writable SHF_MERGE section is not supported" ;
752751
753752 return true ;
754753}
@@ -934,7 +933,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
934933 if (sec.sh_link < size)
935934 linkSec = this ->sections [sec.sh_link ];
936935 if (!linkSec)
937- fatal ( toString ( this ) + " : invalid sh_link index: " + Twine (sec.sh_link ) );
936+ Fatal (ctx) << this << " : invalid sh_link index: " << Twine (sec.sh_link );
938937
939938 // A SHF_LINK_ORDER section is discarded if its linked-to section is
940939 // discarded.
@@ -963,8 +962,9 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
963962
964963 ArrayRef<uint8_t > data = sec.content ();
965964 auto reportFatal = [&](const uint8_t *place, const Twine &msg) {
966- fatal (toString (sec.file ) + " :(" + sec.name + " +0x" +
967- Twine::utohexstr (place - sec.content ().data ()) + " ): " + msg);
965+ Fatal (ctx) << sec.file << " :(" << sec.name << " +0x"
966+ << Twine::utohexstr (place - sec.content ().data ())
967+ << " ): " << msg;
968968 };
969969 while (!data.empty ()) {
970970 // Read one NOTE record.
@@ -1159,8 +1159,8 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
11591159 sym->isUsedInRegularObj = true ;
11601160 if (LLVM_UNLIKELY (eSym.st_shndx == SHN_COMMON)) {
11611161 if (value == 0 || value >= UINT32_MAX)
1162- fatal ( toString ( this ) + " : common symbol '" + sym->getName () +
1163- " ' has invalid alignment: " + Twine (value) );
1162+ Fatal (ctx) << this << " : common symbol '" << sym->getName ()
1163+ << " ' has invalid alignment: " << Twine (value);
11641164 hasCommonSyms = true ;
11651165 sym->resolve (ctx, CommonSymbol{ctx, this , StringRef (), binding, stOther,
11661166 type, value, size});
@@ -1207,7 +1207,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
12071207 else if (secIdx >= SHN_LORESERVE)
12081208 secIdx = 0 ;
12091209 if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1210- fatal ( toString ( this ) + " : invalid section index: " + Twine (secIdx) );
1210+ Fatal (ctx) << this << " : invalid section index: " << Twine (secIdx);
12111211 if (LLVM_UNLIKELY (eSym.getBinding () != STB_LOCAL))
12121212 error (toString (this ) + " : non-local symbol (" + Twine (i) +
12131213 " ) found at index < .symtab's sh_info (" + Twine (end) + " )" );
@@ -1217,7 +1217,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
12171217 if (type == STT_FILE)
12181218 sourceFile = CHECK (eSym.getName (stringTable), this );
12191219 if (LLVM_UNLIKELY (stringTable.size () <= eSym.st_name ))
1220- fatal ( toString ( this ) + " : invalid symbol name offset" ) ;
1220+ Fatal (ctx) << this << " : invalid symbol name offset" ;
12211221 StringRef name (stringTable.data () + eSym.st_name );
12221222
12231223 symbols[i] = reinterpret_cast <Symbol *>(locals + i);
@@ -1267,7 +1267,7 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
12671267 else if (secIdx >= SHN_LORESERVE)
12681268 secIdx = 0 ;
12691269 if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1270- fatal ( toString ( this ) + " : invalid section index: " + Twine (secIdx) );
1270+ Fatal (ctx) << this << " : invalid section index: " << Twine (secIdx);
12711271 InputSectionBase *sec = sections[secIdx];
12721272 if (sec == &InputSection::discarded) {
12731273 if (sym.traced ) {
@@ -1405,15 +1405,15 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
14051405 const uint8_t *verneedBuf = data.begin ();
14061406 for (unsigned i = 0 ; i != sec->sh_info ; ++i) {
14071407 if (verneedBuf + sizeof (typename ELFT::Verneed) > data.end ())
1408- fatal ( toString ( this ) + " has an invalid Verneed" ) ;
1408+ Fatal (ctx) << this << " has an invalid Verneed" ;
14091409 auto *vn = reinterpret_cast <const typename ELFT::Verneed *>(verneedBuf);
14101410 const uint8_t *vernauxBuf = verneedBuf + vn->vn_aux ;
14111411 for (unsigned j = 0 ; j != vn->vn_cnt ; ++j) {
14121412 if (vernauxBuf + sizeof (typename ELFT::Vernaux) > data.end ())
1413- fatal ( toString ( this ) + " has an invalid Vernaux" ) ;
1413+ Fatal (ctx) << this << " has an invalid Vernaux" ;
14141414 auto *aux = reinterpret_cast <const typename ELFT::Vernaux *>(vernauxBuf);
14151415 if (aux->vna_name >= this ->stringTable .size ())
1416- fatal ( toString ( this ) + " has a Vernaux with an invalid vna_name" ) ;
1416+ Fatal (ctx) << this << " has a Vernaux with an invalid vna_name" ;
14171417 uint16_t version = aux->vna_other & VERSYM_VERSION;
14181418 if (version >= verneeds.size ())
14191419 verneeds.resize (version + 1 );
@@ -1501,12 +1501,12 @@ template <class ELFT> void SharedFile::parse() {
15011501 if (dyn.d_tag == DT_NEEDED) {
15021502 uint64_t val = dyn.getVal ();
15031503 if (val >= this ->stringTable .size ())
1504- fatal ( toString ( this ) + " : invalid DT_NEEDED entry" ) ;
1504+ Fatal (ctx) << this << " : invalid DT_NEEDED entry" ;
15051505 dtNeeded.push_back (this ->stringTable .data () + val);
15061506 } else if (dyn.d_tag == DT_SONAME) {
15071507 uint64_t val = dyn.getVal ();
15081508 if (val >= this ->stringTable .size ())
1509- fatal ( toString ( this ) + " : invalid DT_SONAME entry" ) ;
1509+ Fatal (ctx) << this << " : invalid DT_SONAME entry" ;
15101510 soName = this ->stringTable .data () + val;
15111511 }
15121512 }
0 commit comments