git: c8edd0542647 - main - clang: Support building with GCC and DEBUG_FILES disabled

Jessica Clarke jrtc27 at FreeBSD.org
Tue Aug 24 14:06:01 UTC 2021


The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=c8edd0542647f59ab07dd73e865edd34706397a5

commit c8edd0542647f59ab07dd73e865edd34706397a5
Author:     Jessica Clarke <jrtc27 at FreeBSD.org>
AuthorDate: 2021-08-24 13:59:18 +0000
Commit:     Jessica Clarke <jrtc27 at FreeBSD.org>
CommitDate: 2021-08-24 14:04:25 +0000

    clang: Support building with GCC and DEBUG_FILES disabled
    
    If MK_DEBUG_FILES=no then the Clang link rule has clang as .TARGET,
    rather than clang.full, causing the implicit ${CFLAGS.${.TARGET:T}} to
    be CFLAGS.clang, and thus pull in flags intended for when your compiler
    is Clang, not when linking Clang itself. This doesn't matter if your
    compiler is in fact Clang, but it breaks using GCC as, for example,
    bsd.sys.mk adds -Qunused-arguments to CFLAGS.clang. This is seen when
    trying to build a bootstrap toolchain on Linux where GCC is the system
    compiler.
    
    Thus, introduce a new internal NO_TARGET_FLAGS variable that is set by
    Clang to disable the addition of these implicit flags. This is a bigger
    hammer than necessary, as flags for .o files would be safe, but that is
    not needed for Clang.
    
    Note that the same problem does not arise for LDFLAGS when building LLD
    with BFD, since our build produces a program called ld.lld, not plain
    lld (unlike upstream, where ld.lld is a symlink to lld so they can
    support multiple different flavours in one binary).
    
    Suggested by:   sjg
    Fixes:          31ba4ce8898f ("Allow bootstrapping llvm-tblgen on macOS and Linux")
    MFC after:      1 week
    Reviewed by:    dim, imp, emaste
    Differential Revision:  https://reviews.freebsd.org/D31532
---
 share/mk/bsd.sys.mk          | 9 ++++++++-
 usr.bin/clang/clang/Makefile | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
index a964cf6e596c..80cc3080e552 100644
--- a/share/mk/bsd.sys.mk
+++ b/share/mk/bsd.sys.mk
@@ -273,7 +273,14 @@ LDFLAGS+=	${LDFLAGS.${LINKER_TYPE}}
 # Only allow .TARGET when not using PROGS as it has the same syntax
 # per PROG which is ambiguous with this syntax. This is only needed
 # for PROG_VARS vars.
-.if !defined(_RECURSING_PROGS)
+#
+# Some directories (currently just clang) also need to disable this since
+# CFLAGS.${COMPILER_TYPE}, CFLAGS.${.IMPSRC:T} and CFLAGS.${.TARGET:T} all live
+# in the same namespace, meaning that, for example, GCC builds of clang pick up
+# CFLAGS.clang via CFLAGS.${.TARGET:T} and thus try to pass Clang-specific
+# flags. Ideally the different sources of CFLAGS would be namespaced to avoid
+# collisions.
+.if !defined(_RECURSING_PROGS) && !defined(NO_TARGET_FLAGS)
 .if ${MK_WARNS} != "no"
 CFLAGS+=	${CWARNFLAGS.${.TARGET:T}}
 .endif
diff --git a/usr.bin/clang/clang/Makefile b/usr.bin/clang/clang/Makefile
index ec42fe78cf90..31f092608583 100644
--- a/usr.bin/clang/clang/Makefile
+++ b/usr.bin/clang/clang/Makefile
@@ -34,4 +34,7 @@ MLINKS+= clang.1 cc.1 \
 
 LIBADD+=	z
 
+# Ensure we don't add CFLAGS.clang when using GCC
+NO_TARGET_FLAGS=
+
 .include "../clang.prog.mk"


More information about the dev-commits-src-all mailing list