LoginSignup
7
4

More than 5 years have passed since last update.

Linuxカーネルのビルド要件

Posted at

前にtiwtterでやりとしたことのまとめ的に φ(..)メモメモ

Linuxカーネルのビルド要件(gccのバージョンとか)はv4.9まではDocumentation/Changesファイルに、v4.10からはDocumentation/process/changes.rstに記載されています。例えばv4.19-rc1だとこんな感じです。

====================== ===============  ========================================
        Program        Minimal version       Command to check the version
====================== ===============  ========================================
GNU C                  4.6              gcc --version
GNU make               3.81             make --version
binutils               2.20             ld -v
flex                   2.5.35           flex --version
bison                  2.0              bison --version
util-linux             2.10o            fdformat --version
kmod                   13               depmod -V
e2fsprogs              1.41.4           e2fsck -V
jfsutils               1.1.3            fsck.jfs -V
reiserfsprogs          3.6.3            reiserfsck -V
xfsprogs               2.6.0            xfs_db -V
squashfs-tools         4.0              mksquashfs -version
btrfs-progs            0.18             btrfsck
pcmciautils            004              pccardctl -V
quota-tools            3.09             quota -V
PPP                    2.4.0            pppd --version
isdn4k-utils           3.1pre1          isdnctrl 2>&1|grep version
nfs-utils              1.0.5            showmount --version
procps                 3.2.0            ps --version
oprofile               0.9              oprofiled --version
udev                   081              udevd --version
grub                   0.93             grub --version || grub-install --version
mcelog                 0.6              mcelog --version
iptables               1.4.2            iptables -V
openssl & libcrypto    1.0.0            openssl version
bc                     1.06.95          bc --version
Sphinx\ [#f1]_         1.3      sphinx-build --version
====================== ===============  ========================================

基本的にはLinuxカーネルをビルドするための最小バージョンが定義されます。上限は特に決められてないですね。
最近のカーネルでバージョンの上限に引っかかることはあまりないと思いますが、何かしらの理由で古いカーネルをビルドしたい場合は上限に引っかかる場合があります。

ここで、gcc8の登場です。

masami@fedora:~$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.1.1 20180712 (Red Hat 8.1.1-5) (GCC) 

そしてv4.0をgcc8でビルドするとこうなります。

In file included from include/linux/compiler.h:54,
                 from include/uapi/linux/stddef.h:1,
                 from include/linux/stddef.h:4,
                 from ./include/uapi/linux/posix_types.h:4,
                 from include/uapi/linux/types.h:13,
                 from include/linux/types.h:5,
                 from include/linux/mod_devicetable.h:11,
                 from scripts/mod/devicetable-offsets.c:2:
include/linux/compiler-gcc.h:107:1: fatal error: linux/compiler-gcc8.h: No such file or directory                                                            
 #include gcc_header(__GNUC__)
 ^~~~
compilation terminated.

linux/compiler-gcc8.hがないと怒られてますヽ(`Д´)ノプンプン これは何故かと言うと、以下のようにコンパイラ&コンパイラのバージョンによって読み込むヘッダを切り替えるようになっているからです。そのため、リリース時点で存在しなかったgccバージョンは対応してません。

masami@fedora:~/linux-4.0$ ls -l  include/linux/compiler-*
-rw-rw-r--. 1 masami masami  320 Apr 13  2015 include/linux/compiler-clang.h
-rw-rw-r--. 1 masami masami  635 Apr 13  2015 include/linux/compiler-gcc3.h
-rw-rw-r--. 1 masami masami 3089 Apr 13  2015 include/linux/compiler-gcc4.h
-rw-rw-r--. 1 masami masami 2484 Apr 13  2015 include/linux/compiler-gcc5.h
-rw-rw-r--. 1 masami masami 4280 Apr 13  2015 include/linux/compiler-gcc.h
-rw-rw-r--. 1 masami masami 1047 Apr 13  2015 include/linux/compiler-intel.h

gccのバージョンについてはcompiler-gcc: integrate the various compiler-gcc[345].h filesで削除されてv4.2にこのコミットが入っているので、v4.2からは上限に当たることはないのではと思います。

これを力技でcompiler-gcc5.hをcompiler-gcc8.hとしてコピーしてビルドするとワーニングが結構うるさくなります。

nclude/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]
 int ____ilog2_NaN(void);
 ^~~
  CC      arch/x86/kernel/cpu/perf_event_intel_ds.o
In file included from include/linux/kernel.h:11,
                 from include/linux/list.h:8,
                 from include/linux/wait.h:6,
                 from include/linux/fs.h:6,
                 from fs/exportfs/expfs.c:12:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]
 int ____ilog2_NaN(void);
 ^~~
  LD      fs/exportfs/exportfs.o
  LD      fs/exportfs/built-in.o
  CC      fs/ext4/balloc.o
In file included from include/linux/kernel.h:11,
                 from include/linux/list.h:8,
                 from include/linux/preempt.h:10,
                 from include/linux/spinlock.h:50,
                 from include/linux/mmzone.h:7,
                 from include/linux/gfp.h:5,
                 from include/linux/slab.h:14,
                 from arch/x86/kernel/cpu/perf_event_intel_ds.c:3:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]
 int ____ilog2_NaN(void);
 ^~~
In file included from include/linux/kernel.h:11,
                 from mm/memory-failure.c:38:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]
 int ____ilog2_NaN(void);
 ^~~
  CC      arch/x86/kernel/cpu/perf_event_intel.o
  CC      mm/cleancache.o
In file included from include/linux/kernel.h:11,
                 from include/linux/list.h:8,
                 from include/linux/module.h:9,
                 from mm/cleancache.c:14:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]
 int ____ilog2_NaN(void);
 ^~~
  CC      mm/page_isolation.o

それでもなんとかビルドできました(^o^)

Setup is 16252 bytes (padded to 16384 bytes).                                                                                                                 
System is 6186 kB                                                                                                                                             
CRC 70c0f49e                                                                                                                                                  
Kernel: arch/x86/boot/bzImage is ready  (#1) 

だがしかし、古いgccが必要ならそのバージョンがあるディストリビューションをvmとかで動かしたほうが手軽だと思います。

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4