From ca54ca7422ae51a10c284c977f9e0f2582d93977 Mon Sep 17 00:00:00 2001 From: Alexis Engelke Date: Tue, 25 Dec 2018 17:06:47 +0100 Subject: [PATCH] Add compile-time option for architecture mode This allows to decode x86-32 machine code on a 64-bit platform (but not vice versa). As a side-effect, we also get rid of pointer-size detection for architecture selection. --- decode.h | 4 ++++ meson.build | 9 ++++----- meson_options.txt | 1 + tests/meson.build | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 meson_options.txt diff --git a/decode.h b/decode.h index 6f9abec..a8b3172 100644 --- a/decode.h +++ b/decode.h @@ -5,6 +5,10 @@ #include #include +#if defined(ARCH_X86_64) && __SIZEOF_POINTER__ < 8 +#error "Decoding x86-64 requires a 64-bit architecture" +#endif + #ifndef ssize_t #define ssize_t intptr_t #endif diff --git a/meson.build b/meson.build index d23c1b1..bf3c7ae 100644 --- a/meson.build +++ b/meson.build @@ -29,14 +29,13 @@ if get_option('warning_level').to_int() >= 3 language: 'c') endif -c_compiler = meson.get_compiler('c') -pointer_size = c_compiler.sizeof('void*') -if pointer_size == 4 +archmode = get_option('archmode') +if archmode == '32' add_project_arguments(['-DARCH_386'], language: 'c') -elif pointer_size == 8 +elif archmode == '64' add_project_arguments(['-DARCH_X86_64'], language: 'c') else - error('Invalid pointer size') + error('Invalid architecture mode') endif instr_data = custom_target('tables', diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..ce5a124 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('archmode', type: 'combo', choices: ['32', '64']) diff --git a/tests/meson.build b/tests/meson.build index de7edb9..199a9cb 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -15,7 +15,7 @@ cases = [ test_driver = executable('test_driver', 'driver.c', dependencies: libx86decode, c_args: ['-D_GNU_SOURCE']) -test_args = files('common.sh') + [test_driver.full_path(), '@0@'.format(pointer_size * 8)] +test_args = files('common.sh') + [test_driver.full_path(), get_option('archmode')] foreach case : cases test(case[0], sh, args: test_args + files(case[1]))