From 97b1d8744c037072056341c9749bfd54a6948f46 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Mon, 13 Sep 2021 15:01:15 +0200 Subject: [PATCH] Fix linking with static lib --- configure | 13 +++++++++++-- linux-user/main.c | 2 +- meson.build | 28 ++++++++++++++++++---------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 1692a0a5c4..ec986bc544 100755 --- a/configure +++ b/configure @@ -836,6 +836,7 @@ fi werror="" as_shared_lib="no" +as_static_lib="no" for opt do optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') @@ -1584,8 +1585,13 @@ for opt do ;; --as-shared-lib) as_shared_lib="yes" - QEMU_CFLAGS="$QEMU_CFLAGS -fPIC -DAS_SHARED_LIB=1" - QEMU_CXXFLAGS="$QEMU_CXXFLAGS -fPIC -DAS_SHARED_LIB=1" + QEMU_CFLAGS="$QEMU_CFLAGS -fPIC -DAS_LIB=1" + QEMU_CXXFLAGS="$QEMU_CXXFLAGS -fPIC -DAS_LIB=1" + ;; + --as-static-lib) + as_static_lib="yes" + QEMU_CFLAGS="$QEMU_CFLAGS -fPIC -DAS_LIB=1" + QEMU_CXXFLAGS="$QEMU_CXXFLAGS -fPIC -DAS_LIB=1" ;; *) echo "ERROR: unknown option $opt" @@ -4927,6 +4933,9 @@ fi if test "$as_shared_lib" = "yes" ; then echo "AS_SHARED_LIB=y" >> $config_host_mak fi +if test "$as_static_lib" = "yes" ; then + echo "AS_STATIC_LIB=y" >> $config_host_mak +fi echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak diff --git a/linux-user/main.c b/linux-user/main.c index 68e55ae483..aaaa7119db 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -654,7 +654,7 @@ int libafl_qemu_run(void) //// --- End LibAFL code --- -#ifdef AS_SHARED_LIB +#ifdef AS_LIB int qemu_user_init(int argc, char **argv, char **envp); __attribute__((section(".init_array"))) void *_qemu_user_init_ctr = &qemu_user_init; diff --git a/meson.build b/meson.build index c5c2c34ef8..8467315d91 100644 --- a/meson.build +++ b/meson.build @@ -2656,16 +2656,7 @@ foreach target : target_dirs exe_name += '-unsigned' endif - if 'AS_SHARED_LIB' in config_host - emulator = shared_library(exe_name, exe['sources'], - install: true, - c_args: c_args, - dependencies: arch_deps + deps + exe['dependencies'], - objects: lib.extract_all_objects(recursive: true), - link_language: link_language, - link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []), - link_args: link_args) - else + if 'AS_SHARED_LIB' not in config_host and 'AS_STATIC_LIB' not in config_host emulator = executable(exe_name, exe['sources'], install: true, c_args: c_args, @@ -2675,6 +2666,23 @@ foreach target : target_dirs link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []), link_args: link_args, gui_app: exe['gui']) + else + if 'AS_SHARED_LIB' in config_host + emulator = shared_library(exe_name, exe['sources'], + install: true, + c_args: c_args, + dependencies: arch_deps + deps + exe['dependencies'], + objects: lib.extract_all_objects(recursive: true), + link_language: link_language, + link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []), + link_args: link_args) + endif + if 'AS_STATIC_LIB' in config_host + emulator = static_library(exe_name, exe['sources'], + c_args: c_args, + dependencies: arch_deps + deps + exe['dependencies'], + objects: lib.extract_all_objects(recursive: true)) + endif endif if targetos == 'darwin'