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

upx output of binary 'go' file can not run on macOS #222

Closed
hr3lxphr6j opened this issue Sep 18, 2018 · 42 comments
Closed

upx output of binary 'go' file can not run on macOS #222

hr3lxphr6j opened this issue Sep 18, 2018 · 42 comments
Milestone

Comments

@hr3lxphr6j
Copy link

What's the problem (or question)?

upx output binary file can not run on macOS

What should have happened?

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
}
$ go build go-test.go

$ ./go-test
Hello World

$ upx go-test
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2018
UPX 3.95        Markus Oberhumer, Laszlo Molnar & John Reiser   Aug 26th 2018

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   2003464 ->   1007632   50.29%   macho/amd64   go-test

Packed 1 file.

$ ./go-test
[1]    9461 killed     ./go-test

Do you have an idea for a solution?

How can we reproduce the issue?

Please tell us details about your environment.

  • UPX version used (upx --version):
    upx 3.95
    UCL data compression library 1.03
    zlib data compression library 1.2.11
    LZMA SDK version 4.43
    
  • Host Operating System and version: macOS High Sierra 10.13.6
  • Host CPU architecture: x86_64
  • Target Operating System and version: macOS High Sierra 10.13.6
  • Target CPU architecture: x86_64
@joshdk
Copy link

joshdk commented Sep 19, 2018

I can confirm that I am also seeing this issue. It appears to be an issue with the official 3.95 release, as I do not see the failure using the official 3.94 release.

To reproduce I built a simple Docker image (using the following Dockerfile with macos$ docker build -t upx-macos-repro .) that installs the 3.94 and 3.95 UPX releases:

FROM golang:1.10.4

RUN apt update \
 && apt install xz-utils \
 && cd /tmp \
 && wget --quiet https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz \
 && wget --quiet https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz \
 && tar -xf upx-3.94-amd64_linux.tar.xz \
 && tar -xf upx-3.95-amd64_linux.tar.xz

I then ran the image with:

macos$ docker run --rm -it \
  -v $PWD:$PWD -w $PWD \
  upx-macos-repro:latest

Inside the image, I compiled and compressed test binaries using both releases:

root# ls -lh
total 8.0K
-rw-r--r-- 1 root root 356 Sep 19 01:18 Dockerfile
-rw-r--r-- 1 root root  72 Sep 19 01:03 main.go

root# GOOS=darwin GOARCH=amd64 go build -o hello .

root# ls -lh
total 2.0M
-rw-r--r-- 1 root root  356 Sep 19 01:18 Dockerfile
-rwxr-xr-x 1 root root 2.0M Sep 19 01:25 hello
-rw-r--r-- 1 root root   72 Sep 19 01:03 main.go

root# cp hello hello-3.94

root# cp hello hello-3.95

root# ls -lh
total 6.0M
-rw-r--r-- 1 root root  356 Sep 19 01:18 Dockerfile
-rwxr-xr-x 1 root root 2.0M Sep 19 01:25 hello
-rwxr-xr-x 1 root root 2.0M Sep 19 01:25 hello-3.94
-rwxr-xr-x 1 root root 2.0M Sep 19 01:25 hello-3.95
-rw-r--r-- 1 root root   72 Sep 19 01:03 main.go

root# /tmp/upx-3.94-amd64_linux/upx hello-3.94
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2017
UPX 3.94        Markus Oberhumer, Laszlo Molnar & John Reiser   May 12th 2017

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   2085008 ->    696976   33.43%   macho/amd64   hello-3.94

Packed 1 file.

root# /tmp/upx-3.95-amd64_linux/upx hello-3.95
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2018
UPX 3.95        Markus Oberhumer, Laszlo Molnar & John Reiser   Aug 26th 2018

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   2085008 ->    696336   33.40%   macho/amd64   hello-3.95

Packed 1 file.

root# ls -lh
total 3.5M
-rw-r--r-- 1 root root  356 Sep 19 01:18 Dockerfile
-rwxr-xr-x 1 root root 2.0M Sep 19 01:25 hello
-rwxr-xr-x 1 root root 681K Sep 19 01:25 hello-3.94
-rwxr-xr-x 1 root root 681K Sep 19 01:25 hello-3.95
-rw-r--r-- 1 root root   72 Sep 19 01:03 main.go

root# sha256sum --binary --tag hello*
SHA256 (hello) = 4a15193351665d4acf528b01c8edd6e486e4ae8867c890e2c0514b679351159f
SHA256 (hello-3.94) = 0cbaf0a47d94ffb7f1680b8a4a5525ce8bc645842cf31fa1cc57a0b40ad88b38
SHA256 (hello-3.95) = 9c8dc585c0ac84af66b19561111cd4a81cd64e4a59eb83adcc2b3382910e0b15

After exiting the image, I then ran the original and compressed binaries, resulting in the execution failure:

macos$ ./hello
Hello World
macos$ ./hello-3.94
Hello World
macos$ ./hello-3.95
Killed: 9

Additionally, I have bundled all of these files together and uploaded them in repro.tar.gz.

Thank you all for the hard work on this amazing project!
Cheers!

@jreiser jreiser changed the title upx output binary file can not run on macOS upx output of binary 'go' file can not run on macOS Sep 19, 2018
jreiser added a commit that referenced this issue Sep 23, 2018
#222
	modified:   p_mach.cpp
	modified:   p_mach.h
	modified:   stub/src/amd64-darwin.macho-entry.S
	also *.macho-*.h, *.macho-fold.map, amd64-darwin.macho-entry.bin.dump
@jreiser
Copy link
Collaborator

jreiser commented Sep 30, 2018

The tip of devel branch, 37d6a34, works for me; also tested on Mojave. A compiled version for Linux is available beginning at the upx-automatic-builds page as: https://github.com/upx/upx-automatic-builds/blob/devel-20180924-37d6a34-travis/amd64-linux-gcc-8-release/upx-git-37d6a34e5867.out .

jreiser added a commit that referenced this issue Oct 14, 2018
#222
	modified:   p_mach.cpp
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/amd64-darwin.macho-upxmain.c
	also *-darwin.macho-fold.{h,map}
@jreiser
Copy link
Collaborator

jreiser commented Oct 14, 2018

The tip of devel branch fixes upx -d for such 'rust' executables.

@hairyhenderson
Copy link

@jreiser is there any timeline on a UPX release with this fix?

@jreiser
Copy link
Collaborator

jreiser commented Nov 2, 2018

@tammersaleh See the comment #222 (comment) of Sep.30. I'll bet you can figure out how to get the version which runs on amd64-darwin.

@hmage
Copy link

hmage commented Nov 3, 2018

@jreiser which is not what package managers will do -- they will update the package only when new release is out.

@hmage
Copy link

hmage commented Nov 3, 2018

See Homebrew/homebrew-core#32422

@hairyhenderson
Copy link

@jreiser is there anything blocking a 3.96 release with this fix? Is there anything we can do to help this along?

@jreiser
Copy link
Collaborator

jreiser commented Nov 12, 2018

@hairyhenderson

  1. Post a Comment that "I tried commit #... [paste the 40-character commit ID, which github will turn into a link] from ... [give the download link, or say how you created the executable of upx itself]. The output from upx compression worked for me in this case, and upx -d decompression restored the original file." The experience of UPX Team is that not enough users actually try the development versions. Posting reproducible issues is a big help that is made even more valuable when real users verify developer fixes before a release.
    See the comment upx output of binary 'go' file can not run on macOS #222 (comment) for an example of pre-built executable of upx. Or use homebrew, or borrow a Linux box.
  2. If part 1 works, then why aren't you happy? Oh, you say that some other entire project wants to use upx? Then have 1 or 2 others from that project chime in, "I tried commit #..., it works for me."
  3. Making a release is not an automated process. There are 6 or 7 different hardware+OS combinations which must be tested to verify hand-written assembly language decompressors. Virtualization is not available for some of them, so real hardware must be employed.
  4. Markus is the only one who can make an official release. The NRV match finder+selector is not open source. The UCL implementation is compatible but with slightly less compression. Almost any worthwhile real executable will be smaller if compressed with LZMA, but LZMA decompression takes around 10 times long [still reasonably fast] and about 10 times the energy (a multiply operation for every bit).
  5. $DAYJOB often has priority.

@hairyhenderson
Copy link

Thanks for the quick response @jreiser. I'll try to find some time to test the fix.

I can imagine that it's a complex project to deal with, given all the different platforms you support! I'm not trying to complain or rush things, and I totally understand priority pressures. It just wasn't clear to me where this stood. Now it is, and I thank you for the clarity!

@hairyhenderson
Copy link

Ok, I've used brew install --HEAD upx to build 473b904, and I've compressed a Go program (gomplate) with it, then decompressed (with upx -d), and it looks good to me ✅:

$ sha256sum bin/*
5b7a8474260b3ed09884afb0b798aa0e710cfa42b17b1dcff92e77bb38207c21  bin/gomplate_darwin-amd64 # original
dd30fde418e918dca38764d72821bb32cbe5a8836adac8412c68a61b6e9bfb19  bin/gomplate_darwin-amd64-slim # compressed
5b7a8474260b3ed09884afb0b798aa0e710cfa42b17b1dcff92e77bb38207c21  bin/gomplate_darwin-amd64-slim-decompressed # decompressed

and the compressed executable works:

$ bin/gomplate_darwin-amd64-slim -i '{{ print "it works!" }}'
it works!

Perhaps some others can verify as well?

@grtfou
Copy link

grtfou commented Dec 13, 2018

It's work. Thanks for @hairyhenderson 's answer.

$ go version
go version go1.11.1 darwin/amd64

$ brew install --HEAD upx

$ upx -V
upx 3.96-git-473b90419f68
UCL data compression library 1.03
zlib data compression library 1.2.11
LZMA SDK version 4.43

$ upx -o besthello hello
$ ./besthello
Hello World!

@hairyhenderson
Copy link

Thanks @grtfou!

@hairyhenderson
Copy link

@jreiser @markus-oberhumer - it looks like at least 2 more (myself and @grtfou) have confirmed the fix. I'll try to see if I can find more if you need more broad testing.

Also @hackmac89 - I see you 👍d my comment - does that mean you can also verify the fix? Can you do so in writing? 🙂

@geocine
Copy link

geocine commented Dec 19, 2018

@hairyhenderson I can confirm , your comment is working. I uninstalled 3.95 and installed HEAD

@hackmac89
Copy link

@hairyhenderson yep, can confirm it´s working.

estahn added a commit to estahn/cloudping that referenced this issue Jan 13, 2019
upx currently breaks macOS binaries (see upx/upx#222)
@fxcoudert
Copy link

@markus-oberhumer could a 3.96 release be cut? While shipping upx in Homebrew we are seeing the number of necessary patches accumulate (4 patches now) to make the software work.

@markus-oberhumer
Copy link
Collaborator

Yeah, a new release is probably a good idea. Should happen soon.

@steeve
Copy link

steeve commented May 27, 2020

Thanks @jreiser! I'll do that later today

@steeve
Copy link

steeve commented May 27, 2020

@jreiser here you go! Here is the uncompressed executable https://we.tl/t-OFgjlWIeMe
As I said earlier, that executable works with upx 3.94.

Thanks!

@steeve
Copy link

steeve commented May 28, 2020

Just ran a bisect, and it found this commit: 4f69799.
(on a side note, the build was painless, congrats!)

@gonejack
Copy link

@hairyhenderson it works for me too now, after go upgraded to 1.14.3 while upx is still at 3.96

@MenJeremy
Copy link

I have the same issue but with Lazarus IDE 2.0.8 x86_64.
Any suggestions how to downgrade upx on Mac to 3.94 using homebrew?

@steeve
Copy link

steeve commented May 29, 2020

Any suggestions how to downgrade upx on Mac to 3.94 using homebrew?

You can do that:

brew uninstall upx
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/b1f92701367028062abb3518426aa5d8dacc224b/Formula/upx.rb

@MenJeremy
Copy link

Thanks @steeve, I can now compress again with version 3.94 :)

jreiser added a commit that referenced this issue Jun 7, 2020
#222  go-1.14 (but not go-1.14.3 ?)
	modified:   ../p_mach.cpp
	modified:   ../p_mach.h
	modified:   ../p_unix.cpp
	modified:   ../p_unix.h
	modified:   ../stub/src/amd64-darwin.macho-main.c

	modified:   ../stub/amd64-darwin.macho-fold.h
	modified:   ../stub/arm.v5a-darwin.macho-fold.h
	modified:   ../stub/arm64-darwin.macho-fold.h
	modified:   ../stub/tmp/amd64-darwin.macho-fold.map
	modified:   ../stub/tmp/arm.v5a-darwin.macho-fold.map
	modified:   ../stub/tmp/arm64-darwin.macho-fold.map
jreiser added a commit that referenced this issue Jun 7, 2020
@MenJeremy
Copy link

Any suggestions how to downgrade upx on Mac to 3.94 using homebrew?

You can do that:

brew uninstall upx
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/b1f92701367028062abb3518426aa5d8dacc224b/Formula/upx.rb

@steeve Is there a way to test different versions, ex: 3.9.5, I can't seem to find a list of formulas for upx ?

@steeve
Copy link

steeve commented Jun 16, 2020

You could find the history at https://github.com/Homebrew/homebrew-core/commits/master/Formula/upx.rb

You can look for the affect commit: #222 (comment)

@KempWatson
Copy link

Where is v3.96 for Mac OS? I don't see it in the downloads in GitHub? Thanks!

@jreiser
Copy link
Collaborator

jreiser commented Aug 31, 2020

@KempWatson That's right, there are no pre-built executables of UPX for MacOS listed on https://github.com/upx/upx/releases because there are no free (as in beer) public build environments for MacOS like there are for Linux and MSWindows. This is due to Apple's licensing policies. Various users have reported success building UPX using brew; search the internet for examples. (Or, because UPX is universally cross-platform [any UPX on any platform can compress for every supported executable file format] then use any Linux or WIndows machine to do the compression.)

@jph00
Copy link

jph00 commented Nov 11, 2020

@jreiser GitHub Actions provides a free public build environment for MacOS, Linux, and MSWindows.

@dimitarvp
Copy link

On macOS Big Sur 11.1:

Tried using an older version via the methods specified above and figured I'll try the last version (3.95_1) but...

/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of upx from a GitHub commit URL is unsupported! 'brew extract upx' to stable tap on GitHub instead. (UsageError)

Current version (3.96) produces binaries that display Killed when started still.

@dimitarvp
Copy link

Haven't tried compiling upx from source btw; just did brew install upx. Attached at the bottom is a zipped executable file that you can generate yourself (if you have Rust installed) and test like so:

$ upx --version
upx 3.96
# <extra text snipped>
$ cargo new --bin hello
$ cd hello
$ cargo build --release
$ ./target/release/hello
"Hello, world!"
$ upx --all-methods ./target/release/hello
$ ./target/release/hello
[1]    40004 killed     ./target/release/hello

hello.zip

HarikrishnanBalagopal added a commit to HarikrishnanBalagopal/move2kube that referenced this issue Mar 3, 2021
Issue seems to be with v3.94 of upx that comes installed by
default in ubuntu-latest images of Github actions.

A number of very similar issues:
upx/upx#450
upx/upx#222

Signed-off-by: Harikrishnan Balagopal <harikrishmenon@gmail.com>
HarikrishnanBalagopal added a commit to HarikrishnanBalagopal/move2kube that referenced this issue Mar 3, 2021
…mediately

Issue seems to be with v3.94 of upx that comes installed by
default in ubuntu-latest images of Github actions.

A number of very similar issues:
upx/upx#450
upx/upx#222

Signed-off-by: Harikrishnan Balagopal <harikrishmenon@gmail.com>
ashokponkumar pushed a commit to konveyor/move2kube that referenced this issue Mar 3, 2021
…mediately (#441)

Issue seems to be with v3.94 of upx that comes installed by
default in ubuntu-latest images of Github actions.

A number of very similar issues:
upx/upx#450
upx/upx#222

Signed-off-by: Harikrishnan Balagopal <harikrishmenon@gmail.com>
rmarchei added a commit to rmarchei/p2cli that referenced this issue Apr 9, 2021
upx 3.96 currently fails there. See upx/upx#222
markus-oberhumer pushed a commit that referenced this issue Aug 17, 2022
#222  go-1.14 (but not go-1.14.3 ?)
	modified:   ../p_mach.cpp
	modified:   ../p_mach.h
	modified:   ../p_unix.cpp
	modified:   ../p_unix.h
	modified:   ../stub/src/amd64-darwin.macho-main.c

	modified:   ../stub/amd64-darwin.macho-fold.h
	modified:   ../stub/arm.v5a-darwin.macho-fold.h
	modified:   ../stub/arm64-darwin.macho-fold.h
	modified:   ../stub/tmp/amd64-darwin.macho-fold.map
	modified:   ../stub/tmp/arm.v5a-darwin.macho-fold.map
	modified:   ../stub/tmp/arm64-darwin.macho-fold.map
markus-oberhumer pushed a commit that referenced this issue Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests