@@ -1391,13 +1391,22 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
1391
1391
fs .Type = sym .SDWARFSECT
1392
1392
syms = append (syms , fs )
1393
1393
1394
+ // Length field is 4 bytes on Dwarf32 and 12 bytes on Dwarf64
1395
+ lengthFieldSize := int64 (4 )
1396
+ if isDwarf64 (ctxt ) {
1397
+ lengthFieldSize += 8
1398
+ }
1399
+
1394
1400
// Emit the CIE, Section 6.4.1
1395
1401
cieReserve := uint32 (16 )
1396
1402
if haslinkregister (ctxt ) {
1397
1403
cieReserve = 32
1398
1404
}
1405
+ if isDwarf64 (ctxt ) {
1406
+ cieReserve += 4 // 4 bytes added for cid
1407
+ }
1399
1408
createUnitLength (ctxt , fs , uint64 (cieReserve )) // initial length, must be multiple of thearch.ptrsize
1400
- addDwarfAddrField (ctxt , fs , 0xffffffff ) // cid.
1409
+ addDwarfAddrField (ctxt , fs , ^ uint64 ( 0 )) // cid
1401
1410
fs .AddUint8 (3 ) // dwarf version (appendix F)
1402
1411
fs .AddUint8 (0 ) // augmentation ""
1403
1412
dwarf .Uleb128put (dwarfctxt , fs , 1 ) // code_alignment_factor
@@ -1423,8 +1432,7 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
1423
1432
dwarf .Uleb128put (dwarfctxt , fs , int64 (- ctxt .Arch .PtrSize )/ dataAlignmentFactor ) // ...is saved at [CFA - (PtrSize/4)].
1424
1433
}
1425
1434
1426
- // 4 is to exclude the length field.
1427
- pad := int64 (cieReserve ) + 4 - fs .Size
1435
+ pad := int64 (cieReserve ) + lengthFieldSize - fs .Size
1428
1436
1429
1437
if pad < 0 {
1430
1438
Exitf ("dwarf: cieReserve too small by %d bytes." , - pad )
@@ -1480,10 +1488,16 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
1480
1488
1481
1489
// Emit the FDE header, Section 6.4.1.
1482
1490
// 4 bytes: length, must be multiple of thearch.ptrsize
1483
- // 4 bytes: Pointer to the CIE above, at offset 0
1491
+ // 4/8 bytes: Pointer to the CIE above, at offset 0
1484
1492
// ptrsize: initial location
1485
1493
// ptrsize: address range
1486
- fs .AddUint32 (ctxt .Arch , uint32 (4 + 2 * ctxt .Arch .PtrSize + len (deltaBuf ))) // length (excludes itself)
1494
+
1495
+ fdeLength := uint64 (4 + 2 * ctxt .Arch .PtrSize + len (deltaBuf ))
1496
+ if isDwarf64 (ctxt ) {
1497
+ fdeLength += 4 // 4 bytes added for CIE pointer
1498
+ }
1499
+ createUnitLength (ctxt , fs , fdeLength )
1500
+
1487
1501
if ctxt .LinkMode == LinkExternal {
1488
1502
addDwarfAddrRef (ctxt , fs , fs )
1489
1503
} else {
0 commit comments