[gtksourceview] build: use more aggressive linker flags



commit 1a95c36d301b20a7f3eb70fe4619c8792a1d71c8
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 29 10:47:56 2020 -0800

    build: use more aggressive linker flags
    
    This tries to use more aggressive linker options such as:
    
      -Wl,Bsymbolic
      -fno-plt
      -Wl,-z,defs
      -Wl,-z,now
      -Wl,-z,relro
    
    when we have a non-plain build that is not a debug build. We avoid debug
    builds because the flags can get in the way of tooling such as profilers.

 gtksourceview/meson.build |  1 +
 meson.build               | 17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index 6f0e2886..fd080a9c 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -241,6 +241,7 @@ gtksource_lib = shared_library(package_string, gtksource_res,
                 objects: cc.get_id() == 'msvc' ? gtksource_objs : [],
              link_whole: cc.get_id() == 'msvc' ? [] : gtksource_libs,
                  c_args: core_c_args,
+              link_args: release_link_args,
                 install: true,
   gnu_symbol_visibility: 'hidden',
 )
diff --git a/meson.build b/meson.build
index 3baae99c..d30aa68c 100644
--- a/meson.build
+++ b/meson.build
@@ -7,6 +7,8 @@ project('gtksourceview', 'c',
                      'warning_level=2' ],
 )
 
+buildtype = get_option('buildtype')
+
 i18n = import('i18n')
 gnome = import('gnome')
 pkg = import('pkgconfig')
@@ -221,7 +223,7 @@ else
     '-Wunused',
     '-fno-strict-aliasing',
   ]
-  if get_option('buildtype') != 'plain'
+  if buildtype != 'plain'
     test_c_args += '-fstack-protector-strong'
   endif
 endif
@@ -254,9 +256,13 @@ add_project_arguments(global_c_args, language: 'c')
 
 # Various optimizations for non-debug builds including disabling of
 # cast checks, asserts, and additional link options.
-global_link_args = []
-test_link_args = ['-Wl,-z,relro', '-Wl,-z,now']
-if not get_option('buildtype').startswith('debug')
+release_link_args = []
+test_link_args = [
+  '-Wl,-z,defs',   # Detect and reject underlinking
+  '-Wl,-z,now',    # Disable lazy binding
+  '-Wl,-z,relro',  # Read-only segments after relocation
+]
+if not buildtype.startswith('debug')
   add_global_arguments([
     '-DG_DISABLE_ASSERT',
     '-DG_DISABLE_CAST_CHECKS',
@@ -265,10 +271,9 @@ if not get_option('buildtype').startswith('debug')
 endif
 foreach link_arg: test_link_args
   if cc.has_link_argument(link_arg)
-    global_link_args += link_arg
+    release_link_args += link_arg
   endif
 endforeach
-add_project_link_arguments(global_link_args, language: 'c')
 
 configure_file(
          output: 'config.h',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]