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

Bug#989521: marked as done (gcc-N: make ssp linking work on musl)



Your message dated Wed, 14 Jul 2021 09:03:28 +0000
with message-id <E1m3ang-000DKO-EB@fasolo.debian.org>
and subject line Bug#989521: fixed in gcc-11 11.1.0-4
has caused the Debian Bug report #989521,
regarding gcc-N: make ssp linking work on musl
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
989521: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=989521
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Source: gcc-11
Version: 11.1.0-2
Tags: patch
X-Debbugs-Cc: Szabolcs Nagy <szabolcs.nagy@arm.com>, Rich Felker <dalias@libc.org>

I was looking into making the Debian packaging of gcc work with musl and
ran into issues with musl. Once enabling -fstack-protector-something,
linking tends to fail with missing symbols.

The reason is that musl enables TARGET_LIBC_PROVIDES_SSP, because its
libc.so provides the relevant ssp functions. No extra library needs to
be linked. What it does not provide though is libssp_nonshared.a. The
upstream gcc does not handle this situation and considers their presence
interlocked.

More background on this can be found at
https://www.openwall.com/lists/musl/2014/11/05/3.

Another issue is that any object compiled with
-fstack-protector-something makes it use a symbol from
libssp_nonshared.a, so the resulting link has to include -lssp_nonshared
regardless of whether a -fstack-protector-something is given.

The solution chosen by Alpine is changing LINK_SSP_SPEC to
unconditionally link "-lssp_nonshared", see
https://git.alpinelinux.org/aports/commit/?id=d307f133de1f8a9993ab0d6fd51176b9373df4c3.
Since Alpine is the largest musl user, following their lead seems
natural.

Once doing so, bootstrapping fails, because libbacktrace is built before
libssp and at that time there is no libssp_nonshared.a. However, it
isn't actually needed during bootstrap, because it's not built with
-fstack-protector-something. An empty libssp_nonshared.a would to to
make -lssp_nonshared happy there. So I propose injecting such an empty
library before the build. When someone enables ssp on gcc libraries,
this approach will break of course, but the breakage is already there
due to the missing ordering. Once the ordering is fixed upstream, my
workaround can be dropped without replacement.

Please consider applying the attached patch.

