Skip to contentSkip to conversation

trace-cruncher: Build trace-obj-debug.c as library

PATCH Superseded Yordan Karadzhov (VMware) 2 participants 2 messages Apr 30, 2022 – May 2, 2022 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 trace-cruncher: Build trace-obj-debug.c as library

The code for resolving virtual address to function name gets build as shared library. The library is installed as package data. Later this library can be used by the different sub-modules of tracecruncher.

---

This patch applies on top of the patch:
https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Fixing the problem of '$ORIGIN' not being properly added to the 'RUNPATH' of the shared libraries, built by the sub-modules.

 Makefile | 24 +++++++++++++++++++++---
 setup.py |  4 ++--
 2 files changed, 23 insertions(+), 5 deletions(-)
Makefile +21 -3
index 52428c0..9b62c4a 100644
@@ -13,13 +13,31 @@ NC	:= '\e[0m'
 
 DOCDIR = ./docs
 
-all:
+CC = gcc
+CFLAGS = -fPIC -Wall -Wextra -O2 -g
+LDFLAGS = -shared
+RM = rm -rf
+
+DBG_LIB = tracecruncher/libobjdebug.so
+PY_SETUP = setup
+
+DBG_SRCS = src/trace-obj-debug.c
+DBG_OBJS = src/trace-obj-debug.o
+
+all: $(DBG_LIB) $(PY_SETUP)
 	@ echo ${CYAN}Buildinging trace-cruncher:${NC};
+
+$(PY_SETUP):
 	python3 setup.py build
 
+$(DBG_LIB): $(DBG_OBJS)
+	$(CC) ${LDFLAGS} -o $@ $^ -L./tracecruncher -lbfd
+
 clean:
-	rm -f src/npdatawrapper.c
-	rm -rf build
+	${RM} src/npdatawrapper.c
+	${RM} $(DBG_LIB)
+	${RM} src/*.o
+	${RM} build
 
 install:
 	@ echo ${CYAN}Installing trace-cruncher:${NC};
setup.py +2 -2
index 58561cf..d9e296b 100644
@@ -37,7 +37,7 @@ def add_library(lib, min_version,
         libs_found.extend([(lib, lib_version)])
 
 def third_party_paths():
-    library_dirs = []
+    library_dirs = ['$ORIGIN', 'tracecruncher']
     include_dirs = [np.get_include()]
     libs_required = [('libtraceevent', '1.5.0'),
                      ('libtracefs',    '1.3.0'),
@@ -61,7 +61,6 @@ include_dirs, library_dirs = third_party_paths()
 
 def extension(name, sources, libraries):
     runtime_library_dirs = library_dirs
-    runtime_library_dirs.extend('$ORIGIN')
     return Extension(name, sources=sources,
                            include_dirs=include_dirs,
                            library_dirs=library_dirs,
@@ -91,6 +90,7 @@ def main():
           url='https://github.com/vmware/trace-cruncher',
           license='LGPL-2.1',
           packages=find_packages(),
+          package_data={'tracecruncher': ['libobjdebug.so']},
           ext_modules=[module_ft, module_data, module_ks],
           classifiers=[
               'Development Status :: 4 - Beta',
Signature · 1 line
2.32.0
#1 lore raw
Quoted 24 lines · Yordan Karadzhov (VMware)

The code for resolving virtual address to function name gets build as shared library. The library is installed as package data. Later this library can be used by the different sub-modules of tracecruncher.

---

This patch applies on top of the patch:
https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Fixing the problem of '$ORIGIN' not being properly added to the 'RUNPATH' of the shared libraries, built by the sub-modules.

 Makefile | 24 +++++++++++++++++++++---
 setup.py |  4 ++--
 2 files changed, 23 insertions(+), 5 deletions(-)
Makefile +0 -0
index 52428c0..9b62c4a 100644

Makefile NC := '\e[0m' · line 21

Quoted 10 lines
Makefile +6 -1
@@ -13,13 +13,31 @@ NC  := '\e[0m'
 
 DOCDIR = ./docs
 
-all:
+CC = gcc
+CFLAGS = -fPIC -Wall -Wextra -O2 -g
+LDFLAGS = -shared
+RM = rm -rf
+
+DBG_LIB = tracecruncher/libobjdebug.so

Having an internal library to share and reuse code is very useful. It can be used for a lot of common code, not only for bfd wrappers. Please, can you change the name of the library to be more common? I would suggest libtccommon.so, libtcbase.so or something like that. Thanks!

Quoted 56 lines
Makefile +15 -2
+PY_SETUP = setup
+
+DBG_SRCS = src/trace-obj-debug.c
+DBG_OBJS = src/trace-obj-debug.o
+
+all: $(DBG_LIB) $(PY_SETUP)
        @ echo ${CYAN}Buildinging trace-cruncher:${NC};
+
+$(PY_SETUP):
        python3 setup.py build
 
+$(DBG_LIB): $(DBG_OBJS)
+       $(CC) ${LDFLAGS} -o $@ $^ -L./tracecruncher -lbfd
+
 clean:
-       rm -f src/npdatawrapper.c
-       rm -rf build
+       ${RM} src/npdatawrapper.c
+       ${RM} $(DBG_LIB)
+       ${RM} src/*.o
+       ${RM} build
 
 install:
        @ echo ${CYAN}Installing trace-cruncher:${NC};
setup.py +2 -3
index 58561cf..d9e296b 100644
@@ -37,7 +37,7 @@ def add_library(lib, min_version,
         libs_found.extend([(lib, lib_version)])
 
 def third_party_paths():
-    library_dirs = []
+    library_dirs = ['$ORIGIN', 'tracecruncher']
     include_dirs = [np.get_include()]
     libs_required = [('libtraceevent', '1.5.0'),
                      ('libtracefs',    '1.3.0'),
@@ -61,7 +61,6 @@ include_dirs, library_dirs = third_party_paths()
 
 def extension(name, sources, libraries):
     runtime_library_dirs = library_dirs
-    runtime_library_dirs.extend('$ORIGIN')
     return Extension(name, sources=sources,
                            include_dirs=include_dirs,
                            library_dirs=library_dirs,
@@ -91,6 +90,7 @@ def main():
           url='https://github.com/vmware/trace-cruncher',
           license='LGPL-2.1',
           packages=find_packages(),
+          package_data={'tracecruncher': ['libobjdebug.so']},
           ext_modules=[module_ft, module_data, module_ks],
           classifiers=[
               'Development Status :: 4 - Beta',
--

2.32.0

Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center