How to compile static racket binaries

59 views
Skip to first unread message

Tristram Oaten

unread,
Apr 2, 2020, 4:51:54 AM4/2/20
to Racket Users
Hi friends.

raco exe makes dynamic executables, and raco distribute doesn't change that:

$ ldd ./tst
linux-vdso.so.1 (0x00007ffc9ed46000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fbeb4c09000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbeb4a18000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbeb4c67000)

On windows, it looks like one can --embed-dlls, which is kindof what I want, but for all platforms.

I'd like to compile statically for ease of distribution and deployment. Is this possible?

Matthew Flatt

unread,
Apr 2, 2020, 8:16:23 AM4/2/20
to Tristram Oaten, Racket Users
Those ".so"s are OS-supplied dynamic libraries, and I think there's no
way to link to them statically. Of course, the resulting executable
will only work on a sufficiently compatible variant of Linux.

Are you seeing a specific problem when moving the executable among
machines? If so, what are the different Linux distributions on each
end?

Tristram Oaten

unread,
Apr 2, 2020, 9:28:00 AM4/2/20
to Racket Users
Thanks Matthew.

My use case is trying to get binaries into a container for deployment.

I've compiled it on ubuntu 19:10, and am running into this problem on ubuntu:latest (18.04), due to the different versions of libc.
If I run on ubuntu:19.10, it works as expected, but that's too brittle for my liking.

I'm keen find a way to statically-link libc, in the way that gcc, rust, go etc can do it.

George Neuner

unread,
Apr 2, 2020, 10:03:19 AM4/2/20
to racket...@googlegroups.com
On Thu, 2 Apr 2020 06:28:00 -0700 (PDT), Tristram Oaten
<tris...@oaten.name> wrote:

>My use case is trying to get binaries into a container for deployment.
>
>I've compiled it on ubuntu 19:10, and am running into this problem on
>ubuntu:latest (18.04), due to the different versions of libc.
>If I run on ubuntu:19.10, it works as expected, but that's too brittle for
>my liking.
>
>I'm keen find a way to statically-link libc, in the way that gcc, rust, go
>etc can do it.

Is there a reason that you can't put the (actually linked) C library
into the container with the application?

George

Matthew Flatt

unread,
Apr 2, 2020, 10:24:58 AM4/2/20
to Tristram Oaten, Racket Users
At Thu, 2 Apr 2020 06:28:00 -0700 (PDT), Tristram Oaten wrote:
> I've compiled it on ubuntu 19:10, and am running into this problem on
> ubuntu:latest (18.04), due to the different versions of libc.

Ah, I didn't realize that the C library version had changed in recent
Linux distributions. (It had been the same for several years.) That's a
pain.

The distributions at https://download.racket-lang.org/ are built with
an old enough Linux distribution to be portable in practice. So, using
that build is one option.

Currently, I guess you're building your own Racket executable on Ubuntu
19.10. That's the point where you can elect to statically link:

- If you're building from the source distribution, add
LDFLAGS=--static
to your `configure` line.

- If you're building from a Git repo checkout, add
CONFIGIRE_ARGS_qq="LDFLAGS=--static"
to your `make` line. In an existing tree, you'll need to
delete "racket/src/build" to ensure that it's rebuilt.

Make sure the "libffi-dev" package is installed, because the makefiles
for the bundled libffi do not like `--static`.

I'm not sure how well statically linking to the C library will work. I
get several linker warnings like this one:

warning: Using 'getgrgid' in statically linked applications requires
at runtime the shared libraries from the glibc version used for linking

For this reason and others, I'm surprised that other language
implementations statically link to the C library, but it's difficult to
keep track.

George Neuner

unread,
Apr 2, 2020, 12:00:19 PM4/2/20
to racket...@googlegroups.com

On 4/2/2020 10:24 AM, Matthew Flatt wrote:
> At Thu, 2 Apr 2020 06:28:00 -0700 (PDT), Tristram Oaten wrote:
> > I've compiled it on ubuntu 19:10, and am running into this problem on
> > ubuntu:latest (18.04), due to the different versions of libc.
>
> Ah, I didn't realize that the C library version had changed in recent
> Linux distributions. (It had been the same for several years.) That's a
> pain.

AFAIK, Ubuntu 19.10 is using glibc 2.30.

Version 2.30 (Aug 2019) fixed some privilege elevation and unwanted code
execution vulnerabilities dating from 2.26.  Also fixed a data
corruption issue with memmove introduced in 2.28 (in 2018).

https://www.gnu.org/software/libc/
https://www.cvedetails.com/vulnerability-list/vendor_id-72/product_id-767/GNU-Glibc.html

George

Jonathan Simpson

unread,
Apr 2, 2020, 6:32:42 PM4/2/20
to Racket Users
On Thursday, April 2, 2020 at 10:24:58 AM UTC-4, Matthew Flatt wrote:

I'm not sure how well statically linking to the C library will work. I
get several linker warnings like this one:

 warning: Using 'getgrgid' in statically linked applications requires
 at runtime the shared libraries from the glibc version used for linking

For this reason and others, I'm surprised that other language
implementations statically link to the C library, but it's difficult to
keep track.


I've never used rust, but a quick google search seems to indicate that it doesn't statically link glibc. Instead it uses musl libc for static linking. Glibc is not designed to support statically linking, but Racket might could support it if it were musl compatible(I have no idea whether Racket actually supports musl or not.)

-- Jonathan
 
Reply all
Reply to author
Forward
0 new messages