This commit introduces a build-time feature test for the elfutils libasm library in the shared tools/build system. It adds the test program and updates the Makefiles to attempt building it to detect support. Note on static linking: pkg-config for libdw/libelf on modern systems does not list -lebl as a dependency. Older versions of elfutils that require explicitly linking -lebl statically are unsupported by this feature check. --- tools/build/Makefile.feature | 2 ++ tools/build/feature/Makefile | 9 +++++++++ tools/build/feature/test-libasm.c | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 tools/build/feature/test-libasm.c diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index ed1374af31c1..422329dbc20a 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -118,6 +118,7 @@ FEATURE_TESTS_EXTRA := \ hello \ babeltrace2-ctf-writer \ libcapstone \ + libasm \ libcheck \ libbfd-liberty \ libbfd-liberty-z \ @@ -150,6 +151,7 @@ FEATURE_DISPLAY ?= \ numa_num_possible_cpus \ libpython \ libcapstone \ + libasm \ llvm-perf \ zlib \ lzma \ diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 62909a9c799d..f0f39a2ab203 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -47,6 +47,7 @@ FILES= \ test-timerfd.bin \ test-babeltrace2-ctf-writer.bin \ test-libcapstone.bin \ + test-libasm.bin \ test-libcheck.bin \ test-compile-32.bin \ test-compile-x32.bin \ @@ -184,6 +185,11 @@ ifeq ($(findstring -static,${LDFLAGS}),-static) DWARFLIBS += -ldl endif +ASMLIBS := -lasm -ldw -lelf +ifeq ($(findstring -static,${LDFLAGS}),-static) + ASMLIBS += -lz -llzma -lbz2 -lzstd +endif + $(OUTPUT)test-libdw.bin: $(BUILD) $(DWLIBS) @@ -311,6 +317,9 @@ $(OUTPUT)test-babeltrace2-ctf-writer.bin: $(OUTPUT)test-libcapstone.bin: $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone) +$(OUTPUT)test-libasm.bin: + $(BUILD) $(ASMLIBS) + $(OUTPUT)test-libcheck.bin: $(BUILD) # -lcheck is provided by $(FEATURE_CHECK_LDFLAGS-libcheck) diff --git a/tools/build/feature/test-libasm.c b/tools/build/feature/test-libasm.c new file mode 100644 index 000000000000..f3598ad1cc9e --- /dev/null +++ b/tools/build/feature/test-libasm.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +typedef struct ebl Ebl; +extern Ebl *ebl_openbackend (Elf *elf); +extern void ebl_closebackend (Ebl *ebl); + +int main(void) +{ + Elf *elf = elf_begin(0, ELF_C_READ, NULL); + Ebl *ebl = ebl_openbackend(elf); + DisasmCtx_t *ctx = disasm_begin(ebl, elf, NULL); + disasm_end(ctx); + ebl_closebackend(ebl); + elf_end(elf); + return 0; +} -- 2.54.0.1064.gd145956f57-goog