simple module build is failing in linux

Programming, for all ages and all languages.
Post Reply
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

simple module build is failing in linux

Post by ggodw000 »

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: Select all

// 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: Select all

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: Select all

#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: Select all

=~=~=~=~=~=~=~=~=~=~=~= 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
nullplan
Member
Member
Posts: 1770
Joined: Wed Aug 30, 2017 8:24 am

Re: simple module build is failing in linux

Post by nullplan »

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!
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

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
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

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
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: simple module build is failing in linux

Post by Schol-R-LEA »

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.
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

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: Select all

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
Last edited by ggodw000 on Sat Jan 19, 2019 1:31 am, edited 1 time in total.
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
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

Here is the centos 6.5 with 2.6 kernel compilation error:
First and last few lines:

Code: Select all

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
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

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
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: simple module build is failing in linux

Post by Schol-R-LEA »

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.
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

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
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: simple module build is failing in linux

Post by ggodw000 »

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
Post Reply