Unable to run 32-bit executable on Ubuntu 16.04 on Pipelines
Asked by Zeex:

Hello,

I'm having an issue with running a 32-bit executable built with GCC inside a Bitbucket pipeline using the atlassian/default-image:2 image:

    + file /usr/local/bin/pawncc/usr/local/bin/pawncc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=1df4edb3e7046c89aaac29df60750a897c3e0540, not stripped

    + ldd /usr/local/bin/pawncc	not a dynamic executable

LDD says that it's "not a dynamic executable".

Do I need to install some extra packages to run 32-bit programs? I currently have the following:

    + apt-get install -y libc6:i386 linux-libc-dev:i386 cmake gcc-multilib gcc-4.8 gcc-4.8-multilib g++-4.8 g++-4.8-multilib cmake snapd

**Update:**

Sample bitbucket-pipelines.yml that reproduces the issue:

```
image: atlassian/default-image:2

pipelines:
default:
- step:
name: Build
script:
- uname -a
- cat /etc/lsb-release
- dpkg --add-architecture i386
- apt-get update -qq
- apt-get install -y binfmt-support file wget libc6-i386 linux-libc-dev:i386 gcc gcc-multilib
- echo 'int main() { printf("Hello, world!"); }' >> test.c
- gcc -m32 test.c -o test
- ./test
```

Output:

    bash: ./test: cannot execute binary file: Exec format error


Answers:
author: Nic Brough -Adaptavist-
body: If ldd is reporting it's not a valid executable, then it's been built incorrectly for the current architecture, or you are missing supporting libraries in the running environment.

While this running inside a bitbucket pipeline, it's not really a bitbucket question - there's something missing from the environment or the compile

comments: author: Zeex
body: The executable is built correctly - I'm using the same script on Travis CI and it's working


author: Nic Brough -Adaptavist-
body: Ok, that's one thing fixed or ruled out. The next question has to be what is the difference between your Travis environment and the Bitbucket pipeline environment?


author: Zeex
body: No idea... I even ran the same Docker image as Pipelines uses on my computer with the same set of commands, and it worked for me there


author: Zeex
body: <https://community.atlassian.com/t5/Bitbucket-questions/Unable-to-run-32-bit-linux-application-inside-Docker-containers/qaq-p/1673437>


author: Zeex
body: I've just tried using a i386 image of ubuntu (i386/ubuntu:xenial) and it failed as well, but this time during build initialization stage:

standard_init_linux.go:211: exec user process caused "exec format error"time="2021-05-14T13:04:46Z" level=error msg="init failed" error="standard_init_linux.go:211: exec user process caused \\"exec format error\\"" name=kata-agent pid=1 source=agentpanic: --this line should have never been executed, congratulations--goroutine 1 \[running, locked to thread\]:main.init.0() /go/src/github.com/kata-containers/agent/agent.go:1489 +0x10f+ umask 000+ GIT_LFS_SKIP_SMUDGE=1 retry 6 git clone --branch="master" --depth 50 https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/$BITBUCKET_REPO_FULL_NAME.git $BUILD_DIRCloning into '/opt/atlassian/pipelines/agent/build'...


author: Zeex
body: [@Nic Brough -Adaptavist-](/t5/user/viewprofilepage/user-id/781454)any other ideas?


author: Nic Brough -Adaptavist-
body: No, it's the same answer - the environment you've got is different somehow, the one in your pipeline can't run the executable because it doesn't support that type of executable like the other test environments do.


author: Zeex
body: I suspect that Bitbucket runs some script that modifies the default environment of the container, because the same build scripts run PERFECTLY when I using Docker with the same image (atlassian/default-image). Or maybe Pipelines run docker with some weird options that prevent 32-bit support or something.


author: Thomas Rosenberger
body: Hey all, the last post has been made quite a while ago, but since I found an easy solution for executing 32-bit applications on Bitbucket pipeline, I felt like sharing this info with you.

I ran into the same issue with my 32-bit binary of google protoc compiler "protoc.bin".

The solution is installing 2 packages to enable execution of 32-bit applications.

Below you can find an example .yaml which installs the 2 required packages:

* gcc-multilib
* g++-multilib

```
image: ubuntu:latest

pipelines:
default:
 - step:
script:
 - apt-get update && apt-get install -y gcc-multilib g++-multilib
 - # Add your build commands here
```

Hope this helps.


author: Jason
body: [@Zeex](/t5/user/viewprofilepage/user-id/4385380) [@mfkenney](/t5/user/viewprofilepage/user-id/4629147) Did you find a solution or workaround for this?

I've run into exactly the same issue and have come to the same conclusion. Bitbucket Pipelines must run the docker containers with a different configuration or in an environment that doesn't support 32-bit executables.   

We've created our own docker image as follows:  

```
FROM ubuntu:20.04

RUN dpkg --add-architecture i386 && \
    apt-get update && \
    apt-get install -y build-essential libc6-i386 libstdc++6 unzip?git libgit2-dev python3 python3-pip python3-cffi

...
```

When running this docker image on Windows using WSL then the build script works fine.

However, when running the same scripts inside Bitbucket Pipelines then there is an error:

```
bash: /opt/mspgcc/bin/msp430-gcc: cannot execute binary file: Exec format error
```

comments: author: Zeex
body: Yes, I emailed Bitbucket support and they were able to enable 32-bit for my pipeline


author: mfkenney
body: [@Zeex](/t5/user/viewprofilepage/user-id/4385380) Just FYI, I ran into the same problem. I have a 64-bit Debian container image with some 32-bit executables (an old GCC cross compiler). The image works on every Docker installation I've tried except Bitbucket. My work-around is to use a self-hosted pipeline runner -- the image runs fine.

I have no idea how Bitbucket is running the images in their Cloud but they must be doing something non-standard ...


Tags: bitbucket-cloud

bitbucket-pipelines

cloud