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: autogenerated code is not dumped #37191

Closed
changkun opened this issue Feb 12, 2020 · 1 comment
Closed

cmd/objdump: autogenerated code is not dumped #37191

changkun opened this issue Feb 12, 2020 · 1 comment

Comments

@changkun
Copy link
Member

changkun commented Feb 12, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes, the autogenerated code does not appear in 1.13 and 1.14rc1.
But 1.12.6 is OK.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/changkun/Library/Caches/go-build"
GOENV="/Users/changkun/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/changkun/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j_/h4j7spgj3znbfxcbbph5fp4w0000gn/T
/go-build516351997=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
	"fmt"
	_ "net/http"
)

func init() {
	println("func main.init")
}

func main() {
	fmt.Printf("hello, %s", "world!")
}
$ go build -gcflags "-N -l" -ldflags=-compressdwarf=false -o ~/main.out ~/main.go
$ go tool objdump -s main.init main.out > main.S

What did you expect to see?

TEXT main.init.0(SB) /Users/changkun/main.go
  main.go:8		0x1224cb0		65488b0c2530000000	MOVQ GS:0x30, CX			
  main.go:8		0x1224cb9		483b6110		CMPQ 0x10(CX), SP			
  main.go:8		0x1224cbd		763b			JBE 0x1224cfa				
  main.go:8		0x1224cbf		4883ec18		SUBQ $0x18, SP				
  main.go:8		0x1224cc3		48896c2410		MOVQ BP, 0x10(SP)			
  main.go:8		0x1224cc8		488d6c2410		LEAQ 0x10(SP), BP			
  main.go:9		0x1224ccd		e87e89e0ff		CALL runtime.printlock(SB)		
  main.go:9		0x1224cd2		488d0586ae0800		LEAQ go.string.*+9951(SB), AX		
  main.go:9		0x1224cd9		48890424		MOVQ AX, 0(SP)				
  main.go:9		0x1224cdd		48c74424080f000000	MOVQ $0xf, 0x8(SP)			
  main.go:9		0x1224ce6		e89592e0ff		CALL runtime.printstring(SB)		
  main.go:9		0x1224ceb		e8e089e0ff		CALL runtime.printunlock(SB)		
  main.go:10		0x1224cf0		488b6c2410		MOVQ 0x10(SP), BP			
  main.go:10		0x1224cf5		4883c418		ADDQ $0x18, SP				
  main.go:10		0x1224cf9		c3			RET					
  main.go:8		0x1224cfa		e80118e3ff		CALL runtime.morestack_noctxt(SB)	
  main.go:8		0x1224cff		ebaf			JMP main.init.0(SB)			
  :-1			0x1224d01		cc			INT $0x3				
  :-1			0x1224d02		cc			INT $0x3				
  :-1			0x1224d03		cc			INT $0x3				
  :-1			0x1224d04		cc			INT $0x3				
  :-1			0x1224d05		cc			INT $0x3				
  :-1			0x1224d06		cc			INT $0x3				
  :-1			0x1224d07		cc			INT $0x3				
  :-1			0x1224d08		cc			INT $0x3				
  :-1			0x1224d09		cc			INT $0x3				
  :-1			0x1224d0a		cc			INT $0x3				
  :-1			0x1224d0b		cc			INT $0x3				
  :-1			0x1224d0c		cc			INT $0x3				
  :-1			0x1224d0d		cc			INT $0x3				
  :-1			0x1224d0e		cc			INT $0x3				
  :-1			0x1224d0f		cc			INT $0x3				

