Object 为';a、 输出';对象到elf

Object 为';a、 输出';对象到elf,object,hyperlink,loader,cc,Object,Hyperlink,Loader,Cc,抱歉,如果标题没有它应有的好,但我不确定我到底在做什么,除了尝试移植一些旧的sun/vax目标代码 我正试图让“世界上最快的拼字游戏程序”(ANDREW W.APPEL和GUY J.JACOBSON)建立在我的linux机器上。它显然是为sun和vax编写的,并在其上构建/运行 我已经把它建立到需要在DAWG中链接的点。如果下面代码中的行出现错误(因为exec结构中没有a_magic成员) 更改为 header.a_info = OMAGIC; 所有代码都将生成,但生成的自定义加载程序(dic

抱歉,如果标题没有它应有的好,但我不确定我到底在做什么,除了尝试移植一些旧的sun/vax目标代码

我正试图让“世界上最快的拼字游戏程序”(ANDREW W.APPEL和GUY J.JACOBSON)建立在我的linux机器上。它显然是为sun和vax编写的,并在其上构建/运行

我已经把它建立到需要在DAWG中链接的点。如果下面代码中的行出现错误(因为exec结构中没有a_magic成员)

更改为

header.a_info = OMAGIC;
所有代码都将生成,但生成的自定义加载程序(dict.o)的格式(a.out)不正确,因此无法链接入。构建/链接的结束

cc -Os -g -s -o crab main.o manager.o command.o graphics.o genmove.o eval.o checks.o list.o globals.o ./dictionary/dict.o -lcurses -ltermlib
./dictionary/dict.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: crab] Error 1
还有冒犯性的“dict.o”

# file dict.o
dict.o: a.out little-endian 32-bit executable
下面是创建“dict.o”的代码,它首先创建了一个空的头文件

/* Reserve room for .o header in outfile */
    skipheader ()
    {
        struct exec junk;
    
        fwrite (&junk, sizeof junk, 1, outfile);
    }
然后添加一些节点信息

putw (0, outfile);      /* Special node zero */
然后是符号表

/* Two global symbols to be defined in dict.o: */
char s_dawg[] = "_dawg", s_root[] = "_root";

/*
   Putstab puts out the single word in the data segment giving the
   value of the root edge, then writes symbol table and string table
   info into outfile. e is an edge pointing to the root of the dawg.
*/

putstab(e) unsigned long e;
{
    struct nlist    sym;    /* Symbol table entry */

 /* Output data segment ... */
    putw (e, outfile);      /* Value of edge into dawg root */

 /* Symbol table entry for "unsigned long dawg[]" */
    sym.n_un.n_strx = sizeof (long);
                /* First offset into string table just
                   past longword holding string table size
                   */
    sym.n_type = N_TEXT | N_EXT;/* Externally visible in text segment */
    sym.n_desc = N_GSYM;    /* Global symbol */
    sym.n_value = 0;        /* offset 0 in text segment */
    fwrite (&sym, sizeof sym, 1, outfile);/* output symbol (_dawg) */

 /* Symbol table entry for "unsigned long root" */
    sym.n_un.n_strx += sizeof s_dawg;/* Next offset into string table */
    sym.n_type = N_DATA | N_EXT;/* Externally visible in data segment */
    sym.n_desc = N_GSYM;    /* Global symbol */
    sym.n_value += edgesused * sizeof (unsigned long);
    fwrite (&sym, sizeof sym, 1, outfile);/* output symbol (_root) */

    putw (sizeof (long) + sizeof s_dawg + sizeof s_root, outfile);
                /* output size of string table */

    fwrite (s_dawg, sizeof s_dawg, 1, outfile);/* _dawg string */
    fwrite (s_root, sizeof s_root, 1, outfile);/* _root string */
}
最后返回到报头区域,提前重新服务

    /* Fill in .o header in outfile */
fixheader()
{
    struct exec header;

#ifdef SUN4
    header.a_dynamic = 0;
    header.a_toolversion = TV_SUN4;
    header.a_machtype = M_SPARC;
#endif
 /* OMAGIC - magic # for loader .o files */
    header.a_magic = OMAGIC;
 /* Put dawg in text segment to make it shared and r/o */
    header.a_text = edgesused * sizeof (unsigned long);
    header.a_data = sizeof (unsigned long);
    header.a_bss = 0;
 /* Defining two symbols */
    header.a_syms = 2 * sizeof (struct nlist);
    header.a_entry = 0;
    header.a_trsize = 0;
    header.a_drsize = 0;

 /* Write out header info at beginning of outfile */
    rewind (outfile);
    fwrite (&header, sizeof header, 1, outfile);
}
所以,我的问题是,创造一个类似于上述的elf的最佳方法是什么?可以调整结构成员以匹配elf成员吗?我完全是在说jibberish语吗

我还记得很多很多年前,我打过a.out的头球等等,但那是很久以前的事了,我不知道为什么

谢谢你的帮助。请尽量减少虐待

    /* Fill in .o header in outfile */
fixheader()
{
    struct exec header;

#ifdef SUN4
    header.a_dynamic = 0;
    header.a_toolversion = TV_SUN4;
    header.a_machtype = M_SPARC;
#endif
 /* OMAGIC - magic # for loader .o files */
    header.a_magic = OMAGIC;
 /* Put dawg in text segment to make it shared and r/o */
    header.a_text = edgesused * sizeof (unsigned long);
    header.a_data = sizeof (unsigned long);
    header.a_bss = 0;
 /* Defining two symbols */
    header.a_syms = 2 * sizeof (struct nlist);
    header.a_entry = 0;
    header.a_trsize = 0;
    header.a_drsize = 0;

 /* Write out header info at beginning of outfile */
    rewind (outfile);
    fwrite (&header, sizeof header, 1, outfile);
}