[CRIU] How to compile criu static binary

Christopher Covington cov at codeaurora.org
Mon Mar 9 07:09:40 PDT 2015


On 03/09/2015 09:47 AM, Christopher Covington wrote:
> Hi John,
> 
> On 03/09/2015 08:56 AM, Pavel Emelyanov wrote:
>> On 03/08/2015 02:31 PM, John Statham wrote:
>>> Is it possible to compile any version of criu binary statically ?
>>
>> We didn't try, but if the libraries we use allow for that, I see
>> no reason why it shouldn't work :)
>>
>>> If you have already tried this on any version of criu...could you
>>> provide some relevant source code/ changes for same.
> 
> We've done it with older versions, but my vague recollection is that the
> latest versions have problems in the test suite or libcriu or something like
> that, which being nonessential you can just not specify for building (test
> suite) or hack out of the makefiles (libcriu).

I just remembered I recently changed my build scripts to never build
statically because of this warning-turned-error:

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

plugin.c uses dlopen.

> My personal preference is to use dynamic linking but set the
> linker/loader/interpreter and library search path/rpath as needed for foreign
> systems. For example if you wanted to target a Debian multiarch style layout
> using a toolchain that doesn't default to that, you could pass (replacing the
> AArch64 examples with whatever target architecture you care about)
> 
> USERCFLAGS="-Wl,-dynamic-linker=/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
> -Wl,-rpath=/lib/aarch64-linux-gnu"
> 
> (Although in practice I use the more portable /lib/ld-linux-aarch64.so.1
> linker/loader/interpreter path.)
> 
> Something similar should work for /data/local on Android or /tmp or /opt on
> other Linux systems.
> 
> You can check that these flags correctly took effect, and also list out the
> libraries you need to make sure exist in RPATH, with the following commands.
> 
> aarch64-linux-gnu-readelf -a criu | grep -Ei '(interpr|needed|rpath)'
> 
> If the interpreter is set wrong, you'll probably get a criu not found or does
> not exist error (which at first I found confusing).
> 
> Alternatively, if you have an ELF that doesn't have INTERP and RPATH
> customized, you can achieve pretty much the same effect with:
> 
> LD_LIBRARY_PATH=/path/to/my/libs /path/to/my/ld-linux.so /path/to/criu
> 
> Mildly interesting CRIU corner case: last time I tried to dump and restore a
> process launched like this (such as `/lib64/ld-linux-x86-64.so.2 /bin/sleep
> infinity`) it failed because of funky /proc/self/exe issues, but this style of
> invocation is so obscure that I didn't know what the right way to fix it would
> be so I just installed my linker/loader/interpreter and libraries into INTERP
> and RPATH, respectively, and moved on.
> 
> Chris
> 


-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


More information about the CRIU mailing list