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/objdump: add -gnu flag to use GNU/AT&T syntax in disassembly #34372

Open
laboger opened this issue Sep 18, 2019 · 3 comments
Labels
Milestone

Comments

@laboger
Copy link
Contributor

@laboger laboger commented Sep 18, 2019

I have had a patch to do this for quite a while on ppc64 which I've provided to internal and external developers who want to write Go assembler to optimize their code. I tried to sneak it in a while back for ppc64 but Cherry suggested I make it a proposal.

The initial goal was to make it easier for Go developers who write Go assembler to verify they are getting the native assembler they expect. Many are experts in their native assembler but not in Go assembler. With this change, the Go objdump will show both side by side. This is also helpful for any code compiled with Golang. The gnu objdump can be used to disassemble Go binaries but not all objects created by Go are accepted.

This could be controlled by option but that is probably too much bother, unless there are concerns about doing this all the time.

It can be added easily for ppc64 and others assuming GNUSyntax works well. I tried it for x86 but since I'm not fluent there I can't verify if the output looks like it should.

Here is an example of the output:

TEXT main.main(SB) /home/boger/gotests/hello.go
func main() {
  0x98e50               e87e0010                MOVD 16(R30),R3                      // ld r3,16(r30)
  0x98e54               7c230840                CMPU R3,R1                           // cmpld r3,r1
  0x98e58               41800010                BLT 0x98e68                          // blt 0x98e68
  0x98e5c               7ca802a6                MOVD LR,R5                           // mflr r5
  0x98e60               4bfc8d81                CALL runtime.morestack_noctxt(SB)    // bl 0x61be0
  0x98e64               4bffffec                BR main.main(SB)                     // b 0x98e50
  0x98e68               7fe802a6                MOVD LR,R31                          // mflr r31
  0x98e6c               fbe1ff91                MOVDU R31,-112(R1)                   // stdu r31,-112(r1)
    fmt.Printf("Hello\n")
  0x98e70               3fe00017                ADDIS $0,$23,R31                     // lis r31,23
  0x98e74               e87f4018                MOVD 16408(R31),R3                   // ld r3,16408(r31)
        return Fprintf(os.Stdout, format, a...)
  0x98e78               3fe0000f                ADDIS $0,$15,R31                     // lis r31,15
  0x98e7c               389fd580                ADD R31,$-10880,R4                   // addi r4,r31,-10880
  0x98e80               f8810020                MOVD R4,32(R1)                       // std r4,32(r1)
  0x98e84               f8610028                MOVD R3,40(R1)                       // std r3,40(r1)
  0x98e88               3fe0000d                ADDIS $0,$13,R31                     // lis r31,13
  0x98e8c               387f2e5a                ADD R31,$11866,R3                    // addi r3,r31,11866
  0x98e90               f8610030                MOVD R3,48(R1)                       // std r3,48(r1)
  0x98e94               38600006                MOVD $6,R3                           // li r3,6
  0x98e98               f8610038                MOVD R3,56(R1)                       // std r3,56(r1)
  0x98e9c               f8010040                MOVD R0,64(R1)                       // std r0,64(r1)
  0x98ea0               f8010048                MOVD R0,72(R1)                       // std r0,72(r1)
  0x98ea4               f8010050                MOVD R0,80(R1)                       // std r0,80(r1)
  0x98ea8               4bff8849                CALL fmt.Fprintf(SB)                 // bl 0x916f0
  0x98eac               ebe10000                MOVD 0(R1),R31                       // ld r31,0(r1)
  0x98eb0               7fe803a6                MOVD R31,LR                          // mtlr r31
  0x98eb4               38210070                ADD R1,$112,R1                       // addi r1,r1,112
  0x98eb8               4e800020                RET                                  // bclr 20,lt,0
@gopherbot gopherbot added this to the Proposal milestone Sep 18, 2019
@gopherbot gopherbot added the Proposal label Sep 18, 2019
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 14, 2019

It seems a little awkward to print two copies of the assembly by default. Would it make sense to have a -gnu flag instead?

@laboger

This comment has been minimized.

Copy link
Contributor Author

@laboger laboger commented Nov 18, 2019

An option would be great. I wasn't sure on the policy of adding new options to Go's objdump tool.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 27, 2019

I'm completely fine with a -gnu option on go tool objdump.
I can't see that anyone would object to that.
I don't believe this needs to go through the proposal process, unless anyone objects.

@rsc rsc changed the title proposal: add gnu assembler output as comments alongside Go assembler in Go objdump output cmd/objdump: add -gnu flag to use GNU/AT&T syntax in disassembly Nov 27, 2019
@rsc rsc added NeedsFix and removed Proposal labels Nov 27, 2019
@rsc rsc modified the milestones: Proposal, Go1.15 Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.