I'm trying to compile kernel version 4.4 in Ubuntu 16.04 LTS. I added or modified some code to store the block number of the write block in the block I / O layer into the custom buffer.
I modified the codes [linux-kernel-location]/block/blk-core.c (original):
...
#include <custom/custom-buffer.h>
...
blk_qt_t submit_bio(int rw, struct bio *bio)
{
...
if(rw & WRITE)
{
unsigned long cntUnit = bio->bi_bdev->bd_super->s_blocks / bdev_logical_block_size(bio->bi_bdev);
unsigned long blk_no = bio->bi_iter.bi_sector / cntUnit;
count_vm_events(PGPGOUT, count);
custom_buf_write_blk_no(blk_no);
}
...
}
...
[linux-kernel-location]/block/Makefile (original):
...
obj-y += custom/
[linux-kernel-location]/block/Kconfig (original):
...
source "block/custom/Kconfig"
and created directories [linux-kernel-location]/include/custom, [linux-kernel-location]/block/custom. Then, I created files [linux-kernel-location]/include/custom/custom-buffer.h:
#ifndef _CUSTOM_BUFFER_H_
#define _CUSTOM_BUFFER_H_
extern int custom_buf_write_blk_no(unsigned long blk_no);
#endif
[linux-kernel-location]/block/custom/Makefile:
obj-y += custom-buffer.o
[linux-kernel-location]/block/custom/Kconfig:
config CUSTOM_BUFFER
tristate
depends on BLOCK
default y
[linux-kernel-location]/block/custom/custom-buffer.c(include definition of custom_buf_write_blk_no(unsigned long blk_no)
with EXPORT_SYMBOL
macro).
I typed make
command in shell at linux kernel location, and the following results were obtained:
...
LD init/built-in.o
block/built-in.o: In function `submit_bio':
[linux-kernel-location]/block/blk-core.c:2117: undefined reference to `custom_buf_write_blk_no'
block/built-in.o:(___ksymtab+custom_buf_write_blk_no+0x0): undefined reference to `custom_buf_write_blk_no'
Makefile:927: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1
My guess is I need to fix the Makefile, how do I fix it?
Edit: I also know that this is happening because linker can not find the symbol in the linking process. But I don't know how to fix it in the Makefile that the Kbuild system applies to.
Solved by self: custom-buffer.c
has a wrong letter. I fixed it correctly so it was compiled well.
It's too hard to find typos...