Building bazel "LSB executable" vs "LSB shared object"

224 views
Skip to first unread message

Adam Singer

unread,
Jul 13, 2022, 3:09:59 PM7/13/22
to bazel-...@googlegroups.com
Please excuse me if this was a duplicate posting on bazel-discuss, I can't tell if the web interface sent a message or not.

Hi all,

I'm building bazel (with patches) and not able to produce a similar executable as found on the github releases page. Following instructions on https://bazel.build/contribute/getting-startedhttps://bazel.build/install/compile-source while building on/for linux is producing a "LSB shared object" for `bazel-bin/src/bazel` instead of "LSB executable" as found in the bazel releases on github. 

I'm using the following command

```
bazel build -c opt //src:bazel
```
and 

```
bazel build -c opt //src:bazel-bin
```

Both produce "LSB shared object". The releases linux binaries work in the environment I'm using (linux host with older glibc libraries), but when using the source built `bazel-bin/src/bazel` something seems not statically linked correctly and I receive missing `GLIBC_<version>` errors. I think this has todo with the final linking of an executable vs shared object when building bazel from source code. 

Built from source:

```
$ file bazel
bazel: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, BuildID[sha1]=3bb0a79a91a3c8aff414f96a5d8973bdbdf4b54c, not stripped
```

Downloaded from github releases:

```
$ file bazel
bazel: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c26169f06e65dd020ad1c0ea4b9981759dd68ff0, not stripped
```

I was able to manually add some changes to BUILD files such as `linkstatic=1` / `features=["fully_static_link"]` / `-static -static-libstdc++` on linkeropts, which produced "LSB executable", on some of the cc_binary targets and the resulting binaries produced were LSB executable, but that seems wrong that I would need todo that the BUILD file level. I also ran into other issues where cross linking static and shared objects fails for some external libraries. 

I think the short and hopefully simple question is, what flags/commands do I need to use to build a bazel executable similar to the release from source?  

--
Adam M. Singer   Software EngineerScala/Build Team, Twitter, Inc.

Adam Singer

unread,
Jul 14, 2022, 4:38:51 AM7/14/22
to bazel-discuss
The tl;dr to this question was to use the docker image gcr.io/bazel-public/centos7-releaser 

```
$ docker run --name test_bash --rm -i -t gcr.io/bazel-public/centos7-releaser bash
$ git clone --depth 1 -b <branch> https://github.com/bazelbuild/bazel.git
$ bazel build --sandbox_tmpfs_path=/tmp //src:bazel
$ file bazel-bin/src/bazel
bazel-bin/src/bazel: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c26169f06e65dd020ad1c0ea4b9981759dd68ff0, not stripped 
```

https://bazelbuild.slack.com/archives/CA31HN1T3/p1657753189897049?thread_ts=1657654252.455979&cid=CA31HN1T3  / https://github.com/bazelbuild/continuous-integration/blob/c721e576f7b1f7b741d77c226edb489e8c73792b/pipelines/bazel-release.yml#L38-L98 

Thanks Benjamin Peterson! 
Reply all
Reply to author
Forward
0 new messages