This patch series fixes cross compilation issues.
The first two patches address the package configuration issue. It sets
the package path so the compiler can find the architecture's package.
The patch 03 sets the Python configuration path and renames the .so to
reflect the build target.
The last three patches fix the static build failures. Patch 04 is to fix
the issue caused by newer version's elfutils, and the last patches fix
the building failure for feature detecting binaries.
This patch series is tested for building perf on x86_64 host for Arm64
target.
Leo Yan (6):
perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
perf: build: Append libtraceevent path in PKG_CONFIG_LIBDIR
perf: build: Set Python configuration for cross compilation
perf: build: Only link libebl.a for old libdw
perf: build: Link lib 'lzma' for static build
perf: build: Link lib 'zstd' for static build
tools/build/feature/Makefile | 42 +++++++++++++++++++++++++++---------
tools/perf/Makefile.config | 25 +++++++++++++++++++--
tools/perf/Makefile.perf | 15 ++++++++++++-
3 files changed, 69 insertions(+), 13 deletions(-)
--
2.34.1
On recent Linux distros like Ubuntu Noble and Debian Bookworm, the
'pkg-config-aarch64-linux-gnu' package is missing. As a result, the
aarch64-linux-gnu-pkg-config command is not available, which causes
build failures.
Alternatively, this commit sets the PKG_CONFIG_LIBDIR environment
variable dynamically based on the cross compiler to ensure the correct
package configurations.
Signed-off-by: Leo Yan <[email protected]>
---
tools/build/feature/Makefile | 14 +++++++++++++-
tools/perf/Makefile.perf | 15 ++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index ed54cef450f5..6f52f892f9a3 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -82,7 +82,19 @@ FILES= \
FILES := $(addprefix $(OUTPUT),$(FILES))
-PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+PKG_CONFIG ?= pkg-config
+
+ifdef CROSS_COMPILE
+ ifndef PKG_CONFIG_LIBDIR
+ CROSS_ARCH = $(shell $(CC) -dumpmachine)
+ PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
+ export PKG_CONFIG_LIBDIR
+ endif
+endif
all: $(FILES)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 5c35c0d89306..c1553a546a4f 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -193,7 +193,20 @@ HOSTLD ?= ld
HOSTAR ?= ar
CLANG ?= clang
-PKG_CONFIG = $(CROSS_COMPILE)pkg-config
+PKG_CONFIG ?= pkg-config
+
+# Set the PKG_CONFIG_LIBDIR for cross compilation.
+ifdef CROSS_COMPILE
+ ifndef PKG_CONFIG_LIBDIR
+ CROSS_ARCH = $(shell $(CC) -dumpmachine)
+ PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
+ export PKG_CONFIG_LIBDIR
+ endif
+endif
RM = rm -f
LN = ln -f
--
2.34.1
The libunwind feature test failed with the static linkage. This is due
to the 'lzma' lib is missed, so link it to dismiss building failure.
Signed-off-by: Leo Yan <[email protected]>
---
tools/build/feature/Makefile | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 2f4cfb7b8c14..18aa6e654804 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -200,27 +200,27 @@ $(OUTPUT)test-numa_num_possible_cpus.bin:
$(BUILD) -lnuma
$(OUTPUT)test-libunwind.bin:
- $(BUILD) -lelf
+ $(BUILD) -lelf -llzma
$(OUTPUT)test-libunwind-debug-frame.bin:
- $(BUILD) -lelf
+ $(BUILD) -lelf -llzma
$(OUTPUT)test-libunwind-x86.bin:
- $(BUILD) -lelf -lunwind-x86
+ $(BUILD) -lelf -llzma -lunwind-x86
$(OUTPUT)test-libunwind-x86_64.bin:
- $(BUILD) -lelf -lunwind-x86_64
+ $(BUILD) -lelf -llzma -lunwind-x86_64
$(OUTPUT)test-libunwind-arm.bin:
- $(BUILD) -lelf -lunwind-arm
+ $(BUILD) -lelf -llzma -lunwind-arm
$(OUTPUT)test-libunwind-aarch64.bin:
- $(BUILD) -lelf -lunwind-aarch64
+ $(BUILD) -lelf -llzma -lunwind-aarch64
$(OUTPUT)test-libunwind-debug-frame-arm.bin:
- $(BUILD) -lelf -lunwind-arm
+ $(BUILD) -lelf -llzma -lunwind-arm
$(OUTPUT)test-libunwind-debug-frame-aarch64.bin:
- $(BUILD) -lelf -lunwind-aarch64
+ $(BUILD) -lelf -llzma -lunwind-aarch64
$(OUTPUT)test-libaudit.bin:
$(BUILD) -laudit
--
2.34.1
Since libdw version 0.177, elfutils has merged libebl.a into libdw (see
the commit "libebl: Don't install libebl.a, libebl.h and remove backends
from spec." in the elfutils repository).
As a result, libebl.a does not exist on Debian Bullseye and newer
releases, causing static perf builds to fail on these distributions.
This commit checks the libdw version and only links libebl.a if it
detects that the libdw version is older than 0.177.
Signed-off-by: Leo Yan <[email protected]>
---
tools/build/feature/Makefile | 12 +++++++++++-
tools/perf/Makefile.config | 12 +++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 6f52f892f9a3..2f4cfb7b8c14 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -159,7 +159,17 @@ $(OUTPUT)test-libopencsd.bin:
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
-DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
+ DWARFLIBS += -lelf -lz -llzma -lbz2
+
+ LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
+ LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
+ LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
+
+ # Elfutils merged libebl.a into libdw.a starting from version 0.177,
+ # Link libebl.a only if libdw is older than this version.
+ ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
+ DWARFLIBS += -lebl
+ endif
endif
$(OUTPUT)test-dwarf.bin:
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 646e5af0ed51..e8d3713b081c 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -152,7 +152,17 @@ ifdef LIBDW_DIR
endif
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
- DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
+ DWARFLIBS += -lelf -ldl -lz -llzma -lbz2
+
+ LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
+ LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
+ LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
+
+ # Elfutils merged libebl.a into libdw.a starting from version 0.177,
+ # Link libebl.a only if libdw is older than this version.
+ ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
+ DWARFLIBS += -lebl
+ endif
endif
FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
--
2.34.1
Python configuration has dedicated folders for different architectures.
For example, Python 3.11 has two folders as shown below, one for Arm64
and another for x86_64:
/usr/lib/python3.11/config-3.11-aarch64-linux-gnu/
/usr/lib/python3.11/config-3.11-x86_64-linux-gnu/
This commit updates the Python configuration path based on the
compiler's machine type, guiding the compiler to find the correct path
for Python libraries. It also renames the generated .so file name to
match the machine name.
Signed-off-by: Leo Yan <[email protected]>
---
tools/perf/Makefile.config | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index f545e0c3c176..646e5af0ed51 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -303,6 +303,11 @@ endif
ifdef PYTHON_CONFIG
PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
+ # Update the python flags for cross compilation
+ ifdef CROSS_COMPILE
+ PYTHON_NATIVE := $(shell echo $(PYTHON_EMBED_LDOPTS) | sed 's/\(-L.*\/\)\(.*-linux-gnu\).*/\2/')
+ PYTHON_EMBED_LDOPTS := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EMBED_LDOPTS))
+ endif
PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
@@ -904,6 +909,9 @@ else
PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no")
ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes)
PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])')
+ ifdef CROSS_COMPILE
+ PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX))
+ endif
LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX)
else
$(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent)
--
2.34.1
When build static perf, Makefile reports the error:
Makefile.config:480: No libdw DWARF unwind found, Please install
elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR
The libdw has been installed on the system, but the build system fails
to build the feature detecting binary 'test-libdw-dwarf-unwind'. The
failure is caused by missing to link the lib 'zstd'.
Link lib 'zstd' for the static build, in the end, the dwarf feature can
be enabled in the static perf.
Signed-off-by: Leo Yan <[email protected]>
---
tools/build/feature/Makefile | 2 +-
tools/perf/Makefile.config | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 18aa6e654804..80c237890a06 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -159,7 +159,7 @@ $(OUTPUT)test-libopencsd.bin:
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
- DWARFLIBS += -lelf -lz -llzma -lbz2
+ DWARFLIBS += -lelf -lz -llzma -lbz2 -lzstd
LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index e8d3713b081c..acd405bc46de 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -152,7 +152,7 @@ ifdef LIBDW_DIR
endif
DWARFLIBS := -ldw
ifeq ($(findstring -static,${LDFLAGS}),-static)
- DWARFLIBS += -lelf -ldl -lz -llzma -lbz2
+ DWARFLIBS += -lelf -ldl -lz -llzma -lbz2 -lzstd
LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
--
2.34.1
When a user specifies the path for libtraceevent, it means a self-built
package is being used instead of the distro package. This commit appends
the specified path in the variable 'PKG_CONFIG_LIBDIR', so that later
pkg-config can retrieve version info from the self-built folder.
Signed-off-by: Leo Yan <[email protected]>
---
tools/perf/Makefile.config | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 7f1e016a9253..f545e0c3c176 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -1181,7 +1181,10 @@ ifneq ($(NO_LIBTRACEEVENT),1)
CFLAGS += -DHAVE_LIBTRACEEVENT $(LIBTRACEEVENT_CFLAGS)
LDFLAGS += $(LIBTRACEEVENT_LDFLAGS)
EXTLIBS += ${TRACEEVENTLIBS}
- LIBTRACEEVENT_VERSION := $(shell PKG_CONFIG_PATH=$(LIBTRACEEVENT_DIR) $(PKG_CONFIG) --modversion libtraceevent)
+ ifdef LIBTRACEEVENT_DIR
+ PKG_CONFIG_LIBDIR := $(LIBTRACEEVENT_DIR):$(PKG_CONFIG_LIBDIR)
+ endif
+ LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent)
LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
--
2.34.1
Hi Leo,
On Tue, Jun 04, 2024 at 10:32:18AM +0100, Leo Yan wrote:
> On recent Linux distros like Ubuntu Noble and Debian Bookworm, the
> 'pkg-config-aarch64-linux-gnu' package is missing. As a result, the
> aarch64-linux-gnu-pkg-config command is not available, which causes
> build failures.
>
> Alternatively, this commit sets the PKG_CONFIG_LIBDIR environment
> variable dynamically based on the cross compiler to ensure the correct
> package configurations.
>
> Signed-off-by: Leo Yan <[email protected]>
> ---
> tools/build/feature/Makefile | 14 +++++++++++++-
> tools/perf/Makefile.perf | 15 ++++++++++++++-
> 2 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index ed54cef450f5..6f52f892f9a3 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -82,7 +82,19 @@ FILES= \
>
> FILES := $(addprefix $(OUTPUT),$(FILES))
>
> -PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
> +PKG_CONFIG ?= pkg-config
> +
> +ifdef CROSS_COMPILE
> + ifndef PKG_CONFIG_LIBDIR
Can we do that only if the cross-compile-pkg-config is not available?
Thanks,
Namhyung
> + CROSS_ARCH = $(shell $(CC) -dumpmachine)
> + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
> + export PKG_CONFIG_LIBDIR
> + endif
> +endif
>
> all: $(FILES)
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 5c35c0d89306..c1553a546a4f 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -193,7 +193,20 @@ HOSTLD ?= ld
> HOSTAR ?= ar
> CLANG ?= clang
>
> -PKG_CONFIG = $(CROSS_COMPILE)pkg-config
> +PKG_CONFIG ?= pkg-config
> +
> +# Set the PKG_CONFIG_LIBDIR for cross compilation.
> +ifdef CROSS_COMPILE
> + ifndef PKG_CONFIG_LIBDIR
> + CROSS_ARCH = $(shell $(CC) -dumpmachine)
> + PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
> + PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
> + export PKG_CONFIG_LIBDIR
> + endif
> +endif
>
> RM = rm -f
> LN = ln -f
> --
> 2.34.1
>
On Tue, Jun 04, 2024 at 10:32:21AM +0100, Leo Yan wrote:
> Since libdw version 0.177, elfutils has merged libebl.a into libdw (see
> the commit "libebl: Don't install libebl.a, libebl.h and remove backends
> from spec." in the elfutils repository).
>
> As a result, libebl.a does not exist on Debian Bullseye and newer
> releases, causing static perf builds to fail on these distributions.
>
> This commit checks the libdw version and only links libebl.a if it
> detects that the libdw version is older than 0.177.
>
> Signed-off-by: Leo Yan <[email protected]>
> ---
> tools/build/feature/Makefile | 12 +++++++++++-
> tools/perf/Makefile.config | 12 +++++++++++-
> 2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index 6f52f892f9a3..2f4cfb7b8c14 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -159,7 +159,17 @@ $(OUTPUT)test-libopencsd.bin:
>
> DWARFLIBS := -ldw
> ifeq ($(findstring -static,${LDFLAGS}),-static)
> -DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
> + DWARFLIBS += -lelf -lz -llzma -lbz2
> +
> + LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
> + LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
> + LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
> +
> + # Elfutils merged libebl.a into libdw.a starting from version 0.177,
> + # Link libebl.a only if libdw is older than this version.
> + ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
> + DWARFLIBS += -lebl
> + endif
> endif
Is there a better way to collect required libraries using pkg-config?
I guess that's what we want to with the pkg-config in the first place.
Maybe `pkg-config --print-requires-private libdw` ?
Thanks,
Namhyung
>
> $(OUTPUT)test-dwarf.bin:
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 646e5af0ed51..e8d3713b081c 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -152,7 +152,17 @@ ifdef LIBDW_DIR
> endif
> DWARFLIBS := -ldw
> ifeq ($(findstring -static,${LDFLAGS}),-static)
> - DWARFLIBS += -lelf -lebl -ldl -lz -llzma -lbz2
> + DWARFLIBS += -lelf -ldl -lz -llzma -lbz2
> +
> + LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
> + LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
> + LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
> +
> + # Elfutils merged libebl.a into libdw.a starting from version 0.177,
> + # Link libebl.a only if libdw is older than this version.
> + ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
> + DWARFLIBS += -lebl
> + endif
> endif
> FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
> FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
> --
> 2.34.1
>
Hi Namhyung,
On 6/6/24 18:28, Namhyung Kim wrote:
>> --- a/tools/build/feature/Makefile
>> +++ b/tools/build/feature/Makefile
>> @@ -82,7 +82,19 @@ FILES= \
>>
>> FILES := $(addprefix $(OUTPUT),$(FILES))
>>
>> -PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
>> +PKG_CONFIG ?= pkg-config
>> +
>> +ifdef CROSS_COMPILE
>> + ifndef PKG_CONFIG_LIBDIR
>
> Can we do that only if the cross-compile-pkg-config is not available?
Makes sense for me. I will update for this.
Thanks,
Leo
On 6/6/24 18:40, Namhyung Kim wrote:
[...]
>> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
>> index 6f52f892f9a3..2f4cfb7b8c14 100644
>> --- a/tools/build/feature/Makefile
>> +++ b/tools/build/feature/Makefile
>> @@ -159,7 +159,17 @@ $(OUTPUT)test-libopencsd.bin:
>>
>> DWARFLIBS := -ldw
>> ifeq ($(findstring -static,${LDFLAGS}),-static)
>> -DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
>> + DWARFLIBS += -lelf -lz -llzma -lbz2
>> +
>> + LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw)
>> + LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
>> + LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
>> +
>> + # Elfutils merged libebl.a into libdw.a starting from version 0.177,
>> + # Link libebl.a only if libdw is older than this version.
>> + ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
>> + DWARFLIBS += -lebl
>> + endif
>> endif
>
> Is there a better way to collect required libraries using pkg-config?
> I guess that's what we want to with the pkg-config in the first place.
> Maybe `pkg-config --print-requires-private libdw` ?
Unfortunately, `pkg-config --print-requires-private libdw` does not work
for the libebl.a after checked on Debian:buster.
# pkg-config --modversion libdw
0.176
# pkg-config --print-requires-private libdw
zlib
liblzma
# pkg-config --libs-only-l libdw
-ldw -lelf
# ldd /usr/lib/x86_64-linux-gnu/libdw.so
linux-vdso.so.1 (0x00007fff733e3000)
libelf.so.1 => /usr/lib/x86_64-linux-gnu/libelf.so.1 (0x0000702e24ec6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x0000702e24ec1000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x0000702e24ea3000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x0000702e24e7b000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x0000702e24e68000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000702e24ca8000)
/lib64/ld-linux-x86-64.so.2 (0x0000702e24f3e000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
(0x0000702e24c85000)
I think libdw.pc cannot reflect the required dependencies, we still need
to use a way liked in this patch (it is a bit ugly :) to link '-lebl'.
Thanks,
Leo