git: 01718a2e94da - main - tools/build: Work around broken Clang FreeBSD resource dir logic pre-13
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 31 Jul 2023 17:28:34 UTC
The branch main has been updated by jrtc27:
URL: https://cgit.FreeBSD.org/src/commit/?id=01718a2e94dae03994448f40e0b57a3432f5272c
commit 01718a2e94dae03994448f40e0b57a3432f5272c
Author: Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2023-07-31 17:28:08 +0000
Commit: Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-07-31 17:28:08 +0000
tools/build: Work around broken Clang FreeBSD resource dir logic pre-13
Prior to Clang 13 (e.g. in the Clang 11 present in 13.0-RELEASE), the
resource directory logic for FreeBSD was broken and would not resolve
symlinks, meaning symlinks would only work if in a directory next to the
containing lib directory. Therefore we cannot even use a symlink for
worldtmp, we have to make a wrapper script that execs the real binary
via an absolute path.
Reported by: markj
Reviewed by: markj
Fixes: 65f28f63a73d ("tools/build: Create toolchain symlinks for non-absolute compiler/linker")
Differential Revision: https://reviews.freebsd.org/D41238
---
tools/build/Makefile | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/tools/build/Makefile b/tools/build/Makefile
index 46fd5c7d3159..fd7fd158f169 100644
--- a/tools/build/Makefile
+++ b/tools/build/Makefile
@@ -338,10 +338,21 @@ _host_tools_to_symlink:= ${_host_tools_to_symlink:Nsh}
.endif
# We also need to symlink any non-absolute toolchain commands. Clang finds its
-# resource directory relative to itself, so CC/CXX/CPP must be symlinked, and
-# we do the same for LD for consistency. There should be no concerns about
-# installing over the current system since we don't use the toolchain during
-# install.
+# resource directory relative to itself, so CC/CXX/CPP cannot be copied, and
+# there should be no concerns about installing over the current system since we
+# don't use the toolchain during install, so that's not an issue. However,
+# before Clang 13 there was no symlink detection for FreeBSD so that was broken
+# in the same way as copying (https://reviews.llvm.org/D103346), thus create a
+# wrapper script for each to work around this and behave like a symlink.
+# Remove this hack and just use a symlink once Clang 13 can be assumed.
+# For consistency, we use the same strategy for LD.
+.include <bsd.compiler.mk>
+.if ${.MAKE.OS} == "FreeBSD" && ${COMPILER_TYPE} == "clang" && \
+ ${COMPILER_VERSION} < 130000
+_WRAP_HOST_TOOL= sh -c "printf '\#!/bin/sh\nexec \"\%s\" \"\$$@\"\n' \"\$$0\" > \"\$$1\" && chmod +x \"\$$1\""
+.else
+_WRAP_HOST_TOOL= ${_LINK_HOST_TOOL}
+.endif
.for var in CC CXX CPP LD
.for X in $${_empty_var_} X
.if !empty(${X}${var}) && !${${X}${var}:M/*} && \
@@ -382,7 +393,7 @@ host-symlinks:
echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \
fi; \
rm -f "${DESTDIR}/bin/${_tool}"; \
- ${_LINK_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}"
+ ${_WRAP_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}"
.endfor
# Create all the directories that are needed during the legacy, bootstrap-tools