Bug 283273 - bin/csh: tc.const.h built with host, not target, headers -- circular dependency
Summary: bin/csh: tc.const.h built with host, not target, headers -- circular dependency
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL: https://reviews.freebsd.org/D48880
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-11 23:20 UTC by Ed Maste
Modified: 2025-02-14 20:21 UTC (History)
0 users

See Also:
linimon: mfc-stable14?
linimon: mfc-stable13-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2024-12-11 23:20:08 UTC
On my laptop I have WIP that has TIOCSTI removed. tcsh supports this (with `#ifdef TIOCSTI` in its source). However, buildworld failed in tcsh:

.../contrib/tcsh/sh.set.c:761:15: error: use of undeclared identifier 'STRfilec'
  761 |     if (adrof(STRfilec) == 0)
      |               ^

tc.const.h is generated via (bin/csh/Makefile):

tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h ${BUILD_TOOLS_META}
        @rm -f ${.TARGET}
        @echo '/* Do not edit this file, make creates it. */' > ${.TARGET}
        @echo '#ifndef _h_tc_const' >> ${.TARGET}
        @echo '#define _h_tc_const' >> ${.TARGET}
        ${CC:N${CCACHE_BIN}} -E ${CFLAGS:C/-DHAVE_ICONV//} ${.ALLSRC} -D_h_tc_const | \
            grep 'Char STR' | \
            sed -e 's/Char \([a-zA-Z0-9_]*\)\(.*\)/extern Char \1[];/' | \
            sort >> ${.TARGET}
        @echo '#endif /* _h_tc_const */' >> ${.TARGET}

This uses the host's headers which in my case do not define TIOCSTI, and as a result there's no definition for STRfilec (comparing stock build on ref14-amd64.freebsd with one on my machine):

$ diff -purw bin/csh/ref-obj/ bin/csh/obj/ | egrep -v 'Only in|Binary files'
diff -purw bin/csh/ref-obj/tc.const.h bin/csh/obj/tc.const.h
--- bin/csh/ref-obj/tc.const.h  2024-12-11 17:17:29.000000000 -0500
+++ bin/csh/obj/tc.const.h      2024-12-11 18:13:33.439537000 -0500
@@ -122,7 +122,6 @@ extern Char STRfignore[];
 extern Char STRfakecom1[];
 extern Char STRfakecom[];
 extern Char STRfignore[];
-extern Char STRfilec[];
 extern Char STRgid[];
 extern Char STRglobdot[];
 extern Char STRglobstar[];
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2024-12-12 00:26:34 UTC
^Triage: tag this as having an inline patch so the automated tools can find it.
Comment 2 Ed Maste freebsd_committer freebsd_triage 2024-12-12 00:48:05 UTC
(The diff above is showing the error, it is not a patch to be applied.)
Comment 3 Ed Maste freebsd_committer freebsd_triage 2024-12-12 13:52:31 UTC
This dates to the original "BSD 4.4 Lite bin Sources" commit, 4b88c807ea9c629dc5691abc7e3cac9ea0d776dd.
Comment 4 Ed Maste freebsd_committer freebsd_triage 2024-12-12 20:25:17 UTC
I'm not sure exactly what's happening here.  If I delete all tc.const.h (find <objdir> -name tc.const.h -print -delete) followed by `make buildworld` tc.const.h is not generated correctly (for either bin/csh or rescue/rescue).

But I think we should be getting the right path via --sysroot in CC. In the buildenv environment I do see

CC=cc -target x86_64-unknown-freebsd15.0 --sysroot=/usr/obj/.../amd64.amd64/tmp -B/usr/obj/.../amd64.amd64/tmp/usr/bin

I tried deleting all tc.const.h  and then running `make buildenv` followed by `make -C bin/csh` and tc.const.h is indeed generated correctly.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2024-12-12 20:34:02 UTC
Oh, I see. tc.const.h is being generated in ">>> stage 2.3: build tools" which does not have the --sysroot set.

From the bin/csh/Makefile:
---
build-tools: gethost 
tc.defs.c: gethost 

DEPENDOBJS+= gethost
gethost: gethost.c sh.err.h tc.const.h sh.h ${BUILD_TOOLS_META}
---
so we build tc.const.h as a dependency of gethost as a stage 2.3 build tool, but for tc.const.h to be correct we need the target headers from stage 4.1.
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-02-09 00:31:32 UTC
A commit in branch main references this bug:

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

commit ed8b456f82ed822652f2abb24d65ab73ac3dbb0a
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-02-07 01:23:47 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-02-09 00:30:55 +0000

    csh: Remove gethost dependency on tc.const.h

    gethost is a build tool built in stage 2.3, but it had a dependency on
    tc.const.h, which requires target headers (that are not installed until
    stage 4.1).  The build falls back to the host's headers if the target
    headers don't yet exist, which may result in a build failure if the
    host's headers don't match the target.

    As gethost.c doesn't actually require the definitions in tc.const.h, add
    a hack to skip the include of tc.const.h and remove the dependency.

    PR:             283273
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Fixes: e754e5f36195 ("Upgrade to 6.10")
    Differential Revision: https://reviews.freebsd.org/D48880

 bin/csh/Makefile | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Comment 7 Mark Linimon freebsd_committer freebsd_triage 2025-02-14 20:21:48 UTC
^Triage: set flags for possible MFCs (just close if not).