Can't navigate Linux kernel source code

Answered

First of all, i need neither build Linux kernel nor run it. I just want to be able to browse its source code.

My CLion version is CLion 2023.1.3, Build #CL-231.9011.31, built on May 15, 2023. My OS is Fedora 37.

When I open a random file in a newly created project, it looks like that:

 

So I thought maybe I need to build it. Since CLion supports Makefile, and Linux is build on Kbuild which AFAIK is built on top of a Makefile,I decided to go for it. That's what I did:

  1. Run make distclean defconfig clean in a console. Found it here, in a Linux section.
  2. Added V=1 bzImage modules arguments in both locations that seem relevant (I have no idea which one is correct):
  3. Then I pressed "Run Makefile". It didn't work out:
    /usr/bin/make -f /home/vadim/projects/linux/Makefile -C /home/vadim/projects/linux
    make: Entering directory '/home/vadim/projects/linux'
      CALL    scripts/checksyscalls.sh
      DESCEND objtool
    <stdin>:1:10: fatal error: libelf.h: No such file or directory
    compilation terminated.
      INSTALL libsubcmd_headers
      CC      /home/vadim/projects/linux/tools/objtool/arch/x86/special.o
    In file included from /home/vadim/projects/linux/tools/objtool/include/objtool/objtool.h:13,
                     from /home/vadim/projects/linux/tools/objtool/include/objtool/arch.h:11,
                     from /home/vadim/projects/linux/tools/objtool/include/objtool/check.h:11,
                     from /home/vadim/projects/linux/tools/objtool/include/objtool/special.h:10,
                     from arch/x86/special.c:4:
    /home/vadim/projects/linux/tools/objtool/include/objtool/elf.h:10:10: fatal error: gelf.h: No such file or directory
       10 | #include <gelf.h>
          |          ^~~~~~~~
    compilation terminated.
    make[4]: *** [/home/vadim/projects/linux/tools/build/Makefile.build:98: /home/vadim/projects/linux/tools/objtool/arch/x86/special.o] Error 1
    make[3]: *** [/home/vadim/projects/linux/tools/build/Makefile.build:140: arch/x86] Error 2
    make[2]: *** [Makefile:66: /home/vadim/projects/linux/tools/objtool/objtool-in.o] Error 2
    make[1]: *** [Makefile:73: objtool] Error 2
    make: *** [/home/vadim/projects/linux/Makefile:1440: tools/objtool] Error 2
    make: Leaving directory '/home/vadim/projects/linux'

    Process finished with exit code 2

     

Any idea how to make this whole thing work?

1
6 comments

Hello!

Here is the instruction for working with Linux kernel in CLion. And also take a look at these notes: https://twitter.com/andrewshcheglov/status/1364940835448578051.

0

I've tried all the steps described in that doc, but errors still remain. Maybe this google doc has some updates which haven't yet gone online? Haven't tried compilation database generator yet though.

 

0

I think there is a typo. Instead of bear make V=1 bzImage modules, it should be bear -- make V=1 bzImage modules.

When this command finished, I got the following error:

/home/vadim/projects/linux_2/tools/objtool/include/objtool/elf.h:10:10: fatal error: gelf.h: No such file or directory
   10 | #include <gelf.h>
      |          ^~~~~~~~
compilation terminated.
make[4]: *** [/home/vadim/projects/linux_2/tools/build/Makefile.build:98: /home/vadim/projects/linux_2/tools/objtool/arch/x86/special.o] Error 1
make[3]: *** [/home/vadim/projects/linux_2/tools/build/Makefile.build:140: arch/x86] Error 2
make[2]: *** [Makefile:66: /home/vadim/projects/linux_2/tools/objtool/objtool-in.o] Error 2
make[1]: *** [Makefile:73: objtool] Error 2
make: *** [Makefile:1440: tools/objtool] Error 2
0

Have you tried the suggestion about the generated headers (https://twitter.com/andrewshcheglov/status/1364940835448578051)?

Are you able to build the project in Terminal outside CLion?

0

I think OP's errors are irrelevant for me. Anyways, i've run what Andrey wrote, namely 'make include/generated/ arch/x86/include/generated/', but this command itself resulted in the same error:

  CALL    scripts/checksyscalls.sh
  DESCEND objtool
<stdin>:1:10: fatal error: libelf.h: No such file or directory
compilation terminated.
  INSTALL libsubcmd_headers
  CC      /home/vadim/projects/linux_2/tools/objtool/arch/x86/special.o
In file included from /home/vadim/projects/linux_2/tools/objtool/include/objtool/objtool.h:13,
                 from /home/vadim/projects/linux_2/tools/objtool/include/objtool/arch.h:11,
                 from /home/vadim/projects/linux_2/tools/objtool/include/objtool/check.h:11,
                 from /home/vadim/projects/linux_2/tools/objtool/include/objtool/special.h:10,
                 from arch/x86/special.c:4:
/home/vadim/projects/linux_2/tools/objtool/include/objtool/elf.h:10:10: fatal error: gelf.h: No such file or directory
   10 | #include <gelf.h>
      |          ^~~~~~~~
compilation terminated.
make[4]: *** [/home/vadim/projects/linux_2/tools/build/Makefile.build:98: /home/vadim/projects/linux_2/tools/objtool/arch/x86/special.o] Error 1
make[3]: *** [/home/vadim/projects/linux_2/tools/build/Makefile.build:140: arch/x86] Error 2
make[2]: *** [Makefile:66: /home/vadim/projects/linux_2/tools/objtool/objtool-in.o] Error 2
make[1]: *** [Makefile:73: objtool] Error 2
make: *** [Makefile:1440: tools/objtool] Error 2

Regarding your second question, I don't know how to build a project in a terminal. Talking about 'make distclean defconfig clean' -- I've run it in a terminal outside CLion. If you're talking about building a json with a bear tool, I've run 'bear -- make V=1 bzImage modules' in an ordinary terminal as well.

0

ok, so first I've installed dependencies which were missing:

sudo dnf install gcc make ncurses-devel bison flex elfutils-libelf-devel openssl-devel

then built the Linux kernel with an ordinary make command.

make

and its modules:

sudo make modules_install

Then I've opened CLion, repeated all the steps from a google doc, and there is still one error:

<command-line>: fatal error: init/utsversion-tmp.h: No such file or directory

Quick googling didn't help, but I didn't need it that much anyway: browsing Linux code now works, previous errors disappeared.

0

Please sign in to leave a comment.