From: Ruinan Date: Thu, 30 Nov 2023 07:54:06 +0000 (+0800) Subject: cmd/asm: print absolute PC for all patterns "off(PC)" in testEndToEnd X-Git-Tag: go1.22rc1~68 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b11d19e03b57d6cec1142002a22c3df732118847;p=gostls13.git cmd/asm: print absolute PC for all patterns "off(PC)" in testEndToEnd Before this CL, testEndToEnd only turns the relative PC to absolute PC when pattern "off(PC)" is the suffix of an instruction. But there are some instructions like: ADR 10(PC), R10 it's also acceptable for the assembler while the pattern "off(PC)" is not a suffix, which makes the test fail. This CL fixes this issue by searching the pattern in the whole string instead of only in the suffix. Change-Id: I0cffedeb7b3c63abca7697671088cf993aff71ff Reviewed-on: https://go-review.googlesource.com/c/go/+/547235 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Ruinan Sun Reviewed-by: Carlos Amedee --- diff --git a/src/cmd/asm/internal/asm/endtoend_test.go b/src/cmd/asm/internal/asm/endtoend_test.go index 592d7b4b76..6e1aa1cd95 100644 --- a/src/cmd/asm/internal/asm/endtoend_test.go +++ b/src/cmd/asm/internal/asm/endtoend_test.go @@ -141,11 +141,17 @@ Diff: // Turn relative (PC) into absolute (PC) automatically, // so that most branch instructions don't need comments // giving the absolute form. - if len(f) > 0 && strings.HasSuffix(printed, "(PC)") { - last := f[len(f)-1] - n, err := strconv.Atoi(last[:len(last)-len("(PC)")]) + if len(f) > 0 && strings.Contains(printed, "(PC)") { + index := len(f) - 1 + suf := "(PC)" + for !strings.HasSuffix(f[index], suf) { + index-- + suf = "(PC)," + } + str := f[index] + n, err := strconv.Atoi(str[:len(str)-len(suf)]) if err == nil { - f[len(f)-1] = fmt.Sprintf("%d(PC)", seq+n) + f[index] = fmt.Sprintf("%d%s", seq+n, suf) } } diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index 46ea6645af..12b4e3255e 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -981,6 +981,14 @@ again: ADR next, R11 // ADR R11 // 2b000010 next: NOP + ADR -2(PC), R10 // 0a000010 + ADR 2(PC), R16 // 10000010 + ADR -26(PC), R1 // 01000010 + ADR 12(PC), R2 // 02000010 + ADRP -2(PC), R10 // 0a000090 + ADRP 2(PC), R16 // 10000090 + ADRP -26(PC), R1 // 01000090 + ADRP 12(PC), R2 // 02000090 // LDP/STP LDP (R0), (R0, R1) // 000440a9