D
Domingo Fiesta Segura
Hi,
Recently I've been playing on C programming avoiding libc and also
assembly. Well, I guess some of us like to mess up with things like:
#include <linux/types.h>
#include <linux/unistd.h>
int errno;
_syscall1(int, exit, int, status)
_syscall3(ssize_t, write, int, fd, const void *, buf, size_t, count)
void _start()
{
write(1, "Hello there\n", 12);
exit(0);
}
And then compiling with "-nostdlib".
In case argc, argv and/or envp are needed we have to get it from the
stack (AFAIK). Thats the work for /usr/lib/crt1.o in glibc. Of course,
we all knew that.
Searching through the glibc sources I found a curious code in
glibc-2.3.1/sysdeps/unix/start.c, something like this:
static void start1();
void _start ()
{
start1();
}
/* There are some dummy declarations for i386 */
static void start1(int argc, char *argp)
{
char **argv = &argp;
/* Get environment here ... */
/* Call __libc_init */
exit(main(argc, argv, __environ));
}
But doesn't work, why?
P.S: For now I have my own crt1-toy.S version for x86, I'm trying to
work out another crti1-toy.S PPC32 version. Suggestions welcomed.
Thanks for your attention.
Recently I've been playing on C programming avoiding libc and also
assembly. Well, I guess some of us like to mess up with things like:
#include <linux/types.h>
#include <linux/unistd.h>
int errno;
_syscall1(int, exit, int, status)
_syscall3(ssize_t, write, int, fd, const void *, buf, size_t, count)
void _start()
{
write(1, "Hello there\n", 12);
exit(0);
}
And then compiling with "-nostdlib".
In case argc, argv and/or envp are needed we have to get it from the
stack (AFAIK). Thats the work for /usr/lib/crt1.o in glibc. Of course,
we all knew that.
Searching through the glibc sources I found a curious code in
glibc-2.3.1/sysdeps/unix/start.c, something like this:
static void start1();
void _start ()
{
start1();
}
/* There are some dummy declarations for i386 */
static void start1(int argc, char *argp)
{
char **argv = &argp;
/* Get environment here ... */
/* Call __libc_init */
exit(main(argc, argv, __environ));
}
But doesn't work, why?
P.S: For now I have my own crt1-toy.S version for x86, I'm trying to
work out another crti1-toy.S PPC32 version. Suggestions welcomed.
Thanks for your attention.