@@ -1188,20 +1188,28 @@ void BitcodeFile::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
1188
1188
Symbols.push_back (createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, *this ));
1189
1189
}
1190
1190
1191
- static ELFKind getELFKind (MemoryBufferRef MB) {
1191
+ static ELFKind getELFKind (MemoryBufferRef MB, StringRef ArchiveName ) {
1192
1192
unsigned char Size ;
1193
1193
unsigned char Endian;
1194
1194
std::tie (Size , Endian) = getElfArchType (MB.getBuffer ());
1195
1195
1196
+ auto Fatal = [&](StringRef Msg) {
1197
+ StringRef Filename = MB.getBufferIdentifier ();
1198
+ if (ArchiveName.empty ())
1199
+ fatal (Filename + " : corrupted ELF file: " + Msg);
1200
+ else
1201
+ fatal (ArchiveName + " (" + Filename + " ): corrupted ELF file: " + Msg);
1202
+ };
1203
+
1196
1204
if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
1197
- fatal (MB. getBufferIdentifier () + " : invalid data encoding" );
1205
+ Fatal ( " invalid data encoding" );
1198
1206
if (Size != ELFCLASS32 && Size != ELFCLASS64)
1199
- fatal (MB. getBufferIdentifier () + " : invalid file class" );
1207
+ Fatal ( " invalid file class" );
1200
1208
1201
1209
size_t BufSize = MB.getBuffer ().size ();
1202
1210
if ((Size == ELFCLASS32 && BufSize < sizeof (Elf32_Ehdr)) ||
1203
1211
(Size == ELFCLASS64 && BufSize < sizeof (Elf64_Ehdr)))
1204
- fatal (MB. getBufferIdentifier () + " : file is too short" );
1212
+ Fatal ( " file is too short" );
1205
1213
1206
1214
if (Size == ELFCLASS32)
1207
1215
return (Endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;
@@ -1236,7 +1244,7 @@ InputFile *elf::createObjectFile(MemoryBufferRef MB, StringRef ArchiveName,
1236
1244
if (isBitcode (MB))
1237
1245
return make<BitcodeFile>(MB, ArchiveName, OffsetInArchive);
1238
1246
1239
- switch (getELFKind (MB)) {
1247
+ switch (getELFKind (MB, ArchiveName )) {
1240
1248
case ELF32LEKind:
1241
1249
return make<ObjFile<ELF32LE>>(MB, ArchiveName);
1242
1250
case ELF32BEKind:
@@ -1251,7 +1259,7 @@ InputFile *elf::createObjectFile(MemoryBufferRef MB, StringRef ArchiveName,
1251
1259
}
1252
1260
1253
1261
InputFile *elf::createSharedFile (MemoryBufferRef MB, StringRef DefaultSoName) {
1254
- switch (getELFKind (MB)) {
1262
+ switch (getELFKind (MB, " " )) {
1255
1263
case ELF32LEKind:
1256
1264
return make<SharedFile<ELF32LE>>(MB, DefaultSoName);
1257
1265
case ELF32BEKind:
@@ -1293,7 +1301,7 @@ template <class ELFT> void LazyObjFile::parse() {
1293
1301
return ;
1294
1302
}
1295
1303
1296
- if (getELFKind (this ->MB ) != Config->EKind ) {
1304
+ if (getELFKind (this ->MB , ArchiveName ) != Config->EKind ) {
1297
1305
error (" incompatible file: " + this ->MB .getBufferIdentifier ());
1298
1306
return ;
1299
1307
}
0 commit comments