Buildworld fails with external GCC toolchain

From: Yasuhiro Kimura <yasu_at_FreeBSD.org>
Date: Fri, 11 Feb 2022 20:07:56 UTC
Hello,

I'm tring to update devel/binutils port to 2.38. When it was updated
to 2.37.1, there was a suggestion that it should also be checked if
building base system with GCC succeeds as binutils is a part of
external GCC toolchain. So I'd like to do it with binutils 2.38 before
updating the port. And as a preparation for it, I tried building base
system with current external GCC toolchain (that is, with binutils
2.37.1).

At first I read following wiki pages.

https://wiki.freebsd.org/ExternalToolchain
https://wiki.freebsd.org/ExternalGCC

Next I took following steps.

1. Make clean install of 14-CURRENT amd64 with the install image of
   20220210 snapshot.
2. Checkout latest main of src repository (d4b0fa45dc1 at that time).
3. pkg install amd64-gcc9
4. cd /usr/src
5. make -j 4 CROSS_TOOLCHAIN=amd64-gcc9 buildworld buildkernel

Then step 5 failed as following.

----------------------------------------------------------------------
--- all_subdir_rescue ---
/usr/local/bin/x86_64-unknown-freebsd14.0-ld: nc.lo: in function `_$$hide$$ nc.lo main':
(.text.startup+0xd42): warning: warning: mktemp() possibly used unsafely; consider using mkstemp()
/usr/local/bin/x86_64-unknown-freebsd14.0-ld: /usr/obj/usr/src/amd64.amd64/tmp/usr/lib/libncursesw_real.a(lib_set_term.o): in function `_nc_setupscreen_sp':
/usr/src/contrib/ncurses/ncurses/base/lib_set_term.c:415: undefined reference to `_nc_set_buffer_sp'
/usr/local/bin/x86_64-unknown-freebsd14.0-ld: /usr/obj/usr/src/amd64.amd64/tmp/usr/lib/libncursesw_real.a(lib_tstp.o): in function `handle_SIGTSTP':
/usr/src/contrib/ncurses/ncurses/tty/lib_tstp.c:222: undefined reference to `flushinp_sp'
/usr/local/bin/x86_64-unknown-freebsd14.0-ld: /usr/obj/usr/src/amd64.amd64/tmp/usr/lib/libncursesw_real.a(lib_getch.o): in function `check_mouse_activity':
/usr/src/contrib/ncurses/ncurses/base/lib_getch.c:188: undefined reference to `_nc_timed_wait'
/usr/local/bin/x86_64-unknown-freebsd14.0-ld: /usr/obj/usr/src/amd64.amd64/tmp/usr/lib/libncursesw_real.a(lib_getstr.o): in function `wgetnstr':
/usr/src/contrib/ncurses/ncurses/base/lib_getstr.c:106: undefined reference to `erasechar_sp'
/usr/local/bin/x86_64-unknown-freebsd14.0-ld: /usr/src/contrib/ncurses/ncurses/base/lib_getstr.c:107: undefined reference to `killchar_sp'
collect2: error: ld returned 1 exit status
*** [rescue] Error code 1

make[5]: stopped in /usr/obj/usr/src/amd64.amd64/rescue/rescue
--- all_subdir_stand ---

make[2]: stopped in /usr/src
--- all_subdir_share ---

make[2]: stopped in /usr/src
--- all_subdir_rescue ---
1 error

make[5]: stopped in /usr/obj/usr/src/amd64.amd64/rescue/rescue
*** [rescue] Error code 2

make[4]: stopped in /usr/src/rescue/rescue
1 error

make[4]: stopped in /usr/src/rescue/rescue

make[3]: stopped in /usr/src/rescue

make[2]: stopped in /usr/src
--- all_subdir_lib ---

make[2]: stopped in /usr/src
      167.49 real       492.07 user        94.42 sys

make[1]: stopped in /usr/src

make: stopped in /usr/src
----------------------------------------------------------------------

If I check commit messages of main branch over the last few months, I
can find some commits that fix warning message displayed by GCC. So
currently external GCC toolchain seems to work fine. Then what is the
cause of my build failure? Did I do something wrong?

Best Regards.

---
Yasuhiro Kimura