diff --git a/configure b/configure index 31228f2711..1692a0a5c4 100755 --- a/configure +++ b/configure @@ -835,6 +835,7 @@ if test "$mingw32" = "yes" ; then fi werror="" +as_shared_lib="no" for opt do optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') @@ -1582,9 +1583,9 @@ for opt do --disable-slirp-smbd) slirp_smbd=no ;; --as-shared-lib) - QEMU_LDFLAGS="$QEMU_LDFLAGS -shared" - QEMU_CFLAGS="QEMU_CFLAGS -fPIC -DAS_SHARED_LIB=1" - QEMU_CXXFLAGS="QEMU_CXXFLAGS -fPIC -DAS_SHARED_LIB=1" + as_shared_lib="yes" + QEMU_CFLAGS="$QEMU_CFLAGS -fPIC -DAS_SHARED_LIB=1" + QEMU_CXXFLAGS="$QEMU_CXXFLAGS -fPIC -DAS_SHARED_LIB=1" ;; *) echo "ERROR: unknown option $opt" @@ -4923,6 +4924,10 @@ if test "$secret_keyring" = "yes" ; then echo "CONFIG_SECRET_KEYRING=y" >> $config_host_mak fi +if test "$as_shared_lib" = "yes" ; then + echo "AS_SHARED_LIB=y" >> $config_host_mak +fi + echo "ROMS=$roms" >> $config_host_mak echo "MAKE=$make" >> $config_host_mak echo "PYTHON=$python" >> $config_host_mak diff --git a/linux-user/main.c b/linux-user/main.c index 87736f3a9c..68e55ae483 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -656,7 +656,7 @@ int libafl_qemu_run(void) #ifdef AS_SHARED_LIB int qemu_user_init(int argc, char **argv, char **envp); -__attribute__((section(".init_array"))) static void *ctr = &qemu_user_init; +__attribute__((section(".init_array"))) void *_qemu_user_init_ctr = &qemu_user_init; int qemu_user_init(int argc, char **argv, char **envp) #else diff --git a/meson.build b/meson.build index 7e58e6279b..c5c2c34ef8 100644 --- a/meson.build +++ b/meson.build @@ -2656,15 +2656,26 @@ foreach target : target_dirs exe_name += '-unsigned' endif - emulator = executable(exe_name, exe['sources'], + 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, - gui_app: exe['gui']) + link_args: link_args) + else + emulator = executable(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, + gui_app: exe['gui']) + endif if targetos == 'darwin' icon = 'pc-bios/qemu.rsrc'