[CRIU] Re: [PATCH 1/2] make: Shrink amount of generated defines for parasite code

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 23 04:17:14 EDT 2012


On Fri, Mar 23, 2012 at 11:54:31AM +0400, Pavel Emelyanov wrote:
> On 03/23/2012 02:47 AM, Cyrill Gorcunov wrote:
> > No need to include every symbol found in generated object
> > files, just define the minimum we need (after all we do not
> > filter names by symbol types, so one day it might become
> > a problem in names collision).
> > 
> > Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> 
> I don't want to keep in mind the fact that once a new symbol
> is added I need to patch one more file. Why is "exporting"
> everything is bad? 

Because symbols may be defined in several places and we might get
the situation where symbols are redefined. Look what I just hit
in my dev local branch

[cyrill at moon crtools]$ make all
  CC       parasite-syscall.o
In file included from parasite-syscall.c:29:0: parasite-blob.h:15:0: error: "parasite_blob_offset__change_bit" redefined [-Werror]

(Side note, as I said it's my local dev branch where I'm working
 on syscalls table creation and such, so you can't hit this problem
 yet)

This is because the change_bit() helper is defined in two places

[cyrill at moon crtools]$ nm parasite.bin.o | grep "change_bit"
000000000000285f t change_bit
000000000000385f t change_bit

000000000000385f <change_bit>:
    385f:	55                   	push   %rbp
    3860:	48 89 e5             	mov    %rsp,%rbp
    3863:	89 7d fc             	mov    %edi,-0x4(%rbp)
    3866:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
    386a:	48 8b 45 f0          	mov    -0x10(%rbp),%rax
    386e:	8b 55 fc             	mov    -0x4(%rbp),%edx
    3871:	48 8b 4d f0          	mov    -0x10(%rbp),%rcx
    3875:	0f bb 10             	btc    %edx,(%rax)
    3878:	5d                   	pop    %rbp
    3879:	c3                   	retq   

000000000000285f <change_bit>:
    285f:	55                   	push   %rbp
    2860:	48 89 e5             	mov    %rsp,%rbp
    2863:	89 7d fc             	mov    %edi,-0x4(%rbp)
    2866:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
    286a:	48 8b 45 f0          	mov    -0x10(%rbp),%rax
    286e:	8b 55 fc             	mov    -0x4(%rbp),%edx
    2871:	48 8b 4d f0          	mov    -0x10(%rbp),%rcx
    2875:	0f bb 10             	btc    %edx,(%rax)
    2878:	5d                   	pop    %rbp
    2879:	c3                   	retq   

As you see the functions are the same on machine level, and they
are defined twice in generated object file simply because

 1) no optimization were turned on
 2) two object files were linked via ld script while
    always_inline used for prototypes so gcc simply put
    a copy into every file it compiles.

There will be no duplications once I finish my dances with syscall
table (I've hit different issue which I dont know yet how to resolve
in this area).

But all this duplicated symbols problem made me think -- why the hell
this all is that complex, the idea behind parasite and restorer was that

 1) Have a single entry point for each parasite/restorer (by signle entry
    point I mean a couple of known offsets which we define in -blob.h),
    NOT every symbol found in file.

 2) Everything else should be defined as a "protocol". For parasite we do
    send command and argumens, nothing else is needed. If we ever need one
    more symbol -- we should consider it with very suspicious.

    For restorer we simply need two entry points, because everything else
    also defined as a part of protocol (we allocate space for argumens).

    Actually for restorer I would suggest to implement the same protocol
    as defined for parasite for unification, but this can wait.

	Cyrill


More information about the CRIU mailing list