OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:59 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: simple module build is failing in linux
PostPosted: Fri Jan 18, 2019 1:51 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
First I got include problem for #include <linux/init.h>
By finding where the init.h is I found several locations and specified in makefile the best one that seems to be. Now I am getting build error below.
Since logs are massive (444000 chars), it will not fit here so I put the last section of the log generated from build:

Paths I discovered for init.h and linkage.h
Code:
// centos 72
///usr/src/kernels/3.10.0-327.el7.x86_64/arch/x86/include/asm/init.h
///usr/src/kernels/3.10.0-327.el7.x86_64/include/config/debug/memory/init.h
///usr/src/kernels/3.10.0-327.el7.x86_64/include/config/provide/ohci1394/dma/init.h
///usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/init.h

///usr/src/kernels/3.10.0-327.el7.x86_64/arch/x86/include/asm/linkage.h
///usr/src/kernels/3.10.0-327.el7.x86_64/include/asm-generic/linkage.h
///usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/linkage.h
///usr/src/kernels/3.10.0-327.el7.x86_64.debug/arch/x86/include/asm/linkage.h
///usr/src/kernels/3.10.0-327.el7.x86_64.debug/include/asm-generic/linkage.h
///usr/src/kernels/3.10.0-327.el7.x86_64.debug/include/linux/linkage.h


Makefile and hello module body:
Code:
CC=gcc
I1=/usr/src/kernels/3.10.0-327.el7.x86_64/arch/x86/include/
I2=/usr/src/kernels/3.10.0-327.el7.x86_64/include/
I3=/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/

CFLAGS=-O3 -I $(I1) -I $(I2)

hello: hello.c
    $(CC) $(CFLAGS) hello.c


Code:
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL")

static int hello_init(void) {
//  printk(KERN_ALERT "Hello, world.\n");
    printk("Hello, world.\n");
    return 0;
}

static void hello_exit(void) {
//  printk(KERN_ALERT "Goodbye, cruel world.\n");
    printk("Goodbye, cruel world.\n");
}

module_init(hello_init);
module_exit(hello_exit);


Code:
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2019.01.18 11:43:02 =~=~=~=~=~=~=~=~=~=~=~=
make hello1
gcc -O3 -I /usr/src/kernels/3.10.0-327.el7.x86_64/arch/x86/include/ -I /usr/src/kernels/3.10.0-327.el7.x86_64/include/ hello.c
In file included from hello.c:27:0:
/usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/init.h:155:13: error: expected =, ,, ;, asm or __attribute__ before load_default_modules
void __init load_default_modules(void);
             ^
/usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/init.h:255:13: error: expected =, ,, ;, asm or __attribute__ before parse_early_param
void __init parse_early_param(void);
             ^

...
...
...

  static exitcall_t __exitcall_##fn __exit_call = fn
                                    ^
/usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/init.h:279:24: note: in expansion of macro __exitcall
#define module_exit(x) __exitcall(x);
                        ^
hello.c:44:1: note: in expansion of macro module_exit
module_exit(hello_exit);
^
hello.c:44:24: error: expected declaration specifiers before ; token
module_exit(hello_exit);
                        ^
In file included from /usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/cache.h:4:0,
                 from /usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/time.h:4,
                 from /usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/stat.h:18,
                 from /usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/module.h:10,
                 from hello.c:28:
/usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/kernel.h:255:6: error: old-style parameter declarations in prototyped function definition
void do_exit(long error_code)
      ^