TEXT main.init(SB) <autogenerated>
  <autogenerated>:1	0x1224dd0		65488b0c2530000000	MOVQ GS:0x30, CX			
  <autogenerated>:1	0x1224dd9		483b6110		CMPQ 0x10(CX), SP			
  <autogenerated>:1	0x1224ddd		7658			JBE 0x1224e37				
  <autogenerated>:1	0x1224ddf		4883ec08		SUBQ $0x8, SP				
  <autogenerated>:1	0x1224de3		48892c24		MOVQ BP, 0(SP)				
  <autogenerated>:1	0x1224de7		488d2c24		LEAQ 0(SP), BP				
  <autogenerated>:1	0x1224deb		803d719e2b0001		CMPB $0x1, main.initdone.(SB)		
  <autogenerated>:1	0x1224df2		7702			JA 0x1224df6				
  <autogenerated>:1	0x1224df4		eb09			JMP 0x1224dff				
  <autogenerated>:1	0x1224df6		488b2c24		MOVQ 0(SP), BP				
  <autogenerated>:1	0x1224dfa		4883c408		ADDQ $0x8, SP				
  <autogenerated>:1	0x1224dfe		c3			RET					
  <autogenerated>:1	0x1224dff		803d5d9e2b0001		CMPB $0x1, main.initdone.(SB)		
  <autogenerated>:1	0x1224e06		7402			JE 0x1224e0a				
  <autogenerated>:1	0x1224e08		eb07			JMP 0x1224e11				
  <autogenerated>:1	0x1224e0a		e8416be0ff		CALL runtime.throwinit(SB)		
  <autogenerated>:1	0x1224e0f		0f0b			UD2					
  <autogenerated>:1	0x1224e11		c6054b9e2b0001		MOVB $0x1, main.initdone.(SB)		
  <autogenerated>:1	0x1224e18		e8b3b9e8ff		CALL fmt.init(SB)			
  <autogenerated>:1	0x1224e1d		e86e8affff		CALL net/http.init(SB)			
  <autogenerated>:1	0x1224e22		e889feffff		CALL main.init.0(SB)			
  <autogenerated>:1	0x1224e27		c605359e2b0002		MOVB $0x2, main.initdone.(SB)		
  <autogenerated>:1	0x1224e2e		488b2c24		MOVQ 0(SP), BP				
  <autogenerated>:1	0x1224e32		4883c408		ADDQ $0x8, SP				
  <autogenerated>:1	0x1224e36		c3			RET					
  <autogenerated>:1	0x1224e37		e8c416e3ff		CALL runtime.morestack_noctxt(SB)	
  <autogenerated>:1	0x1224e3c		eb92			JMP main.init(SB)			

What did you see instead?

TEXT main.init.0(SB) /Users/changkun/main.go
  main.go:8		0x1233e80		65488b0c2530000000	MOVQ GS:0x30, CX			
  main.go:8		0x1233e89		483b6110		CMPQ 0x10(CX), SP			
  main.go:8		0x1233e8d		763b			JBE 0x1233eca				
  main.go:8		0x1233e8f		4883ec18		SUBQ $0x18, SP				
  main.go:8		0x1233e93		48896c2410		MOVQ BP, 0x10(SP)			
  main.go:8		0x1233e98		488d6c2410		LEAQ 0x10(SP), BP			
  main.go:9		0x1233e9d		e8beb1dfff		CALL runtime.printlock(SB)		
  main.go:9		0x1233ea2		488d05ef280900		LEAQ go.string.*+10552(SB), AX		
  main.go:9		0x1233ea9		48890424		MOVQ AX, 0(SP)				
  main.go:9		0x1233ead		48c74424080f000000	MOVQ $0xf, 0x8(SP)			
  main.go:9		0x1233eb6		e8e5badfff		CALL runtime.printstring(SB)		
  main.go:9		0x1233ebb		e820b2dfff		CALL runtime.printunlock(SB)		
  main.go:10		0x1233ec0		488b6c2410		MOVQ 0x10(SP), BP			
  main.go:10		0x1233ec5		4883c418		ADDQ $0x18, SP				
  main.go:10		0x1233ec9		c3			RET					
  main.go:8		0x1233eca		e8a149e2ff		CALL runtime.morestack_noctxt(SB)	
  main.go:8		0x1233ecf		ebaf			JMP main.init.0(SB)			
  :-1			0x1233ed1		cc			INT $0x3				
  :-1			0x1233ed2		cc			INT $0x3				
  :-1			0x1233ed3		cc			INT $0x3				
  :-1			0x1233ed4		cc			INT $0x3				
  :-1			0x1233ed5		cc			INT $0x3				
  :-1			0x1233ed6		cc			INT $0x3				
  :-1			0x1233ed7		cc			INT $0x3				
  :-1			0x1233ed8		cc			INT $0x3				
  :-1			0x1233ed9		cc			INT $0x3				
  :-1			0x1233eda		cc			INT $0x3				
  :-1			0x1233edb		cc			INT $0x3				
  :-1			0x1233edc		cc			INT $0x3				
  :-1			0x1233edd		cc			INT $0x3				
  :-1			0x1233ede		cc			INT $0x3				
  :-1			0x1233edf		cc			INT $0x3				
@cherrymui
Copy link
Member

That is because we no longer generate main.init function. Instead we generate a variable for running the init routines. Autogenerated functions in general, e.g. type equality functions, still present.

@golang golang locked and limited conversation to collaborators Feb 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants