This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

avr-gcc printf ---huge Target file


A bug? maybe...

$ avr-gcc -v
Using built-in specs.
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man
--bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib
--enable-shared --with-system-zlib --enable-long-long --enable-nls
--without-included-gettext --disable-checking --disable-libssp
--build=i486-linux-gnu --host=i486-linux-gnu --target=avr
Thread model: single
gcc version 4.3.3 (GCC)

/code uartPrintf.c
#include <avr/io.h>
#include <stdio.h>

/* 8MHZ 19200 */
#define BAUD 25

static int uart_putchar(char c, FILE *stream);

static int uart_getchar(FILE *stream);

static FILE mystream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar,
_FDEV_SETUP_RW);

static int uart_putchar(char c, FILE *stream){
    if (c == '\n')
        uart_putchar('\r', stream);
    loop_until_bit_is_set(UCSRA, UDRE);
    UDR = c;
    return 0;
}

static int uart_getchar(FILE *stream){
    loop_until_bit_is_set(UCSRA, RXC);
    return UDR;
}

void init_uart(void){
    /* set baud rate */
    UBRRH = (unsigned char)(BAUD>>8);
    UBRRL = (unsigned char)BAUD;
    /* UDR is empty */
    UCSRA = _BV(UDRE);
    /* set frame format: 8bit, 1stopbit */
    UCSRC = _BV(URSEL)|_BV(UCSZ0)|_BV(UCSZ1);
    /* enable receiver and transmitter */
    UCSRB = _BV(RXEN) | _BV(TXEN);
}

int main(void){
    char num[10];
    init_uart();
    stdout = &mystream;
    stdin = &mystream;
    printf("get string: ");   /* printf("get string: \n") */
    puts(fgets(num, 10, stdin));
    while(1);

    return 0;
}
/endcode



$ avr-gcc -mmcu=atmega16 -Wall -Os -o uartPrintf.o uartPrintf.c
$ avr-objcopy -j .text -j .data -O ihex uartPrintf.o uartPrintf.hex

$ ls -l uartPrintf.hex
-rw-r--r-- 1 inx inx 4861 Aug 12 19:11 uartPrintf.hex
$ avr-size uartPrintf.o
   text    data     bss     dec     hex filename
   1696      26       6    1728     6c0 uartPrintf.o

change printf("get string: ");   to  printf("get string: \n") */

$ ls -l uartPrintf.hex
-rw-r--r-- 1 inx inx 1114 Aug 12 19:12 uartPrintf.hex
$ avr-size uartPrintf.o
   text    data     bss     dec     hex filename
    362      26       6     394     18a uartPrintf.o



when i try to use -S option, the diff of two asm file is :
        rcall .                                               <
        ldi r24,lo8(.LC1)
 ldi r24,lo8(.LC1)
        ldi r25,hi8(.LC1)
 ldi r25,hi8(.LC1)
        in r30,__SP_L__                                       |
 call puts
        in r31,__SP_H__                                       <
        std Z+2,r25                                           <
        std Z+1,r24                                           <
        call printf                                           <
        pop __tmp_reg__                                       <
        pop __tmp_reg__                                       <

one call puts() and the other call printf()....why printf() build so
huge target file, but scanf() not(i test also) ?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]