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/link: c-shared build mode not working with UPX #42238

Open
esmailzadeh1 opened this issue Oct 27, 2020 · 3 comments
Open

cmd/link: c-shared build mode not working with UPX #42238

esmailzadeh1 opened this issue Oct 27, 2020 · 3 comments

Comments

@esmailzadeh1
Copy link

@esmailzadeh1 esmailzadeh1 commented Oct 27, 2020

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

go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build986805596=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wrote a simple Golang file. is as follows:

package main
func main() {
}

Then build it :
go build -buildmode=c-shared -o library.so main.go

After library.so created I want to compress it with UPX

run upx -9 library.so and got error

What did you expect to see?

92200 -> 49976 54.20% linux/amd64 library.so

What did you see instead?

upx: library.so: CantPackException: PT_NOTE 0xa71cc above stub

I opened a issue in GitHub UPX. They told me the problem the library.so does not have the correct format to allow compression.

This problem only when use -buildmode=c-shared in command-line.

Thanks.

@ianlancetaylor ianlancetaylor changed the title c-shared build mode not working with UPX cmd/link: c-shared build mode not working with UPX Oct 27, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 27, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 27, 2020

That's odd, since we are invoking the C linker to create the shared library.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 28, 2020

Change https://golang.org/cl/265957 mentions this issue: cmd/link: merge note sections into one segment

@mengzhuo
Copy link
Contributor

@mengzhuo mengzhuo commented Nov 2, 2020

@esmailzadeh1 update ld (binutils) to 2.32 and you should able to compress c-shared binaries by upx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.