Blame SOURCES/gcc11-libgcc-link.patch

e60d6e
libgcc: Honor LDFLAGS_FOR_TARGET when linking libgcc_s
e60d6e
e60d6e
When building gcc with some specific LDFLAGS_FOR_TARGET, e.g.
e60d6e
LDFLAGS_FOR_TARGET=-Wl,-z,relro,-z,now
e60d6e
those flags propagate info linking of target shared libraries,
e60d6e
e.g. lib{ubsan,tsan,stdc++,quadmath,objc,lsan,itm,gphobos,gdruntime,gomp,go,gfortran,atomic,asan}.so.*
e60d6e
but there is one important exception, libgcc_s.so.* linking ignores it.
e60d6e
e60d6e
The following patch fixes that.
e60d6e
e60d6e
Bootstrapped/regtested on x86_64-linux with LDFLAGS_FOR_TARGET=-Wl,-z,relro,-z,now
e60d6e
and verified that libgcc_s.so.* is BIND_NOW when it previously wasn't, and
e60d6e
without any LDFLAGS_FOR_TARGET on x86_64-linux and i686-linux.
e60d6e
There on x86_64-linux I've verified that the libgcc_s.so.1 linking command
e60d6e
line for -m64 is identical except for whitespace to one without the patch,
e60d6e
and for -m32 multilib $(LDFLAGS) actually do supply there an extra -m32
e60d6e
that also repeats later in the @multilib_flags@, which should be harmless.
e60d6e
e60d6e
2021-08-04  Jakub Jelinek  <jakub@redhat.com>
e60d6e
e60d6e
	* config/t-slibgcc (SHLIB_LINK): Add $(LDFLAGS).
e60d6e
	* config/t-slibgcc-darwin (SHLIB_LINK): Likewise.
e60d6e
	* config/t-slibgcc-vms (SHLIB_LINK): Likewise.
e60d6e
e60d6e
--- libgcc/config/t-slibgcc
e60d6e
+++ libgcc/config/t-slibgcc
e60d6e
@@ -32,7 +32,7 @@ SHLIB_INSTALL_SOLINK = $(LN_S) $(SHLIB_SONAME) \
e60d6e
 	$(DESTDIR)$(slibdir)$(SHLIB_SLIBDIR_QUAL)/$(SHLIB_SOLINK)
e60d6e
 
e60d6e
 SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \
e60d6e
-	$(SHLIB_LDFLAGS) \
e60d6e
+	$(SHLIB_LDFLAGS) $(LDFLAGS) \
e60d6e
 	-o $(SHLIB_DIR)/$(SHLIB_SONAME).tmp @multilib_flags@ \
e60d6e
 	$(SHLIB_OBJS) $(SHLIB_LC) && \
e60d6e
 	rm -f $(SHLIB_DIR)/$(SHLIB_SOLINK) && \
e60d6e
--- libgcc/config/t-slibgcc-darwin
e60d6e
+++ libgcc/config/t-slibgcc-darwin
e60d6e
@@ -15,7 +15,7 @@ SHLIB_LC = -lc
e60d6e
 # Note that this version is used for the loader, not the linker; the linker
e60d6e
 # uses the stub versions named by the versioned members of $(INSTALL_FILES).
e60d6e
 
e60d6e
-SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) -dynamiclib -nodefaultlibs \
e60d6e
+SHLIB_LINK = $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -dynamiclib -nodefaultlibs \
e60d6e
 	-install_name @shlib_slibdir@/$(SHLIB_INSTALL_NAME) \
e60d6e
 	-single_module -o $(SHLIB_DIR)/$(SHLIB_SONAME) \
e60d6e
 	-Wl,-exported_symbols_list,$(SHLIB_MAP) \
e60d6e
--- libgcc/config/t-slibgcc-vms
e60d6e
+++ libgcc/config/t-slibgcc-vms
e60d6e
@@ -22,7 +22,7 @@ SHLIB_LINK = \
e60d6e
   objdump --syms $(SHLIB_OBJS) | \
e60d6e
   $(SHLIB_SYMVEC) >> SYMVEC_$$$$.opt ; \
e60d6e
   echo "case_sensitive=NO" >> SYMVEC_$$$$.opt; \
e60d6e
-  $(CC) $(LIBGCC2_CFLAGS) -nodefaultlibs \
e60d6e
+  $(CC) $(LIBGCC2_CFLAGS) $(LDFLAGS) -nodefaultlibs \
e60d6e
   -shared --for-linker=/noinform -o $(SHLIB_NAME) $(SHLIB_OBJS) \
e60d6e
   --for-linker=SYMVEC_$$$$.opt \
e60d6e
   --for-linker=gsmatch=equal,$(shlib_version)