Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] Static linking (try it at home!) [was: kernel update snafu]
- Date: Fri, 20 Jun 2014 15:46:39 +0900
- From: "Stephen J. Turnbull" <stephen@example.com>
- Subject: [tlug] Static linking (try it at home!) [was: kernel update snafu]
- References: <CABHGxq578Vh4zFgTRRc2JKtWz=ua74J5bdJULNQeTzyeD6hkxQ@mail.gmail.com> <53A1726F.5030500@imaginatorium.org> <CAAhy3duLPCTPQ3SwO896mOXRHXrMQMSQj_JgeGWZLZgTDW8XCg@mail.gmail.com> <CAKXLc7ebGJbRB5sE9cHXa7JeTixcD-hCL3HdAmF363ikK5B_aw@mail.gmail.com> <CAAhy3duOKji5UNbz2UMmq5jKXqi0e=_dG4Csh2EAt1sUA1m-NQ@mail.gmail.com>
Raymond Wan writes: > > AFAIR, you cannot statically link glibc. So you'll need 32-bit glibc. > > Basically if you can run other 32-bit software you should be fine. > > Ah...I guess I never ran a 32-bit program on this system before. And > I didn't know that you cannot statistically link to glibc. I fed it > to "ldd" and it didn't report that. I don't think that's strictly true. Remember, a static library is *not* a monolithic object file, but rather a bundle of objects each of which will be added to the resulting binary "as needed" (ie, if an entry point is referenced by a module already linked in the program). So if all you want to do is use printf, you *can* statically link. It's not even hard. Eg, consider test.c: #include <stdio.h> #include <stdlib.h> int main (int c, char *v[]) { printf("Hello, TLUG!"); exit(0); } Then compile with "gcc -o dtest test.c", giving a binary of 8044 bytes, dynamically linked (according to ldd) to linux-vdso.so.1, libc.so.6, and /lib64/ld-linux-x86-64.so.2. Runs fine, produces expected output. Now compile with "gcc -static -o stest test.c", giving a binary of 973252 (!) bytes which is *not* dynamically linked (according to ldd), but it runs fine, and produces expected output (on my system, YMMV). N.B. file(1) agrees which is dynamic and which is static. Stripping the binaries slims (?) them down to 6216 and 750808 bytes, respectively. ISTR that some components of glibc (IIRC nss, the Name Service Switch is one) are not supposed to be linked statically for some reason. In glibc (it's specific to glibc), "nss" is not (just) the DNS, it's a whole bunch of things where the system needs to map names to objects. So for many programs you'll need to do some dynamic linking anyway. Of course, glibc is free software; I'm sure it's *possible* to statically link everything you need somehow, although you may have to compile the glibc objects yourself and list them as .o files in the gcc command. TLUG historical reference: Steve Baur claimed to have a collection of statically linked Emacsen going back to Emacs 18.55, and bash or zsh of similar age which still ran, without recompiling, on any Linux system (on 32-bit x86 hardware, of course) as of 2007 or so. That meant he could boot a "useful" system with only two files: vmlinux and xemacs (linked to "/sbin/init" :-). ELispM, anyone? (Didn't think so, but hey, had to try!)
- Follow-Ups:
- Re: [tlug] Static linking (try it at home!) [was: kernel update snafu]
- From: Kalin KOZHUHAROV
- Re: [tlug] Static linking (try it at home!) [was: kernel update snafu]
- From: Raymond Wan
- References:
- [tlug] Ubuntu 10.04 - kernel update snafu
- From: Jim Breen
- Re: [tlug] Ubuntu 10.04 - kernel update snafu
- From: Brian Chandler
- Re: [tlug] Ubuntu 10.04 - kernel update snafu
- From: Raymond Wan
- Re: [tlug] Ubuntu 10.04 - kernel update snafu
- From: Kalin KOZHUHAROV
- Re: [tlug] Ubuntu 10.04 - kernel update snafu
- From: Raymond Wan
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Places where to apply to for a technical internship?
- Next by Date: Re: [tlug] Static linking (try it at home!) [was: kernel update snafu]
- Previous by thread: Re: [tlug] Ubuntu 10.04 - kernel update snafu
- Next by thread: Re: [tlug] Static linking (try it at home!) [was: kernel update snafu]
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links