@@ -1260,25 +1260,6 @@ SyntheticSection *EhInputSection::getParent() const {
1260
1260
return cast_or_null<SyntheticSection>(parent);
1261
1261
}
1262
1262
1263
- // Returns the index of the first relocation that points to a region between
1264
- // Begin and Begin+Size.
1265
- template <class IntTy , class RelTy >
1266
- static unsigned getReloc (IntTy begin, IntTy size, const ArrayRef<RelTy> &rels,
1267
- unsigned &relocI) {
1268
- // Start search from RelocI for fast access. That works because the
1269
- // relocations are sorted in .eh_frame.
1270
- for (unsigned n = rels.size (); relocI < n; ++relocI) {
1271
- const RelTy &rel = rels[relocI];
1272
- if (rel.r_offset < begin)
1273
- continue ;
1274
-
1275
- if (rel.r_offset < begin + size)
1276
- return relocI;
1277
- return -1 ;
1278
- }
1279
- return -1 ;
1280
- }
1281
-
1282
1263
// .eh_frame is a sequence of CIE or FDE records.
1283
1264
// This function splits an input section into records and returns them.
1284
1265
template <class ELFT > void EhInputSection::split () {
@@ -1308,20 +1289,25 @@ void EhInputSection::split(ArrayRef<RelTy> rels) {
1308
1289
if (size == 0 ) // ZERO terminator
1309
1290
break ;
1310
1291
uint32_t id = endian::read32<ELFT::TargetEndianness>(d.data () + 4 );
1311
- // If it is 0xFFFFFFFF, the next 8 bytes contain the size instead,
1312
- // but we do not support that format yet.
1313
- if (size == UINT32_MAX) {
1314
- msg = " CIE/FDE too large" ;
1315
- break ;
1316
- }
1317
1292
size += 4 ;
1318
- if (size > d.size ()) {
1319
- msg = " CIE/FDE ends past the end of the section" ;
1293
+ if (LLVM_UNLIKELY (size > d.size ())) {
1294
+ // If it is 0xFFFFFFFF, the next 8 bytes contain the size instead,
1295
+ // but we do not support that format yet.
1296
+ msg = size == UINT32_MAX + uint64_t (4 )
1297
+ ? " CIE/FDE too large"
1298
+ : " CIE/FDE ends past the end of the section" ;
1320
1299
break ;
1321
1300
}
1322
1301
1323
- uint64_t off = d.data () - rawData.data ();
1324
- (id == 0 ? cies : fdes).emplace_back (off, this , size, getReloc (off, size, rels, relI));
1302
+ // Find the first relocation that points to [off,off+size). Relocations
1303
+ // have been sorted by r_offset.
1304
+ const uint64_t off = d.data () - rawData.data ();
1305
+ while (relI != rels.size () && rels[relI].r_offset < off)
1306
+ ++relI;
1307
+ unsigned firstRel = -1 ;
1308
+ if (relI != rels.size () && rels[relI].r_offset < off + size)
1309
+ firstRel = relI;
1310
+ (id == 0 ? cies : fdes).emplace_back (off, this , size, firstRel);
1325
1311
d = d.slice (size);
1326
1312
}
1327
1313
if (msg)
0 commit comments