linux: 将32位.o文件和64位.o文件链接成64位的可执行程序
来源:互联网 发布:可以看youtube 软件 编辑:程序博客网 时间:2024/06/05 16:46
- torshie@Orz:/tmp$ cat t.c
- int f() {
- int x = 35;
- int y = 20;
- return x + y;
- }
- torshie@Orz:/tmp$ cat main.c
- extern int f();
- int main() {
- printf("%d\n", f());
- }
- torshie@Orz:/tmp$ gcc t.c -m32 -c
- torshie@Orz:/tmp$ gcc main.c -m64 -c
- main.c: In function ‘main’:
- main.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
- torshie@Orz:/tmp$ gcc main.o t.o
- /usr/bin/ld: i386 architecture of input file `t.o' is incompatible with i386:x86-64 output
- collect2: ld returned 1 exit status
- torshie@Orz:/tmp$ objcopy t.o -O elf64-x86-64
- torshie@Orz:/tmp$ gcc main.o t.o
- torshie@Orz:/tmp$ ./a.out
- Segmentation fault
- torshie@Orz:/tmp$ gcc t.c -O2 -c -m32
- torshie@Orz:/tmp$ objcopy -O elf64-x86-64 t.o
- torshie@Orz:/tmp$ gcc t.o main.o
- torshie@Orz:/tmp$ ./a.out
- 55
- torshie@Orz:/tmp$ uname -a
- Linux Orz 2.6.27-7-generic #1 SMP Tue Nov 4 19:33:06 UTC 2008 x86_64 GNU/Linux
- torshie@Orz:/tmp$ cat /proc/cpuinfo |grep 'model name'
- model name : Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz
- model name : Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz
如上面的示例, 注意: 可以链接跟最终程序能够正确的运行是两个不通的概念. (32位x86跟64位x86的调用约定不一样, 如果是自己手写的汇编的话就可以完全避免seg fault)
出乎我意料的是objcopy -O elf32-i386 main.o这个命令也能正确运行, 但是无法正确链接. 看来elf文件格式跟文件中指令的格式没有太大关系~~~
- linux: 将32位.o文件和64位.o文件链接成64位的可执行程序
- 32位?64位?Mach-O?
- 如何判断可执行程序exe及动态链接库dll是合法的可执行程序,及其是32位还是64位?
- [MinGW]_[初级]_[64位的windres如何编译出32位的链接文件]
- 64位Linux 编译32位程序
- Linux 64位 编译32位程序
- 查看linux系统/文件 是32位还是64位
- 查看linux库文件32位还是64位
- 查看linux库文件32位还是64位
- 查看Linux系统/文件是32位还是64位
- 怎样判断一个exe可执行程序是32位的还是64位的
- 32位和64位程序兼容性
- 64位系统注册32位的directshow filter文件
- linux(ubuntu 10.10) 64位系统 gcc编译(c)成32位(静态)可执行应用程序的方法
- 32位和64位程序的区别
- windbg分析64位机上32位程序的dump文件
- 识别你的系统是32位还是64位, Linux文件和目录访问权限设置
- 32位Linux下操作64位(4G以上)大文件的总结
- 分段与分页,LDT与GDT
- Wildmagic4笔记
- ibatis 处理oracle clob大字段方法
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- MVC中的Html.ActionLink的介绍
- linux: 将32位.o文件和64位.o文件链接成64位的可执行程序
- aspcms 菜单栏
- Qt+c++ GoolMap
- android中ImageView的ScaleType属性
- XP系统不能使用Gmail了
- [Microsoft][ODBC SQL Server Driver]无效的描述符索引
- javaMail发送邮件和附件(转载别人的文章加入了发送附件)
- JAVA移位运算符
- 如何配置OpenGL ES的上下文(OpenGL ES2.0官方文档翻译)