aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-12-05 04:41:10 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2016-12-13 09:17:06 +0530
commit3e2d894f550d67dc3c65526b73931e52d7a37162 (patch)
tree50d64c942fd82a0f7e90c099aec686e821c05aca
parent4967b2a5ea0a67f6229a2dd0ea3d08fd93650061 (diff)
downloadmeson-3e2d894f550d67dc3c65526b73931e52d7a37162.zip
meson-3e2d894f550d67dc3c65526b73931e52d7a37162.tar.gz
meson-3e2d894f550d67dc3c65526b73931e52d7a37162.tar.bz2
Add test for cc.symbols_have_underscore_prefix
Also add MSVC support while doing so. Doesn't test 32-bit Windows yet because I can't figure out how to do manual setup for function calls on Win32 which also does symbol mangling. But this is fine for now.
-rw-r--r--test cases/common/126 llvm ir and assembly/meson.build53
-rw-r--r--test cases/common/126 llvm ir and assembly/square-x86.S23
-rw-r--r--test cases/common/126 llvm ir and assembly/square-x86_64.S25
-rw-r--r--test cases/common/126 llvm ir and assembly/symbol-underscore.h2
4 files changed, 94 insertions, 9 deletions
diff --git a/test cases/common/126 llvm ir and assembly/meson.build b/test cases/common/126 llvm ir and assembly/meson.build
index 8b9be33..97cce18 100644
--- a/test cases/common/126 llvm ir and assembly/meson.build
+++ b/test cases/common/126 llvm ir and assembly/meson.build
@@ -1,17 +1,54 @@
project('llvm-ir', 'c', 'cpp')
foreach lang : ['c', 'cpp']
- cc_id = meson.get_compiler(lang).get_id()
+ cc = meson.get_compiler(lang)
+ cc_id = cc.get_id()
+ ## Build a trivial executale with mixed LLVM IR source
if cc_id == 'clang'
e = executable('square_ir_' + lang, 'square.ll', 'main.' + lang)
test('test IR square' + lang, e)
endif
- # FIXME: msvc does not support passing assembly to cl.exe, but you can pass
- # it to ml.exe and get a compiled object. Meson should add support for
- # transparently building assembly with ml.exe with MSVC.
- if cc_id != 'msvc'
- cpu = host_machine.cpu_family()
- e = executable('square_asm_' + lang, 'square-' + cpu + '.S', 'main.' + lang)
- test('test ASM square' + lang, e, args : [e.full_path()])
+ ## Build a trivial executable with mixed assembly source
+ # This also helps test whether cc.symbols_have_underscore_prefix() is working
+ # properly. This is done by assembling some assembly into an object that will
+ # provide the unsigned_squared() symbol to main.c/cpp. This requires the
+ # C symbol mangling to be known in advance.
+ if cc.symbols_have_underscore_prefix()
+ uscore_args = ['-DMESON_TEST__UNDERSCORE_SYMBOL']
+ message('underscore is prefixed')
+ else
+ uscore_args = []
+ message('underscore is NOT prefixed')
endif
+ cpu = host_machine.cpu_family()
+ square_base = 'square-' + cpu
+ square_impl = square_base + '.S'
+ # MSVC cannot directly compile assembly files, so we pass it through the
+ # cl.exe pre-processor first and then assemble it with the ml.exe assembler.
+ # Then we can link it into the executable.
+ if cc_id == 'msvc'
+ cl = find_program('cl')
+ if cpu == 'x86'
+ ml = find_program('ml')
+ elif cpu == 'x86_64'
+ ml = find_program('ml64')
+ else
+ error('Unsupported cpu family: "' + cpu + '"')
+ endif
+ # Preprocess file (ml doesn't support pre-processing)
+ preproc_name = lang + square_base + '.i'
+ square_preproc = custom_target(lang + square_impl + 'preproc',
+ input : square_impl,
+ output : preproc_name,
+ command : [cl, '/EP', '/P', '/Fi' + preproc_name, '@INPUT@'] + uscore_args)
+ # Use assembled object file instead of the original .S assembly source
+ square_impl = custom_target(lang + square_impl,
+ input : square_preproc,
+ output : lang + square_base + '.obj',
+ command : [ml, '/Fo', '@OUTPUT@', '/c', '@INPUT@'])
+
+ endif
+ e = executable('square_asm_' + lang, square_impl, 'main.' + lang,
+ c_args : uscore_args, cpp_args : uscore_args)
+ test('test ASM square' + lang, e)
endforeach
diff --git a/test cases/common/126 llvm ir and assembly/square-x86.S b/test cases/common/126 llvm ir and assembly/square-x86.S
index f3d67e7..b38da4f 100644
--- a/test cases/common/126 llvm ir and assembly/square-x86.S
+++ b/test cases/common/126 llvm ir and assembly/square-x86.S
@@ -1,5 +1,26 @@
#include "symbol-underscore.h"
+/* This sadly doesn't test the symbol underscore stuff. I can't figure out how
+ * to not use an automatic stdcall mechanism and do everything manually. */
+#ifdef _MSC_VER
+
+.386
+.MODEL FLAT, C
+
+PUBLIC square_unsigned
+_TEXT SEGMENT
+
+square_unsigned PROC var1:DWORD
+ mov eax, var1
+ imul eax, eax
+ ret
+square_unsigned ENDP
+
+_TEXT ENDS
+END
+
+#else
+
.text
.globl SYMBOL_NAME(square_unsigned)
@@ -7,3 +28,5 @@ SYMBOL_NAME(square_unsigned):
movl 4(%esp), %eax
imull %eax, %eax
retl
+
+#endif
diff --git a/test cases/common/126 llvm ir and assembly/square-x86_64.S b/test cases/common/126 llvm ir and assembly/square-x86_64.S
index ea73a9d..4adc31e 100644
--- a/test cases/common/126 llvm ir and assembly/square-x86_64.S
+++ b/test cases/common/126 llvm ir and assembly/square-x86_64.S
@@ -1,9 +1,34 @@
#include "symbol-underscore.h"
+#ifdef _MSC_VER /* MSVC on Windows */
+
+PUBLIC SYMBOL_NAME(square_unsigned)
+_TEXT SEGMENT
+
+SYMBOL_NAME(square_unsigned) PROC
+ mov eax, ecx
+ imul eax, eax
+ ret
+SYMBOL_NAME(square_unsigned) ENDP
+
+_TEXT ENDS
+END
+
+#else
+
.text
.globl SYMBOL_NAME(square_unsigned)
+# ifdef _WIN32 /* MinGW */
+SYMBOL_NAME(square_unsigned):
+ imull %ecx, %ecx
+ movl %ecx, %eax
+ retq
+# else /* Linux and OS X */
SYMBOL_NAME(square_unsigned):
imull %edi, %edi
movl %edi, %eax
retq
+# endif
+
+#endif
diff --git a/test cases/common/126 llvm ir and assembly/symbol-underscore.h b/test cases/common/126 llvm ir and assembly/symbol-underscore.h
index 508cf50..d0f3ef9 100644
--- a/test cases/common/126 llvm ir and assembly/symbol-underscore.h
+++ b/test cases/common/126 llvm ir and assembly/symbol-underscore.h
@@ -1,4 +1,4 @@
-#if defined(__WIN32__) || defined(__APPLE__)
+#if defined(MESON_TEST__UNDERSCORE_SYMBOL)
# define SYMBOL_NAME(name) _##name
#else
# define SYMBOL_NAME(name) name