Helmut
diff --minimal -Nru gcc-11-11.1.0/debian/changelog gcc-11-11.1.0/debian/changelog
--- gcc-11-11.1.0/debian/changelog	2021-05-08 13:50:11.000000000 +0200
+++ gcc-11-11.1.0/debian/changelog	2021-06-04 18:14:22.000000000 +0200
@@ -1,3 +1,10 @@
+gcc-11 (11.1.0-2.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Fix -fstack-protector on musl. (Closes: #-1)
+
+ -- Helmut Grohne <helmut@subdivi.de>  Fri, 04 Jun 2021 18:14:22 +0200
+
 gcc-11 (11.1.0-2) experimental; urgency=medium
 
   * Update to git 20210508 from the gcc-11 branch.
diff --minimal -Nru gcc-11-11.1.0/debian/patches/musl-ssp.diff gcc-11-11.1.0/debian/patches/musl-ssp.diff
--- gcc-11-11.1.0/debian/patches/musl-ssp.diff	1970-01-01 01:00:00.000000000 +0100
+++ gcc-11-11.1.0/debian/patches/musl-ssp.diff	2021-06-04 18:14:16.000000000 +0200
@@ -0,0 +1,21 @@
+See https://git.alpinelinux.org/aports/commit/?id=d307f133de1f8a9993ab0d6fd51176b9373df4c3
+and https://www.openwall.com/lists/musl/2014/11/05/3
+
+--- gcc-11-11.1.0.orig/src/gcc/gcc.c
++++ gcc-11-11.1.0/src/gcc/gcc.c
+@@ -1087,8 +1087,15 @@
+ 
+ #ifndef LINK_SSP_SPEC
+ #ifdef TARGET_LIBC_PROVIDES_SSP
++#if DEFAULT_LIBC == LIBC_MUSL
++/* When linking without -fstack-protector-something but including objects that
++   were built with -fstack-protector-something, calls to __stack_chk_fail_local
++   can be emitted. Thus -lssp_nonshared must be linked unconditionally.  */
++#define LINK_SSP_SPEC "-lssp_nonshared"
++#else
+ #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
+ 		       "|fstack-protector-strong|fstack-protector-explicit:}"
++#endif
+ #else
+ #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
+ 		       "|fstack-protector-strong|fstack-protector-explicit" \
diff --minimal -Nru gcc-11-11.1.0/debian/rules.patch gcc-11-11.1.0/debian/rules.patch
--- gcc-11-11.1.0/debian/rules.patch	2021-05-02 09:17:25.000000000 +0200
+++ gcc-11-11.1.0/debian/rules.patch	2021-06-04 18:11:17.000000000 +0200
@@ -61,6 +61,7 @@
 	pr87808 \
 	pr94253 \
 	gcc-arm-disable-guality-tests \
+	musl-ssp \
 
 ifneq (,$(filter $(distrelease),precise xenial bionic focal groovy hirsute))
   debian_patches += pr100067-revert
diff --minimal -Nru gcc-11-11.1.0/debian/rules2 gcc-11-11.1.0/debian/rules2
--- gcc-11-11.1.0/debian/rules2	2021-05-02 09:26:04.000000000 +0200
+++ gcc-11-11.1.0/debian/rules2	2021-06-04 18:10:24.000000000 +0200
@@ -1191,6 +1191,14 @@
 	rm -rf $(builddir)
 	mkdir $(builddir)
 
+ifneq (,$(filter musl-%,$(DEB_TARGET_ARCH)))
+	# We have to unconditionally link -lssp_nonshared on musl (see
+	# musl-ssp.diff). While gcc provides it, it comes a little late in the
+	# build for bootstrapping so we provide an empty one.
+	mkdir $(builddir)/gcc
+	ar rcs $(builddir)/gcc/libssp_nonshared.a
+endif
+
 	: # some tools like gettext are built with a newer libstdc++
 	mkdir -p bin
 	for i in msgfmt; do \

--- End Message ---
--- Begin Message ---
Source: gcc-11
Source-Version: 11.1.0-4
Done: Matthias Klose <doko@debian.org>

We believe that the bug you reported is fixed in the latest version of
gcc-11, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 989521@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Matthias Klose <doko@debian.org> (supplier of updated gcc-11 package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Wed, 14 Jul 2021 10:19:29 +0200
Source: gcc-11
Architecture: source
Version: 11.1.0-4
Distribution: experimental
Urgency: medium
Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Changed-By: Matthias Klose <doko@debian.org>
Closes: 989521
Changes:
 gcc-11 (11.1.0-4) experimental; urgency=medium
 .
   * Update to git 20210714 from the gcc-11 branch.
     - Fix PR middle-end/101291, PR tree-optimization/101394, PR ipa/101066,
       PR middle-end/101423, PR tree-optimization/100778, PR target/101377,
       PR tree-optimization/100778, PR tree-optimization/101229,
       PR tree-optimization/101173, PR tree-optimization/101280,
       PR middle-end/101156, PR tree-optimization/100923,
       PR tree-optimization/101088, PR tree-optimization/101025,
       PR tree-optimization/101158, PR tree-optimization/101151,
       PR tree-optimization/101105, PR middle-end/100672, PR target/101175,
       PR middle-end/101167, PR inline-asm/100785, PR target/100310 (x86),
       PR target/100856 (ARM), PR target/101016 (ARM), PR middle-end/101062,
       PR middle-end/101062, PR target/100777 (PPC), PR target/99842 (PPC),
       PR middle-end/100876, PR c++/100876, PR middle-end/100732,
       PR middle-end/100684, PR middle-end/100574, PR middle-end/100307,
       PR middle-end/100250, PR target/100871 (S390), PR target/101046,
       PR rtl-optimization/101008, PR debug/100852, PR target/100887,
       PR middle-end/100898, PR target/100887 (x86), PR middle-end/101009,
       PR tree-optimization/100981, PR tree-optimization/100934, PR ipa/100791,
       PR analyzer/99212, PR analyzer/101082, PR analyzer/99212,
       PR analyzer/100615, PR analyzer/100244, PR c++/100879, PR c/100783,
       PR c/100619, PR inline-asm/100785, PR c/100902, PR c++/101181,
       PR c++/101247, PR c++/101247, PR c++/101194, PR c++/98832,
       PR c++/101182, PR c++/100918, PR c++/97420, PR c++/101098, PR c++/100838,
       PR c++/86355, PR c++/101087, PR c++/101040, PR c++/97566, PR c++/100752,
       PR c++/101106, PR c/100902, PR c++/101078, PR c++/101029, PR c++/100946,
       PR d/101273, PR d/101282, PR d/100999, PR d/100967, PR fortran/100227,
       PR fortran/100283, PR fortran/101123, PR fortran/95501,
       PR fortran/95502, PR fortran/100965, PR c++/100796, PR preprocessor/96391,
       PR target/101235 (PPC), PR target/99939 (ARM), PR fortran/93524,
       PR middle-end/101167, PR libstdc++/91488, PR d/100999,
       PR libstdc++/100387, PR libstdc++/100806, PR libstdc++/95833,
       PR libstdc++/91488, PR libstdc++/100940, PR libstdc++/100940,
       PR libstdc++/100894, PR libstdc++/101034, PR libstdc++/101055,
       PR libstdc++/100475, PR libstdc++/100982, PR libstdc++/98842,
       PR libstdc++/100824, PR libstdc++/100824, PR libstdc++/100824,
       PR libstdc++/100577, PR libstdc++/100770, PR libstdc++/100690,
       PR libstdc++/100631, PR libstdc++/100631, PR libstdc++/100639.
   * Fix -fstack-protector on musl (Helmut Grohne). Closes: #989521.
   * Drop gdb build dependency on mipsel and mips64el for now.
     Addresses: #990842.
Checksums-Sha1:
 66df92c49483dc3c9459f45021e4085271f9271a 27457 gcc-11_11.1.0-4.dsc
 ab7fdb19fada1ad47abb1b74867abf96cbcc5262 2226328 gcc-11_11.1.0-4.debian.tar.xz
 ad5de8a474c84564ee23722399f540c6f7b56cc8 9298 gcc-11_11.1.0-4_source.buildinfo
Checksums-Sha256:
 055462c903d68d7c71fa45ddf5f508b10a5482aa0cbf41a46be093ae40125ee5 27457 gcc-11_11.1.0-4.dsc
 62cf90ef856dbfc9fbf70ab0021551830a92e4d8e9657dd03a0f140c8255c63e 2226328 gcc-11_11.1.0-4.debian.tar.xz
 e43cf48ee5c8afd0afd2f578fbedbde264ad8325efe9e4029f0e3b8b10dada9c 9298 gcc-11_11.1.0-4_source.buildinfo
Files:
 790c8f6db1f6bf3123c075e8c5570fc5 27457 devel optional gcc-11_11.1.0-4.dsc
 4a41442e69fbc1c5c8a886c518b9afeb 2226328 devel optional gcc-11_11.1.0-4.debian.tar.xz
 10cb9066e427aeddd2f72998adcb1f94 9298 devel optional gcc-11_11.1.0-4_source.buildinfo

-----BEGIN PGP SIGNATURE-----

iQJEBAEBCAAuFiEE1WVxuIqLuvFAv2PWvX6qYHePpvUFAmDuo1sQHGRva29AZGVi
aWFuLm9yZwAKCRC9fqpgd4+m9QmND/9uZICFgB67uZXVoGXMIG+yr/o2fPokgfh9
UKHM5cwsZqkOT6WS30oj1mhIpL6kwepQc6sJBC82osQrTecd8ZIAhrhEWr9NxWrR
mTC2hi6IdBgHdywEyImXK/kfDnV3aRf3ikZKUQ4m4PAwNL63A0r3PVIRstbotCYr
vdf32QkldoYCKj4fhlVXecxm5Yh4GmVoOcaJ/xJgqIzKL+s0JNcd93+4WdI0oMs4
7WKYlx9VKv6qSAkbVB5xvvTtUA9CRIP+85EvjMAg01dlKOh7GVZxnBQGJ4JWXGnM
nnlMy+f8ZQJreOaLHKHnYQ+jW3sewPLsP+KPHq5+ISTRKnzJcVI31ydqBqH0VgJP
TCOzqi4lvdZCVqunlqpcwqz5K/DZkNNMvRAcMRXfPRZZI+M0SbkVpLZJmDEBnrUX
tA48Lc/iwyzVEUZtmRxmYgnML1pxPrYhQTkXTnEK8uy1HUwanVuos2pg/TkPp8Qt
dk4aFfzwiDwbRktBvF9iXqBsJ6htJ8XVkqZ2voRC4Tf/9TOzA9EIwToM0XTT+L3D
XOHLbSd4od6ATP5LHVgAxYyn8ASMUQxcJDVvdR8fwGEwULyer3HDEiJbBmufP/wO
htDZZrhNBs/ntq9A9GGgr2PHfNk8Ur50BI8U+gICmQvr+uJtTGn5gIOX32ydqdZ9
p2rj2H7vGQ==
=HQQ1
-----END PGP SIGNATURE-----

--- End Message ---

Reply to: