Skip to content

Commit

Permalink
riscv64: fix objdump related tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Meng Zhuo <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
lrzlin authored and mengzhuo committed Dec 18, 2024
1 parent f23035d commit 5f2ba6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions riscv64/riscv64asm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func testExtDis(
}
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)

Expand Down
5 changes: 5 additions & 0 deletions riscv64/riscv64asm/gnu.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func GNUSyntax(inst Inst) string {
}
}

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]
Expand Down
4 changes: 2 additions & 2 deletions riscv64/riscv64asm/objdumpext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func writeELF64(f *os.File, size int) error {
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, &sect)
Expand All @@ -293,7 +293,7 @@ func writeELF64(f *os.File, size int) error {
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
}

0 comments on commit 5f2ba6d

Please sign in to comment.