@@ -921,17 +921,18 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
921921 using Elf_Note = typename ELFT::Note;
922922
923923 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;
928929 };
929930 while (!data.empty ()) {
930931 // Read one NOTE record.
931932 auto *nhdr = reinterpret_cast <const Elf_Nhdr *>(data.data ());
932933 if (data.size () < sizeof (Elf_Nhdr) ||
933934 data.size () < nhdr->getSize (sec.addralign ))
934- reportFatal ( data.data (), " data is too short" );
935+ return void ( err ( data.data ()) << " data is too short" );
935936
936937 Elf_Note note (*nhdr);
937938 if (nhdr->n_type != NT_GNU_PROPERTY_TYPE_0 || note.getName () != " GNU" ) {
@@ -948,30 +949,32 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
948949 while (!desc.empty ()) {
949950 const uint8_t *place = desc.data ();
950951 if (desc.size () < 8 )
951- reportFatal ( place, " program property is too short" );
952+ return void ( err ( place) << " program property is too short" );
952953 uint32_t type = read32<ELFT::Endianness>(desc.data ());
953954 uint32_t size = read32<ELFT::Endianness>(desc.data () + 4 );
954955 desc = desc.slice (8 );
955956 if (desc.size () < size)
956- reportFatal ( place, " program property is too short" );
957+ return void ( err ( place) << " program property is too short" );
957958
958959 if (type == featureAndType) {
959960 // We found a FEATURE_1_AND field. There may be more than one of these
960961 // in a .note.gnu.property section, for a relocatable object we
961962 // accumulate the bits set.
962963 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" );
964965 f.andFeatures |= read32<ELFT::Endianness>(desc.data ());
965966 } else if (ctx.arg .emachine == EM_AARCH64 &&
966967 type == GNU_PROPERTY_AARCH64_FEATURE_PAUTH) {
967968 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" );
971973 } 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);
975978 }
976979 f.aarch64PauthAbiCoreInfo = desc;
977980 }
@@ -1173,8 +1176,10 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
11731176 secIdx = check (getExtendedSymbolTableIndex<ELFT>(eSym, i, shndxTable));
11741177 else if (secIdx >= SHN_LORESERVE)
11751178 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+ }
11781183 if (LLVM_UNLIKELY (eSym.getBinding () != STB_LOCAL))
11791184 ErrAlways (ctx) << this << " : non-local symbol (" << i
11801185 << " ) found at index < .symtab's sh_info (" << end << " )" ;
@@ -1183,9 +1188,12 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
11831188 uint8_t type = eSym.getType ();
11841189 if (type == STT_FILE)
11851190 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);
11891197
11901198 symbols[i] = reinterpret_cast <Symbol *>(locals + i);
11911199 if (eSym.st_shndx == SHN_UNDEF || sec == &InputSection::discarded)
@@ -1236,8 +1244,10 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
12361244 secIdx = 0 ;
12371245 }
12381246
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+ }
12411251 InputSectionBase *sec = sections[secIdx];
12421252 if (sec == &InputSection::discarded) {
12431253 if (sym.traced ) {
0 commit comments