unikernelLinux / ukl

Unikernel Linux
GNU Lesser General Public License v2.1
165 stars 12 forks source link

cc1plus: error: code model kernel does not support PIC mode #23

Closed pmmccorm closed 1 year ago

pmmccorm commented 1 year ago

I am following the instructions from the readme, and with gcc version:

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

I get this error when compiling glibc:

$ make stamp-glibc-configure
rm -f stamp-glibc-configure
mkdir -p glibc-build
cd glibc-build && \
/home/pmccormick/scm/ukl/glibc/configure \
    CFLAGS="-g -O2 -fthread-jumps -mcmodel=kernel -mno-red-zone  -UUKL_BP" \
    --prefix=/home/pmccormick/scm/ukl \
    --enable-hacker-mode \
    --enable-timezone-tools \
    --disable-build-nscd \
    --disable-nscd \
    --disable-pt_chown \
    --enable-static-nss \
    --disable-shared \
    --disable-tunables \
    --disable-werror \
    x86_64-ukl \
    build_alias=x86_64-ukl \
    host_alias=x86_64-ukl \
    target_alias=x86_64-ukl
configure: WARNING: you should use --build, --host, --target
checking build system type... x86_64-pc-ukl
checking host system type... x86_64-pc-ukl
checking for x86_64-ukl-gcc... no
checking for gcc... gcc
checking for suffix of object files... configure: error: in `/home/pmccormick/scm/ukl/glibc-build':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
make: *** [Makefile:948: stamp-glibc-configure] Error 1

Which boils down to (using hello-world from the repo as an example):

$  gcc -g -O2 -ggdb -mno-red-zone -mcmodel=kernel -static -c hello-world.c -o hello-world.o
cc1plus: error: code model kernel does not support PIC mode

I also tried with gcc 10 and 11: same error.

clang seems to work fine however, but glibc seems to only support being compiled with gcc.

What am I doing wrong here?

rwmjones commented 1 year ago

Your GCC was compiled with -enable-pie so PIC is always enabled. The kernel model doesn't support PIC so you will need to add a flag such as -fno-pic or -fno-pie.

See also: https://github.com/unikernelLinux/ukl/issues/22

pmmccorm commented 1 year ago

Thanks for the quick reply! I think this will work now with this change:

diff --git a/Makefile.am b/Makefile.am
index 40027d1..ab291f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -115,7 +115,7 @@ LIBC_OBJS = libc.a libpthread.a libm.a librt.a libcrypt.a crt1.o crti.o crtn.o

 noinst_DATA += $(LIBC_OBJS)

-GLIBC_CFLAGS = -g -O2 -fthread-jumps -mcmodel=kernel -mno-red-zone
+GLIBC_CFLAGS = -g -O2 -fthread-jumps -mcmodel=kernel -mno-red-zone -fno-pie
 if ENABLE_BYPASS
 GLIBC_CFLAGS += -DUKL_BP
 else
khers commented 1 year ago

See #24 for a temporary solution and #25 for when we have fixed it.