riscv64: fix objdump related tests
The TestObjdumpRISCV64TestDecodeGNUSyntaxdata and
TestObjdumpRISCV64TestDecodeGoSyntaxdata was failed due to lack of
.riscv.attributes in elf file, this patch adds these extension's
attributes and allow `inst` output mismatch.
Fix: golang/go#70864
Change-Id: I6bcac3e6a3bd0ec3cc66356998914a1aa8d7c468
Reviewed-on: https://go-review.googlesource.com/c/arch/+/636735
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/riscv64/riscv64asm/ext_test.go b/riscv64/riscv64asm/ext_test.go
index fa6961f..25e2bf7 100644
--- a/riscv64/riscv64asm/ext_test.go
+++ b/riscv64/riscv64asm/ext_test.go
@@ -148,6 +148,9 @@
}
suffix += " (allowed mismatch)"
}
+ if strings.Contains(text, "unknown") && strings.Contains(dec.text, ".insn") {
+ return
+ }
totalErrors++
cmp := fmt.Sprintf("decode(%x) = %q, %d, want %q, %d%s\n", enc, text, len(enc), dec.text, dec.nenc, suffix)
diff --git a/riscv64/riscv64asm/gnu.go b/riscv64/riscv64asm/gnu.go
index d6b3dc0..3ee0449 100644
--- a/riscv64/riscv64asm/gnu.go
+++ b/riscv64/riscv64asm/gnu.go
@@ -42,6 +42,11 @@
}
}
+ if inst.Op == ANDI && inst.Args[2].(Simm).Imm == 255 {
+ op = "zext.b"
+ args = args[:len(args)-1]
+ }
+
if inst.Op == ADDIW && inst.Args[2].(Simm).Imm == 0 {
op = "sext.w"
args = args[:len(args)-1]
diff --git a/riscv64/riscv64asm/objdumpext_test.go b/riscv64/riscv64asm/objdumpext_test.go
index 4f1f21a..1dc0964 100644
--- a/riscv64/riscv64asm/objdumpext_test.go
+++ b/riscv64/riscv64asm/objdumpext_test.go
@@ -277,7 +277,7 @@
Type: uint32(0x70000003), // SHT_RISCV_ATTRIBUTES
Addr: 0,
Off: uint64(off2 + (off3-off2)*4 + strtabsize),
- Size: 102,
+ Size: 114,
Addralign: 1,
}
binary.Write(&buf, binary.LittleEndian, §)
@@ -293,7 +293,7 @@
buf.WriteString("\x00.text\x00.riscv.attributes\x00.shstrtab\x00")
// Contents of .riscv.attributes section
// which specify the extension and priv spec version. (1.11)
- buf.WriteString("Ae\x00\x00\x00riscv\x00\x01[\x00\x00\x00\x05rv64i2p1_m2pp_a2p1_f2p2_d2p2_q2p2_zibsr2p0_zifencei2p0_zmmul1p0_zfh1p0_zfhmin1p0\x00\x08\x01\x0a\x0b")
+ buf.WriteString("Aq\x00\x00\x00riscv\x00\x01g\x00\x00\x00\x05rv64i2p0_m2p0_a2p0_f2p0_d2p0_q2p0_c2p0_zmmul1p0_zfh1p0_zfhmin1p0_zba1p0_zbb1p0_zbc1p0_zbs1p0\x00\x08\x01\x0a\x0b")
f.Write(buf.Bytes())
return nil
}