Page 1 of 1

Link tests are not allowed after GCC_NO_EXECUTABLES: A possible reason

Posted: Sun Jan 19, 2025 2:46 pm
by CaydendW
Hello OSDEVers,

This is not a question but more of an answer to a problem I had a few days ago concerning making a GCC hosted cross compiler. There are already some threads with this but in the interest of not necrobumping one/all of those, I'm making a quick post detailing my experience and why it happened.

This wasn't my first time doing this charade and I decided I wanted to get a hosted cross compiler ASAP instead of fudging the paths needed to start building ports. Me being me, I also decided to re-roll my own libc. Thus, I filled in the exact bare minimum required to get GCC compiling for my target so that I could have the hosted cross compiler working and ready and I wouldn't have to come back to it when my libc was already mature.

GCC and libgcc compiled and installed without issue once I had the needed functions implemented/prototyped. The issue came when I wanted to quickly get libcstc++ built and installed. When I ran `make all-target-libstc++-v3` (GCC 11.1.0), I got the following cryptic error message:

Code: Select all

checking for shl_load... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES
make: *** [Makefile:12073: configure-target-libstc++-v3] Error 1
To say I was puzzled would be an understatement. I spent a while scratching my head and trying to figure out why it wasn't working. Perhaps it was my poor knowledge of how autoconf works but after kludging configure to not do link tests (Forcefully set gcc_no_link to no), I finally got the C compiler to just error out so I could start adding the required functions of libstdc++ as the compiler needed them (Weird workflow, I know).

I came back later and reconfigured out of curiosity once I had the needed libc functions and lo and behold, it configured fine. No kludges, no nonsense.

