[CRIU] [PATCH 0/2] make: Add compile time testing for system headers
Kir Kolyshkin
kir at openvz.org
Tue May 7 16:37:43 EDT 2013
On 05/07/2013 01:08 PM, Cyrill Gorcunov wrote:
> On Tue, May 07, 2013 at 11:26:47PM +0400, Pavel Emelyanov wrote:
>> On 05/07/2013 11:14 PM, Cyrill Gorcunov wrote:
>>> On Tue, May 07, 2013 at 11:08:37PM +0400, Pavel Emelyanov wrote:
>>>> 2 things bother me.
>>>>
>>>> 1. tcp piggie compilation fail may be not due to structs duplication
>>>> 2. code duplication between sk-tcp.c and utilities.mak
>>> At moment we address only name clashes (struct and enums), thus if we
>>> need more precise (per-member check or say size of structure check) this
>>> facility won't be enough for sure. But I must admit I don't fully understand
>>> (1), could you please elaborate?
>> I mean "name clash => compilation fail", but the reverse statement is not true,
>> while we rely on it.
> But the test is exactly for name redefinition detection, nothing more ;)
> If compilation fail we will have to investigate what's gone wrong anyway.
>
May I suggest a proper test for this? I just took a look at how autoconf
does it.
What they have is AC_CHECK_MEMBER macro which checks for a specific member
in a structure. The code generated (except for #includes) looks like this:
#include <HEADERNAME>
int main () {
static struct STRUCTNAME ac_aggr;
if (ac_aggr.FIELDNAME)
return 0;
return 0;
}
I think this is what we should do, too, to check is struct is defined,
using any field.
Similar to autotools, we can have a template for such check, compiling
it with
-D STRUCTNAME=tcp_repair_opt -D FIELDNAME=opt_val -D
HEADERNAME=netinet/tcp.h
Or maybe just
#include <HEADERNAME>
int main() {
static struct STRUCTNAME name;
return 0;
}
The idea is the only reason such code should fail to compile is when
struct is undefined,
or header file is not found (for which we can add another test if needed).
More information about the CRIU
mailing list