Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
the scripts for creating Linux kernel modules
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Wed Mar 06, 2024 6:45 am    Post subject: the scripts for creating Linux kernel modules Reply with quote

Hello, forum... can someone tell me the sequence of GCC commands to create a Linux kernel module?
for example, I have the file
Code:
My_module.c


what gcc commands without make need to be executed to get My_module.ko ?
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3855

PostPosted: Wed Mar 06, 2024 9:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Wed Mar 06, 2024 11:21 am    Post subject: Reply with quote

CaptainBlood wrote:


and where do these scripts lie in the kernel source codes?
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1693
Location: South America

PostPosted: Wed Mar 06, 2024 12:07 pm    Post subject: Re: the scripts for creating Linux kernel modules Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Wed Mar 06, 2024 12:12 pm    Post subject: Re: the scripts for creating Linux kernel modules Reply with quote

[quote="GDH-gentoo"]
Gentoopc wrote:
.


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
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1693
Location: South America

PostPosted: Wed Mar 06, 2024 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Wed Mar 06, 2024 12:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1693
Location: South America

PostPosted: Wed Mar 06, 2024 12:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22636

PostPosted: Wed Mar 06, 2024 3:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Wed Mar 06, 2024 5:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22636

PostPosted: Wed Mar 06, 2024 5:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Thu Mar 07, 2024 8:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3693
Location: Rasi, Finland

PostPosted: Thu Mar 07, 2024 8:41 am    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Thu Mar 07, 2024 9:09 am    Post subject: Reply with quote

Zucca wrote:
.


If only it were that simple.
Code:
make -n

Code:
 MAKEFLAGS="-n" make -C

It's all working. it doesn't give flags GCC and ld
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1693
Location: South America

PostPosted: Thu Mar 07, 2024 11:06 am    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Thu Mar 07, 2024 12:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1693
Location: South America

PostPosted: Thu Mar 07, 2024 12:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3855

PostPosted: Thu Mar 07, 2024 1:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Thu Mar 07, 2024 1:59 pm    Post subject: Reply with quote

GDH-gentoo wrote:


this does not output all the gcc commands that are used when building the module. I have an
Code:
  f.c
with the code for the module.
Code:
 make
what options should I specify to make to get all the paths and flags for gcc?
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6145
Location: Dallas area

PostPosted: Thu Mar 07, 2024 2:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gentoopc
Guru
Guru


Joined: 25 Dec 2017
Posts: 364

PostPosted: Thu Mar 07, 2024 2:12 pm    Post subject: Reply with quote

Anon-E-moose wrote:
.


Aren't you guys ashamed of not knowing such things?
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5095
Location: Bavaria

PostPosted: Thu Mar 07, 2024 2:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
wjb
l33t
l33t


Joined: 10 Jul 2005
Posts: 631
Location: Fife, Scotland

PostPosted: Thu Mar 07, 2024 3:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6145
Location: Dallas area

PostPosted: Thu Mar 07, 2024 3:58 pm    Post subject: Reply with quote

Gentoopc wrote:
Anon-E-moose 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
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3693
Location: Rasi, Finland

PostPosted: Thu Mar 07, 2024 5:01 pm    Post subject: Reply with quote

Code:
make SHELL='sh -x'
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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum