How printf output messages to kernel with uclibc lib

Denys Vlasenko vda.linux at googlemail.com
Sun Feb 1 13:20:39 UTC 2009


On Sunday 01 February 2009 12:52, loody wrote:
> >> >> I have one question about my problem.
> >> >> Can I replace the kernel execute command, "/init", as "/hello"; that
> >> >> means the first user space program is hello, not standard int.
> >> >> Is that the problem which make printt not workable?
> >> >>
> >> >> I have no idea whether kernel has to do something in "init" such that
> >> >> "hello" can call printf to show message.
> >> >
> >> > [f]printf ultimately results in write() syscalls performed on
> >> > open file descriptors.
> >> >
> >> > If you have trouble verifying that your userspace programs
> >> > are able to execute, start with this test program:
> >> >
> >> > int main() {
> >> >        write(1, "Hello\n", 6);
> >> >        for (;;)
> >> >                continue;
> >> > }
> >> >
> >> > Compile it and run as init. You should see "Hello"
> >> > message. If you don't, your toolchain is producing broken
> >> > executables.
> >> > --
> >> > vda
> >> >
> >>
> >> Hi:
> >> I have search the calls.S in arch/arm/kernel, but I cannot find the
> >> sys call, write, you mention.
> >> ( I use arm platform, so I search the syscalls implemented by arm)
> >> Is it a wrap function? If so, I guess I should include some header to do
> >> so.
> >> But I have no idea what header I can use.
> >
> > Check which system call does uclibc call for printf(). It might help.
> Hi:
> I try to do that before.
> in uclibc, _stdio.c, there are 3 _stdio_streams[] receiving the
> printf messages.
>      Then I cannot find how uclibc calling which sys call to pass these streams.

You do not need to find it. You are attacking the problem from the wrong end.

By using bare write(), you will be able to determine whether
your toolchain works at all, without even using printf.

As long as you don't know whether at least write() works,
it's utterly pointless to look into printf internals.

--
vda


More information about the uClibc mailing list