9832fd
This patch is based on the following upstream commit:
9832fd
9832fd
commit 94a4e9e4f401ffe829a992820439977ead0a0ce7
9832fd
Author: Florian Weimer <fweimer@redhat.com>
9832fd
Date:   Thu Apr 25 10:41:43 2019 +0200
9832fd
9832fd
    Extend BIND_NOW to installed programs with --enable-bind-now
9832fd
    
9832fd
    Commit 2d6ab5df3b675e96ee587ae6a8c2ce004c6b1ba9 ("Document and fix
9832fd
    --enable-bind-now [BZ #21015]") extended BIND_NOW to all installed
9832fd
    shared objects.  This change also covers installed programs.
9832fd
    
9832fd
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
9832fd
9832fd
diff --git a/INSTALL b/INSTALL
9832fd
index 230be71b9d0821c2..277ea46d9c25a9ae 100644
9832fd
--- a/INSTALL
9832fd
+++ b/INSTALL
9832fd
@@ -144,10 +144,10 @@ will be used, and CFLAGS sets optimization options for the compiler.
9832fd
      Enable lock elision for pthread mutexes by default.
9832fd
 
9832fd
 '--enable-bind-now'
9832fd
-     Disable lazy binding for installed shared objects.  This provides
9832fd
-     additional security hardening because it enables full RELRO and a
9832fd
-     read-only global offset table (GOT), at the cost of slightly
9832fd
-     increased program load times.
9832fd
+     Disable lazy binding for installed shared objects and programs.
9832fd
+     This provides additional security hardening because it enables full
9832fd
+     RELRO and a read-only global offset table (GOT), at the cost of
9832fd
+     slightly increased program load times.
9832fd
 
9832fd
 `--disable-werror'
9832fd
      By default, the GNU C Library is built with `-Werror'.  If you wish
9832fd
diff --git a/Makeconfig b/Makeconfig
9832fd
index 1ad9b6f0d494c027..bc13b39c2ea5708a 100644
9832fd
--- a/Makeconfig
9832fd
+++ b/Makeconfig
9832fd
@@ -389,6 +389,8 @@ endif
9832fd
 # test modules.
9832fd
 ifeq ($(bind-now),yes)
9832fd
 LDFLAGS-lib.so += -Wl,-z,now
9832fd
+# Extra flags for dynamically linked non-test main programs.
9832fd
+link-extra-flags += -Wl,-z,now
9832fd
 endif
9832fd
 
9832fd
 # Additional libraries to link into every test.
9832fd
@@ -405,7 +407,8 @@ ifndef +link-pie
9832fd
 						    S$(start-installed-name))\
9832fd
 			  $(+preinit) $(link-extra-libs) \
9832fd
 			  $(common-objpfx)libc% $(+postinit),$^) \
9832fd
-	     $(link-extra-libs) $(link-libc) $(+postctorS) $(+postinit)
9832fd
+	     $(link-extra-libs) $(link-extra-flags) $(link-libc) \
9832fd
+	     $(+postctorS) $(+postinit)
9832fd
 endif
9832fd
 # Command for statically linking programs with the C library.
9832fd
 ifndef +link-static
9832fd
@@ -419,8 +422,8 @@ ifndef +link-static
9832fd
 			   $(common-objpfx)libc% $(+postinit),$^) \
9832fd
 	      $(link-extra-libs-static)
9832fd
 +link-static-after-libc = $(+postctorT) $(+postinit)
9832fd
-+link-static = $(+link-static-before-libc) $(link-libc-static) \
9832fd
-	       $(+link-static-after-libc)
9832fd
++link-static = $(+link-static-before-libc) $(link-extra-flags) \
9832fd
+	       $(link-libc-static) $(+link-static-after-libc)
9832fd
 +link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
9832fd
 		     $(+link-static-after-libc)
9832fd
 endif
9832fd
@@ -438,7 +441,8 @@ ifeq (yes,$(build-shared))
9832fd
 			   $(common-objpfx)libc% $(+postinit),$^) \
9832fd
 	      $(link-extra-libs)
9832fd
 +link-after-libc = $(+postctor) $(+postinit)
9832fd
-+link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
9832fd
++link = $(+link-before-libc) $(link-extra-flags) $(link-libc) \
9832fd
+	$(+link-after-libc)
9832fd
 +link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
9832fd
 else
9832fd
 +link = $(+link-static)
9832fd
diff --git a/manual/install.texi b/manual/install.texi
9832fd
index 47d832cc59bc695e..5cacd974ce093ce9 100644
9832fd
--- a/manual/install.texi
9832fd
+++ b/manual/install.texi
9832fd
@@ -161,10 +161,10 @@ so that they can be invoked directly.
9832fd
 Enable lock elision for pthread mutexes by default.
9832fd
 
9832fd
 @item --enable-bind-now
9832fd
-Disable lazy binding for installed shared objects.  This provides
9832fd
-additional security hardening because it enables full RELRO and a
9832fd
-read-only global offset table (GOT), at the cost of slightly increased
9832fd
-program load times.
9832fd
+Disable lazy binding for installed shared objects and programs.  This
9832fd
+provides additional security hardening because it enables full RELRO
9832fd
+and a read-only global offset table (GOT), at the cost of slightly
9832fd
+increased program load times.
9832fd
 
9832fd
 @pindex pt_chown
9832fd
 @findex grantpt