From 6e160995b0e9b1125abc211e17844752f47b650d Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Thu, 6 Sep 2018 03:57:45 +0300 Subject: Improve D link argument handling --- mesonbuild/compilers/d.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 5beacbd..9ad0599 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -122,9 +122,8 @@ class DCompiler(Compiler): def get_linker_search_args(self, dirname): # -L is recognized as "add this to the search path" by the linker, - # while the compiler recognizes it as "pass to linker". So, the first - # -L is for the compiler, telling it to pass the second -L to the linker. - return ['-L=-L' + dirname] + # while the compiler recognizes it as "pass to linker". + return ['-Wl,-L' + dirname] def get_coverage_args(self): return ['-cov'] @@ -231,7 +230,7 @@ class DCompiler(Compiler): paths = padding else: paths = paths + ':' + padding - return ['-L=-rpath={}'.format(paths)] + return ['-Wl,-rpath={}'.format(paths)] def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'): if extra_args is None: -- cgit v1.1 From d2483d44128778f4d7fe6b028abd2431d2e9f4cc Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Thu, 6 Sep 2018 04:07:00 +0300 Subject: Refactor D argument translation function --- mesonbuild/compilers/d.py | 68 +++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 23 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 9ad0599..abf9297 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -286,20 +286,25 @@ class DCompiler(Compiler): # The flags might have been added by pkg-config files, # and are therefore out of the user's control. for arg in args: + # Translate OS specific arguments first. + osargs = [] + if is_windows(): + osargs = cls.translate_arg_to_windows(arg) + elif is_osx(): + osargs = cls.translate_arg_to_osx(arg) + if osargs: + dcargs.extend(osargs) + continue + + # Translate common D arguments here. if arg == '-pthread': continue if arg.startswith('-Wl,'): + # Translate linker arguments here. linkargs = arg[arg.index(',') + 1:].split(',') for la in linkargs: - if la.startswith('--out-implib='): - # Import library name for MSVC targets - dcargs.append('-L=/IMPLIB:' + la[13:].strip()) - continue dcargs.append('-L=' + la.strip()) continue - elif arg.startswith('-install_name'): - dcargs.append('-L=' + arg) - continue elif arg.startswith('-link-defaultlib') or arg.startswith('-linker'): # these are special arguments to the LDC linker call, # arguments like "-link-defaultlib-shared" do *not* @@ -312,7 +317,7 @@ class DCompiler(Compiler): # translate library link flag dcargs.append('-L=' + arg) continue - elif arg.startswith('-L/') or arg.startswith('-L./'): + elif arg.startswith('-L'): # we need to handle cases where -L is set by e.g. a pkg-config # setting to select a linker search path. We can however not # unconditionally prefix '-L' with '-L' because the user might @@ -327,26 +332,43 @@ class DCompiler(Compiler): # or other objects that we need to link. dcargs.append('-L=' + arg) continue - elif arg.startswith('-mscrtlib='): - mscrtlib = arg[10:].lower() - if cls is LLVMDCompiler: - # Default crt libraries for LDC2 must be excluded for other - # selected crt options. - if mscrtlib != 'libcmt': - dcargs.append('-L=/NODEFAULTLIB:libcmt') - dcargs.append('-L=/NODEFAULTLIB:libvcruntime') + dcargs.append(arg) - # Fixes missing definitions for printf-functions in VS2017 - if mscrtlib.startswith('msvcrt'): - dcargs.append('-L=/DEFAULTLIB:legacy_stdio_definitions.lib') + return dcargs - dcargs.append(arg) + @classmethod + def translate_arg_to_windows(cls, arg): + args = [] + if arg.startswith('-Wl,'): + # Translate linker arguments here. + linkargs = arg[arg.index(',') + 1:].split(',') + for la in linkargs: + if la.startswith('--out-implib='): + # Import library name + args.append('-L=/IMPLIB:' + la[13:].strip()) + elif arg.startswith('-mscrtlib='): + args.append(arg) + mscrtlib = arg[10:].lower() + if cls is LLVMDCompiler: + # Default crt libraries for LDC2 must be excluded for other + # selected crt options. + if mscrtlib != 'libcmt': + args.append('-L=/NODEFAULTLIB:libcmt') + args.append('-L=/NODEFAULTLIB:libvcruntime') + + # Fixes missing definitions for printf-functions in VS2017 + if mscrtlib.startswith('msvcrt'): + args.append('-L=/DEFAULTLIB:legacy_stdio_definitions.lib') - continue - dcargs.append(arg) + return args - return dcargs + @classmethod + def translate_arg_to_osx(cls, arg): + args = [] + if arg.startswith('-install_name'): + args.append('-L=' + arg) + return args def get_debug_args(self, is_debug): return clike_debug_args[is_debug] -- cgit v1.1 From fd4c996a67328d849c95ae74b7f9315550671a56 Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Thu, 6 Sep 2018 04:14:49 +0300 Subject: Remove translation of file paths This would also pass all the source and object files to linker, which is not desirable. --- mesonbuild/compilers/d.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index abf9297..6912ac9 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -327,11 +327,6 @@ class DCompiler(Compiler): # a linker search path. dcargs.append('-L=' + arg) continue - elif arg.startswith('/') or arg.startswith('./'): - # absolute (or relative) paths passed to the linker may be static libraries - # or other objects that we need to link. - dcargs.append('-L=' + arg) - continue dcargs.append(arg) -- cgit v1.1 From 040dd03a7a605829df14678dac4aa2dee0eda4b1 Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Thu, 6 Sep 2018 04:18:56 +0300 Subject: Fix remaining soname and rpath issues on OSX --- mesonbuild/compilers/d.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 6912ac9..6801db7 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -150,12 +150,15 @@ class DCompiler(Compiler): def get_soname_args(self, *args): # FIXME: Make this work for cross-compiling - gcc_type = GCC_STANDARD if is_windows(): - gcc_type = GCC_CYGWIN - if is_osx(): - gcc_type = GCC_OSX - return get_gcc_soname_args(gcc_type, *args) + return [] + elif is_osx(): + soname_args = get_gcc_soname_args(GCC_OSX, *args) + if soname_args: + return ['-Wl,' + ','.join(soname_args)] + return [] + + return get_gcc_soname_args(GCC_STANDARD, *args) def get_feature_args(self, kwargs, build_to_src): res = [] @@ -230,7 +233,7 @@ class DCompiler(Compiler): paths = padding else: paths = paths + ':' + padding - return ['-Wl,-rpath={}'.format(paths)] + return ['-Wl,-rpath,{}'.format(paths)] def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'): if extra_args is None: -- cgit v1.1 From 644809fe59f331a7143587b9b71ad3c514cbb59b Mon Sep 17 00:00:00 2001 From: GoaLitiuM Date: Thu, 6 Sep 2018 04:52:09 +0300 Subject: Make sure static library files are passed properly to the linker --- mesonbuild/compilers/d.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 6801db7..5433b36 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -328,6 +328,17 @@ class DCompiler(Compiler): # compiler (pass flag through to the linker) # Hence, we guess here whether the flag was intended to pass # a linker search path. + + # Make sure static library files are passed properly to the linker. + if arg.endswith('.a') or arg.endswith('.lib'): + if arg.startswith('-L='): + farg = arg[3:] + else: + farg = arg[2:] + if len(farg) > 0 and not farg.startswith('-'): + dcargs.append('-L=' + farg) + continue + dcargs.append('-L=' + arg) continue -- cgit v1.1