Blame SOURCES/gcc11-libgcc-link.patch

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