eudev-project / eudev

Repository for eudev development
GNU General Public License v2.0
522 stars 147 forks source link

Static linking support for binaries, not only libs #230

Closed slashbeast closed 1 year ago

slashbeast commented 2 years ago

I have a really niche use case where I need udev inside initramfs, that does not came with libc or really much else. For that I build and link everything statically against musl libc using Alpine Linux as build root.

I did a quick check on it and while building with LDFLAGS='-static' I see that it kind of work like I wanted it to, but not really.

taking udevd as example:

# make V=99 udevd
/bin/sh ../../libtool  --tag=CC   --mode=link gcc  -g -O2  -static -o udevd udevd.o libudev-core.la
libtool: link: gcc -g -O2 -o udevd udevd.o  ./.libs/libudev-core.a

It does link with static libudev-core, which is good, but the binary itself remain dynamic. if I drop 'udevd' and manually execute the gcc at linking phase adding '-static'

# gcc -g -O2 -static -o udevd udevd.o  ./.libs/libudev-core.a

I do indeed get fully statically linked executable that I can transfer to glibc system and have it run there

Would that be possible for you to add '--enable-static_link' or another option that would produce all the executables really static?

slashbeast commented 2 years ago

Looks like it can be quick hacked after all, by passing 'LDFLAGS="-all-static" as make's argv rather than setting LDFLAGS as environmental variable, as this would break configure tests, and '-all-static' is libtool flag.

./configure
make LDFLAGS="-all-static"

Seems to work just fine.

bbonev commented 2 years ago

Thank you for the report, can you provide a PR to get this info documented?

bbonev commented 1 year ago

I am closing the issue, in case you decide to provide a PR, that will be welcomed