LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-21-2020, 03:10 PM   #1
zvivered
Member
 
Registered: Sep 2007
Posts: 294

Rep: Reputation: 23
Kernel driver with 2 files - ko contains binary of one file only


Hello,

Attached Makefile and source code for a simple kernel device driver.
With this Makefile, if there a syntax error in file1.c, it's ignored.

file1.o, file2.o, file1.ko are created but it's a fake.

The nm output of file1.o is identical to that of file2.o

Can you please help understand what is wrong in my Makefile ?

Thank you,
Zvika
Attached Files
File Type: txt file1.txt (1.1 KB, 24 views)
File Type: txt file2.txt (891 Bytes, 12 views)
File Type: txt Makefile.txt (213 Bytes, 15 views)
 
Old 03-21-2020, 04:35 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,755

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by zvivered View Post
Hello,
Attached Makefile and source code for a simple kernel device driver. With this Makefile, if there a syntax error in file1.c, it's ignored.

file1.o, file2.o, file1.ko are created but it's a fake.

The nm output of file1.o is identical to that of file2.o Can you please help understand what is wrong in my Makefile ?

Thank you,
Zvika
So you would like us to debug your code for you??? Have you read the docs on the makefiles for kernel modules?
https://www.kernel.org/doc/Documenta...ld/modules.txt

You've been working on kernel modules for at least three years now..your entire makefile (as posted) consists of 7 lines, all of which are pretty straight-forward. Why do you think, if there's an error in the file1.c code and you ignore it, that you're going to get valid output?
 
Old 03-22-2020, 01:47 AM   #3
zvivered
Member
 
Registered: Sep 2007
Posts: 294

Original Poster
Rep: Reputation: 23
Hello TBOne,

I read the link you sent.
Did not find error in my Makefile.

If there is an error in file1.c, build should fail.
But upon build completion I got ko.
It does not make sense.

Accoding to nm, the ko contains symbols from file2 only.

Thank you,
Zvika
 
Old 03-22-2020, 08:47 AM   #4
zvivered
Member
 
Registered: Sep 2007
Posts: 294

Original Poster
Rep: Reputation: 23
Hello,

The right Makefile is:
...
obj-m += mydrv.o
mydrv-y += file1.o
mydrv-y += file2.o
...

The output is mydrv.ko

Thank you,
Zvika
 
Old 03-22-2020, 10:08 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,755

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by zvivered View Post
Hello TBOne,
I read the link you sent. Did not find error in my Makefile.

If there is an error in file1.c, build should fail. But upon build completion I got ko. It does not make sense. Accoding to nm, the ko contains symbols from file2 only.
And since you didn't tell us what this supposed 'syntax error' was/is in your first post (or here), how are we to know what it's doing or why?
Quote:
Originally Posted by zvivered
The right Makefile is:
...
obj-m += mydrv.o
mydrv-y += file1.o
mydrv-y += file2.o
...

The output is mydrv.ko
Glad you read the documentation.
 
  


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
In if test the list contains only one specific string or multiple same specific string Mike_Brown Linux - Newbie 1 01-27-2016 10:52 PM
.oui: cannot execute binary file .oui: cannot execute binary file .oui kazi9822 Linux - Server 18 09-28-2012 04:44 PM
Linux utility to combine two or more binary files into a single binary file mageshvan Programming 7 05-05-2011 08:06 AM
Help: Opening GenICs binary file, writing to binary file for GADGET-2 (in C) parallax147 Programming 0 10-05-2010 11:06 AM
list all contains and subdirectories' contains babis Linux - Newbie 2 10-22-2004 09:40 PM

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

All times are GMT -5. The time now is 06:30 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