The reason I didn't try this first is because:
1. The wiki enrty for hosted cross compiler (https://wiki.osdev.org/Hosted_GCC_Cross-Compiler) lists the minimum requirements needed to get GCC to compile. I then later interpreted the article to imply that if GCC compiled fine, libstdc++ would compile fine too. At least for GCC 11.1.0, this is not the case. libstdc++ needs one hell of a lot more support and seems to refuse to configure unless you have that support.
2. Googling the issue led to a dead-end of Bugzilla reports and unanswered osdev.org threads. The one thread that had the answer that was correct was actually viewtopic.php?t=29983. I misconstrued the answer given by the user 'heat' as saying that I needed a libc of some sort. To make this crystal clear to the next poor soul who gets trapped by this: You need more than just a libc! You need a libc that is complete enough to compile libstdc++ to some extent (To exactly what extent, I don't know). Otherwise, it will not configure and you will get that cryptic error message. You can kludge it using the hack I listed above to get the compiler to show you what functions you need but you will need to go into the configure script and set that by hand.

This also explains why I did not encounter this charade 2 years ago. When I built my first ever hosted cross compiler, my libc was already good enough to compile libstdc++ without a hitch.

Perhaps someone could edit the wiki entry to reflect this. I am sure I'd mess up some or other standard that the wiki seeks so I'll leave it to anyone experienced to do that if they so please.

Hope this is of some use to someone.

Happy programming,
CaydendW

Re: Link tests are not allowed after GCC_NO_EXECUTABLES: A possible reason

Posted: Sun Jan 19, 2025 8:23 pm
by Octocontrabass
CaydendW wrote: Sun Jan 19, 2025 2:46 pmI got the following cryptic error message:
I'd expect there to be another error message buried in a config.log somewhere telling you exactly which libc functionality you're missing. I'm not surprised you couldn't find it, though.
CaydendW wrote: Sun Jan 19, 2025 2:46 pmPerhaps someone could edit the wiki entry to reflect this. I am sure I'd mess up some or other standard that the wiki seeks so I'll leave it to anyone experienced to do that if they so please.
If your post is any indication of your writing ability, you'll be fine.

Re: Link tests are not allowed after GCC_NO_EXECUTABLES: A possible reason

Posted: Mon Jan 20, 2025 1:28 pm
by CaydendW
Hey there Octocontrabass,

Thanks for the response. Oddly enough, the config.log actually had very little useful data so far as I looked. Unless, I missed it further up/down from the section I looked at, I am reasonably sure the config.log had nothing for me. Relevant piece I looked at:

Code: Select all

configure:8635: checking for dlfcn.h
configure:8635:  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    -c -g -O2  conftest.c >&5
conftest.c:50:10: fatal error: dlfcn.h: No such file or directory
   50 | #include <dlfcn.h>
      |          ^~~~~~~~~
compilation terminated.
configure:8635: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "package-unused"
| #define PACKAGE_TARNAME "libstdc++"
| #define PACKAGE_VERSION "version-unused"
| #define PACKAGE_STRING "package-unused version-unused"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| /* end confdefs.h.  */
| #include <stdio.h>
| #ifdef HAVE_SYS_TYPES_H
| # include <sys/types.h>
| #endif
| #ifdef HAVE_SYS_STAT_H
| # include <sys/stat.h>
| #endif
| #ifdef STDC_HEADERS
| # include <stdlib.h>
| # include <stddef.h>
| #else
| # ifdef HAVE_STDLIB_H
| #  include <stdlib.h>
| # endif
| #endif
| #ifdef HAVE_STRING_H
| # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
| #  include <memory.h>
| # endif
| # include <string.h>
| #endif
| #ifdef HAVE_STRINGS_H
| # include <strings.h>
| #endif
| #ifdef HAVE_INTTYPES_H
| # include <inttypes.h>
| #endif
| #ifdef HAVE_STDINT_H
| # include <stdint.h>
| #endif
| #ifdef HAVE_UNISTD_H
| # include <unistd.h>
| #endif
| 
| #include <dlfcn.h>
configure:8635: result: no
configure:8821: checking for objdir
configure:8836: result: .libs
configure:9107: checking if  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    supports -fno-rtti -fno-exceptions
configure:9125:  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    -c -g -O2  -fno-rtti -fno-exceptions conftest.c >&5
cc1: warning: command-line option '-fno-rtti' is valid for C++/D/ObjC++ but not for C
configure:9129: $? = 0
configure:9142: result: no
configure:9162: checking for  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    option to produce PIC
configure:9448: result: -fPIC -DPIC
configure:9460: checking if  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    PIC flag -fPIC -DPIC works
configure:9478:  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    -c -g -O2  -fPIC -DPIC -DPIC conftest.c >&5
configure:9482: $? = 0
configure:9495: result: yes
configure:9519: checking if  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    static flag -static works
configure:9547: result: yes
configure:9562: checking if  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    supports -c -o file.o
configure:9583:  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    -c -g -O2  -o out/conftest2.o conftest.c >&5
configure:9587: $? = 0
configure:9609: result: yes
configure:9617: checking if  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    supports -c -o file.o
configure:9664: result: yes
configure:9697: checking whether the  /home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/xgcc -B/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/bin/ -B/home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/lib/ -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/include -isystem /home/cayden/Documents/Code/Kernel/sola/hosted_cross/x86_64-sola/sys-include    linker (/home/cayden/Documents/Code/Kernel/sola/buildcc/build-gcc/./gcc/collect-ld) supports shared libraries
configure:10777: result: yes
configure:11022: checking dynamic linker characteristics
configure:11693: result: no
configure:11800: checking how to hardcode library paths into programs
configure:11825: result: immediate
configure:11922: checking for shl_load
configure:11922: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
After this it just lists cached variables (I did try this after removing the build directory so no caches existed, same result), output variables and condefs.

What I find somewhat peculiar is that it tried to do a compile test for dclfn.h before but couldn't muster a link test. Maybe someone somewhere with more knowledge and experience with GNU autoconf can see where it indicated that it wanted more functionality but I can't.

Happy programming,
CaydendW

Re: Link tests are not allowed after GCC_NO_EXECUTABLES: A possible reason

Posted: Mon Jan 20, 2025 1:35 pm
by nullplan
My guess is that GCC is not well tested under the condition of dlfcn.h not being available, because dlfcn.h is in POSIX. I'd just implement the file. Note that it is perfectly possible to provide stubs that always error if you don't support dynamic linking. See how far you get that way.

Re: Link tests are not allowed after GCC_NO_EXECUTABLES: A possible reason

Posted: Mon Jan 20, 2025 1:40 pm
by CaydendW
Hey there nullplan,

Thanks for the response. Interestingly enough, on my previous OS, I never actually had a problem without dclfn.h. I did everything with static linking and never provided dclfn.h and it worked like a charm. I got a lot of things ported (Incomplete list: GCC, bash, libstdc++, dash, vim, make, binutils, coreutils, findutils, gawk, grep, nasm). It turns out that autconf is actually quite sane if you libc is mostly sane and will work around you not having dynamic linking quite easily.

Current, I still don't have dclfn.h and it works without a hitch. I suppose that autoconf at least expects a tiny sliver of ISO/POSIX compat to configure which I wasn't giving it and it lost its mind. Not a scenario it was tested/inteded for likely.

Happy programming,
CaydendW

Re: Link tests are not allowed after GCC_NO_EXECUTABLES: A possible reason

Posted: Mon Jan 20, 2025 3:48 pm
by Octocontrabass
CaydendW wrote: Mon Jan 20, 2025 1:28 pmUnless, I missed it further up/down from the section I looked at, I am reasonably sure the config.log had nothing for me.
It's supposed to be somewhere in the logs. I don't know what exactly it would look like, but I suspect it's failure to build a hello world program.
CaydendW wrote: Mon Jan 20, 2025 1:28 pmRelevant piece I looked at:
I don't think that's the right test, it only compiles without linking.