取消
显示结果 
搜索替代 
您的意思是: 
Highlighted
Xilinx Employee
Xilinx Employee
105 次查看
注册日期: ‎02-16-2012

[分享] 快速分析MPSoC的裸机应用程序大小,并作优化。

有些应用场景下,存储器的容量受限,导致软件大小受限。而客户需求又必须满足,必须优化应用程序的大小。
使用Xilinx SDK,可以快速分析MPSoC的裸机应用程序大小,并作优化。
首先,Xilinx SDK在编译裸机应用程序后,会自动打印程序大小信息。比如通过下面的打印信息,可以知道这个软件占用4480764字节。

Building target: standalone_lwip_raw_echo.elf
Invoking: ARM v8 gcc linker
aarch64-none-elf-gcc -Wl,-T -Wl,../src/lscript.ld -L../../standalone_lwip_raw_echo_bsp/psu_cortexa53_0/lib -o "standalone_lwip_raw_echo.elf"  ./src/echo.o ./src/i2c_access.o ./src/iic_phyreset.o ./src/main.o ./src/platform.o ./src/platform_mb.o ./src/platform_ppc.o ./src/platform_zynq.o ./src/platform_zynqmp.o ./src/sfp.o ./src/si5324.o   -Wl,--start-group,-lxil,-lgcc,-lc,--end-group -Wl,--start-group,-lxil,-llwip4,-lgcc,-lc,--end-group
Finished building target: standalone_lwip_raw_echo.elf
 
Invoking: ARM v8 Print Size
aarch64-none-elf-size standalone_lwip_raw_echo.elf  |tee "standalone_lwip_raw_echo.elf.size"
   text	   data	    bss	    dec	    hex	filename
 126556	   7928	4346280	4480764	 445efc	standalone_lwip_raw_echo.elf
Finished building: standalone_lwip_raw_echo.elf.size

 

其次,在应用程序工程的Binaries目录下,有编译出来的ELF文件。双击这个ELF文件,Xilinx SDK会对它进行反汇编,并显示反汇编的结果。
反汇编文件显示了各段的大小,方便进行总体分析;也显示了每个符号,也就是各个函数、全局变量的大小,可以进行细节分析。
下面是一个工程的部分反汇编文件。经过分析,可以发现,bd_space占用了2MB。这样可以再回到C代码去,看能否优化bd_space占用的空间。

......\standalone_lwip_raw_echo\Debug\standalone_lwip_raw_echo.elf
architecture: aarch64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000000000

Program Header:
    LOAD off    0x0000000000010000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**16
         filesz 0x0000000000022048 memsz 0x0000000000022080 flags rwx
    LOAD off    0x0000000000200000 vaddr 0x0000000000200000 paddr 0x0000000000200000 align 2**16
         filesz 0x0000000000000000 memsz 0x0000000000425140 flags rw-
    NOTE off    0x0000000000028174 vaddr 0x0000000000018174 paddr 0x0000000000018174 align 2**2
         filesz 0x0000000000000024 memsz 0x0000000000000024 flags r--
