diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-04 17:02:59 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-13 09:17:06 +0530 |
commit | 09f65b7a3cb2bd3bb5b5fa42ffac45f8fb632132 (patch) | |
tree | 9407d6773f0f2378737a5899dfc270d6318bbe0c /mesonbuild/compilers.py | |
parent | e128d26b350e4b8ba02e4de8858aa3deafa07ce1 (diff) | |
download | meson-09f65b7a3cb2bd3bb5b5fa42ffac45f8fb632132.zip meson-09f65b7a3cb2bd3bb5b5fa42ffac45f8fb632132.tar.gz meson-09f65b7a3cb2bd3bb5b5fa42ffac45f8fb632132.tar.bz2 |
New compiler function 'symbols_have_underscore_prefix'
Check if the compiler prefixes an underscore to global symbols. This is
useful when linking to compiled assembly code, or other code that does
not have its C symbol mangling handled transparently by the compiler.
C symbol mangling is platform and architecture dependent, and a helper
function is needed to detect it. Eg: Windows 32-bit prefixes underscore,
but 64-bit does not. Linux does not prefix an underscore but OS X does.
Diffstat (limited to 'mesonbuild/compilers.py')
-rw-r--r-- | mesonbuild/compilers.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index e474d2e..9ddaa56 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1058,6 +1058,40 @@ void bar() { ''' return self.compiles(templ % (prefix, typename), env, extra_args, dependencies) + def symbols_have_underscore_prefix(self, env): + ''' + Check if the compiler prefixes an underscore to global C symbols + ''' + symbol_name = b'meson_uscore_prefix' + code = '''#ifdef __cplusplus + extern "C" { + #endif + void ''' + symbol_name.decode() + ''' () {} + #ifdef __cplusplus + } + #endif + ''' + args = self.get_cross_extra_flags(env, compile=True, link=False) + args += self.get_compiler_check_args() + n = 'symbols_have_underscore_prefix' + with self.compile(code, args, compile_only=True) as p: + if p.returncode != 0: + m = 'BUG: Unable to compile {!r} check: {}' + raise RuntimeError(m.format(n, p.stdo)) + if not os.path.isfile(p.output_name): + m = 'BUG: Can\'t find compiled test code for {!r} check' + raise RuntimeError(m.format(n)) + with open(p.output_name, 'rb') as o: + for line in o: + # Check if the underscore form of the symbol is somewhere + # in the output file. + if b'_' + symbol_name in line: + return True + # Else, check if the non-underscored form is present + elif symbol_name in line: + return False + raise RuntimeError('BUG: {!r} check failed unexpectedly'.format(n)) + def find_library(self, libname, env, extra_dirs): # First try if we can just add the library as -l. code = '''int main(int argc, char **argv) { |