@@ -2261,7 +2261,7 @@ func (d *dwctxt) writedebugaddr(unit *sym.CompilationUnit, debugaddr loader.Sym)
2261
2261
fnSym := loader .Sym (s )
2262
2262
// NB: this looks at SDWARFFCN; it will need to also look
2263
2263
// at range and loc when they get there.
2264
- infosym , _ , rangessym , _ := d .ldr .GetFuncDwarfAuxSyms (fnSym )
2264
+ infosym , locsym , rangessym , _ := d .ldr .GetFuncDwarfAuxSyms (fnSym )
2265
2265
2266
2266
// Walk the relocations of the various DWARF symbols to
2267
2267
// collect relocations corresponding to indirect function
@@ -2271,6 +2271,9 @@ func (d *dwctxt) writedebugaddr(unit *sym.CompilationUnit, debugaddr loader.Sym)
2271
2271
if rangessym != 0 {
2272
2272
dsyms = append (dsyms , rangessym )
2273
2273
}
2274
+ if locsym != 0 {
2275
+ dsyms = append (dsyms , locsym )
2276
+ }
2274
2277
for _ , dsym := range dsyms {
2275
2278
drelocs := d .ldr .Relocs (dsym )
2276
2279
for ri := 0 ; ri < drelocs .Count (); ri ++ {
@@ -2327,13 +2330,14 @@ func (d *dwctxt) dwarfGenerateDebugSyms() {
2327
2330
2328
2331
// Create the section symbols.
2329
2332
frameSym := mkSecSym (".debug_frame" )
2330
- locSym := mkSecSym (".debug_loc" )
2331
2333
lineSym := mkSecSym (".debug_line" )
2332
- var rangesSym loader.Sym
2334
+ var rangesSym , locSym loader.Sym
2333
2335
if buildcfg .Experiment .Dwarf5 {
2334
2336
rangesSym = mkSecSym (".debug_rnglists" )
2337
+ locSym = mkSecSym (".debug_loclists" )
2335
2338
} else {
2336
2339
rangesSym = mkSecSym (".debug_ranges" )
2340
+ locSym = mkSecSym (".debug_loc" )
2337
2341
}
2338
2342
infoSym := mkSecSym (".debug_info" )
2339
2343
var addrSym loader.Sym
@@ -2343,17 +2347,19 @@ func (d *dwctxt) dwarfGenerateDebugSyms() {
2343
2347
2344
2348
// Create the section objects
2345
2349
lineSec := dwarfSecInfo {syms : []loader.Sym {lineSym }}
2346
- locSec := dwarfSecInfo {syms : []loader.Sym {locSym }}
2347
2350
frameSec := dwarfSecInfo {syms : []loader.Sym {frameSym }}
2348
2351
infoSec := dwarfSecInfo {syms : []loader.Sym {infoSym }}
2349
- var addrSec , rangesSec dwarfSecInfo
2352
+ var addrSec , rangesSec , locSec dwarfSecInfo
2350
2353
if buildcfg .Experiment .Dwarf5 {
2351
2354
addrHdr := d .writeDebugAddrHdr ()
2352
2355
addrSec .syms = []loader.Sym {addrSym , addrHdr }
2353
2356
rnglistsHdr := d .writeDebugRngListsHdr ()
2354
2357
rangesSec .syms = []loader.Sym {rangesSym , rnglistsHdr }
2358
+ loclistsHdr := d .writeDebugLocListsHdr ()
2359
+ locSec .syms = []loader.Sym {locSym , loclistsHdr }
2355
2360
} else {
2356
2361
rangesSec = dwarfSecInfo {syms : []loader.Sym {rangesSym }}
2362
+ locSec = dwarfSecInfo {syms : []loader.Sym {locSym }}
2357
2363
}
2358
2364
2359
2365
// Create any new symbols that will be needed during the
@@ -2423,17 +2429,22 @@ func (d *dwctxt) dwarfGenerateDebugSyms() {
2423
2429
if buildcfg .Experiment .Dwarf5 {
2424
2430
// Compute total size of the DWARF5-specific .debug_* syms in
2425
2431
// each compilation unit.
2426
- var rltot , addrtot uint64
2432
+ var rltot , addrtot , loctot uint64
2427
2433
for i := 0 ; i < ncu ; i ++ {
2428
2434
addrtot += uint64 (d .ldr .SymSize (unitSyms [i ].addrsym ))
2429
2435
rs := unitSyms [i ].rangessyms
2430
2436
for _ , s := range rs {
2431
2437
rltot += uint64 (d .ldr .SymSize (s ))
2432
2438
}
2439
+ loc := unitSyms [i ].locsyms
2440
+ for _ , s := range loc {
2441
+ loctot += uint64 (d .ldr .SymSize (s ))
2442
+ }
2433
2443
}
2434
2444
// Call a helper to patch the length field in the headers.
2435
2445
patchHdr (& addrSec , addrtot )
2436
2446
patchHdr (& rangesSec , rltot )
2447
+ patchHdr (& locSec , loctot )
2437
2448
}
2438
2449
2439
2450
// Stitch together the results.
@@ -2505,9 +2516,9 @@ func dwarfaddshstrings(ctxt *Link, add func(string)) {
2505
2516
2506
2517
secs := []string {"abbrev" , "frame" , "info" , "loc" , "line" , "gdb_scripts" }
2507
2518
if buildcfg .Experiment .Dwarf5 {
2508
- secs = append (secs , "addr" , "rnglists" )
2519
+ secs = append (secs , "addr" , "rnglists" , "loclists" )
2509
2520
} else {
2510
- secs = append (secs , "ranges" )
2521
+ secs = append (secs , "ranges" , "loc" )
2511
2522
}
2512
2523
2513
2524
for _ , sec := range secs {
@@ -2667,30 +2678,33 @@ func addDwsectCUSize(sname string, pkgname string, size uint64) {
2667
2678
dwsectCUSize [sname + "." + pkgname ] += size
2668
2679
}
2669
2680
2670
- // writeDebugAddrHdr creates a new symbol and writes the content
2671
- // for the .debug_rnglists header payload to it, then returns the new sym.
2672
- // Format of the header is described in DWARF5 spec section 7.28.
2673
- func (d * dwctxt ) writeDebugRngListsHdr () loader.Sym {
2681
+ // writeDebugMiscSecHdr writes a header section for the new new DWARF5
2682
+ // sections ".debug_addr", ".debug_loclists", and ".debug_rnglists".
2683
+ // A description of the format/layout of these headers can be found in
2684
+ // the DWARF5 spec in sections 7.27 (.debug_addr), 7.28
2685
+ // (.debug_rnglists) and 7.29 (.debug_loclists).
2686
+ func (d * dwctxt ) writeDebugMiscSecHdr (st sym.SymKind , addOffsetEntryCount bool ) loader.Sym {
2674
2687
su := d .ldr .MakeSymbolUpdater (d .ldr .CreateExtSym ("" , 0 ))
2675
- su .SetType (sym . SDWARFRANGE )
2688
+ su .SetType (st )
2676
2689
su .SetReachable (true )
2677
2690
d .createUnitLength (su , 0 ) // will be filled in later.
2678
2691
su .AddUint16 (d .arch , 5 ) // dwarf version (appendix F)
2679
2692
su .AddUint8 (uint8 (d .arch .PtrSize )) // address_size
2680
- su .AddUint8 (0 )
2693
+ su .AddUint8 (0 ) // segment selector
2694
+ if addOffsetEntryCount {
2695
+ su .AddUint32 (d .arch , 0 ) // offset entry count (required but unused)
2696
+ }
2681
2697
return su .Sym ()
2682
2698
}
2683
2699
2684
- // writeDebugAddrHdr creates a new symbol and writes the content
2685
- // for the .debug_addr header payload to it, then returns the new sym.
2686
- // Format of the header is described in DWARF5 spec section 7.27.
2700
+ func (d * dwctxt ) writeDebugRngListsHdr () loader.Sym {
2701
+ return d .writeDebugMiscSecHdr (sym .SDWARFRANGE , true )
2702
+ }
2703
+
2704
+ func (d * dwctxt ) writeDebugLocListsHdr () loader.Sym {
2705
+ return d .writeDebugMiscSecHdr (sym .SDWARFLOC , true )
2706
+ }
2707
+
2687
2708
func (d * dwctxt ) writeDebugAddrHdr () loader.Sym {
2688
- su := d .ldr .MakeSymbolUpdater (d .ldr .CreateExtSym ("" , 0 ))
2689
- su .SetType (sym .SDWARFADDR )
2690
- su .SetReachable (true )
2691
- d .createUnitLength (su , 0 ) // will be filled in later.
2692
- su .AddUint16 (d .arch , 5 ) // dwarf version (appendix F)
2693
- su .AddUint8 (uint8 (d .arch .PtrSize )) // address_size
2694
- su .AddUint8 (0 )
2695
- return su .Sym ()
2709
+ return d .writeDebugMiscSecHdr (sym .SDWARFADDR , false )
2696
2710
}
0 commit comments