build as shared lib

This commit is contained in:
Alwin Berger 2022-01-01 20:59:57 +01:00
parent ae0e744998
commit 1576aa029a
4 changed files with 87 additions and 28 deletions

19
configure vendored
View File

@ -835,6 +835,8 @@ if test "$mingw32" = "yes" ; then
fi
werror=""
as_shared_lib="no"
as_static_lib="no"
for opt do
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
@ -1581,6 +1583,16 @@ for opt do
;;
--disable-slirp-smbd) slirp_smbd=no
;;
--as-shared-lib)
as_shared_lib="yes"
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"
echo "Try '$0 --help' for more information"
@ -4919,6 +4931,13 @@ 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
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
echo "PYTHON=$python" >> $config_host_mak

View File

@ -1797,7 +1797,8 @@ if capstone_opt == 'internal'
build_by_default: false,
sources: capstone_files,
c_args: capstone_cargs,
include_directories: 'capstone/include')
include_directories: 'capstone/include',
pic: 'AS_SHARED_LIB' in config_host)
capstone = declare_dependency(link_with: libcapstone,
include_directories: 'capstone/include/capstone')
endif
@ -1877,7 +1878,8 @@ if have_system
build_by_default: false,
sources: slirp_files,
c_args: slirp_cargs,
include_directories: slirp_inc)
include_directories: slirp_inc,
pic: 'AS_SHARED_LIB' in config_host)
slirp = declare_dependency(link_with: libslirp,
dependencies: slirp_deps,
include_directories: slirp_inc)
@ -1934,7 +1936,8 @@ if have_system
libfdt = static_library('fdt',
build_by_default: false,
sources: fdt_files,
include_directories: fdt_inc)
include_directories: fdt_inc,
pic: 'AS_SHARED_LIB' in config_host)
fdt = declare_dependency(link_with: libfdt,
include_directories: fdt_inc)
endif
@ -2202,7 +2205,8 @@ util_ss.add_all(trace_ss)
util_ss = util_ss.apply(config_all, strict: false)
libqemuutil = static_library('qemuutil',
sources: util_ss.sources() + stub_ss.sources() + genh,
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman])
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman],
pic: 'AS_SHARED_LIB' in config_host)
qemuutil = declare_dependency(link_with: libqemuutil,
sources: genh + version_res)
@ -2267,7 +2271,8 @@ if get_option('b_lto')
pagevary_flags += '-fno-sanitize=cfi-icall'
endif
pagevary = static_library('page-vary-common', sources: pagevary,
c_args: pagevary_flags)
c_args: pagevary_flags,
pic: 'AS_SHARED_LIB' in config_host)
pagevary = declare_dependency(link_with: pagevary)
endif
common_ss.add(pagevary)
@ -2393,7 +2398,8 @@ if enable_modules
input: modinfo_files,
command: [modinfo_generate, '@INPUT@'],
capture: true)
modinfo_lib = static_library('modinfo', modinfo_src)
modinfo_lib = static_library('modinfo', modinfo_src,
pic: 'AS_SHARED_LIB' in config_host)
modinfo_dep = declare_dependency(link_whole: modinfo_lib)
softmmu_ss.add(modinfo_dep)
endif
@ -2412,7 +2418,8 @@ qemu_syms = custom_target('qemu.syms', output: 'qemu.syms',
qom_ss = qom_ss.apply(config_host, strict: false)
libqom = static_library('qom', qom_ss.sources() + genh,
dependencies: [qom_ss.dependencies()],
name_suffix: 'fa')
name_suffix: 'fa',
pic: 'AS_SHARED_LIB' in config_host)
qom = declare_dependency(link_whole: libqom)
@ -2420,7 +2427,8 @@ authz_ss = authz_ss.apply(config_host, strict: false)
libauthz = static_library('authz', authz_ss.sources() + genh,
dependencies: [authz_ss.dependencies()],
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
authz = declare_dependency(link_whole: libauthz,
dependencies: qom)
@ -2429,7 +2437,8 @@ crypto_ss = crypto_ss.apply(config_host, strict: false)
libcrypto = static_library('crypto', crypto_ss.sources() + genh,
dependencies: [crypto_ss.dependencies()],
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
crypto = declare_dependency(link_whole: libcrypto,
dependencies: [authz, qom])
@ -2439,13 +2448,15 @@ libio = static_library('io', io_ss.sources() + genh,
dependencies: [io_ss.dependencies()],
link_with: libqemuutil,
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
io = declare_dependency(link_whole: libio, dependencies: [crypto, qom])
libmigration = static_library('migration', sources: migration_files + genh,
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
migration = declare_dependency(link_with: libmigration,
dependencies: [zlib, qom, io])
softmmu_ss.add(migration)
@ -2455,7 +2466,8 @@ libblock = static_library('block', block_ss.sources() + genh,
dependencies: block_ss.dependencies(),
link_depends: block_syms,
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
block = declare_dependency(link_whole: [libblock],
link_args: '@block.syms',
@ -2465,7 +2477,8 @@ blockdev_ss = blockdev_ss.apply(config_host, strict: false)
libblockdev = static_library('blockdev', blockdev_ss.sources() + genh,
dependencies: blockdev_ss.dependencies(),
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
blockdev = declare_dependency(link_whole: [libblockdev],
dependencies: [block])
@ -2474,20 +2487,23 @@ qmp_ss = qmp_ss.apply(config_host, strict: false)
libqmp = static_library('qmp', qmp_ss.sources() + genh,
dependencies: qmp_ss.dependencies(),
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
qmp = declare_dependency(link_whole: [libqmp])
libchardev = static_library('chardev', chardev_ss.sources() + genh,
name_suffix: 'fa',
dependencies: [gnutls],
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
chardev = declare_dependency(link_whole: libchardev)
libhwcore = static_library('hwcore', sources: hwcore_files + genh,
name_suffix: 'fa',
build_by_default: false)
build_by_default: false,
pic: 'AS_SHARED_LIB' in config_host)
hwcore = declare_dependency(link_whole: libhwcore)
common_ss.add(hwcore)
@ -2515,7 +2531,8 @@ common_all = static_library('common',
sources: common_all.sources() + genh,
implicit_include_directories: false,
dependencies: common_all.dependencies(),
name_suffix: 'fa')
name_suffix: 'fa',
pic: 'AS_SHARED_LIB' in config_host)
feature_to_c = find_program('scripts/feature_to_c.sh')
@ -2609,7 +2626,8 @@ foreach target : target_dirs
include_directories: target_inc,
c_args: c_args,
build_by_default: false,
name_suffix: 'fa')
name_suffix: 'fa',
pic: 'AS_SHARED_LIB' in config_host)
if target.endswith('-softmmu')
execs = [{
@ -2649,6 +2667,7 @@ foreach target : target_dirs
exe_name += '-unsigned'
endif
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,
@ -2658,6 +2677,24 @@ 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'
icon = 'pc-bios/qemu.rsrc'

View File

@ -66,4 +66,5 @@ cd build
--disable-vvfat \
--disable-xen \
--disable-xen-pci-passthrough \
--disable-xfsctl
--disable-xfsctl \
--as-shared-lib

View File

@ -85,6 +85,7 @@ void libafl_snapshot_load( const char* name )
load_snapshot(name, NULL, false, NULL, &err);
}
#ifndef AS_SHARED_LIB
int main(int argc, char **argv, char **envp)
{
// qemu_init(argc, argv, envp);
@ -102,5 +103,6 @@ int main(int argc, char **argv, char **envp)
return 0;
}
#endif
/* End LibAFL instrumentation */