精通ghs编译器

gcc编译器使用过程

  1. 预处理 gcc -E
  2. 编译 gcc -S
  3. 汇编 gcc -c
  4. 链接 gcc

gcc编译器使用例子

D:\>echo int main(int argc, char *argv[]){int a=0; a++; a--; a*=1;} > a.c

D:\>gcc -E a.c -o a.i

D:\>gcc -S a.i -o a.s

D:\>gcc -c a.s -o a.o

D:\>gcc a.o -o a.out

objdump反汇编ELF

 objdump -S a.out


ghs ccrh850编译器使用过程

  1. 预处理 ccrh850 -E
  2. 编译 ccrh850 -S
  3. 汇编 ccrh850 -c
  4. 链接 ccrh850

ccrh850编译器使用例子 

D:\>echo int main(int argc, char *argv[]){int a=0; a++; a--; a*=1;} > a.c

D:\>ccrh850 -E a.c -o a.i

D:\>ccrh850 -S a.i -o a.s

D:\>ccrh850 -c a.s -o a.o

D:\>ccrh850 a.o -o a.out

gdump反汇编ELF 

 gdump -ytext a.out

输出显示如下

Elf header
  e_ident =  7f 45 4c 46 1 1 1 0 0 0 0 0 0 0 0 0  
  e_ident[EI_CLASS] = ELFCLASS32
  e_ident[EI_DATA] = ELFDATA2LSB
  e_ident[EI_VERSION] = 1
  e_type = ET_EXEC
  e_machine = V850E3V5
  e_version = 1
  e_entry = 0x1000
  e_phoff = 0x34
  e_shoff = 0x2be0
  e_flags = 0xf0109940 (REGMODE32,GP_FIX,TP_FIX,EP_NONFIX,REG2_NONRESERVE)
  e_ehsize = 52
  e_phentsize = 32
  e_phnum = 8
  e_shentsize = 40
  e_shnum = 40
  e_shstrndx = 39

Program header #0
  p_type = PT_LOAD
  p_offset = 0x0
  p_vaddr = 0xfff00000
  p_paddr = 0x0
  p_filesz = 0x0
  p_memsz = 0xf7f00
  p_flags = 0x4007 (Execute, Write, Read, Absolute)
  p_align = 0x0

Program header #1
  p_type = PT_LOAD
  p_offset = 0x140
  p_vaddr = 0x1000
  p_paddr = 0x0
  p_filesz = 0x874
  p_memsz = 0x874
  p_flags = 0x5 (Execute, Read)
  p_align = 0x10

Program header #2
  p_type = PT_LOAD
  p_offset = 0x9b4
  p_vaddr = 0x1874
  p_paddr = 0x0
  p_filesz = 0x6
  p_memsz = 0x6
  p_flags = 0x5 (Execute, Read)
  p_align = 0x4

Program header #3
  p_type = PT_LOAD
  p_offset = 0x9bc
  p_vaddr = 0x187c
  p_paddr = 0x0
  p_filesz = 0x54
  p_memsz = 0x54
  p_flags = 0x5 (Execute, Read)
  p_align = 0x4

Program header #4
  p_type = PT_LOAD
  p_offset = 0xa10
  p_vaddr = 0x18d0
  p_paddr = 0x0
  p_filesz = 0x1
  p_memsz = 0x1
  p_flags = 0x5 (Execute, Read)
  p_align = 0x0

Program header #5
  p_type = PT_LOAD
  p_offset = 0x0
  p_vaddr = 0x300000
  p_paddr = 0x0
  p_filesz = 0x0
  p_memsz = 0x1
  p_flags = 0x7 (Execute, Write, Read)
  p_align = 0x0

Program header #6
  p_type = PT_LOAD
  p_offset = 0x0
  p_vaddr = 0x300010
  p_paddr = 0x0
  p_filesz = 0x0
  p_memsz = 0xc
  p_flags = 0x7 (Execute, Write, Read)
  p_align = 0x4

Program header #7
  p_type = PT_LOAD
  p_offset = 0x0
  p_vaddr = 0x300020
  p_paddr = 0x0
  p_filesz = 0x0
  p_memsz = 0x100000
  p_flags = 0x7 (Execute, Write, Read)
  p_align = 0x10

Section header #0
  sh_name =
  sh_type = SHT_NULL
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #1
  sh_name = .stack
  sh_type = SHT_NOBITS
  sh_flags = 0x403 (Alloc, Write, Absolute (GHS extension))
  sh_addr = 0xfff00000
  sh_offset = 0x0
  sh_size = 0xf7f00
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #2
  sh_name = .tdata
  sh_type = SHT_NULL
  sh_flags = 0x402 (Alloc, Absolute (GHS extension))
  sh_addr = 0xffff7f00
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #3
  sh_name = .zdata
  sh_type = SHT_NULL
  sh_flags = 0x402 (Alloc, Absolute (GHS extension))
  sh_addr = 0xffff8000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #4
  sh_name = .zbss
  sh_type = SHT_NULL
  sh_flags = 0x403 (Alloc, Write, Absolute (GHS extension))
  sh_addr = 0xffff8000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #5
  sh_name = .rozdata
  sh_type = SHT_NULL
  sh_flags = 0x402 (Alloc, Absolute (GHS extension))
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #6
  sh_name = .robase
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 16
  sh_entsize = 0

Section header #7
  sh_name = .rosda_start
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #8
  sh_name = .rosdata
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #9
  sh_name = .rosda_end
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #10
  sh_name = .rodata
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #11
  sh_name = .callt
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x1000
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #12
  sh_name = .text
  sh_type = SHT_PROGBITS
  sh_flags = 0x6 (Execinstr, Alloc)
  sh_addr = 0x1000
  sh_offset = 0x140
  sh_size = 0x874
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 16
  sh_entsize = 0

Section header #13
  sh_name = .syscall
  sh_type = SHT_PROGBITS
  sh_flags = 0x6 (Execinstr, Alloc)
  sh_addr = 0x1874
  sh_offset = 0x9b4
  sh_size = 0x6
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #14
  sh_name = .secinfo
  sh_type = SHT_PROGBITS
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x187c
  sh_offset = 0x9bc
  sh_size = 0x54
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #15
  sh_name = .fixaddr
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x18d0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #16
  sh_name = .fixtype
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x18d0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #17
  sh_name = .ROM.data
  sh_type = SHT_PROGBITS
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x18d0
  sh_offset = 0xa10
  sh_size = 0x1
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 1
  sh_entsize = 0

Section header #18
  sh_name = .ROM.tls.cond.data
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x18d1
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #19
  sh_name = .ROM.sdata
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x18d1
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #20
  sh_name = .data
  sh_type = SHT_NOBITS
  sh_flags = 0x3 (Alloc, Write)
  sh_addr = 0x300000
  sh_offset = 0xa10
  sh_size = 0x1
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 1
  sh_entsize = 0

Section header #21
  sh_name = .tls.cond.data
  sh_type = SHT_NOBITS
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x300001
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #22
  sh_name = .sda_start
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x300010
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 16
  sh_entsize = 0

Section header #23
  sh_name = .sdata
  sh_type = SHT_NOBITS
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x300010
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #24
  sh_name = .sbss
  sh_type = SHT_NULL
  sh_flags = 0x3 (Alloc, Write)
  sh_addr = 0x300010
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #25
  sh_name = .sda_end
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x300010
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #26
  sh_name = .bss
  sh_type = SHT_NOBITS
  sh_flags = 0x3 (Alloc, Write)
  sh_addr = 0x300010
  sh_offset = 0x0
  sh_size = 0xc
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #27
  sh_name = .tls.cond.bss
  sh_type = SHT_NULL
  sh_flags = 0x2 (Alloc)
  sh_addr = 0x30001c
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #28
  sh_name = .heap
  sh_type = SHT_NOBITS
  sh_flags = 0x3 (Alloc, Write)
  sh_addr = 0x300020
  sh_offset = 0x0
  sh_size = 0x100000
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 16
  sh_entsize = 0

Section header #29
  sh_name = /DISCARD/
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #30
  sh_name = .ghrettbl
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0xa14
  sh_size = 0x50
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #31
  sh_name = .ghcalltbl
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0xa64
  sh_size = 0x84
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #32
  sh_name = .ghtailcalltbl
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #33
  sh_name = .note.renesas
  sh_type = SHT_NOTE
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0xae8
  sh_size = 0x3c
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #34
  sh_name = .linfix
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #35
  sh_name = .gstackfix
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0x0
  sh_size = 0x0
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 4
  sh_entsize = 0

Section header #36
  sh_name = .rominfo
  sh_type = SHT_PROGBITS
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0xb24
  sh_size = 0x1b
  sh_link = 0x0
  sh_info = 0x0
  sh_addralign = 0
  sh_entsize = 0

Section header #37
  sh_name = .symtab
  sh_type = SHT_SYMTAB
  sh_flags = 0x0 (no flags)
  sh_addr = 0x0
  sh_offset = 0xb40
  sh_size = 0xbf0

你可能感兴趣的:(ghs)