aboutsummaryrefslogtreecommitdiff
path: root/contrib/elftoolchain
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2021-12-13 23:44:13 +0000
committerMark Johnston <markj@FreeBSD.org>2021-12-13 23:47:15 +0000
commit3aa0bc89c6a1165cb16987493540372af24e760f (patch)
treecb4e88e3d6bab7c12195e7d3b96600c1aa2d2fac /contrib/elftoolchain
parentc983ec6428ecfa362903cbdba1dc9f4303e2f28c (diff)
downloadsrc-3aa0bc89c6a1165cb16987493540372af24e760f.tar.gz
src-3aa0bc89c6a1165cb16987493540372af24e760f.zip
libdwarf: Add a weak uncompress() symbol
This works around brokenness in buildworld's bootstrapping logic: it uses the source tree's metadata to collect dependency info (such as, "libdwarf depends on libz") but links against static host libraries. If these two are out of sync, as is the case if one builds a commit prior to the introduction of the libz dependency, then the build fails when trying to statically link nm(1). Mitigate the problem by defining a weak uncompress() symbol which simply returns an error. This ensures that the build won't fail when statically linking libdwarf without zlib. The downside is that any tools using libdwarf without zlib will now hit a runtime error if they attempt to decode compressed sections, but at least they'll fail deterministically, and compressed debug info is only enabled by default in main. In particular, this fixes building of branches lacking commit dbf05458e3bd, such as releng branches, stable/12 and 13 and old revisions of main. Previously the nm(1) build would fail with: ld: error: undefined symbol: uncompress >>> referenced by libdwarf_elf_init.c:233 >>> (/usr/src/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c:233) >>> libdwarf_elf_init.o:(_dwarf_elf_init) in archive >>> /usr/lib/libdwarf.a Reported by: dim, ler, krion Reviewed by: imp, emaste Fixes: dbf05458e3bd ("libdwarf: Support consumption of compressed ELF sections") MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33419
Diffstat (limited to 'contrib/elftoolchain')
-rw-r--r--contrib/elftoolchain/libdwarf/zlib_stub.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/elftoolchain/libdwarf/zlib_stub.c b/contrib/elftoolchain/libdwarf/zlib_stub.c
new file mode 100644
index 000000000000..173c581b31ec
--- /dev/null
+++ b/contrib/elftoolchain/libdwarf/zlib_stub.c
@@ -0,0 +1,27 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 The FreeBSD Foundation
+ *
+ * This software was developed by Mark Johnston under sponsorship from
+ * the FreeBSD Foundation.
+ */
+
+#include <sys/cdefs.h>
+
+/*
+ * A hack to allow libdwarf.a to be statically linked without zlib. This is
+ * unfortunately required for FreeBSD <= 13.0 to bootstrap build tools
+ * such as nm(1), as they use metadata from the source tree to generate the
+ * dependency list but then link with the build host's libraries.
+ */
+
+extern int uncompress(void *, unsigned long *, const void *,
+ unsigned long);
+
+int __weak_symbol
+uncompress(void *dst __unused, unsigned long *dstsz __unused,
+ const void *src __unused, unsigned long srcsz __unused)
+{
+ return (-6); /* Z_VERSION_ERROR */
+}