This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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

Re: How to get printf() output?


Toralf Lund <toralf@procaptura.com>

> It works. I'm 100% sure about that. write() could be incorrect, as I 
> haven't tested its functionality thoroughly - I've been focusing on 
> checking whether it is called or not, and I think it isn't ;-(

 I produced my test executable with gcc-2.95.3 when the 'specs' in my
gcc-3.3.1 hadn't any default target board edited into it...

 The peculiar thing with gcc-3.x has been that it magically replaces
'printf()'s with 'puts()', ie. "printf("Hello World");" will be changed
to be "puts("Hello World");". Producing the assembly file shows this:

---------------- clip ----------------------------
/home1/kai/test/hello > cat hello.c
/* #include <stdio.h> */

int
main (void)
{
        printf("Hello World with printf()\n");
        puts("Hello World with puts()\n");
        return 0;
}
---------------- clip ----------------------------

C code giving (using '-S' in its compile) :

---------------- clip ----------------------------
/home1/kai/test/hello > cat hello_cpu32.s
        .file   "hello.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "Hello World with printf()"
.LC1:
        .string "Hello World with puts()\n"
        .text
        .align  2
        .globl  main
        .type   main, @function
main:
        link.w %a6,#0
        move.l %a6,-(%sp)
        move.l %a2,-(%sp)
        pea .LC0
        lea puts,%a2		<--- should be printf
        jbsr (%a2)
        pea .LC1
        jbsr (%a2)
        clr.l %d0
        move.l -8(%a6),%a2
        move.l -4(%a6),%a6
        unlk %a6
        rts
        .size   main, .-main
        .ident  "GCC: (GNU) 3.3.1"
---------------- clip ----------------------------

when gcc-2.95.3 still didn't edit whole functions away...

 So maybe you even haven't the 'printf()' in your executable but
something else and that really doesn't output via 'write()' at all...

 In this "Hello World" case the 'replaced printf()'s, also output'ed
via '_write_r()' and then via 'write()', ie. these were linked into
the executable, so replacing 'printf()'s with 'puts()'s isn't the
reason for your problem...

 Looking at the assembly output for the C code and seeing whether those
printf()'s are replaced with something else, can be one way to find
some sanity... In my "Hello World" case one looking at the disassembly
listing and trying to find the call to 'printf()' from it, could lead
into one soon going up the walls ;-)

Cheers, Kai
 

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


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