private flags = 0:

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         000180f4  0000000000000000  0000000000000000  00010000  2**8
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .init         00000034  0000000000018100  0000000000018100  00028100  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .fini         00000034  0000000000018140  0000000000018140  00028140  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  3 .note.gnu.build-id 00000024  0000000000018174  0000000000018174  00028174  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .rodata       00000cc8  0000000000018198  0000000000018198  00028198  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .rodata1      00000020  0000000000018e60  0000000000018e60  00028e60  2**0
                  ALLOC
  6 .sdata2       00000000  0000000000018e80  0000000000018e80  00032048  2**0
                  CONTENTS
  7 .sbss2        00000000  0000000000018e80  0000000000018e80  00032048  2**0
                  CONTENTS
  8 .data         00001eb0  0000000000018e80  0000000000018e80  00028e80  2**3
                  CONTENTS, ALLOC, LOAD, DATA
  9 .data1        00000010  000000000001ad30  000000000001ad30  0002ad30  2**0
                  ALLOC
 10 .ctors        00000000  000000000001ad40  000000000001ad40  00032048  2**0
                  CONTENTS
 11 .dtors        00000000  000000000001ad40  000000000001ad40  00032048  2**0
                  CONTENTS
 12 .eh_frame     00000004  000000000001ad40  000000000001ad40  0002ad40  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 13 .mmu_tbl0     00000010  000000000001b000  000000000001b000  0002b000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 14 .mmu_tbl1     00002000  000000000001c000  000000000001c000  0002c000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 15 .mmu_tbl2     00004000  000000000001e000  000000000001e000  0002e000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 16 .preinit_array 00000000  0000000000022000  0000000000022048  00032048  2**0
                  CONTENTS, ALLOC, LOAD, DATA
 17 .init_array   00000008  0000000000022000  0000000000022000  00032000  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 18 .fini_array   00000040  0000000000022008  0000000000022008  00032008  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 19 .sdata        00000038  0000000000022048  0000000000022048  00032048  2**0
                  ALLOC
 20 .sbss         00000000  0000000000022080  0000000000022080  00032048  2**0
                  CONTENTS
 21 .tdata        00000000  0000000000022080  0000000000022080  00032048  2**0
                  CONTENTS, ALLOC, LOAD, DATA, THREAD_LOCAL
 22 .tbss         00000000  0000000000022080  0000000000022080  00000000  2**0
                  ALLOC, THREAD_LOCAL
 23 .bss          00410140  0000000000200000  0000000000200000  00200000  2**21
                  ALLOC
 24 .heap         0000a000  0000000000610140  0000000000610140  00200000  2**0
                  ALLOC
 25 .stack        0000b000  000000000061a140  000000000061a140  00200000  2**0
                  ALLOC
 26 .comment      00000011  0000000000000000  0000000000000000  00032048  2**0
                  CONTENTS, READONLY
 27 .debug_line   0001fd0a  0000000000000000  0000000000000000  00032059  2**0
                  CONTENTS, READONLY, DEBUGGING
 28 .debug_info   000572da  0000000000000000  0000000000000000  00051d63  2**0
                  CONTENTS, READONLY, DEBUGGING
 29 .debug_abbrev 0000d1f9  0000000000000000  0000000000000000  000a903d  2**0
                  CONTENTS, READONLY, DEBUGGING
 30 .debug_aranges 00000dd0  0000000000000000  0000000000000000  000b6240  2**4
                  CONTENTS, READONLY, DEBUGGING
 31 .debug_str    00025c05  0000000000000000  0000000000000000  000b7010  2**0
                  CONTENTS, READONLY, DEBUGGING
 32 .debug_macro  00007c8c  0000000000000000  0000000000000000  000dcc15  2**0
                  CONTENTS, READONLY, DEBUGGING
 33 .debug_frame  000053a8  0000000000000000  0000000000000000  000e48a8  2**3
                  CONTENTS, READONLY, DEBUGGING
 34 .debug_loc    000395e8  0000000000000000  0000000000000000  000e9c50  2**0
                  CONTENTS, READONLY, DEBUGGING
 35 .debug_ranges 00005c70  0000000000000000  0000000000000000  00123238  2**0
                  CONTENTS, READONLY, DEBUGGING
SYMBOL TABLE:
0000000000000000 l    df *ABS*	0000000000000000 asm_vectors.o
0000000000000210 l       *ABS*	0000000000000000 FPUContextSize
0000000000000000 l       .text	0000000000000000 VBAR
0000000000000384 l       .text	0000000000000000 SynchronousInterruptHandler
0000000000000488 l       .text	0000000000000000 IRQInterruptHandler
0000000000000584 l       .text	0000000000000000 FIQInterruptHandler
00000000000005e4 l       .text	0000000000000000 SErrorInterruptHandler
0000000000000454 l       .text	0000000000000000 synchronoushandler
... ...
00000000002000d0 l     O .bss	0000000000000008 dhcp_pcb
00000000002000d8 l     O .bss	0000000000000001 dhcp_pcb_refcount
... ...
0000000000006358 g     F .text	0000000000000018 dhcp_release
0000000000003438 g     F .text	0000000000000124 XTtcPs_CfgInitialize
00000000000130b0 g     F .text	0000000000000078 inet_chksum_pbuf
000000000000a470 g     F .text	000000000000009c pbuf_take
0000000000017768 g     F .text	00000000000000b8 XEmacPs_BdRingClone
000000000000a430 g     F .text	0000000000000040 pbuf_skip
0000000000010dd0 g     F .text	000000000000017c setup_rx_bds
0000000000017fd8  w    F .text	0000000000000008 isatty
0000000000400000 g     O .bss	0000000000200000 bd_space
0000000000017fb8  w    F .text	0000000000000010 _fstat
... ...

 

0 项奖励