64位linux上编译生成32位代码

1655阅读 0评论2010-08-22 bailiangcn
分类:LINUX

首先需要安装32位的兼容库

apt-get install ia32-libs libc6-dev-i386 linux32


一、概述:
汇编 as -32
链接 ld –m elf_i386
编译 gcc -m32

二、汇编语言

.section .data

.section .test
.globl _start
_start:
movl $1, %eax
movl $4, %ebx
int $0x80


 as -32 hello.s -o hello.o
 readelf -h hello.o
结果显示
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          116 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         8
  Section header string table index: 5
上一篇:vim的正则表达式
下一篇:查看二进制文件命令