]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld: generate correct .debug_frames on RISC architectures
authorShenghou Ma <minux@golang.org>
Thu, 7 May 2015 04:48:09 +0000 (00:48 -0400)
committerMinux Ma <minux@golang.org>
Fri, 8 May 2015 00:34:27 +0000 (00:34 +0000)
With this patch, gdb seems to be able to corretly backtrace Go
process on at least linux/{arm,arm64,ppc64}.

Change-Id: Ic40a2a70e71a19c4a92e4655710f38a807b67e9a
Reviewed-on: https://go-review.googlesource.com/9822
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
13 files changed:
src/cmd/5l/l.go
src/cmd/5l/obj.go
src/cmd/6l/l.go
src/cmd/6l/obj.go
src/cmd/7l/l.go
src/cmd/7l/obj.go
src/cmd/8l/l.go
src/cmd/8l/obj.go
src/cmd/9l/l.go
src/cmd/9l/obj.go
src/cmd/internal/ld/dwarf.go
src/cmd/internal/ld/lib.go
src/runtime/runtime-gdb_test.go

index a52154594d0c6414003dcccfc16c866393c7e66b..adc8d286ae702501cfbfadb6dde1d70e9fb2a7c7 100644 (file)
@@ -72,7 +72,8 @@ const (
        MINLC     = 4
 )
 
-/* Used by ../ld/dwarf.c */
+/* Used by ../internal/ld/dwarf.go */
 const (
        DWARFREGSP = 13
+       DWARFREGLR = 14
 )
