Cross compiling , yes but with `gcc` or `clang` ?

 I need to build a driver for a graphic card of the powerpc architecture.

 Build with `gcc`

The steps to do that seems more of less easy: add toolchain, run make with options to point new toolchain.

First: 

Here in opensuse with `zypper` we added  the `ppc64le` toolchain.
sudo zypper in cross-ppc64le-linux-glibc-devel cross-ppc64le-gcc15-bootstrap 

Second:

Clean previous configs with `mrproper` and then run `all` (maybe you need to run also `menuconfig`)
make -j$(nproc) O=~/LF/cross/powerpc ARCH=powerpc HOSTCC=gcc CROSS_COMPILE=powerpc64le-suse-linux- mrproper
make ARCH=powerpc mrproper
make -j$(nproc) V=1 O=~/LF/cross/powerpc ARCH=powerpc HOSTCC=gcc CROSS_COMPILE=powerpc64le-suse-linux-  all
 

Log:

This is a line from the output, we see how the compiler name is composed with $CROSS_COMPILE plus the compiler name `gcc` in this case.
  powerpc64le-suse-linux-gcc -Wp,-MMD,lib/.iomem_copy.o.d -nostdinc -I/home/jg/LF/linux_work/linux_mainline/arch/powerpc/include -I./arch/powerpc/include/generated -I/home/jg/LF/linux_work/linux_mainline/include -I./include -I/home/jg/LF/linux_work/linux_mainline/arch/powerpc/include/uapi -I./arch/powerpc/include/generated/uapi -I/home/jg/LF/linux_work/linux_mainline/include/uapi -I./include/generated/uapi -include /home/jg/LF/linux_work/linux_mainline/include/linux/compiler-version.h -include /home/jg/LF/linux_work/linux_mainline/include/linux/kconfig.h -include /home/jg/LF/linux_work/linux_mainline/include/linux/compiler_types.h -D__KERNEL__ -mbig-endian -m32 -I /home/jg/LF/linux_work/linux_mainline/arch/powerpc -fmacro-prefix-map=/home/jg/LF/linux_work/linux_mainline/= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -msoft-float -ffixed-r2 -mmultiple -mno-readonly-in-sdata -mcpu=powerpc -mno-prefixed -mno-pcrel -mno-altivec -mno-vsx -mno-mma -fno-asynchronous-unwind-tables -mno-string -mbig-endian -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fomit-frame-pointer -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fmin-function-alignment=4 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=1024 -Wno-main -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -mstack-protector-guard=tls -mstack-protector-guard-reg=r2 -mstack-protector-guard-offset=776 -I/home/jg/LF/linux_work/linux_mainline/lib -Ilib    -DKBUILD_MODFILE='"lib/iomem_copy"' -DKBUILD_BASENAME='"iomem_copy"' -DKBUILD_MODNAME='"iomem_copy"' -D__KBUILD_MODNAME=kmod_iomem_copy -c -o lib/iomem_copy.o /home/jg/LF/linux_work/linux_mainline/lib/iomem_copy.c   ; ./tools/objtool/objtool --static-call   lib/iomem_copy.o  

 

 gcc or clang

But,but, but ... what if you've been playing also with `clang` and you have a leftover like `LLVM=0` in your environment which seems harmless and it seems to say "don't used LLVM (clang)" ;-)  .

That will trigger `clang` event if you have the `make` command with options that points to`gcc` toolchain like `CROSS_COMPILE` . 

In the case of `clang` there is no such different binaries for different architectures , there is only one `clang` binary.

So, if even you have not installed anything to support cross compile with clang  (because in clang the only you need is the  target <triple> option) you can cross compile.

The kernel utilities (makefile) is able to setup the needed options to build based in `CROSS_COMPILE` parameter. 

 


Comments

Popular posts from this blog

I need a i386 kernel.

End of the Mentorship start of new journey

My kernel is building ... after 1h `make` exits with no error