goplus / llgo

A Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python
Apache License 2.0
308 stars 24 forks source link

Panicking while compiling a simple Go program #651

Open BahaaBBM opened 1 month ago

BahaaBBM commented 1 month ago

Hello, this is my first time using llgo. I'm encountering a panic when trying to compile a simple 'Hello, World' program.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x6f2fd4]

goroutine 1 [running]:
github.com/goplus/llgo/ssa.(*aProgram).rtNamed(0xc00008a008, {0x82d90b, 0x5})
    /go/src/llgo/ssa/package.go:256 +0xb4
github.com/goplus/llgo/ssa.(*aProgram).rtType(0xc00008a008, {0x82d90b?, 0xc00b639f80?})
    /go/src/llgo/ssa/package.go:262 +0x1d
github.com/goplus/llgo/ssa.(*aProgram).rtIface(...)
    /go/src/llgo/ssa/package.go:274
github.com/goplus/llgo/ssa.(*aProgram).toType(0xc00008a008, {0x8b5620, 0xc000100a50})
    /go/src/llgo/ssa/type.go:373 +0xc93
github.com/goplus/llgo/ssa.(*aProgram).rawType(0xc00008a008, {0x8b5620, 0xc000100a50})
    /go/src/llgo/ssa/type.go:252 +0x65
github.com/goplus/llgo/ssa.(*aProgram).toNamed(0xc00008a008, 0xc000142070)
    /go/src/llgo/ssa/type.go:511 +0x17a
github.com/goplus/llgo/ssa.(*aProgram).toType(0xc00008a008, {0x8b5648, 0xc000142070})
    /go/src/llgo/ssa/type.go:382 +0x191
github.com/goplus/llgo/ssa.(*aProgram).rawType(0xc00008a008, {0x8b5648, 0xc000142070})
    /go/src/llgo/ssa/type.go:252 +0x65
github.com/goplus/llgo/ssa.(*aProgram).toLLVMTypes(0xc00008a008, 0xc005dffda0, 0x2)
    /go/src/llgo/ssa/type.go:447 +0x89
github.com/goplus/llgo/ssa.(*aProgram).toLLVMFunc(0xc00008a008, 0xc005e42200)
    /go/src/llgo/ssa/type.go:460 +0x4f
github.com/goplus/llgo/ssa.(*aProgram).FuncDecl(0xc00008a008, 0xc007e6b408?, 0xc00aa13af0?)
    /go/src/llgo/ssa/type_cvt.go:66 +0x65
github.com/goplus/llgo/ssa.(*aPackage).NewFuncEx(0xc0070407e0, {0xc00aa13af0, 0x9}, 0xc005e42200, 0x1, 0x0)
    /go/src/llgo/ssa/decl.go:191 +0x92
github.com/goplus/llgo/cl.(*context).compileFuncDecl(0xc005b52270, 0xc0070407e0, 0xc0094b0000)
    /go/src/llgo/cl/compile.go:229 +0x945
github.com/goplus/llgo/cl.processPkg(0xc005b52270, 0xc0070407e0, 0xc009297680)
    /go/src/llgo/cl/compile.go:871 +0x394
github.com/goplus/llgo/cl.NewPackageEx(0xc00008a008, 0xc00798dcb0, 0xc009297680, {0xc005af6360, 0x3, 0x3})
    /go/src/llgo/cl/compile.go:829 +0x614
github.com/goplus/llgo/internal/build.buildPkg(0xc007af8240, 0xc0091aba60, 0x0)
    /go/src/llgo/internal/build/build.go:490 +0x308
github.com/goplus/llgo/internal/build.buildAllPkgs(0xc007af8240, {0xc0075e9f50?, 0xc0000341c0?, 0x82d070?}, 0x0)
    /go/src/llgo/internal/build/build.go:327 +0x3f1
github.com/goplus/llgo/internal/build.Do({0xc000112230?, 0x82d0ab?, 0x2?}, 0xc007e6be08)
    /go/src/llgo/internal/build/build.go:195 +0xa91
github.com/goplus/llgo/cmd/internal/build.runCmd(0xc000142000?, {0xc000112230?, 0x0?, 0x0?})
    /go/src/llgo/cmd/internal/build/build.go:44 +0x9d
main.main()
    /go/src/llgo/cmd/llgo/llgo.go:90 +0x4b3
xushiwei commented 1 month ago

please print your go version?

go version
BahaaBBM commented 1 month ago

go1.22.5 linux/amd64

aofei commented 1 month ago

Please provide the output of:

BahaaBBM commented 1 month ago

llgo v0.9.4 linux/amd64

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/smart/.cache/go-build'
GOENV='/home/smart/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/smart/Go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/smart/Go/'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/smart/Programs/go/'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/smart/Programs/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3919813185=/tmp/go-build -gno-record-gcc-switches'

Linux smart-Latitude-E6400 5.15.0-117-generic #127-Ubuntu SMP Fri Jul 5 20:13:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux


NAME="Linux Mint"
VERSION="21.2 (Victoria)"
ID=linuxmint
ID_LIKE="ubuntu debian"
PRETTY_NAME="Linux Mint 21.2"
VERSION_ID="21.2"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.linuxmint.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=victoria
UBUNTU_CODENAME=jammy
BahaaBBM commented 1 month ago

Please provide the output of:

* `llgo version` (or simply tell us how it was installed, especially if it prints something like `llgo (devel) linux/amd64`)

* `go env`

* `uname -a`

* `cat /etc/os-release`

I tried to install it in both ways, using go install -v github.com/goplus/llgo/cmd/llgo@latestand downloading the binary release, both didn't work.

xushiwei commented 1 month ago

Do you add require github.com/goplus/llgo v0.9.4 in your go.mod file?

BahaaBBM commented 1 month ago

Do you add require github.com/goplus/llgo v0.9.4 in your go.mod file?

Thanks, I didn't know that I have to do that, I just tried it on a simple filellgo build main.go. But now I ran into another error:

ld.lld: error: undefined symbol: syscall.WaitStatus.TrapCause
>>> referenced by os
>>>               /tmp/8143fa2412f629088bf8c54fcae3e8558113ac1c841b81acd18731f59d7554fc-d-1a6e55.o:(os.(*ProcessState).String)
>>> referenced by os
>>>               /tmp/8143fa2412f629088bf8c54fcae3e8558113ac1c841b81acd18731f59d7554fc-d-1a6e55.o:(os.(*ProcessState).String)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
BahaaBBM commented 1 month ago

I think the problem is related to the fmt package? Removing the fmt package resolved the issue.

xushiwei commented 1 month ago

Thanks, I didn't know that I have to do that, I just tried it on a simple filellgo build main.go.

Will do this automatically in the future.