Repository: go
Issue: runtime: Crash in autogenerated function 
Labels: NeedsInvestigation,compiler/runtime

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.15.2 linux/amd64
</pre>

### Does this issue reproduce with the latest release?


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/phuser/.cache/go-build"
GOENV="/home/phuser/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/phuser/go/pkg/mod"
GONOPROXY="github.ibm.com"
GONOSUMDB="github.ibm.com"
GOOS="linux"
GOPATH="/home/phuser/go"
GOPRIVATE="github.ibm.com"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/phuser/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/phuser/goroot/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g  "
CGO_ENABLED="1"
GOMOD="/code/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build256493267=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.15.2 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.15.2
uname -sr: Linux 4.19.76-linuxkit
/lib64/libc.so.6: GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7
</pre></details>

### What did you do?

We have a project that consumes a number of external projects. As part of this, we log key points of interest using Zap (https://github.com/uber-go/zap) and Lumberjack (https://github.com/natefinch/lumberjack) during the execution of the program.

We received a report of a crash from a tester with the following call stack:

```
go.uber.org/zap/zapcore.(*writerWrapper).Write(0xc000205640, 0xc01ce21c00, 0xd5, 0x400, 0x1370200, 0x0, 0x0)
        <autogenerated>:1 +0x5a fp=0xc01d705890 sp=0xc01d705848 pc=0x90a69a
go.uber.org/zap/zapcore.(*ioCore).Write(0xc00039e180, 0x0, 0xbff8a186aa6a005f, 0xa711142ecab, 0x1370200, 0x0, 0x0, 0xc04697ad70, 0x10, 0x1, ...)
        /home/phuser/go/pkg/mod/go.uber.org/zap@v1.16.0/zapcore/core.go:90 +0x106 fp=0xc01d705978 sp=0xc01d705890 pc=0x8f94c6
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc00039de00, 0xc046952900, 0x2, 0x2)
        /home/phuser/go/pkg/mod/go.uber.org/zap@v1.16.0/zapcore/entry.go:220 +0x12d fp=0xc01d705b38 sp=0xc01d705978 pc=0x8fb86d
go.uber.org/zap.(*Logger).Info(0xc0003d8000, 0xc04697ad70, 0x10, 0xc046952900, 0x2, 0x2)
        /home/phuser/go/pkg/mod/go.uber.org/zap@v1.16.0/logger.go:188 +0x85 fp=0xc01d705b70 sp=0xc01d705b38 pc=0x9137e5
(omitted)
Aborted (core dumped)
```

Unfortunately, no core dump was found, despite `ulimit -c unlimited` having been set prior, as well as a call to the following upon startup of our program:

`debug.SetTraceback("crash")`

Using `go tool objdump` the compiler generated the following assembly in which we crashed:

```
TEXT go.uber.org/zap/zapcore.(*writerWrapper).Write(SB) <autogenerated>
  <autogenerated>:1     0x90a640                64488b0c25f8ffffff      MOVQ FS:0xfffffff8, CX
  <autogenerated>:1     0x90a649                483b6110                CMPQ 0x10(CX), SP
  <autogenerated>:1     0x90a64d                7673                    JBE 0x90a6c2
  <autogenerated>:1     0x90a64f                4883ec40                SUBQ $0x40, SP
  <autogenerated>:1     0x90a653                48896c2438              MOVQ BP, 0x38(SP)
  <autogenerated>:1     0x90a658                488d6c2438              LEAQ 0x38(SP), BP
  <autogenerated>:1     0x90a65d                488b5920                MOVQ 0x20(CX), BX
  <autogenerated>:1     0x90a661                4885db                  TESTQ BX, BX
  <autogenerated>:1     0x90a664                7566                    JNE 0x90a6cc
  <autogenerated>:1     0x90a666                488b442448              MOVQ 0x48(SP), AX
  <autogenerated>:1     0x90a66b                488b08                  MOVQ 0(AX), CX
  <autogenerated>:1     0x90a66e                488b4008                MOVQ 0x8(AX), AX
  <autogenerated>:1     0x90a672                488b4918                MOVQ 0x18(CX), CX
  <autogenerated>:1     0x90a676                48890424                MOVQ AX, 0(SP)
  <autogenerated>:1     0x90a67a                488b442450              MOVQ 0x50(SP), AX
  <autogenerated>:1     0x90a67f                4889442408              MOVQ AX, 0x8(SP)
  <autogenerated>:1     0x90a684                488b442458              MOVQ 0x58(SP), AX
  <autogenerated>:1     0x90a689                4889442410              MOVQ AX, 0x10(SP)
  <autogenerated>:1     0x90a68e                488b442460              MOVQ 0x60(SP), AX
  <autogenerated>:1     0x90a693                4889442418              MOVQ AX, 0x18(SP)
  <autogenerated>:1     0x90a698                ffd1                    CALL CX
  <autogenerated>:1     0x90a69a                488b442420              MOVQ 0x20(SP), AX
  <autogenerated>:1     0x90a69f                488b4c2428              MOVQ 0x28(SP), CX
  <autogenerated>:1     0x90a6a4                488b542430              MOVQ 0x30(SP), DX
  <autogenerated>:1     0x90a6a9                4889442468              MOVQ AX, 0x68(SP)
  <autogenerated>:1     0x90a6ae                48894c2470              MOVQ CX, 0x70(SP)
  <autogenerated>:1     0x90a6b3                4889542478              MOVQ DX, 0x78(SP)
  <autogenerated>:1     0x90a6b8                488b6c2438              MOVQ 0x38(SP), BP
  <autogenerated>:1     0x90a6bd                4883c440                ADDQ $0x40, SP
  <autogenerated>:1     0x90a6c1                c3                      RET
  <autogenerated>:1     0x90a6c2                e8194eb6ff              CALL runtime.morestack_noctxt(SB)
  <autogenerated>:1     0x90a6c7                e974ffffff              JMP go.uber.org/zap/zapcore.(*writerWrapper).Write(SB)
  <autogenerated>:1     0x90a6cc                488d7c2448              LEAQ 0x48(SP), DI
  <autogenerated>:1     0x90a6d1                48393b                  CMPQ DI, 0(BX)
  <autogenerated>:1     0x90a6d4                7590                    JNE 0x90a666
  <autogenerated>:1     0x90a6d6                488923                  MOVQ SP, 0(BX)
  <autogenerated>:1     0x90a6d9                eb8b                    JMP 0x90a666
```

So it looks to me like we crashed on: `MOVQ 0x20(SP), AX`

We create the zap logger with:

```Go
	lLogger := &lumberjack.Logger{
		Filename:   fn,
		MaxSize:    500, // In megabytes.
		MaxAge:     1,   // Maximum age of log.
		MaxBackups: 4,   // Maximum amount of logs.
		LocalTime:  true,
	}

	config := zap.NewDevelopmentEncoderConfig()
	config.FunctionKey = "F"
	core := zapcore.NewTee(
		zapcore.NewCore(
			zapcore.NewConsoleEncoder(config),
			zapcore.AddSync(lLogger),
			zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
				return lvl <= zapcore.ErrorLevel
			})),
		zapcore.NewCore(
			zapcore.NewConsoleEncoder(config),
			zapcore.AddSync(os.Stderr),
			zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
				return lvl >= zapcore.WarnLevel
			})),
	)
```

Thus according to the zap code, `zapcore.AddSync` will wrap the Lumberjack logger with a `writerWrapper` which is merely an interface comprised of `io.Writer` plus a `Sync` method, which is supplied by zap.

It looks to me like the Go compiler is autogenerating some glue to make the `writerWrapper` interface compatible with the desired `WriteSyncer` which is an interface specifying an `io.Writer` and `Sync` method.

I'm opening the issue here because it dies in between Zap and Lumberjack and seems like we have stack corruption somehow, rather than squarely in one of those two projects. It also looks like, although this is not PPC64LE, Go has previously had issues with stack corruption in or nearby autogenerated functions on #10628.

If it matters, we have attempted to log a string, a `zap.Uint64` (7 character key and uint64 value), and a `zap.Bool` (7 character key and bool value).

### What did you expect to see?

No crash.

### What did you see instead?

Crash without a core file.