@@ -921,17 +921,18 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
921
921
using Elf_Note = typename ELFT::Note;
922
922
923
923
ArrayRef<uint8_t > data = sec.content ();
924
- auto reportFatal = [&](const uint8_t *place, const Twine &msg) {
925
- Fatal (ctx) << sec.file << " :(" << sec.name << " +0x"
926
- << Twine::utohexstr (place - sec.content ().data ())
927
- << " ): " << msg;
924
+ auto err = [&](const uint8_t *place) -> ELFSyncStream {
925
+ auto diag = Err (ctx);
926
+ diag << sec.file << " :(" << sec.name << " +0x"
927
+ << Twine::utohexstr (place - sec.content ().data ()) << " ): " ;
928
+ return diag;
928
929
};
929
930
while (!data.empty ()) {
930
931
// Read one NOTE record.
931
932
auto *nhdr = reinterpret_cast <const Elf_Nhdr *>(data.data ());
932
933
if (data.size () < sizeof (Elf_Nhdr) ||
933
934
data.size () < nhdr->getSize (sec.addralign ))
934
- reportFatal ( data.data (), " data is too short" );
935
+ return void ( err ( data.data ()) << " data is too short" );
935
936
936
937
Elf_Note note (*nhdr);
937
938
if (nhdr->n_type != NT_GNU_PROPERTY_TYPE_0 || note.getName () != " GNU" ) {
@@ -948,30 +949,32 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
948
949
while (!desc.empty ()) {
949
950
const uint8_t *place = desc.data ();
950
951
if (desc.size () < 8 )
951
- reportFatal ( place, " program property is too short" );
952
+ return void ( err ( place) << " program property is too short" );
952
953
uint32_t type = read32<ELFT::Endianness>(desc.data ());
953
954
uint32_t size = read32<ELFT::Endianness>(desc.data () + 4 );
954
955
desc = desc.slice (8 );
955
956
if (desc.size () < size)
956
- reportFatal ( place, " program property is too short" );
957
+ return void ( err ( place) << " program property is too short" );
957
958
958
959
if (type == featureAndType) {
959
960
// We found a FEATURE_1_AND field. There may be more than one of these
960
961
// in a .note.gnu.property section, for a relocatable object we
961
962
// accumulate the bits set.
962
963
if (size < 4 )
963
- reportFatal ( place, " FEATURE_1_AND entry is too short" );
964
+ return void ( err ( place) << " FEATURE_1_AND entry is too short" );
964
965
f.andFeatures |= read32<ELFT::Endianness>(desc.data ());
965
966
} else if (ctx.arg .emachine == EM_AARCH64 &&
966
967
type == GNU_PROPERTY_AARCH64_FEATURE_PAUTH) {
967
968
if (!f.aarch64PauthAbiCoreInfo .empty ()) {
968
- reportFatal (data.data (),
969
- " multiple GNU_PROPERTY_AARCH64_FEATURE_PAUTH entries are "
970
- " not supported" );
969
+ return void (
970
+ err (data.data ())
971
+ << " multiple GNU_PROPERTY_AARCH64_FEATURE_PAUTH entries are "
972
+ " not supported" );
971
973
} else if (size != 16 ) {
972
- reportFatal (data.data (), " GNU_PROPERTY_AARCH64_FEATURE_PAUTH entry "
973
- " is invalid: expected 16 bytes, but got " +
974
- Twine (size));
974
+ return void (err (data.data ())
975
+ << " GNU_PROPERTY_AARCH64_FEATURE_PAUTH entry "
976
+ " is invalid: expected 16 bytes, but got "
977
+ << size);
975
978
}
976
979
f.aarch64PauthAbiCoreInfo = desc;
977
980
}
@@ -1173,8 +1176,10 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
1173
1176
secIdx = check (getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
1174
1177
else if (secIdx >= SHN_LORESERVE)
1175
1178
secIdx = 0 ;
1176
- if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1177
- Fatal (ctx) << this << " : invalid section index: " << secIdx;
1179
+ if (LLVM_UNLIKELY (secIdx >= sections.size ())) {
1180
+ Err (ctx) << this << " : invalid section index: " << secIdx;
1181
+ secIdx = 0 ;
1182
+ }
1178
1183
if (LLVM_UNLIKELY (eSym.getBinding () != STB_LOCAL))
1179
1184
ErrAlways (ctx) << this << " : non-local symbol (" << i
1180
1185
<< " ) found at index < .symtab's sh_info (" << end << " )" ;
@@ -1183,9 +1188,12 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
1183
1188
uint8_t type = eSym.getType ();
1184
1189
if (type == STT_FILE)
1185
1190
sourceFile = CHECK2 (eSym.getName (stringTable), this );
1186
- if (LLVM_UNLIKELY (stringTable.size () <= eSym.st_name ))
1187
- Fatal (ctx) << this << " : invalid symbol name offset" ;
1188
- StringRef name (stringTable.data () + eSym.st_name );
1191
+ unsigned stName = eSym.st_name ;
1192
+ if (LLVM_UNLIKELY (stringTable.size () <= stName)) {
1193
+ Err (ctx) << this << " : invalid symbol name offset" ;
1194
+ stName = 0 ;
1195
+ }
1196
+ StringRef name (stringTable.data () + stName);
1189
1197
1190
1198
symbols[i] = reinterpret_cast <Symbol *>(locals + i);
1191
1199
if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
@@ -1236,8 +1244,10 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
1236
1244
secIdx = 0 ;
1237
1245
}
1238
1246
1239
- if (LLVM_UNLIKELY (secIdx >= sections.size ()))
1240
- Fatal (ctx) << this << " : invalid section index: " << secIdx;
1247
+ if (LLVM_UNLIKELY (secIdx >= sections.size ())) {
1248
+ Err (ctx) << this << " : invalid section index: " << secIdx;
1249
+ continue ;
1250
+ }
1241
1251
InputSectionBase *sec = sections[secIdx];
1242
1252
if (sec == &InputSection::discarded) {
1243
1253
if (sym.traced ) {
0 commit comments