How to Rename a Kernel Module Name Without Renaming The .Ko Passed to Insmod

How to rename a kernel module name without renaming the .ko passed to insmod?

Rename your obj-m in Makefile and set dependency of obj-m to original module.

For example, I have file hello.c that contain all of my source code. But I want module to be mynewname.

Here is whole Makefile that does this:

obj-m := mynewname.o 
mynewname-objs := hello.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean

I set obj-m to mynewname.o and make mynewname.o dependant on hello.o. After invoking make you'll get mynewname.ko.

Hello world kernel module for android & unknown relocation: 27 when insmod

It turns out I had to use

make CFLAGS_MODULE=-fno-pic

Why need add another dot in section name

Thank you Robert for reminder.
Found the answer in the mailing list
http://www.uwsg.indiana.edu/hypermail/linux/kernel/1002.2/01728.html

The problem is that with -ffunction-sections -fdata-sections gcc
creates sections like .text.head and .data.nosave
whenever someone has innocuous code like this:
static void head(...) {...}
or this:
static int nosave = 1;
somewhere in the kernel. Currently, kernel linker scripts
are confused by such names and put these sections in wrong places.



Related Topics



Leave a reply



Submit