Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gawen/9c174e8428eb034de4bdefd0d9d776c7 to your computer and use it in GitHub Desktop.
Save gawen/9c174e8428eb034de4bdefd0d9d776c7 to your computer and use it in GitHub Desktop.
add ld option '-alwaysRestoreDWARFLinkRegister[=false}' for go1.13.1
From 0b30d58c6b06dcdb8203f400c1b74ec08392a08f Mon Sep 17 00:00:00 2001
From: Gawen Arab <[email protected]>
Date: Wed, 23 Oct 2019 19:37:41 +0200
Subject: [PATCH] add ld option '-alwaysRestoreDWARFLinkRegister[=false}'
---
src/cmd/link/internal/ld/dwarf.go | 2 +-
src/cmd/link/internal/ld/link.go | 2 ++
src/cmd/link/internal/ld/main.go | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go
index 39c8a7f120..1accfaf15c 100644
--- a/src/cmd/link/internal/ld/dwarf.go
+++ b/src/cmd/link/internal/ld/dwarf.go
@@ -1489,7 +1489,7 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol {
// TODO(bryanpkc): This is imprecise. In general, the instruction
// that stores the return address to the stack frame is not the
// same one that allocates the frame.
- if pcsp.value > 0 {
+ if pcsp.value > 0 || ctxt.alwaysRestoreDWARFLinkRegister {
// The return address is preserved at (CFA-frame_size)
// after a stack frame has been allocated.
deltaBuf = append(deltaBuf, dwarf.DW_CFA_offset_extended_sf)
diff --git a/src/cmd/link/internal/ld/link.go b/src/cmd/link/internal/ld/link.go
index d3ffacf54e..919c425de8 100644
--- a/src/cmd/link/internal/ld/link.go
+++ b/src/cmd/link/internal/ld/link.go
@@ -69,6 +69,8 @@ type Link struct {
BuildMode BuildMode
compressDWARF bool
+ alwaysRestoreDWARFLinkRegister bool
+
Tlsg *sym.Symbol
Libdir []string
Library []*sym.Library
diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go
index 67e5ef9392..0ed4a3adb7 100644
--- a/src/cmd/link/internal/ld/main.go
+++ b/src/cmd/link/internal/ld/main.go
@@ -124,6 +124,7 @@ func Main(arch *sys.Arch, theArch Arch) {
flag.Var(&ctxt.LinkMode, "linkmode", "set link `mode`")
flag.Var(&ctxt.BuildMode, "buildmode", "set build `mode`")
flag.BoolVar(&ctxt.compressDWARF, "compressdwarf", true, "compress DWARF if possible")
+ flag.BoolVar(&ctxt.alwaysRestoreDWARFLinkRegister, "alwaysRestoreDWARFLinkRegister", false, "generate DWARF debug code to always restore the Link Register from the stack trace, ignoring the current value of LR. This makes old stack unwinder be able to not reject DWARF CFI")
objabi.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo)
objabi.Flagfn1("L", "add specified `directory` to library path", func(a string) { Lflag(ctxt, a) })
objabi.AddVersionFlag() // -V
--
2.23.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment