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: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-11 23:20 UTC by Ed Maste
Modified: 2024-12-12 20:39 UTC (History)
0 users

See Also:


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.