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

Unsafe package with Control flow #903

Open
Thibaud1255 opened this issue Jan 3, 2025 · 2 comments
Open

Unsafe package with Control flow #903

Thibaud1255 opened this issue Jan 3, 2025 · 2 comments

Comments

@Thibaud1255
Copy link

What version of Garble and Go are you using?

1.23.3

$ garble version
mvdan.cc/garble v0.13.0
$ go version
go version go1.23.3 windows/amd64

What environment are you running Garble on?

Windows 11

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\GUY\AppData\Local\go-build
set GOENV=C:\Users\GUY\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\GUY\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\GUY\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.3
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\GUY\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\GUY\AppData\Local\Temp\go-build1744563614=/tmp/go-build -gno-record-gcc-switches

What did you do?

create a main.go with a package using unsafe package and
use //garble:controlflow

  1. Create a main.go which call a package
  2. the package need to use unsafe package and //garble:controlflow on it
  3. it will simply crash saying it cannot resolve the package or typecheck error: utils\unsafe.go:5:2: "unsafe" imported and not used

What did you expect to see?

Compile it normally

What did you see instead?

Crashing

@lu4p
Copy link
Member

lu4p commented Jan 3, 2025

Can you share an example which triggers this issue?

@Thibaud1255
Copy link
Author

Can you share an example which triggers this issue?

sure it have this error:
image

example.go:

package example

import (
	"fmt"
	"unsafe"
)

//garble:controlflow
func ModifyValue() {
	var a int = 42
	var p *int = &a

	fmt.Println("Value of a:", a)
	fmt.Println("Address of a:", p)

	var up unsafe.Pointer = unsafe.Pointer(p)

	var p2 *int = (*int)(up)

	*p2 = 100

	fmt.Println("New value of a:", a)
}

main.go:

package main

import (
	"main/example"
)

func main() {
	example.ModifyValue()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants