ashtian01 / optiboot

Automatically exported from code.google.com/p/optiboot
0 stars 0 forks source link

Code grows to >512 bytes with gcc 4.5.3 #54

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Optiboot has been built using gcc 4.3.2, as distributed with winavr, avr 
crosspack, and Arduino development environments.

Sometime between gcc4.5.2 and gcc4.5.3, optimization has changed such that 
binary size grows from 500 bytes to 522 bytes (over our 512 byte limit!)
This seems to be because of a change in the distance over which common code is 
detected/refactored, and will be brought up with the avr-gcc people, but it at 
least needs a tag here...

Original issue reported on code.google.com by wes...@gmail.com on 24 Jan 2012 at 4:57

GoogleCodeExporter commented 8 years ago
With gcc 4.3.2:

 /* Forever loop */
  for (;;) {
    /* get character from UART */
    ch = getch();
    7e60:   a2 d0           rcall   .+324       ; 0x7fa6 <getch>

    if(ch == STK_GET_PARAMETER) {
    7e62:   81 34           cpi r24, 0x41   ; 65
    7e64:   61 f4           brne    .+24        ; 0x7e7e <main+0x7e>
      unsigned char which = getch();
    7e66:   9f d0           rcall   .+318       ; 0x7fa6 <getch>
    7e68:   08 2f           mov r16, r24
      verifySpace();
    7e6a:   af d0           rcall   .+350       ; 0x7fca <verifySpace>
      if (which == 0x82) {
    7e6c:   02 38           cpi r16, 0x82   ; 130
    7e6e:   11 f0           breq    .+4         ; 0x7e74 <main+0x74>
    /*
     * Send optiboot version as "minor SW version"
     */
    putch(OPTIBOOT_MINVER);
      } else if (which == 0x81) {
    7e70:   01 38           cpi r16, 0x81   ; 129
    7e72:   11 f4           brne    .+4         ; 0x7e78 <main+0x78>
      putch(OPTIBOOT_MAJVER);
    7e74:   84 e0           ldi r24, 0x04   ; 4
    7e76:   01 c0           rjmp    .+2         ; 0x7e7a <main+0x7a>
      } else {
    /*
     * GET PARAMETER returns a generic 0x03 reply for
         * other parameters - enough to keep Avrdude happy
     */
    putch(0x03);
    7e78:   83 e0           ldi r24, 0x03   ; 3
    7e7a:   8d d0           rcall   .+282       ; 0x7f96 <putch>
    7e7c:   89 c0           rjmp    .+274       ; 0x7f90 <main+0x190>
      }

Original comment by wes...@gmail.com on 24 Jan 2012 at 4:58

GoogleCodeExporter commented 8 years ago
With gcc 4.5.3.  Note: TWO calls to putch():

  /* Forever loop */
  for (;;) {
    /* get character from UART */
    ch = getch();
    7e60:   ad d0           rcall   .+346       ; 0x7fbc <getch>

    if(ch == STK_GET_PARAMETER) {
    7e62:   81 34           cpi r24, 0x41   ; 65
    7e64:   89 f4           brne    .+34        ; 0x7e88 <main+0x88>
      unsigned char which = getch();
    7e66:   aa d0           rcall   .+340       ; 0x7fbc <getch>
      verifySpace();
    7e68:   89 83           std Y+1, r24    ; 0x01
    7e6a:   ba d0           rcall   .+372       ; 0x7fe0 <verifySpace>
      if (which == 0x82) {
    7e6c:   89 81           ldd r24, Y+1    ; 0x01
    7e6e:   82 38           cpi r24, 0x82   ; 130
    7e70:   19 f4           brne    .+6         ; 0x7e78 <main+0x78>
    /*
     * Send optiboot version as "minor SW version"
     */
    putch(OPTIBOOT_MINVER);
    7e72:   84 e0           ldi r24, 0x04   ; 4
    7e74:   9c d0           rcall   .+312       ; 0x7fae <putch>
    7e76:   98 c0           rjmp    .+304       ; 0x7fa8 <main+0x1a8>
      } else if (which == 0x81) {
    7e78:   81 38           cpi r24, 0x81   ; 129
    7e7a:   19 f4           brne    .+6         ; 0x7e82 <main+0x82>
      putch(OPTIBOOT_MAJVER);
    7e7c:   84 e0           ldi r24, 0x04   ; 4
    7e7e:   97 d0           rcall   .+302       ; 0x7fae <putch>
    7e80:   93 c0           rjmp    .+294       ; 0x7fa8 <main+0x1a8>
      } else {
    /*
     * GET PARAMETER returns a generic 0x03 reply for
         * other parameters - enough to keep Avrdude happy
     */
    putch(0x03);
    7e82:   83 e0           ldi r24, 0x03   ; 3
    7e84:   94 d0           rcall   .+296       ; 0x7fae <putch>
    7e86:   90 c0           rjmp    .+288       ; 0x7fa8 <main+0x1a8>
      }
    }

Original comment by wes...@gmail.com on 24 Jan 2012 at 5:00

GoogleCodeExporter commented 8 years ago
Fixed by using attribute "OS_main" instead of "naked" for main()
http://code.google.com/p/optiboot/source/detail?r=3aaa971abb56d72e34e49ec7373303
57c465a797

Original comment by wes...@gmail.com on 28 Jan 2012 at 4:52