[lttng-dev] [PATCH babeltrace] Fix: Static build on OS X

Jérémie Galarneau jeremie.galarneau at efficios.com
Wed May 4 17:12:44 UTC 2016


On Wed, May 4, 2016 at 11:57 AM, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> ----- On May 4, 2016, at 10:54 AM, Michael Jeanson mjeanson at efficios.com wrote:
>
>> The OS X linker fails to resolve common symbols in a static
>> library for some unexplained reason. Initializing the variables
>> to zero makes the symbol become uninitialized data and fixes
>> the linking.
>
> We don't initialize static/global variables to 0/NULL ever in our
> coding style, presuming they are zeroed (similarly to the kernel
> coding style).
>
> Why should we diverge from this coding style in this specific instance ?
> Why not elsewhere ?

To provide more context, this is not a matter of diverging from the
coding style for the sake of style or to initialize the variable to
zero. This is done to work around a "quirk" of the Darwin tool-chain.

However, we should look into the reason why initializing the variable
changes the symbol's type.

>From section 3.5.7 of the C89 standard:

If an object that has static storage duration is not initialized
explicitly, it is initialized implicitly as if every member that has
arithmetic type were assigned 0 and every member that has pointer type
were assigned a null pointer constant.

In this respect, I would expect the assignation of "0" to be
functionally equivalent and not result in any observable change
whatsoever. I don't think this has changed in more recent versions of
the standard, but I may be wrong.

We can also add a dummy function to libbabeltrace and call it from
babeltrace.c. Still, I'd like to know why it works on linux and not on
OS X.

Jérémie

>
> Thanks,
>
> Mathieu
>
>>
>> Signed-off-by: Michael Jeanson <mjeanson at efficios.com>
>> ---
>> lib/babeltrace.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/babeltrace.c b/lib/babeltrace.c
>> index 0bcfd1d..f05808d 100644
>> --- a/lib/babeltrace.c
>> +++ b/lib/babeltrace.c
>> @@ -31,7 +31,7 @@
>> #include <babeltrace/ctf-text/types.h>
>> #include <stdlib.h>
>>
>> -int babeltrace_verbose, babeltrace_debug;
>> +int babeltrace_verbose = 0, babeltrace_debug = 0;
>>
>> static
>> void __attribute__((constructor)) init_babeltrace_lib(void)
>> --
>> 2.7.4
>>
>> _______________________________________________
>> lttng-dev mailing list
>> lttng-dev at lists.lttng.org
>> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list