[syslinux] error on implementing printf

H. Peter Anvin hpa at zytor.com
Mon Jun 1 09:45:29 PDT 2009


liu Aleaxander wrote:
> 
> well, this program is simple. but it can't work; then i debugged it, found
> something error really happened.
> it's called from hello() in hello.c, here is the snippet::
> 
> void hello(void)
> {
>     static char hello_str[] = "Hello, World!  (hello.c)\r\n";
> 
>     myputs(hello_str);
>     printf(hello_str);
>     printf("testing with format output %d\n\r", 2);
> }
> 
> 
> 
> here is the disassemble:
> 
> sub esp, 0x0000000c   ; seems it want allocate some memory, but I didn't see
> anything pushed on it..
> mov eax, 0x00100fb0   ; the address of hello_str.
> 
> call 0x100170(myputs)  ; the myputs() function.  Seems the function passed
> the parameter by register but not stack.
>                                     ; then I would be really confused, why
> it don't use the stack after allocating the stack memory.
> 
> ; and for now, it goes well, the hello_str displayed well.
> 
> mov eax, 0x00100fb0  ; also use the eax to pass the parameter.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> call 0x1001b8(printf)     ; the printf function. trace in.....
> 

The 32-bit code in Syslinux is compiled with -mregparm=3, which means
that it uses registers to pass in the arguments to *non-varadic*
functions.  However, it should not use registers to pass in the argument
to a varadic function like printf().  The easiest explanation for this
problem is that it is missing the prototype, i.e. <stdio.h> isn't included.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.




More information about the Syslinux mailing list