0

I work a lot with kernels because package them in my distro (Parabola), and sometimes some modifications make one single .c file fail to build. However I wanted to know if there's a way to test one of those single .c files to know if it will end up failing when building the whole kernel. For example, let's say that drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c fails to build, so if I manually do:

$ gcc drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

it fails with:

drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c:23:10: fatal error: linux/moduleparam.h: No such file or directory
   23 | #include <linux/moduleparam.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

most includes are under the includes dir, but idk how to make it work. Is it possible to do what I want? and how?

0

2 Answers 2

0

When gcc fails to build something, it should return a nonzero exit code. When it builds something successfully, it should return 0.

If you are doing this in the shell, you can check the exit code of the most recent command that was run; it lives in the $? variable. You could compare the exit code to 0, and if they don't match, then you can do whatever you want to do when there's an error, something like:

gcc somefile.c
if [ $? != 0 ]; then
# do whatever you want to do on errors
fi
0

If I understand the question correctly you want to know how to build a single .o file within the kernel tree. To do that just invoke make with that single .o file as target. Do this from the linux kernel source root directory.

For example:

$ make ./drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.o
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  DESCEND  objtool
  CC [M]  drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.o
$
1
  • does that work for a clean source? I mean, without having previously built the kernel, because I just tried it and I get the error "*** No rule to make target"
    – Megver83
    Commented May 18, 2020 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.