Gentoo Archives: gentoo-commits

From: Sergei Trofimovich <slyfox@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gcc-config:master commit in: gcc-backup/, /
Date: Sat, 07 Sep 2019 21:30:22
Message-Id: 1567891752.44570a44be60a8fc33bd05089047c1f2980b3047.slyfox@gentoo
1 commit: 44570a44be60a8fc33bd05089047c1f2980b3047
2 Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
3 AuthorDate: Sat Sep 7 20:17:52 2019 +0000
4 Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
5 CommitDate: Sat Sep 7 21:29:12 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/gcc-config.git/commit/?id=44570a44
7
8 gcc-config: store gcc backup into /lib/gcc-backup, not /lib
9
10 Writing (and removing) libraries to /lib outside package manager
11 was a surprise to users in bug #667020# where libunwind.so was
12 clobbered by gcc-config runs.
13
14 This change isolates all logic that handles file copies
15 outside package manager into /lib/gcc-backup directory.
16
17 To make new library still resolveable we install env.d entry
18 with contents of
19 LDPATH="/lib/gcc-backup"
20
21 Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>
22
23 Makefile | 22 +++++++++++++++++++---
24 envd-gcc-backup | 3 +++
25 gcc-backup/README | 41 +++++++++++++++++++++++++++++++++++++++++
26 gcc-config | 17 ++++++++++++++++-
27 4 files changed, 79 insertions(+), 4 deletions(-)
28
29 diff --git a/Makefile b/Makefile
30 index 2b3b235..087000b 100644
31 --- a/Makefile
32 +++ b/Makefile
33 @@ -3,6 +3,7 @@ EPREFIX ?=
34 PN = gcc-config
35 PV = git
36 P = $(PN)-$(PV)
37 +BACKUPDIR = gcc-backup
38
39 PREFIX = $(EPREFIX)/usr
40 BINDIR = $(PREFIX)/bin
41 @@ -11,15 +12,18 @@ ESELECTDIR = $(PREFIX)/share/eselect/modules
42
43 SUBLIBDIR = lib
44 LIBDIR = $(PREFIX)/$(SUBLIBDIR)
45 +LIBGCC_BACKUPDIR = $(EPREFIX)/$(SUBLIBDIR)/$(BACKUPDIR)
46 +
47 +ENVD = $(EPREFIX)/etc/env.d
48
49 MKDIR_P = mkdir -p -m 755
50 INSTALL_EXE = install -m 755
51 INSTALL_DATA = install -m 644
52
53 -all: .gcc-config
54 +all: .gcc-config .envd-gcc-backup
55
56 clean:
57 - rm -f .gcc-config
58 + rm -f .gcc-config .envd-gcc-backup
59
60 .gcc-config: gcc-config
61 sed \
62 @@ -27,14 +31,26 @@ clean:
63 -e 's:@GENTOO_EPREFIX@:$(EPREFIX):g' \
64 -e 's:@GENTOO_LIBDIR@:$(SUBLIBDIR):g' \
65 -e 's:@PV@:$(PV):g' \
66 + -e 's:@GENTOO_GCC_BACKUP_DIR@:$(BACKUPDIR):g' \
67 $< > $@
68 chmod a+rx $@
69
70 +.envd-gcc-backup: envd-gcc-backup
71 + sed \
72 + -e 's:@LIBGCC_BACKUPDIR@:$(LIBGCC_BACKUPDIR):g' \
73 + $< > $@
74 +
75 install: all
76 - $(MKDIR_P) $(DESTDIR)$(BINDIR) $(DESTDIR)$(ESELECTDIR) $(DESTDIR)$(DOCDIR)
77 + $(MKDIR_P) $(DESTDIR)$(BINDIR)
78 $(INSTALL_EXE) .gcc-config $(DESTDIR)$(BINDIR)/gcc-config
79 + $(MKDIR_P) $(DESTDIR)$(ESELECTDIR)
80 $(INSTALL_DATA) gcc.eselect $(DESTDIR)$(ESELECTDIR)
81 + $(MKDIR_P) $(DESTDIR)$(DOCDIR)
82 $(INSTALL_DATA) README $(DESTDIR)$(DOCDIR)
83 + $(MKDIR_P) $(DESTDIR)$(LIBGCC_BACKUPDIR)
84 + $(INSTALL_DATA) gcc-backup/README $(DESTDIR)$(LIBGCC_BACKUPDIR)
85 + $(MKDIR_P) $(DESTDIR)$(ENVD)
86 + $(INSTALL_DATA) .envd-gcc-backup $(DESTDIR)$(ENVD)/99gcc-backup
87
88 test check: .gcc-config
89 cd tests && ./run_tests
90
91 diff --git a/envd-gcc-backup b/envd-gcc-backup
92 new file mode 100644
93 index 0000000..4367b62
94 --- /dev/null
95 +++ b/envd-gcc-backup
96 @@ -0,0 +1,3 @@
97 +# A fallback for libgcc_s.so.* and dependencies.
98 +# See @LIBGCC_BACKUPDIR@/README for details
99 +LDPATH="@LIBGCC_BACKUPDIR@"
100
101 diff --git a/gcc-backup/README b/gcc-backup/README
102 new file mode 100644
103 index 0000000..fdac223
104 --- /dev/null
105 +++ b/gcc-backup/README
106 @@ -0,0 +1,41 @@
107 +What is gcc-backup
108 +==================
109 +
110 +gcc-backup is a directory to backup critical runtime
111 +libraries used by gcc to link in code too big to inline it
112 +from code generator.
113 +
114 +See gcc/doc/libgcc.texi doc in gcc source tree.
115 +
116 +gcc-config is responsible to back up libgcc_s.so.* and it's
117 +runtime dependencies.
118 +
119 +Which systems needed this backup
120 +================================
121 +
122 +During normal system operation these libraries should not be
123 +needed (unless gcc installation is somehow completely broken).
124 +
125 +The main use case for libgcc-backup is booting of a system
126 +with the following properties:
127 +- '/usr' mount is separate from '/' mount
128 +- AND binaries in /bin (say, /bin/bash) are executed before
129 + /usr is mounted
130 +
131 +Which systems link libgcc_s.so in
132 +=================================
133 +
134 +By default gcc attempts to link libgcc_s.so in into every
135 +binary and shared library. If code generator happens to
136 +generate the code that does not refer libgcc_s.so then
137 +-Wl,--as-needed linker option omits the dependency.
138 +
139 +Thus any system might have libgcc_s.so linked into any binary
140 +or shared library.
141 +
142 +What goes into this directory
143 +=============================
144 +
145 +- libgcc_s.so.* itself: gcc driver attempts to link it in as-is
146 +- libunwind.so.*: ia64-*-linux only, a runtime dependency of
147 + libgcc_so.so.*
148
149 diff --git a/gcc-config b/gcc-config
150 index 01e2b90..65b30bc 100755
151 --- a/gcc-config
152 +++ b/gcc-config
153 @@ -42,6 +42,9 @@ PV="@PV@"
154 GENTOO_LIBDIR="@GENTOO_LIBDIR@"
155 [[ ${GENTOO_LIBDIR} == @*@ ]] && GENTOO_LIBDIR="lib"
156
157 +GENTOO_GCC_BACKUP_DIR="@GENTOO_GCC_BACKUP_DIR@"
158 +[[ ${GENTOO_GCC_BACKUP_DIR} == @*@ ]] && GENTOO_GCC_BACKUP_DIR="gcc-backup"
159 +
160 usage() {
161 cat <<-EOF
162 Usage: gcc-config [options] [CC Profile]
163 @@ -316,11 +319,23 @@ handle_split_usr() {
164 if is_same_mountpoint "${EROOT}/lib" "${ROOT}/${LDPATH}" ; then
165 local lib old_libs=0 saved_nullglob=$(shopt -p nullglob)
166 shopt -s nullglob
167 +
168 + # We relied on these copies until Sept 2019.
169 + # Can be removed in 2021.
170 for lib in "${EROOT}"/lib*/libgcc_s{.so*,*dylib} "${EROOT}"/lib*/libunwind.so.7* ; do
171 # If we previously had stuff in /, make sure ldconfig gets re-run.
172 rm -f "${lib}"
173 old_libs=1
174 done
175 +
176 + for lib in \
177 + "${EROOT}"/lib*/"${GENTOO_GCC_BACKUP_DIR}"/libgcc_s.so.* \
178 + "${EROOT}"/lib*/"${GENTOO_GCC_BACKUP_DIR}"/libunwind.so.* ; do
179 + # If we previously had stuff in /, make sure ldconfig gets re-run.
180 + rm -f "${lib}"
181 + old_libs=1
182 + done
183 +
184 ${saved_nullglob}
185 return ${old_libs}
186 fi
187 @@ -328,7 +343,7 @@ handle_split_usr() {
188 # Only bother with this stuff for the native ABI. We assume the user
189 # doesn't have critical binaries for non-native ABIs which is fair.
190 local gcclib
191 - local libdir="${EROOT}${GENTOO_LIBDIR}"
192 + local libdir="${EROOT}/${GENTOO_LIBDIR}/${GENTOO_GCC_BACKUP_DIR}"
193 mkdir -p "${libdir}"/.gcc.config.new || return 0 # !?!?!
194 for gcclib in gcc_s unwind ; do
195 # This assumes that we always have the .so symlink,