From c93f95560d3fde9eaefcc62c454c67b8b5626fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwenol=C3=A9=20Beauchesne?= Date: Tue, 18 Feb 2003 16:48:04 +0000 Subject: Merge in CVS dietlibc 0.21 for IA-64 and X86-64 support. However, drop the following architectures we currently don't support: arm, mips, mipsel, parisc, s390, sparc64. --- mdk-stage1/dietlibc/.cvsignore | 16 + mdk-stage1/dietlibc/AUTHOR | 2 + mdk-stage1/dietlibc/BUGS | 8 + mdk-stage1/dietlibc/CAVEAT | 5 + mdk-stage1/dietlibc/CHANGES | 887 ++++++++++++++++++++++++++++++ mdk-stage1/dietlibc/COPYING | 340 ++++++++++++ mdk-stage1/dietlibc/FAQ | 209 +++++++ mdk-stage1/dietlibc/Makefile | 351 ++++++++++-- mdk-stage1/dietlibc/PORTING | 28 + mdk-stage1/dietlibc/README | 14 +- mdk-stage1/dietlibc/SECURITY | 13 + mdk-stage1/dietlibc/THANKS | 31 ++ mdk-stage1/dietlibc/TODO | 26 + mdk-stage1/dietlibc/alpha/Makefile.add | 2 +- mdk-stage1/dietlibc/alpha/__alarm.c | 13 + mdk-stage1/dietlibc/alpha/__longjmp.S | 9 +- mdk-stage1/dietlibc/alpha/__testandset.S | 11 + mdk-stage1/dietlibc/alpha/clone.S | 2 +- mdk-stage1/dietlibc/alpha/lseek64.S | 5 + mdk-stage1/dietlibc/alpha/n_sigprocmask.S | 3 + mdk-stage1/dietlibc/alpha/setjmp.S | 31 +- mdk-stage1/dietlibc/alpha/sigaction.c | 7 + mdk-stage1/dietlibc/alpha/signal.S | 3 - mdk-stage1/dietlibc/alpha/sigprocmask.S | 3 - mdk-stage1/dietlibc/alpha/socketpair.S | 3 + mdk-stage1/dietlibc/alpha/start.S | 20 +- mdk-stage1/dietlibc/alpha/syscalls.h | 371 +++++++++++++ mdk-stage1/dietlibc/alpha/unified.S | 12 +- mdk-stage1/dietlibc/binshstr.h | 6 + mdk-stage1/dietlibc/diet.1 | 31 ++ mdk-stage1/dietlibc/diet.c | 313 +++++++++-- mdk-stage1/dietlibc/dietdirent.h | 4 +- mdk-stage1/dietlibc/dietdns.h | 4 + mdk-stage1/dietlibc/dietfeatures.h | 92 +++- mdk-stage1/dietlibc/dieticonv.h | 12 + mdk-stage1/dietlibc/dietlibm.h | 5 + mdk-stage1/dietlibc/dietstdarg.h | 12 - mdk-stage1/dietlibc/dietstdio.h | 83 ++- mdk-stage1/dietlibc/dietuglyweaks.h | 24 + mdk-stage1/dietlibc/dirstream.h | 78 --- mdk-stage1/dietlibc/dyn_start.c | 40 ++ mdk-stage1/dietlibc/dyn_stop.c | 23 + mdk-stage1/dietlibc/findcflags.sh | 8 + mdk-stage1/dietlibc/i386/Makefile.add | 7 +- mdk-stage1/dietlibc/i386/PIC.h | 82 +++ mdk-stage1/dietlibc/i386/__half.S | 10 + mdk-stage1/dietlibc/i386/__longjmp.S | 1 + mdk-stage1/dietlibc/i386/__ten.S | 9 + mdk-stage1/dietlibc/i386/__testandset.S | 1 + mdk-stage1/dietlibc/i386/accept.S | 4 + mdk-stage1/dietlibc/i386/acos.S | 30 + mdk-stage1/dietlibc/i386/acosh.S | 18 + mdk-stage1/dietlibc/i386/asin.S | 29 + mdk-stage1/dietlibc/i386/asinh.S | 18 + mdk-stage1/dietlibc/i386/atan.S | 27 + mdk-stage1/dietlibc/i386/atan2.S | 12 + mdk-stage1/dietlibc/i386/atanh.S | 19 + mdk-stage1/dietlibc/i386/atol.S | 55 ++ mdk-stage1/dietlibc/i386/atoll.S | 64 +++ mdk-stage1/dietlibc/i386/bind.S | 4 + mdk-stage1/dietlibc/i386/cbrt.S | 46 ++ mdk-stage1/dietlibc/i386/ceil.S | 44 ++ mdk-stage1/dietlibc/i386/clone.S | 29 +- mdk-stage1/dietlibc/i386/connect.S | 4 + mdk-stage1/dietlibc/i386/copysign.S | 18 + mdk-stage1/dietlibc/i386/cos.S | 24 + mdk-stage1/dietlibc/i386/cosh.S | 29 + mdk-stage1/dietlibc/i386/dyn_syscalls.S | 283 ++++++++++ mdk-stage1/dietlibc/i386/exp.S | 35 ++ mdk-stage1/dietlibc/i386/exp10.S | 27 + mdk-stage1/dietlibc/i386/exp2.S | 18 + mdk-stage1/dietlibc/i386/expm1.S | 23 + mdk-stage1/dietlibc/i386/fabs.S | 11 + mdk-stage1/dietlibc/i386/floor.S | 26 + mdk-stage1/dietlibc/i386/fmod.S | 37 ++ mdk-stage1/dietlibc/i386/getenv.S | 48 ++ mdk-stage1/dietlibc/i386/getpeername.S | 4 + mdk-stage1/dietlibc/i386/getsockname.S | 4 + mdk-stage1/dietlibc/i386/getsockopt.S | 4 + mdk-stage1/dietlibc/i386/htonl.S | 13 + mdk-stage1/dietlibc/i386/htons.S | 11 + mdk-stage1/dietlibc/linuxnet.h | 19 + mdk-stage1/dietlibc/parselib.h | 23 + mdk-stage1/dietlibc/start.h | 14 - mdk-stage1/dietlibc/syscalls.h | 151 +---- mdk-stage1/dietlibc/threadsafe.sh | 5 + 86 files changed, 4073 insertions(+), 427 deletions(-) create mode 100644 mdk-stage1/dietlibc/BUGS create mode 100644 mdk-stage1/dietlibc/CAVEAT create mode 100644 mdk-stage1/dietlibc/CHANGES create mode 100644 mdk-stage1/dietlibc/COPYING create mode 100644 mdk-stage1/dietlibc/FAQ create mode 100644 mdk-stage1/dietlibc/PORTING create mode 100644 mdk-stage1/dietlibc/SECURITY create mode 100644 mdk-stage1/dietlibc/THANKS create mode 100644 mdk-stage1/dietlibc/TODO create mode 100644 mdk-stage1/dietlibc/alpha/__alarm.c create mode 100644 mdk-stage1/dietlibc/alpha/__testandset.S create mode 100644 mdk-stage1/dietlibc/alpha/lseek64.S create mode 100644 mdk-stage1/dietlibc/alpha/n_sigprocmask.S create mode 100644 mdk-stage1/dietlibc/alpha/sigaction.c delete mode 100644 mdk-stage1/dietlibc/alpha/signal.S delete mode 100644 mdk-stage1/dietlibc/alpha/sigprocmask.S create mode 100644 mdk-stage1/dietlibc/alpha/socketpair.S create mode 100644 mdk-stage1/dietlibc/alpha/syscalls.h create mode 100644 mdk-stage1/dietlibc/binshstr.h create mode 100644 mdk-stage1/dietlibc/diet.1 create mode 100644 mdk-stage1/dietlibc/dietdns.h create mode 100644 mdk-stage1/dietlibc/dieticonv.h create mode 100644 mdk-stage1/dietlibc/dietlibm.h delete mode 100644 mdk-stage1/dietlibc/dietstdarg.h create mode 100644 mdk-stage1/dietlibc/dietuglyweaks.h delete mode 100644 mdk-stage1/dietlibc/dirstream.h create mode 100644 mdk-stage1/dietlibc/dyn_start.c create mode 100644 mdk-stage1/dietlibc/dyn_stop.c create mode 100755 mdk-stage1/dietlibc/findcflags.sh create mode 100644 mdk-stage1/dietlibc/i386/PIC.h create mode 100644 mdk-stage1/dietlibc/i386/__half.S create mode 100644 mdk-stage1/dietlibc/i386/__ten.S create mode 100644 mdk-stage1/dietlibc/i386/accept.S create mode 100644 mdk-stage1/dietlibc/i386/acos.S create mode 100644 mdk-stage1/dietlibc/i386/acosh.S create mode 100644 mdk-stage1/dietlibc/i386/asin.S create mode 100644 mdk-stage1/dietlibc/i386/asinh.S create mode 100644 mdk-stage1/dietlibc/i386/atan.S create mode 100644 mdk-stage1/dietlibc/i386/atan2.S create mode 100644 mdk-stage1/dietlibc/i386/atanh.S create mode 100644 mdk-stage1/dietlibc/i386/atol.S create mode 100644 mdk-stage1/dietlibc/i386/atoll.S create mode 100644 mdk-stage1/dietlibc/i386/bind.S create mode 100644 mdk-stage1/dietlibc/i386/cbrt.S create mode 100644 mdk-stage1/dietlibc/i386/ceil.S create mode 100644 mdk-stage1/dietlibc/i386/connect.S create mode 100644 mdk-stage1/dietlibc/i386/copysign.S create mode 100644 mdk-stage1/dietlibc/i386/cos.S create mode 100644 mdk-stage1/dietlibc/i386/cosh.S create mode 100644 mdk-stage1/dietlibc/i386/dyn_syscalls.S create mode 100644 mdk-stage1/dietlibc/i386/exp.S create mode 100644 mdk-stage1/dietlibc/i386/exp10.S create mode 100644 mdk-stage1/dietlibc/i386/exp2.S create mode 100644 mdk-stage1/dietlibc/i386/expm1.S create mode 100644 mdk-stage1/dietlibc/i386/fabs.S create mode 100644 mdk-stage1/dietlibc/i386/floor.S create mode 100644 mdk-stage1/dietlibc/i386/fmod.S create mode 100644 mdk-stage1/dietlibc/i386/getenv.S create mode 100644 mdk-stage1/dietlibc/i386/getpeername.S create mode 100644 mdk-stage1/dietlibc/i386/getsockname.S create mode 100644 mdk-stage1/dietlibc/i386/getsockopt.S create mode 100644 mdk-stage1/dietlibc/i386/htonl.S create mode 100644 mdk-stage1/dietlibc/i386/htons.S create mode 100644 mdk-stage1/dietlibc/linuxnet.h create mode 100644 mdk-stage1/dietlibc/parselib.h delete mode 100644 mdk-stage1/dietlibc/start.h create mode 100755 mdk-stage1/dietlibc/threadsafe.sh (limited to 'mdk-stage1') diff --git a/mdk-stage1/dietlibc/.cvsignore b/mdk-stage1/dietlibc/.cvsignore index 7c88cb004..f0be42e21 100644 --- a/mdk-stage1/dietlibc/.cvsignore +++ b/mdk-stage1/dietlibc/.cvsignore @@ -10,3 +10,19 @@ bin-i386 bin-mips bin-ppc bin-sparc +bin-mipsel +bin-parisc +bin-s390 +bin-sparc64 +pic-alpha +pic-arm +pic-i386 +pic-mips +pic-ppc +pic-sparc +pic-mipsel +pic-parisc +pic-s390 +pic-sparc64 +bin-ia64 +bin-x86_64 diff --git a/mdk-stage1/dietlibc/AUTHOR b/mdk-stage1/dietlibc/AUTHOR index 6d8ab1a05..3f6a44e6d 100644 --- a/mdk-stage1/dietlibc/AUTHOR +++ b/mdk-stage1/dietlibc/AUTHOR @@ -1 +1,3 @@ Felix von Leitner + +Please see the file THANKS for additional authors and contributors. diff --git a/mdk-stage1/dietlibc/BUGS b/mdk-stage1/dietlibc/BUGS new file mode 100644 index 000000000..d030db5e6 --- /dev/null +++ b/mdk-stage1/dietlibc/BUGS @@ -0,0 +1,8 @@ +Please report bugs to + + felix-dietlibc@fefe.de + +or to the mailing list at + + dietlibc@fefe.de + diff --git a/mdk-stage1/dietlibc/CAVEAT b/mdk-stage1/dietlibc/CAVEAT new file mode 100644 index 000000000..efd20d6f5 --- /dev/null +++ b/mdk-stage1/dietlibc/CAVEAT @@ -0,0 +1,5 @@ + +Beware! Much of this code is untested! + +Someday, we will have a test suite and everything will be just fine. + diff --git a/mdk-stage1/dietlibc/CHANGES b/mdk-stage1/dietlibc/CHANGES new file mode 100644 index 000000000..24282baa5 --- /dev/null +++ b/mdk-stage1/dietlibc/CHANGES @@ -0,0 +1,887 @@ +0.22: + fix i386 libm + fix netinet/ip_icmp.h (Rui Prior) + make strings.h susv3 compliant (Gunnar Ritter) + remove stdio dependence in abort + fix truncate64, ftruncate64 (Luc Van Oostenryck and Yuri Kozlov) + fix and improve erand48() (Luc Van Oostenryck) + fix realpath for non-existant directories (Gergely Nagy and Gerrit Pape) + fix DNS timeout and IPv6 socket reuse + strtoul now accepts "-1" as well (Thomas Ogrisegg) + add i386 strcasecmp and __ltostr (Thomas Ogrisegg) + add killpg prototype (Luc Van Oostenryck) + remove some compiler warnings (Luc Van Oostenryck) + better rand() from Knuth's TAOCP (Luc Van Oostenryck) + fix unified x86_64 unified syscall 64-bit return value issue (Gwenole) + the getdents64 emulation was broken and repairing it opened a can of + worms. So I ripped it out. I also changed the readdir64 emulation + to work if there is no getdents64. + fix ia64 start.S (Thanks to Volker Birk for an account on his ia64 box) + many ia64 fixes (waitpid, nice, fork, vfork, time, utime ...) + More fixes from Gwenole (printf %p only printed the last 32 bits, I + botched the getdents64 #ifdefs, we violated the x86_64 ABI) + change signal() to do as glibc does + remove a few more warnings + add new 2.5 syscall #defines + add epoll_create, epoll_ctl and epoll_wait + the new x86 syscall numbers exceed 255, breaking our %al optimization + I worked around it with conditional assembly in cpp macros. Ugh. + +0.21: + use gcc's size_t, ptrdiff_t and wchar_t types (Olaf) + use -G 8 on MIPS to reduce code size (Johannes Stezenbach) + add munlock (Jens Låås) + argh, atexit fell victim to bit rot (or maybe Olaf) + add WANT_INET_ADDR_DNS to make gethostbyname not look up IP numbers + but use them to fill in the struct hostent directly. + signal is now a correct signal (Olaf) + read optimizer cflags for diet -Os gcc from ~/.diet/gcc, overriding + the built-in defaults. + add file "SECURITY". I will document design tradeoffs that have + security implications there. + fixed regex LINEEND condition + add .size directive to i386 syscalls + shove a few more bytes off the i386 socket calls + setjmp, longjmp and clone for x86_64 are now implemented but not tested (Olaf) + fix sparc signals + +0.20: + calloc was botched + umount and stime for x86_64 (Gwenole Beauchesne) + some malloc fixes for very big numbers (Enrico Scholz, me) + x86_64 unified syscall did not preserve rbx violating ABI (Gwenole) + realpath fix if path did not contain a slash (Gwenole) + add ucontext + add asm/statfs.h to work around people using + +0.19: + current gcc cvs makes __thread a keyword (Eric Troan) + be more strict regarding hostile DNS packets (me) + fix ia64 compile problems (Gerrit Pape) + make killpg a function and not a macro (broke bash 2.05b) + fix ia64 start code and unified syscall (me) + add sparc/strlen.S from Thomas Ogrisegg + add more space to ARM __jmp_buf in setjmp.h (Andre) + fix libcompat/syscall.S (did't compile on arm) + add integer overflow fix in xdr_array after bugtraq advisory (me) + fix x86_64 socket calls and mmap (and some more) (Gwenole Beauchesne) + add calloc integer overflow fix after RUS-CERT advisory (me) + add fread and fwrite integer overflow fix (me) + +0.18: + add stpcpy (from Thomas Ogrisegg) + check in mktime fix (from Luc Van Oostenryck) + add libm2.s from contrib to i386 (oops, how long has it been sitting + there?) + add truncate64 and ftruncate64 and prototype for truncate (only had ftruncate) + Michal Ludvig ported the diet libc to the x86_64 architecture (the + upcoming AMD Hammer chips!). You can't even buy the chips yet and + the diet libc already supports it! Amazing ;-) + Michal's patch also fixed several of the outstanding warnings. Thanks! + Andre sent a patch to add ARM profiling. He says it does not work + yet, but it's a start. + added getdents64 backwards compatibility and include it in large file + support #defines + perror now checks if the message is NULL like glibc (Thomas Ogrisegg) + ftell did not take ungetc into account (Kevin Ryde through Debian). + Thomas Ogrisegg sent a port to IA64! + sigaddset, sigdelset and setismember segfaulted for signal 0 (Gunnar Ritter) + Enrico Scholz reported several bugs in the header files. + change __malloc__ to __attribute_malloc__ + add pa-risc socketcall (but see TODO) (Felix J. Ogris) + fix *rand48 initialization (Kevin Ryde) + fnmatch infinite loop fix (Piotr Esden-Tempski) + make signal() into a sigaction wrapper function + add memrchr (Emil) + remove __attribute__((const)) from getpid() (Yuri Kozlov) + make getserv* also work if proto is NULL (Jens Låås) + now clone on parisc works (Thomas Ogrisegg) + getopt* fix from Thomas Walpuski + add syscall() to libcompat (Thomas Ogrisegg) + fix strncpy and strrchr i386 assembly versions for dynamic linking + (John K. Hohm) + allow short option grouping in getopt* (Ralf Wildenhues) + make the DNS resolver IPv6 transport capable (WANT_IPV6_DNS) + mention -v in diet.1 (Bryan Henderson) + auto-detect gcc 3 on i386 and remove compiler option warnings + putenv tweak (Thomas Ogrisegg) + add missing socket syscalls for PA-RISC and IA64 (Thomas Ogrisegg) + add cpio.h and tar.h (Thomas Ogrisegg) + change opendir/readdir/closedir from malloc to mmap (Thomas Ogrisegg) + cleanups from Florian LaRoche + +0.17: + fix several bugs in getservent_r + Gunnar Ritter reported the following: + moved tcgetpgrp and tcsetpgrp to unistd.h + adjusted lstat->lstat64 #define to make it work with function pointers + move __dietlibc__ #define from features.h to diet + Thomas Ogrisegg sent x86 memccpy and strncpy routines and introduced + an dietfeatures.h #define WANT_FULL_POSIX_COMPAT + Thomas also sent me profiling support (so far only on x86, but + profiling/PORTING describes what needs to be done for other + architectures)! + add contrib/dprof.c, also from Thomas. + Andreas Krennmair sent a patch to add the BSD regex interface to + libcompat + Andre noticed that __dtostr never sets first to false. Oops! + Andre has provided a largely untested patch that seems to fix the problem. + Igor Gilitschenski sent a patch for the "%8.7lx" issue. + abort did not flush all stdio streams + fix some nasty regular expression bugs + write a stupid malloc checker (contrib/debug-realloc.c) to help me + debug my regular expressions. Please read contrib/debug-realloc.txt + our i386 memchr,memcmp were broken for the count=0 case + fix DNS domain search + i386 memccpy exchanged esi and edi :-( I should do more checks before + accepting external code... + +0.16: + "diet -v" or "diet -Os" segfaulted without further arguments. + Andre found two very embarassing bugs in my four lines of md5 glue. + I need to get more sleep. + Thanks Ogrisegg found that ptrace does not work as documented and + provided a wrapper that emulates the glibc behaviour. + Dirk Engling saved 8 bytes and 4 cycles in the ARM clone() + fix ptrace.h for S/390 and ARM + provide a PORTING document so we don't lose track of which file need + to be touched to port the diet libc to a new platform. + remove a few warnings + provide a prototype for usleep. + make __dtostr work on ARM by using long instead of long long. + Idea by Dirk Engling. + fix an argument counting bug in *scanf (Thomas Ogrisegg) + Forgot an #endif in asm/sigcontext.h (Mike Castle) + Kurt Garloff sent in patches to + fix struct termios on non-x86 architectures + printf("%+05d\n",500) was broken (Raimar Falke told me, Olaf fixed it) + create libcompat.a (and move daemon to it) + add getdelim and getline + *printf now recognize 'z' integer flag (and ignore it) + Dirk Engling provided a strcpy.S for ARM. + Olaf: fixed *scanf familie. It hadn't wored with "long long". + Hans Lermen fixed i386/getenv.S + diet -Os no longer discards -fpic and -fno-pic + fix i386 rand/random to use correct RAND_MAX (thanks, Jaroslav + Macodiseas) + sys/ipc.h now includes sys/types.h + Olaf: started to make the sparc64 port + scandir should not sort if compar() is NULL (reported by Andrea Marrosu) + +0.15: + vfork sucks. I reverted to the old behavior where vfork==fork. + fix bsearch (and remove i386 assembly bsearch, needs to be redone). + Thanks Ogrisegg sent a patch to make the PA-RISC unified syscall + thread-safe! + remove vfork and add alarm to dynamic syscalls. + fix diet-dyn to link in dyn_dstop.o and not dyn_stop.o. + The MD5 code generated unaligned accesses when passed an unaligned + pointer on little endian ARM and MIPS. + MIPS unified syscall didn't compile anymore. + Put up new mipsel target to cross compile for little endian mips. + The mips target will again explicitly set endianness to big endian. + Compiling natively on a MIPS box should not touch the endianness. + Duh, when we removed return0, we broke tzset when the time zone parser + was disabled. Uwe Ohse noticed this. Thanks! + Fix gethostbyname to match host names case insensitively in /etc/hosts. + Oops, this was reported 6 weeks ago but I overlooked the email. + Thanks, Denis Rachal! + vsnprintf's zero termination was broken. + Uwe Ohse found a few more bugs: + Remove WANT_BUGGY_GLIBC_STRSEP. The Linux man page is broken, glibc + does it correctly. + Make inet_aton use strtoul instead of strtol + fdopen would close the file descriptor if it could not malloc the + buffer. + strftime updates. + Make _FILE_OFFSET_BITS includes -Wundef clean + Andre found a typo in endian.h for big endian mips + Ryan told me that fmod was not included in libm. Oops. + strstr(whatever,"") returned NULL, not whatever. Found by a new test + suite entry for strstr that I wrote. + Thomas Ogrisegg suggested or sent patches for the following: + add for profiling support. + make strncpy a #define in string.h to save a few bytes. + an i386 assembler getenv implementation (roughly half the size) + add grantpt, ptsname, unlockpt + add a getenv test suite entry. + Andre contributed an ARM assembler md5 implementation and he fixed mmap + on ARM. + add glibc macro names in sys/reboot.h. Mentioned by Laurent G. Bercot + getservent_r did not parse lines without aliases. Thanks, Jaroslav + Macodiseas! + fix MIPS start code (argv[0] was always corrupt) + removed annoying -Wconversion gcc switch + add -v to diet.c and fix MIPS CFLAGS in diet. Thanks, Johannes Stezenbach + Kurt Garloff sent these diffs: + add fdatasync (and make it a pthread cancellation point) + numerous alpha issues, like using .quad instead of .long for + offsets, change strip to -strip in Makefile (so a failing strip does + not abort the make), try to be more friendly to the gcc 2.96 that + SuSE 7.1 AXP ships with. + +0.14: + fix brk again (missing __brk, trivial oversight) + a new i386/atol.S that is 4 bytes smaller (and faster, too!). Thanks, + Thomas Ogrisegg! + Thomas also contributed a PA-RISC port including testandset, so + libpthread will work once we implement clone! Great work, Thomas. + made the fake locale more believable. + If you need gettext, use http://www.ca.postgresql.org/~petere/gettext.html + moved _exit into the unified syscall on x86. + Uwe Ohse found many more bugs: + getpass EINTR handling, ttyname, sysconf_cpus with SLASH_PROC_OK, + liblatin1 was more or less completely broken if you gave it chars as + arguments, not ints (signedness). execvp had a buffer overflow in + case a PATH element exceeded PATH_MAX, but it's not a security + problem since setuid programs need to set their path to some known + value anyway. + hasmntopt did not work with foo=bar style options + Uwe also improved ftw's stack usage. + Put movl instead of popl rationale in comment in i386/unified.S since + three people have suggested saving a few bytes with popl now ;) + I discovered __attribute__((malloc)) and started using it. For gcc 3, + it improves the optimizer when functions return malloced pointers. + Steven Rostedt pointed out that my setvbuf was broken with regard to + size==0 and sent a patch to fix it. + Thomas Ogrisegg made setenv smaller. + Olaf: implemented the parisc clone and an atomic testandset, modified the + libpthread to respect the parisc UPgrowing stack. still non functional, + because the unified syscall uses errno :( + tcgetospeed read from the wrong termios field. Thanks, Gunnar Ritter! + Fixed asprintf (relied on vsnprintf(NULL,...) to return length but + don't write anything which was no longer the case. It also + allocated one byte unnecessarily, which Uwe Ohse found. + Fix ttyname (readlink does not \0-terminate, forgot to do that). + +0.13: + add readdir64 and automatic mapping if _FILE_OFFSET_BITS == 64 + make diet not include the linker safeguard stuff when preprocessing + Olaf: port to S/390! + me: fix vfork (it was put into dietlibc.a twice) + res_query did not initialize last + diet (not diet-dyn, of course) now adds -static to the gcc command line + fixed fflush on input streams (tic from ncurses exposed this) + duh, there is an alarm system call, too, so we use it and not setitimer + fix comparison in gmtime_r that caused Jan 1 to be converted to Dec 32. + rewrote __dtostr (it also has one more argument now) + Thanks to Erik Troan for bringing these to my attention: + make putenv behave like glibc (putenv("HOME") == unsetenv("HOME")) + fix strncat for the case where n == 0 (security implications?) + fix bsearch (it didn't find the very last element in the array, same + bug in both the C and the i386 assembly version). + fixed FNM_PATHNAME in fnmatch + fix brk (the syscall was documented incorrectly in the Linux man page) + Thanks, Thomas Ogrisegg! + added negated character classes to fnmatch (not required by POSIX) + make the utmp routines open utmp read-only if read-write doesn't work. + remove syscalls.c directory, it is obsolete now with unified syscalls + +0.12: + more contributions from Frank Klemm. + iconv can now do UCS-2, too. + Imported several x86 assembly routines from Wouter van Kleunen. + Lots of bug fixes, and several more i386 specific versions of common + routines to make them smaller. + add memmem (a GNU extension that looks useful) + several changes from Michal Ludvig: inttypes.h gets C99 macros, + add pivot_root syscall, %n for *scanf. + add adjtimex (thanks, Laurent BERCOT) + add Frank Klemm's optimized md5 + add -Os option to diet (see diet.1). + several IPv6 constants and HZ were missing, thanks Johannes Kloos. + add 32-bit uid/gid syscalls. + add rand48 (thanks, Johannes Kloos) + fixed a lot of bugs in getopt* (thanks, Johannes) + add strxfrm and tweak limits.h. glib-1.3.8 now compiles without changes. + add a few more module syscalls. modutils-2.4.9 now compiles without changes. + fix gethostent alias list termination. Major oops. + add execle and two DNS constants (from Johannes Kloos). + opendir did not close-on-exec (thanks, Laurent Bercot). + DNS will now properly signal errors and set h_errno. + A few more cleanups (thanks, Andreas Jabs and Matthias Andree). + Added an uber-cool linker safeguard feature! Idea by Matthias Andree. + If you enable WANT_SAFEGUARD in dietfeatures.h, diet will include an + external reference to a symbol that is only in the diet libc. So, + when you accidentally link a diet libc compiled object file against + glibc, the linker will barf. This will bloat your object files, but + you can remove all the references with "strip -R .note" from + the binaries in the end (which you should do anyway). + fix ARM unified syscall (select did not work). + add getpwent_r ala glibc and replace getpwent + do the same for getgrent and getspent + remove entlib (new code is smaller) + rewrite getserv* to use parselib (and provide ..._r, too) + add getpwnam_r and getpwuid_r + rewrite getproto* to use parselib (and protive ..._r, too) + Olaf muddled with the dynamic linker. It's a clean-room + implementation in the sense that it once worked for Olaf in a clean + room ;) + add if_nameindex and if_freenameindex. + fixed arm unified syscalls to work with current binutils (; is no + longer a line separator but starts a comment, switched to .macro) + changed all st_[cma]time types to signed long so comparisons against + LONG_MIN will work correctly. (GNU tar does this) + fixed two bugs regarding ungetc. + add getusershell, setusershell, endusershell (for vs_ftpd) + add prctl, dirfd (also for vs_ftpd) + fixed strftime (was completely hosed) + added real make install target + +0.11: + fix major oops in DNS routines (only with WANT_FULL_RESOLV_CONF enabled). + fix vsscanf bug (Thanks, David Chappell). + add floor, ceil and memchr prototypes. + add __builtin_expect and expect #defines for gcc versions below 3.0 + cleaner errno vs __errno_location handling + add placeholder iconv (iconv_open will always return EINVAL) + try to remove kernel 2.4 header dependency in IPv6 sockaddr_in6 + initialization of getaddrinfo. + fix vsnprintf %X (printed lower case) + I wrote a new getopt. It appears to actually work (it is POSIX + compliant, it does not sort argv like the GNU version) and is only + a little over 300 bytes on x86. + Guillaume Cottenceau just wrote me that strncat should be even more + broken than it already is: it should append n bytes AND THEN \0! + I wonder how many programmers have produces off-by-one errors here... + Fix regexec offset return. autoconf now believes that diet libc has + POSIX regular expressions. + Fix fnmatch (a/b/* matched a/b/c/d even if FNM_PATHNAME was set) + Fix regular expression match for x* when there is no x at all. + Fix memory leak in error case in gethostbyname(2|). Thanks, Dietz Pröpper. + Add %h to vsnprintf. + Add FAQ. + Make %h work for signed numbers and add %hh to vsnprintf. + initgroups ignored the group argument :-( + remove printf references and nested functions from glob. + added an errno in libpthread that will display a prominent linker + warning. + started getting rid of kernel headers. Big task! :-( + add res_mkquery. The diet libc can now compile and link mtr. + Olaf: added a lot of code in libdl (not yet complete), changed the + startup code to make it work with his libdl and ld.so (needs still work + too) + __dns_readstartfiles only took the first domain or search path. + Thanks, Anthony de Boer + Olaf: added clone and a new unified_syscall for PowerPC + also dynlinker is now available (i386 only at this time) + crufted together a stdarg.h implementation from the various gcc headers. + implement getopt_long (ugh, the GNU people need professional help) + fixed word delimiters in regex (they looked for space, i.e. "," did + not work as delimiter) + errno.h now declares sys_errlist and sys_nerr. + added mkdtemp. + Uwe Ohse reported all of the following bugs: + ttyname should return 0 if !isatty. + realpath returns NULL if "." cannot be opened + putenv erroneously accepted (and mishandled) entries without "=". + popen returned 255 instead of 127 if /bin/sh could not be run. + fgetc did not set the internal EOF indicator on EOF. + bsearch contained an assumption about integer arithmetic overflow + behavior. + system did not set SIGCHLD and thus contained a race. + popen did not set close-on-exec and could leak an fd on malloc error. + daemon did not check whether open returns an fd below 3 + perror did not save errno. + Olaf: Peter Jones reported some problems with perror; strerror had the + same problem. + Peter also posted a patch to atexit/exit. With some modifications it is + now implemented. + Unbuffered stdio and ungetc can no longer be disabled. I will try to + implement part of it using ELF weak symbols. + Added minimal sysconf (tehe) from David Chappell. + Added overflow handling for strtoul and strtol. + Added WANT_ETC_HOSTS in dietfeatures.h and made gethostbyname/2 use + it before falling back to DNS if enabled. + Added a littie backwards compatibility cruft for gpm (man, do these + sources stink!) + Added openpty. + Squeeze a few bytes off the is* routines, courtesy of Peter Jones. + Fix fseek return value. + Add dirname and basename. + Add a few i386 math routines contributed by Frank Klemm. + Fixed getservent (did not allow _ and - in the aliases). + Thanks, Oden Eriksson + Added a float.h so configure believes we have ANSI header files. + Fix a lot more stdio bugs that Uwe Ohse pointed out. + Olaf: has added a new scanf and printf core that is suitable for all + scanf and printf function implementations + Imported a few more functions and optimizations from Frank Klemm (he + also rewrote dtostr to have more precision) + Olaf: checked in a new sig* function family (based on rt_sig*). + legacy <2.2 signal-handling doesn't work at the moment. + Made rudimentary iconv that can convert back and forth between + iso-8859-1, utf-8 and ucs-4 (for debugging). + Thanks to Markus Kuhn for the excellent utf-8(7)! + +0.10: + update getpagesize. + add personality. + add "%*s" and "%*.*s" support to vsnprintf. + add putchar (apparently arm-linux-gcc will substitute printf("\n") + with putchar('\n') behind your back...?! + import include/scsi/ from glibc. + add iopl. + add execl and sigdelset prototypes. + add getopt_long stuff to getopt.h (may compile but won't link). + add RPC headers (no code yet). + add mlockall, munlockall + make "diet gcc foo.c" work. + added Sun RPC code and removed as many warnings as possible in a + heroic act of self-mutilation. + added getproto* and getdtablesize for the RPC cruft :-( + added getpass. mount from util-linux actually compiles now! + fix the sig*set routines. mount actually works now *bg* + fix fwrite dividing by zero when trying to fwrite n records of size 0. + added an initial regex implementation (3500 bytes!!!). + add llseek and lseek64 with optional lseek fall-back. + add res_init. + add asprintf (ugh, what an ugly function). + expanded arpa/nameser.h to include backwards compatibility defines + add ut_name alias to ut_host in struct utmp. + add inet_ntop, inet_pton, gethostbyname2. + add sysinfo, recvmsg, sendmsg. + add endmntent, getmntent, setmntent. + fix fnmatch (thanks, Guillaume Cottenceau!) + add setenv. + remove __restrict from mntent.h, add __restrict__ removal alias for + older gcc versions in sys/cdefs.h. + add rlim_t, sig_atomic_t declarations. + add sigsetjmp #define for __sigsetjmp (oops). + (Thanks to Chris Siebenmann for these three bug reports) + add a gruesome hack to printf floating point to accept %f and kludge + together support for %.2f. Don't look at the code, please! + fixed tcsetpgrp (oops, this is embarassing! Thanks, Chris Siebenmann) + imported fix for entlib by Jeff Garzik. + add glob implementation from Guillaume Cottenceau (Thanks!!) + add libdl fragments from Olaf (Yeah! One step closer to dynamic linking!) + add REG_ICASE and word start/end handling to my regular expressions. + my regular expressions now actually match substrings (i.e. "foobar" to "bar"). + wrap getcwd to comply to man page (the syscall returns the number of + bytes, not the buffer) + add realpath. + fix vfprintf. + fix *scanf %s zero termination. + add abs, labs, llabs. + add , ioperm syscall. + add flock to + fixes to bsearch and the regular expressions. + add fake herror. + add scandir and alphasort. + add killpg + implemented a gross hack to make libpthread compile when + dietfeatures.h does not define WANT_THREAD_SAFE (it's empty then). + add getaddrinfo and freeaddrinfo (man, what a fucked up interface!) + fix sigsuspend (syscall had completely fscked up arguments!) + RLIM_INFINITY from the kernel is broken. Thanks to Chris Siebenmann + for sending a patch. + add getserv*. + add WANT_FULL_RESOLV_CONF so that the DNS routines use "domain" and + "search" from resolv.conf. + +0.9: + fixed initgroups (oops) + Cleanup appending file open for stdio (thanks, James Antill) + imported vfprintf fix from James Antill. + add fnmatch + change index, rindex and bcmp as weak ELF symbols (were #defined before) + Olaf added character classes to *scanf. + Put object and library files into a separate directory (bin-$ARCH). + Add "cross" make target to make all architectures. + Add "diet" program and man page. + Add getgrnam, getgrgid + Add cfmakeraw (Thanks, Antonio Musumeci) + localtime won't call gettimeofday when the tzfile parser is used. + +0.8: + vsnprintf(0,...) estimated the length of strings with a padding width + incorrectly. + new reboot() from Olaf. + added prototypes for getsockopt and setsockopt. + added experimental sem* and shm* + define EXIT_SUCCESS and EXIT_FAILURE + added setvbuf (only changes mode, not buffer) + added dietwarning.h (woohoo, linker warnings!) and used it to warn of + insecurity (system, sprintf) or bloat (printf and stdio). + added qsort() and bsearch(). Benchmark on 1000 random ints: + glibc: 679414 cycles qsort and 3352 cycles bsearch + diet libc: 300010 cycles qsort, 553 cycles bsearch + I have no idea why glibc is so slow. + added __isnan (references by libm.a from glibc). + added popen() and pclose(). Now the diet libc can link slsh (from + S-Lang!) + corrected usleep. It was more of an msleep until now. + corrected __dtostr (it looped when trying to format "0.0"). + several fixes to stdio (thanks to S-Lang's excellent test suite!) + added ungetc (does it work?) + added inet_aton (yuck!) + added gethostbyname, gethostbyaddr, gethostbyname_r and gethostbyaddr_r + added h_errno and __h_errno_location + added inet_ntoa + added setpgrp and getpgrp, strsignal and execv (thanks, Olaf) + add bcopy, index, rindex macros + add isgraph and isxdigit + add strftime (ugh!!!) + Olaf fixed strftime, gmtime_r leap year bug. + Jeff Garzik contributed a spec file. I put it in contrib and hope + everbody knows what to do with it... + Olaf checked in a ton of libpthread stuff. + added mkstemp using /dev/urandom (harder to guess than getpid()). + add large file backwards compatibility support (so gzip will run on + kernel 2.2 and 2.0) + added shutdown + added nice + added pseudo-locale support for is* (they are now weak aliases, + isupper -> __isupper_ascii etc). So, for example, liblatin1 can + overwrite the default is* functions. + added liblatin1.a + added tzfile implementation (does it work for anyone else?) + added syslog(3) (thanks to Rene Müller!) + Jeff Garzik contributed getgr*, getpw* and getsp* in one tiny package. + Thanks! + merged duplicate code in execv and execvp into exec_lib.o + +0.7.2: + added several prototypes to already implemented functions and + . Thanks for Abraham for pointing this out. + added prototypes for process group and dup syscalls. Thanks to + Abraham again. He also contributed an implementation for daemon(), + an ugly BSD hack. I decided to diversify the lib/ directory a + little and now created a libugly/ directory for stuff like system() + and daemon() ;-) + added libstdio and moved all that stdio crap from lib/ there. The + idea is to start separating now what we will separate for shared + libraries anyway. + optimized x86 unified-syscall by Olaf. + added limits.h, removed __ARCHBITS from endian.h (use __WORDSIZE from + limits.h instead) + added remove.c and enough cruft to limits.h to make it compile lzo, + lzop and bzip2. + added mktime, asctime_r, asctime and ctime (needed for gzip). + Someone will need to implement a reader for the glibc localtime file + format some day (man tzfile, ugh!) :-( + added unlink prototype to unistd.h. + added gmtime and gmtime_r. + fixed sparc unified syscall error handling (please upgrade!). + removed readdir glibc compatibility cruft. + removed stat glibc compatibility cruft. + oops, my fread was broken for pipes. + Olaf found a bug in pipe() for sparc, too. + +0.7.1: + optimized away the static arrays from __ltostr and __lltostr. + optimized away the static arrays (and more!) from strtoul and strtoull. + added system (by Olaf). + added tolower and toupper + added getopt from Olaf (~600 bytes on x86!) + added clone for mips (by Olaf). + fixed longjmp and setjmp on sparc not to require glibc include files. + added pause for all (by Olaf). + added __attribute__ ((__const__)) to ctype.h + added isupper and islower. + added putc and putchar as macros. + added strcasecmp and strncasecmp (thanks to Abraham vd Merwe for + insightful discussions and patches I partially used for the last three) + added getpriority and setpriority (also by Abraham) + oops, I broke strtoul in a recent optimization attempt. + oi, setjmp and longjmp were broken on other platforms, too! + Thanks to Sébastien Côté for reporting this. + +0.7: + clone support for i386,alpha,arm and sparc by Olaf. + Initial dynamic loading glue for i386, also by Olaf. + We don't have a dynamic loader yet, so this is not yet usable. + added readv, sigdelset, sigaltstack, sigfillset, sigismember, usleep, + vsprintf, writev, all by Olaf. + imported readdir fix from Guillaume. Mhh, can the kernel interface + really be this broken? + Found a kludgy way to detect whether the kernel includes define struct + stat64 (they also define STAT64_HAS_BROKEN_ST_INO). If this does + not work for you, please tell me! + Removed bogus __seek_types enum, it's a bunch of #defines now. + Fixed stdio line buffering. The code was already there but I forgot + to mark stdio and stdout as line buffered. This should really be + done dynamically using isatty, though. + Removed superfluous "if (1)" in execvp.c + +0.6.14: + *scanf did not append the 0 byte for %s. + added creat and changed creat to call open directly instead of open64. + did for fread what 0.6.10 did for fwrite. + repaired buffered stdio a little (line buffering is still not + supported). + [All of these bugs have been reported by Guillaume. Thanks!] + added __pure__ to strchr and strrchr in + +0.6.13: + included COPYING to make clear that the diet libc is covered by the + GNU General Public License (and _not_ the LGPL). That means that + you need to obtain a license from me if you want to use the diet + libc in a proprietary program that you want to distribute. + The x86 unified syscall swapped arguments #4 and #5 and noone + noticed until now! Thanks to Guillaume Cottenceau for reporting + this! + The malloc had a subtle bug with small allocations that could cause + segfault. Guillaume reported it, Olaf fixed it. + +0.6.12: + added assert, statfs and fstatfs + added include/net/if.h so fget compiles again. + +0.6.11: + added putenv. + +0.6.10: + fixed fwrite. It returned the number of bytes written, not the number + of records. Thanks to Albert D. Cahalan for pointing this out. + fixed fgets. It returned EOF on empty lines. Thanks, Erik Frey. + added brk and sbrk. harold@nb.com.sg made me do it. + +0.6.9: + fixed execvp not to return on ENOENT + did for {open|read|close|seek|tell}dir what I did for stat before. + The glibc compatibility part is currently non-functional. + fixed white space handling in sscanf " (" would not match " (". + fixed printf to accept 'l' flag. + fixed getpwuid (ignored last line) + +0.6.8: + Olaf contributed initial thread-safe syscalls for i386, alpha, sparc, + mips and arm. I did the one for ppc. They can be enabled in dietfeatures.h. + added strlcpy and strlcat from OpenBSD. + added stat64, fstat64 and lstat64. + added endian.h and made ending of strlen.c endianness-aware + added string routines size tweak to dietfeatures.h. Most of the + string routines have been unrolled. This is up to three times as + fast but creates up to three times larger code. Now you can disable + the unrolling. + added sendfile. + I also added pread. It works on x86 and sparc but not on ppc and mips. + I have no idea what's going on. strace disagrees with the kernel. + Can anyone help? I asked the Linux kernel mailing list for help, too. + added a few aliases of the type __libc_open for open. nm on + libpthreads.so indicates that we will need them. + +0.6.7: + the sources now compile without warnings with -Wall. + printf now prints "(null)" when %s is passed NULL. This can be + removed with WANT_NULL_PRINTF in dietfeatures.h + added vfprintf, execl, ttyname. + stat, lstat and fstat are now #defined to __dietstat, __dietlstat and + __dietfstat so they can use the normal kernel struct stat. + stat, lstat and fstat are now C wrappers that convert to the glibc + struct stat. So we can avoid that overhead for programs that use + dietlibc headers. + +0.6.6: + changed the Makefiles so you can now set CFLAGS on the command line + added memccmp (analogous to memccpy) and strncmp. + Olaf fixed another bug in the sparc unified syscall. + Paul Clifford contributed a C version of his strlen.S that is much + more efficient than the previous strlen on all platforms! It also + looks like technology from Roswell. ;-} + added a "real" stdio. Well, almost. Please contribute! + added dietfeatures.h so you can remove features you don't need. + removed debug code from vsnprintf that changed \0 to ' ' (argh!). + stdio now works with simple programs and minigzip from libz. + stdio uses some major trickery to avoid linking the stdio, stderr and + stdout (and reserving space for them) when they are not used. + +0.6.5: + Red Plait found several bugs in diet libc, + most of them bugs in the new header files, but also missing sigset + functions. + Paul Clifford contributed an assembly strlen.S for ARM and fixed + several bugs. + Fixed ppc/setjmp and mips/pipe. + Olaf contributed a new sparc unified syscall. + +0.6.4: + declared is* static inline in getservent. + added assert_fail, strtoul, isalpha, isdigit, isalnum, isascii. + changed strlen to return 0 when passed NULL. + new, much smaller unified syscall for MIPS. Thanks to Olaf the Mad + Scientist who actually implemented this without access to a MIPS + box, just from reading the architecture manual. And it worked out + of the box. + started a set of system includes, mainly so that I can use lcc and + my alpha-linux cross compiler (which is unable to cross-compile + glibc). diet libc can now be compiled without any include files + from a normal libc. The includes do declare more than diet libc + currently delivers and they are still far from complete for real + applications. + I will only add assembly versions that are smaller _and_ faster than + the C version. Larger routines are only accepted if they are called + very often and are substantially faster. + added i386 assembly strchr, which is smaller and faster than the old + version. It is, however, larger than the version contributed by + proton (thanks, anyway). + added i386 strlen (31% faster, 14% smaller) + "make t" will now create a map file called "mapfile". + +0.6.3: + added sys_errlist, strerror and perror + added isblank + added atol + +0.6.2: + mmap for ARM didn't compile. Thanks, Paul! + +0.6.1: + split mmap into the architecture specific subdirectories. + getenv now copes with environ==NULL, thanks Paul Clifford. + Paul also contributed a smaller ARM startup code. + +0.6: + strcat returned the wrong result. Thanks, Dietz Pröpper. + strtod now understands a negative exponent (oops, thanks Bertram Barth) + Port to arm-linux-gnu, but on the Netwinder I use for testing the + __dtostr does not work (I have no idea why!) + The MIPS port now uses (much smaller) non-PIC code. That means that + the applications you link against diet libc also have to be compiled + non-PIC. I suggest copying the CFLAGS from the diet libc Makefile. + Thanks to Ralf Bächle for helping me with this! + I made subdirectories for the architectures and use VPATH to override + VPATH so that make finds the source file automatically. That should + simplify the sources greatly. + Olaf Dreesen contributed Alpha support including setjmp and longjmp! + ARM and MIPS now also have setjmp and longjmp + "compile" and "load" are now make targets. Use them for djb programs. + added contrib/elftrunc.c which will remove unnecessary ELF headers. + Again, contributed from Olaf. Great work! + +0.5.12: + printf also does signed numbers. + If you don't use atexit, dietlibc now does not link exit, only _exit. + *printf now correctly returns the number of bytes written. + Olaf contributed experimental sscanf and vsscanf implementations. + If passed NULL as buffer, snprintf will not write anything but still + return the number of bytes it would have written. + Initial MIPS port! (Oh, the agony!) + No setjmp and longjmp support yet! Please contribute! + I even implemented unified syscalls for MIPS. Still, MIPS code is + almost twice the size of SPARC code. If anyone knows why: please + tell me! + +0.5.11: + I implemented new unified syscalls for x86, sparc and ppc, this time based + on .s files and not .c files, and I moved the syscalls into + subdirectores to clean the dietlibc sources up a little. + A binary consisting of printf("%s is %d\n","olaf",23) is now + 2864 bytes on sparc + 2488 bytes on intel + I kludgily implemented fprintf(stdout,... and fprintf(stderr,... + to make a few more applications work. + Olaf Dreesen also implemented some unified syscall stuff for x86. + He discovered that with our unified syscall interface it actually + costs <10 bytes total to make all system calls thread safe! + I implemented atexit() (can register up to 4 callbacks). + I implemented strtod and __dtostr (the opposite). Now we can add + floating point support to vsnprintf and sscanf! + +0.5.10: + I actually saw that I can not only merge the errno handling code of + the system calls on x86, I can also merge the rest (including the + arguments) except for setting the system call number. All those + system calls are now just a jump to a unified system call handler. + I got rid of x86openclose again. The savings are substantial: + chown from embutils went from 7664 to 7184 bytes! + If I'd move the system call wrappers to assembly language, I could + even reduce the alignment (does not matter since it's just a jump + anyway) and get rid of the "ret" behind each jump (one byte per + system call!) + +0.5.9: + added memchr, strpbrk, strstr, strtol, isspace (hehe) + fixed strdup + fixed return values for strcpy and strcat (thanks to Norbert Berzen) + Olaf Dreesen contributed a strtol and initial {sn|vsn|}printf implementation + (no signed integers, only strings and unsigned integers (but + supporting octal, hex and decimal). Thanks, Olaf! (by the way: + that code must be wonderful, I don't understand it at all *bg*) + Olaf's printf does understand padding like in "%08d" and "%8d" and + automatically pads pointers with '0'. + Rewrote the x86 start code, old: 22 instructions, new: 12 instructions. + Thanks to proton for inspiration on this. + The new x86 start code also does not reference exit any more, thus saving + 64 bytes for executables that don't call exit explicitly. + [insert maniacal laughter] EVERY BYTE COUNTS!1!! ;-) + Moved errno and environ to start.S, saving no byte binary size but + speeding up compilation and slightly shortening dietlibc.a ;-) + For x86: joined open and close into one assembler file, sharing the + errno handling. This is a feasibility test and it actually saves a + few bytes. I think I will reimplement the _syscall[1-6] macros on + all platforms now to share the errno handling code for them. + +0.5.8: + fixed strchr to be able to look for 0. + + added _llseek, ftruncate, getpgid, getresgid, getresuid, getsid, + memccpy, memmove, mprotect, setregid, setresgid, setresuid, setreuid, + strncpy, swapon, truncate, strtok, strtok_r, strspn, strcspn (all + contributed by Olaf Dreesen) + + added execvp, getcwd + + fixed __xmknod + + Note: can it be that the ftw interface really is so broken that I + cannot implement it without having to implement some searching data + structure? I included an experimental ftw implementation that will + not follow symlinks. + +0.5.7: + oops, if_nametoindex was broken! + +0.5.6: + ported to ppc-linux. + fixed i386 sigsetjmp (I mistyped the function name) + included sigjmp.c + +0.5.5: + added wait, sys_siglist, longjmp/setjmp/sigsetjmp for i386 and sparc + actually, it wasn't fork that wasn't working for sparc, it was pipe. + I fixed it now. + dietlibc/SPARC assumes -msupersparc (does not provide div, mul, etc) + fixed readdir to use getdents and not the intel inline asm + +0.5.4: + ported to sparclinux (sparc32 only). Beware: does not work yet. + added raise, abort, readlink, strcat, geteuid, geteuid, wait3, access + +0.5.3: + added tcsetattr and getenv to compile e3 + +0.5.2: + added vhangup, tcgetattr, isatty and memcmp for fgetty + (http://www.fefe.de/fgetty/) + added localtime from uC-libc. + +0.5.1: + stat and friends actually work now. Yuck! Another case of + translation between kernel and userland. Why can't the kernel + people and the libc people simply agree on a standard? + removed many unnecessary includes to speed up compilation. + added -fomit-frame-pointer and i386 compilation target to reduce code size. + inlined socketcall to reduce code size. + "load" and "compile" are examples for djb code. + +0.5: + Olaf Dreesen contributed a much smaller implementation of malloc and friends. + each object file is now treated with "strip -x -R .note -R .comment" + split each system call into a separate object file + added ntohs, htons, alarm, if_indextoname and if_nametoindex + +0.4.1: + oops, the strchr implementation was wrong. Thanks Jens Laas! + +0.4: + copied opendir and friends from uC-libc. + added getservent and getservby* in gerservent.c + +0.3: + remove readdir system call + added getdents system call + added getpwnam/getpwuid implementation in getpwnam.c + added a few string functions (in str*.c) + diff --git a/mdk-stage1/dietlibc/COPYING b/mdk-stage1/dietlibc/COPYING new file mode 100644 index 000000000..5b6e7c66c --- /dev/null +++ b/mdk-stage1/dietlibc/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/mdk-stage1/dietlibc/FAQ b/mdk-stage1/dietlibc/FAQ new file mode 100644 index 000000000..02bae3dcd --- /dev/null +++ b/mdk-stage1/dietlibc/FAQ @@ -0,0 +1,209 @@ +diet libc FAQ. + + +Q: How do I compile this? I don't see a configure? +A: Just type make. + + +Q: How do I install it? make install? +A: Yep. It will then install itself to /opt/diet, with the wrapper in + /opt/diet/bin/diet. Or you don't install it at all. + The diet libc comes with a wrapper called "diet", which can be found + in bin-$(ARCH)/diet, i.e. bin-i386/diet for most of us. Copy this + wrapper somewhere in your path (for example ~/bin) and then just + compile stuff by prepending diet to the command line, e.g. "diet gcc + -pipe -g -o t t.c". + + +Q: How do I compile programs using autoconf with the diet libc? +A: Set CC in the environment properly. For Bourne Shells: + + $ CC="diet gcc -nostdinc" ./configure --disable-nls + + That should be enough, but you might also want to set + --disable-shared and --enable-static for packages using libtool. + + +Q: My program complains about missing asm/* or linux/* header files! +A: It is quite linux specific. You can try omitting the -nostdinc, but + except for some cases conflicts are likely. You should not be using + the kernel headers in your software. + + +Q: Do you have cross compiling support? +A: Yes. Just type something like "make ARCH=arm CROSS=arm-linux- all". + For arm, alpha, mips, ppc, sparc and i386, shortcuts exist. You can + also use "make arm", for example. You still use the same "diet" + program as for normal compilation, but you can then say + + $ diet sparc-linux-gcc -pipe -g -o t t.c + + Programs using autoconf can be configured like this: + + $ CC="diet sparc-linux-gcc" ./configure --disable-nls + + +Q: There are a few warnings about possibly uninitialized variables when + compiling the diet libc. Can't you remove them? +A: This type of warning can only be removed by a) compiling without + warnings or b) initializing the variables in question. In all cases, + the variables won't actually be used uninitialized, but adding an + explicit initializer will add a few bytes of code. As you know, the + goal of the diet libc is to not waste a single byte of code, so we + don't add initializers ;-) + + +Q: When linking binaries, I get warnings about stdio and printf all the + time. What gives? +A: Since the diet libc was written to make writing small programs + possible, it also tries to assist in the process of seeing causes of + bloat. Premier causes for bloat are stdio and the printf family of + functions. The diet libc will also warn you if you still use + assert() (which is normally not enabled in production code) or if you + use functions that use static buffers (like gethostbyname and + friends). + + +Q: My program stopped parsing command line arguments properly! Now what? +A: The getopt in the diet libc adheres to the Single Unix Specification. + In particular, it initialized optind to 1 (not 0) and breaks if + someone sets optint to 0 (as some misguided legacy programs to). + Also, it does not reorder arguments, i.e. something like "rm -f foo -v" + will not see -v as option but rather as non-option argument. If you + need GNU getopt behaviour, please use GNU getopt instead of the diet + libc code. + + +Q: I get linker errors about missing __ctype_b! +A: This happens when you link in code that was compiled with the glibc + headers. The most common culprit is a library like -lncurses, + -lcrypto or -lresolv. All external libraries you use have to be + compiled with the diet libc headers (CC="diet gcc"), and there is no + libresolv with the diet libc, it's in the main libc! + + +Q: My program links, but when I run it, I get no output at all and it + appears to terminate immediately. +A: This normally happens if you link in glibc. The major reason for + this was that shared libraries were linked in. diet sets -static + since version 0.13, so if it still happens to you, you need to strace + and debug your software. + + +Q: Why aren't you compatible to glibc? I thought the interface was a + standard? +A: Yes, the interface is, but a lot of details are missing. For + example, the diet libc uses a different "struct stat" layout than + glibc. We use the one from the kernel, glibc uses an own one and + links in translation code. This is part of the reason why glibc is + so big and ugly. If we support all of this, we end up as bloated as + glibc. + + +Q: Where is the test suite? +A: The humble beginnings are in the "test" directory, but it can't be + run automatically yet. + + +Q: GPL sucks! Now I can't compile my BSD programs with the diet libc! +A: Wrong. You can compile them, and you can use them. You just can't + redistribute the binaries. If you are a distribution vendor and want + to use the diet libc to make BSD licensed binaries for the install + or rescue floppy which you sell commercially, please talk to me. + + +Q: Where are the shared libaries? make install didn't install them! +A: You have to explicitly build them with "make dyn". Since they are + experimental and only supported on a small subset of the platforms, + that is not default. Also, I recommend you only use shared libraries + if you really know what you are doing. For example, you can't just + use your system shared libraries, because they have a dependency on + glibc in them, so the program will crash. And you have to explicitly + compile the code with -fPIC or -fpic. You can then use them by + substituting "diet-dyn" for "diet" on the command line. + + +Q: My target platform does not have a MMU. Should I be using uClibc? +A: I am not aware of any issues with MMU-less systems. You should be + able to use the diet libc just fine. Having a MMU or not is mostly + an issue for the kernel, not libc. + + +Q: How do I make myself a cross compiler? +A: untar binutils and gcc (I used version 2.11.2 and 3.0.4 respectively) + Then use the --target=arm-linux (or whatever platform you want) + configure options. For gcc, add --enable-languages=c (otherwise gcc + will try to make C++, Objective C and Java, too, and those + compilations will fail because they require installed libc headers + which you don't have yet). I recommend using --enable-static + --disable-shared, too, because otherwise the binutils shared + libraries will overwrite each other if you install more than one + cross binutils for different targets. + binutils$ ./configure --enable-static --disable-shared --prefix=/opt/cross --target=arm-linux + gcc$ ./configure --enable-static --disable-shared --prefix=/opt/cross --target=arm-linux --enable-languages=c + For some platforms, gcc compilation will fail while trying to compile + some part of libgcc.a because it depends on some libc header file. + This is a gcc bug and you should complain using gccbug, because you + can't cross-compile libc unless you successfully installed the cross + compiler. + + +Q: Where are the xdr_* symbols? +Q: Where are the RPC symbols? +Q: util-linux says that rpcgen output does not work?! +A: Add -lrpc. The code is from Sun and frankly it is so ugly and so + rarely used that I don't want to include it in libc. + + +Q: I am missing some BSD/GNU extension! +A: I started adding a few of them to libcompat. You have to link it in + manually, though, as using them is bad for portability and I want + people to make a conscious effort to write non-portable applications + by not including them in the libc itself. + + +Q: I'm just starting with the diet libc. Should I use the tarball or + the CVS version? +A: Always use the CVS version. We generally don't add unstable test + stuff on the CVS tree, and our APIs are stable (they are + standardized, remember?). In fact, we don't add much stuff at all. + Most changes are bug fixes and optimizations, and in general you'll + want those. + + +Q: Does the diet libc support profiling (with gprof)? +A: There is experimental support for profiling, but so far it only works + on x86. To use it, do "make profiling" before make install. Then, + diet will link in the support code if it finds a -pg on the gcc + command line. + + +Q: I get compiler errors in a line with caddr_t, u_long, n_short or + nlong or similar. +A: Add -D_BSD_SOURCE to the compiler command line. The diet libc tries + to encourage portable and standards compliant programming, so it + hides these legacy BSD types from the standard name space. The + reason is that the Single Unix Specification contains a specification + of the socket API but does not mention those types. + + +Q: I get compiler errors in a line with u_int8_t or similar. +A: Add -D_GNU_SOURCE to the compiler command line. See previous + question. This is a very questionable GNU extension. The C Standard + defines uint8_t, uint16_t and uint32_t. Use those instead. + + +Q: Can I compile or use the diet libc with a compiler that is not gcc? +A: Compile: no. Use: yes. + + +Q: Can you please port the diet libc to FreeBSD/Solaris/Windows? +A: No. + + +Q: Why do you support non-embedded platforms like IA64 and x86_64? +A: The diet libc is also useful for servers because it can improve + performance by an order of magnitude for certain programming models. + Please see http://www.fefe.de/fnord/ (in particular .../fnord/SPEED) + for an example and/or read http://www.fefe.de/talk.pdf for some + benchmarks. diff --git a/mdk-stage1/dietlibc/Makefile b/mdk-stage1/dietlibc/Makefile index b6e7b2783..ca28ec345 100644 --- a/mdk-stage1/dietlibc/Makefile +++ b/mdk-stage1/dietlibc/Makefile @@ -1,13 +1,96 @@ -ARCH=$(shell uname -m | sed 's/i[4-9]86/i386/') +INSTALL=install +prefix=/usr +# Set the following to install to a different root +#DESTDIR=/tmp/fefix +# Use "make DEBUG=1" to compile a debug version. + +MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6][lb]/arm/' -e 's/ppc64/ppc/') + +# This extra-ugly cruft is here so make will not run uname and sed each +# time it looks at $(OBJDIR). This alone sped up running make when +# nothing has to be done from 1 sec to 0.12 sec on a 900 MHz Athlon. +# We don't use ARCH:=$(MYARCH) so we can detect unknown architectures. +ifeq ($(MYARCH),i386) +ARCH=i386 +else +ifeq ($(MYARCH),mips) +ARCH=mips +else +ifeq ($(MYARCH),alpha) +ARCH=alpha +else +ifeq ($(MYARCH),ppc) +ARCH=ppc +else +ifeq ($(MYARCH),arm) +ARCH=arm +else +ifeq ($(MYARCH),sparc) +ARCH=sparc +else +ifeq ($(MYARCH),sparc64) +ARCH=sparc64 +else +ifeq ($(MYARCH),s390) +ARCH=s390 +else +ifeq ($(MYARCH),mipsel) +ARCH=mipsel +else +ifeq ($(MYARCH),parisc) +ARCH=parisc +else +ifeq ($(MYARCH),x86_64) +ARCH=x86_64 +else +ifeq ($(MYARCH),ia64) +ARCH=ia64 +else +$(error unknown architecture, please fix Makefile) +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif + +# ARCH=$(MYARCH) + +LIBDIR=${prefix}/lib +ifeq ($(ARCH),x86_64) +LIBDIR=${prefix}/lib64 +endif +BINDIR=${prefix}/bin +MAN1DIR=${prefix}/share/man/man1 +INSTALLHOME=$(LIBDIR)/dietlibc OBJDIR=bin-$(ARCH) +ILIBDIR=$(INSTALLHOME)/lib-$(ARCH) + +HOME=$(shell pwd) -all: $(OBJDIR) $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/librpc.a $(OBJDIR)/diet +WHAT= $(OBJDIR) $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o \ + $(OBJDIR)/dietlibc.a $(OBJDIR)/liblatin1.a \ + $(OBJDIR)/libcompat.a $(OBJDIR)/libm.a \ + $(OBJDIR)/librpc.a $(OBJDIR)/libpthread.a \ + $(OBJDIR)/diet $(OBJDIR)/diet-i $(OBJDIR)/elftrunc -CFLAGS=-pipe +all: $(WHAT) + +profiling: $(OBJDIR)/libgmon.a $(OBJDIR)/pstart.o + +CFLAGS=-pipe -nostdinc CROSS= -VPATH=lib:libstdio:libugly:libcruft:libcrypt:libshell:liblatin1:librpc:libregex:syscalls.c +CC=gcc + +VPATH=lib:libstdio:libugly:libcruft:libcrypt:libshell:liblatin1:libcompat:libdl:librpc:libregex:libm:profiling SYSCALLOBJ=$(patsubst syscalls.s/%.S,$(OBJDIR)/%.o,$(wildcard syscalls.s/*.S)) @@ -17,13 +100,23 @@ LIBSTDIOOBJ=$(patsubst libstdio/%.c,$(OBJDIR)/%.o,$(wildcard libstdio/*.c)) LIBCRUFTOBJ=$(patsubst libcruft/%.c,$(OBJDIR)/%.o,$(wildcard libcruft/*.c)) LIBCRYPTOBJ=$(patsubst libcrypt/%.c,$(OBJDIR)/%.o,$(wildcard libcrypt/*.c)) LIBSHELLOBJ=$(patsubst libshell/%.c,$(OBJDIR)/%.o,$(wildcard libshell/*.c)) +LIBCOMPATOBJ=$(patsubst libcompat/%.c,$(OBJDIR)/%.o,$(wildcard libcompat/*.c)) $(OBJDIR)/syscall.o +LIBMATH=$(patsubst libm/%.c,%.o,$(wildcard libm/*.c)) LIBRPCOBJ=$(patsubst librpc/%.c,$(OBJDIR)/%.o,$(wildcard librpc/*.c)) LIBREGEXOBJ=$(patsubst libregex/%.c,$(OBJDIR)/%.o,$(wildcard libregex/*.c)) +LIBDLOBJ=$(patsubst libdl/%.c,$(OBJDIR)/%.o,$(wildcard libdl/*.c)) $(OBJDIR)/_dl_jump.o + +LIBPTHREAD_OBJS=$(patsubst libpthread/%.c,$(OBJDIR)/%.o,$(shell ./threadsafe.sh)) $(OBJDIR)/__testandset.o + +LIBGMON_OBJS=$(OBJDIR)/__mcount.o $(OBJDIR)/monitor.o $(OBJDIR)/profil.o + include $(ARCH)/Makefile.add -ifeq ($(CFLAGS),-pipe) +LIBMATHOBJ=$(patsubst %,$(OBJDIR)/%,$(LIBMATH)) + +ifeq ($(CFLAGS),-pipe -nostdinc) CFLAGS+=-O -fomit-frame-pointer endif @@ -31,28 +124,39 @@ ifneq ($(DEBUG),) CFLAGS = -g COMMENT = : endif -CFLAGS += -Wall -Wno-switch +CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wredundant-decls -Wno-unused PWD=$(shell pwd) .SUFFIXES: .SUFFIXES: .S .c -$(OBJDIR): +# added real dynamic dietlibc.so +PICODIR = pic-$(ARCH) + +$(OBJDIR) $(PICODIR): mkdir $@ % :: %,v -$(OBJDIR)/%.o: %.S +$(OBJDIR)/pstart.o: start.S + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -DPROFILING -c $< -o $@ + +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -c $< -o $@ + $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ $(OBJDIR)/%.o: %.c $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -c $< -o $@ - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ + $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ -DIETLIBC_OBJ = $(SYSCALLOBJ) $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ +DIETLIBC_OBJ = $(OBJDIR)/unified.o \ +$(SYSCALLOBJ) $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ $(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ) \ -$(OBJDIR)/__longjmp.o $(OBJDIR)/setjmp.o $(OBJDIR)/unified.o \ +$(OBJDIR)/__longjmp.o $(OBJDIR)/setjmp.o \ $(OBJDIR)/mmap.o $(OBJDIR)/clone.o $(OBJDIR)/dietlibc.a: $(DIETLIBC_OBJ) $(OBJDIR)/start.o @@ -65,67 +169,184 @@ LIBLATIN1_OBJS=$(patsubst liblatin1/%.c,$(OBJDIR)/%.o,$(wildcard liblatin1/*.c)) $(OBJDIR)/liblatin1.a: $(LIBLATIN1_OBJS) $(CROSS)ar cru $@ $^ +$(OBJDIR)/libgmon.a: $(LIBGMON_OBJS) + $(CROSS)ar cru $@ $^ + +$(OBJDIR)/libpthread.a: $(LIBPTHREAD_OBJS) dietfeatures.h + $(CROSS)ar cru $@ $(LIBPTHREAD_OBJS) + +$(OBJDIR)/libcompat.a: $(LIBCOMPATOBJ) + $(CROSS)ar cru $@ $(LIBCOMPATOBJ) + +$(OBJDIR)/libm.a: $(LIBMATHOBJ) + $(CROSS)ar cru $@ $(LIBMATHOBJ) + $(OBJDIR)/libdietc.so: $(OBJDIR)/dietlibc.a $(CROSS)ld -whole-archive -shared -o $@ $^ +dyn: dyn_lib + +# added dynamic linker +$(OBJDIR)/libdl.a: $(LIBDLOBJ) + $(CROSS)ar cru $@ $(LIBDLOBJ) + +dyn_lib: $(PICODIR) $(PICODIR)/libc.so $(PICODIR)/dstart.o \ + $(PICODIR)/dyn_so_start.o $(PICODIR)/dyn_start.o $(PICODIR)/dyn_stop.o \ + $(PICODIR)/libpthread.so $(PICODIR)/libdl.so $(PICODIR)/libcompat.so \ + $(PICODIR)/diet-dyn $(PICODIR)/diet-dyn-i + +$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ + +$(PICODIR)/pthread_%.o: libpthread/pthread_%.c + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ + $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ + +$(PICODIR)/%.o: %.c + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ + $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ + +$(PICODIR)/dstart.o: start.S + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ + +$(PICODIR)/dyn_so_start.o: dyn_start.c + $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@ + $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ + +DYN_LIBC_PIC = $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ +$(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ) + +DYN_LIBC_OBJ = $(PICODIR)/dyn_syscalls.o $(PICODIR)/errlist.o \ + $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(DYN_LIBC_PIC)) + +DYN_PTHREAD_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBPTHREAD_OBJS)) + +DYN_LIBDL_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBDLOBJ)) + +DYN_LIBCOMPAT_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBCOMPATOBJ)) + +$(PICODIR)/libc.so: $(PICODIR) $(DYN_LIBC_OBJ) + $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so + +$(PICODIR)/libpthread.so: $(DYN_PTHREAD_OBJS) dietfeatures.h + $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so + +$(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h + $(CROSS)$(CC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -o $@ $(CFLAGS) -I. -Iinclude libdl/_dl_main.c -Wl,-soname=libdl.so + +#$(PICODIR)/libdl.so: $(DYN_LIBDL_OBJS) dietfeatures.h +# $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBDL_OBJS) -L$(PICODIR) -ldietc -Wl,-soname=libdl.so + +$(PICODIR)/libcompat.so: $(DYN_LIBCOMPAT_OBJS) dietfeatures.h + $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBCOMPAT_OBJS) -L$(PICODIR) -lc -Wl,-soname=libcompat.so + + + $(SYSCALLOBJ): syscalls.h -$(OBJDIR)/diet: diet.c $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a - $(CROSS)$(CC) -Iinclude $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(PWD)\" +$(OBJDIR)/elftrunc: $(OBJDIR)/diet contrib/elftrunc.c + bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/elftrunc.c + +VERSION=dietlibc-$(shell head -1 CHANGES|sed 's/://') +CURNAME=$(notdir $(shell pwd)) + +$(OBJDIR)/diet: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o + $(CROSS)$(CC) -Iinclude $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc + $(CROSS)strip -R .comment -R .note $@ + +$(OBJDIR)/diet-i: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o + $(CROSS)$(CC) -Iinclude $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(INSTALLHOME)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc $(CROSS)strip -R .comment -R .note $@ +$(PICODIR)/diet-dyn: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c + $(CROSS)$(CC) -Iinclude $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(HOME)/$(PICODIR)/libdl.so + $(CROSS)strip -R .command -R .note $@ + +$(PICODIR)/diet-dyn-i: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c + $(CROSS)$(CC) -Iinclude $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(ILIBDIR)/libdl.so -DINSTALLVERSION + $(CROSS)strip -R .command -R .note $@ + $(OBJDIR)/djb: $(OBJDIR)/compile $(OBJDIR)/load $(OBJDIR)/compile: - echo 'exec gcc $(CFLAGS) -I$(PWD)/$(OBJDIR)/include -c $${1+"$$@"}' > $@ + echo 'exec' $(CC) '$(CFLAGS) -I$(PWD)/$(OBJDIR)/include -c $${1+"$$@"}' > $@ chmod 755 $@ $(OBJDIR)/load: - echo 'main="$$1"; shift; exec gcc -nostdlib -o "$$main" $(PWD)/$(OBJDIR)/start.o "$$main".o $${1+"$$@"} $(PWD)/$(OBJDIR)/dietlibc.a -lgcc' > $@ + echo 'main="$$1"; shift; exec' $(CC) '-nostdlib -o "$$main" $(PWD)/$(OBJDIR)/start.o "$$main".o $${1+"$$@"} $(PWD)/$(OBJDIR)/dietlibc.a -lgcc' > $@ chmod 755 $@ clean: - rm -f *.o *.a t t1 compile load exports mapfile libdietc.so - rm -rf bin-* + rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so + rm -rf bin-* pic-* + $(MAKE) -C examples clean + $(MAKE) -C dynlinker clean + $(MAKE) -C libdl clean -tar: clean - rm -f armv4l - ln -sf arm armv4l - cd ..; tar cvvf dietlibc.tar.bz2 dietlibc --use=bzip2 --exclude CVS +tar: clean rename + cd ..; tar cvvf $(VERSION).tar.bz2 $(VERSION) --use=bzip2 --exclude CVS + +rename: + if test $(CURNAME) != $(VERSION); then cd .. && mv $(CURNAME) $(VERSION); fi $(OBJDIR)/exports: $(OBJDIR)/dietlibc.a nm -g $(OBJDIR)/dietlibc.a | grep -w T | awk '{ print $$3 }' | sort -u > $(OBJDIR)/exports .PHONY: t t1 t: - $(CROSS)$(CC) -g $(CFLAGS) -fno-builtin -nostdlib -Iinclude -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a -lgcc -Wl,-Map,mapfile + $(CROSS)$(CC) -g $(CFLAGS) -fno-builtin -nostdlib -Iinclude -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dietlibc.a -lgcc $(OBJDIR)/dyn_stop.o -Wl,-Map,mapfile t1: $(CROSS)$(CC) -g -o t1 t.c -install: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/diet - cp $(OBJDIR)/start.o $(INSTALLPREFIX)$(prefix)/lib/dietstart.o - cp $(OBJDIR)/dietlibc.a $(INSTALLPREFIX)$(prefix)/lib/libdietc.a - cp $(OBJDIR)/liblatin1.a $(INSTALLPREFIX)$(prefix)/lib/libdietlatin1.a - cp $(OBJDIR)/diet $(INSTALLPREFIX)$(prefix)/bin/diet - -.PHONY: sparc ppc mips arm alpha i386 - -arm sparc ppc alpha i386: - $(MAKE) ARCH=$@ CROSS=$@-linux- all t bin-$@/libdietc.so - -mips: - $(MAKE) ARCH=$@ CROSS=$@-linux-gnu- all t bin-$@/libdietc.so +install: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/librpc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/elftrunc $(OBJDIR)/diet-i + $(INSTALL) -d $(DESTDIR)$(ILIBDIR) $(DESTDIR)$(MAN1DIR) $(DESTDIR)$(BINDIR) + $(INSTALL) $(OBJDIR)/start.o $(DESTDIR)$(ILIBDIR)/start.o + $(INSTALL) -m 644 $(OBJDIR)/libm.a $(OBJDIR)/libpthread.a $(OBJDIR)/librpc.a \ +$(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(DESTDIR)$(ILIBDIR) + $(INSTALL) -m 644 $(OBJDIR)/dietlibc.a $(DESTDIR)$(ILIBDIR)/libc.a +ifeq ($(MYARCH),$(ARCH)) + $(INSTALL) $(OBJDIR)/diet-i $(DESTDIR)$(BINDIR)/diet + -$(INSTALL) $(PICODIR)/diet-dyn-i $(DESTDIR)$(BINDIR)/diet-dyn +endif + -$(INSTALL) $(OBJDIR)/pstart.o $(OBJDIR)/libgmon.a $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR) + -$(INSTALL) $(PICODIR)/libc.so $(DESTDIR)$(ILIBDIR)/libc.so + -$(INSTALL) $(PICODIR)/libpthread.so $(DESTDIR)$(ILIBDIR)/libpthread.so + -$(INSTALL) $(PICODIR)/libdl.so $(DESTDIR)$(ILIBDIR)/libdl.so + -$(INSTALL) $(PICODIR)/libcompat.so $(DESTDIR)$(ILIBDIR)/libcompat.so + -$(INSTALL) $(PICODIR)/dyn_start.o $(DESTDIR)$(ILIBDIR)/dyn_dstart.o + -$(INSTALL) $(PICODIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)/dyn_dstop.o + -$(INSTALL) $(PICODIR)/dstart.o $(PICODIR)/dyn_so_start.o $(DESTDIR)$(ILIBDIR) + $(INSTALL) -m 644 diet.1 $(DESTDIR)$(MAN1DIR)/diet.1 + if test -f $(PICODIR)/libc.so -a ! -f $(DESTDIR)/etc/diet.ld.conf; then echo "$(ILIBDIR)" > $(DESTDIR)/etc/diet.ld.conf; fi + for i in `find include -name \*.h`; do install -m 644 -D $$i $(DESTDIR)$(INSTALLHOME)/$$i; done + +.PHONY: sparc ppc mips arm alpha i386 parisc mipsel powerpc s390 sparc64 +.PHONY: x86_64 ia64 + +arm sparc ppc alpha i386 mips parisc s390 sparc64 x86_64 ia64: + $(MAKE) ARCH=$@ CROSS=$@-linux- all + +# Cross compile for little endian MIPS +mipsel: + $(MAKE) ARCH=$@ CROSS=mips-linux- all + +mips-gnu: + $(MAKE) ARCH=$@ CROSS=$@-linux-gnu- all + +# Some people named their cross compiler toolchain powerpc-linux-gcc +powerpc: + $(MAKE) ARCH=ppc CROSS=powerpc-linux- all cross: - $(MAKE) arm sparc ppc alpha i386 mips + $(MAKE) arm sparc ppc alpha i386 mips sparc64 # these depend on dietfeatures.h for large file backward compatibility -$(OBJDIR)/__fstat64.o $(OBJDIR)/__lstat64.o $(OBJDIR)/__stat64.o: dietfeatures.h +$(OBJDIR)/__fstat64.o $(OBJDIR)/__lstat64.o $(OBJDIR)/__stat64.o $(OBJDIR)/lseek64.o $(OBJDIR)/readdir64.o $(OBJDIR)/stat64.o $(OBJDIR)/lstat64.o $(OBJDIR)/fstat64.o $(OBJDIR)/truncate64.o $(OBJDIR)/__truncate64.o $(OBJDIR)/ftruncate64.o $(OBJDIR)/__ftruncate64.o $(PICODIR)/dyn_syscalls.o $(PICODIR)/__truncate64.o $(PICODIR)/__ftruncate64.o $(PICODIR)/__stat64.o $(PICODIR)/__lstat64.o $(PICODIR)/__fstat64.o: dietfeatures.h # these depend on dietfeatures.h for thread support -$(OBJDIR)/alloc.o $(OBJDIR)/perror.o $(OBJDIR)/logging.o $(OBJDIR)/unified.o: dietfeatures.h +$(OBJDIR)/alloc.o $(OBJDIR)/perror.o $(OBJDIR)/logging.o $(OBJDIR)/unified.o $(OBJDIR)/clone.o $(OBJDIR)/set_errno.o: dietfeatures.h # these depend on dietfeatures.h for linker warnings $(OBJDIR)/assert_fail.o $(OBJDIR)/sprintf.o $(OBJDIR)/vsnprintf.o $(OBJDIR)/___div.o $(OBJDIR)/fflush.o $(OBJDIR)/setvbuf.o $(OBJDIR)/system.o $(OBJDIR)/sendfile.o $(OBJDIR)/setenv.o: dietfeatures.h @@ -137,10 +358,56 @@ fclose.o $(OBJDIR)/fdglue.o $(OBJDIR)/fflush.o $(OBJDIR)/fgetc.o $(OBJDIR)/fputc strcasecmp.o $(OBJDIR)/strcat.o $(OBJDIR)/strchr.o $(OBJDIR)/strcmp.o $(OBJDIR)/strcpy.o $(OBJDIR)/strlen.o $(OBJDIR)/strncasecmp.o $(OBJDIR)/strncat.o $(OBJDIR)/strrchr.o: dietfeatures.h # these depend on dietfeatures.h for /proc -$(OBJDIR)/tty.o: dietfeatures.h - -# these depend on dietfeatures.h for ungetc support ;-) -$(OBJDIR)/ungetc.o: dietfeatures.h +$(OBJDIR)/ttyname.o $(OBJDIR)/sysconf_cpus.o: dietfeatures.h # these depend on dietfeatures.h for WANT_TZFILE_PARSER $(OBJDIR)/localtime_r.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_SMALL_STDIO_BUFS +$(LIBSTDIOOBJ): dietfeatures.h + +# these depend on dietfeatures.h for WANT_FULL_RESOLV_CONF +$(OBJDIR)/dnscruft.o $(OBJDIR)/dnscruft2.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_THREAD_SAFE and errno +$(LIBRPCOBJ) $(OBJDIR)/logging.o $(OBJDIR)/alloc.o $(OBJDIR)/cfsetospeed.o $(OBJDIR)/cfsetispeed.o \ +$(OBJDIR)/execl.o $(OBJDIR)/execlp.o $(OBJDIR)/execv.o $(OBJDIR)/execvp.o $(OBJDIR)/isatty.o \ +$(OBJDIR)/lockf.o $(OBJDIR)/perror.o $(OBJDIR)/remove.o $(OBJDIR)/set_errno.o $(OBJDIR)/sigemptyset.o \ +$(OBJDIR)/tcsetattr.o $(OBJDIR)/dnscruft2.o $(OBJDIR)/dnscruft.o $(OBJDIR)/entlib.o \ +$(OBJDIR)/gethostbyaddr.o $(OBJDIR)/gethostbyaddr_r.o $(OBJDIR)/gethostbyname.o \ +$(OBJDIR)/gethostbyname_r.o $(OBJDIR)/gethostbyname2.o $(OBJDIR)/gethostbyname2_r.o \ +$(OBJDIR)/inet_pton.o $(OBJDIR)/mkstemp.o $(OBJDIR)/mktemp.o $(OBJDIR)/tempnam.o \ +$(OBJDIR)/glob.o $(OBJDIR)/realpath.o $(OBJDIR)/fdglue.o $(OBJDIR)/fdglue2.o \ +$(OBJDIR)/getaddrinfo.o $(OBJDIR)/getnameinfo.o $(OBJDIR)/getprotoent.o \ +$(OBJDIR)/getservent.o $(OBJDIR)/iconv.o $(OBJDIR)/iconv_open.o \ +$(OBJDIR)/netent.o $(OBJDIR)/system.o $(OBJDIR)/stdin.o $(OBJDIR)/stdout.o \ +$(OBJDIR)/stderr.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_CRYPT_MD5 +$(OBJDIR)/crypt.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_FREAD_OPTIMIZATION +$(OBJDIR)/fread.o $(OBJDIR)/fwrite.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_DYNAMIC +$(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o: dietfeatures.h + +$(OBJDIR)/unified.o: dietuglyweaks.h + +$(OBJDIR)/adjtimex.o: include/sys/timex.h + +$(OBJDIR)/fgetc_unlocked.o $(OBJDIR)/fread.o $(OBJDIR)/ungetc.o: dietstdio.h + +# these depend on dietfeatures.h for WANT_LINKER_WARNINGS +$(OBJDIR)/setlinebuf.o $(OBJDIR)/bzero.o $(OBJDIR)/setegid.o \ +$(OBJDIR)/seteuid.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_FULL_POSIX_COMPAT +$(OBJDIR)/strncpy.o: dietfeatures.h +$(OBJDIR)/strxfrm.o: dietfeatures.h + +# these depend on dietfeatures.h for WANT_INET_ADDR_DNS +$(OBJDIR)/gethostbyname_r.o: dietfeatures.h + + +# CFLAGS+=-W -Wshadow -Wid-clash-31 -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings diff --git a/mdk-stage1/dietlibc/PORTING b/mdk-stage1/dietlibc/PORTING new file mode 100644 index 000000000..4e2a6358c --- /dev/null +++ b/mdk-stage1/dietlibc/PORTING @@ -0,0 +1,28 @@ +To port the diet libc to a new architecture, you need to: + + - edit Makefile to detect the architecture + - create a directory for the architecture, and put a Makefile.add in + it. Look at the other Makefile.adds for guidance. + - provide start.S (the start code, look at glibc) + - provide unified.S (the unified syscall) + - provide syscalls.h (the syscall numbers, from asm/unistd.h) + - provide setjmp and longjmp + - edit include/setjmp.h + - pipe, clone and mmap often need special care + - edit include/sys/ioctl.h + - edit include/sys/ptrace.h + - edit include/asm/sigcontext.h + - edit include/sys/ucontext.h + - edit include/endian.h + - edit include/fcntl.h + - edit include/sys/mman.h + - edit include/sys/shm.h + - edit include/sys/stat.h + - edit include/errno.h + - edit syscalls.h + - edit include/termios.h + - edit diet.c to make it recognize the architecture and add proper + CFLAGS + - edit libcompat/syscall.S + +(I may have missed a few) diff --git a/mdk-stage1/dietlibc/README b/mdk-stage1/dietlibc/README index ce9838832..2a1fa332c 100644 --- a/mdk-stage1/dietlibc/README +++ b/mdk-stage1/dietlibc/README @@ -1,3 +1,8 @@ + The system library is a challenge to all those using the computer to + write their own faster and better routines or to bow to the superior + strength and skill of a true master. + --http://www.inner.net/users/cmetz/program-like-a-klingon + diet libc to statically link programs that don't need all the bloat from glibc. @@ -7,10 +12,7 @@ To compile: $ make -make should compile the diet libc itself without warnings. In addition -to the diet libc, the default make target includes t, which is a test -program and probably contains code which produces warnings. You can -safely ignore them. +make should compile the diet libc itself. When make is done, it will have created dietlibc.a in bin-i386 (or bin-ppc, bin-alpha, bin-sparc, bin-ppc or bin-arm, depending on your @@ -41,3 +43,7 @@ The embedded utils are small replacements for common utilities like mv, chown, ls, and even a small tar that can extract tar files. The binary repository contains a few utilities I linked against the diet libc, for example gzip, bzip2 and fdisk. + + +The license for the diet libc is the GNU General Public License, version +2 (as included in the file COPYING). diff --git a/mdk-stage1/dietlibc/SECURITY b/mdk-stage1/dietlibc/SECURITY new file mode 100644 index 000000000..67debc6e7 --- /dev/null +++ b/mdk-stage1/dietlibc/SECURITY @@ -0,0 +1,13 @@ +The diet libc was written with small code and embedded devices in mind, +not with security for network servers. + +Of course we still try to avoid buffer overflows, but there are some +parts of the code where tradeoffs have been made. This file is meant to +document them. + + 1. The DNS routines do not check whether the answer came from the IP + of the DNS server. The rationale is that people who can sniff the + network to find out the query, source port and DNS sequence number + can also spoof DNS packets to appear to come from the server we + asked, so it does not actually increase security to have that + check. diff --git a/mdk-stage1/dietlibc/THANKS b/mdk-stage1/dietlibc/THANKS new file mode 100644 index 000000000..cda9400b6 --- /dev/null +++ b/mdk-stage1/dietlibc/THANKS @@ -0,0 +1,31 @@ +The malloc code was done by Olaf Dreesen, who also helped with the SPARC +start code and fork(). Olaf also did the printf and scanf routines and +he implemented pthreads (wow!) and his now writing a dynamic linker, and +he ported the diet libc to S/390. + +Thomas Ogrisegg ported the diet libc to PA-RISC and IA64 and fixed a few things. + +I initially took some syscalls from Redhat minilibc, but the code has +been completely replaced now. + +I initially took localtime and the directory reading routines from +uClibc, but the code has been completely replaced now. + +syslog and crypt were contributed by René Müller. + +Jeff Garzik contributed {get,set}{pw,gr,sp}ent. + +Uwe Ohse went through the code and fixed many bugs. + +Frank Klemm contributed the math library and a lot of correctness and +smallness patches and rewrote many functions in ix86 assembly language. + +Erik Troan found several important bugs and sent in patches to fix them. + +I also grabbed code from glibc (mostly assembly routines), and looked at +the OpenBSD libc for inspiration. + +Michal Ludvig did the porting to x86_64 and Gwenole Beauchesne helped +finish the port. + +Johannes Stezenbach improved the MIPS port. diff --git a/mdk-stage1/dietlibc/TODO b/mdk-stage1/dietlibc/TODO new file mode 100644 index 000000000..3e323ad44 --- /dev/null +++ b/mdk-stage1/dietlibc/TODO @@ -0,0 +1,26 @@ + - "locale" + - real regerror + - improve code size and quality with __restrict__. + - FPU exception handling (for mawk) + - res_mkquery should not assume op is QUERY + - syslog + - gethost/netent -> parselib? + - Look at qsort (the make test suite exhibits the worst case) + - Make __dtostr do scientific notation. + - fix %g in printf. They are more or less completely b0rken (in + particular rounding the last digit does not work). + - qmail-queue dumps core since we added vfork. Editing fork.h to #define + vfork to fork works. What happens here? + - use TCP if buf[2]&2 is non-zero in DNS answers. + - look at mktime: "Falls tm_isdst == -1 gesetzt, so sollte mktime + versuchen herauszufinden, ob Sommerzeit eingestellt ist (und laut linux + manpage auch tzname setzen), ansonsten die angegebene DST + berücksichtigen." + - better rand()? + - try to make zebra compile. + - printf %e + - move DNS stuff to libresolv.a? + - x86_64: readdir fails their test (Gwenole Beauchesne) + - regular expressions standards compliance; test suite from AT&T + - fgetpwent (needed for cvm) + - investigate putting some libgcc symbols in dietlibc.so for gcc<3 diff --git a/mdk-stage1/dietlibc/alpha/Makefile.add b/mdk-stage1/dietlibc/alpha/Makefile.add index 10ff0faef..68b10b43c 100644 --- a/mdk-stage1/dietlibc/alpha/Makefile.add +++ b/mdk-stage1/dietlibc/alpha/Makefile.add @@ -2,4 +2,4 @@ CFLAGS+=-Os -Iinclude -fomit-frame-pointer -fstrict-aliasing VPATH:=alpha:syscalls.s:$(VPATH) -LIBOBJ+=$(patsubst %,$(OBJDIR)/%,divq.o divl.o remq.o reml.o seteuid.o __time.o) +LIBOBJ+=$(patsubst %,$(OBJDIR)/%,divq.o divl.o remq.o reml.o __time.o __alarm.o) diff --git a/mdk-stage1/dietlibc/alpha/__alarm.c b/mdk-stage1/dietlibc/alpha/__alarm.c new file mode 100644 index 000000000..7ca35cb78 --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/__alarm.c @@ -0,0 +1,13 @@ +#include +#include + +unsigned int alarm(unsigned int seconds) { + struct itimerval old, new; + unsigned int ret; + new.it_interval.tv_usec=0; + new.it_interval.tv_sec=0; + new.it_value.tv_usec =0; + new.it_value.tv_sec =(long)seconds; + if (setitimer(ITIMER_REAL,&new,&old)==-1) return 0; + return old.it_value.tv_sec+(old.it_value.tv_usec?1:0); +} diff --git a/mdk-stage1/dietlibc/alpha/__longjmp.S b/mdk-stage1/dietlibc/alpha/__longjmp.S index d86d76717..31e374d0f 100644 --- a/mdk-stage1/dietlibc/alpha/__longjmp.S +++ b/mdk-stage1/dietlibc/alpha/__longjmp.S @@ -1,11 +1,10 @@ -#ifdef __alpha__ - #include .text .align 2 .global __longjmp +.type __longjmp,@function __longjmp: mov $17, $0 /* a1 -> v0 */ @@ -18,7 +17,7 @@ __longjmp: ldq $26, (JB_PC*8) ($16) /* ra */ ldq $fp, (JB_FP*8) ($16) /* fp */ - ldq $1, (JB_SP*8) ($16) /* sp */ + ldq $sp, (JB_SP*8) ($16) /* sp */ ldt $f2, (JB_F2*8) ($16) /* f2 */ ldt $f3, (JB_F3*8) ($16) /* f3 */ @@ -30,9 +29,5 @@ __longjmp: ldt $f9, (JB_F9*8) ($16) /* f9 */ cmoveq $0, 0x1, $0 - mov $1, $sp ret $31, ($26), 1 - - -#endif diff --git a/mdk-stage1/dietlibc/alpha/__testandset.S b/mdk-stage1/dietlibc/alpha/__testandset.S new file mode 100644 index 000000000..c5ef81241 --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/__testandset.S @@ -0,0 +1,11 @@ +.text +.align 2 +.global __testandsets +.type __testandsets,@function +__testandset: + ldq_l $0, 0($16) /* load lock */ + bne $0,1f /* ok there is a lock... */ + lda $0, 1($31) /* load a 1 to register 0 */ + stq_c $0, 0($16) /* write lock is locked :) */ + beq $0,__testandset /* oops someone changed MY lock */ +1: ret $31, ($26), 0x01 /* return */ diff --git a/mdk-stage1/dietlibc/alpha/clone.S b/mdk-stage1/dietlibc/alpha/clone.S index b7e32d707..28e61a8bc 100644 --- a/mdk-stage1/dietlibc/alpha/clone.S +++ b/mdk-stage1/dietlibc/alpha/clone.S @@ -1,5 +1,5 @@ #include "syscalls.h" -#include +#include .text .align 2 diff --git a/mdk-stage1/dietlibc/alpha/lseek64.S b/mdk-stage1/dietlibc/alpha/lseek64.S new file mode 100644 index 000000000..f051e734d --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/lseek64.S @@ -0,0 +1,5 @@ +#include "syscalls.h" + +.global lseek64 +lseek64: + br lseek diff --git a/mdk-stage1/dietlibc/alpha/n_sigprocmask.S b/mdk-stage1/dietlibc/alpha/n_sigprocmask.S new file mode 100644 index 000000000..55f9fde28 --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/n_sigprocmask.S @@ -0,0 +1,3 @@ +#include "syscalls.h" + +syscall_weak(osf_sigprocmask,__old_sigprocmask,__n_sigprocmask) diff --git a/mdk-stage1/dietlibc/alpha/setjmp.S b/mdk-stage1/dietlibc/alpha/setjmp.S index 3768056be..04bfd3d94 100644 --- a/mdk-stage1/dietlibc/alpha/setjmp.S +++ b/mdk-stage1/dietlibc/alpha/setjmp.S @@ -1,15 +1,16 @@ #include .text +.weak setjmp +.type setjmp,@function +setjmp: +.weak __setjmp +.type __setjmp,@function +__setjmp: + mov 0, $17 .global __sigsetjmp +.type __sigsetjmp,@function __sigsetjmp: - ldgp $gp, 0($gp) - - mov $sp, $1 - lda $sp, -16($sp) - - stq $26, 0($sp) /* save ra */ - stq $9, (JB_S0*8) ($16) /* s0 */ stq $10, (JB_S1*8) ($16) /* s1 */ stq $11, (JB_S2*8) ($16) /* s2 */ @@ -19,7 +20,7 @@ __sigsetjmp: stq $26, (JB_PC*8) ($16) /* ra */ stq $fp, (JB_FP*8) ($16) /* fp */ - stq $1, (JB_SP*8) ($16) /* sp */ + stq $sp, (JB_SP*8) ($16) /* sp */ stt $f2, (JB_F2*8) ($16) /* f2 */ stt $f3, (JB_F3*8) ($16) /* f3 */ @@ -30,17 +31,5 @@ __sigsetjmp: stt $f8, (JB_F8*8) ($16) /* f8 */ stt $f9, (JB_F9*8) ($16) /* f9 */ - br $26, __sigjmp_save /* call __sigjmp_save */ + br $31, __sigjmp_save /* jmp __sigjmp_save */ - ldq $26, 0($sp) /* restore ra */ - - lda $sp, 16($sp) - ret $31, ($26), 1 /* back to caller */ - -.weak setjmp -setjmp: -.weak __setjmp -__setjmp: - ldgp $gp, 0($gp) - mov 0, $17 - br __sigsetjmp diff --git a/mdk-stage1/dietlibc/alpha/sigaction.c b/mdk-stage1/dietlibc/alpha/sigaction.c new file mode 100644 index 000000000..f6c3ada7d --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/sigaction.c @@ -0,0 +1,7 @@ +#include + +int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, long nr, void* restorer); + +int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { + return __rt_sigaction(signum, act, oldact, _NSIG/8, 0); +} diff --git a/mdk-stage1/dietlibc/alpha/signal.S b/mdk-stage1/dietlibc/alpha/signal.S deleted file mode 100644 index ceca0f02d..000000000 --- a/mdk-stage1/dietlibc/alpha/signal.S +++ /dev/null @@ -1,3 +0,0 @@ -#include "syscalls.h" - -syscall(osf_signal,signal) diff --git a/mdk-stage1/dietlibc/alpha/sigprocmask.S b/mdk-stage1/dietlibc/alpha/sigprocmask.S deleted file mode 100644 index d9da836c2..000000000 --- a/mdk-stage1/dietlibc/alpha/sigprocmask.S +++ /dev/null @@ -1,3 +0,0 @@ -#include "syscalls.h" - -syscall_weak(osf_sigprocmask,sigprocmask,__sigprocmask) diff --git a/mdk-stage1/dietlibc/alpha/socketpair.S b/mdk-stage1/dietlibc/alpha/socketpair.S new file mode 100644 index 000000000..06956a7ce --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/socketpair.S @@ -0,0 +1,3 @@ +#include "syscalls.h" + +syscall(socketpair,socketpair) diff --git a/mdk-stage1/dietlibc/alpha/start.S b/mdk-stage1/dietlibc/alpha/start.S index 00b8e950d..850ce2420 100644 --- a/mdk-stage1/dietlibc/alpha/start.S +++ b/mdk-stage1/dietlibc/alpha/start.S @@ -1,7 +1,3 @@ -#include "start.h" - -#ifdef __alpha__ - .text .align 2 .set noreorder @@ -17,19 +13,21 @@ _start: ldgp $gp, 0($gp) /* prepare to call main */ - ldl $16, 0($sp) /* argc */ + ldl $16, 0($sp) /* argc / a0 */ - lda $17, 8($sp) /* argv */ + lda $17, 8($sp) /* argv / a1 */ - addq $16, 1, $18 /* argp */ + addq $16, 1, $18 /* argp / a2 */ s8addq $18, $17, $18 /* (8*(argc+1))+argv -> argp */ stq $18, environ - mov $0, $21 /* mov v0(dynload) to a5 */ - +#ifdef WANT_DYNAMIC +/* in v0 ($0) is the ld.so _fini pointer */ + mov $0, $19 /* mov v0(dynload) to a3 */ + jsr $26, dyn_start +#else jsr $26, main +#endif mov $0, $16 jsr $26, exit /* YES, CALL! for threads and atexit ! (+4 byte) */ - -#endif diff --git a/mdk-stage1/dietlibc/alpha/syscalls.h b/mdk-stage1/dietlibc/alpha/syscalls.h new file mode 100644 index 000000000..5c654b4bf --- /dev/null +++ b/mdk-stage1/dietlibc/alpha/syscalls.h @@ -0,0 +1,371 @@ + +#define __NR_osf_syscall 0 /* not implemented */ +#define __NR_exit 1 +#define __NR_fork 2 +#define __NR_read 3 +#define __NR_write 4 +#define __NR_osf_old_open 5 /* not implemented */ +#define __NR_close 6 +#define __NR_osf_wait4 7 +#define __NR_osf_old_creat 8 /* not implemented */ +#define __NR_link 9 +#define __NR_unlink 10 +#define __NR_osf_execve 11 /* not implemented */ +#define __NR_chdir 12 +#define __NR_fchdir 13 +#define __NR_mknod 14 +#define __NR_chmod 15 +#define __NR_chown 16 +#define __NR_brk 17 +#define __NR_osf_getfsstat 18 /* not implemented */ +#define __NR_lseek 19 +#define __NR_getxpid 20 +#define __NR_osf_mount 21 +#define __NR_umount 22 +#define __NR_setuid 23 +#define __NR_getxuid 24 +#define __NR_exec_with_loader 25 /* not implemented */ +#define __NR_ptrace 26 +#define __NR_osf_nrecvmsg 27 /* not implemented */ +#define __NR_osf_nsendmsg 28 /* not implemented */ +#define __NR_osf_nrecvfrom 29 /* not implemented */ +#define __NR_osf_naccept 30 /* not implemented */ +#define __NR_osf_ngetpeername 31 /* not implemented */ +#define __NR_osf_ngetsockname 32 /* not implemented */ +#define __NR_access 33 +#define __NR_osf_chflags 34 /* not implemented */ +#define __NR_osf_fchflags 35 /* not implemented */ +#define __NR_sync 36 +#define __NR_kill 37 +#define __NR_osf_old_stat 38 /* not implemented */ +#define __NR_setpgid 39 +#define __NR_osf_old_lstat 40 /* not implemented */ +#define __NR_dup 41 +#define __NR_pipe 42 +#define __NR_osf_set_program_attributes 43 +#define __NR_osf_profil 44 /* not implemented */ +#define __NR_open 45 +#define __NR_osf_old_sigaction 46 /* not implemented */ +#define __NR_getxgid 47 +#define __NR_osf_sigprocmask 48 +#define __NR_osf_getlogin 49 /* not implemented */ +#define __NR_osf_setlogin 50 /* not implemented */ +#define __NR_acct 51 +#define __NR_sigpending 52 + +#define __NR_ioctl 54 +#define __NR_osf_reboot 55 /* not implemented */ +#define __NR_osf_revoke 56 /* not implemented */ +#define __NR_symlink 57 +#define __NR_readlink 58 +#define __NR_execve 59 +#define __NR_umask 60 +#define __NR_chroot 61 +#define __NR_osf_old_fstat 62 /* not implemented */ +#define __NR_getpgrp 63 +#define __NR_getpagesize 64 +#define __NR_osf_mremap 65 /* not implemented */ +#define __NR_vfork 66 +#define __NR_stat 67 +#define __NR_lstat 68 +#define __NR_osf_sbrk 69 /* not implemented */ +#define __NR_osf_sstk 70 /* not implemented */ +#define __NR_mmap 71 /* OSF/1 mmap is superset of Linux */ +#define __NR_osf_old_vadvise 72 /* not implemented */ +#define __NR_munmap 73 +#define __NR_mprotect 74 +#define __NR_madvise 75 +#define __NR_vhangup 76 +#define __NR_osf_kmodcall 77 /* not implemented */ +#define __NR_osf_mincore 78 /* not implemented */ +#define __NR_getgroups 79 +#define __NR_setgroups 80 +#define __NR_osf_old_getpgrp 81 /* not implemented */ +#define __NR_setpgrp 82 /* BSD alias for setpgid */ +#define __NR_osf_setitimer 83 +#define __NR_osf_old_wait 84 /* not implemented */ +#define __NR_osf_table 85 /* not implemented */ +#define __NR_osf_getitimer 86 +#define __NR_gethostname 87 +#define __NR_sethostname 88 +#define __NR_getdtablesize 89 +#define __NR_dup2 90 +#define __NR_fstat 91 +#define __NR_fcntl 92 +#define __NR_osf_select 93 +#define __NR_poll 94 +#define __NR_fsync 95 +#define __NR_setpriority 96 +#define __NR_socket 97 +#define __NR_connect 98 +#define __NR_accept 99 +#define __NR_getpriority 100 +#define __NR_send 101 +#define __NR_recv 102 +#define __NR_sigreturn 103 +#define __NR_bind 104 +#define __NR_setsockopt 105 +#define __NR_listen 106 +#define __NR_osf_plock 107 /* not implemented */ +#define __NR_osf_old_sigvec 108 /* not implemented */ +#define __NR_osf_old_sigblock 109 /* not implemented */ +#define __NR_osf_old_sigsetmask 110 /* not implemented */ +#define __NR_sigsuspend 111 +#define __NR_osf_sigstack 112 +#define __NR_recvmsg 113 +#define __NR_sendmsg 114 +#define __NR_osf_old_vtrace 115 /* not implemented */ +#define __NR_osf_gettimeofday 116 +#define __NR_osf_getrusage 117 +#define __NR_getsockopt 118 + +#define __NR_readv 120 +#define __NR_writev 121 +#define __NR_osf_settimeofday 122 +#define __NR_fchown 123 +#define __NR_fchmod 124 +#define __NR_recvfrom 125 +#define __NR_setreuid 126 +#define __NR_setregid 127 +#define __NR_rename 128 +#define __NR_truncate 129 +#define __NR_ftruncate 130 +#define __NR_flock 131 +#define __NR_setgid 132 +#define __NR_sendto 133 +#define __NR_shutdown 134 +#define __NR_socketpair 135 +#define __NR_mkdir 136 +#define __NR_rmdir 137 +#define __NR_osf_utimes 138 +#define __NR_osf_old_sigreturn 139 /* not implemented */ +#define __NR_osf_adjtime 140 /* not implemented */ +#define __NR_getpeername 141 +#define __NR_osf_gethostid 142 /* not implemented */ +#define __NR_osf_sethostid 143 /* not implemented */ +#define __NR_getrlimit 144 +#define __NR_setrlimit 145 +#define __NR_osf_old_killpg 146 /* not implemented */ +#define __NR_setsid 147 +#define __NR_quotactl 148 +#define __NR_osf_oldquota 149 /* not implemented */ +#define __NR_getsockname 150 + +#define __NR_osf_pid_block 153 /* not implemented */ +#define __NR_osf_pid_unblock 154 /* not implemented */ + +#define __NR_sigaction 156 +#define __NR_osf_sigwaitprim 157 /* not implemented */ +#define __NR_osf_nfssvc 158 /* not implemented */ +#define __NR_osf_getdirentries 159 +#define __NR_osf_statfs 160 +#define __NR_osf_fstatfs 161 + +#define __NR_osf_asynch_daemon 163 /* not implemented */ +#define __NR_osf_getfh 164 /* not implemented */ +#define __NR_osf_getdomainname 165 +#define __NR_setdomainname 166 + +#define __NR_osf_exportfs 169 /* not implemented */ + +#define __NR_osf_alt_plock 181 /* not implemented */ + +#define __NR_osf_getmnt 184 /* not implemented */ + +#define __NR_osf_alt_sigpending 187 /* not implemented */ +#define __NR_osf_alt_setsid 188 /* not implemented */ + +#define __NR_osf_swapon 199 +#define __NR_msgctl 200 +#define __NR_msgget 201 +#define __NR_msgrcv 202 +#define __NR_msgsnd 203 +#define __NR_semctl 204 +#define __NR_semget 205 +#define __NR_semop 206 +#define __NR_osf_utsname 207 +#define __NR_lchown 208 +#define __NR_osf_shmat 209 +#define __NR_shmctl 210 +#define __NR_shmdt 211 +#define __NR_shmget 212 +#define __NR_osf_mvalid 213 /* not implemented */ +#define __NR_osf_getaddressconf 214 /* not implemented */ +#define __NR_osf_msleep 215 /* not implemented */ +#define __NR_osf_mwakeup 216 /* not implemented */ +#define __NR_msync 217 +#define __NR_osf_signal 218 /* not implemented */ +#define __NR_osf_utc_gettime 219 /* not implemented */ +#define __NR_osf_utc_adjtime 220 /* not implemented */ + +#define __NR_osf_security 222 /* not implemented */ +#define __NR_osf_kloadcall 223 /* not implemented */ + +#define __NR_getpgid 233 +#define __NR_getsid 234 +#define __NR_sigaltstack 235 +#define __NR_osf_waitid 236 /* not implemented */ +#define __NR_osf_priocntlset 237 /* not implemented */ +#define __NR_osf_sigsendset 238 /* not implemented */ +#define __NR_osf_set_speculative 239 /* not implemented */ +#define __NR_osf_msfs_syscall 240 /* not implemented */ +#define __NR_osf_sysinfo 241 +#define __NR_osf_uadmin 242 /* not implemented */ +#define __NR_osf_fuser 243 /* not implemented */ +#define __NR_osf_proplist_syscall 244 +#define __NR_osf_ntp_adjtime 245 /* not implemented */ +#define __NR_osf_ntp_gettime 246 /* not implemented */ +#define __NR_osf_pathconf 247 /* not implemented */ +#define __NR_osf_fpathconf 248 /* not implemented */ + +#define __NR_osf_uswitch 250 /* not implemented */ +#define __NR_osf_usleep_thread 251 +#define __NR_osf_audcntl 252 /* not implemented */ +#define __NR_osf_audgen 253 /* not implemented */ +#define __NR_sysfs 254 +#define __NR_osf_subsys_info 255 /* not implemented */ +#define __NR_osf_getsysinfo 256 +#define __NR_osf_setsysinfo 257 +#define __NR_osf_afs_syscall 258 /* not implemented */ +#define __NR_osf_swapctl 259 /* not implemented */ +#define __NR_osf_memcntl 260 /* not implemented */ +#define __NR_osf_fdatasync 261 /* not implemented */ + + +/* + * Linux-specific system calls begin at 300 + */ +#define __NR_bdflush 300 +#define __NR_sethae 301 +#define __NR_mount 302 +#define __NR_old_adjtimex 303 +#define __NR_swapoff 304 +#define __NR_getdents 305 +#define __NR_create_module 306 +#define __NR_init_module 307 +#define __NR_delete_module 308 +#define __NR_get_kernel_syms 309 +#define __NR_syslog 310 +#define __NR_reboot 311 +#define __NR_clone 312 +#define __NR_uselib 313 +#define __NR_mlock 314 +#define __NR_munlock 315 +#define __NR_mlockall 316 +#define __NR_munlockall 317 +#define __NR_sysinfo 318 +#define __NR__sysctl 319 +/* 320 was sys_idle. */ +#define __NR_oldumount 321 +#define __NR_swapon 322 +#define __NR_times 323 +#define __NR_personality 324 +#define __NR_setfsuid 325 +#define __NR_setfsgid 326 +#define __NR_ustat 327 +#define __NR_statfs 328 +#define __NR_fstatfs 329 +#define __NR_sched_setparam 330 +#define __NR_sched_getparam 331 +#define __NR_sched_setscheduler 332 +#define __NR_sched_getscheduler 333 +#define __NR_sched_yield 334 +#define __NR_sched_get_priority_max 335 +#define __NR_sched_get_priority_min 336 +#define __NR_sched_rr_get_interval 337 +#define __NR_afs_syscall 338 +#define __NR_uname 339 +#define __NR_nanosleep 340 +#define __NR_mremap 341 +#define __NR_nfsservctl 342 +#define __NR_setresuid 343 +#define __NR_getresuid 344 +#define __NR_pciconfig_read 345 +#define __NR_pciconfig_write 346 +#define __NR_query_module 347 +#define __NR_prctl 348 +#define __NR_pread 349 +#define __NR_pwrite 350 +#define __NR_rt_sigreturn 351 +#define __NR_rt_sigaction 352 +#define __NR_rt_sigprocmask 353 +#define __NR_rt_sigpending 354 +#define __NR_rt_sigtimedwait 355 +#define __NR_rt_sigqueueinfo 356 +#define __NR_rt_sigsuspend 357 +#define __NR_select 358 +#define __NR_gettimeofday 359 +#define __NR_settimeofday 360 +#define __NR_getitimer 361 +#define __NR_setitimer 362 +#define __NR_utimes 363 +#define __NR_getrusage 364 +#define __NR_wait4 365 +#define __NR_adjtimex 366 +#define __NR_getcwd 367 +#define __NR_capget 368 +#define __NR_capset 369 +#define __NR_sendfile 370 +#define __NR_setresgid 371 +#define __NR_getresgid 372 +#define __NR_dipc 373 +#define __NR_pivot_root 374 +#define __NR_mincore 375 +#define __NR_pciconfig_iobase 376 +#define __NR_getdents64 377 +#define __NR_gettid 378 +#define __NR_readahead 379 +#define __NR_security 380 /* syscall for security modules */ +#define __NR_tkill 381 +#define __NR_setxattr 382 +#define __NR_lsetxattr 383 +#define __NR_fsetxattr 384 +#define __NR_getxattr 385 +#define __NR_lgetxattr 386 +#define __NR_fgetxattr 387 +#define __NR_listxattr 388 +#define __NR_llistxattr 389 +#define __NR_flistxattr 390 +#define __NR_removexattr 391 +#define __NR_lremovexattr 392 +#define __NR_fremovexattr 393 +#define __NR_futex 394 +#define __NR_sched_setaffinity 395 +#define __NR_sched_getaffinity 396 +#define __NR_tuxcall 397 +#define __NR_io_setup 398 +#define __NR_io_destroy 399 +#define __NR_io_getevents 400 +#define __NR_io_submit 401 +#define __NR_io_cancel 402 +#define __NR_alloc_hugepages 403 +#define __NR_free_hugepages 404 +#define __NR_exit_group 405 +#define __NR_lookup_dcookie 406 +#define __NR_sys_epoll_create 407 +#define __NR_sys_epoll_ctl 408 +#define __NR_sys_epoll_wait 409 +#define __NR_remap_file_pages 410 +#define __NR_set_tid_address 411 + +#define syscall_weak(name,wsym,sym) \ +.text ; \ +.align 2 ; \ +.weak wsym; \ +.type wsym,@function ; \ +wsym: ; \ +.global sym ; \ +.type sym,@function ; \ +sym: ; \ + lda $0, __NR_##name($31) ; \ + br __unified_syscall + +#define syscall(name,sym) \ +.text ; \ +.align 2 ; \ +.global sym ; \ +.type sym,@function ; \ +sym: ; \ + lda $0, __NR_##name($31) ; \ + br __unified_syscall + diff --git a/mdk-stage1/dietlibc/alpha/unified.S b/mdk-stage1/dietlibc/alpha/unified.S index 02a1c9bcd..506bf7387 100644 --- a/mdk-stage1/dietlibc/alpha/unified.S +++ b/mdk-stage1/dietlibc/alpha/unified.S @@ -1,15 +1,25 @@ #include +#include "syscalls.h" +.weak exit +exit: +.global _exit +_exit: + lda $0, __NR_exit .global __unified_syscall __unified_syscall: callsys bne $19, .Lerror + +/* here we go and "reuse" the return for weak-void functions */ +#include "dietuglyweaks.h" + ret $31, ($26), 0x01 .Lerror: .global error_unified_syscall error_unified_syscall: -#ifdef WANT_THREAD_SAVE +#ifdef WANT_THREAD_SAFE lda $sp, -16($sp) /* alloc 2 qwords on stack */ stq $26, 0($sp) /* save ra to stack */ stq $0, 8($sp) /* save v0 to stack */ diff --git a/mdk-stage1/dietlibc/binshstr.h b/mdk-stage1/dietlibc/binshstr.h new file mode 100644 index 000000000..f1bf789fe --- /dev/null +++ b/mdk-stage1/dietlibc/binshstr.h @@ -0,0 +1,6 @@ + +extern const char __binsh [8]; + +#define __sh (__binsh + 5 ) + +/* end of binshstr.h */ diff --git a/mdk-stage1/dietlibc/diet.1 b/mdk-stage1/dietlibc/diet.1 new file mode 100644 index 000000000..c28aeba40 --- /dev/null +++ b/mdk-stage1/dietlibc/diet.1 @@ -0,0 +1,31 @@ +.TH diet 1 "April 2001" +.SH NAME +.PP +diet \- mangle gcc command line arguments +.SH SYNOPSIS +.PP +.B diet [-v] [-Os] +[\fInormal gcc command line\fP] +.SH DESCRIPTION +.PP +diet is a small wrapper around gcc. It will try to look at the command +line you specify and try to mangle it so that gcc will compile against +the diet libc header files and link against the diet libc itself. + +diet tries to be smart for cross compiling. If the first argument is +not gcc but sparc-linux-gcc, diet will guess that you want to cross +compile for sparc and use bin-sparc/dietlibc.a instead of the dietlibc.a +for your default architecture. + +The -v option will make diet print the modified gcc command line before +executing it. + +When passed the -Os option before the gcc argument, diet will mangle the +gcc options to include the best known for-size optimization settings for +the platform. +.SH FILES +~/.diet/\fIcompiler\fR may contain compiler options as you would +specify them on the command line, i.e. separated by spaces. Those will +then be used instead of the built-in defaults for diet -Os. +.SH AUTHOR +Felix von Leitner diff --git a/mdk-stage1/dietlibc/diet.c b/mdk-stage1/dietlibc/diet.c index 1de6befc8..86b21a1e1 100644 --- a/mdk-stage1/dietlibc/diet.c +++ b/mdk-stage1/dietlibc/diet.c @@ -1,7 +1,11 @@ #include #include +#include #include #include +#include + +#include "dietfeatures.h" /* goal: * when invoked as @@ -15,90 +19,337 @@ * "sparc-linux-gcc -nostdlib -static -o t t.o /path/to/dietlibc/bin-sparc/start.o /path/to/dietlibc/bin-sparc/dietlibc.a" */ -void error(const char *message) { - write(2,message,strlen(message)); +static void error(const char *message) { + __write2(message); exit(1); } +static const char* Os[] = { + "i386","-Os","-mpreferred-stack-boundary=2", + "-malign-functions=0","-malign-jumps=0", + "-malign-loops=0","-fomit-frame-pointer",0, + "x86_64","-Os","-fno-omit-frame-pointer",0, + "sparc","-Os","-mcpu=supersparc",0, + "sparc64","-Os","-m64",0, + "alpha","-Os","-fomit-frame-pointer",0, + "arm","-Os","-fomit-frame-pointer",0, + "mips","-Os","-fomit-frame-pointer","-mno-abicalls","-G","8","-fno-pic",0, + "ppc","-Os","-fomit-frame-pointer","-mpowerpc-gpopt","-mpowerpc-gfxopt",0, + "s390","-Os","-fomit-frame-pointer",0, + "sh","-Os","-fomit-frame-pointer",0, + "ia64","-Os","-fno-omit-frame-pointer",0, + "x86_64","-Os","-fstrict-aliasing","-momit-leaf-frame-pointer","-mfance-math-387",0, + 0}; + int main(int argc,char *argv[]) { - int link=0; + int _link=0; int compile=0; + int preprocess=0; + int verbose=0; + int profile=0; char diethome[]=DIETHOME; - char platform[1000]=DIETHOME "/bin-"; - char *nostdlib="-nostdlib"; - char *libgcc="-lgcc"; - char dashL[1000]="-L"; + char platform[1000]; +#ifdef __DYN_LIB + int shared=0; +#endif + char* shortplatform=0; +#ifdef WANT_SAFEGUARD + char safeguard1[]="-include"; + char safeguard2[]=DIETHOME "/include/dietref.h"; +#endif + const char *nostdlib="-nostdlib"; + const char *libgcc="-lgcc"; + char dashL[1000]; + char dashstatic[]="-static"; int i; + int mangleopts=0; + char manglebuf[1024]; + +#ifdef INSTALLVERSION + strcpy(platform,DIETHOME "/lib-"); +#else +#ifndef __DYN_LIB + strcpy(platform,DIETHOME "/bin-"); +#else + strcpy(platform,DIETHOME "/pic-"); +#endif +#endif + strcpy(dashL,"-L"); if (argc<2) { - error("usage: diet [gcc command line]\n" - "e.g. diet gcc -c t.c\n" +usage: + if (verbose) { + __write2( +#ifdef __DYN_LIB + "dyn-" +#endif + "diet version " VERSION +#ifndef INSTALLVERSION + " (non-install version in source tree)" +#endif + "\n\n"); + } + error("usage: diet [-v] [-Os] gcc command line\n" + "e.g. diet -Os gcc -c t.c\n" "or diet sparc-linux-gcc -o foo foo.c bar.o\n"); } + if (!strcmp(argv[1],"-v")) { + ++argv; --argc; + verbose=1; + } + if (argv[1] && !strcmp(argv[1],"-Os")) { + ++argv; --argc; + mangleopts=1; + } + if (!argv[1]) goto usage; { char *tmp=strchr(argv[1],0)-2; - char *tmp2; + char *tmp2,*tmp3; char *cc=argv[1]; if (tmp90) error("platform name too long!\n"); - memmove(platform+len,argv[1],tmp2-cc); + shortplatform=platform+len; + memmove(shortplatform,argv[1],(size_t)(tmp2-cc)); platform[tmp2-cc+len]=0; -/* printf("found platform %s\n",platform); */ + if (shortplatform[0]=='i' && shortplatform[2]=='8' && shortplatform[3]=='6') shortplatform[1]='3'; } else { #ifdef __sparc__ - strcat(platform,"sparc"); +#ifdef __arch64__ + shortplatform="sparc64"; +#else + shortplatform="sparc"; #endif -#ifdef __ppc__ - strcat(platform,"ppc"); +#endif +#ifdef __powerpc__ + shortplatform="ppc"; #endif #ifdef __i386__ - strcat(platform,"i386"); + shortplatform="i386"; #endif #ifdef __alpha__ - strcat(platform,"alpha"); + shortplatform="alpha"; #endif #ifdef __arm__ - strcat(platform,"arm"); + shortplatform="arm"; #endif #ifdef __mips__ - strcat(platform,"mips"); + shortplatform="mips"; +#endif +#ifdef __s390__ + shortplatform="s390"; +#endif +#ifdef __sh__ + shortplatform="sh"; +#endif +#ifdef __hppa__ + shortplatform="parisc"; +#endif +#ifdef __x86_64__ + shortplatform="x86_64"; +#endif +#ifdef __ia64__ + shortplatform="ia64"; #endif + { + char *tmp=platform+strlen(platform); + strcpy(tmp,shortplatform); + shortplatform=tmp; + } + } + /* MIPS needs special handling. If argv contains -EL, change + * platform name to mipsel */ + if (!strcmp(shortplatform,"mips")) { + int i; + for (i=1; i=0) { + int len=read(fd,manglebuf,1023); + if (len>0) { + int i; + manglebuf[len]=0; + *dest++=manglebuf; + for (i=1; i + struct __dirstream { int fd; - char buf[1024]; + char buf[PAGE_SIZE-(sizeof (int)*3)]; unsigned int num; unsigned int cur; }; /* stream data from opendir() */ diff --git a/mdk-stage1/dietlibc/dietdns.h b/mdk-stage1/dietlibc/dietdns.h new file mode 100644 index 000000000..c4c1c5f72 --- /dev/null +++ b/mdk-stage1/dietlibc/dietdns.h @@ -0,0 +1,4 @@ + +int __dns_gethostbyx_r(const char* name, struct hostent* result, + char *buf, size_t buflen, + struct hostent **RESULT, int *h_errnop, int lookfor); diff --git a/mdk-stage1/dietlibc/dietfeatures.h b/mdk-stage1/dietlibc/dietfeatures.h index e1de38577..1692de348 100644 --- a/mdk-stage1/dietlibc/dietfeatures.h +++ b/mdk-stage1/dietlibc/dietfeatures.h @@ -3,40 +3,106 @@ /* feel free to comment some of these out to reduce code size */ -//#define WANT_FLOATING_POINT_IN_PRINTF -//#define WANT_FLOATING_POINT_IN_SCANF +#define WANT_FLOATING_POINT_IN_PRINTF +#define WANT_FLOATING_POINT_IN_SCANF #define WANT_CHARACTER_CLASSES_IN_SCANF #define WANT_NULL_PRINTF +#define WANT_LONGLONG_PRINTF +#define WANT_LONGLONG_SCANF -#define SLASH_PROC_OK +/* 128 or 2048 bytes buffer size? */ +/* #define WANT_SMALL_STDIO_BUFS */ + +/* want fread to read() directly if size of data is larger than buffer? + * This costs a few bytes but is worth it if the application is already + * buffering. */ +#define WANT_FREAD_OPTIMIZATION -// #define WANT_BUFFERED_STDIO +/* this is only for meaningful for ttyname and sysconf_cpus so far */ +#define SLASH_PROC_OK /* use errno_location instead of errno */ -// #define WANT_THREAD_SAFE +#define WANT_THREAD_SAFE -/* make the startcode, etc. dynamic aware */ -/* #undef WANT_DYNAMIC */ +/* make the startcode, etc. dynamic aware ({con,de}structors) */ +/* #define WANT_DYNAMIC */ /* do you want smaller or faster string routines? */ /* #define WANT_FASTER_STRING_ROUTINES */ -/* do you want ungetc? makes fgetc more complex */ -#define WANT_UNGETC +/* define this to have strncpy zero-fill and not just zero-terminate the + * string */ +/* #define WANT_FULL_POSIX_COMPAT */ -// #define WANT_LINKER_WARNINGS +/* read the comment in lib/strncat.c for an explanation */ +/* #define WANT_NON_COMPLIANT_STRNCAT */ + +#undef WANT_LINKER_WARNINGS /* you need to define this if you want to run your programs with large - * file support on kernel 2.2 or 2.4 */ -// #define WANT_LARGEFILE_BACKCOMPAT + * file support on kernel 2.2 or 2.0 */ +#undef WANT_LARGEFILE_BACKCOMPAT /* do you want localtime(3) to read /etc/localtime? * Needed for daylight saving time etc. */ -// #define WANT_TZFILE_PARSER +#define WANT_TZFILE_PARSER + +/* do you want the DNS routines to parse and use "domain" and "search" + * lines from /etc/resolv.conf? Normally not used on boot floppies and + * embedded environments. */ +#define WANT_FULL_RESOLV_CONF + +/* do you want IPv6 transport support in the DNS resolver? */ +#undef WANT_IPV6_DNS + +/* do you want gethostbyname and friends to consult /etc/hosts? */ +#define WANT_ETC_HOSTS + +/* do you want gethostbyname to understand dotted decimal IP numbers + * directly and not try to resolve them? */ +#define WANT_INET_ADDR_DNS + +/* do you want math functions high precision rather than fast/small? */ +#undef WANT_HIGH_PRECISION_MATH + +/* do you want support for matherr? */ +#define WANT_MATHERR + +/* do you want crypt(3) to use MD5 if the salt starts with "$1$"? */ +#define WANT_CRYPT_MD5 + +/* do you want diet to include a safeguard dependency to make linking + * against glibc fail? This may fail with older binutils. */ +#undef WANT_SAFEGUARD + +/* dy you want that malloc(0) return a pointer to a "zero-length" object + * that is realloc-able; means realloc(..,size) gives a NEW object (like a + * call to malloc(size)). + * WARNING: this violates C99 */ +/* #define WANT_MALLOC_ZERO */ + /* stop uncommenting here ;-) */ #ifndef WANT_FASTER_STRING_ROUTINES #define WANT_SMALL_STRING_ROUTINES #endif +#ifdef WANT_THREAD_SAFE +#ifndef __ASSEMBLER__ +#define errno (*__errno_location()) +#define _REENTRANT +#endif +#endif + +#ifdef __DYN_LIB +/* with shared libraries you MUST have a dynamic aware startcode */ +#ifndef WANT_DYNAMIC +#define WANT_DYNAMIC +#endif +/* saveguard crashes with shared objects ... */ +#ifdef WANT_SAFEGUARD +#undef WANT_SAFEGUARD +#endif +#endif + #endif diff --git a/mdk-stage1/dietlibc/dieticonv.h b/mdk-stage1/dietlibc/dieticonv.h new file mode 100644 index 000000000..540ef2f6f --- /dev/null +++ b/mdk-stage1/dietlibc/dieticonv.h @@ -0,0 +1,12 @@ +enum charset { + INVALID=0, + ISO_8859_1, + UTF_8, + UCS_2, + UCS_4 +}; + +#define ic_from(x) (((x) )&0xffff) +#define ic_to(x) (((x)>>16)&0xffff) + +#include diff --git a/mdk-stage1/dietlibc/dietlibm.h b/mdk-stage1/dietlibc/dietlibm.h new file mode 100644 index 000000000..fe735e40d --- /dev/null +++ b/mdk-stage1/dietlibc/dietlibm.h @@ -0,0 +1,5 @@ +#include + +double __poly(double x, size_t n, const double* c); +double exp2(double x); +double log2(double x); diff --git a/mdk-stage1/dietlibc/dietstdarg.h b/mdk-stage1/dietlibc/dietstdarg.h deleted file mode 100644 index 827671b22..000000000 --- a/mdk-stage1/dietlibc/dietstdarg.h +++ /dev/null @@ -1,12 +0,0 @@ -#include - -/* this assumes that va_copy() will be a macro, it is on gcc */ -#ifndef va_copy -# ifdef __va_copy -# define va_copy(x, y) __va_copy(x, y) -# else -/* assume copying it works... */ -# define va_copy(x, y) x = y -# endif -#endif - diff --git a/mdk-stage1/dietlibc/dietstdio.h b/mdk-stage1/dietlibc/dietstdio.h index a1cbeba83..6eba480c4 100644 --- a/mdk-stage1/dietlibc/dietstdio.h +++ b/mdk-stage1/dietlibc/dietstdio.h @@ -1,81 +1,76 @@ -/* diet stdio -- no buffering ;-} */ +/* diet stdio */ -#include "dietfeatures.h" +#include #include -#ifdef WANT_THREAD_SAVE +#include "dietfeatures.h" +#ifdef WANT_THREAD_SAFE #include #endif +#include +#ifdef WANT_SMALL_STDIO_BUFS #define BUFSIZE 128 +#else +#define BUFSIZE 2048 +#endif -typedef struct __file { +struct __stdio_file { int fd; int flags; -#ifdef WANT_BUFFERED_STDIO unsigned int bs; /* read: bytes in buffer */ unsigned int bm; /* position in buffer */ - char buf[BUFSIZE]; - struct __file *next; /* for fflush */ -#endif + unsigned int buflen; /* length of buf */ + char *buf; + struct __stdio_file *next; /* for fflush */ pid_t popen_kludge; -#ifdef WANT_UNGETC - char ungetbuf; + unsigned char ungetbuf; char ungotten; -#endif -#ifdef WANT_THREAD_SAVE +#ifdef WANT_THREAD_SAFE pthread_mutex_t m; #endif -} FILE; - -extern FILE *__stdio_root; +}; #define ERRORINDICATOR 1 #define EOFINDICATOR 2 #define BUFINPUT 4 #define BUFLINEWISE 8 #define NOBUF 16 -#define UNSEEKABLE 32 +#define STATICBUF 32 #define _IONBF 0 #define _IOLBF 1 #define _IOFBF 2 +#include + /* internal function to flush buffer. * However, if next is BUFINPUT and the buffer is an input buffer, it * will not be flushed. Vice versa for output */ extern int __fflush4(FILE *stream,int next); +extern int __buffered_outs(const char *s,size_t len); -FILE *fopen (const char *path, const char *mode); -FILE *fdopen (int fildes, const char *mode); -FILE *freopen (const char *path, const char *mode, FILE *stream); - -int fgetc(FILE *stream); -char *fgets(char *s, int size, FILE *stream); -int getc(FILE *stream); -int getchar(void); -char *gets(char *s); -int ungetc(int c, FILE *stream); +/* ..scanf */ +struct arg_scanf { + void *data; + int (*getch)(void*); + int (*putch)(int,void*); +}; -int fputc(int c, FILE *stream); -int fputs(const char *s, FILE *stream); -int putc(int c, FILE *stream); -int putchar(int c); -int puts(const char *s); +int __v_scanf(struct arg_scanf* fn, const unsigned char *format, va_list arg_ptr); -long fseek( FILE *stream, long offset, int whence); -long ftell( FILE *stream); -void rewind( FILE *stream); -int fgetpos( FILE *stream, fpos_t *pos); -int fsetpos( FILE *stream, fpos_t *pos); +struct arg_printf { + void *data; + int (*put)(void*,size_t,void*); +}; -size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream); +int __v_printf(struct arg_printf* fn, const unsigned char *format, va_list arg_ptr); -size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream); - -int fflush(FILE *stream); - -int fclose(FILE *stream); +extern FILE *__stdio_root; -extern FILE *stdout, *stderr, *stdin; +int __fflush_stdin(void); +int __fflush_stdout(void); +int __fflush_stderr(void); -#define EOF (int)(-1) +FILE* __stdio_init_file(int fd,int closeonerror); +int __stdio_parse_mode(const char *mode); +void __stdio_flushall(void); diff --git a/mdk-stage1/dietlibc/dietuglyweaks.h b/mdk-stage1/dietlibc/dietuglyweaks.h new file mode 100644 index 000000000..4b2aa231a --- /dev/null +++ b/mdk-stage1/dietlibc/dietuglyweaks.h @@ -0,0 +1,24 @@ +#ifndef __DIET_UGLY_WEAKS__ +#define __DIET_UGLY_WEAKS__ + +/* if you change something here ... KNOW what you're doing ! + * it'll effect ALL platforms ! */ + +.weak __thread_doexit +__thread_doexit: +.weak __fflush_stdin +__fflush_stdin: +.weak __fflush_stdout +__fflush_stdout: +.weak __fflush_stderr +__fflush_stderr: +.weak flockfile +flockfile: +.weak funlockfile +funlockfile: +.weak __nop +__nop: +.global __you_tried_to_link_a_dietlibc_object_against_glibc +__you_tried_to_link_a_dietlibc_object_against_glibc: + +#endif diff --git a/mdk-stage1/dietlibc/dirstream.h b/mdk-stage1/dietlibc/dirstream.h deleted file mode 100644 index dc8fba79c..000000000 --- a/mdk-stage1/dietlibc/dirstream.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -/* - * POSIX Standard: 5.1.2 Directory Operations - */ - -#ifndef _DIRSTREAM_H - -#define _DIRSTREAM_H 1 - -#include -#include -#ifdef _POSIX_THREADS -#include -#endif - -/* For now, syscall readdir () only supports one entry at a time. It - * will be changed in the future. -#define NUMENT 3 -*/ -#ifndef NUMENT -#define NUMENT 1 -#endif - -#define SINGLE_READDIR 11 -#define MULTI_READDIR 12 -#define NEW_READDIR 13 - -/* Directory stream type. */ -struct __dirstream { - /* file descriptor */ - int dd_fd; - - /* offset of the next dir entry in buffer */ - off_t dd_nextloc; - - /* bytes of valid entries in buffer */ - size_t dd_size; - - /* -> directory buffer */ - struct dirent *dd_buf; - - /* we have to convert */ - struct dirent convbuf; - - /* offset of the next dir entry in directory. */ - off_t dd_nextoff; - - /* total size of buffer */ - size_t dd_max; - - enum {unknown, have_getdents, no_getdents} dd_getdents; - - /* lock */ -#ifdef _POSIX_THREADS - pthread_mutex_t *dd_lock; -#else - void *dd_lock; -#endif -}; /* stream data from opendir() */ - -#endif /* dirent.h */ diff --git a/mdk-stage1/dietlibc/dyn_start.c b/mdk-stage1/dietlibc/dyn_start.c new file mode 100644 index 000000000..391797e12 --- /dev/null +++ b/mdk-stage1/dietlibc/dyn_start.c @@ -0,0 +1,40 @@ +#include "dietfeatures.h" + +#ifdef WANT_DYNAMIC +#include + +typedef void(*structor)(void); + +__attribute__((section(".ctors"))) +static structor __CTOR_LIST__[1]={((structor)-1)}; + +__attribute__((section(".dtors"))) +static structor __DTOR_LIST__[1]={((structor)-1)}; + +static void __do_global_dtors_aux(void) +{ + structor *df=__CTOR_LIST__; /* ugly trick to prevent warning */ + for (df=((__DTOR_LIST__)+1);(*df) != (structor)0; df++) (*df)(); +} + +void _fini(void) __attribute__((section(".fini"))); +__attribute__((section(".fini"))) void _fini(void) +{ + __do_global_dtors_aux(); +} + +#ifndef __DYN_LIB_SHARED +/* pre main, post _start */ +int _dyn_start(int argc, char **argv, char **envp, structor dl_init); +int _dyn_start(int argc, char **argv, char **envp, structor dl_init) +{ + static __attribute__((section(".init"))) void _init(void); + int main(int argc, char **argv, char **envp); + + if (dl_init) atexit(dl_init); + _init(); + atexit(_fini); + return main(argc, argv, envp); +} +#endif +#endif diff --git a/mdk-stage1/dietlibc/dyn_stop.c b/mdk-stage1/dietlibc/dyn_stop.c new file mode 100644 index 000000000..7213a8089 --- /dev/null +++ b/mdk-stage1/dietlibc/dyn_stop.c @@ -0,0 +1,23 @@ +#include "dietfeatures.h" + +#ifdef WANT_DYNAMIC +typedef void(*structor)(void); + +__attribute__((section(".ctors"))) +static structor __CTOR_END__[1]={((structor)0)}; + +__attribute__((section(".dtors"))) +static structor __DTOR_END__[1]={((structor)0)}; + +static void __do_global_ctors_aux(void) +{ + structor *cf=__DTOR_END__; /* ugly trick to prevent warning */ + for(cf=((__CTOR_END__)-1); (*cf) != (structor)-1; cf--) (*cf)(); +} + +void _init() __attribute__((section(".init"))); +__attribute__((section(".init"))) void _init() +{ + __do_global_ctors_aux(); +} +#endif diff --git a/mdk-stage1/dietlibc/findcflags.sh b/mdk-stage1/dietlibc/findcflags.sh new file mode 100755 index 000000000..8b8b3d74a --- /dev/null +++ b/mdk-stage1/dietlibc/findcflags.sh @@ -0,0 +1,8 @@ +#!/bin/sh +version=`${1:-gcc} -v 2>&1 |sed -n '/gcc version/ {s/gcc version //;p;}'` +case $version in + 2.9*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mpreferred-stack-boundary=2 ;; + 3.0*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mpreferred-stack-boundary=2 ;; + 3*) echo -Os -fomit-frame-pointer -falign-functions=0 -falign-jumps=0 -falign-loops=0 -mpreferred-stack-boundary=2;; + *) echo -O2 -pipe -fomit-frame-pointer ;; +esac diff --git a/mdk-stage1/dietlibc/i386/Makefile.add b/mdk-stage1/dietlibc/i386/Makefile.add index b685cc360..83b18ae29 100644 --- a/mdk-stage1/dietlibc/i386/Makefile.add +++ b/mdk-stage1/dietlibc/i386/Makefile.add @@ -1,3 +1,8 @@ -CFLAGS+=-march=i386 -mcpu=i386 -Os -fomit-frame-pointer +M:=$(shell ./findcflags.sh $(CC)) +LIBOBJ+=$(OBJDIR)/__ten.o $(OBJDIR)/md5asm.o $(OBJDIR)/mmap64.o +LIBMATH+=acos.o asin.o atan.o atan2.o ceil.o cos.o exp.o exp10.o exp2.o expm1.o fabs.o floor.o hypot.o log.o log10.o log2.o sin.o sqrt.o tan.o copysign.o sincos.o __half.o ldexp.o pow.o ilogb.o cbrt.o log1p.o sqrtl.o fmod.o libm2.o +#CFLAGS+=-march=i386 -Os -fomit-frame-pointer -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mpreferred-stack-boundary=2 +CFLAGS+=$(M) VPATH:=i386:syscalls.s:$(VPATH) +LIBGMON_OBJS+=$(OBJDIR)/mcount.o diff --git a/mdk-stage1/dietlibc/i386/PIC.h b/mdk-stage1/dietlibc/i386/PIC.h new file mode 100644 index 000000000..45ddeb446 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/PIC.h @@ -0,0 +1,82 @@ +#ifndef __I386_PIC_H__ +#define __I386_PIC_H__ +#ifdef __DYN_LIB + +#if 1 +/* don't trash the athlon return stack */ +.text +.Lgetpic: + mov (%esp),%ebx + ret + +.macro PIC_INIT + call .Lgetpic + addl $_GLOBAL_OFFSET_TABLE_, %ebx +.endm +#else +/* standard code for PIC init */ +.macro PIC_INIT + call 0f +0: popl %ebx + addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ebx +.endm +#endif + +#define PIC_SAVE pushl %ebx +#define PIC_RESTORE popl %ebx + + +/* get memory variable (var) in register (reg) */ +.macro GET_VAR var reg + movl \var@GOT(%ebx), \reg + movl (\reg), \reg +.endm + +/* put register (reg) into memory variable (var) TRASH register (tmp) */ +.macro PUT_VAR reg var tmp + movl \var@GOT(%ebx), \tmp + movl \reg, (\tmp) +.endm + +/* get memory variable (var) in register (reg) + * IF no more PIC-code is needed */ +.macro GET_1VAR var reg + PIC_SAVE + PIC_INIT + GET_VAR \var, \reg + PIC_RESTORE +.endm + +/* put register (reg) into memory variable (var) + * IF no more PIC-code is needed */ +.macro PUT_1VAR reg var + PIC_SAVE + PIC_INIT + PUT_VAR \reg, \var, %ebx + PIC_RESTORE +.endm + +#else + +#define PIC_SAVE +#define PIC_RESTORE +#define PIC_INIT + +.macro GET_VAR var reg + movl \var, \reg +.endm + +.macro PUT_VAR reg var tmp + movl \reg, \var +.endm + +.macro GET_1VAR var reg + GET_VAR \var, \reg +.endm + +.macro PUT_1VAR reg var + PUT_VAR \reg, \var, none +.endm + +#endif +#endif diff --git a/mdk-stage1/dietlibc/i386/__half.S b/mdk-stage1/dietlibc/i386/__half.S new file mode 100644 index 000000000..6355c93e4 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/__half.S @@ -0,0 +1,10 @@ +# +# Definiert Konstante (float)0.5 unter dem Namen __half +# Wird von etlichen Funktionen benutzt (sinh, cosh, atanh) +# + +.global __half +.data +.type __half,@object +.size __half,4 +__half: .long 0x3f000000 diff --git a/mdk-stage1/dietlibc/i386/__longjmp.S b/mdk-stage1/dietlibc/i386/__longjmp.S index 098275037..a09191f0b 100644 --- a/mdk-stage1/dietlibc/i386/__longjmp.S +++ b/mdk-stage1/dietlibc/i386/__longjmp.S @@ -2,6 +2,7 @@ .text .global __longjmp +.type __longjmp,@function __longjmp: movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */ movl 8(%esp), %eax /* Second argument is return value. */ diff --git a/mdk-stage1/dietlibc/i386/__ten.S b/mdk-stage1/dietlibc/i386/__ten.S new file mode 100644 index 000000000..47b9431f4 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/__ten.S @@ -0,0 +1,9 @@ +# +# Definiert Konstante (float)10. unter dem Namen __ten +# + +.global __ten +.data +.type __ten,@object +.size __ten,4 +__ten: .long 0x41200000 diff --git a/mdk-stage1/dietlibc/i386/__testandset.S b/mdk-stage1/dietlibc/i386/__testandset.S index af7b4d5a0..29b02d57a 100644 --- a/mdk-stage1/dietlibc/i386/__testandset.S +++ b/mdk-stage1/dietlibc/i386/__testandset.S @@ -1,5 +1,6 @@ .text .global __testandset +.type __testandset,@function __testandset: xorl %eax, %eax movl 0x4(%esp),%edx diff --git a/mdk-stage1/dietlibc/i386/accept.S b/mdk-stage1/dietlibc/i386/accept.S new file mode 100644 index 000000000..d8be36a54 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/accept.S @@ -0,0 +1,4 @@ +#include +#include + +__socketcall(accept,ACCEPT) diff --git a/mdk-stage1/dietlibc/i386/acos.S b/mdk-stage1/dietlibc/i386/acos.S new file mode 100644 index 000000000..baabf9f04 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/acos.S @@ -0,0 +1,30 @@ + +.text + +.global acosf,acos,acosl # ,__acos + .type acosf,@function + .type acos,@function + .type acosl,@function +# .type __acos,@function +acosf: + flds 4(%esp) + jmp __acos +acosl: + fldt 4(%esp) + jmp __acos +acos: + fldl 4(%esp) +__acos: + fld %st + fmul %st + fld1 + fsubp + fsqrt + fxch %st(1) + fpatan + ret + +.ende: +.size acos,.ende-acos +.size acosf,.ende-acosf +.size acosl,.ende-acosl diff --git a/mdk-stage1/dietlibc/i386/acosh.S b/mdk-stage1/dietlibc/i386/acosh.S new file mode 100644 index 000000000..0611c9d31 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/acosh.S @@ -0,0 +1,18 @@ +.text +.global acosh +.type acosh,@function + +acosh: + fldln2 + fldl 4(%esp) + fld %st(0) + fmul %st(0),%st(0) + fld1 + fsubrp %st(0),%st(1) + fsqrt + faddp %st(0),%st(1) + fyl2x + ret + +.Lende: + .size acosh,.Lende-acosh diff --git a/mdk-stage1/dietlibc/i386/asin.S b/mdk-stage1/dietlibc/i386/asin.S new file mode 100644 index 000000000..7b0c31407 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/asin.S @@ -0,0 +1,29 @@ + +.text + +.global asinf,asin,asinl # ,__asin + .type asinf,@function + .type asin,@function + .type asinl,@function +# .type __asin,@function +asinf: + flds 4(%esp) + jmp __asin +asinl: + fldt 4(%esp) + jmp __asin +asin: + fldl 4(%esp) +__asin: + fld %st + fmul %st + fld1 + fsubp + fsqrt + fpatan + ret + +.ende: +.size asin,.ende-asin +.size asinf,.ende-asinf +.size asinl,.ende-asinl diff --git a/mdk-stage1/dietlibc/i386/asinh.S b/mdk-stage1/dietlibc/i386/asinh.S new file mode 100644 index 000000000..8c3964392 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/asinh.S @@ -0,0 +1,18 @@ +.text +.global asinh +.type asinh,@function + +asinh: + fldln2 + fldl 4(%esp) + fld %st(0) + fmul %st(0),%st(0) + fld1 + faddp %st(0),%st(1) + fsqrt + faddp %st(0),%st(1) + fyl2x + ret + +.Lende: + .size asinh,.Lende-asinh diff --git a/mdk-stage1/dietlibc/i386/atan.S b/mdk-stage1/dietlibc/i386/atan.S new file mode 100644 index 000000000..76513f928 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/atan.S @@ -0,0 +1,27 @@ + +.text + +.global atanf,atan,atanl + .type atanf,@function + .type atan,@function + .type atanl,@function +atanf: + flds 4(%esp) + fld1 + fpatan + ret +atan: + fldl 4(%esp) + fld1 + fpatan + ret +atanl: + fldt 4(%esp) + fld1 + fpatan + ret + +.ende: +.size atan,.ende-atan +.size atanf,.ende-atanf +.size atanl,.ende-atanl diff --git a/mdk-stage1/dietlibc/i386/atan2.S b/mdk-stage1/dietlibc/i386/atan2.S new file mode 100644 index 000000000..acf6e03ae --- /dev/null +++ b/mdk-stage1/dietlibc/i386/atan2.S @@ -0,0 +1,12 @@ + +.text +.type atan2,@function +.global atan2 +atan2: + fldl 4(%esp) + fldl 12(%esp) + fpatan + ret + +.ende: +.size atan2,.ende-atan2 diff --git a/mdk-stage1/dietlibc/i386/atanh.S b/mdk-stage1/dietlibc/i386/atanh.S new file mode 100644 index 000000000..b75f0fa8e --- /dev/null +++ b/mdk-stage1/dietlibc/i386/atanh.S @@ -0,0 +1,19 @@ +.text +.global atanh +.type atanh,@function + +atanh: + fldln2 + fldl 4(%esp) + fld1 + fld %st(1) + fadd %st(1),%st(0) + fxch %st(1) + fsubp %st(0),%st(2) + fdivp %st(0),%st(1) + fyl2x + fmuls __half + ret + +.Lende: + .size atanh,.Lende-atanh diff --git a/mdk-stage1/dietlibc/i386/atol.S b/mdk-stage1/dietlibc/i386/atol.S new file mode 100644 index 000000000..5bd7f2c24 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/atol.S @@ -0,0 +1,55 @@ +/* + Copyright (C) 2001, 2002 Thomas M. Ogrisegg + + This is free software. You can redistribute and + modify it under the terms of the GNU General Public + Public License. + + atol.S + i386 assembler implementation of atoi(3) & atol(3) +*/ + +.text +.globl atoi +.globl atol +.type atoi,@function +.type atol,@function + +atoi: +atol: + pushl %esi + movl 0x8(%esp), %esi + xorl %eax, %eax + xorl %edx, %edx + xorb %cl, %cl +.LSpace: + lodsb + cmpb $0x21, %al + jng .LSpace + cmpb $'+', %al + jz .Lfe5 + cmpb $'-', %al + jnz .Lfe3 + inc %cl + jmp .Lfe5 +.Lfe2: + imul $0xa, %edx + addl %eax, %edx +.Lfe5: + lodsb +.Lfe3: + cmpb $47, %al + jng .Lout + subb $('0'), %al + cmpb $9, %al + jng .Lfe2 +.Lout: + movl %edx, %eax + or %cl, %cl + jz .Lreturn + negl %eax +.Lreturn: + popl %esi + ret +.size atoi, . - atoi +.size atol, . - atol diff --git a/mdk-stage1/dietlibc/i386/atoll.S b/mdk-stage1/dietlibc/i386/atoll.S new file mode 100644 index 000000000..093bf762a --- /dev/null +++ b/mdk-stage1/dietlibc/i386/atoll.S @@ -0,0 +1,64 @@ + +.text +.type atoll,@function +.global atoll + +atoll: + movl 4(%esp),%ecx + push %edi + + xorl %edi,%edi # sign = 0 + + decl %ecx +.Lspaces: + incl %ecx # while ( isspace(*p) ) p++; + movb (%ecx),%al + cmpb $' ',%al + je .Lspaces + subb $9,%al + cmpb $5,%al + jc .Lspaces # c = *p - 9; + + cmpb $'+'-9,%al # if ( c == '+' - 9 ) p++; + je .Lpos + cmpb $'-'-9,%al # else if ( c == '-' - 9 ) sign = -sign, p++; + jne .Lnosign + decl %edi +.Lpos: incl %ecx +.Lnosign: + + push %ebx + push %esi + push %ebp + movl $10,%ebp + + xorl %esi,%esi # Hi(value) = 0; + xorl %eax,%eax # Lo(value) = 0; +.Lcont: movzbl (%ecx),%ebx # while ( (unsigned) (*p - '0') < 10 ) + inc %ecx + subl $'0',%ebx + cmpl %ebp,%ebx + jnc .Lfini + imull %ebp,%esi # value *= 10, + mull %ebp + addl %edx,%esi + addl %ebx,%eax # value += (*p - '0'); + adcl $0,%esi + jmp .Lcont + +.Lfini: xchg %edx,%esi # return sign== 0 ? +value + xorl %edi,%eax # sign==-1 ? -value + xorl %edi,%edx + subl %edi,%eax + sbbl %edi,%edx + + pop %ebp + pop %esi + pop %ebx + pop %edi + ret + +.Lende: + +.size atoll,.Lende-atoll + diff --git a/mdk-stage1/dietlibc/i386/bind.S b/mdk-stage1/dietlibc/i386/bind.S new file mode 100644 index 000000000..caff9bb8b --- /dev/null +++ b/mdk-stage1/dietlibc/i386/bind.S @@ -0,0 +1,4 @@ +#include +#include + +__socketcall(bind,BIND) diff --git a/mdk-stage1/dietlibc/i386/cbrt.S b/mdk-stage1/dietlibc/i386/cbrt.S new file mode 100644 index 000000000..9d8aebd1e --- /dev/null +++ b/mdk-stage1/dietlibc/i386/cbrt.S @@ -0,0 +1,46 @@ +.text + +tab: .byte 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4 + .byte 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9 + .byte 10,10,11,11,12,12,12,13,13,14,14,14,15,15,15,16 + +_3: .long 0x40400000 + + +.global cbrt +cbrt: + fldl 4(%esp) + movw 10(%esp),%ax + movb %ah,%ch + andw $0x7FFF,%ax + jz zero /* cbrt(0) = 0 */ + pushl %ebx + cwd + movl $16*3,%ebx /* AX 3FE0 3FF0 4000 4010 */ + divw %bx /* AX 154 155 155 155 */ + /* DX 20 0 10 20 */ + shlw $5,%ax + addb %ch,%ch + rcrw %ax /* AX 1540 1550 1550 1550 */ + addw $0x3FF0-0x1550,%ax /* AX 3FE0 3FF0 3FF0 3FF0 */ + movw %dx,%bx + addb tab(%ebx),%al + adcb $0,%ah + popl %ebx + movw %ax,10(%esp) + fldl 4(%esp) /* y x */ + + movl $4,%ecx +lop: + fld %st(0) /* y y x */ + fmul %st(0),%st(0) /* y^2 y x */ + fdivr %st(2),%st(0) /* x/y^2 y x */ + fadd %st(1),%st(0) /* x/y^2+y y x */ + faddp /* x/y^2+2y x */ + fdivs _3 /* y' x */ + loop lop + + fstp %st(1) /* y' */ +zero: + ret + diff --git a/mdk-stage1/dietlibc/i386/ceil.S b/mdk-stage1/dietlibc/i386/ceil.S new file mode 100644 index 000000000..e6a4e989c --- /dev/null +++ b/mdk-stage1/dietlibc/i386/ceil.S @@ -0,0 +1,44 @@ +.text + +.global ceilf,ceil,ceill,__flcetr + .type ceilf,@function + .type ceil,@function + .type ceill,@function + .type __flcetr,@function + +ceilf: + flds 4(%esp) + movb $0x08,%ah + jmp __flcetr + +ceill: + fldt 4(%esp) + movb $0x08,%ah + jmp __flcetr + +ceil: + fldl 4(%esp) + movb $0x08,%ah + +# Wspolny kod dla funkcji floor, ceil i trunc +# W ah maska bitow 11 i 10 rejestru sterowania koprocesora +__flcetr: + xorl %ecx,%ecx # wyzerowanie rejestru + movb %ah,%ch # i utworzenie maski w cx + pushl %eax # krotsze niz subl $4,%esp + fstcw (%esp) + movw (%esp),%ax + andb $0x03,%ah # wyzerowanie bitow 11 i 10 + orl %ecx,%eax # ustawienie bitow z maski + movw %ax,2(%esp) + fldcw 2(%esp) + frndint + fldcw (%esp) # odtworzenie rejestru sterowania + popl %eax # i polozenia stosu + ret + +.Lende: +.size ceil,.Lende-ceil +.size ceill,.Lende-ceill +.size ceilf,.Lende-ceilf +.size flcetr,.Lende-__flcetr diff --git a/mdk-stage1/dietlibc/i386/clone.S b/mdk-stage1/dietlibc/i386/clone.S index ac02eb468..ea43bc2e2 100644 --- a/mdk-stage1/dietlibc/i386/clone.S +++ b/mdk-stage1/dietlibc/i386/clone.S @@ -1,17 +1,21 @@ -#include +#include "syscalls.h" +#include +#include "PIC.h" .text +.type clone,@function .weak clone clone: +.type __clone,@function .global __clone __clone: + mov $-EINVAL, %eax + movl 4(%esp), %ecx /* have non null thread_funcion */ - testl %ecx, %ecx - je .Lclone_error + jecxz .Lclone_error movl 8(%esp), %ecx /* have non null child_stack pointer */ - testl %ecx, %ecx - je .Lclone_error + jecxz .Lclone_error /* put the parameter on thread stack */ subl $8, %ecx @@ -31,9 +35,7 @@ __clone: testl %eax, %eax jl .Lclone_error - je .Lstart_thread - ret - + jne .Lreturn .Lstart_thread: xorl %ebp,%ebp call *%ebx @@ -43,9 +45,16 @@ __clone: .Lclone_error: negl %eax pushl %eax +#ifdef PIC + pushl %ebx + PIC_INIT + call __errno_location@PLT + popl %ebx +#else call __errno_location +#endif popl %ecx movl %ecx, (%eax) - xorl %eax, %eax - decl %eax + orl $-1, %eax +.Lreturn: ret diff --git a/mdk-stage1/dietlibc/i386/connect.S b/mdk-stage1/dietlibc/i386/connect.S new file mode 100644 index 000000000..a295a8814 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/connect.S @@ -0,0 +1,4 @@ +#include +#include + +__socketcall(connect,CONNECT) diff --git a/mdk-stage1/dietlibc/i386/copysign.S b/mdk-stage1/dietlibc/i386/copysign.S new file mode 100644 index 000000000..3a495efee --- /dev/null +++ b/mdk-stage1/dietlibc/i386/copysign.S @@ -0,0 +1,18 @@ + +.text +.type copysign,@function +.global copysign + +# double copysign ( double value, double sign ); + +copysign: + movb 12+7(%esp),%al + movb 4+7(%esp),%ah + andw $0x7F80,%ax + orb %ah,%al + movb 4+7(%esp),%al + fldl 4(%esp) + ret + +.ende: +.size copysign,.ende-copysign diff --git a/mdk-stage1/dietlibc/i386/cos.S b/mdk-stage1/dietlibc/i386/cos.S new file mode 100644 index 000000000..73ba03355 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/cos.S @@ -0,0 +1,24 @@ +.text + +.global cosf,cos,cosl +.type cosf,@function +.type cos,@function +.type cosl,@function + +cosf: + flds 4(%esp) + jmp .Lcos +cos: + fldl 4(%esp) +.Lcos: + call __fmod2pi + fcos + ret +cosl: + fldt 4(%esp) + jmp .Lcos + +.Lende: +.size cos,.Lende-cos +.size cosl,.Lende-cosl +.size cosf,.Lende-cosf diff --git a/mdk-stage1/dietlibc/i386/cosh.S b/mdk-stage1/dietlibc/i386/cosh.S new file mode 100644 index 000000000..f6a33704d --- /dev/null +++ b/mdk-stage1/dietlibc/i386/cosh.S @@ -0,0 +1,29 @@ + +.text +.type cosh,@function +.global cosh + +cosh: # note: exp(x) = 2^(x*log2(e)) + fldl2e + fmull 4(%esp) # x*log2(e) + fld %st(0) # x*log2(e) x*log2(e) + frndint # int(x*log2(e)) x*log2(e) + fxch # x*log2(e) int(x*log2(e)) + fsub %st(1),%st(0) # frac(x*log2(e)) int(x*log2(e)) + f2xm1 # 2^(fract(x*log2(e)))-1 int(x*log2(e)) + fld1 # 1 2^(fract(x*log2(e)))-1 int(x*log2(e)) + faddp %st(0),%st(1) # 2^(fract(x*log2(e))) int(x*log2(e)) + fscale # 2^(x*log2(e)) int(x*log2(e)) + fstp %st(1) # 2^(x*log2(e)) + +# now we have y = exp(x), but cosh(x) = (y + 1/y) * 0.5 + + fld1 + fdiv %st(1),%st(0) + faddp + fmuls __half + ret + +.Lende: + +.size cosh,.ende-cosh diff --git a/mdk-stage1/dietlibc/i386/dyn_syscalls.S b/mdk-stage1/dietlibc/i386/dyn_syscalls.S new file mode 100644 index 000000000..28d668b6c --- /dev/null +++ b/mdk-stage1/dietlibc/i386/dyn_syscalls.S @@ -0,0 +1,283 @@ +/* + * dynamic unified-syscalls + * Olaf Dreesen + */ + +#include "../syscalls.s/environ.S" +#include "../syscalls.s/errno.S" + +#include +#include "syscalls.h" +#include "PIC.h" + +/* ok now include all syscalls.s (*.S) and sysdep *.S */ + +#include "mmap.S" + +/* here on i386 I had split them some pre- some post-unified-syscall, + * because the jumps pre-u.s.c. have only a 1 byte displacement. the first + * post-u.s.c. have also 1 byte dsplacement the rest a 4 byte. + * this pre/post split saves about 250 byte of code .... + * + * Please put additional syscalls AFTER the post-u.s.c. + * or try to not break the savings :) */ + +#include "select.S" + +#include "../syscalls.s/fork.S" +#include "../syscalls.s/read.S" +#include "../syscalls.s/write.S" +#include "../syscalls.s/open.S" +#include "../syscalls.s/close.S" +#include "../syscalls.s/waitpid.S" + +#include "../syscalls.s/getgid.S" +#include "../syscalls.s/getpgid.S" +#include "../syscalls.s/getpid.S" +#include "../syscalls.s/getppid.S" +#include "../syscalls.s/getuid.S" +#include "../syscalls.s/kill.S" +#include "../syscalls.s/ioctl.S" +#include "../syscalls.s/_llseek.S" +#include "../syscalls.s/lseek.S" +#include "../syscalls.s/lstat.S" +#include "../syscalls.s/lstat64.S" +#include "../syscalls.s/mkdir.S" +#include "../syscalls.s/mprotect.S" +#include "../syscalls.s/nanosleep.S" +#include "../syscalls.s/pipe.S" +#include "../syscalls.s/poll.S" +#include "../syscalls.s/readv.S" +#include "../syscalls.s/stat.S" +#include "../syscalls.s/stat64.S" +#include "../syscalls.s/truncate.S" +#include "../syscalls.s/umask.S" +#include "../syscalls.s/wait4.S" +#include "../syscalls.s/writev.S" +#include "../syscalls.s/__getpagesize.S" + +/* OK this is basicaly unified.S */ +.text +.type __unified_syscall_256,@function +.global __unified_syscall_256 +__unified_syscall_256: + movzwl %ax, %eax + jmp .L23 +.L22: +.size __unified_syscall_256,.L22-__unified_syscall_256 +.type exit,@function +.weak exit +exit: +.type _exit,@function +.global _exit +_exit: +__exit: + mov $__NR_exit, %al +__unified_syscall: + movzbl %al, %eax +.L23: + push %edi + push %esi + push %ebx + movl %esp,%edi + movl 0x10(%edi),%ebx + movl 0x14(%edi),%ecx + movl 0x18(%edi),%edx + movl 0x1c(%edi),%esi + movl 0x20(%edi),%edi + int $0x80 + cmp $-124,%eax + jbe .Lnoerror + neg %eax + + /* PIC-code Ohhhhh My. */ + push %eax + PIC_INIT + call __errno_location@PLT + popl %ebx + movl %ebx,(%eax) + orl $-1,%eax +.Lnoerror: + pop %ebx + pop %esi + pop %edi +#include "dietuglyweaks.h" + ret + +#include "../syscalls.s/__pread.S" +#include "../syscalls.s/__pwrite.S" +#include "../syscalls.s/__reboot.S" +#include "../syscalls.s/access.S" +#include "../syscalls.s/adjtimex.S" +#include "../syscalls.s/brk.S" +#include "../syscalls.s/chdir.S" +#include "../syscalls.s/chmod.S" +#include "../syscalls.s/chown.S" +#include "../syscalls.s/chroot.S" +#include "../syscalls.s/dup.S" +#include "../syscalls.s/dup2.S" +#include "../syscalls.s/execve.S" +#include "../syscalls.s/fchdir.S" +#include "../syscalls.s/fchmod.S" +#include "../syscalls.s/fchown.S" +#include "../syscalls.s/fcntl.S" +#include "../syscalls.s/flock.S" +#include "../syscalls.s/fstat.S" +#include "../syscalls.s/fstat64.S" +#include "../syscalls.s/fstatfs.S" +#include "../syscalls.s/fsync.S" +#include "../syscalls.s/fdatasync.S" +#include "../syscalls.s/ftruncate.S" +#include "../syscalls.s/getcwd.S" +#include "../syscalls.s/getdents.S" +#include "../syscalls.s/getdents64.S" +#include "../syscalls.s/getegid.S" +#include "../syscalls.s/geteuid.S" +#include "../syscalls.s/getgroups.S" +#include "../syscalls.s/getitimer.S" +#include "../syscalls.s/getpriority.S" +#include "../syscalls.s/getresgid.S" +#include "../syscalls.s/getresuid.S" +#include "../syscalls.s/getrlimit.S" +#include "../syscalls.s/getrusage.S" +#include "../syscalls.s/getsid.S" +#include "../syscalls.s/gettimeofday.S" +#include "../syscalls.s/ioperm.S" +#include "../syscalls.s/iopl.S" +#include "../syscalls.s/ipc.S" +#include "../syscalls.s/lchown.S" +#include "../syscalls.s/link.S" +#include "../syscalls.s/mknod.S" +#include "../syscalls.s/mlock.S" +#include "../syscalls.s/mlockall.S" +#include "../syscalls.s/mount.S" +#include "../syscalls.s/mremap.S" +#include "../syscalls.s/munlockall.S" +#include "../syscalls.s/munmap.S" +#include "../syscalls.s/n_sigaction.S" +#include "../syscalls.s/n_sigpending.S" +#include "../syscalls.s/n_sigprocmask.S" +#include "../syscalls.s/n_sigsuspend.S" +#include "../syscalls.s/nice.S" +#include "../syscalls.s/pause.S" +#include "../syscalls.s/personality.S" +#include "../syscalls.s/query_module.S" +#include "../syscalls.s/init_module.S" +#include "../syscalls.s/delete_module.S" +#include "../syscalls.s/create_module.S" +#include "../syscalls.s/readlink.S" +#include "../syscalls.s/rename.S" +#include "../syscalls.s/rmdir.S" +#include "../syscalls.s/rt_sigaction.S" +#include "../syscalls.s/rt_sigpending.S" +#include "../syscalls.s/rt_sigprocmask.S" +#include "../syscalls.s/rt_sigqueueinfo.S" +#include "../syscalls.s/rt_sigsuspend.S" +#include "../syscalls.s/rt_sigtimedwait.S" +#include "../syscalls.s/sched_get_priority_max.S" +#include "../syscalls.s/sched_get_priority_min.S" +#include "../syscalls.s/sched_getparam.S" +#include "../syscalls.s/sched_getscheduler.S" +#include "../syscalls.s/sched_rr_get_interval.S" +#include "../syscalls.s/sched_setparam.S" +#include "../syscalls.s/sched_setscheduler.S" +#include "../syscalls.s/sched_yield.S" +#include "../syscalls.s/sendfile.S" +#include "../syscalls.s/setdomainname.S" +#include "../syscalls.s/setfsgid.S" +#include "../syscalls.s/setfsuid.S" +#include "../syscalls.s/setgid.S" +#include "../syscalls.s/setgroups.S" +#include "../syscalls.s/sethostname.S" +#include "../syscalls.s/setitimer.S" +#include "../syscalls.s/setpgid.S" +#include "../syscalls.s/setpriority.S" +#include "../syscalls.s/setregid.S" +#include "../syscalls.s/setresgid.S" +#include "../syscalls.s/setresuid.S" +#include "../syscalls.s/setreuid.S" +#include "../syscalls.s/setrlimit.S" +#include "../syscalls.s/setsid.S" +#include "../syscalls.s/setuid.S" +#include "../syscalls.s/sigaltstack.S" +#include "../syscalls.s/statfs.S" +#include "../syscalls.s/stime.S" +#include "../syscalls.s/swapoff.S" +#include "../syscalls.s/swapon.S" +#include "../syscalls.s/symlink.S" +#include "../syscalls.s/sync.S" +#include "../syscalls.s/sysctl.S" +#include "../syscalls.s/sysinfo.S" +#include "../syscalls.s/syslog.S" +#include "../syscalls.s/time.S" +#include "../syscalls.s/times.S" +#include "../syscalls.s/umount.S" +#include "../syscalls.s/umount2.S" +#include "../syscalls.s/uname.S" +#include "../syscalls.s/unlink.S" +#include "../syscalls.s/utime.S" +#include "../syscalls.s/vhangup.S" + +#include "../syscalls.s/chown32.S" +#include "../syscalls.s/fchown32.S" +#include "../syscalls.s/getegid32.S" +#include "../syscalls.s/geteuid32.S" +#include "../syscalls.s/getgid32.S" +#include "../syscalls.s/getgroups32.S" +#include "../syscalls.s/getresgid32.S" +#include "../syscalls.s/getuid32.S" +#include "../syscalls.s/lchown32.S" +#include "../syscalls.s/setfsgid32.S" +#include "../syscalls.s/setfsuid32.S" +#include "../syscalls.s/setgid32.S" +#include "../syscalls.s/setregid32.S" +#include "../syscalls.s/setresgid32.S" +#include "../syscalls.s/setreuid32.S" +#include "../syscalls.s/setuid32.S" +#include "../syscalls.s/alarm.S" +#include "../syscalls.s/ptrace.S" +#include "../syscalls.s/truncate64.S" +#include "../syscalls.s/ftruncate64.S" +#include "../syscalls.s/epoll_create.S" +#include "../syscalls.s/epoll_ctl.S" +#include "../syscalls.s/epoll_wait.S" + +#undef __PIC__ +#undef __socketcall +/* oh what a kludge! */ +#define socketcall .Lsocketcall +#include "../i386/send.S" +#include "../i386/recv.S" +#include "../i386/socket.S" +#include "../i386/accept.S" +#include "../i386/shutdown.S" +#include "../i386/socketpair.S" +#include "../i386/setsockopt.S" +#include "../i386/sendto.S" +#include "../i386/sendmsg.S" +#include "../i386/recvmsg.S" +#include "../i386/recvfrom.S" +#include "../i386/listen.S" +#include "../i386/getsockopt.S" +#include "../i386/getsockname.S" +#include "../i386/getpeername.S" +#include "../i386/connect.S" +#include "../i386/bind.S" +#undef socketcall +.Lsocketcall: +#include "../i386/socketcall.S" +#define __PIC__ +#undef __socketcall + + +/* so now this was the last u.s.c. */ + +/* other asm-files ... */ +#define PIC + +#define _exit __exit +#include "clone.S" +#undef _exit + +#include "__longjmp.S" +#include "setjmp.S" diff --git a/mdk-stage1/dietlibc/i386/exp.S b/mdk-stage1/dietlibc/i386/exp.S new file mode 100644 index 000000000..6c82128e4 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/exp.S @@ -0,0 +1,35 @@ +.text + +.global expf,exp,expl,__finexp + .type expf,@function + .type exp,@function + .type expl,@function + .type __finexp,@function +expf: + fldl2e + fmuls 4(%esp) + jmp __finexp +expl: + fldl2e + fldt 4(%esp) + fmulp + jmp __finexp +exp: + fldl2e + fmull 4(%esp) +__finexp: + fst %st(1) + frndint + fst %st(2) + fsubrp + f2xm1 + fld1 + faddp + fscale + ret + +.Lende: +.size exp,.Lende-exp +.size expl,.Lende-expl +.size expf,.Lende-expf +.size __finexp,.Lende-__finexp diff --git a/mdk-stage1/dietlibc/i386/exp10.S b/mdk-stage1/dietlibc/i386/exp10.S new file mode 100644 index 000000000..6223e5f85 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/exp10.S @@ -0,0 +1,27 @@ + +.text +.type exp10,@function +.global exp10 +.type pow10,@function +.global pow10 + + +pow10: +exp10: # note: 10^(x) = 2^(x*log2(10)) + fldl2t + fmull 4(%esp) # x*log2(10) + fld %st(0) # x*log2(10) x*log2(10) + frndint # int(x*log2(10)) x*log2(10) + fxch # x*log2(10) int(x*log2(10)) + fsub %st(1),%st(0) # frac(x*log2(10)) int(x*log2(10)) + f2xm1 # 2^(fract(x*log2(10)))-1 int(x*log2(10)) + fld1 # 1 2^(fract(x*log2(10)))-1 int(x*log2(10)) + faddp %st(0),%st(1) # 2^(fract(x*log2(10))) int(x*log2(10)) + fscale # 2^(x*log2(10)) int(x*log2(10)) + fstp %st(1) # 2^(x*log2(10)) + ret + +.ende: + +.size exp10,.ende-exp10 +.size pow10,.ende-pow10 diff --git a/mdk-stage1/dietlibc/i386/exp2.S b/mdk-stage1/dietlibc/i386/exp2.S new file mode 100644 index 000000000..d5389a22e --- /dev/null +++ b/mdk-stage1/dietlibc/i386/exp2.S @@ -0,0 +1,18 @@ +.text +.type exp2,@function +.global exp2 +exp2: # note: exp2(x) = 2^x + fldl 4(%esp) # x + fld %st(0) # x x + frndint # int(x) x + fxch # x int(x) + fsub %st(1),%st(0) # frac(x) int(x) + f2xm1 # 2^(fract(x))-1 int(x) + fld1 # 1 2^(fract(x))-1 int(x) + faddp %st(0),%st(1) # 2^(fract(x)) int(x) + fscale # 2^x int(x) + fstp %st(1) # 2^x + ret + +.ende: +.size exp2,.ende-exp2 diff --git a/mdk-stage1/dietlibc/i386/expm1.S b/mdk-stage1/dietlibc/i386/expm1.S new file mode 100644 index 000000000..677f4723f --- /dev/null +++ b/mdk-stage1/dietlibc/i386/expm1.S @@ -0,0 +1,23 @@ +.text +.type expm1,@function +.global expm1 +expm1: # note: exp(x) = 2^(x*log2(e)) + fldl2e + fmull 4(%esp) # x*log2(e) + fld %st(0) # x*log2(e) x*log2(e) + frndint # int(x*log2(e)) x*log2(e) + fxch # x*log2(e) int(x*log2(e)) + fsub %st(1),%st(0) # frac(x*log2(e)) int(x*log2(e)) + f2xm1 # 2^(fract(x*log2(e)))-1 int(x*log2(e)) + fscale # 2^(x*log2(e))-2^int(x*log2(e)) int(x*log2(e)) + fxch # int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) + fld1 # 1 int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) + fscale # 2^int(x*log2(e)) int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) + fstp %st(1) # 2^int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) + fld1 # 1 2^int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) + fsubrp %st(1) # 2^int(x*log2(e))-1 2^(x*log2(e))-2^int(x*log2(e)) + faddp %st(1) + ret + +.ende: +.size expm1,.ende-expm1 diff --git a/mdk-stage1/dietlibc/i386/fabs.S b/mdk-stage1/dietlibc/i386/fabs.S new file mode 100644 index 000000000..d9c1c2212 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/fabs.S @@ -0,0 +1,11 @@ + +.text +.type fabs,@function +.global fabs +fabs: + fldl 4(%esp) + fabs + ret + +.ende: +.size fabs,.ende-fabs diff --git a/mdk-stage1/dietlibc/i386/floor.S b/mdk-stage1/dietlibc/i386/floor.S new file mode 100644 index 000000000..af26d0c94 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/floor.S @@ -0,0 +1,26 @@ +.text + +.global floorf,floor,floorl + .type floorf,@function + .type floor,@function + .type floorf,@function + +floorf: + flds 4(%esp) + movb $0x04,%ah + jmp __flcetr + +floor: + fldl 4(%esp) + movb $0x04,%ah + jmp __flcetr + +floorl: + fldt 4(%esp) + movb $0x04,%ah + jmp __flcetr + +.Lende: +.size floor,.Lende-floor +.size floorl,.Lende-floorl +.size floorf,.Lende-floorf diff --git a/mdk-stage1/dietlibc/i386/fmod.S b/mdk-stage1/dietlibc/i386/fmod.S new file mode 100644 index 000000000..5bf4c06ab --- /dev/null +++ b/mdk-stage1/dietlibc/i386/fmod.S @@ -0,0 +1,37 @@ +.text +.type fmod,@function +.type fmodf,@function +.type fmodl,@function +.type __fmod2pi,@function +.global fmod, fmodl, fmodf, __fmod2pi + +__fmod2pi: + fldpi + fadd %st(0) + fxch + jmp .Lfmod + +fmodf: + flds 8(%esp) # y + flds 4(%esp) # x + jmp .Lfmod +fmod: + fldl 12(%esp) + fldl 4(%esp) +.Lfmod: + fprem + fstsw %ax + sahf + jp .Lfmod + ret + +fmodl: + fldt 16(%esp) + fldt 4(%esp) + jmp .Lfmod + + +.ende: +.size fmod,.ende-fmod +.size fmodl,.ende-fmodl +.size fmodf,.ende-fmodf diff --git a/mdk-stage1/dietlibc/i386/getenv.S b/mdk-stage1/dietlibc/i386/getenv.S new file mode 100644 index 000000000..dafbf37ee --- /dev/null +++ b/mdk-stage1/dietlibc/i386/getenv.S @@ -0,0 +1,48 @@ +#include "PIC.h" + +.text +.global getenv +.type getenv,@function +getenv: + pushl %esi + pushl %edi + movl 0xc(%esp), %edi + cld + movl %edi, %edx + xorl %eax, %eax + leal -1(%eax), %ecx + repnz scasb + not %ecx + dec %ecx + pushl %ecx + movl (%edx), %ecx + + GET_1VAR environ, %esi # non-PIC: movl environ, %esi + jmp .Lloop + +.Lprepare: + movl (%edx), %ecx + movl %eax, %esi +.Lloop: + lodsl + or %eax, %eax + jz .Lout + cmpb %cl, (%eax) + jnz .Lloop + + movl %edx, %edi + xchg %esi, %eax + movl (%esp), %ecx + repz cmpsb + jne .Lprepare + or %ecx, %ecx + jnz .Lprepare + cmpb $'=', (%esi) + jne .Lprepare + leal 0x1(%esi), %eax +.Lout: + popl %ecx + popl %edi + popl %esi + ret +.size getenv, . - getenv diff --git a/mdk-stage1/dietlibc/i386/getpeername.S b/mdk-stage1/dietlibc/i386/getpeername.S new file mode 100644 index 000000000..833322941 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/getpeername.S @@ -0,0 +1,4 @@ +#include +#include + +__socketcall(getpeername,GETPEERNAME) diff --git a/mdk-stage1/dietlibc/i386/getsockname.S b/mdk-stage1/dietlibc/i386/getsockname.S new file mode 100644 index 000000000..f0618481c --- /dev/null +++ b/mdk-stage1/dietlibc/i386/getsockname.S @@ -0,0 +1,4 @@ +#include +#include + +__socketcall(getsockname,GETSOCKNAME) diff --git a/mdk-stage1/dietlibc/i386/getsockopt.S b/mdk-stage1/dietlibc/i386/getsockopt.S new file mode 100644 index 000000000..23d7c2470 --- /dev/null +++ b/mdk-stage1/dietlibc/i386/getsockopt.S @@ -0,0 +1,4 @@ +#include +#include + +__socketcall(getsockopt,GETSOCKOPT) diff --git a/mdk-stage1/dietlibc/i386/htonl.S b/mdk-stage1/dietlibc/i386/htonl.S new file mode 100644 index 000000000..f3732d16a --- /dev/null +++ b/mdk-stage1/dietlibc/i386/htonl.S @@ -0,0 +1,13 @@ +.text +.global htonl +.type htonl,@function +.global ntohl +.type ntohl,@function + +htonl: +ntohl: + movl 4(%esp),%eax + xchgb %al,%ah + rorl $16,%eax + xchgb %al,%ah + ret diff --git a/mdk-stage1/dietlibc/i386/htons.S b/mdk-stage1/dietlibc/i386/htons.S new file mode 100644 index 000000000..367d6d03c --- /dev/null +++ b/mdk-stage1/dietlibc/i386/htons.S @@ -0,0 +1,11 @@ +.text +.global htons +.type htons,@function +.global ntohs +.type ntohs,@function + +htons: +ntohs: + movzwl 4(%esp),%eax + xchgb %al,%ah + ret diff --git a/mdk-stage1/dietlibc/linuxnet.h b/mdk-stage1/dietlibc/linuxnet.h new file mode 100644 index 000000000..8e2204701 --- /dev/null +++ b/mdk-stage1/dietlibc/linuxnet.h @@ -0,0 +1,19 @@ + +#define SYS_SOCKET 1 /* sys_socket(2) */ +#define SYS_BIND 2 /* sys_bind(2) */ +#define SYS_CONNECT 3 /* sys_connect(2) */ +#define SYS_LISTEN 4 /* sys_listen(2) */ +#define SYS_ACCEPT 5 /* sys_accept(2) */ +#define SYS_GETSOCKNAME 6 /* sys_getsockname(2) */ +#define SYS_GETPEERNAME 7 /* sys_getpeername(2) */ +#define SYS_SOCKETPAIR 8 /* sys_socketpair(2) */ +#define SYS_SEND 9 /* sys_send(2) */ +#define SYS_RECV 10 /* sys_recv(2) */ +#define SYS_SENDTO 11 /* sys_sendto(2) */ +#define SYS_RECVFROM 12 /* sys_recvfrom(2) */ +#define SYS_SHUTDOWN 13 /* sys_shutdown(2) */ +#define SYS_SETSOCKOPT 14 /* sys_setsockopt(2) */ +#define SYS_GETSOCKOPT 15 /* sys_getsockopt(2) */ +#define SYS_SENDMSG 16 /* sys_sendmsg(2) */ +#define SYS_RECVMSG 17 /* sys_recvmsg(2) */ + diff --git a/mdk-stage1/dietlibc/parselib.h b/mdk-stage1/dietlibc/parselib.h new file mode 100644 index 000000000..831d9da2b --- /dev/null +++ b/mdk-stage1/dietlibc/parselib.h @@ -0,0 +1,23 @@ +/* parse lib: parse mmapped text with \n terminated lines */ + +/* a memory buffer. */ +struct state { + const unsigned char* buffirst;/* pointer to the buffer */ + size_t buflen; /* length of the buffer */ + size_t cur; /* already parsed bytes */ +}; + +/* open and mmap file, fill in struct state */ +void __prepare_parse(const char* filename,struct state* s); +/* unmap file */ +void __end_parse(struct state* s); + +/* return the length of the matching string, 0 on error */ +/* match while pred returns nonzero */ +size_t __parse(struct state* s,int (*pred)(int ch)); + +size_t __parse_ws(struct state* s); /* skip ' ' or '\t', break at '\n' or '#' */ +size_t __parse_nws(struct state* s); /* skip non-whitespace, break at '\n' or '#' */ +size_t __parse_1(struct state* s,char c); /* skip to c */ + +size_t scan_ulong(const char* s,unsigned long* l); diff --git a/mdk-stage1/dietlibc/start.h b/mdk-stage1/dietlibc/start.h deleted file mode 100644 index 7f9e6be28..000000000 --- a/mdk-stage1/dietlibc/start.h +++ /dev/null @@ -1,14 +0,0 @@ -.section ".bss" -.align 8 - -.weak errno -errno: -.global __errno -__errno: - .long 0 - -.weak environ -environ: -.global __environ -__environ: - .long 0 diff --git a/mdk-stage1/dietlibc/syscalls.h b/mdk-stage1/dietlibc/syscalls.h index eba7a3c00..aa62f67a9 100644 --- a/mdk-stage1/dietlibc/syscalls.h +++ b/mdk-stage1/dietlibc/syscalls.h @@ -1,142 +1,35 @@ -#ifdef __ASSEMBLER__ +#if defined(__i386__) +#include "i386/syscalls.h" -#include +#elif defined(__x86_64__) +#include "x86_64/syscalls.h" +#elif defined(__sparc__) +#if defined(__arch64__) +#include "sparc64/syscalls.h" #else - -#include - -#endif - -#ifdef __i386__ - -#define syscall_weak(name,wsym,sym) \ -.text; \ -.weak wsym; \ -wsym: ; \ -.global sym; \ -sym: \ - movb $__NR_##name,%al; \ - jmp __unified_syscall - -#define syscall(name,sym) \ -.text; \ -.global sym; \ -sym: \ - movb $__NR_##name,%al; \ - jmp __unified_syscall - +#include "sparc/syscalls.h" #endif -#ifdef __sparc__ - -#define syscall_weak(name,wsym,sym) \ -.text; \ -.weak wsym; \ -wsym: ; \ -.global sym; \ -sym: \ - b __unified_syscall; \ - mov __NR_##name, %g1 - -#define syscall(name,sym) \ -.text; \ -.global sym; \ -sym: \ - b __unified_syscall; \ - mov __NR_##name, %g1 - -#endif - -#ifdef __powerpc__ - -#define syscall_weak(name,wsym,sym) \ -.text; \ -.weak wsym; \ -wsym: ; \ -.global sym; \ -sym: \ - li 0,__NR_##name; \ - b __unified_syscall +#elif defined(__powerpc__) +#include "ppc/syscalls.h" -#define syscall(name,sym) \ -.text; \ -.global sym; \ -sym: \ - li 0,__NR_##name; \ - b __unified_syscall +#elif defined(__mips__) +#include "mips/syscalls.h" -#endif - - -#ifdef __mips__ - -#define syscall_weak(name,wsym,sym) \ -.text; \ -.weak wsym; \ -wsym: ; \ -.global sym; \ -.ent sym; \ -sym: \ - li $2,__NR_##name; \ - la $25,__unified_syscall; \ - jr $25; \ -.end sym - -#define syscall(name,sym) \ -.text; \ -.global sym; \ -.ent sym; \ -sym: \ - li $2,__NR_##name; \ - la $25,__unified_syscall; \ - jr $25; \ -.end sym - -#endif - -#ifdef __arm__ - -#define syscall_weak(name,wsym,sym) \ -.text; \ -.weak wsym; \ -wsym: ; \ -.global sym; \ -sym: \ - swi __NR_##name; \ - b __unified_syscall - -#define syscall(name,sym) \ -.text; \ -.global sym; \ -sym: \ - swi __NR_##name; \ - b __unified_syscall - -#endif +#elif defined(__arm__) +#include "arm/syscalls.h" +#elif defined(__s390__) +#include "s390/syscalls.h" -#ifdef __alpha__ +#elif defined(__alpha__) +#include "alpha/syscalls.h" -#define syscall_weak(name,wsym,sym) \ -.text ; \ -.align 2 ; \ -.weak wsym; \ -.type wsym,@function ; \ -wsym: ; \ -.global sym ; \ -.type sym,@function ; \ -sym: ; \ - lda $0, __NR_##name($31) ; \ - br __unified_syscall +#elif defined(__hppa__) +#include "parisc/syscalls.h" -#define syscall(name,sym) \ -.text ; \ -.align 2 ; \ -.global sym ; \ -.type sym,@function ; \ -sym: ; \ - lda $0, __NR_##name($31) ; \ - br __unified_syscall +#elif defined(__ia64__) +#include "ia64/syscalls.h" #endif diff --git a/mdk-stage1/dietlibc/threadsafe.sh b/mdk-stage1/dietlibc/threadsafe.sh new file mode 100755 index 000000000..67f6f6338 --- /dev/null +++ b/mdk-stage1/dietlibc/threadsafe.sh @@ -0,0 +1,5 @@ +#!/bin/sh +(gcc -E - << EOF | grep -q WANT_THREAD_SAFE) || echo libpthread/pthread_*.c +#include "dietfeatures.h" +WANT_THREAD_SAFE +EOF -- cgit v1.2.1