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.
This commit is contained in:
Alexis Engelke
2018-12-25 17:06:47 +01:00
parent a3f77dbf49
commit ca54ca7422
4 changed files with 10 additions and 6 deletions

View File

@@ -5,6 +5,10 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#if defined(ARCH_X86_64) && __SIZEOF_POINTER__ < 8
#error "Decoding x86-64 requires a 64-bit architecture"
#endif
#ifndef ssize_t #ifndef ssize_t
#define ssize_t intptr_t #define ssize_t intptr_t
#endif #endif

View File

@@ -29,14 +29,13 @@ if get_option('warning_level').to_int() >= 3
language: 'c') language: 'c')
endif endif
c_compiler = meson.get_compiler('c') archmode = get_option('archmode')
pointer_size = c_compiler.sizeof('void*') if archmode == '32'
if pointer_size == 4
add_project_arguments(['-DARCH_386'], language: 'c') add_project_arguments(['-DARCH_386'], language: 'c')
elif pointer_size == 8 elif archmode == '64'
add_project_arguments(['-DARCH_X86_64'], language: 'c') add_project_arguments(['-DARCH_X86_64'], language: 'c')
else else
error('Invalid pointer size') error('Invalid architecture mode')
endif endif
instr_data = custom_target('tables', instr_data = custom_target('tables',

1
meson_options.txt Normal file
View File

@@ -0,0 +1 @@
option('archmode', type: 'combo', choices: ['32', '64'])

View File

@@ -15,7 +15,7 @@ cases = [
test_driver = executable('test_driver', 'driver.c', test_driver = executable('test_driver', 'driver.c',
dependencies: libx86decode, dependencies: libx86decode,
c_args: ['-D_GNU_SOURCE']) 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 foreach case : cases
test(case[0], sh, args: test_args + files(case[1])) test(case[0], sh, args: test_args + files(case[1]))