[PATCH] libtraceevent: Do not change names of functions not of this library

Steven Rostedt <[email protected]> Tue, 30 Dec 2025 10:30:00 -0500
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
From: "Steven Rostedt (Google)" <[email protected]>

The hidden attribute is used for functions within the library that are
not to be exported. They do not have name space naming which is not a
problem for the shared library, because the hidden attribute hides them
from being linked.

But these functions are not protected by the hidden attribute for the
static library. The build was modified to run 'nm' on the shared library
and any hidden function found that does not start with 'tep_' would have
its name changed to 'tep_local_<name>'.

A problem occurred where on x86_32 systems, gcc adds other functions like:

  __stack_chk_fail_local
  __udivdi3
  __umoddi

and these too were converted. But by doing so, it caused the "make test"
build to fail (make test uses the static library):

  /usr/bin/ld: lib/libtraceevent.a(event-parse.o): in function `consolidate_op_arg':
  src/event-parse.c:2302: undefined reference to `_tep_local___udivdi3'
  /usr/bin/ld: src/event-parse.c:2305: undefined reference to `_tep_local___umoddi3'
  /usr/bin/ld: lib/libtraceevent.a(event-parse.o): in function `eval_num_arg':
  src/event-parse.c:4561: undefined reference to `_tep_local___udivdi3'
  /usr/bin/ld: src/event-parse.c:4564: undefined reference to `_tep_local___umoddi3'
  /usr/bin/ld: lib/libtraceevent.a(event-parse.o): in function `print_event_time':
  src/event-parse.c:7168: undefined reference to `_tep_local___udivdi3'
  /usr/bin/ld: src/event-parse.c:7175: undefined reference to `_tep_local___umoddi3'
  /usr/bin/ld: src/event-parse.c:7175: undefined reference to `_tep_local___udivdi3'
  collect2: error: ld returned 1 exit status
  make[1]: *** [Makefile:22: utest/trace-utest] Error 1
  make: *** [Makefile:258: test] Error 2

Read the 'nm' symbols of the temporary static library and record only the
functions that have an address. As the above gcc functions are still
undefined there. Then this will only convert functions that are defined by
the static library and not added by the compiler.

Also add the missing .gitignore file to hide these temp files.

Reported-by: Vitaly Chikunov <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Fixes: 399f8462ff1b1 ("libtraceevent: Have static library to hide hidden functions")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
---
 scripts/utils.mk | 4 ++--
 src/.gitignore   | 2 ++
 src/Makefile     | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)
 create mode 100644 src/.gitignore

diff --git a/scripts/utils.mk b/scripts/utils.mk
index 7cd7355b811f..381e5430e97e 100644
--- a/scripts/utils.mk
+++ b/scripts/utils.mk
@@ -183,5 +183,5 @@ endef
 
 # Make all global functions that do not start with "tep_" have a unique name.
 redefine_local = \
-	$(shell for f in a `nm $(1) 2>/dev/null | grep ' t ' | cut -d' ' -f3 | sort -u`;  do \
-	 if [ "$${f#tep_}" = "$$f" ]; then echo --redefine-sym $$f=_tep_local_$$f; fi; done)
+	$(shell nm $(2) 2>/dev/null | grep '[0-9a-f] t ' > .tmp.func-list; for f in a `nm $(1) 2>/dev/null | grep ' t ' | cut -d' ' -f3 | sort -u`;  do \
+	 if [ "$${f#tep_}" = "$$f" ]; then if grep -q $$f .tmp.func-list; then echo --redefine-sym $$f=_tep_local_$$f; fi; fi; done)
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 000000000000..f5735328db43
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,2 @@
+.tmp.libtraceevent.a
+.tmp.func-list
diff --git a/src/Makefile b/src/Makefile
index 4f16b81bb989..e6ece616e5d4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,7 @@ $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
 $(LIBTRACEEVENT_STATIC): $(bdir)/.tmp.libtraceevent.a $(LIBTRACEEVENT_SHARED)
-	$(Q)objcopy $(call redefine_local,${LIBTRACEEVENT_SHARED}) $< $@
+	$(Q)objcopy $(call redefine_local,${LIBTRACEEVENT_SHARED},$<) $< $@
 
 $(bdir)/.tmp.libtraceevent.a: $(OBJS)
 	$(Q)$(call do_build_static_lib)
@@ -49,7 +49,7 @@ $(DEPS): | $(bdir)
 
 clean:
 	$(Q)$(call do_clean,$(OBJS) $(DEPS) $(bdir)/libtraceevent.o \
-	                    $(bdir)/.tmp.libtraceevent.a)
+	                    $(bdir)/.tmp.libtraceevent.a $(bdir)/.tmp.func-list)
 
 dep_includes := $(wildcard $(DEPS))
 
-- 
2.51.0