블로그 이미지
안녕1999

카테고리

전체 (3067)
자바스크립트 (20)
안드로이드 (14)
WebGL (4)
변비 (17)
정치,경제 (35)
C언어,ARM (162)
컴퓨터(PC, Note Book, 윈.. (41)
전자회로, PCB (27)
유머,안웃긴,GIF,동영상 (118)
국부론60 (71)
모듈(PCB) (3)
건강 (2)
FreeCAD (25)
PADS (43)
퇴직,퇴사,구직,취업 활동 (3)
C# (86)
엑셀 (8)
워드 (0)
LabView (6)
레고 (30)
FPGA (0)
Total
Today
Yesterday

달력

« » 2024.12
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

공지사항

최근에 올라온 글

임베디드용 프로그램은 컴파일된 코드사이즈가 작을 수 록 좋다.

보통 printf등의 함수를 사용하면, 수십kb 이상 파일크기가 증가한다.

약 68kbyte인 상태

=================
Generate binary file
Generate hex file
main.o  :
section               size         addr
.isr_vector            388    134217728
.text                67288    134218116
.eh_frame                4    134285404
.ARM                     8    134285408
.ARM.attributes         41            0
.init_array              8    134285416
.fini_array              4    134285424
.data                 1204    536870912
.jcr                     4    536872116
.fsmc_sram_data          0   1677721600
.fsmc_sram_bss           0   1677721600
.fsmc_sram_perma         0   1677721600
.bss                  2128    536872120
._user_heap_stack     1536    536874248
.factory_values          0    135264256
.debug_info         117485            0
.debug_abbrev         3591            0
.debug_loc          114940            0
.debug_aranges         176            0
.debug_ranges        21624            0
.debug_line          29503            0
.debug_str           20683            0
.comment               112            0
.debug_frame         14992            0
Total               395719
   text    data     bss     dec     hex filename
  67688    1220    3664   72572   11b7c main.o
 D 드라이브의 볼륨: D
 볼륨 일련 번호: 1473-2495
 D:\ARM\DP3000\DP3000 디렉터리
2016-09-09  오후 04:57            68,908 main.bin

printf함수대신, puts등을 여러번 사용하여 구현하기도 한다.

또는 %d, %s등만 구현이 되는 간단한 printf함수를 만들어 사용하기도 한다.


또한, printf, puts등에 사용된 문자열도 코드사이즈 증가에 한몫한다.

가는하면, 디버깅이 끝나면, 주석문으로 처리하는것이 좋다.



컴파일된 함수의 기계어 코드사이즈를 확인할 수 있는 방법

Usage: arm-none-eabi-objdump  
 Display information from object .
 At least one of the following switches must be given:
  -a, --archive-headers    Display archive header information
  -f, --file-headers       Display the contents of the overall file header
  -p, --private-headers    Display object format specific file header contents
  -P, --private=OPT,OPT... Display object format specific contents
  -h, --[section-]headers  Display the contents of the section headers
  -x, --all-headers        Display the contents of all headers
  -d, --disassemble        Display assembler contents of executable sections
  -D, --disassemble-all    Display assembler contents of all sections
  -S, --source             Intermix source code with disassembly
  -s, --full-contents      Display the full contents of all sections requested
  -g, --debugging          Display debug information in object file
  -e, --debugging-tags     Display debug information using ctags style
  -G, --stabs              Display (in raw form) any STABS info in the file
  -W[lLiaprmfFsoRt] or
  --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,
          =frames-interp,=str,=loc,=Ranges,=pubtypes,
          =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,
          =addr,=cu_index]
                           Display DWARF info in the file
  -t, --syms               Display the contents of the symbol table(s)
  -T, --dynamic-syms       Display the contents of the dynamic symbol table
  -r, --reloc              Display the relocation entries in the file
  -R, --dynamic-reloc      Display the dynamic relocation entries in the file
  @                  Read options from 
  -v, --version            Display this program's version number
  -i, --info               List object formats and architectures supported
  -H, --help               Display this information


arm-none-eabi-objdump -S -h -d main.o > ..\main.lst
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .isr_vector   00000184  08000000  08000000  00008000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .text         000106d8  08000184  08000184  00008184  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .eh_frame     00000004  0801085c  0801085c  0001885c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .ARM          00000008  08010860  08010860  00018860  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .ARM.attributes 00000029  00000000  00000000  000204b8  2**0
                  CONTENTS, READONLY
  5 .init_array   00000008  08010868  08010868  00018868  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .fini_array   00000004  08010870  08010870  00018870  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  7 .data         000004b4  20000000  08010874  00020000  2**3
                  CONTENTS, ALLOC, LOAD, DATA
  8 .jcr          00000004  200004b4  08010d28  000204b4  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .fsmc_sram_data 00000000  64000000  64000000  000204e1  2**0
                  CONTENTS
 10 .fsmc_sram_bss 00000000  64000000  64000000  000204e1  2**0
                  CONTENTS
 11 .fsmc_sram_perma 00000000  64000000  64000000  000204e1  2**0
                  CONTENTS
 12 .bss          00000850  200004b8  200004b4  000204b8  2**2
                  ALLOC
 13 ._user_heap_stack 00000600  20000d08  2001fa00  00020d08  2**0
                  ALLOC
 14 .factory_values 00000000  080ff800  080ff800  000204e1  2**0
                  CONTENTS
 15 .debug_info   0001caed  00000000  00000000  000204e1  2**0
                  CONTENTS, READONLY, DEBUGGING
 16 .debug_abbrev 00000e07  00000000  00000000  0003cfce  2**0
                  CONTENTS, READONLY, DEBUGGING
 17 .debug_loc    0001c0fc  00000000  00000000  0003ddd5  2**0
                  CONTENTS, READONLY, DEBUGGING
 18 .debug_aranges 000000b0  00000000  00000000  00059ed8  2**3
                  CONTENTS, READONLY, DEBUGGING
 19 .debug_ranges 00005478  00000000  00000000  00059f88  2**3
                  CONTENTS, READONLY, DEBUGGING
 20 .debug_line   0000733f  00000000  00000000  0005f400  2**0
                  CONTENTS, READONLY, DEBUGGING
 21 .debug_str    000050cb  00000000  00000000  0006673f  2**0
                  CONTENTS, READONLY, DEBUGGING
 22 .comment      00000070  00000000  00000000  0006b80a  2**0
                  CONTENTS, READONLY
 23 .debug_frame  00003a90  00000000  00000000  0006b87c  2**2
                  CONTENTS, READONLY, DEBUGGING

Disassembly of section .text:

08000184 <__do_global_dtors_aux>:
 8000184:	b510      	push	{r4, lr}
 8000186:	4c05      	ldr	r4, [pc, #20]	; (800019c <__do_global_dtors_aux+0x18>)
 8000188:	7823      	ldrb	r3, [r4, #0]
 800018a:	b933      	cbnz	r3, 800019a <__do_global_dtors_aux+0x16>
 800018c:	4b04      	ldr	r3, [pc, #16]	; (80001a0 <__do_global_dtors_aux+0x1c>)
 800018e:	b113      	cbz	r3, 8000196 <__do_global_dtors_aux+0x12>
 8000190:	4804      	ldr	r0, [pc, #16]	; (80001a4 <__do_global_dtors_aux+0x20>)
 8000192:	f3af 8000 	nop.w
 8000196:	2301      	movs	r3, #1
 8000198:	7023      	strb	r3, [r4, #0]
 800019a:	bd10      	pop	{r4, pc}
 800019c:	200004b8 	.word	0x200004b8
 80001a0:	00000000 	.word	0x00000000
 80001a4:	0801085c 	.word	0x0801085c

080001a8 <frame_dummy>:
 80001a8:	4b08      	ldr	r3, [pc, #32]	; (80001cc <frame_dummy+0x24>)
 80001aa:	b510      	push	{r4, lr}
 80001ac:	b11b      	cbz	r3, 80001b6 <frame_dummy+0xe>
 80001ae:	4808      	ldr	r0, [pc, #32]	; (80001d0 <frame_dummy+0x28>)
 80001b0:	4908      	ldr	r1, [pc, #32]	; (80001d4 <frame_dummy+0x2c>)
 80001b2:	f3af 8000 	nop.w
 80001b6:	4808      	ldr	r0, [pc, #32]	; (80001d8 <frame_dummy+0x30>)
 80001b8:	6803      	ldr	r3, [r0, #0]
 80001ba:	b903      	cbnz	r3, 80001be <frame_dummy+0x16>
 80001bc:	bd10      	pop	{r4, pc}
 80001be:	4b07      	ldr	r3, [pc, #28]	; (80001dc <frame_dummy+0x34>)
 80001c0:	2b00      	cmp	r3, #0
 80001c2:	d0fb      	beq.n	80001bc <frame_dummy+0x14>
 80001c4:	e8bd 4010 	ldmia.w	sp!, {r4, lr}
 80001c8:	4718      	bx	r3
 80001ca:	bf00      	nop
 80001cc:	00000000 	.word	0x00000000
 80001d0:	0801085c 	.word	0x0801085c
 80001d4:	200004bc 	.word	0x200004bc
 80001d8:	200004b4 	.word	0x200004b4
 80001dc:	00000000 	.word	0x00000000

080001e0 <_mainCRTStartup>:
 80001e0:	4b15      	ldr	r3, [pc, #84]	; (8000238 <_mainCRTStartup+0x58>)
 80001e2:	2b00      	cmp	r3, #0
 80001e4:	bf08      	it	eq
 80001e6:	4b13      	ldreq	r3, [pc, #76]	; (8000234 <_mainCRTStartup+0x54>)
 80001e8:	469d      	mov	sp, r3
 80001ea:	f5a3 3a80 	sub.w	sl, r3, #65536	; 0x10000
 80001ee:	2100      	movs	r1, #0
 80001f0:	468b      	mov	fp, r1
 80001f2:	460f      	mov	r7, r1
 80001f4:	4813      	ldr	r0, [pc, #76]	; (8000244 <_mainCRTStartup+0x64>)
 80001f6:	4a14      	ldr	r2, [pc, #80]	; (8000248 <_mainCRTStartup+0x68>)
 80001f8:	1a12      	subs	r2, r2, r0
 80001fa:	f010 f819 	bl	8010230 <memset>
 80001fe:	4b0f      	ldr	r3, [pc, #60]	; (800023c <_mainCRTStartup+0x5c>)
 8000200:	2b00      	cmp	r3, #0
 8000202:	d000      	beq.n	8000206 <_mainCRTStartup+0x26>
 8000204:	4798      	blx	r3
 8000206:	4b0e      	ldr	r3, [pc, #56]	; (8000240 <_mainCRTStartup+0x60>)
 8000208:	2b00      	cmp	r3, #0
 800020a:	d000      	beq.n	800020e <_mainCRTStartup+0x2e>
 800020c:	4798      	blx	r3
 800020e:	2000      	movs	r0, #0
 8000210:	2100      	movs	r1, #0
 8000212:	0004      	movs	r4, r0
 8000214:	000d      	movs	r5, r1
 8000216:	480d      	ldr	r0, [pc, #52]	; (800024c <_mainCRTStartup+0x6c>)
 8000218:	2800      	cmp	r0, #0
 800021a:	d002      	beq.n	8000222 <_mainCRTStartup+0x42>
 800021c:	480c      	ldr	r0, [pc, #48]	; (8000250 <_mainCRTStartup+0x70>)
 800021e:	f010 f8f7 	bl	8010410 <atexit>
 8000222:	f00f ffdd 	bl	80101e0 <__libc_init_array>
 8000226:	0020      	movs	r0, r4
 8000228:	0029      	movs	r1, r5
 800022a:	f00f ff5d 	bl	80100e8 <main>
 800022e:	f00f ffc7 	bl	80101c0 <exit>
 8000232:	bf00      	nop
 8000234:	00080000 	.word	0x00080000
	...
 8000244:	200004b8 	.word	0x200004b8
 8000248:	20000d08 	.word	0x20000d08
 800024c:	08010411 	.word	0x08010411
 8000250:	0801041d 	.word	0x0801041d


symbol table에서 각 함수의 크기를 확인할 수 있다.

크기가 큰 함수나, 불필요한 함수는 제거하자.

arm-none-eabi-objdump -S -h -d -t main.o > ..\main.lst
SYMBOL TABLE:
08000000 l    d  .isr_vector	00000000 .isr_vector
08000184 l    d  .text	00000000 .text
0801085c l    d  .eh_frame	00000000 .eh_frame
08010860 l    d  .ARM	00000000 .ARM
00000000 l    d  .ARM.attributes	00000000 .ARM.attributes
08010868 l    d  .init_array	00000000 .init_array
08010870 l    d  .fini_array	00000000 .fini_array
20000000 l    d  .data	00000000 .data
200004b4 l    d  .jcr	00000000 .jcr
64000000 l    d  .fsmc_sram_data	00000000 .fsmc_sram_data
64000000 l    d  .fsmc_sram_bss	00000000 .fsmc_sram_bss
64000000 l    d  .fsmc_sram_perma	00000000 .fsmc_sram_perma
200004b8 l    d  .bss	00000000 .bss
20000d08 l    d  ._user_heap_stack	00000000 ._user_heap_stack
080ff800 l    d  .factory_values	00000000 .factory_values
00000000 l    d  .debug_info	00000000 .debug_info
00000000 l    d  .debug_abbrev	00000000 .debug_abbrev
00000000 l    d  .debug_loc	00000000 .debug_loc
00000000 l    d  .debug_aranges	00000000 .debug_aranges
00000000 l    d  .debug_ranges	00000000 .debug_ranges
00000000 l    d  .debug_line	00000000 .debug_line
00000000 l    d  .debug_str	00000000 .debug_str
00000000 l    d  .comment	00000000 .comment
00000000 l    d  .debug_frame	00000000 .debug_frame
00000000 l    df *ABS*	00000000 C:\DOCUME~1\a\LOCALS~1\Temp\ccG34aLa.o
08010184 l       .text	00000000 LoopCopyDataInit
0801017c l       .text	00000000 CopyDataInit
08010198 l       .text	00000000 LoopFillZerobss
08010192 l       .text	00000000 FillZerobss
080101bc l       .text	00000000 Infinite_Loop
00000000 l    df *ABS*	00000000 d:/arm/bin/../lib/gcc/arm-none-eabi/4.9.3/armv7-m/crti.o
00000000 l    df *ABS*	00000000 crtstuff.c
0801085c l     O .eh_frame	00000000 __EH_FRAME_BEGIN__
200004b4 l     O .jcr	00000000 __JCR_LIST__
08000184 l     F .text	00000000 __do_global_dtors_aux
200004b8 l       .bss	00000000 completed.8108


Posted by 안녕1999
, |

최근에 달린 댓글

글 보관함