# Makefile configuration, without explicit rules
#
+# CROSS is the prefix used for system tools like gcc, ld etc.
+CROSS =
+
+# KCROSS is the prefix we use for klibc installations. This is usually
+# the same as CROSS, but may be different, e.g. to install an i386
+# cross-compilation suite on an x86-64 system, using the same gcc/binutils.
+KCROSS ?= $(CROSS)
+
# Location for installation
prefix = /usr
bindir = $(prefix)/bin
KRNLOBJ = $(SRCROOT)/linux
ARCH = $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
-CROSS =
CC = $(CROSS)gcc
LD = $(CROSS)ld
KLIBSRC = $(SRCROOT)/klibc
rm -f $@
echo 'ARCH=$(ARCH)' >> $@
echo 'CROSS=$(CROSS)' >> $@
+ echo 'KCROSS=$(KCROSS)' >> $@
echo "CC=$(shell bash -c 'type -p $(CC)')" >> $@
echo "LD=$(shell bash -c 'type -p $(LD)')" >> $@
echo 'REQFLAGS=$(filter-out -I%,$(REQFLAGS))' >> $@
mkdir -p $(INSTALLROOT)$(mandir)/man1
mkdir -p $(INSTALLROOT)$(SHLIBDIR)
mkdir -p $(INSTALLROOT)$(INSTALLDIR)
- -rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include
- mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include
- mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)lib
- mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin
- set -xe ; for d in linux asm asm-generic ; do \
+ -rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+ mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+ mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
+ mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
+ set -xe ; for d in linux asm-$(ARCH) asm-generic $(ASMARCH); do \
mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/$$d ; \
- cp -rfL $(KRNLSRC)/include/$$d/. $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/$$d/. ; \
- cp -rfL $(KRNLOBJ)/include/$$d/. $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/$$d/. ; \
- [ ! -d $(KRNLOBJ)/include2/$$d ] || \
- cp -rfL $(KRNLOBJ)/include2/$$d/. $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/$$d/. ; \
+ for r in $(KRNLSRC)/include $(KRNLOBJ)/include $(KRNLOBJ)/include2 ; do \
+ [ ! -d $$r/$$d ] || \
+ cp -rfL $$r/$$d/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/$$d/. ; \
+ done ; \
done
- cp -rf include/. $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/.
- $(INSTALL_DATA) klcc.1 $(INSTALLROOT)$(mandir)/man1/$(CROSS)klcc.1
- $(INSTALL_EXEC) $(CROSS)klcc $(INSTALLROOT)$(bindir)
+ cd $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include && ln -sf asm-$(ARCH) asm
+ cp -rf include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
+ $(INSTALL_DATA) klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
+ $(INSTALL_EXEC) $(KCROSS)klcc $(INSTALLROOT)$(bindir)
-include MCONFIG
#ifndef _KLIBC_ARCHSIGNAL_H
#define _KLIBC_ARCHSIGNAL_H
-/* No special stuff for this architecture */
+/* Hidden definitions */
+
+struct __new_sigaction {
+ __sighandler_t sa_handler;
+ unsigned long sa_flags;
+ void (*sa_restorer)(void); /* Not used by Linux/SPARC */
+ __new_sigset_t sa_mask;
+};
+
+struct k_sigaction {
+ struct __new_sigaction sa;
+ void __user *ka_restorer;
+};
+
+struct __old_sigaction {
+ __sighandler_t sa_handler;
+ __old_sigset_t sa_mask;
+ unsigned long sa_flags;
+ void (*sa_restorer) (void); /* not used by Linux/SPARC */
+};
+
+typedef struct sigaltstack {
+ void __user *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+} stack_t;
#endif
#ifndef _SYS_TIMES_H
#define _SYS_TIMES_H
+#include <klibc/extern.h>
+#include <sys/types.h>
#include <linux/times.h>
__extern clock_t times(struct tms *);
-__extern int gettimeofday(struct timeval *, struct timezone *);
-__extern int settimeofday(const struct timeval *, const struct timezone *);
#endif /* _SYS_TIMES_H */
# -*- perl -*-
# Standard includes
-@includes = ("-I${INSTALLDIR}/${CROSS}include/arch/${ARCH}",
- "-I${INSTALLDIR}/${CROSS}include/bits${BITSIZE}",
- "-I${INSTALLDIR}/${CROSS}include");
+@includes = ("-I${INSTALLDIR}/${KCROSS}include/arch/${ARCH}",
+ "-I${INSTALLDIR}/${KCROSS}include/bits${BITSIZE}",
+ "-I${INSTALLDIR}/${KCROSS}include");
# Default optimization options (for compiles without -g)
@optopt = @OPTFLAGS;
@goptopt = ('-O');
# Options and libraries to pass to ld; shared versus static
-@staticopt = ("$INSTALLDIR/${CROSS}lib/crt0.o");
-@staticlib = ("$INSTALLDIR/${CROSS}lib/libc.a");
-@sharedopt = (@EMAIN, "$INSTALLDIR/${CROSS}lib/interp.o");
-@sharedlib = ('-R', "$INSTALLDIR/lib/${CROSS}libc.so");
+@staticopt = ("$INSTALLDIR/${KCROSS}lib/crt0.o");
+@staticlib = ("$INSTALLDIR/${KCROSS}lib/libc.a");
+@sharedopt = (@EMAIN, "$INSTALLDIR/${KCROSS}lib/interp.o");
+@sharedlib = ('-R', "$INSTALLDIR/${KCROSS}lib/libc.so");
# Returns the language (-x option string) for a specific extension.
sub filename2lang($) {
%description
%{name} is intended to be a minimalistic libc subset for use with
initramfs. It is deliberately written for small size, minimal
-entanglement, and portability, not speed. It is definitely a work in
-progress, and a lot of things are still missing.
+entanglement, and portability, not speed.
+
+%package devel
+Summary: Libraries and tools needed to compile applications against klibc.
+Group: Development/Libraries
+Requires: klibc = %{version}-%{release}
+
+%description devel
+This package contains the link libraries, header files, and gcc
+wrapper scripts needed to compile applications against klibc.
%package utils
Summary: Small utilities built with klibc.
Group: Utilities/System
-Requires: klibc = %{version}
+Requires: klibc = %{version}-%{release}
%description utils
This package contains a collection of programs that are linked against
INSTALLDIR=%{klibcdir} mandir=%{_mandir} INSTALLROOT=%{buildroot} \
install
-# Install the docs
+# Make the .so file in /lib a hardlink (they will be expanded as two
+# files automatically if it crosses filesystems when extracted.)
+ln -f %{buildroot}%{klibcdir}/lib/klibc-*.so %{buildroot}/lib
+# Install the docs
mkdir -p %{buildroot}%{bindocdir} %{buildroot}%{libdocdir}
install -m 444 README %{buildroot}%{libdocdir}
install -m 444 klibc/README %{buildroot}%{libdocdir}/README.klibc
%clean
rm -rf $RPM_BUILD_ROOT
+#
+# Note: libc.so and interp.o are technically -devel files, but
+# put them in this package until we can make really, really sure
+# the dependency system can avoid confusion. (In fact, it would be
+# good to eventually get them out of here, so that multiple runtimes
+# can be installed should it be necessary.)
+#
%files
%defattr(-,root,root,-)
-%{klibcdir}/lib
+/lib/klibc-*.so
+%{klibcdir}/lib/*.so
+%{klibcdir}/lib/interp.o
+
+%files devel
+%defattr(-,root,root,-)
%{klibcdir}/include
+%{klibcdir}/lib/*.a
+%{klibcdir}/lib/crt0.o
%{_bindir}/klcc
-/lib/klibc-*.so
%doc %{_mandir}/man1/*
%doc %{libdocdir}/*
$(SOHASH): $(SOLIB) $(SOLIB).hash
cp -f $(SOLIB) $@
- $(STRIP) $@
+ $(STRIPCMD) $@
rm -f klibc-??????????????????????.so
ln -f $@ klibc-`cat $(SOLIB).hash`.so
; Signal operations
;
int kill(pid_t, int)
+; We really should get rid of the non-rt_* of these, but that takes
+; sanitizing <signal.h> for all architectures, sigh...
<?> int sigaction(int, const struct sigaction *, struct sigaction *)
-int rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t)
<?> int sigsuspend(const sigset_t *)
+<?> int sigpending(sigset_t *)
+<?> int sigprocmask(int, const sigset_t *, sigset_t *)
+int rt_sigaction(int, const struct sigaction *, struct sigaction *, size_t)
int rt_sigsuspend(const sigset_t *, size_t)
-<?> int sigpending(sigset_t)
int rt_sigpending(sigset_t *, size_t)
-<?> int sigprocmask(int, const sigset_t *, sigset_t *)
int rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t)
<?> unsigned int alarm(unsigned int)
int getitimer(int, struct itimerval *)
#
# Enable this to compile with register parameters; only safe for
-# gcc > 3
-REGPARM_OPT := -mregparm=3 -DREGPARM=3
+# gcc >= 3
+REGPARM_OPT := -mregparm=3 -D_REGPARM=3
gcc_major := $(shell echo __GNUC__ | $(CC) -E -xc - | tail -n 1)
-OPTFLAGS = -march=i386 -Os -g
+OPTFLAGS = -march=i386 -Os -g -fomit-frame-pointer
LDFLAGS = -m elf_i386
-ifneq ($(shell if [ $(gcc_major) -gt 2 ] ; then echo "new"; fi ;),)
-REGPARM := $(REGPARM_OPT)
+ifneq ($(gcc_major),2)
+REQFLAGS += $(REGPARM_OPT)
OPTFLAGS += -falign-functions=0 -falign-jumps=0 -falign-loops=0
ARCHREQFLAGS += -m32
else
push %ebp # Keep gdb from getting confused
push %ebp # Keep gdb from getting confused
# Push the arguments and called __libc_init()
-#ifndef REGPARM
+#ifndef _REGPARM
push %edx # atexit() function
push %eax # ELF array
#endif
.globl _exit
.type _exit,@function
_exit:
-#ifdef REGPARM
+#ifdef _REGPARM
movl %eax,%ebx
#else
popl %ebx
.globl __ashldi3
.type __ashldi3,@function
__ashldi3:
-#ifndef REGPARM
+#ifndef _REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movb 12(%esp),%cl
.globl __ashrdi3
.type __ashrdi3,@function
__ashrdi3:
-#ifndef REGPARM
+#ifndef _REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movb 12(%esp),%cl
.globl __lshrdi3
.type __lshrdi3,@function
__lshrdi3:
-#ifndef REGPARM
+#ifndef _REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movb 12(%esp),%cl
.type __muldi3,@function
__muldi3:
push %esi
-#ifndef REGPARM
+#ifndef _REGPARM
movl 8(%esp),%eax
movl %eax,%esi
movl 16(%esp),%ecx
.globl __negdi2
.type __negdi2,@function
__negdi2:
-#ifndef REGPARM
+#ifndef _REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
#endif
.type open,@function
open:
-#ifdef REGPARM
+#ifdef _REGPARM
movl 4(%esp),%eax
movl 8(%esp),%edx
movl 12(%esp),%ecx
.globl setjmp
.type setjmp, @function
setjmp:
-#ifdef REGPARM
+#ifdef _REGPARM
movl %eax,%edx
#else
movl 4(%esp),%edx
.globl longjmp
.type longjmp, @function
longjmp:
-#ifdef REGPARM
+#ifdef _REGPARM
xchgl %eax,%edx
#else
movl 4(%esp),%edx # jmp_ptr address
.globl __syscall_common
.type __syscall_common,@function
__syscall_common:
-#ifdef REGPARM
+#ifdef _REGPARM
xchgl %ebx,(%esp)
#else
popl %eax
pushl %edi
pushl %ebp
-#ifdef REGPARM
+#ifdef _REGPARM
xchgl %eax,%ebx
xchgl %ecx,%edx
movl ARG(0),%esi
print OUT "${fname}:\n";
if ( $stype eq 'varadic' ) {
- print OUT "#ifdef REGPARM\n";
+ print OUT "#ifdef _REGPARM\n";
print OUT "\tmovl 4(%esp),%eax\n";
print OUT "\tmovl 8(%esp),%edx\n";
print OUT "\tmovl 12(%esp),%ecx\n";
# 2 MB - normal binaries start at 4 MB
SHAREDFLAGS = -Ttext 0x00200200
+# Additional asm- directories needed during installation
+ASMARCH = asm-i386
+
#define _KLIBC_IN_OPEN_C
#include <unistd.h>
#include <fcntl.h>
+#include <bitsize.h>
-#if BITSIZE == 32 && !defined(__i386__)
+#if _BITSIZE == 32 && !defined(__i386__)
extern int __open(const char *, int, mode_t);
#include <signal.h>
#include <sys/syscall.h>
-#if !defined(__NR_sigaction)
+#ifndef __NR_sigaction
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
{