LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 01-13-2016, 06:15 PM   #1
dfatlq
Member
 
Registered: May 2012
Posts: 49

Rep: Reputation: Disabled
build a static (.a) library for kernel modules.


Hello,

How do you build only a static (.a) library for kernel modules.

The closest I got was with

obj-m:=whatever.o
whatever-objs:=lib.a
lib-y:=linuxdriverc.o
lib-y+=linuxdrivercpp.o
lib-y+=linuxdriverfile.o

that creates the .a library but also some whatever files. I just want the .a library ??? I'd like to name it too, but it looks like it only likes lib.a

TIA!!
 
Old 01-14-2016, 11:49 AM   #2
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
Not sure how to do this. Have you looked at the makefile for the driver? Are you really wanting a static kernel? Sometimes known as a monolithic kernel.

What are you trying to do? What is the goal?
 
Old 01-14-2016, 05:46 PM   #3
dfatlq
Member
 
Registered: May 2012
Posts: 49

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Rinndalir View Post
Not sure how to do this. Have you looked at the makefile for the driver? Are you really wanting a static kernel? Sometimes known as a monolithic kernel.

What are you trying to do? What is the goal?
I want to create static libraries for creating kernel modules (drivers).
 
Old 01-15-2016, 01:57 PM   #4
Rinndalir
Member
 
Registered: Sep 2015
Posts: 733

Rep: Reputation: Disabled
Static modules are somewhat an oxymoron. See what I mean?
 
Old 01-15-2016, 02:32 PM   #5
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by dfatlq View Post
How do you build only a static (.a) library for kernel modules.
You can't, as that doesn't make sense.
Libraries, dynamic or static, are for userspace executables. There simply is no loader-linker for the kernel, other than the kernel module loader.
Also for basic security, kernel modules are in a different format from userspace executables.

Regards

Last edited by blue_z; 01-15-2016 at 02:36 PM.
 
Old 01-15-2016, 05:37 PM   #6
dfatlq
Member
 
Registered: May 2012
Posts: 49

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by blue_z View Post
You can't, as that doesn't make sense.
Libraries, dynamic or static, are for userspace executables. There simply is no loader-linker for the kernel, other than the kernel module loader.
Also for basic security, kernel modules are in a different format from userspace executables.

Regards
In another post I just did, I noticed if I build a .o separately and include it on the build, the symbols are found. If I take that same .o and put it in a static .a library and include that, it will link in the static lib but symbols are not found.

So it looks like for some reason, they only take .o files instead of .a files? There must be a way to have the Makefile automate creating the -objs references from extracting the .a library. I don't understand why they would not accept .a files for convenience and having a library of stable kernel module support files which will only be linked if used?

??
 
Old 01-17-2016, 08:42 PM   #7
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by dfatlq View Post
In another post I just did, I noticed if I build a .o separately and include it on the build, the symbols are found. If I take that same .o and put it in a static .a library and include that, it will link in the static lib but symbols are not found.
Seems like you're asking an XY question. You have a problem X, and came up with solution Y. But you're stuck making Y work, so you're asking for help on Y.
The fundamental issue is really solving X, not Y.

In this case X seems to be functionality that currently exists in userspace (as libraries), that you seem to want to put in kernel space (i.e. in a kernel module).
This is not a simple case of it's just machine code (as you assert in your other thread).
It's a matter of drawing a line between an unsecure userspace and a kernel executing in privileged mode.
You seem to have knowledge of executable file formats and library structures, but ignore the finer points of a secure kernel.

Some functionality can be clearly delegated to user or kernel space. If it's in the grey area, then you can implement it in the kernel, make a case for inclusion into the kernel, and then see if it is accepted by the community for mainline. Or your efforts may get rejected.
Since this functionality seems to already exist in userland rather than the kernel, a decision has already been made, so you may have an uphill battle to reverse that (e.g. your intent to relocate this functionality maybe misguided).

Quote:
Originally Posted by dfatlq View Post
So it looks like for some reason, they only take .o files instead of .a files? There must be a way to have the Makefile automate creating the -objs references from extracting the .a library. I don't understand why they would not accept .a files for convenience and having a library of stable kernel module support files which will only be linked if used?
Who or what is this "they"?
As you've already been told, you simply cannot link kernel code with userspace code.
Security has precedence over convenience.

Regards

Last edited by blue_z; 01-17-2016 at 08:49 PM.
 
Old 01-17-2016, 08:57 PM   #8
dfatlq
Member
 
Registered: May 2012
Posts: 49

Original Poster
Rep: Reputation: Disabled
A static .a library is basically just an archive of object .o files. The linker takes care of selecting the object files needed based on symbols. So I don't see it as having anything to do with userspace.
 
Old 01-18-2016, 06:32 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
To understand why "your request is absurd problematic," kindly consider that ... "in any operating system," there are two worlds:
  • The "user-land" world that is kindly created by the operating-system kernel for the benefit of user programs ... and ...
  • The "kernel" world, which is responsible for creating (the foundations of ...) that environment, but which therefore cannot partake of it.

"The kernel" is an always-resident program whose sole purpose is "to control the system hardware." Programs which run in this environment do not have access to any of the facilities that the kernel is responsible for creating ... nor to any of the "(user-land) system programs," such as ld the Linux loader, which user-land programs "can presume, and therefore utterly ignore."

If you want to create a kernel extension using a library, you must (a) ensure that the library code is statically linked to create an executable, and (b) that the resulting executable has no external references of any kind, nor(!) any expectations of being able to access any of the facilities which exist "in user-land."
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Linking Static library to Kernel Module john.sung Linux - Kernel 2 11-17-2012 07:47 PM
How to link a static library to a kernel module pallava Linux - Newbie 1 09-26-2007 08:25 PM
how to build static library .a using .so and .o for gnash saritha Fedora 0 09-11-2007 12:33 AM
kernel static vs modules JAKK Linux - General 2 01-28-2007 11:04 PM
How can I use gcc to build a static library? vtluu Red Hat 1 04-12-2004 10:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration