diff --git a/FAQ b/FAQ index 4712a232..5627a670 100644 --- a/FAQ +++ b/FAQ @@ -246,7 +246,7 @@ A: UPDATE: the defaults have been changed as of 2005-04-23. code. Unfortunately, these options have been renamed on gcc 3. You can fix this by creating a file ~/.diet/gcc containing this line: - -Os -fomit-frame-pointer -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2 + -Os -fomit-frame-pointer -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4 If you get this options not for diet -Os gcc but for diet -Os i386-linux-gcc, put this in ~/.diet/i386-linux-gcc instead. diff --git a/Makefile b/Makefile index 4f93cd30..167a304f 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ MAN1DIR=${prefix}/man/man1 EXTRACFLAGS= -MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6]t\?e\?[lb]/arm/') +MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-7]t\?e\?[lb]/arm/') # This extra-ugly cruft is here so make will not run uname and sed each # time it looks at $(OBJDIR). This alone sped up running make when @@ -107,6 +107,8 @@ CFLAGS=$(DEFAULTCFLAGS) CROSS= CC=gcc +CCC=$(CROSS)$(CC) +STRIP=$(COMMENT) $(CROSS)strip INC=-I. -isystem include VPATH=lib:libstdio:libugly:libcruft:libcrypt:libshell:liblatin1:libcompat:libdl:librpc:libregex:libm:profiling @@ -141,7 +143,7 @@ endif ifneq ($(DEBUG),) CFLAGS = -g -COMMENT = : +STRIP = : endif CFLAGS += -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow @@ -163,31 +165,31 @@ $(OBJDIR) $(PICODIR): % :: %,v -$(OBJDIR)/%: $(OBJDIR) - ifeq ($(CC),tcc) -$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h | $(OBJDIR) $(CROSS)cpp $(INC) $< | $(CROSS)as --noexecstack -o $@ -$(OBJDIR)/%.o: %.c +$(OBJDIR)/%.o: %.c | $(OBJDIR) tcc -I. -Iinclude -c $< -o $@ - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ + -$(STRIP) -x -R .comment -R .note $@ else -$(OBJDIR)/pstart.o: start.S - $(CROSS)$(CC) $(INC) $(CFLAGS) -DPROFILING -c $< $(ASM_CFLAGS) -o $@ +$(OBJDIR)/pstart.o: start.S | $(OBJDIR) + $(CCC) $(INC) $(CFLAGS) -DPROFILING -c $< $(ASM_CFLAGS) -o $@ -$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h - $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< $(ASM_CFLAGS) -o $@ +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h | $(OBJDIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRAFLAGS) -c $< $(ASM_CFLAGS) -o $@ -$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c - $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ +$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c | $(OBJDIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@ + -$(STRIP) -x -R .comment -R .note $@ -$(OBJDIR)/%.o: %.c - $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ -D__dietlibc__ - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ +$(OBJDIR)/%.o: %.c | $(OBJDIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@ -D__dietlibc__ + -$(STRIP) -x -R .comment -R .note $@ endif + + ifeq ($(shell $(CC) -v 2>&1 | grep "gcc version"),gcc version 4.0.0) SAFE_CFLAGS=$(shell echo $(CFLAGS)|sed 's/-Os/-O2/') SAFER_CFLAGS=$(shell echo $(CFLAGS)|sed 's/-Os/-O/') @@ -198,8 +200,8 @@ endif CC+=-D__dietlibc__ -$(OBJDIR)/crypt.o: libcrypt/crypt.c - $(CROSS)$(CC) $(INC) $(SAFER_CFLAGS) -c $< -o $@ +$(OBJDIR)/crypt.o: libcrypt/crypt.c | $(OBJDIR) + $(CCC) $(INC) $(SAFER_CFLAGS) -c $< -o $@ DIETLIBC_OBJ = $(OBJDIR)/unified.o \ $(SYSCALLOBJ) $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ @@ -213,9 +215,9 @@ $(OBJDIR)/dietlibc.a: $(DIETLIBC_OBJ) $(OBJDIR)/start.o $(OBJDIR)/librpc.a: $(LIBRPCOBJ) $(CROSS)ar cru $@ $(LIBRPCOBJ) -$(OBJDIR)/libcrypt.a: +$(OBJDIR)/libcrypt.a: | $(OBJDIR) touch dummy.c - $(CROSS)$(CC) -c dummy.c + $(CCC) -c dummy.c $(CROSS)ar cru $@ dummy.o rm -f dummy.c dummy.o @@ -250,23 +252,23 @@ dyn_lib: $(PICODIR) $(PICODIR)/libc.so $(PICODIR)/dstart.o \ $(PICODIR)/libpthread.so $(PICODIR)/libdl.so $(PICODIR)/libcompat.so \ $(PICODIR)/libm.so $(PICODIR)/diet-dyn $(PICODIR)/diet-dyn-i -$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h - $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB $(ASM_CFLAGS) -c $< -o $@ +$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h | $(PICODIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB $(ASM_CFLAGS) -c $< -o $@ -$(PICODIR)/pthread_%.o: libpthread/pthread_%.c - $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ +$(PICODIR)/pthread_%.o: libpthread/pthread_%.c | $(PICODIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ + $(STRIP) -x -R .comment -R .note $@ -$(PICODIR)/%.o: %.c - $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ +$(PICODIR)/%.o: %.c | $(PICODIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ + $(STRIP) -x -R .comment -R .note $@ -$(PICODIR)/dstart.o: start.S - $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB $(ASM_CFLAGS) -c $< -o $@ +$(PICODIR)/dstart.o: start.S | $(PICODIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB $(ASM_CFLAGS) -c $< -o $@ -$(PICODIR)/dyn_so_start.o: dyn_start.c - $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@ - $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ +$(PICODIR)/dyn_so_start.o: dyn_start.c | $(PICODIR) + $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@ + $(STRIP) -x -R .comment -R .note $@ DYN_LIBC_PIC = $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ $(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ) @@ -283,54 +285,54 @@ DYN_LIBCOMPAT_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBCOMPATOBJ)) DYN_LIBMATH_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBMATHOBJ)) $(PICODIR)/libc.so: $(PICODIR) $(DYN_LIBC_OBJ) - $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so + $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so $(PICODIR)/libpthread.so: $(DYN_PTHREAD_OBJS) dietfeatures.h $(PICODIR)/libc.so - $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so + $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so $(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h $(PICODIR)/libc.so - $(LD_UNSET) $(CROSS)$(CC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -Bsymbolic -Wl,-Bsymbolic \ + $(LD_UNSET) $(CCC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -Bsymbolic -Wl,-Bsymbolic \ -o $@ $(SAFE_CFLAGS) $(INC) libdl/_dl_main.c -Wl,-soname=libdl.so $(OBJDIR)/pthread_create.o $(PICODIR)/pthread_create.o: dietfeatures.h $(OBJDIR)/pthread_internal.o $(PICODIR)/pthread_internal.o: dietfeatures.h #$(PICODIR)/libdl.so: $(DYN_LIBDL_OBJS) dietfeatures.h -# $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBDL_OBJS) -L$(PICODIR) -ldietc -Wl,-soname=libdl.so +# $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBDL_OBJS) -L$(PICODIR) -ldietc -Wl,-soname=libdl.so $(PICODIR)/libcompat.so: $(DYN_LIBCOMPAT_OBJS) dietfeatures.h $(PICODIR)/libc.so - $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBCOMPAT_OBJS) -L$(PICODIR) -lc -Wl,-soname=libcompat.so + $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBCOMPAT_OBJS) -L$(PICODIR) -lc -Wl,-soname=libcompat.so $(PICODIR)/libm.so: $(DYN_LIBMATH_OBJS) dietfeatures.h $(PICODIR)/libc.so - $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBMATH_OBJS) -L$(PICODIR) -lc -Wl,-soname=libm.so + $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBMATH_OBJS) -L$(PICODIR) -lc -Wl,-soname=libm.so $(SYSCALLOBJ): syscalls.h $(OBJDIR)/elftrunc: $(OBJDIR)/diet contrib/elftrunc.c - bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/elftrunc.c + bin-$(MYARCH)/diet $(CCC) $(CFLAGS) -o $@ contrib/elftrunc.c $(OBJDIR)/dnsd: $(OBJDIR)/diet contrib/dnsd.c - bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/dnsd.c + bin-$(MYARCH)/diet $(CCC) $(CFLAGS) -o $@ contrib/dnsd.c VERSION=dietlibc-$(shell head -n 1 CHANGES|sed 's/://') CURNAME=$(notdir $(shell pwd)) $(OBJDIR)/diet: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o - $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc - $(CROSS)strip -R .comment -R .note $@ + $(CCC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc + $(STRIP) -R .comment -R .note $@ $(OBJDIR)/diet-i: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o - $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc - $(CROSS)strip -R .comment -R .note $@ + $(CCC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc + $(STRIP) -R .comment -R .note $@ $(PICODIR)/diet-dyn: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c - $(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 - $(CROSS)strip -R .command -R .note $@ + $(LD_UNSET) $(CCC) -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 + $(STRIP) -R .command -R .note $@ $(PICODIR)/diet-dyn-i: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c - $(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 - $(CROSS)strip -R .command -R .note $@ + $(LD_UNSET) $(CCC) -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 + $(STRIP) -R .command -R .note $@ $(OBJDIR)/djb: $(OBJDIR)/compile $(OBJDIR)/load @@ -360,14 +362,14 @@ $(OBJDIR)/exports: $(OBJDIR)/dietlibc.a .PHONY: t t1 t: - $(CROSS)$(CC) -g $(CFLAGS) -fno-builtin -nostdlib -isystem include -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dietlibc.a -lgcc $(OBJDIR)/dyn_stop.o -Wl,-Map,mapfile + $(CCC) -g $(CFLAGS) -fno-builtin -nostdlib -isystem include -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dietlibc.a -lgcc $(OBJDIR)/dyn_stop.o -Wl,-Map,mapfile t1: - $(CROSS)$(CC) -g -o t1 t.c + $(CCC) -g -o t1 t.c install-bin: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/librpc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/elftrunc $(OBJDIR)/diet-i $(INSTALL) -d $(DESTDIR)$(ILIBDIR) $(DESTDIR)$(MAN1DIR) $(DESTDIR)$(BINDIR) - $(INSTALL) $(OBJDIR)/start.o $(DESTDIR)$(ILIBDIR)/start.o + $(INSTALL) -m 644 $(OBJDIR)/start.o $(DESTDIR)$(ILIBDIR)/start.o $(INSTALL) -m 644 $(OBJDIR)/libm.a $(OBJDIR)/libpthread.a $(OBJDIR)/librpc.a \ $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/libcrypt.a $(DESTDIR)$(ILIBDIR) $(INSTALL) -m 644 $(OBJDIR)/dietlibc.a $(DESTDIR)$(ILIBDIR)/libc.a @@ -549,9 +551,7 @@ $(OBJDIR)/fcntl64.o: dietfeatures.h # WANT_SSP # This facepalm brought to you by: Ubuntu! -$(OBJDIR)/stackgap.o: lib/stackgap.c dietfeatures.h - $(CROSS)$(CC) $(INC) $(CFLAGS) -c lib/stackgap.c -o $@ -D__dietlibc__ -fno-stack-protector - $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ +$(OBJDIR)/stackgap.o $(PICODIR)/stackgap.o: EXTRACFLAGS:=-fno-stack-protector # WANT_MALLOC_ZERO $(OBJDIR)/strndup.o: dietfeatures.h diff --git a/arm/Makefile.add b/arm/Makefile.add index 361e98b3..9c9a67c3 100644 --- a/arm/Makefile.add +++ b/arm/Makefile.add @@ -1,6 +1,7 @@ LIBOBJ+=$(OBJDIR)/md5asm.o $(OBJDIR)/__aeabi_unwind_cpp.o LIBOBJ+=$(OBJDIR)/__fadvise.o $(OBJDIR)/arm_fadvise.o +LIBOBJ+=$(OBJDIR)/__aeabi_read_tp.o $(OBJDIR)/arm_set_tls.o CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing #ifdef __ARM_EABI__ #CFLAGS+=-mabi=aapcs-linux -mno-thumb-interwork diff --git a/arm/__aeabi_read_tp.S b/arm/__aeabi_read_tp.S new file mode 100644 index 00000000..65fcf5f6 --- /dev/null +++ b/arm/__aeabi_read_tp.S @@ -0,0 +1,13 @@ +#include "arm-features.h" + +FUNC_START __aeabi_read_tp + +#if __ARM_ARCH__ < 6 + mvn r0, #0xf000 + sub pc, r0, #31 +#else + mrc 15, 0, r0, cr13, cr0, 3 + bx lr +#endif + +FUNC_END __aeabi_read_tp diff --git a/arm/__aeabi_unwind_cpp.S b/arm/__aeabi_unwind_cpp.S index ca631bcb..9334eee8 100644 --- a/arm/__aeabi_unwind_cpp.S +++ b/arm/__aeabi_unwind_cpp.S @@ -1,21 +1,14 @@ -.text -.global __aeabi_unwind_cpp_pr0 -.hidden __aeabi_unwind_cpp_pr0 -.type __aeabi_unwind_cpp_pr0, %function +#include "arm-features.h" -.global __aeabi_unwind_cpp_pr1 +FUNC_START __aeabi_unwind_cpp_pr0 +FUNC_START __aeabi_unwind_cpp_pr1 +FUNC_START __aeabi_unwind_cpp_pr2 +.hidden __aeabi_unwind_cpp_pr0 .hidden __aeabi_unwind_cpp_pr1 -.type __aeabi_unwind_cpp_pr1, %function - -.global __aeabi_unwind_cpp_pr2 .hidden __aeabi_unwind_cpp_pr2 -.type __aeabi_unwind_cpp_pr2, %function -__aeabi_unwind_cpp_pr0: -__aeabi_unwind_cpp_pr1: -__aeabi_unwind_cpp_pr2: - mov pc, lr @ return from subroutine + RET -.size __aeabi_unwind_cpp_pr0,.-__aeabi_unwind_cpp_pr0 -.size __aeabi_unwind_cpp_pr1,.-__aeabi_unwind_cpp_pr1 -.size __aeabi_unwind_cpp_pr2,.-__aeabi_unwind_cpp_pr2 +FUNC_END __aeabi_unwind_cpp_pr2 +FUNC_END __aeabi_unwind_cpp_pr1 +FUNC_END __aeabi_unwind_cpp_pr0 diff --git a/arm/__fadvise.c b/arm/__fadvise.c index 0aa1246d..aee78fc0 100644 --- a/arm/__fadvise.c +++ b/arm/__fadvise.c @@ -1,5 +1,7 @@ -#include #include "syscalls.h" +#define _LINUX_SOURCE +#include +#include #ifndef __NR_fadvise64 long fadvise64_64(int fd, off64_t offset, off64_t len, int advice) diff --git a/arm/__guard.S b/arm/__guard.S index 7218d131..a4e53aa6 100644 --- a/arm/__guard.S +++ b/arm/__guard.S @@ -1,4 +1,5 @@ .data +.align 2 .type __guard,#object .global __guard .type __stack_chk_guard,#object @@ -7,3 +8,5 @@ __guard: __stack_chk_guard: .long 0xaff00 +.size __guard, . - __guard +.size __stack_chk_guard, . - __stack_chk_guard diff --git a/arm/__longjmp.S b/arm/__longjmp.S index 31307bd2..3a8203fe 100644 --- a/arm/__longjmp.S +++ b/arm/__longjmp.S @@ -1,11 +1,23 @@ -.text -.global __longjmp -.type __longjmp,function -__longjmp: +#include "arm-features.h" + +FUNC_START __longjmp mov ip, r0 movs r0, r1 moveq r0, #1 -#ifndef __SOFTFP__ - lfm f4, 4, [ip], #48 +#ifndef __SOFTFP__ +# if __ARM_ARCH__ == 7 + vldm ip!, {d0-d15} +# ifdef __ARM_NEON__ + vldm ip!, {d16-d31} +# endif +# else + lfm f4, 4, [ip]! +# endif #endif - ldmia ip, {r4-r11, sp, pc} + +#ifdef __IWMMXT__ +# warning "sigjmp will not restore iwmmxt coprocessor registers" +#endif + + ldmia ip!, {r4-r11, sp, pc} +FUNC_END __longjmp diff --git a/arm/__testandset.S b/arm/__testandset.S index d9c57648..3b62c516 100644 --- a/arm/__testandset.S +++ b/arm/__testandset.S @@ -1,7 +1,15 @@ -.text -.global __testandset -__testandset: +#include "arm-features.h" + +FUNC_START __testandset mov r2, r0 mov r1, #1 +# if __ARM_ARCH__ < 6 swp r0, r1, [r2] - mov pc, lr +# else +1: ldrex r0, [r2] + strex r3, r1, [r2] + cmp r3, #0 + bne 1b +# endif + RET +FUNC_END __testandset diff --git a/arm/arm-features.h b/arm/arm-features.h new file mode 100644 index 00000000..fa5d0451 --- /dev/null +++ b/arm/arm-features.h @@ -0,0 +1,110 @@ +/* --*- asm -*-- */ + +#ifndef H_DIETLIBC_ARM_FEATURES_H +#define H_DIETLIBC_ARM_FEATURES_H + +/* Stolen from gcc (gcc/config/arm/lib1funcs.asm) */ +#if defined(__ARM_ARCH_2__) +# define __ARM_ARCH__ 2 +#endif + +#if defined(__ARM_ARCH_3__) +# define __ARM_ARCH__ 3 +#endif + +#if defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__) \ + || defined(__ARM_ARCH_4T__) +# define __ARM_ARCH__ 4 +#endif + +#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \ + || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \ + || defined(__ARM_ARCH_5TEJ__) +# define __ARM_ARCH__ 5 +#endif + +#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ + || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ + || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \ + || defined(__ARM_ARCH_6M__) +# define __ARM_ARCH__ 6 +#endif + +#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ + || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) +# define __ARM_ARCH__ 7 +#endif + +#ifndef __ARM_ARCH__ +#error Unable to determine architecture. +#endif + +#define DIET_JMPBUFSZ_REGS_REGULAR 10*32/8 /* r4-r11, sp, pc */ +#define DIET_JMPBUFSZ_REGS_FPv4 16*64/8 /* d0-d15 */ + +#if !defined(__SOFTFP__) || defined(__IWMMXT__) +# define DIET_HAVE_COPROC_REGS 1 +#else +# undef DIET_HAVE_COPROC_REGS +#endif + +#ifdef __ASSEMBLER__ + +.macro FUNC_START name + .text + .align 0 + .global \name + .type \name, %function +\name: +.endm + +.macro FUNC_START_WEAK name + .text + .align 0 + .weak \name + .type \name, %function +\name: +.endm + +.macro FUNC_END name + .size \name, . - \name +.endm + +.macro RET +#if (__ARM_ARCH__ > 4) || defined(__ARM_ARCH_4T__) + bx lr +#else + mov pc, lr +#endif +.endm + +.macro SWI_UNIFIED name +#ifdef __ARM_EABI__ + b __unified_syscall_swi +#else + swi \name + b __unified_syscall +#endif +.endm + +.macro SWI_UNIFIED4 +#ifdef __ARM_EABI__ + b __unified_syscall_swi +#else + swi \name + b __unified_syscall4 +#endif +.endm + +.macro LOAD_ARG4_5 +#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(__ARM_ARCH_5T__) + ldr r4, [sp,#16] + ldr r5, [sp,#20] +#else + ldrd r4, [sp,#16] +#endif +.endm + +#endif /* __ASSEMBLER__ */ + +#endif /* H_DIETLIBC_ARM_FEATURES_H */ diff --git a/arm/arm_set_tls.S b/arm/arm_set_tls.S new file mode 100644 index 00000000..94c4ba45 --- /dev/null +++ b/arm/arm_set_tls.S @@ -0,0 +1,27 @@ +#include "syscalls.h" +#include "arm-features.h" + +#ifdef __ARM_EABI__ + +@ Calling convention: +@ r0 ... thread data +@ Returns: +@ r0 ... low-level error code +FUNC_START __arm_set_tls + mov ip, r7 + ldr r7, =__ARM_NR_set_tls + swi 0 + mov r7, ip + + @ we do not have much options here to handle errors because + @ errno might not be available yet. Return error code as-is + @ and let it handle by the caller + + RET +FUNC_END __arm_set_tls + +#else + +#warning "setup-tls only implemented for ARM_EABI!" + +#endif diff --git a/arm/clone.S b/arm/clone.S index 4a4b2f4a..7b43d66a 100644 --- a/arm/clone.S +++ b/arm/clone.S @@ -1,11 +1,7 @@ - #include #include "syscalls.h" +#include "arm-features.h" - .text - .weak clone - .global __clone - @ @ Some slightly tricky stuff here... edit with care :-) @ @@ -15,13 +11,12 @@ #define CLONE_VM 0x00000100 #define CLONE_THREAD 0x00010000 - + @ ; don't do this yet @#define RESET_PID - -clone: -__clone: +FUNC_START_WEAK clone +FUNC_START __clone @ ; start with a sanity check cmp r0, #0 cmpne r1, #0 @@ -31,13 +26,13 @@ __clone: @ ; insert args into stack str r3, [r1, #-4]! str r0, [r1, #-4]! - + @ ; do the system call @ ; get the flags mov r0, r2 -#ifdef RESET_PID +#ifdef RESET_PID mov ip, r2 -#endif +#endif @ ; child sp is already in r1 stmfd sp!, {r4, r7} @stmdb sp!, {r4, r7} @@ -46,14 +41,14 @@ __clone: ldr r4, [sp, #16] ldr r7, =__NR_clone swi 0 - + cmp r0, #0 beq 1f - ldmfd sp!, {r4, r7} + ldmfd sp!, {r4, r7} blt __unified_syscall @ (return code < 0): handle as an error - bx lr -1: -#ifdef RESET_PID + RET +1: +#ifdef RESET_PID tst ip, #CLONE_THREAD bne 3f @@ -67,21 +62,22 @@ __clone: swi 0 str r0, [r1, #PID_OFFSET] @ ; not defined yet ?? str r0, [r1, #TID_OFFSET] @ ; not defined yet ?? -3: +3: #endif @ ; pick the function arg and call address off the stack and execute ldr r0, [sp, #4] mov lr, pc ldr pc, [sp], #8 - + @ ; and we're done, passing return value through r0 b _exit @ branch to _exit (PIC safe) +FUNC_END __clone +FUNC_END clone - #else - -clone: -__clone: + +FUNC_START_WEAK clone +FUNC_START __clone movs r12, r0 @ check function pointer cmpne r1, #0 @ if function check for stack pointer moveq r0, #-EINVAL @ if one is not available set errno value @@ -101,5 +97,7 @@ __clone: ldmia sp!, { r0, pc } @ load function param and jump to thread function 1: b _exit @ branch to _exit (PIC safe) +FUNC_END __clone +FUNC_END clone #endif diff --git a/arm/dyn_syscalls.S b/arm/dyn_syscalls.S index a4baf28f..56ec38a5 100644 --- a/arm/dyn_syscalls.S +++ b/arm/dyn_syscalls.S @@ -3,6 +3,8 @@ * Olaf Dreesen */ +#include "arm-features.h" + #include "../syscalls.s/environ.S" #include "../syscalls.s/errno.S" @@ -25,7 +27,7 @@ __unified_syscall: mvn r0, #0 #include "dietuglyweaks.h" - mov pc, lr + RET /* ok now include all syscalls.s (*.S) and sysdep *.S */ #include "mmap.S" @@ -104,7 +106,6 @@ __unified_syscall: #include "../syscalls.s/n_sigprocmask.S" #include "../syscalls.s/n_sigsuspend.S" #include "../syscalls.s/nanosleep.S" -#include "../syscalls.s/nice.S" #include "../syscalls.s/open.S" #include "../syscalls.s/pause.S" #include "../syscalls.s/personality.S" diff --git a/arm/md5asm.S b/arm/md5asm.S index 370b5039..feb0926a 100644 --- a/arm/md5asm.S +++ b/arm/md5asm.S @@ -1,3 +1,5 @@ +#include "arm-features.h" + /***************************************************************************** * Copyright (C) 2002 Andre McCurdy * @@ -75,8 +77,9 @@ MD5Init: mov r1, #0 str r1, [r0, #0x10] @ initial count[0] = 0 str r1, [r0, #0x14] @ initial count[1] = 0 - mov pc, lr @ return + RET + .align 3 1: .word 0x67452301 @ initial MD5 context->state[0] .word 0xefcdab89 @ initial MD5 context->state[1] .word 0x98badcfe @ initial MD5 context->state[2] @@ -128,6 +131,7 @@ MD5Update: @ static void __MD5Transform (uint32_t *buf, const uint32_t *in, int repeat); @ -- +.align 3 MD5MagicData: 1: .word 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee @@ -148,6 +152,7 @@ MD5MagicData: .word 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, (17f-19f-4) .word 0x6e4120A9, 0x20657264, 0x7543634d, 0x00796472, (19f-19f-4) +.align 2 __MD5Transform: cmp r2, #0 diff --git a/arm/mmap.S b/arm/mmap.S index d3ea1317..26824a59 100644 --- a/arm/mmap.S +++ b/arm/mmap.S @@ -1,3 +1,5 @@ +#include "arm-features.h" + #include #include "syscalls.h" @@ -28,7 +30,7 @@ mmap: ldr r4, [sp], #4 ldr r5, [sp], #4 cmn r0, #4096 - mov pc, lr @ return + RET #else diff --git a/arm/setjmp.S b/arm/setjmp.S index 6b850d40..afe563dc 100644 --- a/arm/setjmp.S +++ b/arm/setjmp.S @@ -1,17 +1,41 @@ -.text -.weak setjmp -setjmp: -.global __setjmp -__setjmp: +#include "arm-features.h" + +FUNC_START_WEAK setjmp +FUNC_START __setjmp mov r1, #0 -.global __sigsetjmp -__sigsetjmp: -.weak sigsetjmp -sigsetjmp: -#ifndef __SOFTFP__ - sfm f4, 4, [r0], #48 +FUNC_END __setjmp +FUNC_END setjmp + +FUNC_START_WEAK sigsetjmp +FUNC_START __sigsetjmp + +#ifdef DIET_HAVE_COPROC_REGS + /* we have to work on a copy of 'r0' (jmpbuf *) */ + mov ip, r0 +#endif + +#ifndef __SOFTFP__ +# if __ARM_ARCH__ >= 7 + vstmia ip!, {d0-d15} +# ifdef __ARM_NEON__ + vstmia ip!, {d16-d31} +# endif +# else + sfm f4, 4, [ip]! +# endif +#endif + +#ifdef __IWMMXT__ +# warning "setjmp will not save iwmmxt coprocessor registers" #endif + +#ifndef DIET_HAVE_COPROC_REGS stmia r0, {r4-r11, sp, lr} - sub r0, r0, #48 - b __sigjmp_save +#else + stmia ip!, {r4-r11, sp, lr} +#endif + + b __sigjmp_save +FUNC_END __sigsetjmp +FUNC_END sigsetjmp diff --git a/arm/start.S b/arm/start.S index d68d49d6..1e5e0090 100644 --- a/arm/start.S +++ b/arm/start.S @@ -1,23 +1,10 @@ - #include "dietfeatures.h" #include "syscalls.h" +#include "arm-features.h" - .text #ifdef __ARM_EABI__ - .align 4 -#else - .align 2 -#endif - - .global _start - .weak exit - .global _exit - - -#ifdef __ARM_EABI__ - -_start: +FUNC_START _start mov fp, #0 @ clear the frame pointer ldr a1, [sp] @ argc add a2, sp, #4 @ argv @@ -25,27 +12,29 @@ _start: add a3, a2, a1, lsl #2 @ &argv[argc] add a3, a3, #4 @ envp str a3, [ip, #0] @ environ = envp - bl main - + bl CALL_IN_STARTCODE + @ @ The exit status from main() is already in r0. @ We need to branch to 'exit' in case we have linked with 'atexit'. @ bl exit +FUNC_END _start -exit: -_exit: - +FUNC_START _exit +FUNC_START_WEAK exit mov r7, #__NR_exit swi 0 @ never returns. + .align 2 .L3: .word environ - -#else +FUNC_END exit +FUNC_END _exit - -_start: +#else + +FUNC_START _start #ifdef WANT_DYNAMIC mov a4, a1 @ save dynamic ld.so _fini @@ -83,18 +72,20 @@ _start: @ We need to branch to 'exit' in case we have linked with 'atexit'. @ bl exit +FUNC_END _start -exit: -_exit: - +FUNC_START _exit +FUNC_START_WEAK exit #ifdef PROFILING mov r4, r0 @ save a copy of exit status bl _stop_monitor mov r0, r4 #endif swi $__NR_exit @ never returns. +FUNC_END exit +FUNC_END _exit - + .align 2 #ifdef __DYN_LIB .L3: .word environ(GOT) .L4: .word _GLOBAL_OFFSET_TABLE_-(1b+8) diff --git a/arm/strcpy.S b/arm/strcpy.S index 20e1029d..7a865620 100644 --- a/arm/strcpy.S +++ b/arm/strcpy.S @@ -1,10 +1,7 @@ #include "dietfeatures.h" +#include "arm-features.h" -.text - .align 2 - .global strcpy - -strcpy: +FUNC_START strcpy #ifndef WANT_SMALL_STRING_ROUTINES mov ip, r0 ands r2, r1, #3 @@ -61,6 +58,5 @@ strcpy: ldrneb r2, [r1], #1 #endif bne .Lloop - mov pc, lr -.Lfe1: - .size strcpy,.Lfe1-strcpy + RET +FUNC_END strcpy diff --git a/arm/strlen.S b/arm/strlen.S index 6b2b459a..a6af8f0d 100644 --- a/arm/strlen.S +++ b/arm/strlen.S @@ -1,12 +1,7 @@ #include "dietfeatures.h" +#include "arm-features.h" - .text - .align 2 - - .global strlen - -strlen: - +FUNC_START strlen #if 0 teq a1, #0 @ is string pointer NULL ?? moveq pc, lr @ if so, return 0 @@ -61,12 +56,10 @@ strlen: sub a1, a1, a2 #endif - mov pc, lr + RET #ifndef WANT_SMALL_STRING_ROUTINES .Lmagic: .word 0x01010101 #endif - -.Lstrlen: - .size strlen,.Lstrlen-strlen +FUNC_END strlen diff --git a/arm/syscalls.h b/arm/syscalls.h index 896fd5e2..bef48a52 100644 --- a/arm/syscalls.h +++ b/arm/syscalls.h @@ -727,9 +727,9 @@ #define __ARGS_getpeername 0 #define __ARGS_socketpair 0 #define __ARGS_send 0 -#define __ARGS_sendto 0 +#define __ARGS_sendto 1 #define __ARGS_recv 0 -#define __ARGS_recvfrom 0 +#define __ARGS_recvfrom 1 #define __ARGS_shutdown 0 #define __ARGS_setsockopt 0 #define __ARGS_getsockopt 0 @@ -824,70 +824,30 @@ #ifdef __ASSEMBLER__ -#ifdef __ARM_EABI__ +#include "arm-features.h" #define syscall_weak(name,wsym,sym) __syscall_weak __NR_##name, wsym, sym, __ARGS_##name .macro __syscall_weak name wsym sym typ -.text -.type \wsym,function -.weak \wsym -\wsym: -.type \sym,function -.global \sym -\sym: - stmfd sp!,{r4,r5,r7,lr} - ldr r4, [sp,#16] - ldr r5, [sp,#20] - ldr r7, =\name - swi 0 - b __unified_syscall +FUNC_START_WEAK \wsym +__syscall \name, \sym, \typ +FUNC_END \wsym .endm +#ifdef __ARM_EABI__ #define syscall(name,sym) __syscall __NR_##name, sym, __ARGS_##name .macro __syscall name sym typ -.text -.type \sym,function -.global \sym -\sym: - stmfd sp!,{r4,r5,r7,lr} - ldr r4, [sp,#16] - ldr r5, [sp,#20] - ldr r7, =\name - swi 0 - b __unified_syscall +FUNC_START \sym + ldr ip, =\name + b __unified_syscall_swi +FUNC_END \sym .endm #else -#define syscall_weak(name,wsym,sym) __syscall_weak $__NR_##name, wsym, sym, __ARGS_##name -.macro __syscall_weak name wsym sym typ -.text -.type \wsym,function -.weak \wsym -\wsym: -.type \sym,function -.global \sym -\sym: -.ifgt \typ - mov ip, sp - stmfd sp!,{r4, r5, r6} - ldmia ip, {r4, r5, r6} -.endif - swi \name -.ifgt \typ - b __unified_syscall4 -.else - b __unified_syscall -.endif -.endm - #define syscall(name,sym) __syscall $__NR_##name, sym, __ARGS_##name .macro __syscall name sym typ -.text -.type \sym,function -.global \sym -\sym: +FUNC_START \sym .ifgt \typ mov ip, sp stmfd sp!,{r4, r5, r6} @@ -899,6 +859,7 @@ .else b __unified_syscall .endif +FUNC_END \sym .endm #endif diff --git a/arm/unified.S b/arm/unified.S index e6ea3f66..7f6d5311 100644 --- a/arm/unified.S +++ b/arm/unified.S @@ -1,22 +1,29 @@ - #include +#include "arm-features.h" - .text #ifdef __ARM_EABI__ - .align 4 -#else - .align 2 -#endif - .global __unified_syscall - .global __unified_syscall4 +/* expects: + * r0-r3 ... syscall arguments 0-3 + * ip ... syscall number + */ +FUNC_START __unified_syscall_swi + .hidden __unified_syscall_swi + stmfd sp!,{r4,r5,r7,lr} + mov r7, ip + LOAD_ARG4_5 + swi 0 + /* fallthrough to __unified4_syscall */ +FUNC_END __unified_syscall_swi -#ifdef __ARM_EABI__ - -__unified_syscall4: -__unified_syscall: - +/* expects: + * r0 ... syscall return value + * original r4-r7 + lr on stack + */ +FUNC_START __unified_syscall + .hidden __unified_syscall cmn r0, #4096 +#ifndef WANT_THREAD_SAFE rsbcs r2, r0, #0 ldrcs r3, 1f mvncs r0, #0 @@ -25,17 +32,28 @@ __unified_syscall: .balign 4 1: .word errno - +#else + bcc 1f + rsb r4, r0, #0 + bl __errno_location + str r4, [r0] + mvn r0, #0 +1: + ldmfd sp!,{r4,r5,r7,pc} +#endif +FUNC_END __unified_syscall + /* here we go and "reuse" the return for weak-void functions */ #include "dietuglyweaks.h" - mov pc, lr @ return + RET -#else - -__unified_syscall4: +#else + +FUNC_START __unified_syscall4 ldmia sp!, {r4, r5, r6} -__unified_syscall: + +FUNC_START __unified_syscall cmn r0, #4096 movcc pc, lr @ return value comes direct from kernel. @@ -53,10 +71,13 @@ __unified_syscall: /* here we go and "reuse" the return for weak-void functions */ #include "dietuglyweaks.h" - mov pc, lr @ return + RET #ifndef WANT_THREAD_SAFE +.align 2 .L0: .long errno #endif +FUNC_END __unified_syscall +FUNC_END __unified_syscall4 #endif diff --git a/arm/waitpid.S b/arm/waitpid.S index 2c3a75b3..facaff13 100644 --- a/arm/waitpid.S +++ b/arm/waitpid.S @@ -1,15 +1,8 @@ -.text -#ifdef __ARM_EABI__ -.align 4 -#else -.align 2 -#endif -.weak waitpid -.type waitpid, %function -waitpid: -.global __libc_waitpid -.type __libc_waitpid, %function -__libc_waitpid: - mov r3, #0 - b wait4 - .size waitpid, .-waitpid +#include "arm-features.h" + +FUNC_START_WEAK waitpid +FUNC_START __libc_waitpid + mov r3, #0 + b wait4 +FUNC_END __libc_waitpid +FUNC_END waitpid diff --git a/diet.c b/diet.c index 5f3a2ba1..e0406381 100644 --- a/diet.c +++ b/diet.c @@ -25,7 +25,7 @@ static void error(const char *message) { } static const char* Os[] = { - "i386","-Os","-mpreferred-stack-boundary=2", + "i386","-Os","-mpreferred-stack-boundary=4", "-falign-functions=1","-falign-jumps=1", "-falign-loops=1","-fomit-frame-pointer",0, "x86_64","-Os",0, diff --git a/findcflags.sh b/findcflags.sh index 2d600d6a..5b07d970 100755 --- a/findcflags.sh +++ b/findcflags.sh @@ -3,6 +3,6 @@ version=`${1:-gcc} -v 2>&1 |sed -n '/gcc version/ {s/gcc version //;p;}'` case $version in 2.9*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=1 -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 ;; 3.0*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=1 -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 ;; - [34]*) echo -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2;; + [34]*) echo -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4;; *) echo -O2 -pipe -fomit-frame-pointer ;; esac diff --git a/ia64/clone.S b/ia64/clone.S index 0f879704..38bd1a64 100644 --- a/ia64/clone.S +++ b/ia64/clone.S @@ -1,4 +1,4 @@ -/* This is untested code which probably won´t work out of the box! */ +/* This is untested code which probably won't work out of the box! */ #include "syscalls.h" #include @@ -43,4 +43,5 @@ __clone: br.call.dptk.few b0=__error_unified_syscall br.ret.sptk.few b0 .endp __clone +.endp __clone2 .size __clone, . - __clone diff --git a/ia64/unified.S b/ia64/unified.S index 548e0506..4158d9ec 100644 --- a/ia64/unified.S +++ b/ia64/unified.S @@ -16,9 +16,7 @@ .text .globl __unified_syscall -.proc __unified_syscall .globl __error_unified_syscall -.proc __error_unified_syscall .globl _exit .proc _exit @@ -27,11 +25,16 @@ _exit: .endp _exit .size _exit, . - _exit +.proc __unified_syscall __unified_syscall: break.i 0x100000 movl r2=errno cmp.eq p6,p0=-1,r10 ;; +.endp __unified_syscall +.size __unified_syscall, . - __unified_syscall + +.proc __error_unified_syscall __error_unified_syscall: (p6) st4 [r2]=r8 (p6) mov r8=-1 @@ -39,6 +42,6 @@ __error_unified_syscall: #include "dietuglyweaks.h" br.ret.sptk.few rp +.endp __error_unified_syscall -.size __unified_syscall, __error_unified_syscall - __unified_syscall .size __error_unified_syscall, . - __error_unified_syscall diff --git a/include/fcntl.h b/include/fcntl.h index 24b64ba4..1c6c32b7 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -621,8 +621,10 @@ struct flock64 extern int fcntl (int __fd, int __cmd, ...) __THROW; #ifndef __NO_STAT64 extern int fcntl64 (int __fd, int __cmd, ...) __THROW; +extern int fstatat64(int dirfd, const char *pathname, struct stat *buf, int flags) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define fcntl fcntl64 +#define fstatat fstatat64 #endif #endif diff --git a/include/setjmp.h b/include/setjmp.h index 10b0a07b..7fb03031 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -166,7 +166,7 @@ typedef int __jmp_buf[3]; #ifdef __arm__ #define __JMP_BUF_SP 8 #ifndef __ASSEMBLER__ -typedef int __jmp_buf[24]; +typedef int __jmp_buf[10 + 16*2 + 16*2]; #endif #endif diff --git a/include/stdlib.h b/include/stdlib.h index 4976f865..f6e760ab 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -29,7 +29,7 @@ long int strtol(const char *nptr, char **endptr, int base) __THROW; unsigned long int strtoul(const char *nptr, char **endptr, int base) __THROW; extern int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase) __THROW; -extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int g) __THROW; +extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int flags) __THROW; #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L __extension__ long long int strtoll(const char *nptr, char **endptr, int base) __THROW; @@ -43,7 +43,7 @@ double atof(const char *nptr) __THROW; __extension__ long long int atoll(const char *nptr); void exit(int status) __THROW __attribute__((__noreturn__)); -void abort(void) __THROW; +void abort(void) __THROW __attribute__((__noreturn__)); extern int rand(void) __THROW; extern int rand_r(unsigned int *seed) __THROW; diff --git a/include/unistd.h b/include/unistd.h index e1e4457d..56494c0c 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -39,6 +39,8 @@ loff_t lseek64(int fildes, loff_t offset, int whence) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define lseek(fildes,offset,whence) lseek64(fildes,offset,whence) #endif +#else +#define lseek64(fildes,offset,whence) lseek(fildes,offset,whence) #endif int chdir(const char *path) __THROW; diff --git a/lib/__dtostr.c b/lib/__dtostr.c index 1d082e3b..bc612008 100644 --- a/lib/__dtostr.c +++ b/lib/__dtostr.c @@ -5,13 +5,15 @@ static int copystring(char* buf,int maxlen, const char* s) { int i; - for (i=0; i<3&&i0?"inf":"-inf"); - if (isnan(d)) return copystring(buf,maxlen,"nan"); + if (isinf(d)) + return copystring(buf,maxlen, + (d<0)? + (flags&0x02?"-INF":"-inf"): + (flags&0x02?"INF":"inf")); + if (isnan(d)) return copystring(buf,maxlen,flags&0x02?"NAN":"nan"); e10=1+(long)(e*0.30102999566398119802); /* log10(2) */ /* Wir iterieren von Links bis wir bei 0 sind oder maxlen erreicht * ist. Wenn maxlen erreicht ist, machen wir das nochmal in @@ -126,7 +132,7 @@ int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned i if (prec2 || prec>(unsigned int)(buf-oldbuf)+1) { /* more digits wanted */ if (!maxlen) return 0; --maxlen; *buf='.'; ++buf; - if (g) { + if ((flags & 0x01)) { if (prec2) prec=prec2; prec-=buf-oldbuf-1; } else { diff --git a/lib/__utime.c b/lib/__utime.c index e0132653..2d0e4af6 100644 --- a/lib/__utime.c +++ b/lib/__utime.c @@ -1,5 +1,7 @@ -#include #include +#define _BSD_SOURCE +#include +#include #ifndef __NR_utime int utime(const char *filename, const struct utimbuf *times) diff --git a/lib/__v_printf.c b/lib/__v_printf.c index 36202f59..964c0056 100644 --- a/lib/__v_printf.c +++ b/lib/__v_printf.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "dietstdio.h" #include "dietwarning.h" @@ -346,45 +347,49 @@ int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr) #ifdef WANT_FLOATING_POINT_IN_PRINTF /* print a floating point value */ case 'f': + case 'F': case 'g': + case 'G': { - int g=(ch=='g'); + int flags=(((ch&0x5f)=='G') ? 0x01 : 0x00) | ((ch&0x20) ? 0x00 : 0x02); double d=va_arg(arg_ptr,double); s=buf+1; if (width==0) width=1; if (!flag_dot) preci=6; if (flag_sign || d < +0.0) flag_in_sign=1; - sz=__dtostr(d,s,sizeof(buf)-1,width,preci,g); - - if (flag_dot) { - char *tmp; - if ((tmp=strchr(s,'.'))) { - if (preci || flag_hash) ++tmp; - while (preci>0 && *++tmp) --preci; - *tmp=0; - } else if (flag_hash) { - s[sz]='.'; - s[++sz]='\0'; + sz=__dtostr(d,s,sizeof(buf)-1,width,preci,flags); + + if (!isnan(d) && !isinf(d)) { /* skip NaN + INF values */ + if (flag_dot) { + char *tmp; + if ((tmp=strchr(s,'.'))) { + if (preci || flag_hash) ++tmp; + while (preci>0 && *++tmp) --preci; + *tmp=0; + } else if (flag_hash) { + s[sz]='.'; + s[++sz]='\0'; + } } - } - if (g) { - char *tmp,*tmp1; /* boy, is _this_ ugly! */ - if ((tmp=strchr(s,'.'))) { - tmp1=strchr(tmp,'e'); - while (*tmp) ++tmp; - if (tmp1) tmp=tmp1; - while (*--tmp=='0') ; - if (*tmp!='.') ++tmp; - *tmp=0; - if (tmp1) strcpy(tmp,tmp1); + if ((flags&0x01)) { + char *tmp,*tmp1; /* boy, is _this_ ugly! */ + if ((tmp=strchr(s,'.'))) { + tmp1=strchr(tmp,'e'); + while (*tmp) ++tmp; + if (tmp1) tmp=tmp1; + while (*--tmp=='0') ; + if (*tmp!='.') ++tmp; + *tmp=0; + if (tmp1) strcpy(tmp,tmp1); + } } - } - if ((flag_sign || flag_space) && d>=0) { - *(--s)=(flag_sign)?'+':' '; - ++sz; + if ((flag_sign || flag_space) && d>=0) { + *(--s)=(flag_sign)?'+':' '; + ++sz; + } } sz=strlen(s); diff --git a/lib/stackgap.c b/lib/stackgap.c index 55842b14..5bf7bf98 100644 --- a/lib/stackgap.c +++ b/lib/stackgap.c @@ -126,6 +126,9 @@ void __setup_tls(tcbhead_t* mainthread) { #elif defined(__sparc__) register tcbhead_t* __thread_self __asm("%g7"); __thread_self=mainthread; +#elif defined(__arm__) + extern void __arm_set_tls(void*); + __arm_set_tls(mainthread); #else #warning "no idea how to enable TLS on this platform, edit lib/stackgap.c" #endif diff --git a/libpthread/pthread_errno.c b/libpthread/pthread_errno.c deleted file mode 100644 index d035544a..00000000 --- a/libpthread/pthread_errno.c +++ /dev/null @@ -1,5 +0,0 @@ -int errno; - -#include "dietwarning.h" - -link_warning("errno","\e[1;33;41m>>> your multithreaded code uses errno! <<<\e[0m"); diff --git a/libugly/asctime.c b/libugly/asctime.c index e1fcc870..9d304e6b 100644 --- a/libugly/asctime.c +++ b/libugly/asctime.c @@ -1,6 +1,6 @@ #include -static char buf[25]; +static char buf[26]; char *asctime(const struct tm *timeptr) { return asctime_r(timeptr,buf); diff --git a/libugly/asctime_r.c b/libugly/asctime_r.c index 43c5e2cb..aae09ad0 100644 --- a/libugly/asctime_r.c +++ b/libugly/asctime_r.c @@ -25,5 +25,6 @@ char *asctime_r(const struct tm *t, char *buf) { num2str(buf+20,(t->tm_year+1900)/100); num2str(buf+22,(t->tm_year+1900)%100); buf[24]='\n'; + buf[25]='\0'; return buf; } diff --git a/libugly/strftime.c b/libugly/strftime.c index 2a1e8a8b..d327d793 100644 --- a/libugly/strftime.c +++ b/libugly/strftime.c @@ -45,38 +45,39 @@ size_t strftime ( char* dst, size_t max, const char* format, const struct tm* t else again: switch (*format) { -// case '%': *p++ = '%'; break; // reduce size of jump table - case 'n': *p++ = '\n'; break; - case 't': *p++ = '\t'; break; +// case '%': *p++ = '%'; break; // reduce size of jump table + case 'n': *p++ = '\n'; break; + case 't': *p++ = '\t'; break; case 'O': case 'E': ++format; goto again; - case 'c': src = "%b %a %d %k:%M:%S %Z %Y"; goto _strf; - case 'r': src = "%I:%M:%S %p"; goto _strf; - case 'R': src = "%H:%M"; goto _strf; - case 'x': src = "%b %a %d"; goto _strf; - case 'X': src = "%k:%M:%S"; goto _strf; - case 'D': src = "%m/%d/%y"; goto _strf; + case 'c': src = "%b %a %d %k:%M:%S %Z %Y"; goto _strf; + case 'r': src = "%I:%M:%S %p"; goto _strf; + case 'R': src = "%H:%M"; goto _strf; + case 'x': src = "%b %a %d"; goto _strf; + case 'X': src = "%k:%M:%S"; goto _strf; + case 'D': src = "%m/%d/%y"; goto _strf; + case 'F': src = "%Y-%m-%d"; goto _strf; case 'T': src = "%H:%M:%S"; _strf: p += strftime (p, (size_t)(dst+max-p), src, tm); break; - case 'a': src = sweekdays [tm->tm_wday]; goto _str; - case 'A': src = weekdays [tm->tm_wday]; goto _str; + case 'a': src = sweekdays [tm->tm_wday]; goto _str; + case 'A': src = weekdays [tm->tm_wday]; goto _str; case 'h': - case 'b': src = smonths [tm->tm_mon]; goto _str; - case 'B': src = months [tm->tm_mon]; goto _str; + case 'b': src = smonths [tm->tm_mon]; goto _str; + case 'B': src = months [tm->tm_mon]; goto _str; case 'p': src = ampm [tm->tm_hour > 12 ? 3 : 2]; goto _str; case 'P': src = ampm [tm->tm_hour > 12 ? 1 : 0]; goto _str; - case 'C': no = tm->tm_year/100 + 19; goto _no; - case 'd': no = tm->tm_mday; goto _no; - case 'e': no = tm->tm_mday; goto _nos; - case 'H': no = tm->tm_hour; goto _no; - case 'I': no = tm->tm_hour % 12; goto _no; - case 'j': no = tm->tm_yday; goto _no; - case 'k': no = tm->tm_hour; goto _nos; - case 'l': no = tm->tm_hour % 12; goto _nos; - case 'm': no = tm->tm_mon + 1; goto _no; - case 'M': no = tm->tm_min; goto _no; - case 'S': no = tm->tm_sec; goto _no; - case 'u': no = tm->tm_wday ? tm->tm_wday : 7; goto _no; - case 'w': no = tm->tm_wday; goto _no; + case 'C': no = tm->tm_year/100 + 19; goto _no; + case 'd': no = tm->tm_mday; goto _no; + case 'e': no = tm->tm_mday; goto _nos; + case 'H': no = tm->tm_hour; goto _no; + case 'I': no = tm->tm_hour % 12; goto _no; + case 'j': no = tm->tm_yday; goto _no; + case 'k': no = tm->tm_hour; goto _nos; + case 'l': no = tm->tm_hour % 12; goto _nos; + case 'm': no = tm->tm_mon + 1; goto _no; + case 'M': no = tm->tm_min; goto _no; + case 'S': no = tm->tm_sec; goto _no; + case 'u': no = tm->tm_wday ? tm->tm_wday : 7; goto _no; + case 'w': no = tm->tm_wday; goto _no; case 'U': no = (tm->tm_yday - tm->tm_wday + 7) / 7; goto _no; case 'W': no = (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7; goto _no; case 's': { diff --git a/libugly/strptime.c b/libugly/strptime.c index 9d7f530c..7babbb7d 100644 --- a/libugly/strptime.c +++ b/libugly/strptime.c @@ -119,10 +119,10 @@ char* strptime(const char* s,const char* format, struct tm* tm) { ++s; break; case 'x': - s=strptime(s,"%b %a %d",tm); + s=strptime(s,"%m/%d/%y",tm); break; case 'X': - s=strptime(s,"%k:%M:%S",tm); + s=strptime(s,"%H:%M:%S",tm); break; case 'y': i=getint(&s,2); diff --git a/parisc/strcmp.S b/parisc/strcmp.S index 9dddd59d..737cbdb1 100644 --- a/parisc/strcmp.S +++ b/parisc/strcmp.S @@ -1,6 +1,8 @@ .text .globl strcmp +.weak strcoll +strcoll: strcmp: .PROC .CALLINFO diff --git a/s390/Makefile.add b/s390/Makefile.add index b70b9715..65c20f00 100644 --- a/s390/Makefile.add +++ b/s390/Makefile.add @@ -1,4 +1,4 @@ CFLAGS+=-Os # -fomit-frame-pointer -fstrict-aliasing VPATH:=s390:syscalls.s:$(VPATH) -LIBOBJ+=$(OBJDIR)/__waitpid.o +LIBOBJ+=$(OBJDIR)/__waitpid.o $(OBJDIR)/__fadvise.o diff --git a/s390/__fadvise.c b/s390/__fadvise.c new file mode 100644 index 00000000..f06b8a3c --- /dev/null +++ b/s390/__fadvise.c @@ -0,0 +1,29 @@ +#include "syscalls.h" + +#define _LINUX_SOURCE +#include +#include + +struct fadvise64_64_layout +{ + int fd; + off64_t offset; + off64_t len; + int advise; +}; + +long fadvise64_64(int fd, off64_t offset, off64_t len, int advise) +{ + struct fadvise64_64_layout parameters; + extern long __s390_fadvise64_64(struct fadvise64_64_layout *args); + + parameters.fd = fd; + parameters.offset = offset; + parameters.len = len; + parameters.advise = advise; + + return __s390_fadvise64_64(¶meters); +} + +int posix_fadvise(int fd, off64_t offset, off64_t len, int advise) + __attribute__((__alias__("fadvise64_64"))); diff --git a/s390/setjmp.S b/s390/setjmp.S index 7522373c..762f9e34 100644 --- a/s390/setjmp.S +++ b/s390/setjmp.S @@ -14,6 +14,7 @@ __setjmp: .global _setjmp .type _setjmp,@function +_setjmp: lhi %r3,0 .size _setjmp,.-_setjmp @@ -26,15 +27,18 @@ __sigsetjmp: std %f6,48(%r2) /* Make a tail call to __sigjmp_save; it takes the same args. */ - basr %r1,%r0 + basr %r1,0 #ifdef PIC -.L0: la %r1,.L1-.L0(0,%r1) +.L0: al %r1,.L1-.L0(0,%r1) l %r1,__sigjmp_save@GOT12(0,%r1) +#else +.L0: l %r1,.L1-.L0(0,%r1) +#endif br %r1 + .p2align 3 +#ifdef PIC .L1: .long _GLOBAL_OFFSET_TABLE_-.L0 #else - l %r1,.L1(0,%r1) - br %r1 .L1: .long __sigjmp_save #endif .size __sigsetjmp,.-__sigsetjmp; diff --git a/s390/syscalls.h b/s390/syscalls.h index a383547d..922a72bc 100644 --- a/s390/syscalls.h +++ b/s390/syscalls.h @@ -277,6 +277,7 @@ #define __NR_mknodat 290 #define __NR_fchownat 291 #define __NR_futimesat 292 +#define __NR_fstatat64 293 #define __NR_unlinkat 294 #define __NR_renameat 295 #define __NR_linkat 296 diff --git a/s390x/setjmp.S b/s390x/setjmp.S index 7522373c..762f9e34 100644 --- a/s390x/setjmp.S +++ b/s390x/setjmp.S @@ -14,6 +14,7 @@ __setjmp: .global _setjmp .type _setjmp,@function +_setjmp: lhi %r3,0 .size _setjmp,.-_setjmp @@ -26,15 +27,18 @@ __sigsetjmp: std %f6,48(%r2) /* Make a tail call to __sigjmp_save; it takes the same args. */ - basr %r1,%r0 + basr %r1,0 #ifdef PIC -.L0: la %r1,.L1-.L0(0,%r1) +.L0: al %r1,.L1-.L0(0,%r1) l %r1,__sigjmp_save@GOT12(0,%r1) +#else +.L0: l %r1,.L1-.L0(0,%r1) +#endif br %r1 + .p2align 3 +#ifdef PIC .L1: .long _GLOBAL_OFFSET_TABLE_-.L0 #else - l %r1,.L1(0,%r1) - br %r1 .L1: .long __sigjmp_save #endif .size __sigsetjmp,.-__sigsetjmp; diff --git a/sparc/strchr.S b/sparc/strchr.S index e27e4541..8c2c78c6 100644 --- a/sparc/strchr.S +++ b/sparc/strchr.S @@ -11,6 +11,8 @@ .text .globl strchr +.weak index +index: strchr: ldub [%o0], %o2 cmp %o2, %o1 diff --git a/sparc/strcmp.S b/sparc/strcmp.S index 50c82b5e..81379f20 100644 --- a/sparc/strcmp.S +++ b/sparc/strcmp.S @@ -11,6 +11,8 @@ .text .globl strcmp +.weak strcoll +strcoll: strcmp: clr %o4 .Lloop: diff --git a/syscalls.s/fadvise64.S b/syscalls.s/fadvise64.S index 89a6eea6..23e01e46 100644 --- a/syscalls.s/fadvise64.S +++ b/syscalls.s/fadvise64.S @@ -3,15 +3,14 @@ #include "syscalls.h" +#ifdef __NR_fadvise64 +syscall(fadvise64,fadvise64) + #ifndef __NR_fadvise64_64 +posix_fadvise = fadvise64 .globl posix_fadvise -.type posix_fadvise,@function -posix_fadvise: #endif -#ifdef __NR_fadvise64 -syscall(fadvise64,fadvise64) - #endif #endif diff --git a/syscalls.s/newfstatat.S b/syscalls.s/newfstatat.S index daa27147..f10d087a 100644 --- a/syscalls.s/newfstatat.S +++ b/syscalls.s/newfstatat.S @@ -2,4 +2,12 @@ #ifdef __NR_newfstatat syscall(newfstatat,newfstatat) + +#ifdef __NR_fstatat64 +# error __NR_newfstatat and __NR_fstatat64 must not both be defined +#endif + +fstatat = newfstatat +.globl fstatat + #endif diff --git a/test/asprintf.c b/test/asprintf.c index 996a5aa5..0d4f2eb3 100644 --- a/test/asprintf.c +++ b/test/asprintf.c @@ -13,7 +13,7 @@ int main(int argc, char **argv) { assert(strlen(path) == asprintlen); printf("%s\n", path); - asprintlen=asprintf(&path, "/proc" "/%d/stat", strlen(argv[1])); + asprintlen=asprintf(&path, "/proc" "/%zu/stat", strlen(argv[1])); assert(strlen(path) == asprintlen); printf("%s\n", path); diff --git a/test/atexit.c b/test/atexit.c index 709a3e44..79ee392b 100644 --- a/test/atexit.c +++ b/test/atexit.c @@ -2,7 +2,7 @@ #include void blah(void) { - write(2,"atexit\n",7); + write(1,"atexit\n",7); } int main() { diff --git a/test/cycles.c b/test/cycles.c index 35547f8a..c7805cd3 100644 --- a/test/cycles.c +++ b/test/cycles.c @@ -12,6 +12,18 @@ asm volatile ("rdtsc" : "=a" (l), "=d" (h)); \ dst = (((uint64_t)h) << 32) | l; \ } while (0) +#elif defined (__powerpc64__) +#define RDTSC(dst) asm volatile ("mftb %0" : "=r" (dst)) +#elif defined (__powerpc__) +#define RDTSC(dst) do { \ + uint32_t chk, tbl, tbu; \ + /* The code below is as suggested in Motorola reference manual for 32 bits PPCs. */ \ + __asm__ __volatile__ ("1: mftbu %0; mftb %1; mftbu %2; cmpw %2,%0; bne 1b" \ + : "=r" (tbu), "=r" (tbl), "=r" (chk) ); \ + dst = ((uint64_t)tbu << 32) | tbl; \ +} while (0) +#elif defined (__sparcv9__) +#define RDTSC(dst) asm volatile ("rd %%tick, %%0":"=r"(dst)) #else #error "Unimplemented rdtsc" #endif