Skip to content

Commit 90239b7

Browse files
authored
Modify versioned-symbol gate to fail if the system libstdc++ requires a newer GLIBCXX/CXXABI than the built one provides:
1 parent 125753e commit 90239b7

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

gcc/13/Containerfile

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,60 @@ RUN set -ex; \
136136
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
137137

138138
# gcc installs .so files in /usr/local/lib64 (and /usr/local/lib)...
139-
RUN set -ex; \
140-
# this filename needs to sort higher than all the architecture filenames ("aarch64-...", "armeabi...", etc)
141-
{ echo '/usr/local/lib64'; echo '/usr/local/lib'; } > /etc/ld.so.conf.d/000-local-lib.conf; \
142-
ldconfig -v; \
143-
# the libc created by gcc might be too old for a newer Debian
144-
# check that the Debian libstdc++ doesn't have newer requirements than the gcc one
145-
deb="$(readlink -ve /usr/lib/*/libstdc++.so* | head -1)"; \
146-
gcc="$(readlink -ve /usr/local/lib*/libstdc++.so | head -1)"; \
147-
# using LD_PRELOAD to make sure "abidiff" itself doesn't fail with the exact error we're trying to test for 😂😭
148-
LD_PRELOAD="$deb" abidiff --no-added-syms "$deb" "$gcc"
139+
# RUN set -ex; \
140+
# # this filename needs to sort higher than all the architecture filenames ("aarch64-...", "armeabi...", etc)
141+
# { echo '/usr/local/lib64'; echo '/usr/local/lib'; } > /etc/ld.so.conf.d/000-local-lib.conf; \
142+
# ldconfig -v; \
143+
# # the libc created by gcc might be too old for a newer Debian
144+
# # check that the Debian libstdc++ doesn't have newer requirements than the gcc one
145+
# deb="$(readlink -ve /usr/lib/*/libstdc++.so* | head -1)"; \
146+
# gcc="$(readlink -ve /usr/local/lib*/libstdc++.so | head -1)"; \
147+
# # using LD_PRELOAD to make sure "abidiff" itself doesn't fail with the exact error we're trying to test for 😂😭
148+
# LD_PRELOAD="$deb" abidiff --no-added-syms "$deb" "$gcc"
149+
150+
RUN set -eux; \
151+
# Make sure /usr/local libs are on the path for ld.so
152+
{ echo '/usr/local/lib64'; echo '/usr/local/lib'; } > /etc/ld.so.conf.d/000-local-lib.conf; \
153+
ldconfig -v; \
154+
\
155+
# Locate system vs built libstdc++
156+
deb="$(readlink -ve /usr/lib/*/libstdc++.so* | head -1)"; \
157+
gcc="$(readlink -ve /usr/local/lib*/libstdc++.so | head -1)"; \
158+
echo "System libstdc++: $deb"; \
159+
echo "Built libstdc++: $gcc"; \
160+
\
161+
# Ensure objdump is available (binutils)
162+
command -v objdump >/dev/null 2>&1 || { \
163+
apt-get update; \
164+
apt-get install -y --no-install-recommends binutils; \
165+
rm -rf /var/lib/apt/lists/*; \
166+
}; \
167+
\
168+
# Highest provided (exports) in a lib: GLIBCXX_* / CXXABI_* versions
169+
max_provided_ver() { \
170+
objdump -T "$1" \
171+
| awk '/GLIBCXX_|CXXABI_/{print $NF}' \
172+
| sed 's/.*@@\|.*@//' \
173+
| sort -V | uniq | tail -n1; \
174+
}; \
175+
# Highest required (undefined imports) from a lib: what this lib needs at runtime
176+
max_required_ver() { \
177+
objdump -T "$1" \
178+
| awk '/UND/ && /GLIBCXX_|CXXABI_/{print $NF}' \
179+
| sed 's/.*@@\|.*@//' \
180+
| sort -V | uniq | tail -n1; \
181+
}; \
182+
\
183+
deb_req="$(max_required_ver "$deb")"; \
184+
gcc_prov="$(max_provided_ver "$gcc")"; \
185+
echo "System libstdc++ requires up to: ${deb_req:-none}"; \
186+
echo "Your GCC build provides up to: ${gcc_prov:-none}"; \
187+
\
188+
# Fail if the system requires a newer version than our built lib provides
189+
if [ -n "${deb_req:-}" ] && [ "$(printf '%s\n%s\n' "$gcc_prov" "$deb_req" | sort -V | tail -n1)" != "$gcc_prov" ]; then \
190+
echo >&2 "ERROR: System requires $deb_req but your libstdc++ provides only $gcc_prov"; \
191+
exit 1; \
192+
fi
149193

150194
# ensure that alternatives are pointing to the new compiler and that old one is no longer used
151195
RUN set -ex; \

0 commit comments

Comments
 (0)