Skip to content

Commit ed2fce2

Browse files
Clément Chigotianlancetaylor
Clément Chigot
authored andcommitted
cmd/link: support dwarf64 when writing .debug_frame
Fixes #28558 Change-Id: I0ecd9c47fb017cf4bd44725a83a0016c7bb94633 Reviewed-on: https://go-review.googlesource.com/c/go/+/156478 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 53d859b commit ed2fce2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/cmd/link/internal/ld/dwarf.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,13 +1391,22 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
13911391
fs.Type = sym.SDWARFSECT
13921392
syms = append(syms, fs)
13931393

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+
13941400
// Emit the CIE, Section 6.4.1
13951401
cieReserve := uint32(16)
13961402
if haslinkregister(ctxt) {
13971403
cieReserve = 32
13981404
}
1405+
if isDwarf64(ctxt) {
1406+
cieReserve += 4 // 4 bytes added for cid
1407+
}
13991408
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
14011410
fs.AddUint8(3) // dwarf version (appendix F)
14021411
fs.AddUint8(0) // augmentation ""
14031412
dwarf.Uleb128put(dwarfctxt, fs, 1) // code_alignment_factor
@@ -1423,8 +1432,7 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
14231432
dwarf.Uleb128put(dwarfctxt, fs, int64(-ctxt.Arch.PtrSize)/dataAlignmentFactor) // ...is saved at [CFA - (PtrSize/4)].
14241433
}
14251434

1426-
// 4 is to exclude the length field.
1427-
pad := int64(cieReserve) + 4 - fs.Size
1435+
pad := int64(cieReserve) + lengthFieldSize - fs.Size
14281436

14291437
if pad < 0 {
14301438
Exitf("dwarf: cieReserve too small by %d bytes.", -pad)
@@ -1480,10 +1488,16 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
14801488

14811489
// Emit the FDE header, Section 6.4.1.
14821490
// 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
14841492
// ptrsize: initial location
14851493
// 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+
14871501
if ctxt.LinkMode == LinkExternal {
14881502
addDwarfAddrRef(ctxt, fs, fs)
14891503
} else {

0 commit comments

Comments
 (0)