Skip to content

archlinux编译使用systemtap

chyyuu edited this page Nov 18, 2016 · 2 revisions

参考 https://wiki.archlinux.org/index.php/SystemTap 中的"Kernel rebuild"编译安装linux kernel,注意加上CONFIG_DEBUG_INFO=y选项。

注意 System.map is missing问题。

编译安装最新的systemtap。

然后,重启机器。

注意,与标准的 make install相比,用pacman -U *.pkg.tar.gz OR pacman -U *.pkg.tar,在/lib/modules/4.8.x/build 不是符号链接。传统方式用的是符号链接,导致在stap的第四步gcc编译中,

-I"/usr/local/share/systemtap/runtime" 会成功

-I/home/chyyuu/develop/build"/usr/local/share/systemtap/runtime"会出现找不到runtime_defines.h的问题

正确情况

stap -vvv foo.stp

第四步的输出

Pass 4: using cached /root/.systemtap/cache/c7/stapconf_c7f5c557c08995b9fec7bf5a1dd44256_725.h
Running env -uARCH -uKBUILD_EXTMOD -uCROSS_COMPILE -uKBUILD_IMAGE -uKCONFIG_CONFIG -uINSTALL_PATH -uLD_LIBRARY_PATH PATH=/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-ndk:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/share/bcc/tools:/usr/share/bcc/tools make -C /lib/modules/4.8.8-1-ARCH/build M=/tmp/stapDzHUYS modules CONFIG_DEBUG_INFO= CONFIG_STACK_VALIDATION= ARCH=x86_64 V=1 -j5
make: 进入目录“/usr/lib/modules/4.8.8-1-ARCH/build”
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (		\
echo >&2;							\
echo >&2 "  ERROR: Kernel configuration is invalid.";		\
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
echo >&2 ;							\
/bin/false)
mkdir -p /tmp/stapDzHUYS/.tmp_versions ; rm -f /tmp/stapDzHUYS/.tmp_versions/*
make -f ./scripts/Makefile.build obj=/tmp/stapDzHUYS
(cat /dev/null;   echo kernel//tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.ko;) > /tmp/stapDzHUYS/modules.order
  gcc -Wp,-MD,/tmp/stapDzHUYS/.stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/include -I./arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -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 -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -gdwarf-4 -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -DCC_HAVE_ASM_GOTO -Iinclude2/asm/mach-default -I/lib/modules/4.8.8-1-ARCH/build -include /tmp/stapDzHUYS/stapconf_c7f5c557c08995b9fec7bf5a1dd44256_725.h -freorder-blocks -fasynchronous-unwind-tables -Wframe-larger-than=512 -fno-ipa-icf -Wno-unused -Werror -I"/usr/local/share/systemtap/runtime"  -DMODULE  -DKBUILD_BASENAME='"stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src"'  -DKBUILD_MODNAME='"stap_cd39dfe070426b76af7f67b81c54f1c6_17235"' -c -o /tmp/stapDzHUYS/.tmp_stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.c
  gcc -Wp,-MD,/tmp/stapDzHUYS/.stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/include -I./arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -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 -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -gdwarf-4 -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -DCC_HAVE_ASM_GOTO -Iinclude2/asm/mach-default -I/lib/modules/4.8.8-1-ARCH/build -include /tmp/stapDzHUYS/stapconf_c7f5c557c08995b9fec7bf5a1dd44256_725.h -freorder-blocks -fasynchronous-unwind-tables -Wframe-larger-than=512 -fno-ipa-icf -Wno-unused -Werror -I"/usr/local/share/systemtap/runtime"  -DMODULE  -DKBUILD_BASENAME='"stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0"'  -DKBUILD_MODNAME='"stap_cd39dfe070426b76af7f67b81c54f1c6_17235"' -c -o /tmp/stapDzHUYS/.tmp_stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0.o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0.c
  if [ "-pg" = "-pg" ]; then if [ /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount  "/tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0.o"; fi; fi;
  if [ "-pg" = "-pg" ]; then if [ /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount  "/tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.o"; fi; fi;
  ld -m elf_x86_64   -r -o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_aux_0.o 
make -f ./scripts/Makefile.modpost
  find /tmp/stapDzHUYS/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost -m  -i ./Module.symvers -I /tmp/stapDzHUYS/Module.symvers  -o /tmp/stapDzHUYS/Module.symvers -S  -w  -s -T -
  gcc -Wp,-MD,/tmp/stapDzHUYS/.stap_cd39dfe070426b76af7f67b81c54f1c6_17235.mod.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/include -I./arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -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 -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -gdwarf-4 -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -DCC_HAVE_ASM_GOTO -Iinclude2/asm/mach-default -I/lib/modules/4.8.8-1-ARCH/build -include /tmp/stapDzHUYS/stapconf_c7f5c557c08995b9fec7bf5a1dd44256_725.h -freorder-blocks -fasynchronous-unwind-tables -Wframe-larger-than=512 -fno-ipa-icf -Wno-unused -Werror -I"/usr/local/share/systemtap/runtime"  -DKBUILD_BASENAME='"stap_cd39dfe070426b76af7f67b81c54f1c6_17235.mod"'  -DKBUILD_MODNAME='"stap_cd39dfe070426b76af7f67b81c54f1c6_17235"' -DMODULE  -c -o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.mod.o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.mod.c
  ld -r -m elf_x86_64 -T ./scripts/module-common.lds --build-id  -o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.ko /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.o /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.mod.o
make: 离开目录“/usr/lib/modules/4.8.8-1-ARCH/build”
Spawn waitpid result (0x0): 0
Pass 4: compiled C into "stap_cd39dfe070426b76af7f67b81c54f1c6_17235.ko" in 2030usr/130sys/2815real ms.
Cleaning cache, interval reached 25606 s > 300 s.
Copying /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.ko to /root/.systemtap/cache/cd/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.ko
Copying /tmp/stapDzHUYS/stap_cd39dfe070426b76af7f67b81c54f1c6_17235_src.c to /root/.systemtap/cache/cd/stap_cd39dfe070426b76af7f67b81c54f1c6_17235.c
Copying /tmp/stapDzHUYS/stapconf_c7f5c557c08995b9fec7bf5a1dd44256_725.h to /root/.systemtap/cache/c7/stapconf_c7f5c557c08995b9fec7bf5a1dd44256_725.h


Clone this wiki locally