SUSE / clang-extract

Other
7 stars 3 forks source link

sample livepatch for cmdline_proc_show created by clang-extract is ~20x bigger than one created by klp-ccp #25

Open marcosps opened 1 month ago

marcosps commented 1 month ago

When creating the livepatch using klp-ccp for file fs/proc/cmdline.c function cmdline_proc_show generates a file of about ~40 LoC, while when generating with clang-extract generates about ~900 LoC. This can be checked on upstream by running the following command:

/usr/local/bin/clang-extract -Wp,-MMD,fs/proc/.cmdline.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/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__ -fmacro-prefix-map=./= -Werror -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -fdump-ipa-clones -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=branch -fno-jump-tables -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -fno-jump-tables -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -ftrivial-auto-var-init=zero -fno-stack-clash-protection -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -flive-patching=inline-clone -fmin-function-alignment=16 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -Wall -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=2048 -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-dangling-pointer -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-overflow -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-restrict -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 -g -fsanitize=kernel-address -fasan-shadow-offset=0xdffffc0000000000 --param asan-globals=1 --param asan-instrumentation-with-call-threshold=10000 --param asan-instrument-allocas=1 --param asan-stack=1 --param asan-kernel-mem-intrinsic-prefix=1 -DKBUILD_MODFILE="fs/proc/proc" -DKBUILD_BASENAME="cmdline" -DKBUILD_MODNAME="proc" -D__KBUILD_MODNAME=kmod_proc -c -o fs/proc/cmdline.o fs/proc/cmdline.c -DCE_DEBUGINFO_PATH=/home/mpdesouza/git/linux/vmlinux -DCE_SYMVERS_PATH=/home/mpdesouza/git/linux/Module.symvers -DCE_OUTPUT_FILE=/home/mpdesouza/kgr/livepatches/proc_cmdline/ce/linux/work_fs_proc_cmdline.c/proc_cmdline_fs_proc_cmdline.c -DCE_OUTPUT_FUNCTION_PROTOTYPE_HEADER=/home/mpdesouza/kgr/livepatches/proc_cmdline/ce/linux/work_fs_proc_cmdline.c/proto.h -DCE_DSC_OUTPUT=/home/mpdesouza/kgr/livepatches/proc_cmdline/ce/linux/work_fs_proc_cmdline.c/lp.dsc -DCE_EXTRACT_FUNCTIONS=cmdline_proc_show -DCE_IPACLONES_PATH=/home/mpdesouza/git/linux/fs/proc/cmdline.c.000i.ipa-clones -DCE_KEEP_INCLUDES -DCE_RENAME_SYMBOLS

Also, it still generates codes that doesn't compile, for example:

In file included from /home/mpdesouza/kgr/livepatches/proc_cmdline/ce/linux/work_fs_proc_cmdline.c/livepatch.c:1009:
./include/linux/module.h:577:9: error: unknown type name ‘ctor_fn_t’
  577 |         ctor_fn_t *ctors;
      |         ^~~~~~~~~

Please let me know if you need more information about it how to reproduce it.

giulianobelinassi commented 1 month ago

Please check if this issue remains after c9e4aa50125388192176582ff828b36d17654a15

Note that clang-extract generating long code is not necessary a bug, but of course we can implement optimizations to reduce code size.

marcosps commented 1 month ago

It still returns the same error, and currently it increased the number of LoC to ~1000. But either way it's still broken, so I believe that we can ignore the number of lines for now.