日期:2014-05-16  浏览次数:20785 次

求助g++编译参数
有一个arm的elf执行文件,使用readelf查看只有text和bss段,不知道是用什么参数编译出来的呢?我尝试用-s -O3 -static参数编译一个程序,但有很多段。

$arm-none-linux-gnueabi-readelf -a test_elf
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: EXEC (Executable file)
  Machine: ARM
  Version: 0x1
  Entry point address: 0x80d4
  Start of program headers: 52 (bytes into file)
  Start of section headers: 2760868 (bytes into file)
  Flags: 0x5000002, has entry point, Version5 EABI
  Size of this header: 52 (bytes)
  Size of program headers: 32 (bytes)
  Number of program headers: 4
  Size of section headers: 40 (bytes)
  Number of section headers: 4
  Section header string table index: 3

Section Headers:
  [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
  [ 0] NULL 00000000 000000 000000 00 0 0 0
  [ 1] .text PROGBITS 000080d4 0000d4 2a1fb8 00 WAX 0 0 1
  [ 2] .bss NOBITS 002aa08c 2a208c 332f74 00 WA 0 0 1
  [ 3] .shstrtab STRTAB 00000000 2a208c 000016 00 0 0 1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

Program Headers:
  Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
  LOAD 0x000000 0x00008000 0x00008000 0x2a208c 0x2a3000 RWE 0x1000
  LOAD 0x001000 0x002ab000 0x002ab000 0x2a1000 0x2a1000 RWE 0x1000
  LOAD 0x001000 0x0054c000 0x0054c000 0x24000 0x24000 RWE 0x1000
  LOAD 0x2a0000 0x00570000 0x00570000 0x00000 0x6d000 RW 0x8000

 Section to Segment mapping:
  Segment Sections...
  00 .text 
  01  
  02  
  03  

There is no dynamic section in this file.

There are no relocations in this file.

There are no unwind sections in this file.

No version information found in this file.

使用file查看
$file test_elf
 ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped



------解决方案--------------------
一些人想学习一个elf文件格式,自己写的吧
------解决方案--------------------
gcc可以合并段,具体参数忘了

VC的还记得
------解决方案--------------------
得写ld链接脚本
具体怎么写网上可查.