问题
Im newbie at AIX. I got many errors when I compiled kernel extension. After then, finally I compiled and Linked.
But When I excuted the binary, I got this error.
bash# ./sysconfig_1 load ./question.exp
Could not load program ./sysconfig_1:
The program does not have an entry point or
the o_snentry field in the auxiliary haeder is invalid.
Examine file headers with the 'dump -ohv' command
Could anyone help me?
//sysconfig_1.c
#include <sys/types.h>
#include <sys/sysconfig.h>
#include <sys/device.h>
#include <sys/errno.h>
main(int argc, char *argv[])
{
struct cfg_load cl;
struct cfg_kmod ck;
int rc;
int act = -1;
if (argc == 3)
{
if ((strcmp(argv[1], "load")) == 0)
act = SYS_KLOAD;
else if (strcmp(argv[1], "unload") == 0)
act = SYS_KULOAD;
}
if (act == -1)
{
printf("usage: %s load|unload <kmod>\n, argv[0]");
exit(1);
}
cl.path =argv[2];
cl.libpath = NULL;
if (act == SYS_KLOAD)
{
/* Load Kernel Module */
rc = sysconfig(SYS_KLOAD, &cl, sizeof(struct cfg_load));
if (rc == CONF_SUCC)
printf("kload returns %d, kmid = %x\n", rc, cl.kmid);
else
printf("kload returns %d, errno = %d\n", rc); //, errno);
if ((rc == CONF_SUCC) && (cl.kmid != 0))
{
/*
* Invoke entry point (kmod) or config routine (dd)
* for kernel extension with CFG_INIT parameter.
*/
ck.kmid = cl.kmid;
ck.cmd = CFG_INIT;
rc = sysconfig(SYS_CFGKMOD, &ck, sizeof(struct cfg_kmod));
if (rc == CONF_SUCC)
printf("cfgkmod returns %d, kmid = %x\n", rc, cl.kmid);
else
printf("cfgkmod returns %d, errno = %d\n", rc); // , errno);
}
} else {
/* Query to determine if kernel module is loaded. */
rc = sysconfig(SYS_QUERYLOAD, &cl, sizeof(struct cfg_load));
if (rc == CONF_SUCC)
printf("queryload returns %d, kmid = %x\n", rc, cl.kmid);
else
printf("queryload returns %d, errno = %x\n", rc); // , errno);
if ((rc == 0) && (cl.kmid != 0))
{
/*
* Invoke entry point (kmod) or config routine (dd)
* for kernel extension with CGW_TERM parameter.
*/
ck.kmid = cl.kmid;
ck.cmd = CFG_TERM;
ck.mdiptr = 0;
ck.mdilen = 0;
rc = sysconfig(SYS_CFGKMOD, &ck, sizeof(struct cfg_kmod));
if (rc == CONF_SUCC)
printf("cfgkmod returns %d, kmid =%x\n", rc, cl.kmid);
else
{
printf("cfgkmod returns %d, errno =%d\n, rc); //, errno");
exit(rc);
}
/* Unconfigure kernel module. */
rc = sysconfig(SYS_KULOAD, &cl, sizeof(struct cfg_load));
if (rc == CONF_SUCC)
printf("unload returns %d, kmid =%x\n", rc, cl.kmid);
else
printf("unload returns %d, errno =%d\n", rc); // , errno);
}
}
exit(rc);
}
//question.c
#include <stdio.h>
#include <sys/device.h>
question_init(int cmd, struct uio *uio)
{
switch(cmd) {
case CFG_INIT: {
printf("question_init: command=CFW_INIT \n");
break;
}
case CFG_TERM: {
printf("question_init:command=CFG_TERM \n");
break;
}
default:
printf("question_init:command=%d\n", cmd);
}
return 0;
}
question()
{
return 42;
}
I compiled like this. what did I misunderstand?
bash# gcc -D_KERNEL -Wall -g -pipe -maix64 -ffreestanding -msoft-float -c sysconfig_1.c
bash# gcc -D_KERNEL -Wall -g -pipe -maix64 -ffreestanding -msoft-float -c question.c
bash# /usr/bin/ld -o sysconfig_1 -b64 -K -bI:/usr/lib/kernex.exp -lsys -lcsys -lc_r sysconfig_1.o
回答1:
Your program is not intended to run in a freestanding environment, so I guess it's the -ffreestanding
option that causes the problem. The main
function is apparently considered an ordinary function, not an entry point.
来源:https://stackoverflow.com/questions/10749612/errors-when-i-excute-aix-kernel-extension-program