Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/internal/disasm: RISCV64C disassembly support #71102

Open
Jorropo opened this issue Jan 3, 2025 · 4 comments
Open

cmd/internal/disasm: RISCV64C disassembly support #71102

Jorropo opened this issue Jan 3, 2025 · 4 comments
Labels
arch-riscv Issues solely affecting the riscv64 architecture. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@Jorropo
Copy link
Member

Jorropo commented Jan 3, 2025

I am working on #47560 https://go-review.googlesource.com/c/go/+/639656/1 and I notice that go tool objdump seems to not be able to disassemble my instructions properly.

First function of a random binary:

--- /tmp/old	2025-01-03 06:36:17.640800526 +0100
+++ /tmp/new	2025-01-03 06:36:26.500944550 +0100
@@ -2,20 +2,20 @@
   type.go:140           0x11000                 010db303                MOV 16(X27), X6                                 
   type.go:140           0x11004                 00236a63                BLTU X6, X2, 5(PC)                              
   type.go:140           0x11008                 00a10423                MOVB X10, 8(X2)                                 
-  type.go:140           0x1100c                 1b45d2ef                JAL X5, runtime.morestack_noctxt.abi0(SB)       
+  type.go:140           0x1100c                 17c592ef                JAL X5, runtime.morestack_noctxt.abi0(SB)       
   type.go:140           0x11010                 00814503                MOVBU 8(X2), X10                                
   type.go:140           0x11014                 fedff06f                JMP internal/abi.Kind.String(SB)                
   type.go:140           0x11018                 fe113423                MOV X1, -24(X2)                                 
   type.go:140           0x1101c                 fe810113                ADDI $-24, X2, X2                               
   type.go:140           0x11020                 00113023                MOV X1, (X2)                                    
-  type.go:141           0x11024                 000f0397                AUIPC $240, X7                                  
+  type.go:141           0x11024                 000e0397                AUIPC $224, X7                                  
   type.go:141           0x11028                 dfc3b383                MOV -516(X7), X7                                
   type.go:141           0x1102c                 0ff57413                MOVBU X10, X8                                   
-  type.go:141           0x11030                 000f0497                AUIPC $240, X9                                  
+  type.go:141           0x11030                 000e0497                AUIPC $224, X9                                  
   type.go:141           0x11034                 df84b483                MOV -520(X9), X9                                
   type.go:141           0x11038                 02944063                BLT X8, X9, 8(PC)                               
   type.go:144           0x1103c                 00000293                MOV X0, X5                                      
-  type.go:144           0x11040                 0292fc63                BGEU X5, X9, 14(PC)                             
+  type.go:144           0x11040                 0292fb63                BGEU X5, X9, 13(PC)                             
   type.go:144           0x11044                 0003b503                MOV (X7), X10                                   
   type.go:144           0x11048                 0083b583                MOV 8(X7), X11                                  
   type.go:144           0x1104c                 00013083                MOV (X2), X1                                    
@@ -23,12 +23,11 @@
   type.go:144           0x11054                 00008067                RET                                             
   type.go:142           0x11058                 03851293                SLLI $56, X10, X5                               
   type.go:142           0x1105c                 0342d293                SRLI $52, X5, X5                                
-  type.go:142           0x11060                 005382b3                ADD X5, X7, X5      
+  type.go:142           0x11060                 b503929e                ADD X7, X5, X5                             
-  type.go:142           0x11064                 0002b503                MOV (X5), X10                                   
-  type.go:142           0x11068                 0082b583                MOV 8(X5), X11                                  
-  type.go:142           0x1106c                 00013083                MOV (X2), X1                                    
-  type.go:142           0x11070                 01810113                ADDI $24, X2, X2                                
-  type.go:142           0x11074                 00008067                RET                                             
-  type.go:144           0x11078                 00028313                MOV X5, X6                                      
-  type.go:144           0x1107c                 34c5d0ef                CALL runtime.panicIndex(SB)                     
-  type.go:144           0x11080                 00000013                MOV X0, X0                                 
+  type.go:142           0x1106c                 01130001                MOV X0, X0                                      
+  type.go:142           0x11064                 b5830002                ?                                               
+  type.go:142           0x11068                 30830082                ?                                               
+  type.go:142           0x1106c                 01130001                MOV X0, X0                                      
+  type.go:142           0x11070                 80670181                ?                                               
+  type.go:142           0x11074                 83160000                UNIMP                                           
+  type.go:144           0x11078                 308590ef                CALL runtime.panicIndex(SB)                     
+  type.go:144           0x1107c                 00000001                MOV X0, X0
@Jorropo Jorropo changed the title x/arch: RISCV64C support x/arch: RISCV64C disassembly support Jan 3, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/639995 mentions this issue: cmd/internal/disasm: correct instruction length handling for riscv64

@4a6f656c
Copy link
Contributor

4a6f656c commented Jan 3, 2025

This is most likely due to a bug in cmd/internal/disasm - could you try https://go-review.googlesource.com/c/go/+/639995 ?

@Jorropo Jorropo changed the title x/arch: RISCV64C disassembly support cmd/disasm: RISCV64C disassembly support Jan 3, 2025
@Jorropo
Copy link
Member Author

Jorropo commented Jan 3, 2025

indeed thx

@dmitshur dmitshur added this to the Go1.25 milestone Jan 3, 2025
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Jan 3, 2025
@dmitshur dmitshur changed the title cmd/disasm: RISCV64C disassembly support cmd/internal/disasm: RISCV64C disassembly support Jan 3, 2025
@dmitshur dmitshur added the arch-riscv Issues solely affecting the riscv64 architecture. label Jan 3, 2025
@4a6f656c
Copy link
Contributor

4a6f656c commented Jan 4, 2025

It would be worth including this fix in Go 1.24 since this code was only added this cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-riscv Issues solely affecting the riscv64 architecture. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants