/[smeserver]/rpms/dietlibc/sme9/dietlibc-github.patch
ViewVC logotype

Annotation of /rpms/dietlibc/sme9/dietlibc-github.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Fri Jan 25 19:22:17 2013 UTC (11 years, 10 months ago) by slords
Branch: MAIN
CVS Tags: dietlibc-0_33-0_1600_20110311_el6_sme, HEAD
Initial import

1 slords 1.1 .gitignore | 1 +
2     Makefile | 76 +++++++++++++----------
3     alpha/start.S | 9 +++
4     arm/__aeabi_unwind_cpp.S | 25 +++-----
5     arm/__fadvise.c | 5 +-
6     arm/__guard.S | 3 +
7     arm/__longjmp.S | 13 +++--
8     arm/__testandset.S | 16 ++++-
9     arm/arm-features.h | 103 ++++++++++++++++++++++++++++++++
10     arm/clone.S | 22 ++++----
11     arm/dyn_syscalls.S | 18 ++++--
12     arm/mcount.S | 10 +--
13     arm/md5asm.S | 26 +++-----
14     arm/mmap.S | 42 -------------
15     arm/setjmp.S | 29 +++++----
16     arm/start.S | 65 +++++++++++++--------
17     arm/strcpy.S | 12 +---
18     arm/strlen.S | 15 +----
19     arm/syscalls.h | 65 ++++----------------
20     arm/unified.S | 45 +++++++++-----
21     arm/waitpid.S | 19 ++----
22     dietdirent.h | 6 ++-
23     dietelfinfo.h | 20 ++++++
24     dietfeatures.h | 14 +++++
25     dietpagesize.h | 31 ++++++++++
26     dynlinker/ldso_start.S | 9 +++
27     i386/start.S | 8 ++-
28     ia64/start.S | 10 +++
29     include/paths.h | 2 +-
30     include/stdlib.h | 8 ++-
31     include/sys/shm.h | 9 ---
32     lib/__dtostr.c | 18 ++++--
33     lib/__get_elf_aux_value.c | 14 +++++
34     lib/__nice.c | 8 ++-
35     lib/__utime.c | 5 +-
36     lib/__v_printf.c | 59 ++++++++++---------
37     lib/alloc.c | 9 ++-
38     lib/closedir.c | 4 +-
39     lib/mmap64.c | 6 +-
40     lib/opendir.c | 4 +-
41     lib/readdir.c | 2 +-
42     lib/readdir64.c | 6 +-
43     lib/stack_smash_handler2.c | 13 ++++-
44     lib/stackgap.c | 37 ++++++++++-
45     libcompat/syscall.S | 8 ++-
46     libcruft/getpagesize.c | 28 ++++-----
47     libcruft/mkstemp.c | 1 +
48     libcruft/sysconf.c | 17 ++++--
49     libm/ceil.c | 92 +++++++++++++++++++++++++++++
50     libm/gamma.c | 26 ++++----
51     librpc/clnt_raw.c | 11 ++-
52     librpc/clnt_udp.c | 2 +-
53     libugly/strftime.c | 1 +
54     libugly/strptime.c | 5 +-
55     mips/start.S | 9 +++
56     parisc/start.S | 10 +++
57     ppc/start.S | 9 +++
58     ppc64/start.S | 9 +++
59     s390/start.S | 11 ++++
60     s390x/start.S | 11 ++++
61     sparc/shmat.c | 8 +--
62     sparc/start.S | 11 ++++
63     sparc64/start.S | 11 ++++
64     syscalls.s/environ.S | 16 +++++
65     syscalls.s/fadvise64.S | 9 +--
66     test/.gitignore | 85 ++++++++++++++++++++++++++
67     test/Makefile | 10 ++--
68     test/adjtime.c | 18 +++++-
69     test/asprintf.c | 2 +-
70     test/atexit.c | 2 +-
71     test/bsearch.c | 2 +-
72     test/byteswap.c | 8 +-
73     test/cycles.c | 5 +-
74     test/dirent/.gitignore | 2 +
75     test/ftruncate.c | 54 +++++++++++++++++
76     test/getmntent.c | 6 +--
77     test/getservbyname.c | 1 +
78     test/if_nameindex.c | 4 +
79     test/malloc-debugger.c | 2 +-
80     test/math.c | 29 +++++++++
81     test/mktime.c | 6 +-
82     test/mmap_test.c | 2 +-
83     test/pipe.c | 3 +
84     test/printf.c | 44 ++++++++++++--
85     test/printftest.c | 6 +-
86     test/rand48.c | 12 ++--
87     test/runtests.sh | 2 +-
88     test/sendfile.c | 2 +-
89     test/setjmp.c | 106 +++++++++++++++++++++++++++++++++
90     test/sigsetjmp.c | 140 ++++++++++++++++++++++++++++++++++++++++++++
91     test/speed.c | 4 +-
92     test/stdio/.gitignore | 14 +++++
93     test/stdio/tstscanf.c | 4 +-
94     test/stdlib/.gitignore | 13 ++++
95     test/stdlib/testsort.c | 2 +
96     test/stdlib/tst-calloc.c | 2 +
97     test/stdlib/tst-malloc.c | 6 ++-
98     test/stdlib/tst-strtod.c | 4 +-
99     test/string/.gitignore | 16 +++++
100     test/sysconf.c | 80 +++++++++++++++++++++++++
101     test/sysenter.c | 6 +-
102     test/time/.gitignore | 4 +
103     test/time/tst-strftime.c | 6 +-
104     test/time/tst-strptime.c | 23 ++++++-
105     test/waitpid.c | 2 +-
106     x86_64/__time.S | 11 ++++
107     x86_64/start.S | 16 +++++
108     x86_64/time.S | 12 +----
109     108 files changed, 1538 insertions(+), 466 deletions(-)
110    
111     diff --git a/.gitignore b/.gitignore
112     new file mode 100644
113     index 0000000..0a72698
114     --- /dev/null
115     +++ b/.gitignore
116     @@ -0,0 +1 @@
117     +/.cvsps
118     diff --git a/Makefile b/Makefile
119     index 143113b..a4f0c0c 100644
120     --- a/Makefile
121     +++ b/Makefile
122     @@ -88,7 +88,7 @@ ILIBDIR=$(LIBDIR)-$(ARCH)
123    
124     HOME=$(shell pwd)
125    
126     -WHAT= $(OBJDIR) $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o \
127     +WHAT= $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o \
128     $(OBJDIR)/dietlibc.a $(OBJDIR)/liblatin1.a \
129     $(OBJDIR)/libcompat.a $(OBJDIR)/libm.a \
130     $(OBJDIR)/librpc.a $(OBJDIR)/libpthread.a \
131     @@ -105,6 +105,7 @@ CROSS=
132    
133     CC=gcc
134     INC=-I. -isystem include
135     +STRIP=$(CROSS)strip
136    
137     VPATH=lib:libstdio:libugly:libcruft:libcrypt:libshell:liblatin1:libcompat:libdl:librpc:libregex:libm:profiling
138    
139     @@ -128,6 +129,8 @@ LIBPTHREAD_OBJS=$(patsubst libpthread/%.c,$(OBJDIR)/%.o,$(shell ./threadsafe.sh)
140    
141     LIBGMON_OBJS=$(OBJDIR)/__mcount.o $(OBJDIR)/monitor.o $(OBJDIR)/profil.o
142    
143     +NO_STACK_PROTECTOR=stackgap.o __get_elf_aux_value.o
144     +
145     include $(ARCH)/Makefile.add
146    
147     LIBMATHOBJ=$(patsubst %,$(OBJDIR)/%,$(LIBMATH))
148     @@ -150,34 +153,36 @@ PWD=$(shell pwd)
149     # added real dynamic dietlibc.so
150     PICODIR = pic-$(ARCH)
151    
152     -$(OBJDIR) $(PICODIR):
153     - mkdir $@
154     -
155     % :: %,v
156    
157     -$(OBJDIR)/%.o: $(OBJDIR)
158     +%/.dirstamp:
159     + mkdir $*
160     + @touch $@
161    
162     ifeq ($(CC),tcc)
163     -$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h
164     +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h $(OBJDIR)/.dirstamp
165     $(CROSS)cpp $(INC) $< | $(CROSS)as -o $@
166    
167     -$(OBJDIR)/%.o: %.c
168     +$(OBJDIR)/%.o: %.c $(OBJDIR)/.dirstamp
169     tcc -I. -Iinclude -c $< -o $@
170     - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
171     + $(COMMENT) -$(STRIP) -x -R .comment -R .note $@
172     else
173     -$(OBJDIR)/pstart.o: start.S
174     +$(OBJDIR)/pstart.o: start.S $(OBJDIR)/.dirstamp
175     $(CROSS)$(CC) $(INC) $(CFLAGS) -DPROFILING -c $< -o $@
176    
177     -$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h
178     +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h $(OBJDIR)/.dirstamp
179     $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@
180    
181     -$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c
182     +$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c $(OBJDIR)/.dirstamp
183     $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@
184     - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
185     + $(COMMENT) -$(STRIP) -x -R .comment -R .note $@
186     +$(OBJDIR)/stack_smash_handler2.o: XCFLAGS:=-fno-omit-frame-pointer
187    
188     -$(OBJDIR)/%.o: %.c
189     - $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ -D__dietlibc__
190     - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
191     +$(OBJDIR)/%.o: %.c $(OBJDIR)/.dirstamp
192     + $(CROSS)$(CC) $(INC) $(CFLAGS) $(XCFLAGS) -c $< -o $@ -D__dietlibc__
193     + $(COMMENT) -$(STRIP) -x -R .comment -R .note $@
194     +
195     +$(addprefix $(OBJDIR)/,$(NO_STACK_PROTECTOR)): XCFLAGS+=-fno-stack-protector
196     endif
197    
198     ifeq ($(shell $(CC) -v 2>&1 | grep "gcc version"),gcc version 4.0.0)
199     @@ -190,7 +195,7 @@ endif
200    
201     CC+=-D__dietlibc__
202    
203     -$(OBJDIR)/crypt.o: libcrypt/crypt.c
204     +$(OBJDIR)/crypt.o: libcrypt/crypt.c $(OBJDIR)/.dirstamp
205     $(CROSS)$(CC) $(INC) $(SAFER_CFLAGS) -c $< -o $@
206    
207     DIETLIBC_OBJ = $(OBJDIR)/unified.o \
208     @@ -205,7 +210,7 @@ $(OBJDIR)/dietlibc.a: $(DIETLIBC_OBJ) $(OBJDIR)/start.o
209     $(OBJDIR)/librpc.a: $(LIBRPCOBJ)
210     $(CROSS)ar cru $@ $(LIBRPCOBJ)
211    
212     -$(OBJDIR)/libcrypt.a:
213     +$(OBJDIR)/libcrypt.a: $(OBJDIR)/.dirstamp
214     touch dummy.c
215     $(CROSS)$(CC) -c dummy.c
216     $(CROSS)ar cru $@ dummy.o
217     @@ -237,28 +242,28 @@ dyn: dyn_lib
218     $(OBJDIR)/libdl.a: $(LIBDLOBJ)
219     $(CROSS)ar cru $@ $(LIBDLOBJ)
220    
221     -dyn_lib: $(PICODIR) $(PICODIR)/libc.so $(PICODIR)/dstart.o \
222     +dyn_lib: $(PICODIR)/libc.so $(PICODIR)/dstart.o \
223     $(PICODIR)/dyn_so_start.o $(PICODIR)/dyn_start.o $(PICODIR)/dyn_stop.o \
224     $(PICODIR)/libpthread.so $(PICODIR)/libdl.so $(PICODIR)/libcompat.so \
225     $(PICODIR)/libm.so $(PICODIR)/diet-dyn $(PICODIR)/diet-dyn-i
226    
227     -$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h
228     +$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h $(PICODIR)/.dirstamp
229     $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
230    
231     -$(PICODIR)/pthread_%.o: libpthread/pthread_%.c
232     +$(PICODIR)/pthread_%.o: libpthread/pthread_%.c $(PICODIR)/.dirstamp
233     $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
234     - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@
235     + $(COMMENT) $(STRIP) -x -R .comment -R .note $@
236    
237     -$(PICODIR)/%.o: %.c
238     +$(PICODIR)/%.o: %.c $(PICODIR)/.dirstamp
239     $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
240     - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@
241     + $(COMMENT) $(STRIP) -x -R .comment -R .note $@
242    
243     -$(PICODIR)/dstart.o: start.S
244     +$(PICODIR)/dstart.o: start.S $(PICODIR)/.dirstamp
245     $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
246    
247     -$(PICODIR)/dyn_so_start.o: dyn_start.c
248     +$(PICODIR)/dyn_so_start.o: dyn_start.c $(PICODIR)/.dirstamp
249     $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@
250     - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@
251     + $(COMMENT) $(STRIP) -x -R .comment -R .note $@
252    
253     DYN_LIBC_PIC = $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \
254     $(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ)
255     @@ -274,13 +279,13 @@ DYN_LIBCOMPAT_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBCOMPATOBJ))
256    
257     DYN_LIBMATH_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBMATHOBJ))
258    
259     -$(PICODIR)/libc.so: $(PICODIR) $(DYN_LIBC_OBJ)
260     +$(PICODIR)/libc.so: $(DYN_LIBC_OBJ)
261     $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so
262    
263     $(PICODIR)/libpthread.so: $(DYN_PTHREAD_OBJS) dietfeatures.h
264     $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so
265    
266     -$(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h
267     +$(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h $(PICODIR)/.dirstamp
268     $(LD_UNSET) $(CROSS)$(CC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -Bsymbolic -Wl,-Bsymbolic \
269     -o $@ $(SAFE_CFLAGS) $(INC) libdl/_dl_main.c -Wl,-soname=libdl.so
270    
271     @@ -310,19 +315,19 @@ CURNAME=$(notdir $(shell pwd))
272    
273     $(OBJDIR)/diet: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o
274     $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc
275     - $(CROSS)strip -R .comment -R .note $@
276     + $(STRIP) -R .comment -R .note $@
277    
278     $(OBJDIR)/diet-i: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o
279     $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc
280     - $(CROSS)strip -R .comment -R .note $@
281     + $(STRIP) -R .comment -R .note $@
282    
283     $(PICODIR)/diet-dyn: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c
284     $(LD_UNSET) $(CROSS)$(CC) -isystem include $(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
285     - $(CROSS)strip -R .command -R .note $@
286     + $(STRIP) -R .command -R .note $@
287    
288     $(PICODIR)/diet-dyn-i: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c
289     $(LD_UNSET) $(CROSS)$(CC) -isystem include $(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
290     - $(CROSS)strip -R .command -R .note $@
291     + $(STRIP) -R .command -R .note $@
292    
293     $(OBJDIR)/djb: $(OBJDIR)/compile $(OBJDIR)/load
294    
295     @@ -335,7 +340,7 @@ $(OBJDIR)/load:
296     chmod 755 $@
297    
298     clean:
299     - rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so
300     + rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so .dirstamp
301     rm -rf bin-* pic-*
302     $(MAKE) -C examples clean
303     $(MAKE) -C dynlinker clean
304     @@ -531,3 +536,8 @@ $(OBJDIR)/stackgap.o: dietfeatures.h
305    
306     # WANT_MALLOC_ZERO
307     $(OBJDIR)/strndup.o: dietfeatures.h
308     +
309     +
310     +GIT_CVSIMPORT=git cvsimport
311     +cvsimport:
312     + $(GIT_CVSIMPORT) -k -p '--cvs-direct' -d :pserver:cvs@cvs.fefe.de:/cvs dietlibc
313     diff --git a/alpha/start.S b/alpha/start.S
314     index 7e7cf9b..b13c9c9 100644
315     --- a/alpha/start.S
316     +++ b/alpha/start.S
317     @@ -24,6 +24,15 @@ _start:
318    
319     stq $18, environ
320    
321     +#ifdef WANT_ELFINFO
322     +# warning "MAKE ME alpha ASSEMBLER!"
323     +1: ldq $19, $18 ; load *envp into $19
324     + addq $18, 1, $18 ; increment *envp
325     + orr $19, $19, $19
326     + jne 1b
327     + stq $18, __elfinfo
328     +#endif
329     +
330     #ifdef WANT_DYNAMIC
331     /* in v0 ($0) is the ld.so _fini pointer */
332     mov $0, $19 /* mov v0(dynload) to a3 */
333     diff --git a/arm/__aeabi_unwind_cpp.S b/arm/__aeabi_unwind_cpp.S
334     index ca631bc..9334eee 100644
335     --- a/arm/__aeabi_unwind_cpp.S
336     +++ b/arm/__aeabi_unwind_cpp.S
337     @@ -1,21 +1,14 @@
338     -.text
339     -.global __aeabi_unwind_cpp_pr0
340     -.hidden __aeabi_unwind_cpp_pr0
341     -.type __aeabi_unwind_cpp_pr0, %function
342     +#include "arm-features.h"
343    
344     -.global __aeabi_unwind_cpp_pr1
345     +FUNC_START __aeabi_unwind_cpp_pr0
346     +FUNC_START __aeabi_unwind_cpp_pr1
347     +FUNC_START __aeabi_unwind_cpp_pr2
348     +.hidden __aeabi_unwind_cpp_pr0
349     .hidden __aeabi_unwind_cpp_pr1
350     -.type __aeabi_unwind_cpp_pr1, %function
351     -
352     -.global __aeabi_unwind_cpp_pr2
353     .hidden __aeabi_unwind_cpp_pr2
354     -.type __aeabi_unwind_cpp_pr2, %function
355    
356     -__aeabi_unwind_cpp_pr0:
357     -__aeabi_unwind_cpp_pr1:
358     -__aeabi_unwind_cpp_pr2:
359     - mov pc, lr @ return from subroutine
360     + RET
361    
362     -.size __aeabi_unwind_cpp_pr0,.-__aeabi_unwind_cpp_pr0
363     -.size __aeabi_unwind_cpp_pr1,.-__aeabi_unwind_cpp_pr1
364     -.size __aeabi_unwind_cpp_pr2,.-__aeabi_unwind_cpp_pr2
365     +FUNC_END __aeabi_unwind_cpp_pr2
366     +FUNC_END __aeabi_unwind_cpp_pr1
367     +FUNC_END __aeabi_unwind_cpp_pr0
368     diff --git a/arm/__fadvise.c b/arm/__fadvise.c
369     index 0aa1246..c6748c4 100644
370     --- a/arm/__fadvise.c
371     +++ b/arm/__fadvise.c
372     @@ -1,7 +1,10 @@
373     -#include <fcntl.h>
374     #include "syscalls.h"
375    
376     #ifndef __NR_fadvise64
377     +#define _LINUX_SOURCE
378     +#include <fcntl.h>
379     +#include <unistd.h>
380     +
381     long fadvise64_64(int fd, off64_t offset, off64_t len, int advice)
382     {
383     extern long __arm_fadvise64_64(int fd, int advice, off64_t offset, off64_t len);
384     diff --git a/arm/__guard.S b/arm/__guard.S
385     index 7218d13..a4e53aa 100644
386     --- a/arm/__guard.S
387     +++ b/arm/__guard.S
388     @@ -1,4 +1,5 @@
389     .data
390     +.align 2
391     .type __guard,#object
392     .global __guard
393     .type __stack_chk_guard,#object
394     @@ -7,3 +8,5 @@ __guard:
395     __stack_chk_guard:
396     .long 0xaff00
397    
398     +.size __guard, . - __guard
399     +.size __stack_chk_guard, . - __stack_chk_guard
400     diff --git a/arm/__longjmp.S b/arm/__longjmp.S
401     index 31307bd..ba03146 100644
402     --- a/arm/__longjmp.S
403     +++ b/arm/__longjmp.S
404     @@ -1,11 +1,14 @@
405     -.text
406     -.global __longjmp
407     -.type __longjmp,function
408     -__longjmp:
409     +#include "arm-features.h"
410     +
411     +FUNC_START __longjmp
412     mov ip, r0
413     movs r0, r1
414     moveq r0, #1
415     #ifndef __SOFTFP__
416     - lfm f4, 4, [ip], #48
417     + lfm f4, 4, [ip, #10*4]
418     +#endif
419     +#ifdef __IWMMXT__
420     +# warning "sigjmp will not restore iwmmxt coprocessor registers"
421     #endif
422     ldmia ip, {r4-r11, sp, pc}
423     +FUNC_END __longjmp
424     diff --git a/arm/__testandset.S b/arm/__testandset.S
425     index d9c5764..3b62c51 100644
426     --- a/arm/__testandset.S
427     +++ b/arm/__testandset.S
428     @@ -1,7 +1,15 @@
429     -.text
430     -.global __testandset
431     -__testandset:
432     +#include "arm-features.h"
433     +
434     +FUNC_START __testandset
435     mov r2, r0
436     mov r1, #1
437     +# if __ARM_ARCH__ < 6
438     swp r0, r1, [r2]
439     - mov pc, lr
440     +# else
441     +1: ldrex r0, [r2]
442     + strex r3, r1, [r2]
443     + cmp r3, #0
444     + bne 1b
445     +# endif
446     + RET
447     +FUNC_END __testandset
448     diff --git a/arm/arm-features.h b/arm/arm-features.h
449     new file mode 100644
450     index 0000000..cf330eb
451     --- /dev/null
452     +++ b/arm/arm-features.h
453     @@ -0,0 +1,103 @@
454     +/* --*- asm -*-- */
455     +
456     +#ifndef H_DIETLIBC_ARM_FEATURES_H
457     +#define H_DIETLIBC_ARM_FEATURES_H
458     +
459     +/* Stolen from gcc (gcc/config/arm/lib1funcs.asm) */
460     +#if defined(__ARM_ARCH_2__)
461     +# define __ARM_ARCH__ 2
462     +#endif
463     +
464     +#if defined(__ARM_ARCH_3__)
465     +# define __ARM_ARCH__ 3
466     +#endif
467     +
468     +#if defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__) \
469     + || defined(__ARM_ARCH_4T__)
470     +# define __ARM_ARCH__ 4
471     +#endif
472     +
473     +#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
474     + || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
475     + || defined(__ARM_ARCH_5TEJ__)
476     +# define __ARM_ARCH__ 5
477     +#endif
478     +
479     +#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
480     + || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
481     + || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
482     + || defined(__ARM_ARCH_6M__)
483     +# define __ARM_ARCH__ 6
484     +#endif
485     +
486     +#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
487     + || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__)
488     +# define __ARM_ARCH__ 7
489     +#endif
490     +
491     +#ifndef __ARM_ARCH__
492     +#error Unable to determine architecture.
493     +#endif
494     +
495     +
496     +
497     +#ifdef __ASSEMBLER__
498     +
499     +.macro FUNC_START name
500     + .text
501     + .align 0
502     + .global \name
503     + .type \name, %function
504     +\name:
505     +.endm
506     +
507     +.macro FUNC_START_WEAK name
508     + .text
509     + .align 0
510     + .weak \name
511     + .type \name, %function
512     +\name:
513     +.endm
514     +
515     +.macro FUNC_END name
516     + .size \name, . - \name
517     +.endm
518     +
519     +.macro RET
520     +#if (__ARM_ARCH__ > 4) || defined(__ARM_ARCH_4T__)
521     + bx lr
522     +#else
523     + mov pc, lr
524     +#endif
525     +.endm
526     +
527     +.macro SWI_UNIFIED name
528     +#ifdef __ARM_EABI__
529     + b __unified_syscall_swi
530     +#else
531     + swi \name
532     + b __unified_syscall
533     +#endif
534     +.endm
535     +
536     +.macro SWI_UNIFIED4
537     +#ifdef __ARM_EABI__
538     + b __unified_syscall_swi
539     +#else
540     + swi \name
541     + b __unified_syscall4
542     +#endif
543     +.endm
544     +
545     +.macro LOAD_ARG4_5
546     +#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(__ARM_ARCH_5T__)
547     + ldr r4, [sp,#16]
548     + ldr r5, [sp,#20]
549     +#else
550     + ldrd r4, [sp,#16]
551     +#endif
552     +.endm
553     +
554     +#endif /* __ASSEMBLER__ */
555     +
556     +#endif /* H_DIETLIBC_ARM_FEATURES_H */
557     diff --git a/arm/clone.S b/arm/clone.S
558     index 4a4b2f4..b2ef450 100644
559     --- a/arm/clone.S
560     +++ b/arm/clone.S
561     @@ -1,11 +1,8 @@
562    
563     #include <errno.h>
564     #include "syscalls.h"
565     +#include "arm-features.h"
566    
567     - .text
568     - .weak clone
569     - .global __clone
570     -
571     @
572     @ Some slightly tricky stuff here... edit with care :-)
573     @
574     @@ -19,9 +16,8 @@
575     @ ; don't do this yet
576     @#define RESET_PID
577    
578     -
579     -clone:
580     -__clone:
581     +FUNC_START_WEAK clone
582     +FUNC_START __clone
583     @ ; start with a sanity check
584     cmp r0, #0
585     cmpne r1, #0
586     @@ -51,7 +47,8 @@ __clone:
587     beq 1f
588     ldmfd sp!, {r4, r7}
589     blt __unified_syscall @ (return code < 0): handle as an error
590     - bx lr
591     + RET
592     +
593     1:
594     #ifdef RESET_PID
595     tst ip, #CLONE_THREAD
596     @@ -76,12 +73,13 @@ __clone:
597    
598     @ ; and we're done, passing return value through r0
599     b _exit @ branch to _exit (PIC safe)
600     +FUNC_END __clone
601     +FUNC_END clone
602    
603     -
604     #else
605    
606     -clone:
607     -__clone:
608     +FUNC_START_WEAK clone
609     +FUNC_START __clone
610     movs r12, r0 @ check function pointer
611     cmpne r1, #0 @ if function check for stack pointer
612     moveq r0, #-EINVAL @ if one is not available set errno value
613     @@ -101,5 +99,7 @@ __clone:
614     ldmia sp!, { r0, pc } @ load function param and jump to thread function
615    
616     1: b _exit @ branch to _exit (PIC safe)
617     +FUNC_END __clone
618     +FUNC_END clone
619    
620     #endif
621     diff --git a/arm/dyn_syscalls.S b/arm/dyn_syscalls.S
622     index a4baf28..a8fe803 100644
623     --- a/arm/dyn_syscalls.S
624     +++ b/arm/dyn_syscalls.S
625     @@ -8,11 +8,15 @@
626    
627     #include <dietfeatures.h>
628     #include "syscalls.h"
629     +#include "arm-features.h"
630    
631     -.text
632     -__unified_syscall4:
633     +#ifdef __ARM_EABI__
634     +# error "dyn_syscall.S not ported for EABI yet"
635     +#endif
636     +
637     +FUNC_START __unified_syscall4
638     ldmfd sp!, {r4, r5, r6}
639     -__unified_syscall:
640     +FUNC_START __unified_syscall
641     cmn r0, #4096
642     movcc pc, lr
643     rsb r1, r0, #0
644     @@ -25,7 +29,9 @@ __unified_syscall:
645    
646     mvn r0, #0
647     #include "dietuglyweaks.h"
648     - mov pc, lr
649     + RET
650     +FUNC_END __unified_syscall
651     +FUNC_END __unified_syscall4
652    
653     /* ok now include all syscalls.s (*.S) and sysdep *.S */
654     #include "mmap.S"
655     @@ -280,9 +286,11 @@ __unified_syscall:
656     #include "../syscalls.s/fgetxattr.S"
657    
658     /* other asm-files w.o. changes ... */
659     -__exit:
660     +FUNC_START __exit
661     swi $__NR_exit
662     eor pc,lr,lr
663     +FUNC_END __exit
664     +
665     #define _exit __exit
666     #include "clone.S"
667     #undef _exit
668     diff --git a/arm/mcount.S b/arm/mcount.S
669     index a397e92..2e25adf 100644
670     --- a/arm/mcount.S
671     +++ b/arm/mcount.S
672     @@ -1,4 +1,4 @@
673     -
674     +#include "arm-features.h"
675     @
676     @ mcount.S: ARM assembler implementation of mcount
677     @
678     @@ -27,11 +27,7 @@
679     @
680     @
681    
682     -.text
683     -
684     -.global mcount
685     -
686     -mcount:
687     +FUNC_START mcount
688     mov ip, sp
689     stmdb sp!, { r0 - r3, fp, ip, lr, pc } @ build stack frame
690     sub fp, ip, #4 @ setup new fp
691     @@ -43,4 +39,4 @@ mcount:
692     bl __mcount @ call __mcount
693    
694     ldmdb fp, { r0 - r3, fp, sp, pc } @ restore context from stack frame and return.
695     -
696     +FUNC_END mcount
697     diff --git a/arm/md5asm.S b/arm/md5asm.S
698     index 370b503..14ba4b9 100644
699     --- a/arm/md5asm.S
700     +++ b/arm/md5asm.S
701     @@ -50,45 +50,35 @@
702     *****************************************************************************/
703    
704     #include <endian.h>
705     +#include "arm-features.h"
706    
707     #if (__BYTE_ORDER == __LITTLE_ENDIAN)
708    
709     - .global MD5Init
710     - .global MD5Update
711     -
712     - .text
713     -#ifdef __ARM_EABI__
714     - .align 4
715     -#else
716     - .align 2
717     -#endif
718     -
719     @ --
720     @ void MD5Init (MD5_CTX* context);
721     @ --
722    
723     -MD5Init:
724     -
725     +FUNC_START MD5Init
726     adr r1, 1f @ r1 = base address of MD5InitData array
727     ldmia r1, { r1 - r3, r12 } @ load 4 elements from MD5InitData array
728     stmia r0, { r1 - r3, r12 } @ store into MD5 context->state[0..3]
729     mov r1, #0
730     str r1, [r0, #0x10] @ initial count[0] = 0
731     str r1, [r0, #0x14] @ initial count[1] = 0
732     - mov pc, lr @ return
733     + RET
734    
735     + .align 3
736     1: .word 0x67452301 @ initial MD5 context->state[0]
737     .word 0xefcdab89 @ initial MD5 context->state[1]
738     .word 0x98badcfe @ initial MD5 context->state[2]
739     .word 0x10325476 @ initial MD5 context->state[3]
740     -
741     +FUNC_END MD5Init
742    
743     @ --
744     @ void MD5Update (MD5_CTX* context, const uint8_t* buf, signed int len);
745     @ --
746    
747     -MD5Update:
748     -
749     +FUNC_START MD5Update
750     stmdb sp!, { r4 - r8, lr }
751     add r4, r0, #(6 * 4) @ r4 = &context->buffer[0]
752     ldmdb r4, { r0, r3 } @ r0 = count[0], r3 = count[1]
753     @@ -122,12 +112,13 @@ MD5Update:
754     sub r2, r8, r2
755     2: ldmia sp!, { r4 - r8, lr }
756     b memcpy @ classic tail-call optimisation...
757     -
758     +FUNC_END MD5Update
759    
760     @ --
761     @ static void __MD5Transform (uint32_t *buf, const uint32_t *in, int repeat);
762     @ --
763    
764     + .align 3
765     MD5MagicData:
766    
767     1: .word 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee
768     @@ -148,6 +139,7 @@ MD5MagicData:
769     .word 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, (17f-19f-4)
770     .word 0x6e4120A9, 0x20657264, 0x7543634d, 0x00796472, (19f-19f-4)
771    
772     + .align 2
773     __MD5Transform:
774    
775     cmp r2, #0
776     diff --git a/arm/mmap.S b/arm/mmap.S
777     deleted file mode 100644
778     index d3ea131..0000000
779     --- a/arm/mmap.S
780     +++ /dev/null
781     @@ -1,42 +0,0 @@
782     -#include <errno.h>
783     -#include "syscalls.h"
784     -
785     -.text
786     -
787     -@
788     -@ mmap takes 6 parameters - ie more than can be passed in registers via the
789     -@ regular syscall interface. Instead, parameters are passed on the stack.
790     -@
791     -@ On entry, the compiler will have already placed the fifth and sixth
792     -@ parameters on the stack - all we need do here is push the first four and
793     -@ call the syscall.
794     -@
795     -
796     -.global mmap
797     -
798     -#ifdef __ARM_EABI__
799     -
800     -mmap:
801     - str r5, [sp, #-4]!
802     - ldr r5, [sp, #8]
803     - str r4, [sp, #-4]!
804     - ldr r4, [sp, #8]
805     - mov ip, r7
806     - mov r7, #__NR_mmap2
807     - svc 0x00000000
808     - mov r7, ip
809     - ldr r4, [sp], #4
810     - ldr r5, [sp], #4
811     - cmn r0, #4096
812     - mov pc, lr @ return
813     -
814     -#else
815     -
816     -mmap:
817     - stmdb sp!, {r0, r1, r2, r3}
818     - mov r0, sp
819     - swi __NR_mmap
820     - add sp, sp, #16
821     - b __unified_syscall
822     -
823     -#endif
824     diff --git a/arm/setjmp.S b/arm/setjmp.S
825     index 6b850d4..e7503b2 100644
826     --- a/arm/setjmp.S
827     +++ b/arm/setjmp.S
828     @@ -1,17 +1,20 @@
829     -.text
830     -.weak setjmp
831     -setjmp:
832     -.global __setjmp
833     -__setjmp:
834     +#include "arm-features.h"
835     +
836     +FUNC_START_WEAK setjmp
837     +FUNC_START __setjmp
838     mov r1, #0
839     -.global __sigsetjmp
840     -__sigsetjmp:
841     -.weak sigsetjmp
842     -sigsetjmp:
843     +FUNC_END __setjmp
844     +FUNC_END setjmp
845     +
846     +FUNC_START_WEAK sigsetjmp
847     +FUNC_START __sigsetjmp
848     + stmia r0, {r4-r11, sp, lr}
849     #ifndef __SOFTFP__
850     - sfm f4, 4, [r0], #48
851     + sfm f4, 4, [r0, #10*4]
852     +#endif
853     +#ifdef __IWMMXT__
854     +# warning "setjmp will not save iwmmxt coprocessor registers"
855     #endif
856     - stmia r0, {r4-r11, sp, lr}
857     - sub r0, r0, #48
858     b __sigjmp_save
859     -
860     +FUNC_END __sigsetjmp
861     +FUNC_END sigsetjmp
862     diff --git a/arm/start.S b/arm/start.S
863     index d68d49d..cfb298c 100644
864     --- a/arm/start.S
865     +++ b/arm/start.S
866     @@ -1,23 +1,11 @@
867    
868     #include "dietfeatures.h"
869     #include "syscalls.h"
870     +#include "arm-features.h"
871    
872     - .text
873     #ifdef __ARM_EABI__
874     - .align 4
875     -#else
876     - .align 2
877     -#endif
878     -
879     - .global _start
880     - .weak exit
881     - .global _exit
882     -
883     -
884     -#ifdef __ARM_EABI__
885     -
886     -_start:
887    
888     +FUNC_START _start
889     mov fp, #0 @ clear the frame pointer
890     ldr a1, [sp] @ argc
891     add a2, sp, #4 @ argv
892     @@ -25,6 +13,17 @@ _start:
893     add a3, a2, a1, lsl #2 @ &argv[argc]
894     add a3, a3, #4 @ envp
895     str a3, [ip, #0] @ environ = envp
896     +
897     +#ifdef WANT_ELFINFO
898     + mov r6, a3 @ work on a copy of a3 so that common
899     + @ 'main(argc, argv, envp)' function
900     + @ stays valid
901     +1: ldr r5, [r6], #4 @ load *envp and increment it
902     + cmp r5, #0 @ read value==0?
903     + bne 1b
904     + str r6, [ip, #4] @ __elfinfo = envp
905     +#endif
906     +
907     bl main
908    
909     @
910     @@ -32,21 +31,22 @@ _start:
911     @ We need to branch to 'exit' in case we have linked with 'atexit'.
912     @
913     bl exit
914     +FUNC_END _start
915    
916     -exit:
917     -_exit:
918     -
919     +FUNC_START _exit
920     +FUNC_START_WEAK exit
921     mov r7, #__NR_exit
922     swi 0 @ never returns.
923    
924     + .align 2
925     .L3: .word environ
926     -
927     +FUNC_END exit
928     +FUNC_END _exit
929    
930     #else
931    
932    
933     -_start:
934     -
935     +FUNC_START _start
936     #ifdef WANT_DYNAMIC
937     mov a4, a1 @ save dynamic ld.so _fini
938     #endif
939     @@ -59,11 +59,25 @@ _start:
940     #ifdef __DYN_LIB
941     ldr sl, .L4
942     1: add sl, pc, sl
943     - str a3, [sl, ip] @ environ = envp
944     + str a3, [ip, sl]! @ environ = envp; ip = GOT(environ)
945     #else
946     str a3, [ip, #0] @ environ = envp
947     #endif
948    
949     +#ifdef WANT_ELFINFO
950     + mov r6, a3 @ work on a copy of a3 so that common
951     + @ 'main(argc, argv, envp)' function
952     + @ stays valid
953     +1: ldr r5, [r6], #4 @ load *envp and increment it
954     + cmp r5, #0 @ read value==0?
955     + bne 1b
956     +#ifdef __DYN_LIB
957     + str r6, [ip, sl] @ __elfinfo = envp
958     +#else
959     + str r6, [ip, #4] @ __elfinfo = envp
960     +#endif
961     +#endif
962     +
963     #ifdef PROFILING
964     stmdb sp!, { r0 - r3 }
965     ldr r0, .L5
966     @@ -83,18 +97,21 @@ _start:
967     @ We need to branch to 'exit' in case we have linked with 'atexit'.
968     @
969     bl exit
970     +FUNC_END _start
971    
972     -exit:
973     -_exit:
974     -
975     +FUNC_START _exit
976     +FUNC_START_WEAK exit
977     #ifdef PROFILING
978     mov r4, r0 @ save a copy of exit status
979     bl _stop_monitor
980     mov r0, r4
981     #endif
982     swi $__NR_exit @ never returns.
983     +FUNC_END exit
984     +FUNC_END _exit
985    
986    
987     + .align 2
988     #ifdef __DYN_LIB
989     .L3: .word environ(GOT)
990     .L4: .word _GLOBAL_OFFSET_TABLE_-(1b+8)
991     diff --git a/arm/strcpy.S b/arm/strcpy.S
992     index 20e1029..7a86562 100644
993     --- a/arm/strcpy.S
994     +++ b/arm/strcpy.S
995     @@ -1,10 +1,7 @@
996     #include "dietfeatures.h"
997     +#include "arm-features.h"
998    
999     -.text
1000     - .align 2
1001     - .global strcpy
1002     -
1003     -strcpy:
1004     +FUNC_START strcpy
1005     #ifndef WANT_SMALL_STRING_ROUTINES
1006     mov ip, r0
1007     ands r2, r1, #3
1008     @@ -61,6 +58,5 @@ strcpy:
1009     ldrneb r2, [r1], #1
1010     #endif
1011     bne .Lloop
1012     - mov pc, lr
1013     -.Lfe1:
1014     - .size strcpy,.Lfe1-strcpy
1015     + RET
1016     +FUNC_END strcpy
1017     diff --git a/arm/strlen.S b/arm/strlen.S
1018     index 6b2b459..a6af8f0 100644
1019     --- a/arm/strlen.S
1020     +++ b/arm/strlen.S
1021     @@ -1,12 +1,7 @@
1022     #include "dietfeatures.h"
1023     +#include "arm-features.h"
1024    
1025     - .text
1026     - .align 2
1027     -
1028     - .global strlen
1029     -
1030     -strlen:
1031     -
1032     +FUNC_START strlen
1033     #if 0
1034     teq a1, #0 @ is string pointer NULL ??
1035     moveq pc, lr @ if so, return 0
1036     @@ -61,12 +56,10 @@ strlen:
1037     sub a1, a1, a2
1038     #endif
1039    
1040     - mov pc, lr
1041     + RET
1042    
1043     #ifndef WANT_SMALL_STRING_ROUTINES
1044     .Lmagic:
1045     .word 0x01010101
1046     #endif
1047     -
1048     -.Lstrlen:
1049     - .size strlen,.Lstrlen-strlen
1050     +FUNC_END strlen
1051     diff --git a/arm/syscalls.h b/arm/syscalls.h
1052     index d092f55..21a6dcc 100644
1053     --- a/arm/syscalls.h
1054     +++ b/arm/syscalls.h
1055     @@ -700,9 +700,9 @@
1056     #define __ARGS_getpeername 0
1057     #define __ARGS_socketpair 0
1058     #define __ARGS_send 0
1059     -#define __ARGS_sendto 0
1060     +#define __ARGS_sendto 6
1061     #define __ARGS_recv 0
1062     -#define __ARGS_recvfrom 0
1063     +#define __ARGS_recvfrom 6
1064     #define __ARGS_shutdown 0
1065     #define __ARGS_setsockopt 0
1066     #define __ARGS_getsockopt 0
1067     @@ -771,70 +771,30 @@
1068    
1069     #ifdef __ASSEMBLER__
1070    
1071     -#ifdef __ARM_EABI__
1072     +#include "arm-features.h"
1073    
1074     #define syscall_weak(name,wsym,sym) __syscall_weak __NR_##name, wsym, sym, __ARGS_##name
1075     .macro __syscall_weak name wsym sym typ
1076     -.text
1077     -.type \wsym,function
1078     -.weak \wsym
1079     -\wsym:
1080     -.type \sym,function
1081     -.global \sym
1082     -\sym:
1083     - stmfd sp!,{r4,r5,r7,lr}
1084     - ldr r4, [sp,#16]
1085     - ldr r5, [sp,#20]
1086     - ldr r7, =\name
1087     - swi 0
1088     - b __unified_syscall
1089     +FUNC_START_WEAK \wsym
1090     +__syscall \name, \sym, \typ
1091     +FUNC_END \wsym
1092     .endm
1093    
1094     +#ifdef __ARM_EABI__
1095    
1096     #define syscall(name,sym) __syscall __NR_##name, sym, __ARGS_##name
1097     .macro __syscall name sym typ
1098     -.text
1099     -.type \sym,function
1100     -.global \sym
1101     -\sym:
1102     - stmfd sp!,{r4,r5,r7,lr}
1103     - ldr r4, [sp,#16]
1104     - ldr r5, [sp,#20]
1105     - ldr r7, =\name
1106     - swi 0
1107     - b __unified_syscall
1108     +FUNC_START \sym
1109     + ldr ip, =\name
1110     + b __unified_syscall_swi
1111     +FUNC_END \sym
1112     .endm
1113    
1114     #else
1115    
1116     -#define syscall_weak(name,wsym,sym) __syscall_weak $__NR_##name, wsym, sym, __ARGS_##name
1117     -.macro __syscall_weak name wsym sym typ
1118     -.text
1119     -.type \wsym,function
1120     -.weak \wsym
1121     -\wsym:
1122     -.type \sym,function
1123     -.global \sym
1124     -\sym:
1125     -.ifgt \typ
1126     - mov ip, sp
1127     - stmfd sp!,{r4, r5, r6}
1128     - ldmia ip, {r4, r5, r6}
1129     -.endif
1130     - swi \name
1131     -.ifgt \typ
1132     - b __unified_syscall4
1133     -.else
1134     - b __unified_syscall
1135     -.endif
1136     -.endm
1137     -
1138     #define syscall(name,sym) __syscall $__NR_##name, sym, __ARGS_##name
1139     .macro __syscall name sym typ
1140     -.text
1141     -.type \sym,function
1142     -.global \sym
1143     -\sym:
1144     +FUNC_START \sym
1145     .ifgt \typ
1146     mov ip, sp
1147     stmfd sp!,{r4, r5, r6}
1148     @@ -846,6 +806,7 @@
1149     .else
1150     b __unified_syscall
1151     .endif
1152     +FUNC_END \sym
1153     .endm
1154    
1155     #endif
1156     diff --git a/arm/unified.S b/arm/unified.S
1157     index e6ea3f6..bd5b987 100644
1158     --- a/arm/unified.S
1159     +++ b/arm/unified.S
1160     @@ -1,21 +1,28 @@
1161    
1162     #include <dietfeatures.h>
1163     +#include "arm-features.h"
1164    
1165     - .text
1166     #ifdef __ARM_EABI__
1167     - .align 4
1168     -#else
1169     - .align 2
1170     -#endif
1171     - .global __unified_syscall
1172     - .global __unified_syscall4
1173     -
1174    
1175     -#ifdef __ARM_EABI__
1176     +/* expects:
1177     + * r0-r3 ... syscall arguments 0-3
1178     + * ip ... syscall number
1179     + */
1180     +FUNC_START __unified_syscall_swi
1181     + .hidden __unified_syscall_swi
1182     + stmfd sp!,{r4,r5,r7,lr}
1183     + mov r7, ip
1184     + LOAD_ARG4_5
1185     + swi 0
1186     + /* fallthrough to __unified4_syscall */
1187     +FUNC_END __unified_syscall_swi
1188    
1189     -__unified_syscall4:
1190     -__unified_syscall:
1191     -
1192     +/* expects:
1193     + * r0 ... syscall return value
1194     + * original r4-r7 + lr on stack
1195     + */
1196     +FUNC_START __unified_syscall
1197     + .hidden __unified_syscall
1198     cmn r0, #4096
1199     rsbcs r2, r0, #0
1200     ldrcs r3, 1f
1201     @@ -25,17 +32,18 @@ __unified_syscall:
1202     .balign 4
1203     1:
1204     .word errno
1205     +FUNC_END __unified_syscall
1206    
1207     -/* here we go and "reuse" the return for weak-void functions */
1208     #include "dietuglyweaks.h"
1209    
1210     - mov pc, lr @ return
1211     + RET
1212    
1213     #else
1214    
1215     -__unified_syscall4:
1216     +FUNC_START __unified_syscall4
1217     ldmia sp!, {r4, r5, r6}
1218     -__unified_syscall:
1219     +
1220     +FUNC_START __unified_syscall
1221     cmn r0, #4096
1222     movcc pc, lr @ return value comes direct from kernel.
1223    
1224     @@ -53,10 +61,13 @@ __unified_syscall:
1225     /* here we go and "reuse" the return for weak-void functions */
1226     #include "dietuglyweaks.h"
1227    
1228     - mov pc, lr @ return
1229     + RET
1230    
1231     #ifndef WANT_THREAD_SAFE
1232     + .align 2
1233     .L0: .long errno
1234     #endif
1235     +FUNC_END __unified_syscall
1236     +FUNC_END __unified_syscall4
1237    
1238     #endif
1239     diff --git a/arm/waitpid.S b/arm/waitpid.S
1240     index 2c3a75b..0d099a8 100644
1241     --- a/arm/waitpid.S
1242     +++ b/arm/waitpid.S
1243     @@ -1,15 +1,8 @@
1244     -.text
1245     -#ifdef __ARM_EABI__
1246     -.align 4
1247     -#else
1248     -.align 2
1249     -#endif
1250     -.weak waitpid
1251     -.type waitpid, %function
1252     -waitpid:
1253     -.global __libc_waitpid
1254     -.type __libc_waitpid, %function
1255     -__libc_waitpid:
1256     +#include "arm-features.h"
1257     +
1258     +FUNC_START_WEAK waitpid
1259     +FUNC_START __libc_waitpid
1260     mov r3, #0
1261     b wait4
1262     - .size waitpid, .-waitpid
1263     +FUNC_END __libc_waitpid
1264     +FUNC_END waitpid
1265     diff --git a/dietdirent.h b/dietdirent.h
1266     index dbd7206..3e823f8 100644
1267     --- a/dietdirent.h
1268     +++ b/dietdirent.h
1269     @@ -1,8 +1,12 @@
1270     #include <sys/shm.h>
1271    
1272     +#include "dietpagesize.h"
1273     +
1274     struct __dirstream {
1275     int fd;
1276     - char buf[PAGE_SIZE-(sizeof (int)*3)];
1277     unsigned int num;
1278     unsigned int cur;
1279     + char buf[] __attribute__((__aligned__(8)));
1280     }; /* stream data from opendir() */
1281     +
1282     +#define __DIRSTREAM_BUF_SIZE (__DIET_PAGE_SIZE - offsetof(struct __dirstream, buf))
1283     diff --git a/dietelfinfo.h b/dietelfinfo.h
1284     new file mode 100644
1285     index 0000000..de8c717
1286     --- /dev/null
1287     +++ b/dietelfinfo.h
1288     @@ -0,0 +1,20 @@
1289     +#include "dietfeatures.h"
1290     +
1291     +#ifdef WANT_ELFINFO
1292     +#include <elf.h>
1293     +#include <endian.h>
1294     +#include <stdint.h>
1295     +
1296     +/* TODO: exported interface from <linux/elf.h> has been changed in 2.6.25 so
1297     + * the 'elf_addr_t' type is not available anymore. Hence, derive it from
1298     + * __WORDSIZE__. */
1299     +
1300     +#if __WORDSIZE == 64
1301     +typedef uint64_t __diet_elf_addr_t;
1302     +#elif __WORDSIZE == 32
1303     +typedef uint32_t __diet_elf_addr_t;
1304     +#endif
1305     +
1306     +__diet_elf_addr_t const * __get_elf_aux_value(unsigned int tag)
1307     + __attribute__((__visibility__("hidden"),__const__)) __pure;
1308     +#endif
1309     diff --git a/dietfeatures.h b/dietfeatures.h
1310     index dcdda39..0d44425 100644
1311     --- a/dietfeatures.h
1312     +++ b/dietfeatures.h
1313     @@ -138,6 +138,16 @@
1314     #define WANT_SSP
1315     #endif
1316    
1317     +/* Some platforms like x86_64, ppc* or mips do not have a fixed PAGE_SIZE.
1318     + * Select WANT_DYN_PAGESIZE to detect the current PAGE_SIZE at runtime. Else,
1319     + * define WANT_STATIC_PAGESIZE to a proper value (must be a power of 2)
1320     + * matching the configured pagesize of the kernel where your binaries are
1321     + * running on.
1322     + *
1323     + * Selecting WANT_DYN_PAGESIZE enlarges the startup code by around 1-3
1324     + * instructions and might add an additional __elfinfo symbol */
1325     +#define WANT_DYN_PAGESIZE
1326     +/* #define WANT_STATIC_PAGESIZE 0x10000UL */
1327    
1328    
1329     /* stop uncommenting here ;-) */
1330     @@ -169,4 +179,8 @@
1331     #endif
1332     #endif
1333    
1334     +#ifdef WANT_DYN_PAGESIZE
1335     +#define WANT_ELFINFO
1336     +#endif
1337     +
1338     #endif
1339     diff --git a/dietpagesize.h b/dietpagesize.h
1340     new file mode 100644
1341     index 0000000..8ce6ce7
1342     --- /dev/null
1343     +++ b/dietpagesize.h
1344     @@ -0,0 +1,31 @@
1345     +#ifndef H_DIETLIBC_DIETPAGESIZE_H
1346     +#define H_DIETLIBC_DIETPAGESIZE_H
1347     +
1348     +#include <strings.h>
1349     +#include "dietfeatures.h"
1350     +
1351     +extern size_t __libc_getpagesize(void) __attribute__((__const__)) __pure;
1352     +
1353     +#if defined(WANT_STATIC_PAGESIZE)
1354     +# define __DIET_PAGE_SIZE_PREDEF (WANT_STATIC_PAGESIZE)
1355     +# define __DIET_PAGE_SHIFT_PREDEF (ffs(__DIET_PAGE_SIZE_PREDEF)-1)
1356     +#elif defined(__alpha__) || defined(__sparc__)
1357     +# define __DIET_PAGE_SIZE_PREDEF (8192UL)
1358     +# define __DIET_PAGE_SHIFT_PREDEF (13)
1359     +#elif defined(__powerpc64__)
1360     +# define __DIET_PAGE_SIZE_PREDEF (65536UL)
1361     +# define __DIET_PAGE_SHIFT_PREDEF (16)
1362     +#else
1363     +# define __DIET_PAGE_SIZE_PREDEF (4096UL)
1364     +# define __DIET_PAGE_SHIFT_PREDEF (12)
1365     +#endif
1366     +
1367     +#ifdef WANT_DYN_PAGESIZE
1368     +# define __DIET_PAGE_SIZE (__libc_getpagesize())
1369     +# define __DIET_PAGE_SHIFT (ffs(__DIET_PAGE_SIZE)-1)
1370     +#else
1371     +# define __DIET_PAGE_SIZE __DIET_PAGE_SIZE_PREDEF
1372     +# define __DIET_PAGE_SHIFT __DIET_PAGE_SHIFT_PREDEF
1373     +#endif
1374     +
1375     +#endif /* H_DIETLIBC_DIETPAGESIZE_H */
1376     diff --git a/dynlinker/ldso_start.S b/dynlinker/ldso_start.S
1377     index ca278d7..da36845 100644
1378     --- a/dynlinker/ldso_start.S
1379     +++ b/dynlinker/ldso_start.S
1380     @@ -86,6 +86,15 @@ __environ:
1381     .long 0
1382     #endif
1383    
1384     +/* __elfinfo must follow __environ immediately */
1385     +.global __elfinfo
1386     +__elfinfo:
1387     +#if __WORDSIZE == 64
1388     + .quad 0
1389     +#else
1390     + .long 0
1391     +#endif
1392     +
1393     .global fini_entry
1394     fini_entry:
1395     .long 0
1396     diff --git a/i386/start.S b/i386/start.S
1397     index 361af3d..b681d05 100644
1398     --- a/i386/start.S
1399     +++ b/i386/start.S
1400     @@ -20,12 +20,18 @@ _start:
1401     PIC_INIT /* non-PIC: this is an empty line */
1402     PUT_VAR %esi, environ, %ecx /* non-PIC: movl %esi,environ */
1403    
1404     -#ifdef WANT_SYSENTER
1405     +#if defined(WANT_ELFINFO) || defined(WANT_SYSENTER)
1406     /* skip environment, scan for NULL */
1407     1:
1408     lodsl
1409     testl %eax,%eax
1410     jnz 1b
1411     +# ifdef WANT_ELFINFO
1412     + PUT_VAR %esi, __elfinfo, %ecx
1413     +# endif
1414     +#endif
1415     +
1416     +#ifdef WANT_SYSENTER
1417     /* The ELF auxvec follows the environment, consists of key/value pairs.
1418     We are looking for key 32, which stands for the vsyscall page */
1419     1:
1420     diff --git a/ia64/start.S b/ia64/start.S
1421     index 50fd015..c917721 100644
1422     --- a/ia64/start.S
1423     +++ b/ia64/start.S
1424     @@ -40,6 +40,16 @@ _start:
1425     ;;
1426     st8 [r14] = out2 /* store envp in environ */
1427    
1428     +#ifdef WANT_ELFINFO
1429     +# warning "MAKE ME IE64 CODE!"
1430     +1: ld8 r9 = [out2], 8 /* load *envp and increment it */
1431     + orr r9 = r9, r9 /* test for NULL */
1432     + bne 1b
1433     +
1434     + adds r14 = 8, r14 /* __elfinfo = environ + 8 */
1435     + st8 [r14] = out2 /* store envp in __elfinfo */
1436     +#endif
1437     +
1438     #ifdef WANT_DYNAMIC
1439     /* FIXME: dl_init parameter ??? */
1440     br.call.sptk.few rp = _dyn_start
1441     diff --git a/include/paths.h b/include/paths.h
1442     index 553b4fa..9bf216f 100644
1443     --- a/include/paths.h
1444     +++ b/include/paths.h
1445     @@ -2,7 +2,7 @@
1446     #define _PATHS_H
1447    
1448     #define _PATH_BSHELL "/bin/sh"
1449     -#define _PATH_DEFPATH "/bin:/usr/bin:"
1450     +#define _PATH_DEFPATH "/bin:/usr/bin"
1451    
1452     #define _PATH_DEVNULL "/dev/null"
1453    
1454     diff --git a/include/stdlib.h b/include/stdlib.h
1455     index 4976f86..1dd10ff 100644
1456     --- a/include/stdlib.h
1457     +++ b/include/stdlib.h
1458     @@ -28,8 +28,12 @@ long double strtold(const char *nptr, char **endptr) __THROW;
1459     long int strtol(const char *nptr, char **endptr, int base) __THROW;
1460     unsigned long int strtoul(const char *nptr, char **endptr, int base) __THROW;
1461    
1462     +/* HACK: used flags in __dtostr
1463     + 0x01 ... 'g'
1464     + 0x02 ... uppercase
1465     + Define some constants somewhere... */
1466     extern int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase) __THROW;
1467     -extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int g) __THROW;
1468     +extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int flags) __THROW;
1469    
1470     #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L
1471     __extension__ long long int strtoll(const char *nptr, char **endptr, int base) __THROW;
1472     @@ -43,7 +47,7 @@ double atof(const char *nptr) __THROW;
1473     __extension__ long long int atoll(const char *nptr);
1474    
1475     void exit(int status) __THROW __attribute__((__noreturn__));
1476     -void abort(void) __THROW;
1477     +void abort(void) __THROW __attribute__((__noreturn__));
1478    
1479     extern int rand(void) __THROW;
1480     extern int rand_r(unsigned int *seed) __THROW;
1481     diff --git a/include/sys/shm.h b/include/sys/shm.h
1482     index 9b2d04d..70bb17e 100644
1483     --- a/include/sys/shm.h
1484     +++ b/include/sys/shm.h
1485     @@ -60,15 +60,6 @@ struct shm_info {
1486     unsigned long swap_successes;
1487     };
1488    
1489     -#if defined(__i386__) || defined(__mips__) || defined(__arm__) || defined(__powerpc__) || defined (__powerpc64__) || defined(__s390__) || defined(__hppa__) || defined(__x86_64__) || defined(__ia64__)
1490     -#define PAGE_SIZE 4096UL
1491     -#define PAGE_SHIFT 12
1492     -#elif defined(__alpha__) || defined(__sparc__)
1493     -/* sun4* has 4k except sun4 architecture, sparc64 has 8k */
1494     -#define PAGE_SIZE 8192UL
1495     -#define PAGE_SHIFT 13
1496     -#endif
1497     -
1498     extern int shmget(key_t key, int size, int shmflg) __THROW;
1499     extern void *shmat(int shmid, const void *shmaddr, int shmflg) __THROW;
1500     extern int shmdt (const void *shmaddr) __THROW;
1501     diff --git a/lib/__dtostr.c b/lib/__dtostr.c
1502     index 1d082e3..bc61200 100644
1503     --- a/lib/__dtostr.c
1504     +++ b/lib/__dtostr.c
1505     @@ -5,13 +5,15 @@
1506    
1507     static int copystring(char* buf,int maxlen, const char* s) {
1508     int i;
1509     - for (i=0; i<3&&i<maxlen; ++i)
1510     + for (i=0; i<maxlen; ++i) {
1511     buf[i]=s[i];
1512     - if (i<maxlen) { buf[i]=0; ++i; }
1513     + if (!s[i])
1514     + break;
1515     + }
1516     return i;
1517     }
1518    
1519     -int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int g) {
1520     +int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int flags) {
1521     #if 1
1522     union {
1523     unsigned long long l;
1524     @@ -35,8 +37,12 @@ int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned i
1525     double tmp;
1526     char *oldbuf=buf;
1527    
1528     - if ((i=isinf(d))) return copystring(buf,maxlen,i>0?"inf":"-inf");
1529     - if (isnan(d)) return copystring(buf,maxlen,"nan");
1530     + if (isinf(d))
1531     + return copystring(buf,maxlen,
1532     + (d<0)?
1533     + (flags&0x02?"-INF":"-inf"):
1534     + (flags&0x02?"INF":"inf"));
1535     + if (isnan(d)) return copystring(buf,maxlen,flags&0x02?"NAN":"nan");
1536     e10=1+(long)(e*0.30102999566398119802); /* log10(2) */
1537     /* Wir iterieren von Links bis wir bei 0 sind oder maxlen erreicht
1538     * ist. Wenn maxlen erreicht ist, machen wir das nochmal in
1539     @@ -126,7 +132,7 @@ int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned i
1540     if (prec2 || prec>(unsigned int)(buf-oldbuf)+1) { /* more digits wanted */
1541     if (!maxlen) return 0; --maxlen;
1542     *buf='.'; ++buf;
1543     - if (g) {
1544     + if ((flags & 0x01)) {
1545     if (prec2) prec=prec2;
1546     prec-=buf-oldbuf-1;
1547     } else {
1548     diff --git a/lib/__get_elf_aux_value.c b/lib/__get_elf_aux_value.c
1549     new file mode 100644
1550     index 0000000..8a2e3bc
1551     --- /dev/null
1552     +++ b/lib/__get_elf_aux_value.c
1553     @@ -0,0 +1,14 @@
1554     +#include <stdlib.h>
1555     +#include "../dietelfinfo.h"
1556     +
1557     +__diet_elf_addr_t const *__get_elf_aux_value(unsigned int tag)
1558     +{
1559     + extern __diet_elf_addr_t const * const __elfinfo;
1560     + __diet_elf_addr_t const *aux_ptr;
1561     +
1562     + for (aux_ptr = __elfinfo; aux_ptr[0]!=AT_NULL; aux_ptr += 2)
1563     + if (aux_ptr[0]==tag)
1564     + return aux_ptr+1;
1565     +
1566     + return NULL;
1567     +}
1568     diff --git a/lib/__nice.c b/lib/__nice.c
1569     index d751104..8e205c0 100644
1570     --- a/lib/__nice.c
1571     +++ b/lib/__nice.c
1572     @@ -1,9 +1,13 @@
1573     #include "syscalls.h"
1574     -#include <sys/time.h>
1575     +#include <errno.h>
1576     #include <sys/resource.h>
1577    
1578     #ifndef __NR_nice
1579     int nice(int i) {
1580     - return setpriority(PRIO_PROCESS,0,getpriority(PRIO_PROCESS,0)+i);
1581     + if (setpriority(PRIO_PROCESS,0,getpriority(PRIO_PROCESS,0)+i) == -1) {
1582     + errno=EPERM;
1583     + return -1;
1584     + }
1585     + return getpriority(PRIO_PROCESS,0);
1586     }
1587     #endif
1588     diff --git a/lib/__utime.c b/lib/__utime.c
1589     index e013265..0e4d0df 100644
1590     --- a/lib/__utime.c
1591     +++ b/lib/__utime.c
1592     @@ -1,7 +1,10 @@
1593     -#include <utime.h>
1594     #include <syscalls.h>
1595    
1596     #ifndef __NR_utime
1597     +#define _BSD_SOURCE
1598     +#include <utime.h>
1599     +#include <sys/time.h>
1600     +
1601     int utime(const char *filename, const struct utimbuf *times)
1602     {
1603     if (times == NULL)
1604     diff --git a/lib/__v_printf.c b/lib/__v_printf.c
1605     index 36202f5..964c005 100644
1606     --- a/lib/__v_printf.c
1607     +++ b/lib/__v_printf.c
1608     @@ -4,6 +4,7 @@
1609     #include <stdlib.h>
1610     #include <string.h>
1611     #include <errno.h>
1612     +#include <math.h>
1613     #include "dietstdio.h"
1614     #include "dietwarning.h"
1615    
1616     @@ -346,45 +347,49 @@ num_printf:
1617     #ifdef WANT_FLOATING_POINT_IN_PRINTF
1618     /* print a floating point value */
1619     case 'f':
1620     + case 'F':
1621     case 'g':
1622     + case 'G':
1623     {
1624     - int g=(ch=='g');
1625     + int flags=(((ch&0x5f)=='G') ? 0x01 : 0x00) | ((ch&0x20) ? 0x00 : 0x02);
1626     double d=va_arg(arg_ptr,double);
1627     s=buf+1;
1628     if (width==0) width=1;
1629     if (!flag_dot) preci=6;
1630     if (flag_sign || d < +0.0) flag_in_sign=1;
1631    
1632     - sz=__dtostr(d,s,sizeof(buf)-1,width,preci,g);
1633     -
1634     - if (flag_dot) {
1635     - char *tmp;
1636     - if ((tmp=strchr(s,'.'))) {
1637     - if (preci || flag_hash) ++tmp;
1638     - while (preci>0 && *++tmp) --preci;
1639     - *tmp=0;
1640     - } else if (flag_hash) {
1641     - s[sz]='.';
1642     - s[++sz]='\0';
1643     + sz=__dtostr(d,s,sizeof(buf)-1,width,preci,flags);
1644     +
1645     + if (!isnan(d) && !isinf(d)) { /* skip NaN + INF values */
1646     + if (flag_dot) {
1647     + char *tmp;
1648     + if ((tmp=strchr(s,'.'))) {
1649     + if (preci || flag_hash) ++tmp;
1650     + while (preci>0 && *++tmp) --preci;
1651     + *tmp=0;
1652     + } else if (flag_hash) {
1653     + s[sz]='.';
1654     + s[++sz]='\0';
1655     + }
1656     }
1657     - }
1658    
1659     - if (g) {
1660     - char *tmp,*tmp1; /* boy, is _this_ ugly! */
1661     - if ((tmp=strchr(s,'.'))) {
1662     - tmp1=strchr(tmp,'e');
1663     - while (*tmp) ++tmp;
1664     - if (tmp1) tmp=tmp1;
1665     - while (*--tmp=='0') ;
1666     - if (*tmp!='.') ++tmp;
1667     - *tmp=0;
1668     - if (tmp1) strcpy(tmp,tmp1);
1669     + if ((flags&0x01)) {
1670     + char *tmp,*tmp1; /* boy, is _this_ ugly! */
1671     + if ((tmp=strchr(s,'.'))) {
1672     + tmp1=strchr(tmp,'e');
1673     + while (*tmp) ++tmp;
1674     + if (tmp1) tmp=tmp1;
1675     + while (*--tmp=='0') ;
1676     + if (*tmp!='.') ++tmp;
1677     + *tmp=0;
1678     + if (tmp1) strcpy(tmp,tmp1);
1679     + }
1680     }
1681     - }
1682    
1683     - if ((flag_sign || flag_space) && d>=0) {
1684     - *(--s)=(flag_sign)?'+':' ';
1685     - ++sz;
1686     + if ((flag_sign || flag_space) && d>=0) {
1687     + *(--s)=(flag_sign)?'+':' ';
1688     + ++sz;
1689     + }
1690     }
1691    
1692     sz=strlen(s);
1693     diff --git a/lib/alloc.c b/lib/alloc.c
1694     index 9690565..3f0cedb 100644
1695     --- a/lib/alloc.c
1696     +++ b/lib/alloc.c
1697     @@ -18,8 +18,7 @@
1698     #include <stdlib.h>
1699     #include <string.h>
1700    
1701     -#include <sys/shm.h> /* for PAGE_SIZE */
1702     -
1703     +#include "../dietpagesize.h"
1704    
1705     /* -- HELPER CODE --------------------------------------------------------- */
1706    
1707     @@ -39,7 +38,7 @@ typedef struct {
1708     #define BLOCK_START(b) (((void*)(b))-sizeof(__alloc_t))
1709     #define BLOCK_RET(b) (((void*)(b))+sizeof(__alloc_t))
1710    
1711     -#define MEM_BLOCK_SIZE PAGE_SIZE
1712     +#define MEM_BLOCK_SIZE __DIET_PAGE_SIZE
1713     #define PAGE_ALIGN(s) (((s)+MEM_BLOCK_SIZE-1)&(unsigned long)(~(MEM_BLOCK_SIZE-1)))
1714    
1715     /* a simple mmap :) */
1716     @@ -66,7 +65,9 @@ static __alloc_t* __small_mem[8];
1717    
1718     #define FIRST_SMALL(p) (((unsigned long)(p))&(~(MEM_BLOCK_SIZE-1)))
1719    
1720     -static inline int __ind_shift() { return (MEM_BLOCK_SIZE==4096)?4:5; }
1721     +static inline int __ind_shift() {
1722     + return __DIET_PAGE_SHIFT - sizeof(__small_mem)/sizeof(__small_mem[0]);
1723     +}
1724    
1725     static size_t REGPARM(1) get_index(size_t _size) {
1726     register size_t idx=0;
1727     diff --git a/lib/closedir.c b/lib/closedir.c
1728     index 3aade81..21de234 100644
1729     --- a/lib/closedir.c
1730     +++ b/lib/closedir.c
1731     @@ -4,8 +4,10 @@
1732     #include <dirent.h>
1733     #include <stdlib.h>
1734    
1735     +#include "../dietpagesize.h"
1736     +
1737     int closedir (DIR* d) {
1738     int res=close(d->fd);
1739     - munmap (d, PAGE_SIZE);
1740     + munmap (d, __DIET_PAGE_SIZE);
1741     return res;
1742     }
1743     diff --git a/lib/mmap64.c b/lib/mmap64.c
1744     index 0ab29a6..5012394 100644
1745     --- a/lib/mmap64.c
1746     +++ b/lib/mmap64.c
1747     @@ -4,16 +4,18 @@
1748     #include <syscalls.h>
1749     #include <errno.h>
1750    
1751     +#include "../dietpagesize.h"
1752     +
1753     #ifdef __NR_mmap2
1754     void*__mmap2(void*start,size_t length,int prot,int flags,int fd,off_t pgoffset);
1755    
1756     void*__libc_mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset);
1757     void*__libc_mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset) {
1758     - if (offset&(PAGE_SIZE-1)) {
1759     + if (offset&(__DIET_PAGE_SIZE)) {
1760     errno=-EINVAL;
1761     return MAP_FAILED;
1762     }
1763     - return __mmap2(addr,len,prot,flags,fd,offset>>PAGE_SHIFT);
1764     + return __mmap2(addr,len,prot,flags,fd,offset>>__DIET_PAGE_SHIFT);
1765     }
1766    
1767     void*mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset)
1768     diff --git a/lib/opendir.c b/lib/opendir.c
1769     index 2530d1a..847685e 100644
1770     --- a/lib/opendir.c
1771     +++ b/lib/opendir.c
1772     @@ -5,6 +5,8 @@
1773     #include <stdlib.h>
1774     #include <fcntl.h>
1775    
1776     +#include "../dietpagesize.h"
1777     +
1778     DIR* opendir ( const char* name ) {
1779     int fd = open (name, O_RDONLY | O_DIRECTORY);
1780     DIR* t = NULL;
1781     @@ -12,7 +14,7 @@ DIR* opendir ( const char* name ) {
1782     if ( fd >= 0 ) {
1783     if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
1784     goto lose;
1785     - t = (DIR *) mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
1786     + t = (DIR *) mmap (NULL, __DIET_PAGE_SIZE, PROT_READ | PROT_WRITE,
1787     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1788     if (t == MAP_FAILED)
1789     lose:
1790     diff --git a/lib/readdir.c b/lib/readdir.c
1791     index ed885a5..d80a406 100644
1792     --- a/lib/readdir.c
1793     +++ b/lib/readdir.c
1794     @@ -5,7 +5,7 @@
1795    
1796     struct dirent* readdir(DIR *d) {
1797     if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) {
1798     - int res=getdents(d->fd,(struct dirent*)d->buf,sizeof (d->buf)-1);
1799     + int res=getdents(d->fd,(struct dirent*)d->buf,__DIRSTREAM_BUF_SIZE-1);
1800     if (res<=0) return 0;
1801     d->num=res; d->cur=0;
1802     }
1803     diff --git a/lib/readdir64.c b/lib/readdir64.c
1804     index 924f0a8..06d073b 100644
1805     --- a/lib/readdir64.c
1806     +++ b/lib/readdir64.c
1807     @@ -14,7 +14,7 @@
1808     #ifndef WANT_LARGEFILE_BACKCOMPAT
1809     struct dirent64* readdir64(DIR *d) {
1810     if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) {
1811     - int res=getdents64(d->fd,(struct dirent64*)d->buf, sizeof (d->buf)-1);
1812     + int res=getdents64(d->fd,(struct dirent64*)d->buf, __DIRSTREAM_BUF_SIZE-1);
1813     if (res<=0) return 0;
1814     d->num=res; d->cur=0;
1815     }
1816     @@ -32,7 +32,7 @@ again:
1817     if (!trygetdents64) {
1818     #endif
1819     if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) {
1820     - int res=getdents(d->fd,(struct dirent*)d->buf, sizeof (d->buf)-1);
1821     + int res=getdents(d->fd,(struct dirent*)d->buf, __DIRSTREAM_BUF_SIZE-1);
1822     if (res<=0) return 0;
1823     d->num=res; d->cur=0;
1824     }
1825     @@ -46,7 +46,7 @@ again:
1826     #ifdef __NR_getdents64
1827     }
1828     if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) {
1829     - int res=getdents64(d->fd,(struct dirent64*)d->buf,sizeof (d->buf));
1830     + int res=getdents64(d->fd,(struct dirent64*)d->buf,__DIRSTREAM_BUF_SIZE);
1831     if (res<=0) {
1832     if (errno==ENOSYS) {
1833     trygetdents64=0;
1834     diff --git a/lib/stack_smash_handler2.c b/lib/stack_smash_handler2.c
1835     index 9e85099..83c0cef 100644
1836     --- a/lib/stack_smash_handler2.c
1837     +++ b/lib/stack_smash_handler2.c
1838     @@ -8,5 +8,16 @@ void __stack_chk_fail(void);
1839     * diagnostics. No more. :-( */
1840     void __stack_chk_fail(void) {
1841     __write2("smashed stack detected, program terminated.\n");
1842     - _exit(127);
1843     +
1844     + /* trigger a segfault which can be inspected within a debugger (inclusive
1845     + * stack-trace). 'abort(3)' at this place would be too heavy weighted.
1846     + *
1847     + * TODO: limit this to systems which are known to have an MMU (resp. is
1848     + * dietlibc with stack-protector used on systems without an MMU?)
1849     + */
1850     + *(char volatile *)0 = 0;
1851     + while (1) {
1852     + asm("");
1853     + __builtin_unreachable();
1854     + }
1855     }
1856     diff --git a/lib/stackgap.c b/lib/stackgap.c
1857     index 6f1f5c4..1a3af01 100644
1858     --- a/lib/stackgap.c
1859     +++ b/lib/stackgap.c
1860     @@ -16,6 +16,7 @@
1861     #include <elf.h>
1862     #include <stdlib.h>
1863     #include "dietfeatures.h"
1864     +#include "dietelfinfo.h"
1865    
1866     #ifdef WANT_GNU_STARTUP_BLOAT
1867     char* program_invocation_name;
1868     @@ -48,11 +49,12 @@ void* __tdataptr;
1869    
1870     static void findtlsdata(long* auxvec) {
1871     #if (__WORDSIZE == 64)
1872     - Elf64_Phdr* x=0;
1873     + Elf64_Phdr const * x=0;
1874     #else
1875     - Elf32_Phdr* x=0;
1876     + Elf32_Phdr const * x=0;
1877     #endif
1878     size_t i,n=0;
1879     +#ifndef WANT_ELFINFO
1880     while (*auxvec) {
1881     if (auxvec[0]==3) { /* AT_PHDR */
1882     x=(void*)auxvec[1];
1883     @@ -63,6 +65,18 @@ static void findtlsdata(long* auxvec) {
1884     }
1885     auxvec+=2;
1886     } /* if we don't find the entry, the kernel let us down */
1887     +#else
1888     + {
1889     + __diet_elf_addr_t const *x_addr = __get_elf_aux_value(AT_PHDR);
1890     + __diet_elf_addr_t const *n_addr = __get_elf_aux_value(AT_PHNUM);
1891     +
1892     + (void)auxvec;
1893     + if (x_addr)
1894     + x = (__typeof__(x)) *x_addr;
1895     + if (n_addr)
1896     + n = *n_addr;
1897     + }
1898     +#endif
1899     if (!x || !n) return; /* a kernel this old does not support thread local storage anyway */
1900     for (i=0; i<n; ++i)
1901     if (x[i].p_type==PT_TLS) {
1902     @@ -123,6 +137,7 @@ void __setup_tls(tcbhead_t* mainthread) {
1903     }
1904     #endif
1905    
1906     +#ifndef WANT_ELFINFO
1907     static void* find_rand(long* x) {
1908     while (*x) {
1909     if (*x==25)
1910     @@ -131,20 +146,30 @@ static void* find_rand(long* x) {
1911     }
1912     return NULL;
1913     }
1914     +#endif
1915    
1916     int stackgap(int argc,char* argv[],char* envp[]);
1917     int stackgap(int argc,char* argv[],char* envp[]) {
1918     #if defined(WANT_STACKGAP) || defined(WANT_SSP) || defined(WANT_TLS)
1919     - long* auxvec=(long*)envp;
1920     char* rand;
1921     char* tlsdata;
1922     +#ifndef WANT_ELFINFO
1923     + long* auxvec=(long*)envp;
1924     while (*auxvec) ++auxvec; ++auxvec; /* skip envp to get to auxvec */
1925     +#endif
1926     #ifdef WANT_STACKGAP
1927     unsigned short s;
1928     + volatile char* gap;
1929     #endif
1930     #if defined(WANT_STACKGAP) || defined(WANT_SSP)
1931     - volatile char* gap;
1932     +#ifndef WANT_ELFINFO
1933     rand=find_rand(auxvec);
1934     +#else
1935     + {
1936     + __diet_elf_addr_t const *rand_addr = __get_elf_aux_value(25);
1937     + rand = rand_addr ? (void *)*rand_addr : NULL;
1938     + }
1939     +#endif
1940     if (!rand) {
1941     char myrand[10];
1942     int fd=open("/dev/urandom",O_RDONLY);
1943     @@ -165,7 +190,11 @@ int stackgap(int argc,char* argv[],char* envp[]) {
1944     #endif
1945    
1946     #ifdef WANT_TLS
1947     +#ifndef WANT_ELFINFO
1948     findtlsdata(auxvec);
1949     +#else
1950     + findtlsdata(NULL);
1951     +#endif
1952     if (__unlikely(__tmemsize+sizeof(tcbhead_t)<sizeof(tcbhead_t)) ||
1953     __unlikely(__tmemsize>512*1024*1024) ||
1954     __unlikely(__tmemsize<__tdatasize))
1955     diff --git a/libcompat/syscall.S b/libcompat/syscall.S
1956     index c9f72bb..4188167 100644
1957     --- a/libcompat/syscall.S
1958     +++ b/libcompat/syscall.S
1959     @@ -130,6 +130,12 @@ syscall:
1960     b __unified_syscall
1961    
1962     #else
1963     - /* arch not implemented yet */
1964     +#include <endian.h>
1965     + .section .comment
1966     +#if (__WORDSIZE == 64)
1967     + .quad __syscall_2_not_implemented_for_this_arch
1968     +#else
1969     + .long __syscall_2_not_implemented_for_this_arch
1970     +#endif
1971     #endif
1972     .size syscall, . - syscall
1973     diff --git a/libcruft/getpagesize.c b/libcruft/getpagesize.c
1974     index 5ff8973..ac701cf 100644
1975     --- a/libcruft/getpagesize.c
1976     +++ b/libcruft/getpagesize.c
1977     @@ -1,25 +1,23 @@
1978     #include <sys/types.h>
1979     #include <sys/ipc.h>
1980     #include <sys/shm.h>
1981     -/* for environ: */
1982     -#include <stdlib.h>
1983    
1984     -#ifndef PAGE_SIZE
1985     -#define PAGE_SIZE 4096
1986     -#endif
1987     +#include "../dietelfinfo.h"
1988     +#include "../dietpagesize.h"
1989    
1990     -size_t __libc_getpagesize(void);
1991     size_t __libc_getpagesize(void) {
1992     - long* x=(long*)environ;
1993     - int fd;
1994     - while (*x) ++x; ++x; /* skip envp to get to auxvec */
1995     - while (*x) {
1996     - if (*x==6)
1997     - return x[1];
1998     - x+=2;
1999     +#ifdef WANT_DYN_PAGESIZE
2000     + static size_t pgsz;
2001     +
2002     + if (__unlikely(pgsz==0)) {
2003     + __diet_elf_addr_t const *v = __get_elf_aux_value(AT_PAGESZ);
2004     + pgsz = *v; /* causes segfault when 'v==NULL' */
2005     }
2006     - return PAGE_SIZE;
2007     +
2008     + return pgsz;
2009     +#else
2010     + return __DIET_PAGE_SIZE_PREDEF;
2011     +#endif
2012     }
2013    
2014     size_t getpagesize(void) __attribute__((weak,alias("__libc_getpagesize")));
2015     -
2016     diff --git a/libcruft/mkstemp.c b/libcruft/mkstemp.c
2017     index 7dc19d4..226dec4 100644
2018     --- a/libcruft/mkstemp.c
2019     +++ b/libcruft/mkstemp.c
2020     @@ -1,3 +1,4 @@
2021     +#define _FILE_OFFSET_BITS 64
2022     #include <unistd.h>
2023     #include <fcntl.h>
2024     #include <string.h>
2025     diff --git a/libcruft/sysconf.c b/libcruft/sysconf.c
2026     index 6865026..089fbd3 100644
2027     --- a/libcruft/sysconf.c
2028     +++ b/libcruft/sysconf.c
2029     @@ -6,6 +6,9 @@
2030     #define _GNU_SOURCE
2031     #include <sched.h>
2032    
2033     +#include "dietelfinfo.h"
2034     +#include "dietpagesize.h"
2035     +
2036     extern int __sc_nr_cpus();
2037    
2038     static long physpages() {
2039     @@ -42,6 +45,14 @@ long sysconf(int name)
2040     return limit.rlim_cur;
2041     }
2042     case _SC_CLK_TCK:
2043     +#ifdef WANT_ELFINFO
2044     + {
2045     + __diet_elf_addr_t const *v = __get_elf_aux_value(AT_CLKTCK);
2046     + if (v)
2047     + return *v;
2048     + }
2049     +#endif
2050     +
2051     #ifdef __alpha__
2052     return 1024;
2053     #else
2054     @@ -49,11 +60,7 @@ long sysconf(int name)
2055     #endif
2056    
2057     case _SC_PAGESIZE:
2058     -#if ( defined(__alpha__) || defined(__sparc__) )
2059     - return 8192;
2060     -#else
2061     - return 4096;
2062     -#endif
2063     + return __libc_getpagesize();
2064    
2065     case _SC_PHYS_PAGES:
2066     return physpages();
2067     diff --git a/libm/ceil.c b/libm/ceil.c
2068     new file mode 100644
2069     index 0000000..c126b02
2070     --- /dev/null
2071     +++ b/libm/ceil.c
2072     @@ -0,0 +1,92 @@
2073     +/* @(#)s_ceil.c 5.1 93/09/24 */
2074     +/*
2075     + * ====================================================
2076     + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
2077     + *
2078     + * Developed at SunPro, a Sun Microsystems, Inc. business.
2079     + * Permission to use, copy, modify, and distribute this
2080     + * software is freely granted, provided that this notice
2081     + * is preserved.
2082     + * ====================================================
2083     + */
2084     +
2085     +/*
2086     + * ceil(x)
2087     + * Return x rounded toward -inf to integral value
2088     + * Method:
2089     + * Bit twiddling.
2090     + * Exception:
2091     + * Inexact flag raised if x not equal to ceil(x).
2092     + */
2093     +
2094     +#include <math.h>
2095     +
2096     +typedef union {
2097     + double value;
2098     + struct {
2099     + unsigned int lsw;
2100     + unsigned int msw;
2101     + } parts;
2102     +} ieee_double_shape_type;
2103     +
2104     +/* Get two 32 bit ints from a double. */
2105     +
2106     +#define EXTRACT_WORDS(ix0,ix1,d) \
2107     +do { \
2108     + ieee_double_shape_type ew_u; \
2109     + ew_u.value = (d); \
2110     + (ix0) = ew_u.parts.msw; \
2111     + (ix1) = ew_u.parts.lsw; \
2112     +} while (0)
2113     +
2114     +#define INSERT_WORDS(d,ix0,ix1) \
2115     +do { \
2116     + ieee_double_shape_type iw_u; \
2117     + iw_u.parts.msw = (ix0); \
2118     + iw_u.parts.lsw = (ix1); \
2119     + (d) = iw_u.value; \
2120     +} while (0)
2121     +
2122     +static const double huge = 1.0e300;
2123     +
2124     +double ceil(double x)
2125     +{
2126     + int i0,i1,j0;
2127     + unsigned int i,j;
2128     + EXTRACT_WORDS(i0,i1,x);
2129     + j0 = ((i0>>20)&0x7ff)-0x3ff;
2130     + if(j0<20) {
2131     + if(j0<0) { /* raise inexact if x != 0 */
2132     + if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
2133     + if(i0<0) {i0=0x80000000;i1=0;}
2134     + else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
2135     + }
2136     + } else {
2137     + i = (0x000fffff)>>j0;
2138     + if(((i0&i)|i1)==0) return x; /* x is integral */
2139     + if(huge+x>0.0) { /* raise inexact flag */
2140     + if(i0>0) i0 += (0x00100000)>>j0;
2141     + i0 &= (~i); i1=0;
2142     + }
2143     + }
2144     + } else if (j0>51) {
2145     + if(j0==0x400) return x+x; /* inf or NaN */
2146     + else return x; /* x is integral */
2147     + } else {
2148     + i = ((unsigned int)(0xffffffff))>>(j0-20);
2149     + if((i1&i)==0) return x; /* x is integral */
2150     + if(huge+x>0.0) { /* raise inexact flag */
2151     + if(i0>0) {
2152     + if(j0==20) i0+=1;
2153     + else {
2154     + j = i1 + (1<<(52-j0));
2155     + if(j<i1) i0+=1; /* got a carry */
2156     + i1 = j;
2157     + }
2158     + }
2159     + i1 &= (~i);
2160     + }
2161     + }
2162     + INSERT_WORDS(x,i0,i1);
2163     + return x;
2164     +}
2165     diff --git a/libm/gamma.c b/libm/gamma.c
2166     index 9682f35..370bec6 100644
2167     --- a/libm/gamma.c
2168     +++ b/libm/gamma.c
2169     @@ -33,19 +33,19 @@ Return value gamma returns a value in range (-0.1208, +oo). For a input
2170     #include <stdlib.h>
2171     #include <math.h>
2172    
2173     -#define B0 + 1.0l/ 6/ 1/ 2
2174     -#define B1 - 1.0l/ 30/ 3/ 4
2175     -#define B2 + 1.0l/ 42/ 5/ 6
2176     -#define B3 - 1.0l/ 30/ 7/ 8
2177     -#define B4 + 5.0l/ 66/ 9/10
2178     -#define B5 - 691.0l/2730/11/12
2179     -#define B6 + 7.0l/ 6/13/14
2180     -#define B7 - 3617.0l/ 510/15/16
2181     -#define B8 + 43867.0l/ 798/17/18
2182     -#define B9 - 174611.0l/ 330/19/20
2183     -#define B10 + 854513.0l/ 138/21/22
2184     -#define B11 - 236364091.0l/2730/23/24
2185     -#define B12 + 8553103.0l/ 6/25/26
2186     +#define B0 + 1.0/ 6/ 1/ 2
2187     +#define B1 - 1.0/ 30/ 3/ 4
2188     +#define B2 + 1.0/ 42/ 5/ 6
2189     +#define B3 - 1.0/ 30/ 7/ 8
2190     +#define B4 + 5.0/ 66/ 9/10
2191     +#define B5 - 691.0/2730/11/12
2192     +#define B6 + 7.0/ 6/13/14
2193     +#define B7 - 3617.0/ 510/15/16
2194     +#define B8 + 43867.0/ 798/17/18
2195     +#define B9 - 174611.0/ 330/19/20
2196     +#define B10 + 854513.0/ 138/21/22
2197     +#define B11 - 236364091.0/2730/23/24
2198     +#define B12 + 8553103.0/ 6/25/26
2199    
2200     static const double coeff[] = { B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10 };
2201     int signgam;
2202     diff --git a/librpc/clnt_raw.c b/librpc/clnt_raw.c
2203     index 042d130..1e89ac0 100644
2204     --- a/librpc/clnt_raw.c
2205     +++ b/librpc/clnt_raw.c
2206     @@ -53,7 +53,10 @@ static struct clntraw_private {
2207     CLIENT client_object;
2208     XDR xdr_stream;
2209     char _raw_buf[UDPMSGSIZE];
2210     - char mashl_callmsg[MCALL_MSG_SIZE];
2211     + union {
2212     + struct rpc_msg msg;
2213     + char buf[MCALL_MSG_SIZE];
2214     + } mashl_call;
2215     unsigned int mcnt;
2216     } *clntraw_private;
2217    
2218     @@ -101,7 +104,7 @@ unsigned long vers;
2219     call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
2220     call_msg.rm_call.cb_prog = prog;
2221     call_msg.rm_call.cb_vers = vers;
2222     - xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
2223     + xdrmem_create(xdrs, clp->mashl_call.buf, MCALL_MSG_SIZE, XDR_ENCODE);
2224     if (!xdr_callhdr(xdrs, &call_msg)) {
2225     perror("clnt_raw.c - Fatal header serialization error.");
2226     }
2227     @@ -145,8 +148,8 @@ struct timeval timeout;
2228     */
2229     xdrs->x_op = XDR_ENCODE;
2230     XDR_SETPOS(xdrs, 0);
2231     - ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
2232     - if ((!XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
2233     + clp->mashl_call.msg.rm_xid++;
2234     + if ((!XDR_PUTBYTES(xdrs, clp->mashl_call.buf, clp->mcnt)) ||
2235     (!XDR_PUTLONG(xdrs, (long *) &proc)) ||
2236     (!AUTH_MARSHALL(h->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp))) {
2237     return (RPC_CANTENCODEARGS);
2238     diff --git a/librpc/clnt_udp.c b/librpc/clnt_udp.c
2239     index ae7f3d8..003edf5 100644
2240     --- a/librpc/clnt_udp.c
2241     +++ b/librpc/clnt_udp.c
2242     @@ -335,7 +335,7 @@ struct timeval utimeout; /* seconds to wait before giving up */
2243     if (inlen < 4)
2244     continue;
2245     /* see if reply transaction id matches sent id */
2246     - if (*((uint32_t *) (cu->cu_inbuf)) != *((uint32_t *) (cu->cu_outbuf)))
2247     + if (memcmp(cu->cu_inbuf, cu->cu_outbuf, 4) != 0)
2248     continue;
2249     /* we now assume we have the proper reply */
2250     break;
2251     diff --git a/libugly/strftime.c b/libugly/strftime.c
2252     index 56ae082..cf16f37 100644
2253     --- a/libugly/strftime.c
2254     +++ b/libugly/strftime.c
2255     @@ -55,6 +55,7 @@ again:
2256     case 'x': src = "%b %a %d"; goto _strf;
2257     case 'X': src = "%k:%M:%S"; goto _strf;
2258     case 'D': src = "%m/%d/%y"; goto _strf;
2259     + case 'F': src = "%Y-%m-%d"; goto _strf;
2260     case 'T': src = "%H:%M:%S";
2261     _strf: p += strftime (p, (size_t)(dst+max-p), src, tm); break;
2262     case 'a': src = sweekdays [tm->tm_wday]; goto _str;
2263     diff --git a/libugly/strptime.c b/libugly/strptime.c
2264     index 9d7f530..d19f309 100644
2265     --- a/libugly/strptime.c
2266     +++ b/libugly/strptime.c
2267     @@ -119,10 +119,11 @@ char* strptime(const char* s,const char* format, struct tm* tm) {
2268     ++s;
2269     break;
2270     case 'x':
2271     - s=strptime(s,"%b %a %d",tm);
2272     + /* see SUSv2, Ch.7 "LC_TIME Category in the POSIX Locale" */
2273     + s=strptime(s,"%m/%d/%y",tm);
2274     break;
2275     case 'X':
2276     - s=strptime(s,"%k:%M:%S",tm);
2277     + s=strptime(s,"%H:%M:%S",tm);
2278     break;
2279     case 'y':
2280     i=getint(&s,2);
2281     diff --git a/mips/start.S b/mips/start.S
2282     index 57144b3..3cf3433 100644
2283     --- a/mips/start.S
2284     +++ b/mips/start.S
2285     @@ -47,6 +47,15 @@ __start:
2286     #endif
2287     add $a2, $a2, $a1
2288     sw $a2, environ
2289     +#ifdef WANT_ELFINFO
2290     +# warning "MAKE ME MIPS CODE!"
2291     +1: addu $a2, $a2, 4 /* increment envp */
2292     + lw $4, -4($a2) /* load envp[-1]; TODO: is $4 a proper
2293     + temporary register? */
2294     + bnz 1b /* ... until envp[-1]==NULL
2295     + TODO: use proper 'bnz' operation */
2296     + sw $a2, __elfinfo
2297     +#endif
2298     jalr $25
2299     la $25, exit
2300     move $4,$2
2301     diff --git a/parisc/start.S b/parisc/start.S
2302     index 69d9cce..894255c 100644
2303     --- a/parisc/start.S
2304     +++ b/parisc/start.S
2305     @@ -34,6 +34,16 @@ _start:
2306     ldil LP%environ, %r19
2307     ldo RP%environ(%r19), %r19
2308    
2309     +#ifdef WANT_ELFINFO
2310     +# warning "MAKE ME PARISC CODE!"
2311     +1: add %r20, %r19, %r19 ; envp += 4
2312     + ldw -4(0,%r19), %r21 ; load envp[-4] into %r21
2313     + comibf =,0, 0,%21,1b ; compare %21 with 0 without nullification
2314     +
2315     + ldil LP%__elfinfo, %r19
2316     + ldo RP%__elfinfo(%r19), %r19
2317     +#endif
2318     +
2319     /* Expand the stack to store the 5th through 7th args */
2320     ldo 64(%sp), %sp
2321    
2322     diff --git a/ppc/start.S b/ppc/start.S
2323     index 771f1ad..3b5cab1 100644
2324     --- a/ppc/start.S
2325     +++ b/ppc/start.S
2326     @@ -31,6 +31,15 @@ _start:
2327     lis 14,environ@ha
2328     stw 5,environ@l(14)
2329    
2330     +#ifdef WANT_ELFINFO
2331     +1: lwzu 15,0(5)
2332     + addi 5, 5, 4
2333     + cmpwi 15,0
2334     + bne 1b
2335     +
2336     + stw 5,__elfinfo@l(14)
2337     +#endif
2338     +
2339     #ifdef WANT_DYNAMIC
2340     mr 6,7
2341     bl _dyn_start
2342     diff --git a/ppc64/start.S b/ppc64/start.S
2343     index a9208ff..46b4bf0 100644
2344     --- a/ppc64/start.S
2345     +++ b/ppc64/start.S
2346     @@ -58,6 +58,15 @@ _start:
2347     oris 14,14,environ@ha
2348     std 5,environ@l(14)
2349    
2350     +#ifdef WANT_ELFINFO
2351     +1: ldu 15,0(5)
2352     + addi 5, 5, 8
2353     + cmpdi 15,0
2354     + bne 1b
2355     +
2356     + std 5,__elfinfo@l(14)
2357     +#endif
2358     +
2359     #ifdef WANT_DYNAMIC
2360     /* #warning dynamic */
2361     mr 6,7
2362     diff --git a/s390/start.S b/s390/start.S
2363     index c0f971f..585faf7 100644
2364     --- a/s390/start.S
2365     +++ b/s390/start.S
2366     @@ -30,6 +30,17 @@ _start:
2367     l %r1,8(%r13)
2368     st %r4,0(%r1)
2369    
2370     +#ifdef WANT_ELFINFO
2371     +# warning "VERIFY ME!"
2372     +1: ahi %r4, 4 # increment envp
2373     + l %r12, -4(0,%r4) # load envp[-1] into %r12
2374     + or %r12, %r12 # test %r12 for NULL
2375     + brc 1, 1b
2376     +
2377     + ahi %r1, 4
2378     + st %r4,0(%r1)
2379     +#endif
2380     +
2381     /* call main or _dyn_start */
2382     l %r1,0(%r13)
2383     basr %r14,%r1
2384     diff --git a/s390x/start.S b/s390x/start.S
2385     index 25895a6..15ad1f9 100644
2386     --- a/s390x/start.S
2387     +++ b/s390x/start.S
2388     @@ -26,6 +26,17 @@ _start:
2389     larl %r13,environ
2390     stg %r4,0(%r13)
2391    
2392     +#ifdef WANT_ELFINFO
2393     +# warning "VERIFY ME!"
2394     +1: aghi %r4, 8 # increment envp
2395     + lg %r12, -8(0,%r4) # load envp[-1] into %r12
2396     + ogr %r12, %r12 # test %r12 for NULL
2397     + brc 1, 1b
2398     +
2399     + aghi %r13, 8
2400     + stg %r4,0(%r13)
2401     +#endif
2402     +
2403     /* call main or _dyn_start */
2404     #ifdef WANT_DYNAMIC
2405     brasl %r14,_dyn_start
2406     diff --git a/sparc/shmat.c b/sparc/shmat.c
2407     index b7dce2e..ce3bfcb 100644
2408     --- a/sparc/shmat.c
2409     +++ b/sparc/shmat.c
2410     @@ -3,17 +3,15 @@
2411     #include <sys/shm.h>
2412     #include <unistd.h>
2413    
2414     -extern void* __ipc();
2415     +#include "../dietpagesize.h"
2416    
2417     -#ifndef PAGE_SIZE
2418     -#define PAGE_SIZE 4096
2419     -#endif
2420     +extern void* __ipc();
2421    
2422     void* shmat(int shmid,const void* shmaddr,int shmflg) {
2423     void* raddr;
2424     register void* result;
2425     result=__ipc(SHMAT,shmid,shmflg,&raddr,shmaddr);
2426     - if ((unsigned long)result <= -(unsigned long)PAGE_SIZE)
2427     + if ((unsigned long)result <= -(unsigned long)__DIET_PAGE_SIZE)
2428     result=raddr;
2429     return result;
2430     }
2431     diff --git a/sparc/start.S b/sparc/start.S
2432     index a7841e3..bb463c9 100644
2433     --- a/sparc/start.S
2434     +++ b/sparc/start.S
2435     @@ -25,6 +25,17 @@ _start:
2436     or %o3, %lo(environ), %o3
2437     st %o2, [%o3]
2438    
2439     +#ifdef WANT_ELFINFO
2440     +# warning "VERIFY ME!"
2441     +1: add %o2, %o2, 4
2442     + ld [%o2-4], %o4
2443     + orcc %o4, %o4, %o4
2444     + bne 1b
2445     +
2446     + add %o3, %o3, 4
2447     + st %o2, [%o3]
2448     +#endif
2449     +
2450     /* When starting a binary via the dynamic linker, %g1 contains the
2451     address of the shared library termination function, which will be
2452     registered with atexit(). If we are statically linked, this will
2453     diff --git a/sparc64/start.S b/sparc64/start.S
2454     index a79c4e7..a884658 100644
2455     --- a/sparc64/start.S
2456     +++ b/sparc64/start.S
2457     @@ -25,6 +25,17 @@ _start:
2458     or %o3, %lo(environ), %o3
2459     stx %o2, [%o3]
2460    
2461     +#ifdef WANT_ELFINFO
2462     +# warning "VERIFY ME!"
2463     +1: add %o2, %o2, 8
2464     + ldx [%o2-8], %o4
2465     + orcc %o4, %o4, %o4
2466     + bne 1b
2467     +
2468     + add %o3, %o3, 8
2469     + stx %o2, [%o3]
2470     +#endif
2471     +
2472     /* When starting a binary via the dynamic linker, %g1 contains the
2473     address of the shared library termination function, which will be
2474     registered with atexit(). If we are statically linked, this will
2475     diff --git a/syscalls.s/environ.S b/syscalls.s/environ.S
2476     index a4dd95e..294f2d4 100644
2477     --- a/syscalls.s/environ.S
2478     +++ b/syscalls.s/environ.S
2479     @@ -1,6 +1,7 @@
2480     .section ".bss"
2481     .align 8
2482     #include <endian.h>
2483     +#include <dietfeatures.h>
2484    
2485     .type environ,object
2486     .weak environ
2487     @@ -15,3 +16,18 @@ environ:
2488     #endif
2489     .size environ,.-environ
2490     .size __environ,.-__environ
2491     +
2492     +/* __elfinfo will be initialized in start.S to point to the
2493     + terminating NULL of the environment. */
2494     +
2495     +#ifdef WANT_ELFINFO
2496     +.type __elfinfo,object
2497     +.weak __elfinfo
2498     +__elfinfo:
2499     +#if __WORDSIZE == 64
2500     + .quad 0
2501     +#else
2502     + .long 0
2503     +#endif
2504     +.size __elfinfo,.-__elfinfo
2505     +#endif
2506     diff --git a/syscalls.s/fadvise64.S b/syscalls.s/fadvise64.S
2507     index eab3986..fe448b1 100644
2508     --- a/syscalls.s/fadvise64.S
2509     +++ b/syscalls.s/fadvise64.S
2510     @@ -1,12 +1,11 @@
2511     #include "syscalls.h"
2512    
2513     +#ifdef __NR_fadvise64
2514     +syscall(fadvise64,fadvise64)
2515     +
2516     #ifndef __NR_fadvise64_64
2517     +.set posix_fadvise, fadvise64
2518     .globl posix_fadvise
2519     -.type posix_fadvise,@function
2520     -posix_fadvise:
2521     #endif
2522    
2523     -#ifdef __NR_fadvise64
2524     -syscall(fadvise64,fadvise64)
2525     -
2526     #endif
2527     diff --git a/test/.gitignore b/test/.gitignore
2528     new file mode 100644
2529     index 0000000..92c5678
2530     --- /dev/null
2531     +++ b/test/.gitignore
2532     @@ -0,0 +1,85 @@
2533     +/adjtime
2534     +/alarm
2535     +/argv
2536     +/asprintf
2537     +/atexit
2538     +/bsearch
2539     +/byteswap
2540     +/calloc
2541     +/confstr
2542     +/cycles
2543     +/empty
2544     +/fadvise
2545     +/ffs
2546     +/flush
2547     +/fnmatch
2548     +/fputc
2549     +/ftruncate
2550     +/ftw
2551     +/fwrite
2552     +/getaddrinfo
2553     +/getdelim
2554     +/getenv
2555     +/getgrnam
2556     +/gethostbyaddr
2557     +/gethostbyname
2558     +/gethostbyname_r
2559     +/getmntent
2560     +/getopt
2561     +/getpass
2562     +/getpwnam
2563     +/getservbyname
2564     +/getservbyport
2565     +/getusershell
2566     +/glob
2567     +/grent
2568     +/hasmntopt
2569     +/hello
2570     +/iconv
2571     +/if_nameindex
2572     +/ltostr
2573     +/malloc-debugger
2574     +/math
2575     +/md5_testharness
2576     +/memccpy
2577     +/memchr
2578     +/memcmp
2579     +/memrchr
2580     +/memusage
2581     +/mktime
2582     +/mmap_test
2583     +/pipe
2584     +/printf
2585     +/printftest
2586     +/protoent
2587     +/prototypes
2588     +/putenv
2589     +/pwent
2590     +/rand48
2591     +/read1
2592     +/readdir
2593     +/regex
2594     +/select
2595     +/sendfile
2596     +/servent
2597     +/setjmp
2598     +/siglist
2599     +/sigsetjmp
2600     +/speed
2601     +/spent
2602     +/sprintf
2603     +/sscanf
2604     +/stdarg
2605     +/strcasecmp
2606     +/strcmp
2607     +/strncat
2608     +/strncpy
2609     +/strptime
2610     +/strrchr
2611     +/strstr
2612     +/strtol
2613     +/sysconf
2614     +/sysenter
2615     +/ungetc
2616     +/utime
2617     +/waitpid
2618     diff --git a/test/Makefile b/test/Makefile
2619     index 2e406f3..152cf5a 100644
2620     --- a/test/Makefile
2621     +++ b/test/Makefile
2622     @@ -8,13 +8,13 @@ CFLAGS=-nostdinc -Wall
2623     LCOMPAT=-lcompat
2624    
2625     TESTPROGRAMS=adjtime alarm argv asprintf atexit bsearch byteswap calloc confstr cycles empty fadvise flush fnmatch \
2626     -fputc ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \
2627     +fputc ftruncate ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \
2628     gethostbyname_r getmntent getopt getpass getpwnam getservbyname getservbyport getusershell \
2629     -glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \
2630     +glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger math md5_testharness \
2631     memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest \
2632     -protoent prototypes putenv pwent rand48 read1 readdir regex select sendfile servent siglist \
2633     -speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \
2634     -strstr strtol sysenter ungetc utime waitpid
2635     +protoent prototypes putenv pwent rand48 read1 readdir regex select sendfile servent setjmp siglist \
2636     +sigsetjmp speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \
2637     +strstr strtol sysconf sysenter ungetc utime waitpid
2638    
2639     test: $(TESTPROGRAMS)
2640    
2641     diff --git a/test/adjtime.c b/test/adjtime.c
2642     index d42d129..8d7a016 100644
2643     --- a/test/adjtime.c
2644     +++ b/test/adjtime.c
2645     @@ -1,9 +1,25 @@
2646     #include <stdio.h>
2647     +#include <assert.h>
2648     +#include <errno.h>
2649     #include <sys/time.h>
2650    
2651     int main() {
2652     struct timeval a,b;
2653     + int rc;
2654     a.tv_sec=0; a.tv_usec=0;
2655     - printf("%d\n",adjtime(&a,&b));
2656     + rc = adjtime(&a,&b);
2657     + assert(!rc || errno == EPERM);
2658     +
2659     + rc = adjtime(&a, NULL);
2660     + assert(!rc || errno == EPERM);
2661     +
2662     + rc = adjtime(NULL,&b);
2663     + assert(!rc);
2664     + assert(b.tv_sec < 30); /* 30 seconds delta is very unlikely... */
2665     + assert(b.tv_sec > -30); /* 30 seconds delta is very unlikely... */
2666     + assert(b.tv_usec > -1000000);
2667     + assert(b.tv_usec < 1000000);
2668     +
2669     + printf("%lu/%d\n", (unsigned long)b.tv_sec, (int)b.tv_usec);
2670     return 0;
2671     }
2672     diff --git a/test/asprintf.c b/test/asprintf.c
2673     index 996a5aa..0d4f2eb 100644
2674     --- a/test/asprintf.c
2675     +++ b/test/asprintf.c
2676     @@ -13,7 +13,7 @@ int main(int argc, char **argv) {
2677     assert(strlen(path) == asprintlen);
2678    
2679     printf("%s\n", path);
2680     - asprintlen=asprintf(&path, "/proc" "/%d/stat", strlen(argv[1]));
2681     + asprintlen=asprintf(&path, "/proc" "/%zu/stat", strlen(argv[1]));
2682     assert(strlen(path) == asprintlen);
2683     printf("%s\n", path);
2684    
2685     diff --git a/test/atexit.c b/test/atexit.c
2686     index 709a3e4..79ee392 100644
2687     --- a/test/atexit.c
2688     +++ b/test/atexit.c
2689     @@ -2,7 +2,7 @@
2690     #include <unistd.h>
2691    
2692     void blah(void) {
2693     - write(2,"atexit\n",7);
2694     + write(1,"atexit\n",7);
2695     }
2696    
2697     int main() {
2698     diff --git a/test/bsearch.c b/test/bsearch.c
2699     index 961ad35..ede4c88 100644
2700     --- a/test/bsearch.c
2701     +++ b/test/bsearch.c
2702     @@ -35,7 +35,7 @@ int main() {
2703     die("bsearch returned NULL\n");
2704     }
2705     if (k != array+i) die("bsearch found wrong element\n");
2706     - printf("%d\n",k-array);
2707     + printf("%ld\n",k-array);
2708     }
2709     }
2710     return 0;
2711     diff --git a/test/byteswap.c b/test/byteswap.c
2712     index 19239dd..6f43c25 100644
2713     --- a/test/byteswap.c
2714     +++ b/test/byteswap.c
2715     @@ -9,12 +9,12 @@ int main() {
2716     snprintf(buf,100,"%x %x", bswap_16(0x1234), bswap_16(0x5678));
2717     assert(strcmp(buf, "3412 7856") == 0);
2718    
2719     - printf("%lx\n",bswap_32(0x12345678));
2720     - snprintf(buf,100,"%lx", bswap_32(0x12345678));
2721     + printf("%x\n",(unsigned int)bswap_32(0x12345678));
2722     + snprintf(buf,100,"%x", (unsigned int)bswap_32(0x12345678));
2723     assert(strcmp(buf, "78563412") == 0);
2724    
2725     - printf("%qx\n",bswap_64(0x123456789ABCDEFull));
2726     - snprintf(buf,100,"%qx", bswap_64(0x123456789ABCDEFull));
2727     + printf("%llx\n",(unsigned long long)bswap_64(0x123456789ABCDEFull));
2728     + snprintf(buf,100,"%llx", (unsigned long long)bswap_64(0x123456789ABCDEFull));
2729     assert(strcmp(buf, "efcdab8967452301") == 0);
2730     return 0;
2731     }
2732     diff --git a/test/cycles.c b/test/cycles.c
2733     index 35547f8..46b2f32 100644
2734     --- a/test/cycles.c
2735     +++ b/test/cycles.c
2736     @@ -13,7 +13,8 @@
2737     dst = (((uint64_t)h) << 32) | l; \
2738     } while (0)
2739     #else
2740     -#error "Unimplemented rdtsc"
2741     +#warning "Unimplemented rdtsc"
2742     +#define RDTSC(dst) dst = 0
2743     #endif
2744    
2745     extern char **environ;
2746     @@ -24,7 +25,7 @@ int main(int argc,char* argv[]) {
2747     if (!fork()) { execve(argv[1],argv+1,environ); exit(1); }
2748     wait(0);
2749     RDTSC(b);
2750     - printf("%llu cycles\n",b-a);
2751     + printf("%llu cycles\n",(unsigned long long)(b-a));
2752    
2753     return 0;
2754     }
2755     diff --git a/test/dirent/.gitignore b/test/dirent/.gitignore
2756     new file mode 100644
2757     index 0000000..eea7a22
2758     --- /dev/null
2759     +++ b/test/dirent/.gitignore
2760     @@ -0,0 +1,2 @@
2761     +/opendir-tst1
2762     +/tst-seekdir
2763     diff --git a/test/ftruncate.c b/test/ftruncate.c
2764     new file mode 100644
2765     index 0000000..e0ebb5d
2766     --- /dev/null
2767     +++ b/test/ftruncate.c
2768     @@ -0,0 +1,54 @@
2769     +#define _GNU_SOURCE
2770     +#define _XOPEN_SOURCE 600
2771     +#define _FILE_OFFSET_BITS 64
2772     +
2773     +#include <stdlib.h>
2774     +#include <fcntl.h>
2775     +#include <assert.h>
2776     +#include <unistd.h>
2777     +#include <sys/stat.h>
2778     +
2779     +#define CHECK(_sz) \
2780     + assert(ftruncate(fd, (_sz)) == 0); \
2781     + assert(fstat(fd, &st) == 0); \
2782     + assert(st.st_size == (_sz)); \
2783     +
2784     +#define CHECK64(_sz) \
2785     + assert(ftruncate64(fd, (_sz)) == 0); \
2786     + assert(fstat64(fd, &st64) == 0); \
2787     + assert(st64.st_size == (_sz)); \
2788     +
2789     +int main(void)
2790     +{
2791     + char file[] = "/tmp/dietlibc-fadvise-test.XXXXXX";
2792     + int fd;
2793     + struct stat st;
2794     +
2795     + fd = mkstemp(file);
2796     + unlink(file);
2797     +
2798     + assert(ftruncate(fd, 500000) == 0);
2799     + assert(fstat(fd, &st) == 0);
2800     +
2801     + if (st.st_blocks > 1) {
2802     + /* spare files not supported by filesystem :( */
2803     + return EXIT_SUCCESS;
2804     + }
2805     +
2806     + CHECK(1);
2807     + CHECK(0x7fffffff);
2808     +
2809     +#if __WORDSIZE == 32
2810     + {
2811     + struct stat64 st64;
2812     + CHECK64(1);
2813     + CHECK64(0x7fffffff);
2814     + CHECK64(0x80000001ul);
2815     + CHECK64(0x17fffffffull);
2816     + }
2817     +#else
2818     + CHECK(0x17fffffffull);
2819     +#endif
2820     +
2821     + return EXIT_SUCCESS;
2822     +}
2823     diff --git a/test/getmntent.c b/test/getmntent.c
2824     index fc17a83..1039d06 100644
2825     --- a/test/getmntent.c
2826     +++ b/test/getmntent.c
2827     @@ -33,10 +33,6 @@ while ((e = getmntent(fstab))) {
2828    
2829     printf("closing /etc/fstab\n");
2830     assert ( 1 == endmntent(fstab));
2831     - printf("closing /etc/fstab again\n");
2832     - assert ( 1 == endmntent(fstab)); /* endmntent must always return 1 */
2833     - printf("entmntent(0)\n");
2834     - assert ( 1 == endmntent(0)); /* causes a segfault with diet libc */
2835     +
2836     return 0;
2837     }
2838     -
2839     diff --git a/test/getservbyname.c b/test/getservbyname.c
2840     index b70ca19..caf1c9f 100644
2841     --- a/test/getservbyname.c
2842     +++ b/test/getservbyname.c
2843     @@ -1,5 +1,6 @@
2844     #include <stdio.h>
2845     #include <netdb.h>
2846     +#include <arpa/inet.h>
2847    
2848     int main(int argc,char *argv[]) {
2849     struct servent* se;
2850     diff --git a/test/if_nameindex.c b/test/if_nameindex.c
2851     index b3c8b22..0c171f8 100644
2852     --- a/test/if_nameindex.c
2853     +++ b/test/if_nameindex.c
2854     @@ -1,8 +1,12 @@
2855     #include <stdio.h>
2856     +#include <assert.h>
2857     #include <net/if.h>
2858    
2859     int main() {
2860     struct if_nameindex* t=if_nameindex();
2861     +
2862     + assert(t != NULL);
2863     +
2864     if (t) {
2865     struct if_nameindex* t1=t;
2866     while (t->if_index) {
2867     diff --git a/test/malloc-debugger.c b/test/malloc-debugger.c
2868     index 040196e..058807e 100644
2869     --- a/test/malloc-debugger.c
2870     +++ b/test/malloc-debugger.c
2871     @@ -4,7 +4,7 @@
2872     int main() {
2873     char* c=malloc(13);
2874     char* tmp;
2875     - fprintf(stderr,"got %p\n",c);
2876     + fprintf(stdout,"got %p\n",c);
2877     c[0]=14;
2878     // c[15]=0;
2879     tmp=realloc(c,12345);
2880     diff --git a/test/math.c b/test/math.c
2881     new file mode 100644
2882     index 0000000..687103c
2883     --- /dev/null
2884     +++ b/test/math.c
2885     @@ -0,0 +1,29 @@
2886     +#include <math.h>
2887     +#include <float.h>
2888     +#include <assert.h>
2889     +
2890     +int main()
2891     +{
2892     + extern int __isinf(double d);
2893     + extern int __isnan(double d);
2894     +
2895     +#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
2896     + assert(__isinf(__builtin_inff()) == +1);
2897     + assert(__isinf(-__builtin_inff()) == -1);
2898     +
2899     + assert(__isinf(__builtin_inf()) == +1);
2900     + assert(__isinf(-__builtin_inf()) == -1);
2901     +
2902     + assert(__isnan(__builtin_nan("")));
2903     +#endif
2904     +
2905     + assert(__isinf((DBL_MAX * DBL_MAX)) == +1);
2906     + assert(__isinf(-(DBL_MAX * DBL_MAX)) == -1);
2907     +
2908     + assert(isinf((DBL_MAX * DBL_MAX)));
2909     + assert(isinf(-(DBL_MAX * DBL_MAX)));
2910     +
2911     + //assert(isnan(nan("")));
2912     +
2913     + return 0;
2914     +}
2915     diff --git a/test/mktime.c b/test/mktime.c
2916     index 5e9e65c..9b4bd5e 100644
2917     --- a/test/mktime.c
2918     +++ b/test/mktime.c
2919     @@ -9,15 +9,15 @@ int main() {
2920     t.tm_mday=29;
2921     t.tm_mon=2;
2922     t.tm_year=100;
2923     - printf("%d\n",mktime(&t));
2924     + printf("%ld\n",(long)mktime(&t));
2925     t.tm_mday=1;
2926     t.tm_mon=3;
2927     t.tm_year=102;
2928     - printf("%d\n",mktime(&t));
2929     + printf("%ld\n",(long)mktime(&t));
2930     t.tm_mday=1;
2931     t.tm_mon=6;
2932     t.tm_year=102;
2933     - printf("%d\n",mktime(&t));
2934     + printf("%ld\n",(long)mktime(&t));
2935     return 0;
2936     }
2937    
2938     diff --git a/test/mmap_test.c b/test/mmap_test.c
2939     index 1fc2616..5aa79eb 100644
2940     --- a/test/mmap_test.c
2941     +++ b/test/mmap_test.c
2942     @@ -15,7 +15,7 @@ int main (int argc, char * argv[])
2943     void *filememory_1;
2944     void *filememory_2;
2945    
2946     - fd = open (FILENAME, O_RDWR | O_CREAT);
2947     + fd = open (FILENAME, O_RDWR | O_CREAT, 0600);
2948    
2949     if (fd < 0)
2950     {
2951     diff --git a/test/pipe.c b/test/pipe.c
2952     index fb6ba31..315b4ca 100644
2953     --- a/test/pipe.c
2954     +++ b/test/pipe.c
2955     @@ -5,6 +5,9 @@ int
2956     main (void)
2957     {
2958     int fd[2];
2959     + close(3);
2960     + close(4);
2961     +
2962     assert (!pipe (fd));
2963     /* if for some reason the parent process has fd3 or fd4
2964     already open, then this will fail although there is
2965     diff --git a/test/printf.c b/test/printf.c
2966     index 719461a..ef6050d 100644
2967     --- a/test/printf.c
2968     +++ b/test/printf.c
2969     @@ -2,11 +2,26 @@
2970     #include <string.h>
2971     #include <stdlib.h>
2972     #include <assert.h>
2973     +#include <math.h>
2974     +#include <float.h>
2975     #include <sys/param.h>
2976     #include <locale.h>
2977    
2978     #define ALGN 5
2979    
2980     +#ifndef INFINITY
2981     +# if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
2982     +# define INFINITY (__builtin_inf())
2983     +# endif
2984     +#endif
2985     +
2986     +#ifndef NAN
2987     +# if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
2988     +# define NAN (__builtin_nan(""))
2989     +# endif
2990     +#endif
2991     +
2992     +
2993     // https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=112986
2994     #if 0
2995     #undef assert
2996     @@ -60,7 +75,7 @@
2997     TEST_SNPRINTF(EXP, 0, __VA_ARGS__); \
2998     TEST_SNPRINTF(EXP, sizeof(EXP)+ALGN, __VA_ARGS__); \
2999     TEST_SNPRINTF_NULL(EXP, __VA_ARGS__)
3000     -
3001     +
3002    
3003     int main()
3004     {
3005     @@ -101,7 +116,7 @@ int main()
3006     TEST("42.23", "%5.2f", 42.23);
3007     TEST("42.23", "%5.4g", 42.23);
3008     TEST(" 42.2", "%5.3g", 42.23);
3009     -
3010     +
3011     TEST(" 1", "%*i", 4, 1);
3012     TEST(" 1", "%4i", 1);
3013     TEST("1 ", "%-4i", 1);
3014     @@ -131,13 +146,32 @@ int main()
3015     TEST("-01234", "%6.5i", -1234);
3016     TEST(" 1234", "%6.5s", "1234");
3017    
3018     +#ifdef INFINITY
3019     + TEST("inf", "%f", INFINITY);
3020     + TEST("-inf", "%f", -INFINITY);
3021     + TEST("INF", "%F", INFINITY);
3022     + TEST("-INF", "%F", -INFINITY);
3023     +
3024     + TEST("inf", "%g", INFINITY);
3025     + TEST("-inf", "%g", -INFINITY);
3026     + TEST("INF", "%G", INFINITY);
3027     + TEST("-INF", "%G", -INFINITY);
3028     +#endif
3029     +
3030     +#ifdef NAN
3031     + TEST("nan", "%f", NAN);
3032     + TEST("NAN", "%F", NAN);
3033     + TEST("nan", "%g", NAN);
3034     + TEST("NAN", "%G", NAN);
3035     +#endif
3036     +
3037     #ifdef XSI_TESTS
3038     setlocale(LC_ALL, "de_DE");
3039     -
3040     +
3041     TEST("1.234", "%'u", 1234);
3042     TEST("2 1", "%2$u %1$u", 1, 2);
3043     #endif
3044     -
3045     -
3046     +
3047     +
3048     return EXIT_SUCCESS;
3049     }
3050     diff --git a/test/printftest.c b/test/printftest.c
3051     index 4743279..47d9580 100644
3052     --- a/test/printftest.c
3053     +++ b/test/printftest.c
3054     @@ -101,8 +101,8 @@ int main()
3055     printf("#%i#\n",18);
3056     printf("#%d#\n",18);
3057     printf("#%u#\n",18);
3058     - printf("#%lu#\n",18);
3059     - printf("#%li#\n",18);
3060     + printf("#%lu#\n",18l);
3061     + printf("#%li#\n",18l);
3062     printf("#%-+#06d#\n", -123);
3063     printf("#%-+#6d#\n", -123);
3064     printf("#%+#06d#\n", -123);
3065     @@ -142,7 +142,7 @@ int main()
3066     buf);
3067     memset(buf2,0,sizeof(buf));
3068     i=snprintf(buf2, 256, "%.9999u", 10);
3069     - printf("%i %i\n",i,strlen(buf2));
3070     + printf("%i %li\n",i,strlen(buf2));
3071    
3072     printf ("snprintf (\"%%.999999u\", 10) == %d\n",
3073     snprintf(buf2, sizeof(buf2), "%.999999u", 10));
3074     diff --git a/test/rand48.c b/test/rand48.c
3075     index 4f5b08f..1e67632 100644
3076     --- a/test/rand48.c
3077     +++ b/test/rand48.c
3078     @@ -6,16 +6,16 @@ main (void)
3079     {
3080     static unsigned short data[7] = { 1, 2, 3, 4, 5, 6, 7 };
3081    
3082     - printf ("one %X\n", mrand48 ());
3083     - printf ("two %X\n", mrand48 ());
3084     - printf ("three %X\n", mrand48 ());
3085     + printf ("one %lX\n", mrand48 ());
3086     + printf ("two %lX\n", mrand48 ());
3087     + printf ("three %lX\n", mrand48 ());
3088    
3089     lcong48 (data);
3090     printf ("after lcong48:\n");
3091    
3092     - printf ("one %X\n", mrand48 ());
3093     - printf ("two %X\n", mrand48 ());
3094     - printf ("three %X\n", mrand48 ());
3095     + printf ("one %lX\n", mrand48 ());
3096     + printf ("two %lX\n", mrand48 ());
3097     + printf ("three %lX\n", mrand48 ());
3098    
3099     return 0;
3100     }
3101     diff --git a/test/runtests.sh b/test/runtests.sh
3102     index d6fb19b..15b70b1 100644
3103     --- a/test/runtests.sh
3104     +++ b/test/runtests.sh
3105     @@ -1,6 +1,6 @@
3106     SUBDIRS="dirent inet stdio string stdlib time"
3107    
3108     -TESTPROGRAMS="adjtime alarm argv atexit bsearch byteswap calloc confstr empty fadvise flush fputc ffs fnmatch ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent siglist speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysenter ungetc utime waitpid"
3109     +TESTPROGRAMS="adjtime alarm argv atexit bsearch byteswap calloc confstr empty fadvise flush fputc ffs fnmatch ftruncate ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger math md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent setjmp siglist sigsetjmp speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysconf sysenter ungetc utime waitpid"
3110    
3111     STDIN="read1"
3112     PASS="getpass"
3113     diff --git a/test/sendfile.c b/test/sendfile.c
3114     index d43cdd2..28b3af5 100644
3115     --- a/test/sendfile.c
3116     +++ b/test/sendfile.c
3117     @@ -11,5 +11,5 @@ int main() {
3118    
3119     printf("sendfile returned %d\n",ret);
3120    
3121     -return 0;
3122     + return ret<0 ? 1 : 0;
3123     }
3124     diff --git a/test/setjmp.c b/test/setjmp.c
3125     new file mode 100644
3126     index 0000000..15951e5
3127     --- /dev/null
3128     +++ b/test/setjmp.c
3129     @@ -0,0 +1,106 @@
3130     +#include <assert.h>
3131     +#include <stdlib.h>
3132     +#include <string.h>
3133     +#include <setjmp.h>
3134     +
3135     +static int Xmemcmp(void const volatile *a, void const volatile *b, size_t l)
3136     +{
3137     + return memcmp((void const *)a, (void const *)b, l);
3138     +}
3139     +
3140     +int main(void)
3141     +{
3142     + char volatile a[8] = "testbufA";
3143     + jmp_buf env;
3144     + char volatile b[8] = "testbufB";
3145     +
3146     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3147     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3148     +
3149     +
3150     + /* Test 1: not calling longjmp */
3151     + if (setjmp(env) == 0) {
3152     + char volatile somebuf[128];
3153     +
3154     + memset((void *)somebuf, 0xde, sizeof somebuf);
3155     +
3156     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3157     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3158     + } else
3159     + assert(0);
3160     +
3161     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3162     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3163     +
3164     +
3165     + /* Test 2: calling longjmp */
3166     + switch (setjmp(env)) {
3167     + case 0: {
3168     + char volatile somebuf[128];
3169     +
3170     + memset((void *)somebuf, 0xde, sizeof somebuf);
3171     +
3172     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3173     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3174     +
3175     + longjmp(env, 23);
3176     +
3177     + a[0] = 'X';
3178     + b[0] = 'X';
3179     + }
3180     +
3181     + case 23:
3182     + break;
3183     +
3184     + default:
3185     + assert(0);
3186     + }
3187     +
3188     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3189     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3190     +
3191     +
3192     + /* Test 3: calling longjmp again with dirty env */
3193     + switch (setjmp(env)) {
3194     + case 0: {
3195     + char volatile somebuf[128];
3196     +
3197     + memset((void *)somebuf, 0xde, sizeof somebuf);
3198     +
3199     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3200     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3201     +
3202     + longjmp(env, 23);
3203     +
3204     + a[0] = 'X';
3205     + b[0] = 'X';
3206     + }
3207     +
3208     + case 23:
3209     + break;
3210     +
3211     + default:
3212     + assert(0);
3213     + }
3214     +
3215     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3216     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3217     +
3218     +
3219     + /* Test 4: not calling longjmp, but dirty env */
3220     + if (setjmp(env) == 0) {
3221     + char volatile somebuf[128];
3222     +
3223     + memset((void *)somebuf, 0xde, sizeof somebuf);
3224     +
3225     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3226     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3227     + } else
3228     + assert(0);
3229     +
3230     + assert(Xmemcmp(a, "testbufA", 8) == 0);
3231     + assert(Xmemcmp(b, "testbufB", 8) == 0);
3232     +
3233     +
3234     + return EXIT_SUCCESS;
3235     +}
3236     diff --git a/test/sigsetjmp.c b/test/sigsetjmp.c
3237     new file mode 100644
3238     index 0000000..3fa71bb
3239     --- /dev/null
3240     +++ b/test/sigsetjmp.c
3241     @@ -0,0 +1,140 @@
3242     +#include <assert.h>
3243     +#include <stdlib.h>
3244     +#include <stdio.h>
3245     +#include <string.h>
3246     +#include <signal.h>
3247     +#include <setjmp.h>
3248     +
3249     +#define TEST_PATTERN \
3250     + "0123456789abcdefghijklmnopqrstuv" \
3251     + "ZYXWVUTSRQPONMLKJIHGFEDCBA987654" \
3252     + "456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
3253     + "vutsrqponmlkjihgfedcba9876543210" \
3254     + "0123456789ABCDEFGHIJKLMNOPQRSTUV" \
3255     + "zyxwvutsrqponmlkjihgfedcba987654" \
3256     + "456789abcdefghijklmnopqrstuvwxyz" \
3257     + "VUTSRQPONMLKJIHGFEDCBA987654321" \
3258     +
3259     +static struct {
3260     + char volatile a[256];
3261     + sigjmp_buf env;
3262     + char volatile b[256];
3263     +} sigenv = {
3264     + .a = TEST_PATTERN "<",
3265     + .b = TEST_PATTERN ">",
3266     +};
3267     +
3268     +static int volatile sig_seen;
3269     +
3270     +#define VALIDATE_BUFFERS(_sig_exp) do { \
3271     + assert(Xmemcmp(sigenv.a, TEST_PATTERN "<", sizeof sigenv.a) == 0); \
3272     + assert(Xmemcmp(sigenv.b, TEST_PATTERN ">", sizeof sigenv.b) == 0); \
3273     + assert(sig_seen == (_sig_exp)); \
3274     + } while (0)
3275     +
3276     +static int Xmemcmp(void const volatile *a, void const volatile *b, size_t l)
3277     +{
3278     + return memcmp((void const *)a, (void const *)b, l);
3279     +}
3280     +
3281     +static void do_test(int sig_num, int do_save, int block_sig)
3282     +{
3283     + int rc;
3284     + sigset_t block_set;
3285     + sigset_t cur_set;
3286     +
3287     + printf("%s(%d,%d,%d)... ", __func__, sig_num, do_save, block_sig);
3288     + fflush(stdout);
3289     +
3290     + VALIDATE_BUFFERS(0);
3291     +
3292     + sigemptyset(&block_set);
3293     + assert(sigprocmask(SIG_SETMASK, NULL, &cur_set) == 0);
3294     +
3295     + /* verify that tested signal is not blocked */
3296     + if (sig_num != 0)
3297     + assert(!sigismember(&cur_set, sig_num));
3298     +
3299     + /* verify that blocked signal is not already blocked and fill signal set */
3300     + if (block_sig != 0) {
3301     + assert(!sigismember(&cur_set, block_sig));
3302     + sigaddset(&block_set, block_sig);
3303     + }
3304     +
3305     + sig_seen = 0;
3306     + rc = sigsetjmp(sigenv.env, do_save);
3307     + if (rc == 0) {
3308     + char volatile somebuf[128];
3309     +
3310     + memset((void *)somebuf, 0x42, sizeof somebuf);
3311     + VALIDATE_BUFFERS(0);
3312     +
3313     + /* modify signal mask */
3314     + if (block_sig != 0)
3315     + assert(sigprocmask(SIG_BLOCK, &block_set, NULL) == 0);
3316     +
3317     + /* raise a signal which triggers a siglongjmp */
3318     + if (sig_num != 0) {
3319     + raise(sig_num);
3320     + sigenv.a[0] = 'X';
3321     + sigenv.b[0] = 'X';
3322     + assert(0);
3323     + }
3324     + } else if (rc != sig_num)
3325     + /* sigsetjmp() returned with an unexpected value */
3326     + assert(0);
3327     +
3328     + VALIDATE_BUFFERS(sig_num);
3329     + sig_seen = 0;
3330     +
3331     + /* check whether current signal mask contains the blocked signal; it should
3332     + be there iff sigsetjmp() was triggered and sigmask was saved. */
3333     + if (block_sig != 0) {
3334     + sigset_t cur_set;
3335     + assert(sigprocmask(SIG_SETMASK, NULL, &cur_set) == 0);
3336     +
3337     + if (do_save && rc != 0)
3338     + assert(!sigismember(&cur_set, block_sig));
3339     + else {
3340     + assert( sigismember(&cur_set, block_sig));
3341     + sigprocmask(SIG_UNBLOCK, &block_set, NULL);
3342     + }
3343     + }
3344     +
3345     + printf(" ok\n");
3346     +};
3347     +
3348     +static void sig_handler(int num)
3349     +{
3350     + assert(sig_seen == 0);
3351     + sig_seen = num;
3352     + siglongjmp(sigenv.env, num);
3353     +}
3354     +
3355     +int main(void)
3356     +{
3357     + struct sigaction sigact = {
3358     + .sa_handler = sig_handler,
3359     + .sa_flags = SA_NODEFER, /* raised signal will be in blocked mask else */
3360     + };
3361     +
3362     + /* verify our assumptions about the memory layout */
3363     + assert(sizeof sigenv.a == 256);
3364     + assert(sizeof sigenv.b == 256);
3365     + assert(offsetof(__typeof__(sigenv), env) == sizeof sigenv.a);
3366     + assert(offsetof(__typeof__(sigenv), b) == sizeof sigenv.a + sizeof sigenv.env);
3367     +
3368     + sigaction(SIGBUS, &sigact, NULL);
3369     + sigaction(SIGUSR1, &sigact, NULL);
3370     +
3371     + do_test(0, 0, 0);
3372     + do_test(0, 0, SIGUSR1);
3373     + do_test(0, 1, 0);
3374     + do_test(0, 1, SIGUSR1);
3375     + do_test(SIGBUS, 0, 0);
3376     + do_test(SIGBUS, 0, SIGUSR1);
3377     + do_test(SIGBUS, 1, 0);
3378     + do_test(SIGBUS, 1, SIGUSR1);
3379     +
3380     + return EXIT_SUCCESS;
3381     +}
3382     diff --git a/test/speed.c b/test/speed.c
3383     index 674b9a8..22249a7 100644
3384     --- a/test/speed.c
3385     +++ b/test/speed.c
3386     @@ -7,10 +7,10 @@ int main() {
3387     int i;
3388     time_t t;
3389    
3390     - printf("%d\n", time(0));
3391     + printf("%ld\n", (long)time(0));
3392     for (i=0; i<10000000; ++i)
3393     t=time(0);
3394    
3395     - printf("%d\n", time(0));
3396     + printf("%ld\n", (long)time(0));
3397     return 0;
3398     }
3399     diff --git a/test/stdio/.gitignore b/test/stdio/.gitignore
3400     new file mode 100644
3401     index 0000000..8892d20
3402     --- /dev/null
3403     +++ b/test/stdio/.gitignore
3404     @@ -0,0 +1,14 @@
3405     +/tst-fdopen
3406     +/tst-ferror
3407     +/tst-fileno
3408     +/tst-fphex
3409     +/tst-fseek
3410     +/tst-printf
3411     +/tst-sprintf
3412     +/tst-sscanf
3413     +/tst-tmpnam
3414     +/tst-unbputc
3415     +/tst-ungetc
3416     +/tstdiomisc
3417     +/tstgetln
3418     +/tstscanf
3419     diff --git a/test/stdio/tstscanf.c b/test/stdio/tstscanf.c
3420     index 44ddf49..0f55c3c 100644
3421     --- a/test/stdio/tstscanf.c
3422     +++ b/test/stdio/tstscanf.c
3423     @@ -338,14 +338,14 @@ main (int argc, char **argv)
3424     int res;
3425    
3426     res = sscanf ("-InF", "%f", &value);
3427     - if (res != 1 || isinf (value) != -1)
3428     + if (res != 1 || !isinf (value) || !(value<0))
3429     {
3430     fputs ("test failed!\n", stdout);
3431     result = 1;
3432     }
3433    
3434     res = sscanf ("+InfiNiTY", "%f", &value);
3435     - if (res != 1 || isinf (value) != 1)
3436     + if (res != 1 || !isinf (value) || !(value>0))
3437     {
3438     fputs ("test failed!\n", stdout);
3439     result = 1;
3440     diff --git a/test/stdlib/.gitignore b/test/stdlib/.gitignore
3441     new file mode 100644
3442     index 0000000..ce37703
3443     --- /dev/null
3444     +++ b/test/stdlib/.gitignore
3445     @@ -0,0 +1,13 @@
3446     +/test-canon
3447     +/testdiv
3448     +/testrand
3449     +/testsort
3450     +/tst-calloc
3451     +/tst-environ
3452     +/tst-limits
3453     +/tst-malloc
3454     +/tst-rand48
3455     +/tst-strtod
3456     +/tst-strtol
3457     +/tst-strtoll
3458     +/tst-system
3459     diff --git a/test/stdlib/testsort.c b/test/stdlib/testsort.c
3460     index aa4332a..5a92bc0 100644
3461     --- a/test/stdlib/testsort.c
3462     +++ b/test/stdlib/testsort.c
3463     @@ -1,3 +1,5 @@
3464     +#define _BSD_SOURCE
3465     +
3466     #include <stdlib.h>
3467     #include <string.h>
3468     #include <stdio.h>
3469     diff --git a/test/stdlib/tst-calloc.c b/test/stdlib/tst-calloc.c
3470     index a9b9e2a..049117b 100644
3471     --- a/test/stdlib/tst-calloc.c
3472     +++ b/test/stdlib/tst-calloc.c
3473     @@ -17,6 +17,8 @@
3474     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3475     02111-1307 USA. */
3476    
3477     +#define _BSD_SOURCE
3478     +
3479     #include <errno.h>
3480     #include <limits.h>
3481     #include <malloc.h>
3482     diff --git a/test/stdlib/tst-malloc.c b/test/stdlib/tst-malloc.c
3483     index 09fbb1f..4a491d9 100644
3484     --- a/test/stdlib/tst-malloc.c
3485     +++ b/test/stdlib/tst-malloc.c
3486     @@ -21,13 +21,15 @@
3487     #include <stdlib.h>
3488     #include <stdio.h>
3489    
3490     +#include "../../dietfeatures.h"
3491     +
3492     static int errors = 0;
3493    
3494     static void
3495     merror (const char *msg)
3496     {
3497     ++errors;
3498     - printf ("Error: %s\n", msg);
3499     + fprintf (stderr, "Error: %s\n", msg);
3500     }
3501    
3502     int
3503     @@ -56,9 +58,11 @@ main (void)
3504     if (p != NULL)
3505     merror ("realloc (p, 0) failed.");
3506    
3507     +#ifdef WANT_MALLOC_ZERO
3508     p = malloc (0);
3509     if (p == NULL)
3510     merror ("malloc (0) failed.");
3511     +#endif
3512    
3513     p = realloc (p, 0);
3514     if (p != NULL)
3515     diff --git a/test/stdlib/tst-strtod.c b/test/stdlib/tst-strtod.c
3516     index 630a8fc..bacdca7 100644
3517     --- a/test/stdlib/tst-strtod.c
3518     +++ b/test/stdlib/tst-strtod.c
3519     @@ -149,10 +149,10 @@ main (int argc, char ** argv)
3520     }
3521    
3522     const char input2[] = "+1.000000000116415321826934814453125";
3523     - if (strtold (input2, NULL) != +1.000000000116415321826934814453125)
3524     + if (strtold (input2, NULL) != +1.000000000116415321826934814453125L)
3525     {
3526     printf ("input2: %La != %La\n", strtold (input2, NULL),
3527     - +1.000000000116415321826934814453125);
3528     + +1.000000000116415321826934814453125L);
3529     status = 1;
3530     }
3531    
3532     diff --git a/test/string/.gitignore b/test/string/.gitignore
3533     new file mode 100644
3534     index 0000000..94b11fc
3535     --- /dev/null
3536     +++ b/test/string/.gitignore
3537     @@ -0,0 +1,16 @@
3538     +/memccpy
3539     +/memchr
3540     +/memcmp
3541     +/memcpy
3542     +/mempcpy
3543     +/memrchr
3544     +/strcasecmp
3545     +/strcmp
3546     +/strcspn
3547     +/strlen
3548     +/strncat
3549     +/strncpy
3550     +/strpbrk
3551     +/strrchr
3552     +/strspn
3553     +/strstr
3554     diff --git a/test/sysconf.c b/test/sysconf.c
3555     new file mode 100644
3556     index 0000000..32263a5
3557     --- /dev/null
3558     +++ b/test/sysconf.c
3559     @@ -0,0 +1,80 @@
3560     +#include <unistd.h>
3561     +#include <stdio.h>
3562     +#include <stdlib.h>
3563     +#include <assert.h>
3564     +#include <sys/wait.h>
3565     +
3566     +#include "../dietpagesize.h"
3567     +
3568     +static long exec_getconf(char const *var)
3569     +{
3570     + char buf[128];
3571     + pid_t pid;
3572     + int fd[2];
3573     + int status;
3574     + ssize_t l;
3575     +
3576     + if (pipe(fd)<0 || (pid = fork())<0)
3577     + abort();
3578     +
3579     + if (pid==0) {
3580     + close(fd[0]);
3581     +
3582     + if (fd[1]!=1) {
3583     + dup2(fd[1], 1);
3584     + close(fd[1]);
3585     + }
3586     +
3587     + execlp("getconf", "getconf", var, NULL);
3588     + _exit(1);
3589     + }
3590     +
3591     + close(fd[1]);
3592     + l = read(fd[0], buf, sizeof(buf)-1);
3593     + if (l<0) {
3594     + perror("read()");
3595     + goto err;
3596     + } else if (l==sizeof(buf)-1)
3597     + goto err;
3598     + close(fd[0]);
3599     +
3600     + buf[l] = '\0';
3601     +
3602     + if (waitpid(pid, &status, 0)<0)
3603     + goto err;
3604     +
3605     + if (!WIFEXITED(status) || WEXITSTATUS(status)!=0)
3606     + goto err;
3607     +
3608     + return strtol(buf, NULL, 10);
3609     +
3610     + err:
3611     + kill(pid, SIGKILL);
3612     + abort();
3613     +}
3614     +
3615     +static unsigned int do_check(char const *var, long exp)
3616     +{
3617     + long cur = exec_getconf(var);
3618     +
3619     + if (cur!=exp) {
3620     + fprintf(stderr, "%s mismatch: got %ld, expected %ld\n",
3621     + var, cur, exp);
3622     + return 1;
3623     + }
3624     +
3625     + return 0;
3626     +}
3627     +
3628     +int main(int argc, char *argv[])
3629     +{
3630     + unsigned int err = 0;
3631     +
3632     + assert(sysconf(_SC_PAGESIZE) == __DIET_PAGE_SIZE);
3633     + assert(__DIET_PAGE_SIZE == (1<<__DIET_PAGE_SHIFT));
3634     +
3635     + err += do_check("PAGE_SIZE", sysconf(_SC_PAGESIZE));
3636     + err += do_check("CLK_TCK", sysconf(_SC_CLK_TCK));
3637     +
3638     + return err;
3639     +}
3640     diff --git a/test/sysenter.c b/test/sysenter.c
3641     index a8fa3a8..3d85916 100644
3642     --- a/test/sysenter.c
3643     +++ b/test/sysenter.c
3644     @@ -11,11 +11,11 @@ int main() {
3645     int i;
3646     for (i=0; environ[i]; ++i) ;
3647     for (x=(struct elf_aux*)(environ+i+1); x->type; ++x) {
3648     - printf("%d %x\n",x->type,x->value);
3649     + printf("%ld %lx\n",x->type,x->value);
3650     if (x->type==AT_PAGESZ)
3651     - printf("pagesize %d\n",x->value);
3652     + printf("pagesize %ld\n",x->value);
3653     else if (x->type==AT_SYSINFO)
3654     - printf("vsyscall %p\n",x->value);
3655     + printf("vsyscall %p\n",(void *)x->value);
3656     }
3657     return 0;
3658     }
3659     diff --git a/test/time/.gitignore b/test/time/.gitignore
3660     new file mode 100644
3661     index 0000000..dcd3b38
3662     --- /dev/null
3663     +++ b/test/time/.gitignore
3664     @@ -0,0 +1,4 @@
3665     +/tst-mktime
3666     +/tst-posixtz
3667     +/tst-strftime
3668     +/tst-strptime
3669     diff --git a/test/time/tst-strftime.c b/test/time/tst-strftime.c
3670     index e092e93..27db9a4 100644
3671     --- a/test/time/tst-strftime.c
3672     +++ b/test/time/tst-strftime.c
3673     @@ -49,18 +49,18 @@ int main (void) {
3674    
3675     if (res == 0)
3676     {
3677     - printf ("%Zu: %s: res == 0 despite size == %Zu\n",
3678     + printf ("%zu: %s: res == 0 despite size == %zu\n",
3679     cnt, tests[cnt].fmt, size);
3680     result = 1;
3681     }
3682     else if (size < tests[cnt].min)
3683     {
3684     - printf ("%Zu: %s: size == %Zu was enough\n",
3685     + printf ("%zu: %s: size == %zu was enough\n",
3686     cnt, tests[cnt].fmt, size);
3687     result = 1;
3688     }
3689     else
3690     - printf ("%Zu: %s: size == %Zu: OK\n", cnt, tests[cnt].fmt, size);
3691     + printf ("%zu: %s: size == %zu: OK\n", cnt, tests[cnt].fmt, size);
3692    
3693     free (buf);
3694     }
3695     diff --git a/test/time/tst-strptime.c b/test/time/tst-strptime.c
3696     index 6277ea6..2773180 100644
3697     --- a/test/time/tst-strptime.c
3698     +++ b/test/time/tst-strptime.c
3699     @@ -41,10 +41,12 @@ static const struct
3700     { "C", "03/03/00", "%D", 5, 62, 2, 3 },
3701     { "C", "9/9/99", "%x", 4, 251, 8, 9 },
3702     { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 },
3703     +#if 0 /* dietlibc does not support %U/%W/%j and non-POSIX locales */
3704     { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 },
3705     { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 },
3706     { "ja_JP.EUC-JP", "2001 20 \xb7\xee", "%Y %U %a", 1, 140, 4, 21 },
3707     { "ja_JP.EUC-JP", "2001 21 \xb7\xee", "%Y %W %a", 1, 140, 4, 21 },
3708     +#endif
3709     };
3710    
3711    
3712     @@ -72,9 +74,16 @@ test_tm (void)
3713    
3714     for (i = 0; i < sizeof (tm_tests) / sizeof (tm_tests[0]); ++i)
3715     {
3716     + char *pres;
3717     memset (&tm, '\0', sizeof (tm));
3718     -
3719     - if (strptime (tm_tests[i].input, tm_tests[i].format, &tm) != '\0')
3720     +
3721     + pres = strptime (tm_tests[i].input, tm_tests[i].format, &tm);
3722     + if (!pres)
3723     + {
3724     + fprintf(stderr, "failed to parse '%s'\n", day_tests[i].input);
3725     + result = 1;
3726     + }
3727     + else if (*pres != '\0')
3728     {
3729     printf ("not all of `%s' read\n", tm_tests[i].input);
3730     result = 1;
3731     @@ -118,6 +127,7 @@ int main (void) {
3732    
3733     for (i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i)
3734     {
3735     + char *pres;
3736     memset (&tm, '\0', sizeof (tm));
3737    
3738     if (setlocale (LC_ALL, day_tests[i].locale) == NULL)
3739     @@ -125,7 +135,14 @@ int main (void) {
3740     printf ("cannot set locale %s: %m\n", day_tests[i].locale);
3741     }
3742    
3743     - if (*strptime (day_tests[i].input, day_tests[i].format, &tm) != '\0')
3744     + pres = strptime (day_tests[i].input, day_tests[i].format, &tm);
3745     + if (!pres)
3746     + {
3747     + fprintf(stderr, "failed to parse '%s' for locale '%s'\n",
3748     + day_tests[i].input, day_tests[i].locale);
3749     + result = 1;
3750     + }
3751     + else if (*pres != '\0')
3752     {
3753     printf ("not all of `%s' read\n", day_tests[i].input);
3754     result = 1;
3755     diff --git a/test/waitpid.c b/test/waitpid.c
3756     index fe2cb5b..92c0b0e 100644
3757     --- a/test/waitpid.c
3758     +++ b/test/waitpid.c
3759     @@ -11,7 +11,7 @@ int main() {
3760     perror("fork");
3761     _exit(1);
3762     case 0:
3763     - fprintf(stderr,"child, my pid is %u\n",getpid());
3764     + fprintf(stdout,"child, my pid is %u\n",getpid());
3765     sleep(1);
3766     _exit(23);
3767     }
3768     diff --git a/x86_64/__time.S b/x86_64/__time.S
3769     new file mode 100644
3770     index 0000000..774b67f
3771     --- /dev/null
3772     +++ b/x86_64/__time.S
3773     @@ -0,0 +1,11 @@
3774     +/* implement time(2) via gettimeofday(2) on x86-64 because gettimeofday
3775     + is a vsyscall (i.e. no actual switch to kernel mode) */
3776     +.text
3777     +.global time
3778     +.type time,@function
3779     +time:
3780     + mov $0xffffffffff600400,%rax
3781     + call *%rax
3782     + ret
3783     +.Lhere:
3784     + .size time,.Lhere-time
3785     diff --git a/x86_64/start.S b/x86_64/start.S
3786     index adc461a..8b4f3c9 100644
3787     --- a/x86_64/start.S
3788     +++ b/x86_64/start.S
3789     @@ -12,12 +12,28 @@ _start:
3790    
3791     leaq 8(%rsi,%rdi,8),%rdx /* %rdx = envp = (8*rdi)+%rsi+8 */
3792    
3793     +
3794     +#ifdef WANT_ELFINFO
3795     +#ifdef __DYN_LIB
3796     + movq environ@GOTPCREL(%rip), %rax
3797     +#else
3798     + leaq environ(%rip), %rax
3799     +#endif
3800     + movq %rdx, (%rax) /* environ */
3801     +
3802     +1: add $8, %rdx /* increment envp */
3803     + cmpq $0, -8(%rdx) /* load envp[-1] */
3804     + jne 1b /* ... until envp[-1]==NULL */
3805     +
3806     + movq %rdx, 8(%rax) /* __elfinfo */
3807     +#else
3808     #ifdef __DYN_LIB
3809     movq environ@GOTPCREL(%rip), %rax
3810     movq %rdx, (%rax)
3811     #else
3812     movq %rdx, environ(%rip)
3813     #endif
3814     +#endif
3815    
3816     #ifdef PROFILING
3817     pushq %rdi /* save reg args */
3818     diff --git a/x86_64/time.S b/x86_64/time.S
3819     index 774b67f..690ee30 100644
3820     --- a/x86_64/time.S
3821     +++ b/x86_64/time.S
3822     @@ -1,11 +1 @@
3823     -/* implement time(2) via gettimeofday(2) on x86-64 because gettimeofday
3824     - is a vsyscall (i.e. no actual switch to kernel mode) */
3825     -.text
3826     -.global time
3827     -.type time,@function
3828     -time:
3829     - mov $0xffffffffff600400,%rax
3830     - call *%rax
3831     - ret
3832     -.Lhere:
3833     - .size time,.Lhere-time
3834     +/* avoid empty source file */

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed