精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>嵌入式开发>>操作系统设计与实现>>翻译计划—《写你自己的操作系统》>>TEST翻译计划:《DJGPP 能输出ELF格式的文件吗》

主题:TEST翻译计划:《DJGPP 能输出ELF格式的文件吗》
发信人: zelor(东村遗少张作乐)
整理人: wenbobo(2003-01-09 10:07:24), 站内信件
Can DJGPP output the ELF file format? 
DJGPP 能输出ELF格式的文件吗?

Yes! And its quite simple now. What you will need is a good 

installation of DJGPP, you will need sed, bison, flex, bash, etc. 
是的!而且非常简单。你需要一个安装好的DJGPP,你需要sed, bison, flex, 

bash, 等等工具。 

You will also need to do it from a dosbox inside Windows95/98 etc so 

you can use long file names.
你要在WINDOWS95/98等操作系统下开一个dosbox(命令行窗口)来干活,这样的

话可以使用长文件名。
 
First, download the latest binutils. (I used binutils-2.9.1.tar.gz). 

You need the plain binutils, not the binutils for Linux, not the 

binutils for dos, etc, but the plain binutils from any GNU archive 

site.
首先,下载最新的binutils.(我使用binutils-2.9.1.tar.gz)你需要plain 

binutils(这点请BOBO解释一下,我对DJGPP不太了解),不是binutils for 

Linux,也不是binutils for dos或者其他,而是来自于任何GNU架构的plain 

binutils。


Once you have downloaded binutils, if you have LESS than 64mb of 

memory, edit the properties of your dos box and manually enter 65535 

into the box provided for EMS memory, XMS memory and DPMI memory (using 

the selectors in the box will not let you enter 65535 so it must be 

entered by hand).
当你下载了binutils,如果有超过64M的内存,编辑DOS BOX快捷方式的属性,手

工输入65535以规定EMS、XMS和DPMI内存(编辑框旁的调节按钮不允许输入65535

,必须用键盘输入)。

use DJTARX to unpack the binutils into your root directory (its 

easier).
使用DJTARX将binutils释放到根目录(很容易)。

C:
CD \
DJTARX \download\binutils-2.9.1.tar.gz

Once its unpacked you will have to make some very minor modifications 

to you DJGPP installation (nothing drastic!)
你还必须对安装做一些小改动(改动不大!)。

Enter into the DJGPP\bin directory and COPY flex.exe lex.exe, bash.exe 

to sh.exe and make a new directory in your root called \bin and copy 

sh.exe to \bin\sh.exe
进入DJGPP\bin目录并将flex.exe拷贝为lex.exe,将bash.exe拷贝为sh.exe,在

根目录建立一个名为\bin的目录,并将sh.exe拷贝为\bin\sh.exe。

C:
CD \
COPY flex.exe lex.exe
COPY bash.exe sh.exe
MD \bin
COPY \djgpp\bin\bash.exe \bin\sh.exe

The \bin directory must be on the SAME DRIVE as the one you unpacked 

binutils onto, which CAN be a different drive to what DJGPP is 

installed onto.
\bin目录必须与释放的binutils在同一个盘,除非其他盘上已经安装了DJGPP。

Now enter the binutils directory (cd binutils-2.9.1) and edit the 

"configure" script.
现在进入binutils目录(cd binutils-2.9.1)编辑"configure"脚本。

Near the top of the script are three lines that read
脚本前三行如下:

remove 

hard_link
symbolic_link

alter these lines so they read
修改如下:

remove=rm
hard_link=cp
symbolic_link=cp

Save the modified configure script.
保存修改的设置脚本。

Execute the bash shell by typing bash, your prompt should change to 

"bash$ ".
键入bash运行bash shell,你的提示符应改为“bash$ ”。

Now you have to setup bash to work with djgpp, enter these commands.
现在你需要设置bash以配合djgpp,输入如下命令:

export CC="c:/djgpp/bin/gcc.exe"
export LD="c:/djgpp/bin/ld.exe"
export BISON="c:/djgpp/bin/bison.exe"
export YACC="c:/djgpp/bin/bison.exe -y"

Now you are ready to build your new set of ELF utils. First you have to 

run configure with some options.
现在你已经建立了你的新一套ELF工具。首先你必须运行“configure”设置一些

选项。

You can choose what targets you want built into your new set of 

binutils, myself, I built in all targets, just in case I later need 

something other than elf (some a.out formats for BSD, etc!).
你能选择你想用新的binutils生成的目标格式,对我而言,我生成所有目标格式

,万一我今后比ELF格式更需要那些格式呢(比如用于BSD的a.out格式)。

./configure --enable-targets=all --with-gnu-as --with-gnu-ld 

--with-stabs
After a very long process, if all goes well, you will find no errors, 

and will be back at the "bash$ " prompt ready to build your new utils.
经过一个漫长时间的处理,如果一切平安,你将看不到错误,“bash$”提示符返

回,准备着编译你的新工具。

Now... some more tinkering... the configure process is not 100%, you 

have to edit the "libtool" file that's in each directories, 

bfd/libtool, as/libtool, gprof/libtool, ld/libtool and opcodes/libtool. 

So exit from bash ("exit") and use an editor to open those files, and 

just re-save them (make no modifications, just save). This seems to fix 

the crlf/lf/cr unix/dos mechanisms that is a bit broken in libtool.
现在……更多的修补……设置过程尚未成功,你仍需编辑"libtool"文件,该文件

散布在每个子目录中,bfd/libtool, as/libtool, gprof/libtool, ld/libtool 

和 opcodes/libtool。所以离开bash("exit") 用一个编辑器打开这些文件,然后

仅仅重新保存它们即可(不做任何修改,只保存)。这看来是修改回车符在unix

与dos下的差异,这一字节之差将破坏libtool。

Re-enter bash and type "make" and it will build your new utils. If you 

have enabled all targets the resulting .exe files will be about 6 to 

7mb EACH, so strip off the debugging info (strip --strip-all *.exe) and 

then use the DJP compressor on them and they should come out to about 

600 to 900kb each.
重新进入bash,键入“make”,新的工具将建立起来。如果你选择了使用所有目

标格式,最后的.exe文件每个将有6-7MB,赶紧strip掉调试信息吧(strip 

--strip-all *.exe)用,然后用DJP压缩它们,这下它们每个将减成600-900KB。

Alternatively, if you did not want to build all targets you can run 

configure without the "--enable-targets=all" option and replace with 

"--target=i386-unknown-elf".
如果你不愿意建立所有的目标格式,你还有另一条路:你可以运行configure而不

使用"--enable-targets=all"选项,而将其改做"--target=i386-unknown-elf"。

GCC itself does not output ELF/COFF/A.OUT etc files, GCC outputs 

assembler that gets passed to 'AS' which assembles it to whatever 

output format is default.
GCC本身并不能输出ELF/COFF/A.OUT等各种文件格式,GCC输出汇编码,目标代码

的格式取决于汇编器。
 



----
生活,就是理想加泡面。
                    ——张作乐,送你一束玫瑰   
        

[关闭][返回]