0

i'm crosscompiling a helloworld kernel module

my files are:

hello-1.c

#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
    printk(KERN_INFO "Hello world 1.\n");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye world 1.\n");
}

KBuild

obj-m := hello-1-helper.o
hello-1-helper-y := hsllo-1.o

Makefile

export KERNDIR=/home/myname/NXP/SDK2_0/QorIQ-SDK-V2.0-20160527-yocto/build_t1042d4rdb/tmp/work/t1042d4rdb-fsl-linux/linux-qoriq/4.1-r0/git
export PATH:=/opt/fsl-qoriq/2.0/sysroots/x86_64-fslsdk-linux/usr/bin/powerpc-fsl-linux:${PATH}
export ARCH=powerpc
export ARCH_CFLAGS+= -fPIC

default:
    $(MAKE) -C $(KERNDIR) CROSS_COMPILE=powerpc-fsl-linux- M=`pwd` V=1 modules
clean:
    $(MAKE) -C $(KERNDIR) M=`pwd` clean

And here's my terminal output showing error in insmod command:

module_32: hello-1-helper: unknown ADD relocation: 18
insmod: can't insert 'hello-1-helper.ko': invalid module format

but when i comment below line in makefile, everything is ok.

export ARCH_CFLAGS+= -fPIC

for simple codes like this, i can remove this flag. but in another code that i should use -fPIC flag, i have same error

how can i solve it?

Achal
  • 11,821
  • 2
  • 15
  • 37
Ali
  • 1
  • Quite similar [insmod error: inserting './hello.ko': -1 Invalid module format"](https://stackoverflow.com/questions/34379013/insmod-error-inserting-hello-ko-1-invalid-module-format) – Achal Aug 11 '19 at 08:15
  • `export KERNDIR=` - are you running some t1042d4rdb-fsl-linux kernel? What is your output of `uname -a`? – KamilCuk Aug 11 '19 at 08:40
  • yes. i'm running t1042d4rdb-fsl-linux kernel on the board. uname -a: Linux t1042d4rdb 4.1.8-rt8+gbd51baf #1 SMP Tue Jul 23 11:19:29 IRDT 2019 ppc GNU/Linux – Ali Aug 11 '19 at 09:19
  • Can you please try to add this option `-fno-pie` and see if this helps? – Aleksey Aug 12 '19 at 11:00

0 Answers0