为什么不能使用 GCC -O0 标志编译 Linux 内核? (巨大的TLB 中断?)

为什么不能使用 GCC -O0 标志编译 Linux 内核? (巨大的TLB 中断?)
# CC      kernel/fork.o
  gcc -Wp,-MMD,kernel/.fork.o.d -nostdinc -I./arch/um/include -I./arch/um/include/generated  -I./include -I./arch/um/include/uapi -I./arch/um/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -m64 -I./arch/x86/um -I./arch/x86/include -I./arch/x86/include/uapi -I./arch/x86/include/generated -I./arch/x86/include/generated/uapi -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -funsigned-char -std=gnu11 -mcmodel=large -fno-builtin -m64 -D__arch_um__ -I./arch/um/include/shared -I./arch/x86/um/shared -I./arch/um/include/shared/skas -Dvmap=kernel_vmap -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp -Din6addr_loopback=kernel_in6addr_loopback -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr -D_LARGEFILE64_SOURCE -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask -Dmktime=kernel_mktime -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O0 -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-avx -mno-avx2 -fno-allow-store-data-races -Wframe-larger-than=1024 -fno-stack-protector -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-dangling-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-truncation -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -g    -DKBUILD_MODFILE='"kernel/fork"' -DKBUILD_BASENAME='"fork"' -DKBUILD_MODNAME='"fork"' -D__KBUILD_MODNAME=kmod_fork -c -o kernel/fork.o kernel/fork.c  
In file included from ./include/linux/mm_inline.h:10,
                 from kernel/fork.c:46:
./include/linux/swapops.h: In function 'set_pmd_migration_entry':
./include/linux/swapops.h:531:1: error: no return statement in function returning non-void [-Werror=return-type]
  531 | }
      | ^
In file included from kernel/fork.c:52:
./include/linux/hugetlb.h: In function 'hugetlb_follow_page_mask':
./include/linux/hugetlb.h:305:1: error: no return statement in function returning non-void [-Werror=return-type]
  305 | }
      | ^
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:252: kernel/fork.o] Error 1
make[1]: *** [scripts/Makefile.build:497: kernel] Error 2
make: *** [Makefile:2035: .] Error 2

如果你检查linux-6.4.12/include/linux/hugetlb.h你会看到hugetlb_follow_page_maskgets 被定义为BUILD_BUG();这个评论/* should never be compiled in if !CONFIG_HUGETLB_PAGE*/

我在Linux内核代码库中找不到CONFIG_HUGETLB_PAGE控制的地方。由于某种原因,如果您摆脱CC_OPTIMIZE_FOR_PERFORMANCEorCC_OPTIMIZE_FOR_SIZE并尝试引入-O0代替-O2or -Os,它会扰乱 HugeTLB 支持吗?

相关内容