hello.c:44:24: error: expected { at end of input
module_exit(hello_exit);
                        ^
make: *** [hello1] Error 1
[root@dev-learn-rhel7 device-drivers]#

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Fri Jan 18, 2019 2:53 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
You are missing the header files that contain the definitions for __init and __exit_call. To my knowledge both are empty macros. Happy hunting!

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Fri Jan 18, 2019 4:42 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
i need my money now!

i mean answer :lol: :lol:

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Fri Jan 18, 2019 5:59 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
ok, i grepped to see when is the first time the error being reported:


$ egrep -ir "error" hello.build.centos72.log
/usr/src/kernels/3.10.0-327.el7.x86_64/include/linux/init.h:155:13: error: expected =, ,, ;, asm or __attribute__ before load_default_modules


The line 155 os init.h has this line pointing to error:

void __init load_default_modules(void);

Obviously it is complaining about __attribute__ keyword before load_default_modules but I'd rather not add it by myself!

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Fri Jan 18, 2019 6:44 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
The real problem - which I ran into recently myself - is that the information you are working from is out of date; IIUC, according to this video, the kernel module system was completely reworked four years ago. While the method you are using kinda-sorta still works with that version of the kernel (3.10.xxx), it won't work properly in newer kernel versions - there's some backwards compatibility, but it is only just enough to keep older binaries from crashing too often, and for newer code that will make it harder to identify problems if and when something does fail.

You may need to take a moment to process this, which will probably involve banging your head on your desk, screaming expletives, throwing things, etc.

(I am guessing you are using Linux Device Drivers 3rd ed. (2005), or more likely given the kernel version, one of a number of videos based on it from 2014. Unfortunately, plans for a 4th edition were scrapped three years ago...)

I am currently reading Linux Device Drivers Development by John Madieu (2017); I am hoping it is more up to date, though I am hesitant to recommend it until I have read more, as the fact that it is published by the notoriously shoddy Packt fills me with trepidation. I'll try to report on whether it was worth getting sometime after digging deeper into it.

Even if this weren't true, the fact that you are building against kernel 3.10 means it won't run on a system with a different version of the kernel. For the record, 3.10.0 was the version from mid-2013. You would have to build it against your running kernel, which is probably 4.x or so unless you happen to be using a particularly old LTS distro.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Fri Jan 18, 2019 11:41 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
Hi Scrol-l-lea, you hit the bull's eye when you said Linux Device Drivers 3rd edition and that is exactly I am using. I agree I had no confidence in building in 3.x version of kernel which is shipped with centos7.2. I had another VM in which I it is running centos 6.5 with 2.6 kernel. In there it also had build issue too. May be I need to back and check it again. I did not post in my OP however I inded gathered the paths for linux/init.h from 6.5 version you can see in the Makefile section above

Code:
I3=/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/


Based on the page xi of the book, the 3rd ed. covers the 2.6.10 kernel.
centos 65 i worked is 2.6.32-431.el6.x86_64

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Last edited by ggodw000 on Sat Jan 19, 2019 1:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Sat Jan 19, 2019 1:03 am 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
Here is the centos 6.5 with 2.6 kernel compilation error:
First and last few lines:

Code:
make hello
gcc -O3 -I /usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/    hello.c   -o hello
In file included from hello.c:24:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/init.h:255: error: expected =, ,, ;, asm or __attribute__ before parse_early_param
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/init.h:256: error: expected =, ,, ;, asm or __attribute__ before parse_early_options
In file included from /usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/list.h:7,
                 from /usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:9,
                 from hello.c:25:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory
In file included from /usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/list.h:7,
                 from /usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:9,
                 from hello.c:25:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/prefetch.h:53: error: expected declaration specifiers or ... before size_t
.....
.....
.....
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:477: error: expected declaration specifiers or ... before bool
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:480: error: expected =, ,, ;, asm or __attribute__ before each_symbol
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:505: error: expected =, ,, ;, asm or __attribute__ before * token
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h: In function __module_get:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:521: error: _THIS_IP_ undeclared (first use in this function)
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h: In function try_module_get:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:535: error: _THIS_IP_ undeclared (first use in this function)
In file included from hello.c:25:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h: At top level:
/usr/src/kernels/2.6.32-754.10.1.el6.x86_64.debug/include/linux/module.h:762: error: expected ;, , or ) before * token
hello.c:40: error: expected =, ,, ;, asm or __attribute__ before __used
hello.c:41: error: expected =, ,, ;, asm or __attribute__ before __used
make: *** [hello] Error 1
[root@localhost device-drivers]#

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Sat Jan 19, 2019 1:43 am 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
I am amazed how far the I have to go back to 2.6.9, it was centos 4.9!
but starting from 5.0, it jumped to 2.6.18, it looks like no centos used 2.6.10. May be I will try 2.6.18.
Or do you have any book to recommend to start developing on
3.1 kernel or even 2.6.32 version?

Pls let me know the one you are reading.
thx.,

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Mon Jan 21, 2019 12:59 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
ggodw000 wrote:
Pls let me know the one you are reading.


I assume you mean 'let me know how it is', as I put a link to the Amazon US page for it earlier. However, if you need the link again, it is

Linux Device Drivers Development by John Madieu (2017)
https://www.amazon.com/Linux-Device-Dri ... 1785280007

There is also the Packt Publishing page on the book, where they currently have the e-Book on sale for US$5.

https://www.packtpub.com/networking-and ... evelopment

Even at that price, I really don't want to suggest it until I have read more, but you may find it worth trying out for yourself, I guess.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Tue Jan 22, 2019 5:15 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
thanks i am going to evaluate by looking at 1st few pages. It calls out for ubuntu16-04 which is pretty recent version.

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
 Post subject: Re: simple module build is failing in linux
PostPosted: Tue Jan 22, 2019 11:24 pm 
Offline
Member
Member

Joined: Wed Nov 18, 2015 3:04 pm
Posts: 396
Location: San Jose San Francisco Bay Area
I purchased an android version of that book through google playstore after reviewing. After installing ubuntu 16 04 the source helloworld appears to be compiling, therefore I am going to stick with it.

https://github.com/PacktPublishing/Linu ... evelopment

thanks.,

_________________
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 32 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group