简体   繁体   中英

How to build glibc with reduced size?

I'm trying to download glibc 2.23 sources and build them on my Ubuntu system. I need to build that specific version from sources for getting modified version of glibc customized for my research, and it will be used only within my research apps using the loader environment variables (eg, LD_PREDLOAD or LD_LIBRARY_PATH).

But, when building it as following, I got a huge file as an output (libc.so weights about 11MB):

  • download the sources to some local dir (let's say /tmp/glibc/)
  • create new directory for build results (/tmp/glibc/build)
  • run configure from build dir:
  • < build-dir >$ ../configure --prefix=< build-dir > As a result, the build process will produce libc.so file under build-dir with a size of 11MB.

Is there anyway to reduce the size of the built libc.so?

ps

Here are my system details: Linux version 4.4.0-93-generic (buildd@lgw01-03) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017

Thanks :)

Building glibc from source could be a bad idea. See this and some comments there. Its current version is GNU libc 2.26 ... Consider instead upgrading your entire Ubuntu distribution (Ubuntu 17.10 should be released in a few weeks, end of October 2017)

../configure --prefix= build-dir

is a misunderstanding of the role of --prefix in autoconf -ed software. It relates to where the software is installed, not to its build directory.

(and I don't know exactly what should be your --prefix since libc is so essential to your system, perhaps it should be --prefix=/ but you should check carefully)

Is there any way to reduce the size of the built libc.so?

You might use (very carefully) strip(1) , but you risk breaking your system.

And you might not care about reducing the size of libc since it is used (and shared ) by almost every software on your Linux system!

BTW, consider also musl-libc . It can cohabit nicely with GNU glibc, and in practice is used only by programs built with musl-gcc (provided by it).

If you are doing some research, it would be reasonable to work in a chroot(2) -ed environment. See also schroot . You could install with the help of make install DESTDIR=/tmp/instmylibc then copy that /tmp/instmylibc appropriately. Read more about autoconf

PS. Be sure to at least back up your important data before such dangerous experimentations. I don't think that the size of your libc.so should be a significant concern. But you need to use chroot , perhaps with the help of debootstrap during installation of the chroot ed environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM