LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: faxian

编译gcc指定target为i686,在用其编译的代码能运行在i386上吗?

[复制链接]
发表于 2006-4-12 20:09:22 | 显示全部楼层
我在 vmware 里可以运行静态编译的那2个文件。相信是 zip 没有用到 k8 的指令。也许是你的glibc 不够新,有的指令改动了。
可是:

1. 茅:Static linked 的跑不动,说 Illegal instructions,这代表 Pentium 无法识别某些比 Pentium 高端的指令,於是无法执行。推论是 zip 内连带连结的库包含了高端 CPU 的指令,glibc 本身不应有高端 CPU 的指令,因为编译时应该是不用 CFLAGS="-march=xxxxx ...."的,也就是说 zip 本身带了高端 CPU 的指令了

2. 盾:Shared 的可以跑,因为用 shared 方式调用的是本机上的库,自然就可以运行了

I am very confused:confused: :confused: :confused:
vmware系统配置: glibc-2.4 / gcc-4.1.0 / kernel-header-2.6.16 / kernel 2.6.16
哇!走在时代尖端,都是当前最新的了(kernel 除外)!
回复 支持 反对

使用道具 举报

发表于 2006-4-12 20:15:27 | 显示全部楼层
那是不是终极幻想在glibc编译的时候加了参数了?
回复 支持 反对

使用道具 举报

发表于 2006-4-12 20:27:18 | 显示全部楼层
Post by youbest
那是不是终极幻想在glibc编译的时候加了参数了?


偶从来不加参数的。至少在我编译我这个系统的时候,我肯定没加参数。:)。。。。
回复 支持 反对

使用道具 举报

发表于 2006-4-12 20:36:18 | 显示全部楼层
难道要找个会汇编的高人把执行文件反组合才知道真相?
回复 支持 反对

使用道具 举报

发表于 2006-4-13 08:42:43 | 显示全部楼层
偶尔看到的,很不错的文章,值得一读。:)。

http://www.linuxsir.cn/bbs/showthread.php?t=198013
回复 支持 反对

使用道具 举报

发表于 2006-4-13 08:49:32 | 显示全部楼层
Thank you very much for the information.  I'll read it later today.
回复 支持 反对

使用道具 举报

发表于 2006-4-15 14:59:28 | 显示全部楼层
1.18. How can I compile on my fast ix86 machine a working libc for my slow i386? After installing libc, programs abort with "Illegal Instruction".
{AJ} glibc and gcc might generate some instructions on your machine that aren't available on i386. You've got to tell glibc that you're configuring for i386 with adding i386 as your machine, for example:

        ../configure --prefix=/usr i386-pc-linux-gnu

And you need to tell gcc to only generate i386 code, just add `-mcpu=i386' (just -m386 doesn't work) to your CFLAGS.

{UD} This applies not only to the i386. Compiling on a i686 for any older model will also fail if the above methods are not used.


我相信这个就是原因。摘自 GLIBC FAQ。
回复 支持 反对

使用道具 举报

发表于 2006-4-15 15:06:32 | 显示全部楼层
But, how did you run configure in the previous build of your zip package?

I think your host is not i386-pc-linux-gnu, is it?

Also, the -mcpu option is no longer available since gcc-3.4, so it is unlikely your machine will generate i386-only codes.  Am I correct?
回复 支持 反对

使用道具 举报

发表于 2006-4-15 15:53:10 | 显示全部楼层
But, how did you run configure in the previous build of your zip package?


Package zip doesn't have a configure script.

To customize it,  you can use unix/Makefile.
CFLAGS = -O2 -I. -DUNIX $(LOCAL_ZIP)
->
CFLAGS = -O2 -I. -DUNIX $(LOCAL_ZIP) -march=k8

then run:
make -f unix/Makefile generic
(generic is specific to zip, not a common parameter.)

Post by d00m3d
I think your host is not i386-pc-linux-gnu, is it?

Also, the -mcpu option is no longer available since gcc-3.4, so it is unlikely your machine will generate i386-only codes.  Am I correct?


My system was built for i686-pc-linux-gnu.

I used -march instead of -mcpu.
I think my glibc contains something which is  not i386-only. That's why my static build fails in your machine. A different aspect to answer my question. .
回复 支持 反对

使用道具 举报

发表于 2006-4-15 16:05:08 | 显示全部楼层
Oh yes, I forget zip does not come with configure.

Well, then we are looped back (trapped?) to the previous dilemma.  Why does glibc contain higher level machine codes?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表