tech-pkg archive

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

Avoiding some of the problems with multiple GCCs: deleting older libgcc_s.so



Background: libgcc is a utility library used by GCC containing things
like:
- unwinding code
- utilities to perform float128 calculations
...

Like other libraries, if there's an older one in your lookup path by the
same name, it may be picked up, and then symbols will be missing.

An example of this scenario for gcc-aux is http://gnats.netbsd.org/54506

GCC puts all of its libraries in the same place and under the same
names, so it's hard to opt out of this effect for libgcc_s.so.

For NetBSD, the system libgcc_s.so is in the default lookup path, so
there's always going to be a libgcc_s.so found if something tries to
open it.

Here's a diff I have written, and its application to gcc-aux.
It will avoid installing libgcc_s.so on NetBSD, likely avoiding the
problem.

This hopefully eliminates the bigger issue with pkgsrc GCC.

Please tell me your thoughts and suggestions.
I'd like to eventually switch to gfortran, which also has this issue.
Add option to avoid installing a libgcc, if it's older than the
system libgcc.

Index: lang/gcc-aux/options.mk
===================================================================
RCS file: /cvsroot/pkgsrc/lang/gcc-aux/options.mk,v
retrieving revision 1.6
diff -u -r1.6 options.mk
--- lang/gcc-aux/options.mk	10 Jul 2017 00:21:31 -0000	1.6
+++ lang/gcc-aux/options.mk	8 Sep 2019 09:22:52 -0000
@@ -4,9 +4,11 @@
 # Disable option until further notice
 
 PKG_OPTIONS_VAR=	PKG_OPTIONS.gcc-aux
-PKG_SUPPORTED_OPTIONS=  fortran objc testsuite static bootstrap #nls
+PKG_SUPPORTED_OPTIONS=  fortran objc testsuite static bootstrap no-libgcc #nls
 PKG_SUGGESTED_OPTIONS=  fortran objc #nls
 
+PKG_SUGGESTED_OPTIONS.NetBSD+=	no-libgcc
+
 .include "../../mk/bsd.options.mk"
 
 
@@ -30,6 +32,26 @@
 .endif
 .endif
 
+.if !empty(PKG_OPTIONS:Mdelete-libgcc)
+
+.for _libdir_ in ${_OPSYS_LIB_DIRS}
+BASE_LIBGCC!=			find ${_libdir_} -name libgcc_s.so
+BASE_LIBGCC_MATCH_STRING!=	${ECHO} ${BASE_LIBGCC} ${GCC_BRANCH} | \
+				${AWK} -f ../../mk/scripts/larger_symbol_version.awk
+.if ${BASE_LIBGCC_MATCH_STRING:Mnewer}
+DELETE_INSTALLED_LIBGCC=	yes
+.endif
+.endfor
+
+.if ${DELETE_INSTALLED_LIBGCC:Uno}
+post-install:	delete-installed-libgcc
+
+delete-installed-libgcc:
+	${FIND} ${DESTDIR} -name 'libgcc_s.so*' -delete
+
+.endif
+
+.endif
 
 #################################
 ##  ADD LANGUAGE: Objective-C  ##
Index: mk/defaults/options.description
===================================================================
RCS file: /cvsroot/pkgsrc/mk/defaults/options.description,v
retrieving revision 1.592
diff -u -r1.592 options.description
--- mk/defaults/options.description	7 Sep 2019 04:17:42 -0000	1.592
+++ mk/defaults/options.description	8 Sep 2019 09:22:54 -0000
@@ -566,6 +566,7 @@
 nls			Use native language support.
 nntp			Enable Network News Transport Protocol (NNTP) support.
 nntpcache-pgp		Enable pgp signed nocem support.
+no-libgcc		Avoid installing a libgcc if it's older than the system one
 notmuch-emacs		Install emacs support files for notmuch.
 nspluginwrapper		Enable running non native netscape compatible plugins.
 nss			Enable Network Security Services (NSS) support.
Index: mk/scripts/larger_symbol_version.awk
===================================================================
RCS file: mk/scripts/larger_symbol_version.awk
diff -N mk/scripts/larger_symbol_version.awk
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mk/scripts/larger_symbol_version.awk	8 Sep 2019 09:22:55 -0000
@@ -0,0 +1,85 @@
+#!/usr/bin/awk -f
+
+# $NetBSD$
+
+# Copyright (c) 2017 Maya Rashish <maya%NetBSD.org@localhost>.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Maya Rashish.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+# For each absolute symbol in an ELF binary, extract the component
+# of the symbol name that looks like a version.
+#
+# If the supplied version is larger, return 1
+# 
+# example:
+#     echo "/usr/lib/libgcc_s.so 3.4" | awk -f larger_symbol_version.awk
+
+BEGIN {
+	nm = ENVIRON["NM"]
+	if (nm == "")
+		nm = "nm"
+}
+
+
+function largest_symbol_version(ELF) {
+	cmd = nm " -D " ELF " 2>/dev/null"
+	while ((cmd | getline) > 0) {
+		# Absolute symbol of the form ALPHABET_3.4
+		if (($2 == "A") && ($3 ~ /[A-Za-z_]*[0-9]*\.[0-9]*/)) {
+			split($3, matches, ".")
+
+			sub(/[A-Za-z_]*/,"",matches[1])
+
+			# Force numeric comparisons...
+			current_major = matches[1] + 0
+			current_minor = matches[2] + 0
+
+			if (current_major > target_major) {
+				print "the version of " ELF " is newer than target version " target_major "." target_minor
+				exit 0
+			}
+			if ((current_major == target_major) &&
+			    (current_minor > target_minor)) {
+				print "the version of " ELF " is newer than target version " target_major "." target_minor
+				exit 0
+			}
+		}
+	}
+	print "the version of " ELF " is older than target version " target_major "." target_minor
+	exit 0
+}
+
+{ 
+
+	split($NF, target_version, ".")
+	target_major = target_version[1]
+	target_minor = target_version[2]
+
+	largest_symbol_version($1);
+}


Home | Main Index | Thread Index | Old Index