@@ -1323,25 +1323,47 @@ static unsigned getReloc(IntTy begin, IntTy size, const ArrayRef<RelTy> &rels,
1323
1323
// This function splits an input section into records and returns them.
1324
1324
template <class ELFT > void EhInputSection::split () {
1325
1325
const RelsOrRelas<ELFT> rels = relsOrRelas<ELFT>();
1326
- if (rels.areRelocsRel ())
1327
- split<ELFT>(rels.rels );
1328
- else
1329
- split<ELFT>(rels.relas );
1326
+ // getReloc expects the relocations to be sorted by r_offset. See the comment
1327
+ // in scanRelocs.
1328
+ if (rels.areRelocsRel ()) {
1329
+ SmallVector<typename ELFT::Rel, 0 > storage;
1330
+ split<ELFT>(sortRels (rels.rels , storage));
1331
+ } else {
1332
+ SmallVector<typename ELFT::Rela, 0 > storage;
1333
+ split<ELFT>(sortRels (rels.relas , storage));
1334
+ }
1330
1335
}
1331
1336
1332
1337
template <class ELFT , class RelTy >
1333
1338
void EhInputSection::split (ArrayRef<RelTy> rels) {
1334
- // getReloc expects the relocations to be sorted by r_offset. See the comment
1335
- // in scanRelocs.
1336
- SmallVector<RelTy, 0 > storage;
1337
- rels = sortRels (rels, storage);
1338
-
1339
+ ArrayRef<uint8_t > d = rawData;
1340
+ const char *msg = nullptr ;
1339
1341
unsigned relI = 0 ;
1340
- for (size_t off = 0 , end = data ().size (); off != end;) {
1341
- size_t size = readEhRecordSize (this , off);
1342
+ while (!d.empty ()) {
1343
+ if (d.size () < 4 ) {
1344
+ msg = " CIE/FDE too small" ;
1345
+ break ;
1346
+ }
1347
+ uint64_t size = endian::read32<ELFT::TargetEndianness>(d.data ());
1348
+ // If it is 0xFFFFFFFF, the next 8 bytes contain the size instead,
1349
+ // but we do not support that format yet.
1350
+ if (size == UINT32_MAX) {
1351
+ msg = " CIE/FDE too large" ;
1352
+ break ;
1353
+ }
1354
+ size += 4 ;
1355
+ if (size > d.size ()) {
1356
+ msg = " CIE/FDE ends past the end of the section" ;
1357
+ break ;
1358
+ }
1359
+
1360
+ uint64_t off = d.data () - rawData.data ();
1342
1361
pieces.emplace_back (off, this , size, getReloc (off, size, rels, relI));
1343
- off += size;
1362
+ d = d. slice ( size) ;
1344
1363
}
1364
+ if (msg)
1365
+ errorOrWarn (" corrupted .eh_frame: " + Twine (msg) + " \n >>> defined in " +
1366
+ getObjMsg (d.data () - rawData.data ()));
1345
1367
}
1346
1368
1347
1369
static size_t findNull (StringRef s, size_t entSize) {
0 commit comments