Skip to content

net/url: silent Segmentation fault. #51140

@genshen

Description

@genshen

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

$ go version
go version go1.17.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/genshen/Library/Caches/go-build"
GOENV="/Users/genshen/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/genshen/Documents/workspace/Golang/GOPATH/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/genshen/Documents/workspace/Golang/GOPATH"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/genshen/.local/develop/go/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/genshen/.local/develop/go/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.7"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j1/142yfh3s2x7fv38jf8ncld6m0000gn/T/go-build2394676782=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

// main.go
package main

import "C"
import (
	"fmt"
	"net/url"
)

type S struct {
I int
J int
}
func (s *S) String() {
	fmt.Println("S");
}
func main() {
	var s *S = nil;
	fmt.Println(s);

	var Url     *url.URL = nil;
	fmt.Println(Url)
}

Everything looks fine:

$ go build main.go -o main
$ ./main
<nil>
<nil>

However, under lldb/gdb, there is a crash of EXC_BAD_ACCESS (code=1, address=0x8) on mac (or Segmentation fault on Linux):

$ go build main.go -o main
$ lldb main
(lldb) target create "main"
Current executable set to '/Users/xxx/main' (x86_64).
(lldb) r
Process 3973 launched: '/Users/xxx/main' (x86_64)
<nil>
Process 3973 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x000000000408eaa0 main`net/url.(*URL).String + 64
main`net/url.(*URL).String:
->  0x408eaa0 <+64>: movq   0x8(%rax), %rcx
    0x408eaa4 <+68>: movq   (%rax), %rbx
    0x408eaa7 <+71>: testq  %rcx, %rcx
    0x408eaaa <+74>: je     0x408ebf5                 ; <+405>
Target 0: (main) stopped.
(lldb) 

What did you expect to see?

Without EXC_BAD_ACCESS or Segmentation fault error under lldb/gdb. Or give a panic error in normal running (without lldb/gdb).

What did you see instead?

EXC_BAD_ACCESS(mac) or Segmentation fault (linux) error under gdb/lldb (see above).
Please note: It seams fine in normal running (without lldb/gdb), but the error is silent which is hard to find and track it.
Background:
In my development, I call a go api in my swift code, but my app gives me an error of EXC_BAD_ACCESS and the whole app crashed. I spend a lot of time to find the possible bug, and eventually find it may be a bug of the go code (the go code is similar to above main.go code) and created this issue.


related issue: #42816

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions