Skip to content

Commit

Permalink
build: Do not use libelf in the python extension
Browse files Browse the repository at this point in the history
The python extension module is to trace python functions and it doesn't
need to deal with ELF files in general.  The only place needed is to get
the address of libmcount functions.  As it's the minimal functionality,
we can force to use the symbol-rawelf code by removing HAVE_LIBELF
definition in the PYTHON_CFLAGS.  It'd make it lighter without further
dependency.

But this requires separate handling the object files for the python
module.  Let's use a different object file suffix (.oy) to apply the
compiler flags separately.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Feb 26, 2024
1 parent ccdf9c6 commit 8d01502
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ BENCH_OBJS := $(patsubst $(srcdir)/%.c,$(objdir)/%.o,$(BENCH_SRCS))
PYTHON_SRCS := $(srcdir)/python/trace-python.c $(srcdir)/utils/debug.c
PYTHON_SRCS += $(srcdir)/utils/utils.c $(srcdir)/utils/rbtree.c $(srcdir)/utils/shmem.c
PYTHON_SRCS += $(wildcard $(srcdir)/utils/symbol-*.c)
PYTHON_OBJS := $(patsubst $(srcdir)/%.c,$(objdir)/%.op,$(PYTHON_SRCS))
PYTHON_OBJS := $(patsubst $(srcdir)/%.c,$(objdir)/%.oy,$(PYTHON_SRCS))

UFTRACE_ARCH_OBJS := $(objdir)/arch/$(ARCH)/uftrace.o

Expand Down Expand Up @@ -351,7 +351,10 @@ $(objdir)/misc/bench: $(BENCH_OBJS)
$(QUIET_LINK)$(CC) $(BENCH_CFLAGS) -o $@ $(BENCH_OBJS) $(BENCH_LDFLAGS)

ifneq ($(findstring HAVE_LIBPYTHON, $(COMMON_CFLAGS)), )
$(PYTHON_OBJS): $(objdir)/%.op: $(srcdir)/%.c $(COMMON_DEPS)
# Remove libelf/libdw dependency for the python extension
PYTHON_CFLAGS := $(filter-out -DHAVE_LIBELF,$(PYTHON_CFLAGS))

$(PYTHON_OBJS): $(objdir)/%.oy: $(srcdir)/%.c $(COMMON_DEPS)
$(QUIET_CC_FPIC)$(CC) $(PYTHON_CFLAGS) -c -o $@ $<

$(objdir)/python/uftrace_python.so: $(PYTHON_OBJS)
Expand Down Expand Up @@ -438,7 +441,8 @@ clean:
$(call QUIET_CLEAN, uftrace)
$(Q)$(RM) $(objdir)/*.o $(objdir)/*.op $(objdir)/*.so $(objdir)/*.a
$(Q)$(RM) $(objdir)/cmds/*.o $(objdir)/utils/*.o $(objdir)/misc/*.o
$(Q)$(RM) $(objdir)/utils/*.op $(objdir)/libmcount/*.op $(objdir)/python/*.op
$(Q)$(RM) $(objdir)/utils/*.op $(objdir)/libmcount/*.op
$(Q)$(RM) $(objdir)/utils/*.oy $(objdir)/python/*.oy
$(Q)$(RM) $(objdir)/gmon.out $(srcdir)/scripts/*.pyc $(TARGETS)
$(Q)$(RM) $(objdir)/uftrace-*.tar.gz $(objdir)/version.h
$(Q)find -name "*\.gcda" -o -name "*\.gcno" | xargs $(RM)
Expand Down

0 comments on commit 8d01502

Please sign in to comment.