Blob Blame History Raw
From 8456014be8cf0ee3397dc5318ce452f17f241eba Mon Sep 17 00:00:00 2001
From: Xavier Claessens <xavier.claessens@collabora.com>
Date: Tue, 24 Apr 2018 16:27:43 -0400
Subject: [PATCH 05/16] has_multi_link_arguments: Some compilers needs
 -Wl,--fatal-warnings

ld does not treat wrong -z options as fatal by default.
---
 mesonbuild/compilers/c.py                      | 14 ++++++++++++++
 test cases/common/191 has link arg/meson.build |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 88571a3c..e8110969 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -59,6 +59,9 @@ class CCompiler(Compiler):
         else:
             self.exe_wrapper = exe_wrapper
 
+        # Set to None until we actually need to check this
+        self.has_fatal_warnings_link_arg = None
+
     def needs_static_linker(self):
         return True # When compiling static libraries, so yes.
 
@@ -871,6 +874,17 @@ class CCompiler(Compiler):
         return self.has_arguments(args, env, code, mode='compile')
 
     def has_multi_link_arguments(self, args, env):
+        # First time we check for link flags we need to first check if we have
+        # --fatal-warnings, otherwise some linker checks could give some
+        # false positive.
+        fatal_warnings_args = ['-Wl,--fatal-warnings']
+        if self.has_fatal_warnings_link_arg is None:
+            self.has_fatal_warnings_link_arg = False
+            self.has_fatal_warnings_link_arg = self.has_multi_link_arguments(fatal_warnings_args, env)
+
+        if self.has_fatal_warnings_link_arg:
+            args = fatal_warnings_args + args
+
         args = self.linker_to_compiler_args(args)
         code = 'int main(int argc, char **argv) { return 0; }'
         return self.has_arguments(args, env, code, mode='link')
diff --git a/test cases/common/191 has link arg/meson.build b/test cases/common/191 has link arg/meson.build
index 255ff459..e166101a 100644
--- a/test cases/common/191 has link arg/meson.build	
+++ b/test cases/common/191 has link arg/meson.build	
@@ -40,3 +40,5 @@ assert(l2.length() == 0, 'First supported did not return empty array.')
 assert(not cc.has_multi_link_arguments([isnt_arg, is_arg]), 'Arg that should be broken is not.')
 assert(cc.has_multi_link_arguments(is_arg), 'Arg that should have worked does not work.')
 assert(cc.has_multi_link_arguments([useless, is_arg]), 'Arg that should have worked does not work.')
+
+assert(not cc.has_link_argument('-Wl,-z,nodelete42'), 'Did not detect wrong -z linker argument')
-- 
2.17.0