@@ -68,8 +68,7 @@ std::string lld::toString(const InputFile *f) {
68
68
69
69
const ELFSyncStream &elf::operator <<(const ELFSyncStream &s,
70
70
const InputFile *f) {
71
- s << toString (f);
72
- return s;
71
+ return s << toString (f);
73
72
}
74
73
75
74
static ELFKind getELFKind (MemoryBufferRef mb, StringRef archiveName) {
@@ -80,9 +79,9 @@ static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
80
79
auto report = [&](StringRef msg) {
81
80
StringRef filename = mb.getBufferIdentifier ();
82
81
if (archiveName.empty ())
83
- fatal ( filename + " : " + msg) ;
82
+ Fatal (ctx) << filename << " : " << msg;
84
83
else
85
- fatal ( archiveName + " (" + filename + " ): " + msg) ;
84
+ Fatal (ctx) << archiveName << " (" << filename << " ): " << msg;
86
85
};
87
86
88
87
if (!mb.getBuffer ().starts_with (ElfMagic))
@@ -573,7 +572,7 @@ template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
573
572
574
573
ArrayRef<Elf_Sym> eSyms = CHECK (obj.symbols (symtabSec), this );
575
574
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" ;
577
576
578
577
elfSyms = reinterpret_cast <const void *>(eSyms.data ());
579
578
numELFSyms = uint32_t (eSyms.size ());
@@ -666,11 +665,11 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
666
665
ArrayRef<Elf_Word> entries =
667
666
CHECK (obj.template getSectionContentsAsArray <Elf_Word>(sec), this );
668
667
if (entries.empty ())
669
- fatal ( toString ( this ) + " : empty SHT_GROUP" ) ;
668
+ Fatal (ctx) << this << " : empty SHT_GROUP" ;
670
669
671
670
Elf_Word flag = entries[0 ];
672
671
if (flag && flag != GRP_COMDAT)
673
- fatal ( toString ( this ) + " : unsupported SHT_GROUP format" ) ;
672
+ Fatal (ctx) << this << " : unsupported SHT_GROUP format" ;
674
673
675
674
bool keepGroup = (flag & GRP_COMDAT) == 0 || ignoreComdats ||
676
675
ctx.symtab ->comdatGroups
@@ -686,8 +685,8 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
686
685
// Otherwise, discard group members.
687
686
for (uint32_t secIndex : entries.slice (1 )) {
688
687
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);
691
690
this ->sections [secIndex] = &InputSection::discarded;
692
691
}
693
692
}
@@ -704,7 +703,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
704
703
const Elf_Shdr &sec) {
705
704
typename ELFT::SymRange symbols = this ->getELFSyms <ELFT>();
706
705
if (sec.sh_info >= symbols.size ())
707
- fatal ( toString ( this ) + " : invalid symbol index" ) ;
706
+ Fatal (ctx) << this << " : invalid symbol index" ;
708
707
const typename ELFT::Sym &sym = symbols[sec.sh_info ];
709
708
return CHECK (sym.getName (this ->stringTable ), this );
710
709
}
@@ -742,13 +741,13 @@ bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec, StringRef name) {
742
741
if (entSize == 0 )
743
742
return false ;
744
743
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) << " )" ;
748
747
749
748
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" ;
752
751
753
752
return true ;
754
753
}
@@ -934,7 +933,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
934
933
if (sec.sh_link < size)
935
934
linkSec = this ->sections [sec.sh_link ];
936
935
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 );
938
937
939
938
// A SHF_LINK_ORDER section is discarded if its linked-to section is
940
939
// discarded.
@@ -963,8 +962,9 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
963
962
964
963
ArrayRef<uint8_t > data = sec.content ();
965
964
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;
968
968
};
969
969
while (!data.empty ()) {
970
970
// Read one NOTE record.
@@ -1159,8 +1159,8 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
1159
1159
sym->isUsedInRegularObj = true ;
1160
1160
if (LLVM_UNLIKELY (eSym.st_shndx == SHN_COMMON)) {
1161
1161
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);
1164
1164
hasCommonSyms = true ;
1165
1165
sym->resolve (ctx, CommonSymbol{ctx, this , StringRef (), binding, stOther,
1166
1166
type, value, size});
@@ -1207,7 +1207,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
1207
1207
else if (secIdx >= SHN_LORESERVE)
1208
1208
secIdx = 0 ;
1209
1209
if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1210
- fatal ( toString ( this ) + " : invalid section index: " + Twine (secIdx) );
1210
+ Fatal (ctx) << this << " : invalid section index: " << Twine (secIdx);
1211
1211
if (LLVM_UNLIKELY (eSym.getBinding () != STB_LOCAL))
1212
1212
error (toString (this ) + " : non-local symbol (" + Twine (i) +
1213
1213
" ) found at index < .symtab's sh_info (" + Twine (end) + " )" );
@@ -1217,7 +1217,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
1217
1217
if (type == STT_FILE)
1218
1218
sourceFile = CHECK (eSym.getName (stringTable), this );
1219
1219
if (LLVM_UNLIKELY (stringTable.size () <= eSym.st_name ))
1220
- fatal ( toString ( this ) + " : invalid symbol name offset" ) ;
1220
+ Fatal (ctx) << this << " : invalid symbol name offset" ;
1221
1221
StringRef name (stringTable.data () + eSym.st_name );
1222
1222
1223
1223
symbols[i] = reinterpret_cast <Symbol *>(locals + i);
@@ -1267,7 +1267,7 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
1267
1267
else if (secIdx >= SHN_LORESERVE)
1268
1268
secIdx = 0 ;
1269
1269
if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1270
- fatal ( toString ( this ) + " : invalid section index: " + Twine (secIdx) );
1270
+ Fatal (ctx) << this << " : invalid section index: " << Twine (secIdx);
1271
1271
InputSectionBase *sec = sections[secIdx];
1272
1272
if (sec == &InputSection::discarded) {
1273
1273
if (sym.traced ) {
@@ -1405,15 +1405,15 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
1405
1405
const uint8_t *verneedBuf = data.begin ();
1406
1406
for (unsigned i = 0 ; i != sec->sh_info ; ++i) {
1407
1407
if (verneedBuf + sizeof (typename ELFT::Verneed) > data.end ())
1408
- fatal ( toString ( this ) + " has an invalid Verneed" ) ;
1408
+ Fatal (ctx) << this << " has an invalid Verneed" ;
1409
1409
auto *vn = reinterpret_cast <const typename ELFT::Verneed *>(verneedBuf);
1410
1410
const uint8_t *vernauxBuf = verneedBuf + vn->vn_aux ;
1411
1411
for (unsigned j = 0 ; j != vn->vn_cnt ; ++j) {
1412
1412
if (vernauxBuf + sizeof (typename ELFT::Vernaux) > data.end ())
1413
- fatal ( toString ( this ) + " has an invalid Vernaux" ) ;
1413
+ Fatal (ctx) << this << " has an invalid Vernaux" ;
1414
1414
auto *aux = reinterpret_cast <const typename ELFT::Vernaux *>(vernauxBuf);
1415
1415
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" ;
1417
1417
uint16_t version = aux->vna_other & VERSYM_VERSION;
1418
1418
if (version >= verneeds.size ())
1419
1419
verneeds.resize (version + 1 );
@@ -1501,12 +1501,12 @@ template <class ELFT> void SharedFile::parse() {
1501
1501
if (dyn.d_tag == DT_NEEDED) {
1502
1502
uint64_t val = dyn.getVal ();
1503
1503
if (val >= this ->stringTable .size ())
1504
- fatal ( toString ( this ) + " : invalid DT_NEEDED entry" ) ;
1504
+ Fatal (ctx) << this << " : invalid DT_NEEDED entry" ;
1505
1505
dtNeeded.push_back (this ->stringTable .data () + val);
1506
1506
} else if (dyn.d_tag == DT_SONAME) {
1507
1507
uint64_t val = dyn.getVal ();
1508
1508
if (val >= this ->stringTable .size ())
1509
- fatal ( toString ( this ) + " : invalid DT_SONAME entry" ) ;
1509
+ Fatal (ctx) << this << " : invalid DT_SONAME entry" ;
1510
1510
soName = this ->stringTable .data () + val;
1511
1511
}
1512
1512
}
0 commit comments