Skip to content

Commit

Permalink
cmd/objdump: add s390x GNU disasm support
Browse files Browse the repository at this point in the history
This CL provides vendor support for s390x disassembler gnu syntax.
go get golang.org/x/arch@master
go mod tidy
go mod vendor

For #15255

Change-Id: Ia75fa515e7ea7d56913a28147c65650a7ab3062c
Reviewed-on: https://go-review.googlesource.com/c/go/+/581015
Reviewed-by: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Vishwanatha HD <[email protected]>
Run-TryBot: Cherry Mui <[email protected]>
Auto-Submit: Cherry Mui <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Bill O'Farrell <[email protected]>
  • Loading branch information
srinivas-pokala authored and gopherbot committed Aug 21, 2024
1 parent a96e736 commit 0d56058
Show file tree
Hide file tree
Showing 11 changed files with 6,836 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24

require (
github.com/google/pprof v0.0.0-20240722153945-304e4f0156b8
golang.org/x/arch v0.8.1-0.20240716161256-b863392466ea
golang.org/x/arch v0.9.1-0.20240807172201-9d90945922a7
golang.org/x/build v0.0.0-20240722200705-b9910f320300
golang.org/x/mod v0.20.0
golang.org/x/sync v0.8.0
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 h1:KwWnWVW
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68=
github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/arch v0.8.1-0.20240716161256-b863392466ea h1:+dKVGZM+cuxx3fooVKLDxZIPzKR1HYO1Xkd12Je4Z9k=
golang.org/x/arch v0.8.1-0.20240716161256-b863392466ea/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/arch v0.9.1-0.20240807172201-9d90945922a7 h1:4+03DsxQb03qtr7e32FA8tiq18ytCUClXaXxQBDRGbs=
golang.org/x/arch v0.9.1-0.20240807172201-9d90945922a7/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/build v0.0.0-20240722200705-b9910f320300 h1:2Cqg4LnvfD2ZpG8+6KbyYUkweWhNS3SgfcN/eeVseJ0=
golang.org/x/build v0.0.0-20240722200705-b9910f320300/go.mod h1:YsGhg4JUVUWLzdqU2wCrtpRrOveOql6w56FLDHq/CJ4=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/internal/objfile/disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"golang.org/x/arch/arm/armasm"
"golang.org/x/arch/arm64/arm64asm"
"golang.org/x/arch/ppc64/ppc64asm"
"golang.org/x/arch/s390x/s390xasm"
"golang.org/x/arch/x86/x86asm"
)

Expand Down Expand Up @@ -383,13 +384,31 @@ func disasm_ppc64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.By
return text, size
}

func disasm_s390x(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder, gnuAsm bool) (string, int) {
inst, err := s390xasm.Decode(code)
var text string
size := inst.Len
if err != nil || size == 0 || inst.Op == 0 {
size = 2
text = "?"
} else {
if gnuAsm {
text = fmt.Sprintf("%s", s390xasm.GNUSyntax(inst, pc))
} else {
text = fmt.Sprintf("%s", "Go/plan9 syntax unsupported..!!")
}
}
return text, size
}

var disasms = map[string]disasmFunc{
"386": disasm_386,
"amd64": disasm_amd64,
"arm": disasm_arm,
"arm64": disasm_arm64,
"ppc64": disasm_ppc64,
"ppc64le": disasm_ppc64,
"s390x": disasm_s390x,
}

var byteOrders = map[string]binary.ByteOrder{
Expand Down
10 changes: 8 additions & 2 deletions src/cmd/objdump/objdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ var ppcGnuNeed = []string{
"beq",
}

var s390xGnuNeed = []string{
"brasl",
"j",
"clije",
}

func mustHaveDisasm(t *testing.T) {
switch runtime.GOARCH {
case "loong64":
Expand All @@ -112,8 +118,6 @@ func mustHaveDisasm(t *testing.T) {
t.Skipf("skipping on %s, issue 12559", runtime.GOARCH)
case "riscv64":
t.Skipf("skipping on %s, issue 36738", runtime.GOARCH)
case "s390x":
t.Skipf("skipping on %s, issue 15255", runtime.GOARCH)
}
}

Expand Down Expand Up @@ -202,6 +206,8 @@ func testDisasm(t *testing.T, srcfname string, printCode bool, printGnuAsm bool,
need = append(need, armGnuNeed...)
case "ppc64", "ppc64le":
need = append(need, ppcGnuNeed...)
case "s390x":
need = append(need, s390xGnuNeed...)
}
}
args = []string{
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/vendor/golang.org/x/arch/s390x/s390xasm/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

241 changes: 241 additions & 0 deletions src/cmd/vendor/golang.org/x/arch/s390x/s390xasm/decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d56058

Please sign in to comment.