View previous topic :: View next topic |
Author |
Message |
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Wed Mar 06, 2024 6:45 am Post subject: the scripts for creating Linux kernel modules |
|
|
Hello, forum... can someone tell me the sequence of GCC commands to create a Linux kernel module?
for example, I have the file
what gcc commands without make need to be executed to get My_module.ko ? |
|
Back to top |
|
|
CaptainBlood Advocate
Joined: 24 Jan 2010 Posts: 3855
|
Posted: Wed Mar 06, 2024 9:23 am Post subject: |
|
|
Although possibly overkilling, sys-fs/vhba package might help as a template, as it builds against current /usr/src/linux.
Thks 4 ur attention, interest & support. _________________ USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. " |
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Wed Mar 06, 2024 11:21 am Post subject: |
|
|
and where do these scripts lie in the kernel source codes? |
|
Back to top |
|
|
GDH-gentoo Veteran
Joined: 20 Jul 2019 Posts: 1693 Location: South America
|
Posted: Wed Mar 06, 2024 12:07 pm Post subject: Re: the scripts for creating Linux kernel modules |
|
|
Gentoopc wrote: | what gcc commands without make need to be executed to get My_module.ko ? |
None. Kernel modules are created with the kernel's build system, i. e. with the one thing you said you don't want to use, the make command.
Well, that is a half lie actually, the compiler invocations are in kernel makefiles. People don't brother trying to reproduce a build by typing compiler invocations from a shell, though. Using the build system is just way more convenient. That's why build systems exist. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though |
|
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Wed Mar 06, 2024 12:12 pm Post subject: Re: the scripts for creating Linux kernel modules |
|
|
[quote="GDH-gentoo"]
Code: |
gcc -Wall -Werror -std=gnu11 -nostdinc -ffreestanding -O2 -pipe -m32 -c My_module.c
ld -m elf_i386 my_module.o -o my_module.ko
|
what needs to be added here for the module to be assembled? |
|
Back to top |
|
|
GDH-gentoo Veteran
Joined: 20 Jul 2019 Posts: 1693 Location: South America
|
Posted: Wed Mar 06, 2024 12:21 pm Post subject: |
|
|
I don't know. If I wanted to create a module, I'd just hook to the kernel's build system and use make M=some-pathname modules. And I bet the majority here would as well.
Build systems exist for a reason. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though |
|
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Wed Mar 06, 2024 12:29 pm Post subject: |
|
|
GDH-gentoo wrote: | I don't know. If I wanted to create a module, I'd just hook to the kernel's build system and use make M=some-pathname modules. And I bet the majority here would as well.
|
It's not about who would do what, it's about knowledge. |
|
Back to top |
|
|
GDH-gentoo Veteran
Joined: 20 Jul 2019 Posts: 1693 Location: South America
|
Posted: Wed Mar 06, 2024 12:43 pm Post subject: |
|
|
And you don't see the correlation? Knowledge can be acquired, but it takes time and energy, and people invest them for a goal they consider worth it. _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though |
|
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22636
|
Posted: Wed Mar 06, 2024 3:22 pm Post subject: |
|
|
Gentoopc, why are you trying to avoid use of make here? It makes your life simpler, and makes the details the responsibility of the kernel maintainers, rather than requiring you to know intricate details. At worst, you could make your module once using the kernel's Makefiles, make make print the commands it uses to make the module, and then adapt those in an external script. |
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Wed Mar 06, 2024 5:12 pm Post subject: |
|
|
Hu wrote: | Makefiles, make make print the commands it uses to make the module, and then adapt those in an external script. |
how to do it right? |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22636
|
Posted: Wed Mar 06, 2024 5:55 pm Post subject: |
|
|
Make make verbose when making the module using the kernel Makefile. Normally, make makes a show of the commands it runs, but the kernel Makefiles make make silent by default, so you need to make make verbose. |
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Thu Mar 07, 2024 8:10 am Post subject: |
|
|
Hu wrote: | Make make verbose when making the module using the kernel Makefile. Normally, make makes a show of the commands it runs, but the kernel Makefiles make make silent by default, so you need to make make verbose. |
Can you be more precise? which make options should I enter to see which options gcc uses and which link is called? |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3693 Location: Rasi, Finland
|
Posted: Thu Mar 07, 2024 8:41 am Post subject: |
|
|
You're looking for this: Building External Modules
Gentoopc wrote: | Can you be more precise? which make options should I enter to see which options gcc uses and which link is called? |
man make: | -n, --just-print, --dry-run, --recon
Print the commands that would be executed, but do not exe‐
cute them (except in certain circumstances). |
That's all I can really give, as I have no further experience on this field. _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Thu Mar 07, 2024 9:09 am Post subject: |
|
|
If only it were that simple.
Code: | MAKEFLAGS="-n" make -C |
It's all working. it doesn't give flags GCC and ld |
|
Back to top |
|
|
GDH-gentoo Veteran
Joined: 20 Jul 2019 Posts: 1693 Location: South America
|
Posted: Thu Mar 07, 2024 11:06 am Post subject: |
|
|
make V=1 other arguments _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though |
|
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Thu Mar 07, 2024 12:49 pm Post subject: |
|
|
GDH-gentoo wrote: | make V=1 other arguments |
can you specifically tell me which commands to prescribe? Or are there more riddles? |
|
Back to top |
|
|
GDH-gentoo Veteran
Joined: 20 Jul 2019 Posts: 1693 Location: South America
|
Posted: Thu Mar 07, 2024 12:58 pm Post subject: |
|
|
Gentoopc wrote: | can you specifically tell me which commands to prescribe? Or are there more riddles? |
Gentoopc wrote: | Can you be more precise? which make options should I enter to see which options gcc uses and which link is called? |
I was answering this. Didn't you want to know how to make make verbose when building the kernel and its modules? Isn't that what the last posts in this thread are about? _________________
NeddySeagoon wrote: | I'm not a witch, I'm a retired electronics engineer |
Ionen wrote: | As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though |
|
|
Back to top |
|
|
CaptainBlood Advocate
Joined: 24 Jan 2010 Posts: 3855
|
Posted: Thu Mar 07, 2024 1:30 pm Post subject: |
|
|
Trials and errors are key to science and engineering.
Google
Thks 4 ur attention, interest & support. _________________ USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. " |
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Thu Mar 07, 2024 1:59 pm Post subject: |
|
|
this does not output all the gcc commands that are used when building the module. I have an with the code for the module.
what options should I specify to make to get all the paths and flags for gcc? |
|
Back to top |
|
|
Anon-E-moose Watchman
Joined: 23 May 2008 Posts: 6145 Location: Dallas area
|
Posted: Thu Mar 07, 2024 2:09 pm Post subject: |
|
|
If you're really curioud do "man make" and read, read, read.
Or you can just run the make command, and monitor what is executing including flags, in the ps command. There's a man page for that too. _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
|
Gentoopc Guru
Joined: 25 Dec 2017 Posts: 364
|
Posted: Thu Mar 07, 2024 2:12 pm Post subject: |
|
|
Aren't you guys ashamed of not knowing such things? |
|
Back to top |
|
|
pietinger Moderator
Joined: 17 Oct 2006 Posts: 5095 Location: Bavaria
|
Posted: Thu Mar 07, 2024 2:29 pm Post subject: |
|
|
Gentoopc wrote: | Aren't you guys ashamed of not knowing such things? |
That must mean that you are ashamed too. You don't have to be, because you can't know everything ... but you can read. _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
|
wjb l33t
Joined: 10 Jul 2005 Posts: 631 Location: Fife, Scotland
|
Posted: Thu Mar 07, 2024 3:57 pm Post subject: |
|
|
Gentoopc wrote: |
Aren't you guys ashamed of not knowing such things? |
<offtopic by="alongway">
Face is a terrible thing. Just grin and say "nah" if someone says you should be ashamed to not know summat. If you're kippered anyway, you might as well have fun.
</offtopic> |
|
Back to top |
|
|
Anon-E-moose Watchman
Joined: 23 May 2008 Posts: 6145 Location: Dallas area
|
Posted: Thu Mar 07, 2024 3:58 pm Post subject: |
|
|
Gentoopc wrote: |
Aren't you guys ashamed of not knowing such things? |
All the irony meters across the world just exploded.
People are trying to help you by telling you how to fish, obviously you just want someone else to hand you the fish. _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3693 Location: Rasi, Finland
|
Posted: Thu Mar 07, 2024 5:01 pm Post subject: |
|
|
might get you what you want.
But why do you want to see those commands?
Didn't the commands on kbuild documentation ran succesfully? _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
|