index fa749080055e0d76ee592fa7ba55711a8eb0d75c..e4fffdec6a068bedab79d03bde939f1748863b7e 100644 (file)
@@ -56,6 +56,7 @@ func linkarchinit() {
        ld.Thearch.Maxalign = MaxAlign
        ld.Thearch.Minlc = MINLC
        ld.Thearch.Dwarfregsp = DWARFREGSP
+       ld.Thearch.Dwarfreglr = DWARFREGLR
 
        ld.Thearch.Adddynlib = adddynlib
        ld.Thearch.Adddynrel = adddynrel
index 6b42088de3ccb317f8695f62e112f43cb66bc917..64466d126a45987d117f196b62aa804344c2914a 100644 (file)
@@ -40,7 +40,8 @@ const (
        MINLC = 1
 )
 
-/* Used by ../ld/dwarf.c */
+/* Used by ../internal/ld/dwarf.go */
 const (
        DWARFREGSP = 7
+       DWARFREGLR = 16
 )
index 9e6dc60e2d3b26e0fc4e1793167784e3c89fd557..8ee7bb28dbe93685f2c0ffe6633d6581354f5c4d 100644 (file)
@@ -59,6 +59,7 @@ func linkarchinit() {
        ld.Thearch.Maxalign = MaxAlign
        ld.Thearch.Minlc = MINLC
        ld.Thearch.Dwarfregsp = DWARFREGSP
+       ld.Thearch.Dwarfreglr = DWARFREGLR
 
        ld.Thearch.Adddynlib = adddynlib
        ld.Thearch.Adddynrel = adddynrel
index 6f90acb1076543066b0a1e800150557af6d70091..7227cc430fe43fc9e32d50b57bc3e0672d9e24ee 100644 (file)
@@ -71,7 +71,8 @@ const (
        MINLC     = 4
 )
 
-/* Used by ../ld/dwarf.c */
+/* Used by ../internal/ld/dwarf.go */
 const (
        DWARFREGSP = 31
+       DWARFREGLR = 30
 )
index f8ac7d33ea759a4ddf228f7fc148f09cf0b5bb4f..aeea421bc2120430912935932618f9ef031b3e16 100644 (file)
@@ -56,6 +56,7 @@ func linkarchinit() {
        ld.Thearch.Maxalign = MaxAlign
        ld.Thearch.Minlc = MINLC
        ld.Thearch.Dwarfregsp = DWARFREGSP
+       ld.Thearch.Dwarfreglr = DWARFREGLR
 
        ld.Thearch.Adddynlib = adddynlib
        ld.Thearch.Adddynrel = adddynrel
index 60050857c48c6cb81722e1cb1a3886cf7b87cd73..5cb9f8d8afb6cf6c645a2de6848d5ed224750b21 100644 (file)
@@ -40,7 +40,8 @@ const (
        MINLC     = 1
 )
 
-/* Used by ../ld/dwarf.c */
+/* Used by ../internal/ld/dwarf.go */
 const (
        DWARFREGSP = 4
+       DWARFREGLR = 8
 )
index 7b490ae87c507b9092eb865dab58e507e91267ae..5af3f9249b6eeea050012926f92d6f5df2b42afa 100644 (file)
@@ -56,6 +56,7 @@ func linkarchinit() {
        ld.Thearch.Maxalign = MaxAlign
        ld.Thearch.Minlc = MINLC
        ld.Thearch.Dwarfregsp = DWARFREGSP
+       ld.Thearch.Dwarfreglr = DWARFREGLR
 
        ld.Thearch.Adddynlib = adddynlib
        ld.Thearch.Adddynrel = adddynrel
index e7dc102af23e3173891785bd861907a63bda77f8..8723eaeca449af3160fcb345518ba766a61e2bea 100644 (file)
@@ -71,7 +71,8 @@ const (
        MINLC     = 4
 )
 
-/* Used by ../ld/dwarf.c */
+/* Used by ../internal/ld/dwarf.go */
 const (
        DWARFREGSP = 1
+       DWARFREGLR = 65
 )
index 46a92396e405d3e2442506babf5d10e2e70e9f48..2da37561e96a8df3c74783bc3e224d1eeec95fcb 100644 (file)
@@ -60,6 +60,7 @@ func linkarchinit() {
        ld.Thearch.Maxalign = MaxAlign
        ld.Thearch.Minlc = MINLC
        ld.Thearch.Dwarfregsp = DWARFREGSP
+       ld.Thearch.Dwarfreglr = DWARFREGLR
 
        ld.Thearch.Adddynlib = adddynlib
        ld.Thearch.Adddynrel = adddynrel
index 6d90404b13e07049435d03e6fd36365dd4c896fd..476b329e7a817988b1bc9987f3454f8011550205 100644 (file)
@@ -1692,11 +1692,17 @@ func writelines() {
                        switch a.Name {
                        case obj.A_AUTO:
                                dt = DW_ABRV_AUTO
-                               offs = int64(a.Aoffset) - int64(Thearch.Ptrsize)
+                               offs = int64(a.Aoffset)
+                               if !haslinkregister() {
+                                       offs -= int64(Thearch.Ptrsize)
+                               }
 
                        case obj.A_PARAM:
                                dt = DW_ABRV_PARAM
                                offs = int64(a.Aoffset)
+                               if haslinkregister() {
+                                       offs += int64(Thearch.Ptrsize)
+                               }
 
                        default:
                                continue
@@ -1749,7 +1755,6 @@ func writelines() {
 const (
        CIERESERVE          = 16
        DATAALIGNMENTFACTOR = -4
-       FAKERETURNCOLUMN    = 16 // TODO gdb6 doesn't like > 15?
 )
 
 func putpccfadelta(deltapc int64, cfa int64) {
@@ -1778,21 +1783,30 @@ func writeframes() {
        frameo = Cpos()
 
        // Emit the CIE, Section 6.4.1
-       Thearch.Lput(CIERESERVE)        // initial length, must be multiple of thearch.ptrsize
-       Thearch.Lput(0xffffffff)        // cid.
-       Cput(3)                         // dwarf version (appendix F)
-       Cput(0)                         // augmentation ""
-       uleb128put(1)                   // code_alignment_factor
-       sleb128put(DATAALIGNMENTFACTOR) // guess
-       uleb128put(FAKERETURNCOLUMN)    // return_address_register
+       Thearch.Lput(CIERESERVE)              // initial length, must be multiple of thearch.ptrsize
+       Thearch.Lput(0xffffffff)              // cid.
+       Cput(3)                               // dwarf version (appendix F)
+       Cput(0)                               // augmentation ""
+       uleb128put(1)                         // code_alignment_factor
+       sleb128put(DATAALIGNMENTFACTOR)       // guess
+       uleb128put(int64(Thearch.Dwarfreglr)) // return_address_register
 
        Cput(DW_CFA_def_cfa)
 
        uleb128put(int64(Thearch.Dwarfregsp)) // register SP (**ABI-dependent, defined in l.h)
-       uleb128put(int64(Thearch.Ptrsize))    // offset
+       if haslinkregister() {
+               uleb128put(int64(0)) // offset
+       } else {
+               uleb128put(int64(Thearch.Ptrsize)) // offset
+       }
 
-       Cput(DW_CFA_offset + FAKERETURNCOLUMN)                    // return address
-       uleb128put(int64(-Thearch.Ptrsize) / DATAALIGNMENTFACTOR) // at cfa - x*4
+       Cput(DW_CFA_offset_extended)
+       uleb128put(int64(Thearch.Dwarfreglr)) // return address
+       if haslinkregister() {
+               uleb128put(int64(0) / DATAALIGNMENTFACTOR) // at cfa - 0
+       } else {
+               uleb128put(int64(-Thearch.Ptrsize) / DATAALIGNMENTFACTOR) // at cfa - x*4
+       }
 
        // 4 is to exclude the length field.
        pad := CIERESERVE + frameo + 4 - Cpos()
@@ -1834,7 +1848,11 @@ func writeframes() {
                                }
                        }
 
-                       putpccfadelta(int64(nextpc)-int64(pcsp.pc), int64(Thearch.Ptrsize)+int64(pcsp.value))
+                       if haslinkregister() {
+                               putpccfadelta(int64(nextpc)-int64(pcsp.pc), int64(pcsp.value))
+                       } else {
+                               putpccfadelta(int64(nextpc)-int64(pcsp.pc), int64(Thearch.Ptrsize)+int64(pcsp.value))
+                       }
                }
 
                fdesize = Cpos() - fdeo - 4 // exclude the length field.
index 184175e02648c4c5c3713d9b82fda20f0bb2f417..edafaebb0ba961785ce26f8f265c294658ea16cf 100644 (file)
@@ -86,6 +86,7 @@ type Arch struct {
        Maxalign         int
        Minlc            int
        Dwarfregsp       int
+       Dwarfreglr       int
        Linuxdynld       string
        Freebsddynld     string
        Netbsddynld      string
index fe7d38a39c792679df2cf4b6681130404a50f249..8d04f6328c6a8f73b6b34b337a664f901d1e1e96 100644 (file)
@@ -85,7 +85,7 @@ func TestGdbPython(t *testing.T) {
        // stack frames on RISC architectures.
        canBackTrace := false
        switch runtime.GOARCH {
-       case "amd64", "386":
+       case "amd64", "386", "ppc64", "ppc64le", "arm", "arm64":
                canBackTrace = true
                args = append(args,
                        "-ex", "echo BEGIN goroutine 2 bt\n",