About x86-64 mcmodel=kernel and libgcc
Posted: Fri Jan 08, 2021 2:45 pm
So, in this wiki article, there is this part about how to get libgcc to compile and work with -mcmodel=kernel.
and various other flags mentioned in the GCC documentation to try to make it so that the mcmodel=kernel-version of the libgcc would be build without -fPIC enabled. Even trying to set -fno-pic has thus far not been fruitful.
So I was wondering whether anyone else has had any better luck with this, or whether there really is no other way forwards other than to manually patch the Makefiles in the middle of the build.
Of course a possible solution would be to build libgcc with -mno-red-zone and -mcmodel=large, but that does seem rather inefficient.
Now the problem with this, of course, is the fact that one has to manually edit the Makefile during the build process. I've been trying to experiment with using GCC's target fragment files to try to make it so that for my cross-compiler, libgcc wouldn't be tried to be build with -fPIC enabled, because otherwise it will fail by saying that the kernel mcmodel does not support PIC. Various options including things like setting MULTILIB_OPTIONS into multiple orientations such as:Compiling libgcc with -mcmodel=kernel
This may require a workaround. First compile binutils as usual, then add the binaries to the PATH, and start to compile gcc. When compiling libgcc with -mcmodel=kernel, it will fail. Then patch the Makefile to disable PIC, repeat and continue
Code: Select all
MULTILIBS_OPTIONS = mcmodel=kernel/fpic mno-red-zone
So I was wondering whether anyone else has had any better luck with this, or whether there really is no other way forwards other than to manually patch the Makefiles in the middle of the build.
Of course a possible solution would be to build libgcc with -mno-red-zone and -mcmodel=large, but that does seem rather inefficient.