[lttng-dev] [PATCH] Fix: multiple definition error with gcc 5.1

Zifei Tong zifeitong at gmail.com
Mon Apr 27 17:31:45 EDT 2015


When building lttng-tools with gcc 5.1, I saw the following error:
  ../../../src/common/.libs/libcommon.a(mi-lttng.o):(.data.rel.ro.local+0x0):
      multiple definition of `mi_lttng_element_snapshots'
  commands/enable_events.o:(.bss+0x30): first defined here
  collect2: error: ld returned 1 exit status

The output of `nm enable_events.o` shows that the mi_lttng_element_snapshots
was put in the uninitialized data section (BSS), but not a common symbol
which it should be. This causes the multiple definition error.

This issue was also found by others [1], who fixes by declaring
`mi_lttng_element_snapshots' and friends as 'extern'.

However, the root cause I believe is an undefined behavior of accessing
uninitialized variable 'opt_function_entry_symbol' in enable_events.c.
The UB causes Identical Code Folding (ICF) added in gcc 5.x generates
wrong output (fipa-icf is default in -O2, and compiing with -fno-ipa-icf
works just fine).

This patch comments out the accessing of `opt_function_entry_symbol`
which is not used anymore.

[1]: http://permalink.gmane.org/gmane.comp.handhelds.openembedded.core/62798

Signed-off-by: Zifei Tong <zifeitong at gmail.com>
---
 src/bin/lttng/commands/enable_events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c
index ab32994..4b86a30 100644
--- a/src/bin/lttng/commands/enable_events.c
+++ b/src/bin/lttng/commands/enable_events.c
@@ -52,7 +52,6 @@ static int opt_python;
 static int opt_enable_all;
 static char *opt_probe;
 static char *opt_function;
-static char *opt_function_entry_symbol;
 static char *opt_channel_name;
 static char *opt_filter;
 static char *opt_exclude;
@@ -1053,11 +1052,13 @@ static int enable_events(char *session_name)
 					goto error;
 				}
 				break;
+#if 0
 			case LTTNG_EVENT_FUNCTION_ENTRY:
 				strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol,
 						LTTNG_SYMBOL_NAME_LEN);
 				ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
 				break;
+#endif
 			case LTTNG_EVENT_SYSCALL:
 				ev.type = LTTNG_EVENT_SYSCALL;
 				break;
-- 
2.3.5




More information about the lttng-dev mailing list