Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.4.204内核driver编译失败 #517

Closed
forever765 opened this issue Jul 18, 2023 · 2 comments
Closed

5.4.204内核driver编译失败 #517

forever765 opened this issue Jul 18, 2023 · 2 comments

Comments

@forever765
Copy link

环境
OS: Centos7.9.2009
Kernel: 5.4.204-1.el7.elrepo.x86_64

# uname -r
5.4.204-1.el7.elrepo.x86_64
# rpm -qa | grep kernel
kernel-debug-devel-3.10.0-1160.59.1.el7.x86_64
kernel-3.10.0-1160.el7.x86_64
kernel-lt-5.4.204-1.el7.elrepo.x86_64
kernel-devel-3.10.0-1160.el7.x86_64
kernel-lt-headers-5.4.204-1.el7.elrepo.x86_64
kernel-3.10.0-1160.59.1.el7.x86_64
kernel-lt-devel-5.4.204-1.el7.elrepo.x86_64

报错信息

git clone https://github.com/bytedance/Elkeid.git
cd Elkeid/driver/LKM/
make clean && make 或 bash build_script/x86_64/batch_compile_el7.sh
In file included from ./include/linux/bug.h:5:0,
                 from ./include/linux/thread_info.h:12,
                 from ./arch/x86/include/asm/preempt.h:7,
                 from ./include/linux/preempt.h:78,
                 from ./include/linux/spinlock.h:51,
                 from ./include/linux/seqlock.h:36,
                 from ./include/linux/time.h:6,
                 from ./include/linux/stat.h:19,
                 from ./include/linux/module.h:10,
                 from /root/Elkeid/driver/LKM/src/../include/kprobe.h:11,
                 from /root/Elkeid/driver/LKM/src/../include/smith_hook.h:14,
                 from /root/Elkeid/driver/LKM/src/smith_hook.c:7:
./arch/x86/include/asm/bug.h:35:22: error: expected identifier or ‘(’ before string constant
  asm_inline volatile("1:\t" ins "\n"    \
                      ^
./arch/x86/include/asm/bug.h:79:2: note: in expansion of macro ‘_BUG_FLAGS’
  _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));  \
  ^
./include/asm-generic/bug.h:98:3: note: in expansion of macro ‘__WARN_FLAGS’
   __WARN_FLAGS(BUGFLAG_ONCE |   \
   ^
./include/linux/netfilter.h:234:7: note: in expansion of macro ‘WARN_ON_ONCE’
   if (WARN_ON_ONCE(hook >= ARRAY_SIZE(net->nf.hooks_arp)))
       ^
In file included from <command-line>:0:0:
././include/linux/compiler_types.h:214:24: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 #define asm_inline asm __inline
                        ^
./arch/x86/include/asm/bug.h:35:2: note: in expansion of macro ‘asm_inline’
  asm_inline volatile("1:\t" ins "\n"    \
  ^
./arch/x86/include/asm/bug.h:79:2: note: in expansion of macro ‘_BUG_FLAGS’
  _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));  \
  ^
./include/asm-generic/bug.h:98:3: note: in expansion of macro ‘__WARN_FLAGS’
   __WARN_FLAGS(BUGFLAG_ONCE |   \
   ^
./include/linux/netfilter.h:234:7: note: in expansion of macro ‘WARN_ON_ONCE’
   if (WARN_ON_ONCE(hook >= ARRAY_SIZE(net->nf.hooks_arp)))
       ^
././include/linux/compiler_types.h:214:24: error: expected ‘(’ before ‘__inline’
 #define asm_inline asm __inline
                        ^
./arch/x86/include/asm/bug.h:35:2: note: in expansion of macro ‘asm_inline’
  asm_inline volatile("1:\t" ins "\n"    \
  ^
./arch/x86/include/asm/bug.h:79:2: note: in expansion of macro ‘_BUG_FLAGS’
  _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));  \
  ^
./include/asm-generic/bug.h:98:3: note: in expansion of macro ‘__WARN_FLAGS’
   __WARN_FLAGS(BUGFLAG_ONCE |   \
   ^
./include/linux/netfilter.h:250:3: note: in expansion of macro ‘WARN_ON_ONCE’
   WARN_ON_ONCE(1);
   ^
In file included from ./include/linux/bug.h:5:0,
                 from ./include/linux/thread_info.h:12,
                 from ./arch/x86/include/asm/preempt.h:7,
                 from ./include/linux/preempt.h:78,
                 from ./include/linux/spinlock.h:51,
                 from ./include/linux/seqlock.h:36,
                 from ./include/linux/time.h:6,
                 from ./include/linux/stat.h:19,
                 from ./include/linux/module.h:10,
                 from /root/Elkeid/driver/LKM/src/../include/kprobe.h:11,
                 from /root/Elkeid/driver/LKM/src/../include/smith_hook.h:14,
                 from /root/Elkeid/driver/LKM/src/smith_hook.c:7:
./arch/x86/include/asm/bug.h:35:22: error: expected identifier or ‘(’ before string constant
  asm_inline volatile("1:\t" ins "\n"    \
                      ^
./arch/x86/include/asm/bug.h:79:2: note: in expansion of macro ‘_BUG_FLAGS’
  _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));  \
  ^
./include/asm-generic/bug.h:98:3: note: in expansion of macro ‘__WARN_FLAGS’
   __WARN_FLAGS(BUGFLAG_ONCE |   \
   ^
./include/linux/netfilter.h:250:3: note: in expansion of macro ‘WARN_ON_ONCE’
   WARN_ON_ONCE(1);
   ^
In file included from <command-line>:0:0:
././include/linux/compiler_types.h:214:24: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 #define asm_inline asm __inline
                        ^
./arch/x86/include/asm/bug.h:35:2: note: in expansion of macro ‘asm_inline’
  asm_inline volatile("1:\t" ins "\n"    \
  ^
./arch/x86/include/asm/bug.h:79:2: note: in expansion of macro ‘_BUG_FLAGS’
  _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));  \
  ^
./include/asm-generic/bug.h:98:3: note: in expansion of macro ‘__WARN_FLAGS’
   __WARN_FLAGS(BUGFLAG_ONCE |   \
   ^
./include/linux/netfilter.h:250:3: note: in expansion of macro ‘WARN_ON_ONCE’
   WARN_ON_ONCE(1);
   ^
make[3]: *** [/root/Elkeid/driver/LKM/src/smith_hook.o] Error 1
make[2]: *** [/root/Elkeid/driver/LKM] Error 2
make[1]: *** [sub-make] Error 2
make[1]: Leaving directory `/usr/src/kernels/5.4.204-1.el7.elrepo.x86_64'
make: *** [all] Error 2
@shenping-bd
Copy link
Collaborator

gcc 版本过低,在展开asm_inline时出错,应该如gcc 9,保持与内核编译环境一致:
cat /proc/version:
Linux version 5.4.204-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)) #1 SMP Tue Jul 5 16:32:13 EDT 2022

CentOS上更换编译链:
yum --enablerepo=extras install centos-release-scl-rh
yum install devtoolset-9-gcc
scl enable devtoolset-9 bash
ref: https://kb.3gnt.net/index.php?View=entry&EntryID=77

@forever765
Copy link
Author

已编译成功,感谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants