Fix: Static build on OS X
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 4 lines · ----- On May 4, 2016, at 10:54 AM, Michael Jeanson [email protected] 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 ?
Thanks,
Mathieu
Quoted 26 lines
Signed-off-by Michael Jeanson <[email protected]>---
lib/babeltrace.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)lib/babeltrace.c +1
-1@@ -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
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 7 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Mathieu Desnoyers
Quoted 4 lines · ----- On May 4, 2016, at 10:54 AM, Michael Jeanson [email protected] 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.
Quoted 6 lines
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
Quoted 36 lines
Thanks,
Mathieu
Quoted 22 lines
Signed-off-by Michael Jeanson <[email protected]>---
lib/babeltrace.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)lib/babeltrace.c +1
-1@@ -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.4Quoted 4 lines
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
Signature · 7 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Quoted 7 lines · ----- On May 4, 2016, at 11:57 AM, Mathieu Desnoyers…
Quoted 4 lines · ----- On May 4, 2016, at 10:54 AM, Michael Jeanson [email protected] 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.
Quoted 5 lines
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 ?
I'm open to a better solution but after consulting with Jérémie and Philippe it's the best we came up with to fix static compilation on OS X.
Quoted 1 line
Why not elsewhere ?
Seems to be related to an object file that contains "common" symbols and no other directly referenced symbols other than a constructor which happens only with lib/babeltrace.o in the current tree.
Quoted 5 lines
Thanks,
Mathieu
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev