0

我是 AIX 的新手。我在编译内核扩展时遇到了很多错误。在那之后,我终于编译并链接了。

但是当我执行二进制文件时,我得到了这个错误。

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

有人可以帮我吗?

//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;
}

我是这样编译的。我误会了什么?

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
4

1 回答 1

1

您的程序不打算在独立环境中运行,所以我猜这-ffreestanding是导致问题的选项。该main函数显然被认为是普通函数,而不是入口点。

于 2012-05-25T13:15:11.520 回答