From 63c6929d36e5b5802c0983932a3d69e23f330bb5 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Wed, 27 Apr 2011 10:27:09 +0200 Subject: fix allconfig for foxg20 --- mk/build.mk | 6 +- package/cairo/Makefile | 3 + package/dbus/Makefile | 2 + package/dbus/patches/patch-configure | 11 +- package/fontconfig/patches/patch-fontconfig_pc_in | 9 + package/fuse/patches/patch-fuse_pc_in | 9 + .../gdk-pixbuf/patches/patch-gdk-pixbuf-2_0_pc_in | 10 + package/libpthread/Makefile | 2 +- package/libpthread/files/libpthread.so.arm | 5 + package/neon/patches/patch-neon_pc_in | 10 + package/openjdk/Makefile | 2 + package/openjdk/patches/iconv.patch | 49 + package/pcc-libs/Makefile | 1 + package/pcc/Makefile | 1 + target/arm/Makefile | 2 +- target/config/Config.in | 1 - toolchain/uClibc/patches/cris-vfork.patch | 49 - toolchain/uClibc/patches/uClibc-26042011-git.patch | 2506 ++++++++++++++++++++ 18 files changed, 2622 insertions(+), 56 deletions(-) create mode 100644 package/fontconfig/patches/patch-fontconfig_pc_in create mode 100644 package/fuse/patches/patch-fuse_pc_in create mode 100644 package/gdk-pixbuf/patches/patch-gdk-pixbuf-2_0_pc_in create mode 100644 package/libpthread/files/libpthread.so.arm create mode 100644 package/neon/patches/patch-neon_pc_in create mode 100644 package/openjdk/patches/iconv.patch delete mode 100644 toolchain/uClibc/patches/cris-vfork.patch create mode 100644 toolchain/uClibc/patches/uClibc-26042011-git.patch diff --git a/mk/build.mk b/mk/build.mk index 32e125df9..29fb0fc9c 100644 --- a/mk/build.mk +++ b/mk/build.mk @@ -513,7 +513,7 @@ bulk: ( \ echo === building $$arch $$system $$libc on $$(date); \ $(GMAKE) prereq && \ - $(GMAKE) ARCH=$$arch SYSTEM=$$system LIBC=$$libc defconfig; \ + $(GMAKE) ARCH=$$arch SYSTEM=$$system LIBC=$$libc FS=archive defconfig; \ $(GMAKE) VERBOSE=1 all; if [ $$? -ne 0 ]; then touch .exit;fi; \ rm .config; \ ) 2>&1 | tee $(TOPDIR)/bin/$${system}_$${arch}_$$libc/build.log; \ @@ -531,7 +531,7 @@ bulkall: ( \ echo === building $$arch $$system $$libc on $$(date); \ $(GMAKE) prereq && \ - $(GMAKE) ARCH=$$arch SYSTEM=$$system LIBC=$$libc allconfig; \ + $(GMAKE) ARCH=$$arch SYSTEM=$$system LIBC=$$libc FS=archive allconfig; \ $(GMAKE) VERBOSE=1 all; if [ $$? -ne 0 ]; then touch .exit;fi; \ rm .config; \ ) 2>&1 | tee $(TOPDIR)/bin/$${system}_$${arch}_$$libc/build.log; \ @@ -549,7 +549,7 @@ bulkallmod: ( \ echo === building $$arch $$system $$libc on $$(date); \ $(GMAKE) prereq && \ - $(GMAKE) ARCH=$$arch SYSTEM=$$system LIBC=$$libc allmodconfig; \ + $(GMAKE) ARCH=$$arch SYSTEM=$$system LIBC=$$libc FS=archive allmodconfig; \ $(GMAKE) VERBOSE=1 all; if [ $$? -ne 0 ]; then touch .exit;fi; \ rm .config; \ ) 2>&1 | tee $(TOPDIR)/bin/$${system}_$${arch}_$$libc/build.log; \ diff --git a/package/cairo/Makefile b/package/cairo/Makefile index 503468257..f25372af8 100644 --- a/package/cairo/Makefile +++ b/package/cairo/Makefile @@ -28,6 +28,9 @@ $(eval $(call PKG_template,CAIRO,cairo,${PKG_VERSION}-${PKG_RELEASE},${PKG_DEPEN $(eval $(call PKG_template,CAIRO_DEV,cairo-dev,${PKG_VERSION}-${PKG_RELEASE},${PKG_DEPENDS},${PKGSD_CAIRO_DEV},${PKGSC_CAIRO_DEV},${PKG_OPTS})) TARGET_CFLAGS:= $(filter-out -flto,$(TARGET_CFLAGS)) +ifeq ($(TARGET_ARCH),arm) +TARGET_CFLAGS:= $(filter-out -Os,$(TARGET_CFLAGS)) +endif CONFIGURE_ARGS+= --enable-ft=yes \ --enable-tee=yes \ --enable-xlib=yes diff --git a/package/dbus/Makefile b/package/dbus/Makefile index 8b7a96504..02ee6936d 100644 --- a/package/dbus/Makefile +++ b/package/dbus/Makefile @@ -18,6 +18,8 @@ PKG_SUBPKGS:= DBUS DBUS_DEV PKGSC_DBUS_DEV:= devel PKGSD_DBUS_DEV:= DBUS headers +PKG_ARCH_DEPENDS:= !arm + ifeq ($(ADK_STATIC),y) PKG_OPTS:= libonly endif diff --git a/package/dbus/patches/patch-configure b/package/dbus/patches/patch-configure index e5bce5132..1aa31b56b 100644 --- a/package/dbus/patches/patch-configure +++ b/package/dbus/patches/patch-configure @@ -1,5 +1,14 @@ --- dbus-1.4.6.orig/configure 2011-02-17 21:06:57.000000000 +0100 -+++ dbus-1.4.6/configure 2011-04-13 04:47:38.000000000 +0200 ++++ dbus-1.4.6/configure 2011-04-26 16:00:48.797847993 +0200 +@@ -18718,7 +18718,7 @@ DBUS_CLIENT_LIBS="$THREAD_LIBS $NETWORK_ + + + DBUS_BUS_CFLAGS="$XML_CFLAGS" +-DBUS_BUS_LIBS="$XML_LIBS $SELINUX_LIBS $THREAD_LIBS $ADT_LIBS $NETWORK_libs" ++DBUS_BUS_LIBS="$XML_LIBS $SELINUX_LIBS $ADT_LIBS $NETWORK_libs" + + + @@ -19608,18 +19608,6 @@ if test "x$GCC" = "xyes"; then ;; esac diff --git a/package/fontconfig/patches/patch-fontconfig_pc_in b/package/fontconfig/patches/patch-fontconfig_pc_in new file mode 100644 index 000000000..b2670b8df --- /dev/null +++ b/package/fontconfig/patches/patch-fontconfig_pc_in @@ -0,0 +1,9 @@ +--- fontconfig-2.8.0.orig/fontconfig.pc.in 2009-11-16 18:24:52.000000000 +0100 ++++ fontconfig-2.8.0/fontconfig.pc.in 2011-04-25 18:08:32.487672440 +0200 +@@ -7,5 +7,5 @@ Name: Fontconfig + Description: Font configuration and customization library + Version: @VERSION@ + Libs: -L${libdir} -lfontconfig +-Libs.private: @LIBXML2_LIBS@ @EXPAT_LIBS@ @FREETYPE_LIBS@ @ICONV_LIBS@ ++Libs.private: @LIBXML2_LIBS@ @EXPAT_LIBS@ -lfreetype -lz @ICONV_LIBS@ + Cflags: -I${includedir} diff --git a/package/fuse/patches/patch-fuse_pc_in b/package/fuse/patches/patch-fuse_pc_in new file mode 100644 index 000000000..9f21cd567 --- /dev/null +++ b/package/fuse/patches/patch-fuse_pc_in @@ -0,0 +1,9 @@ +--- fuse-2.7.4.orig/fuse.pc.in 2008-02-19 20:51:21.000000000 +0100 ++++ fuse-2.7.4/fuse.pc.in 2011-04-25 18:02:20.087672599 +0200 +@@ -6,5 +6,5 @@ includedir=@includedir@ + Name: fuse + Description: Filesystem in Userspace + Version: @VERSION@ +-Libs: -L${libdir} -lfuse @libfuse_libs@ ++Libs: -L${libdir} -lfuse + Cflags: -I${includedir}/fuse -D_FILE_OFFSET_BITS=64 diff --git a/package/gdk-pixbuf/patches/patch-gdk-pixbuf-2_0_pc_in b/package/gdk-pixbuf/patches/patch-gdk-pixbuf-2_0_pc_in new file mode 100644 index 000000000..ae45cef82 --- /dev/null +++ b/package/gdk-pixbuf/patches/patch-gdk-pixbuf-2_0_pc_in @@ -0,0 +1,10 @@ +--- gdk-pixbuf-2.23.1.orig/gdk-pixbuf-2.0.pc.in 2010-11-30 03:37:47.000000000 +0100 ++++ gdk-pixbuf-2.23.1/gdk-pixbuf-2.0.pc.in 2011-04-25 18:07:16.917662321 +0200 +@@ -13,6 +13,6 @@ Description: Image loading and scaling + Version: @VERSION@ + Requires: gobject-2.0 + Requires.private: gmodule-no-export-2.0 @PNG_DEP_CFLAGS_PACKAGES@ +-Libs: -L${libdir} -lgdk_pixbuf-@GDK_PIXBUF_API_VERSION@ @GDK_PIXBUF_EXTRA_LIBS@ ++Libs: -L${libdir} -lgdk_pixbuf-@GDK_PIXBUF_API_VERSION@ -ltiff -ljpeg -lpng12 -lm + Cflags: -I${includedir}/gdk-pixbuf-@GDK_PIXBUF_API_VERSION@ @GDK_PIXBUF_EXTRA_CFLAGS@ + diff --git a/package/libpthread/Makefile b/package/libpthread/Makefile index 4d61d570a..ed0602c86 100644 --- a/package/libpthread/Makefile +++ b/package/libpthread/Makefile @@ -49,7 +49,7 @@ endif libpthread-dev-install: ifeq ($(ADK_NATIVE),) ${INSTALL_DIR} ${IDIR_LIBPTHREAD_DEV}/usr/lib - ${CP} ./files/libpthread.so.$(ARCH) ${IDIR_LIBPTHREAD_DEV}/usr/lib/libpthread.so + -${CP} ./files/libpthread.so.$(ARCH) ${IDIR_LIBPTHREAD_DEV}/usr/lib/libpthread.so ${CP} ${STAGING_TARGET_DIR}/usr/lib/libpthread_nonshared.a ${IDIR_LIBPTHREAD_DEV}/usr/lib endif diff --git a/package/libpthread/files/libpthread.so.arm b/package/libpthread/files/libpthread.so.arm new file mode 100644 index 000000000..73f6b6c9d --- /dev/null +++ b/package/libpthread/files/libpthread.so.arm @@ -0,0 +1,5 @@ +/* GNU ld script + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ +OUTPUT_FORMAT(elf32-arm) +GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a ) diff --git a/package/neon/patches/patch-neon_pc_in b/package/neon/patches/patch-neon_pc_in new file mode 100644 index 000000000..7ae4faf9a --- /dev/null +++ b/package/neon/patches/patch-neon_pc_in @@ -0,0 +1,10 @@ +--- neon-0.29.5.orig/neon.pc.in 2006-06-26 12:01:29.000000000 +0200 ++++ neon-0.29.5/neon.pc.in 2011-04-25 18:11:35.518922624 +0200 +@@ -6,6 +6,6 @@ includedir=@includedir@ + Name: neon + Description: HTTP/WebDAV client library + Version: @NEON_VERSION@ +-Libs.private: @NEON_LIBS@ ++Libs.private: -lz -lssl -lcrypto -ldl -lxml2 -lm + Libs: -L${libdir} -lneon @NEON_PC_LIBS@ + Cflags: -I${includedir}/neon @NEON_CFLAGS@ diff --git a/package/openjdk/Makefile b/package/openjdk/Makefile index 8d0da3e2c..08d80e4c4 100644 --- a/package/openjdk/Makefile +++ b/package/openjdk/Makefile @@ -24,6 +24,8 @@ PKG_SITES:= http://download.java.net/openjdk/jdk6/promoted/b22/ \ http://icedtea.classpath.org/download/drops/ \ http://icedtea.classpath.org/download/source/ +PKG_CFLINE_OPENJDK:= depends on ADK_TARGET_LIB_GLIBC || ADK_TARGET_LIB_EGLIBC + # autotools infrastructure for OpenJDK ICEDTEA_NAME:= icedtea6 ICEDTEA_VERSION:= 1.10 diff --git a/package/openjdk/patches/iconv.patch b/package/openjdk/patches/iconv.patch new file mode 100644 index 000000000..16a6946f6 --- /dev/null +++ b/package/openjdk/patches/iconv.patch @@ -0,0 +1,49 @@ +diff -Nur w-openjdk-6.orig/openjdk-6/hotspot/make/linux/makefiles/gcc.make w-openjdk-6/openjdk-6/hotspot/make/linux/makefiles/gcc.make +--- w-openjdk-6.orig/openjdk-6/hotspot/make/linux/makefiles/gcc.make 2011-02-28 17:03:13.000000000 +0100 ++++ w-openjdk-6/openjdk-6/hotspot/make/linux/makefiles/gcc.make 2011-04-11 18:36:16.837665258 +0200 +@@ -108,9 +108,6 @@ + CFLAGS += -pipe + endif + +-# Compiler warnings are treated as errors +-WARNINGS_ARE_ERRORS = -Werror +- + # Except for a few acceptable ones + # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit + # conversions which might affect the values. To avoid that, we need to turn +diff -Nur w-openjdk-6.orig/openjdk-6/jdk/make/java/instrument/Makefile w-openjdk-6/openjdk-6/jdk/make/java/instrument/Makefile +--- w-openjdk-6.orig/openjdk-6/jdk/make/java/instrument/Makefile 2011-02-28 17:06:10.000000000 +0100 ++++ w-openjdk-6/openjdk-6/jdk/make/java/instrument/Makefile 2011-04-11 23:14:27.571411016 +0200 +@@ -123,6 +123,8 @@ + # We don't want to link against -ljava + JAVALIB= + ++LDLIBS += -liconv ++ + # + # Add to ambient vpath so we pick up the library files + # +diff -Nur w-openjdk-6.orig/openjdk-6/jdk/make/java/npt/Makefile w-openjdk-6/openjdk-6/jdk/make/java/npt/Makefile +--- w-openjdk-6.orig/openjdk-6/jdk/make/java/npt/Makefile 2011-02-28 17:06:11.000000000 +0100 ++++ w-openjdk-6/openjdk-6/jdk/make/java/npt/Makefile 2011-04-11 23:14:07.017670197 +0200 +@@ -65,6 +65,8 @@ + # We don't want to link against -ljava + JAVALIB= + ++LDLIBS += -liconv ++ + # Add -export options to explicitly spell exported symbols + ifeq ($(PLATFORM), windows) + OTHER_LCF += -export:nptInitialize -export:nptTerminate +diff -Nur w-openjdk-6.orig/openjdk-6/jdk/make/sun/splashscreen/Makefile w-openjdk-6/openjdk-6/jdk/make/sun/splashscreen/Makefile +--- w-openjdk-6.orig/openjdk-6/jdk/make/sun/splashscreen/Makefile 2011-02-28 17:06:12.000000000 +0100 ++++ w-openjdk-6/openjdk-6/jdk/make/sun/splashscreen/Makefile 2011-04-11 23:15:07.221411030 +0200 +@@ -55,6 +55,8 @@ + + JAVALIB= + ++LDLIBS += -liconv ++ + # + # C Flags + # diff --git a/package/pcc-libs/Makefile b/package/pcc-libs/Makefile index 9533b97c9..ec6477779 100644 --- a/package/pcc-libs/Makefile +++ b/package/pcc-libs/Makefile @@ -12,6 +12,7 @@ PKG_SECTION:= lang PKG_URL:= http://pcc.ludd.ltu.se/ PKG_SITES:= http://pcc.ludd.ltu.se/ftp/pub/pcc-releases/ +PKG_ARCH_DEPENDS:= !arm DISTFILES:= ${PKG_NAME}-${PKG_VERSION}.tgz include $(TOPDIR)/mk/package.mk diff --git a/package/pcc/Makefile b/package/pcc/Makefile index a20d3dece..1fd798a74 100644 --- a/package/pcc/Makefile +++ b/package/pcc/Makefile @@ -15,6 +15,7 @@ PKG_URL:= http://pcc.ludd.ltu.se/ PKG_SITES:= http://pcc.ludd.ltu.se/ftp/pub/pcc-releases/ PKG_NOPARALLEL:= 1 +PKG_ARCH_DEPENDS:= !arm DISTFILES:= ${PKG_NAME}-${PKG_VERSION}.tgz include $(TOPDIR)/mk/package.mk diff --git a/target/arm/Makefile b/target/arm/Makefile index 141d2c279..dbf955a81 100644 --- a/target/arm/Makefile +++ b/target/arm/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/mk/modules.mk include $(TOPDIR)/mk/kernel-build.mk include $(TOPDIR)/mk/image.mk -KERNEL:=$(LINUX_DIR)/kernel-adk +KERNEL:=$(LINUX_DIR)/vmlinux LOADADDR:=0x20008000 tools-compile: diff --git a/target/config/Config.in b/target/config/Config.in index 4c8c8bcb5..35c8688b2 100644 --- a/target/config/Config.in +++ b/target/config/Config.in @@ -464,7 +464,6 @@ config ADK_TARGET_ROOTFS_MMC config ADK_TARGET_ROOTFS_ARCHIVE bool "Archive usable for different filesystems" - depends on ADK_HARDWARE_QEMU help Use this option if your root filesystem is ext2/ext3/ext4/xfs. diff --git a/toolchain/uClibc/patches/cris-vfork.patch b/toolchain/uClibc/patches/cris-vfork.patch deleted file mode 100644 index 8e0faa2f3..000000000 --- a/toolchain/uClibc/patches/cris-vfork.patch +++ /dev/null @@ -1,49 +0,0 @@ -diff -Nur uClibc-0.9.32-rc2.orig/libc/sysdeps/linux/cris/Makefile.arch uClibc-0.9.32-rc2/libc/sysdeps/linux/cris/Makefile.arch ---- uClibc-0.9.32-rc2.orig/libc/sysdeps/linux/cris/Makefile.arch 2011-01-20 15:49:47.000000000 +0100 -+++ uClibc-0.9.32-rc2/libc/sysdeps/linux/cris/Makefile.arch 2011-02-07 23:01:26.000000000 +0100 -@@ -7,7 +7,7 @@ - - CSRC := __init_brk.c brk.c sbrk.c - --SSRC := setjmp.S __longjmp.S clone.S sysdep.S syscall.S -+SSRC := setjmp.S __longjmp.S clone.S sysdep.S syscall.S vfork.S - ifeq ($(UNIFIED_SYSCALL),y) - SSRC += __uClibc_syscall.S - endif -diff -Nur uClibc-0.9.32-rc2.orig/libc/sysdeps/linux/cris/vfork.S uClibc-0.9.32-rc2/libc/sysdeps/linux/cris/vfork.S ---- uClibc-0.9.32-rc2.orig/libc/sysdeps/linux/cris/vfork.S 1970-01-01 01:00:00.000000000 +0100 -+++ uClibc-0.9.32-rc2/libc/sysdeps/linux/cris/vfork.S 2011-02-08 00:39:10.000000000 +0100 -@@ -0,0 +1,33 @@ -+/* -+ * vfork.S -+ * -+ * On cris, r9 contains the syscall number (set by generated stub); -+ * r10..r13 contain arguments 0-3 per the standard calling convention. -+ * The return address is in $srp; so we just need to avoid the stack -+ * usage of the normal syscall stubs. -+ */ -+ -+#include -+#include -+ -+ .section ".text","ax" -+ .balign 4 -+ .globl __vfork -+ .type __vfork,@function -+__vfork: -+ move.d __NR_vfork, $r9 -+ break 13 -+ -+ cmps.w -4096,$r10 -+ blo 1f -+ neg.d $r10,$r11 -+ move.d $r11,[errno] -+ moveq -1,$r10 -+1: -+ ret -+ nop -+ -+ .size __vfork,.-__vfork -+ -+weak_alias(__vfork,vfork) -+libc_hidden_weak(vfork) diff --git a/toolchain/uClibc/patches/uClibc-26042011-git.patch b/toolchain/uClibc/patches/uClibc-26042011-git.patch new file mode 100644 index 000000000..bbf4d06f0 --- /dev/null +++ b/toolchain/uClibc/patches/uClibc-26042011-git.patch @@ -0,0 +1,2506 @@ +diff -Nur uClibc-0.9.32-rc3/extra/Configs/Config.in uClibc/extra/Configs/Config.in +--- uClibc-0.9.32-rc3/extra/Configs/Config.in 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/extra/Configs/Config.in 2011-04-26 16:18:21.707661578 +0200 +@@ -1898,6 +1898,18 @@ + This interface is rarely used, and adds around 4.5k. Unless you have + a pressing need for ftw(), you should probably answer N. + ++config UCLIBC_HAS_FTS ++ bool "Support the fts() interface (bsd-compat)" ++ default n ++ help ++ The fts functions are provided for traversing UNIX file hierarchies. ++ ++ This interface is currently used by the elfutils and adds ++ around 7.5k. ++ You should port your application to use the POSIX nftw() ++ interface. ++ ++ Unless you need to build/use elfutils, you should prolly answer N. + + config UCLIBC_HAS_GLOB + bool "Support the glob() interface" +@@ -2322,7 +2334,7 @@ + + config UCLIBC_HAS_BACKTRACE + bool "Add support for application self-debugging" +- depends on HAVE_SHARED && TARGET_sh ++ depends on HAVE_SHARED + default n + help + Answer Y here to compile support for application self-debugging, by adding +diff -Nur uClibc-0.9.32-rc3/include/fts.h uClibc/include/fts.h +--- uClibc-0.9.32-rc3/include/fts.h 1970-01-01 01:00:00.000000000 +0100 ++++ uClibc/include/fts.h 2011-04-26 16:18:21.727663221 +0200 +@@ -0,0 +1,131 @@ ++/* ++ * Copyright (c) 1989, 1993 ++ * The Regents of the University of California. All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * 4. Neither the name of the University nor the names of its contributors ++ * may be used to endorse or promote products derived from this software ++ * without specific prior written permission. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ * ++ * @(#)fts.h 8.3 (Berkeley) 8/14/94 ++ */ ++ ++#ifndef _FTS_H ++#define _FTS_H 1 ++ ++#include ++#include ++ ++/* The fts interface is incompatible with the LFS interface which ++ transparently uses the 64-bit file access functions. */ ++#ifdef __USE_FILE_OFFSET64 ++# error " cannot be used with -D_FILE_OFFSET_BITS==64" ++#endif ++ ++ ++typedef struct { ++ struct _ftsent *fts_cur; /* current node */ ++ struct _ftsent *fts_child; /* linked list of children */ ++ struct _ftsent **fts_array; /* sort array */ ++ dev_t fts_dev; /* starting device # */ ++ char *fts_path; /* path for this descent */ ++ int fts_rfd; /* fd for root */ ++ int fts_pathlen; /* sizeof(path) */ ++ int fts_nitems; /* elements in the sort array */ ++ int (*fts_compar) (const void *, const void *); /* compare fn */ ++ ++#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */ ++#define FTS_LOGICAL 0x0002 /* logical walk */ ++#define FTS_NOCHDIR 0x0004 /* don't change directories */ ++#define FTS_NOSTAT 0x0008 /* don't get stat info */ ++#define FTS_PHYSICAL 0x0010 /* physical walk */ ++#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ ++#define FTS_XDEV 0x0040 /* don't cross devices */ ++#define FTS_WHITEOUT 0x0080 /* return whiteout information */ ++#define FTS_OPTIONMASK 0x00ff /* valid user option mask */ ++ ++#define FTS_NAMEONLY 0x0100 /* (private) child names only */ ++#define FTS_STOP 0x0200 /* (private) unrecoverable error */ ++ int fts_options; /* fts_open options, global flags */ ++} FTS; ++ ++typedef struct _ftsent { ++ struct _ftsent *fts_cycle; /* cycle node */ ++ struct _ftsent *fts_parent; /* parent directory */ ++ struct _ftsent *fts_link; /* next file in directory */ ++ long fts_number; /* local numeric value */ ++ void *fts_pointer; /* local address value */ ++ char *fts_accpath; /* access path */ ++ char *fts_path; /* root path */ ++ int fts_errno; /* errno for this node */ ++ int fts_symfd; /* fd for symlink */ ++ u_short fts_pathlen; /* strlen(fts_path) */ ++ u_short fts_namelen; /* strlen(fts_name) */ ++ ++ ino_t fts_ino; /* inode */ ++ dev_t fts_dev; /* device */ ++ nlink_t fts_nlink; /* link count */ ++ ++#define FTS_ROOTPARENTLEVEL -1 ++#define FTS_ROOTLEVEL 0 ++ short fts_level; /* depth (-1 to N) */ ++ ++#define FTS_D 1 /* preorder directory */ ++#define FTS_DC 2 /* directory that causes cycles */ ++#define FTS_DEFAULT 3 /* none of the above */ ++#define FTS_DNR 4 /* unreadable directory */ ++#define FTS_DOT 5 /* dot or dot-dot */ ++#define FTS_DP 6 /* postorder directory */ ++#define FTS_ERR 7 /* error; errno is set */ ++#define FTS_F 8 /* regular file */ ++#define FTS_INIT 9 /* initialized only */ ++#define FTS_NS 10 /* stat(2) failed */ ++#define FTS_NSOK 11 /* no stat(2) requested */ ++#define FTS_SL 12 /* symbolic link */ ++#define FTS_SLNONE 13 /* symbolic link without target */ ++#define FTS_W 14 /* whiteout object */ ++ u_short fts_info; /* user flags for FTSENT structure */ ++ ++#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ ++#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ ++ u_short fts_flags; /* private flags for FTSENT structure */ ++ ++#define FTS_AGAIN 1 /* read node again */ ++#define FTS_FOLLOW 2 /* follow symbolic link */ ++#define FTS_NOINSTR 3 /* no instructions */ ++#define FTS_SKIP 4 /* discard node */ ++ u_short fts_instr; /* fts_set() instructions */ ++ ++ struct stat *fts_statp; /* stat(2) information */ ++ char fts_name[1]; /* file name */ ++} FTSENT; ++ ++__BEGIN_DECLS ++FTSENT *fts_children (FTS *, int); ++int fts_close (FTS *); ++FTS *fts_open (char * const *, int, ++ int (*)(const FTSENT **, const FTSENT **)); ++FTSENT *fts_read (FTS *); ++int fts_set (FTS *, FTSENT *, int) __THROW; ++__END_DECLS ++ ++#endif /* fts.h */ +diff -Nur uClibc-0.9.32-rc3/ldso/include/dl-elf.h uClibc/ldso/include/dl-elf.h +--- uClibc-0.9.32-rc3/ldso/include/dl-elf.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/include/dl-elf.h 2011-04-26 16:18:21.747664948 +0200 +@@ -184,7 +184,7 @@ + ADJUST_DYN_INFO(DT_DSBT_BASE_IDX, load_off); + + /* Initialize loadmap dsbt info. */ +- load_off.map->dsbt_table = dynamic_info[DT_DSBT_BASE_IDX]; ++ load_off.map->dsbt_table = (void *)dynamic_info[DT_DSBT_BASE_IDX]; + load_off.map->dsbt_size = dynamic_info[DT_DSBT_SIZE_IDX]; + load_off.map->dsbt_index = dynamic_info[DT_DSBT_INDEX_IDX]; + #endif +diff -Nur uClibc-0.9.32-rc3/ldso/include/ldso.h uClibc/ldso/include/ldso.h +--- uClibc-0.9.32-rc3/ldso/include/ldso.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/include/ldso.h 2011-04-26 16:18:21.747664948 +0200 +@@ -34,6 +34,8 @@ + #include + /* Pull in the arch specific page size */ + #include ++/* Pull in the MIN macro */ ++#include + /* Pull in the ldso syscalls and string functions */ + #ifndef __ARCH_HAS_NO_SHARED__ + #include +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/bfin/dl-inlines.h uClibc/ldso/ldso/bfin/dl-inlines.h +--- uClibc-0.9.32-rc3/ldso/ldso/bfin/dl-inlines.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/bfin/dl-inlines.h 2011-04-26 16:18:21.747664948 +0200 +@@ -88,14 +88,39 @@ + segdata->p_memsz = phdr->p_memsz; + + #if defined (__SUPPORT_LD_DEBUG__) +- { +- extern char *_dl_debug; +- extern int _dl_debug_file; +- if (_dl_debug) +- _dl_dprintf(_dl_debug_file, "%i: mapped %x at %x, size %x\n", +- loadaddr.map->nsegs-1, +- segdata->p_vaddr, segdata->addr, segdata->p_memsz); +- } ++ if (_dl_debug) ++ _dl_dprintf(_dl_debug_file, "%i: mapped %x at %x, size %x\n", ++ loadaddr.map->nsegs-1, ++ segdata->p_vaddr, segdata->addr, segdata->p_memsz); ++#endif ++} ++ ++/* Replace an existing entry in the load map. */ ++static __always_inline void ++__dl_update_loadaddr_hdr (struct elf32_fdpic_loadaddr loadaddr, void *addr, ++ Elf32_Phdr *phdr) ++{ ++ struct elf32_fdpic_loadseg *segdata; ++ void *oldaddr; ++ int i; ++ ++ for (i = 0; i < loadaddr.map->nsegs; i++) ++ if (loadaddr.map->segs[i].p_vaddr == phdr->p_vaddr ++ && loadaddr.map->segs[i].p_memsz == phdr->p_memsz) ++ break; ++ if (i == loadaddr.map->nsegs) ++ _dl_exit (-1); ++ ++ segdata = loadaddr.map->segs + i; ++ oldaddr = (void *)segdata->addr; ++ _dl_munmap (oldaddr, segdata->p_memsz); ++ segdata->addr = (Elf32_Addr) addr; ++ ++#if defined (__SUPPORT_LD_DEBUG__) ++ if (_dl_debug) ++ _dl_dprintf(_dl_debug_file, "%i: changed mapping %x at %x (old %x), size %x\n", ++ loadaddr.map->nsegs-1, ++ segdata->p_vaddr, segdata->addr, oldaddr, segdata->p_memsz); + #endif + } + +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/bfin/dl-sysdep.h uClibc/ldso/ldso/bfin/dl-sysdep.h +--- uClibc-0.9.32-rc3/ldso/ldso/bfin/dl-sysdep.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/bfin/dl-sysdep.h 2011-04-26 16:18:21.747664948 +0200 +@@ -120,6 +120,8 @@ + #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \ + (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \ + dl_init_loadaddr_load_count)) ++#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \ ++ (__dl_update_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR))) + #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \ + (__dl_loadaddr_unmap ((LOADADDR), (NULL))) + #define DL_LIB_UNMAP(LIB, LEN) \ +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/c6x/dl-inlines.h uClibc/ldso/ldso/c6x/dl-inlines.h +--- uClibc-0.9.32-rc3/ldso/ldso/c6x/dl-inlines.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/c6x/dl-inlines.h 2011-04-26 16:18:21.747664948 +0200 +@@ -74,6 +74,35 @@ + #endif + } + ++/* Replace an existing entry in the load map. */ ++static __always_inline void ++__dl_update_loadaddr_hdr (struct elf32_dsbt_loadaddr loadaddr, void *addr, ++ Elf32_Phdr *phdr) ++{ ++ struct elf32_dsbt_loadseg *segdata; ++ void *oldaddr; ++ int i; ++ ++ for (i = 0; i < loadaddr.map->nsegs; i++) ++ if (loadaddr.map->segs[i].p_vaddr == phdr->p_vaddr ++ && loadaddr.map->segs[i].p_memsz == phdr->p_memsz) ++ break; ++ if (i == loadaddr.map->nsegs) ++ _dl_exit (-1); ++ ++ segdata = loadaddr.map->segs + i; ++ oldaddr = (void *)segdata->addr; ++ _dl_munmap (oldaddr, segdata->p_memsz); ++ segdata->addr = (Elf32_Addr) addr; ++ ++#if defined (__SUPPORT_LD_DEBUG__) ++ if (_dl_debug) ++ _dl_dprintf(_dl_debug_file, "%i: changed mapping %x at %x (old %x), size %x\n", ++ loadaddr.map->nsegs-1, ++ segdata->p_vaddr, segdata->addr, oldaddr, segdata->p_memsz); ++#endif ++} ++ + static __always_inline void + __dl_loadaddr_unmap (struct elf32_dsbt_loadaddr loadaddr) + { +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/c6x/dl-sysdep.h uClibc/ldso/ldso/c6x/dl-sysdep.h +--- uClibc-0.9.32-rc3/ldso/ldso/c6x/dl-sysdep.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/c6x/dl-sysdep.h 2011-04-26 16:18:21.747664948 +0200 +@@ -104,6 +104,9 @@ + (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \ + dl_init_loadaddr_load_count)) + ++#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \ ++ (__dl_update_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR))) ++ + #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \ + (__dl_loadaddr_unmap ((LOADADDR))) + +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/c6x/elfinterp.c uClibc/ldso/ldso/c6x/elfinterp.c +--- uClibc-0.9.32-rc3/ldso/ldso/c6x/elfinterp.c 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/c6x/elfinterp.c 2011-04-26 16:18:21.747664948 +0200 +@@ -198,6 +198,10 @@ + new_val = sym_val; + *reloc_addr = sym_val; + break; ++ case R_C6000_DSBT_INDEX: ++ new_val = (old_val & ~0x007fff00) | ((tpnt->loadaddr.map->dsbt_index & 0x7fff) << 8); ++ *reloc_addr = new_val; ++ break; + case R_C6000_ABS_L16: + new_val = (old_val & ~0x007fff80) | ((sym_val & 0xffff) << 7); + *reloc_addr = new_val; +@@ -224,7 +228,7 @@ + (char *)symbol_addr, + symtab[symtab_index].st_size); + } +- break; ++ return 0; + default: + return -1; /*call _dl_exit(1) */ + } +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/dl-elf.c uClibc/ldso/ldso/dl-elf.c +--- uClibc-0.9.32-rc3/ldso/ldso/dl-elf.c 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/dl-elf.c 2011-04-26 16:18:21.747664948 +0200 +@@ -314,6 +314,121 @@ + return NULL; + } + ++/* ++ * Make a writeable mapping of a segment, regardless of whether PF_W is ++ * set or not. ++ */ ++static void * ++map_writeable (int infile, ElfW(Phdr) *ppnt, int piclib, int flags, ++ unsigned long libaddr) ++{ ++ int prot_flags = ppnt->p_flags | PF_W; ++ char *status, *retval; ++ char *tryaddr; ++ ssize_t size; ++ unsigned long map_size; ++ char *cpnt; ++ char *piclib2map = NULL; ++ ++ if (piclib == 2 && ++ /* We might be able to avoid this call if memsz doesn't ++ require an additional page, but this would require mmap ++ to always return page-aligned addresses and a whole ++ number of pages allocated. Unfortunately on uClinux ++ may return misaligned addresses and may allocate ++ partial pages, so we may end up doing unnecessary mmap ++ calls. ++ ++ This is what we could do if we knew mmap would always ++ return aligned pages: ++ ++ ((ppnt->p_vaddr + ppnt->p_filesz + ADDR_ALIGN) & ++ PAGE_ALIGN) < ppnt->p_vaddr + ppnt->p_memsz) ++ ++ Instead, we have to do this: */ ++ ppnt->p_filesz < ppnt->p_memsz) ++ { ++ piclib2map = (char *) ++ _dl_mmap(0, (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_memsz, ++ LXFLAGS(prot_flags), flags | MAP_ANONYMOUS, -1, 0); ++ if (_dl_mmap_check_error(piclib2map)) ++ return 0; ++ } ++ ++ tryaddr = piclib == 2 ? piclib2map ++ : ((char*) (piclib ? libaddr : 0) + ++ (ppnt->p_vaddr & PAGE_ALIGN)); ++ ++ size = (ppnt->p_vaddr & ADDR_ALIGN) + ppnt->p_filesz; ++ ++ /* For !MMU, mmap to fixed address will fail. ++ So instead of desperately call mmap and fail, ++ we set status to MAP_FAILED to save a call ++ to mmap (). */ ++#ifndef __ARCH_USE_MMU__ ++ if (piclib2map == 0) ++#endif ++ status = (char *) _dl_mmap ++ (tryaddr, size, LXFLAGS(prot_flags), ++ flags | (piclib2map ? MAP_FIXED : 0), ++ infile, ppnt->p_offset & OFFS_ALIGN); ++#ifndef __ARCH_USE_MMU__ ++ else ++ status = MAP_FAILED; ++#endif ++#ifdef _DL_PREAD ++ if (_dl_mmap_check_error(status) && piclib2map ++ && (_DL_PREAD (infile, tryaddr, size, ++ ppnt->p_offset & OFFS_ALIGN) == size)) ++ status = tryaddr; ++#endif ++ if (_dl_mmap_check_error(status) || (tryaddr && tryaddr != status)) ++ return 0; ++ ++ if (piclib2map) ++ retval = piclib2map; ++ else ++ retval = status; ++ ++ /* Now we want to allocate and zero-out any data from the end ++ of the region we mapped in from the file (filesz) to the ++ end of the loadable segment (memsz). We may need ++ additional pages for memsz, that we map in below, and we ++ can count on the kernel to zero them out, but we have to ++ zero out stuff in the last page that we mapped in from the ++ file. However, we can't assume to have actually obtained ++ full pages from the kernel, since we didn't ask for them, ++ and uClibc may not give us full pages for small ++ allocations. So only zero out up to memsz or the end of ++ the page, whichever comes first. */ ++ ++ /* CPNT is the beginning of the memsz portion not backed by ++ filesz. */ ++ cpnt = (char *) (status + size); ++ ++ /* MAP_SIZE is the address of the ++ beginning of the next page. */ ++ map_size = (ppnt->p_vaddr + ppnt->p_filesz ++ + ADDR_ALIGN) & PAGE_ALIGN; ++ ++ _dl_memset (cpnt, 0, ++ MIN (map_size ++ - (ppnt->p_vaddr ++ + ppnt->p_filesz), ++ ppnt->p_memsz ++ - ppnt->p_filesz)); ++ ++ if (map_size < ppnt->p_vaddr + ppnt->p_memsz && !piclib2map) { ++ tryaddr = map_size + (char*)(piclib ? libaddr : 0); ++ status = (char *) _dl_mmap(tryaddr, ++ ppnt->p_vaddr + ppnt->p_memsz - map_size, ++ LXFLAGS(prot_flags), ++ flags | MAP_ANONYMOUS | MAP_FIXED, -1, 0); ++ if (_dl_mmap_check_error(status) || tryaddr != status) ++ return NULL; ++ } ++ return retval; ++} + + /* + * Read one ELF library into memory, mmap it into the correct locations and +@@ -475,6 +590,7 @@ + status = (char *) _dl_mmap((char *) (piclib ? 0 : minvma), + maxvma - minvma, PROT_NONE, flags | MAP_ANONYMOUS, -1, 0); + if (_dl_mmap_check_error(status)) { ++ cant_map: + _dl_dprintf(2, "%s:%i: can't map '%s'\n", _dl_progname, __LINE__, libname); + _dl_internal_error_number = LD_ERROR_MMAP_FAILED; + _dl_close(infile); +@@ -495,8 +611,11 @@ + char *addr; + + addr = DL_MAP_SEGMENT (epnt, ppnt, infile, flags); +- if (addr == NULL) ++ if (addr == NULL) { ++ cant_map1: ++ DL_LOADADDR_UNMAP (lib_loadaddr, maxvma - minvma); + goto cant_map; ++ } + + DL_INIT_LOADADDR_HDR (lib_loadaddr, addr, ppnt); + ppnt++; +@@ -517,141 +636,9 @@ + } + + if (ppnt->p_flags & PF_W) { +- unsigned long map_size; +- char *cpnt; +- char *piclib2map = 0; +- +- if (piclib == 2 && +- /* We might be able to avoid this +- call if memsz doesn't require +- an additional page, but this +- would require mmap to always +- return page-aligned addresses +- and a whole number of pages +- allocated. Unfortunately on +- uClinux may return misaligned +- addresses and may allocate +- partial pages, so we may end up +- doing unnecessary mmap calls. +- +- This is what we could do if we +- knew mmap would always return +- aligned pages: +- +- ((ppnt->p_vaddr + ppnt->p_filesz +- + ADDR_ALIGN) +- & PAGE_ALIGN) +- < ppnt->p_vaddr + ppnt->p_memsz) +- +- Instead, we have to do this: */ +- ppnt->p_filesz < ppnt->p_memsz) +- { +- piclib2map = (char *) +- _dl_mmap(0, (ppnt->p_vaddr & ADDR_ALIGN) +- + ppnt->p_memsz, +- LXFLAGS(ppnt->p_flags), +- flags | MAP_ANONYMOUS, -1, 0); +- if (_dl_mmap_check_error(piclib2map)) +- goto cant_map; +- DL_INIT_LOADADDR_HDR +- (lib_loadaddr, piclib2map +- + (ppnt->p_vaddr & ADDR_ALIGN), ppnt); +- } +- +- tryaddr = piclib == 2 ? piclib2map +- : ((char*) (piclib ? libaddr : 0) + +- (ppnt->p_vaddr & PAGE_ALIGN)); +- +- size = (ppnt->p_vaddr & ADDR_ALIGN) +- + ppnt->p_filesz; +- +- /* For !MMU, mmap to fixed address will fail. +- So instead of desperately call mmap and fail, +- we set status to MAP_FAILED to save a call +- to mmap (). */ +-#ifndef __ARCH_USE_MMU__ +- if (piclib2map == 0) +-#endif +- status = (char *) _dl_mmap +- (tryaddr, size, LXFLAGS(ppnt->p_flags), +- flags | (piclib2map ? MAP_FIXED : 0), +- infile, ppnt->p_offset & OFFS_ALIGN); +-#ifndef __ARCH_USE_MMU__ +- else +- status = MAP_FAILED; +-#endif +-#ifdef _DL_PREAD +- if (_dl_mmap_check_error(status) && piclib2map +- && (_DL_PREAD (infile, tryaddr, size, +- ppnt->p_offset & OFFS_ALIGN) +- == size)) +- status = tryaddr; +-#endif +- if (_dl_mmap_check_error(status) +- || (tryaddr && tryaddr != status)) { +- cant_map: +- _dl_dprintf(2, "%s:%i: can't map '%s'\n", +- _dl_progname, __LINE__, libname); +- _dl_internal_error_number = LD_ERROR_MMAP_FAILED; +- DL_LOADADDR_UNMAP (lib_loadaddr, maxvma - minvma); +- _dl_close(infile); +- _dl_munmap(header, _dl_pagesize); +- return NULL; +- } +- +- if (! piclib2map) { +- DL_INIT_LOADADDR_HDR +- (lib_loadaddr, status +- + (ppnt->p_vaddr & ADDR_ALIGN), ppnt); +- } +- /* Now we want to allocate and +- zero-out any data from the end of +- the region we mapped in from the +- file (filesz) to the end of the +- loadable segment (memsz). We may +- need additional pages for memsz, +- that we map in below, and we can +- count on the kernel to zero them +- out, but we have to zero out stuff +- in the last page that we mapped in +- from the file. However, we can't +- assume to have actually obtained +- full pages from the kernel, since +- we didn't ask for them, and uClibc +- may not give us full pages for +- small allocations. So only zero +- out up to memsz or the end of the +- page, whichever comes first. */ +- +- /* CPNT is the beginning of the memsz +- portion not backed by filesz. */ +- cpnt = (char *) (status + size); +- +- /* MAP_SIZE is the address of the +- beginning of the next page. */ +- map_size = (ppnt->p_vaddr + ppnt->p_filesz +- + ADDR_ALIGN) & PAGE_ALIGN; +- +-#ifndef MIN +-# define MIN(a,b) ((a) < (b) ? (a) : (b)) +-#endif +- _dl_memset (cpnt, 0, +- MIN (map_size +- - (ppnt->p_vaddr +- + ppnt->p_filesz), +- ppnt->p_memsz +- - ppnt->p_filesz)); +- +- if (map_size < ppnt->p_vaddr + ppnt->p_memsz +- && !piclib2map) { +- tryaddr = map_size + (char*)(piclib ? libaddr : 0); +- status = (char *) _dl_mmap(tryaddr, +- ppnt->p_vaddr + ppnt->p_memsz - map_size, +- LXFLAGS(ppnt->p_flags), flags | MAP_ANONYMOUS | MAP_FIXED, -1, 0); +- if (_dl_mmap_check_error(status) +- || tryaddr != status) +- goto cant_map; +- } ++ status = map_writeable (infile, ppnt, piclib, flags, libaddr); ++ if (status == NULL) ++ goto cant_map1; + } else { + tryaddr = (piclib == 2 ? 0 + : (char *) (ppnt->p_vaddr & PAGE_ALIGN) +@@ -664,11 +651,11 @@ + infile, ppnt->p_offset & OFFS_ALIGN); + if (_dl_mmap_check_error(status) + || (tryaddr && tryaddr != status)) +- goto cant_map; +- DL_INIT_LOADADDR_HDR +- (lib_loadaddr, status +- + (ppnt->p_vaddr & ADDR_ALIGN), ppnt); ++ goto cant_map1; + } ++ DL_INIT_LOADADDR_HDR(lib_loadaddr, ++ status + (ppnt->p_vaddr & ADDR_ALIGN), ++ ppnt); + + /* if (libaddr == 0 && piclib) { + libaddr = (unsigned long) status; +@@ -677,7 +664,6 @@ + } + ppnt++; + } +- _dl_close(infile); + + /* For a non-PIC library, the addresses are all absolute */ + if (piclib) { +@@ -696,6 +682,7 @@ + _dl_dprintf(2, "%s: '%s' is missing a dynamic section\n", + _dl_progname, libname); + _dl_munmap(header, _dl_pagesize); ++ _dl_close(infile); + return NULL; + } + +@@ -711,10 +698,23 @@ + ppnt = (ElfW(Phdr) *)(intptr_t) & header[epnt->e_phoff]; + for (i = 0; i < epnt->e_phnum; i++, ppnt++) { + if (ppnt->p_type == PT_LOAD && !(ppnt->p_flags & PF_W)) { ++#ifdef __ARCH_USE_MMU__ + _dl_mprotect((void *) ((piclib ? libaddr : 0) + + (ppnt->p_vaddr & PAGE_ALIGN)), + (ppnt->p_vaddr & ADDR_ALIGN) + (unsigned long) ppnt->p_filesz, + PROT_READ | PROT_WRITE | PROT_EXEC); ++#else ++ void *new_addr; ++ new_addr = map_writeable (infile, ppnt, piclib, flags, libaddr); ++ if (!new_addr) { ++ _dl_dprintf(_dl_debug_file, "Can't modify %s's text section.", ++ libname); ++ _dl_exit(1); ++ } ++ DL_UPDATE_LOADADDR_HDR(lib_loadaddr, ++ new_addr + (ppnt->p_vaddr & ADDR_ALIGN), ++ ppnt); ++#endif + } + } + #else +@@ -725,6 +725,8 @@ + #endif + } + ++ _dl_close(infile); ++ + tpnt = _dl_add_elf_hash_table(libname, lib_loadaddr, dynamic_info, + dynamic_addr, 0); + tpnt->relro_addr = relro_addr; +@@ -809,20 +811,44 @@ + #ifdef __DSBT__ + /* Handle DSBT initialization */ + { +- struct elf_resolve *t, *ref = NULL; ++ struct elf_resolve *t, *ref; + int idx = tpnt->loadaddr.map->dsbt_index; + unsigned *dsbt = tpnt->loadaddr.map->dsbt_table; + + if (idx == 0) { +- /* This DSO has not been assigned an index */ +- _dl_dprintf(2, "%s: '%s' is missing a dsbt index assignment!\n", +- _dl_progname, libname); +- _dl_exit(1); ++ if (!dynamic_info[DT_TEXTREL]) { ++ /* This DSO has not been assigned an index. */ ++ _dl_dprintf(2, "%s: '%s' is missing a dsbt index assignment!\n", ++ _dl_progname, libname); ++ _dl_exit(1); ++ } ++ /* Find a dsbt table from another module. */ ++ ref = NULL; ++ for (t = _dl_loaded_modules; t; t = t->next) { ++ if (ref == NULL && t != tpnt) { ++ ref = t; ++ break; ++ } ++ } ++ idx = tpnt->loadaddr.map->dsbt_size; ++ while (idx-- > 0) ++ if (!ref || ref->loadaddr.map->dsbt_table[idx] == NULL) ++ break; ++ if (idx <= 0) { ++ _dl_dprintf(2, "%s: '%s' caused DSBT table overflow!\n", ++ _dl_progname, libname); ++ _dl_exit(1); ++ } ++ _dl_if_debug_dprint("\n\tfile='%s'; assigned index %d\n", ++ libname, idx); ++ tpnt->loadaddr.map->dsbt_index = idx; ++ + } + + /* + * Setup dsbt slot for this module in dsbt of all modules. + */ ++ ref = NULL; + for (t = _dl_loaded_modules; t; t = t->next) { + /* find a dsbt table from another module */ + if (ref == NULL && t != tpnt) { +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/dl-startup.c uClibc/ldso/ldso/dl-startup.c +--- uClibc-0.9.32-rc3/ldso/ldso/dl-startup.c 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/dl-startup.c 2011-04-26 16:18:21.747664948 +0200 +@@ -32,8 +32,8 @@ + + /* + * The main trick with this program is that initially, we ourselves are not +- * dynamicly linked. This means that we cannot access any global variables or +- * call any functions. No globals initially, since the Global Offset Table ++ * dynamically linked. This means that we cannot access any global variables ++ * or call any functions. No globals initially, since the Global Offset Table + * (GOT) is initialized by the linker assuming a virtual address of 0, and no + * function calls initially since the Procedure Linkage Table (PLT) is not yet + * initialized. +@@ -55,12 +55,12 @@ + * + * Fortunately, the linker itself leaves a few clues lying around, and when the + * kernel starts the image, there are a few further clues. First of all, there +- * is Auxiliary Vector Table information sitting on which is provided to us by +- * the kernel, and which includes information about the load address that the +- * program interpreter was loaded at, the number of sections, the address the +- * application was loaded at and so forth. Here this information is stored in +- * the array auxvt. For details see linux/fs/binfmt_elf.c where it calls +- * NEW_AUX_ENT() a bunch of time.... ++ * is Auxiliary Vector Table information sitting on the stack which is provided ++ * to us by the kernel, and which includes information about the address ++ * that the program interpreter was loaded at, the number of sections, the ++ * address the application was loaded at, and so forth. Here this information ++ * is stored in the array auxvt. For details see linux/fs/binfmt_elf.c where ++ * it calls NEW_AUX_ENT() a bunch of times.... + * + * Next, we need to find the GOT. On most arches there is a register pointing + * to the GOT, but just in case (and for new ports) I've added some (slow) C +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/frv/dl-inlines.h uClibc/ldso/ldso/frv/dl-inlines.h +--- uClibc-0.9.32-rc3/ldso/ldso/frv/dl-inlines.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/frv/dl-inlines.h 2011-04-26 16:18:21.757661905 +0200 +@@ -72,14 +72,39 @@ + segdata->p_memsz = phdr->p_memsz; + + #if defined (__SUPPORT_LD_DEBUG__) +- { +- extern char *_dl_debug; +- extern int _dl_debug_file; +- if (_dl_debug) +- _dl_dprintf(_dl_debug_file, "%i: mapped %x at %x, size %x\n", +- loadaddr.map->nsegs-1, +- segdata->p_vaddr, segdata->addr, segdata->p_memsz); +- } ++ if (_dl_debug) ++ _dl_dprintf(_dl_debug_file, "%i: mapped %x at %x, size %x\n", ++ loadaddr.map->nsegs-1, ++ segdata->p_vaddr, segdata->addr, segdata->p_memsz); ++#endif ++} ++ ++/* Replace an existing entry in the load map. */ ++static __always_inline void ++__dl_update_loadaddr_hdr (struct elf32_fdpic_loadaddr loadaddr, void *addr, ++ Elf32_Phdr *phdr) ++{ ++ struct elf32_fdpic_loadseg *segdata; ++ void *oldaddr; ++ int i; ++ ++ for (i = 0; i < loadaddr.map->nsegs; i++) ++ if (loadaddr.map->segs[i].p_vaddr == phdr->p_vaddr ++ && loadaddr.map->segs[i].p_memsz == phdr->p_memsz) ++ break; ++ if (i == loadaddr.map->nsegs) ++ _dl_exit (-1); ++ ++ segdata = loadaddr.map->segs + i; ++ oldaddr = (void *)segdata->addr; ++ _dl_munmap (oldaddr, segdata->p_memsz); ++ segdata->addr = (Elf32_Addr) addr; ++ ++#if defined (__SUPPORT_LD_DEBUG__) ++ if (_dl_debug) ++ _dl_dprintf(_dl_debug_file, "%i: changed mapping %x at %x (old %x), size %x\n", ++ loadaddr.map->nsegs-1, ++ segdata->p_vaddr, segdata->addr, oldaddr, segdata->p_memsz); + #endif + } + +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/frv/dl-sysdep.h uClibc/ldso/ldso/frv/dl-sysdep.h +--- uClibc-0.9.32-rc3/ldso/ldso/frv/dl-sysdep.h 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/frv/dl-sysdep.h 2011-04-26 16:18:21.757661905 +0200 +@@ -95,6 +95,8 @@ + #define DL_INIT_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \ + (__dl_init_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR), \ + dl_init_loadaddr_load_count)) ++#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) \ ++ (__dl_update_loadaddr_hdr ((LOADADDR), (ADDR), (PHDR))) + #define DL_LOADADDR_UNMAP(LOADADDR, LEN) \ + (__dl_loadaddr_unmap ((LOADADDR), (NULL))) + #define DL_LIB_UNMAP(LIB, LEN) \ +diff -Nur uClibc-0.9.32-rc3/ldso/ldso/mips/elfinterp.c uClibc/ldso/ldso/mips/elfinterp.c +--- uClibc-0.9.32-rc3/ldso/ldso/mips/elfinterp.c 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/ldso/ldso/mips/elfinterp.c 2011-04-26 16:18:21.757661905 +0200 +@@ -378,8 +378,11 @@ + *got_entry += (unsigned long) tpnt->loadaddr; + } + else { ++ struct symbol_ref sym_ref; ++ sym_ref.sym = sym; ++ sym_ref.tpnt = NULL; + *got_entry = (unsigned long) _dl_find_hash(strtab + +- sym->st_name, tpnt->symbol_scope, tpnt, ELF_RTYPE_CLASS_PLT, NULL); ++ sym->st_name, tpnt->symbol_scope, tpnt, ELF_RTYPE_CLASS_PLT, &sym_ref); + } + + got_entry++; +diff -Nur uClibc-0.9.32-rc3/libc/inet/resolv.c uClibc/libc/inet/resolv.c +--- uClibc-0.9.32-rc3/libc/inet/resolv.c 2011-03-16 20:11:13.000000000 +0100 ++++ uClibc/libc/inet/resolv.c 2011-04-26 16:18:21.767661585 +0200 +@@ -3009,7 +3009,7 @@ + int m = 0; + /* free nsaddrs[m] if they do not point to nsaddr_list[x] */ + while (m < ARRAY_SIZE(_res._u._ext.nsaddrs)) { +- char *p2 = (char*)(_res._u._ext.nsaddrs[m]); ++ char *p2 = (char*)(_res._u._ext.nsaddrs[m++]); + if (p2 < p1 || (p2 - p1) > sizeof(_res.nsaddr_list)) + free(p2); + } +diff -Nur uClibc-0.9.32-rc3/libc/misc/fts/fts.c uClibc/libc/misc/fts/fts.c +--- uClibc-0.9.32-rc3/libc/misc/fts/fts.c 1970-01-01 01:00:00.000000000 +0100 ++++ uClibc/libc/misc/fts/fts.c 2011-04-26 16:18:21.777663244 +0200 +@@ -0,0 +1,1145 @@ ++/*- ++ * Copyright (c) 1990, 1993, 1994 ++ * The Regents of the University of California. All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * 4. Neither the name of the University nor the names of its contributors ++ * may be used to endorse or promote products derived from this software ++ * without specific prior written permission. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef __UCLIBC_HAS_LFS__ ++# include <_lfs_64.h> ++#else ++# define stat64 stat ++# define fstat64 fstat ++#endif ++ ++/* Largest alignment size needed, minus one. ++ Usually long double is the worst case. */ ++#ifndef ALIGNBYTES ++#define ALIGNBYTES (__alignof__ (long double) - 1) ++#endif ++/* Align P to that size. */ ++#ifndef ALIGN ++#define ALIGN(p) (((unsigned long int) (p) + ALIGNBYTES) & ~ALIGNBYTES) ++#endif ++ ++ ++static FTSENT *fts_alloc (FTS *, const char *, size_t) internal_function; ++static FTSENT *fts_build (FTS *, int) internal_function; ++static void fts_lfree (FTSENT *) internal_function; ++static void fts_load (FTS *, FTSENT *) internal_function; ++static size_t fts_maxarglen (char * const *) internal_function; ++static void fts_padjust (FTS *, FTSENT *) internal_function; ++static int fts_palloc (FTS *, size_t) internal_function; ++static FTSENT *fts_sort (FTS *, FTSENT *, int) internal_function; ++static u_short fts_stat (FTS *, FTSENT *, int) internal_function; ++static int fts_safe_changedir (FTS *, FTSENT *, int, const char *) ++ internal_function; ++ ++#ifndef MAX ++#define MAX(a, b) ({ __typeof__ (a) _a = (a); \ ++ __typeof__ (b) _b = (b); \ ++ _a > _b ? _a : _b; }) ++#endif ++ ++#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) ++ ++#define CLR(opt) (sp->fts_options &= ~(opt)) ++#define ISSET(opt) (sp->fts_options & (opt)) ++#define SET(opt) (sp->fts_options |= (opt)) ++ ++#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) ++ ++/* fts_build flags */ ++#define BCHILD 1 /* fts_children */ ++#define BNAMES 2 /* fts_children, names only */ ++#define BREAD 3 /* fts_read */ ++ ++FTS * ++fts_open(argv, options, compar) ++ char * const *argv; ++ register int options; ++ int (*compar) (const FTSENT **, const FTSENT **); ++{ ++ register FTS *sp; ++ register FTSENT *p, *root; ++ register int nitems; ++ FTSENT *parent = NULL; ++ FTSENT *tmp = NULL; ++ ++ /* Options check. */ ++ if (options & ~FTS_OPTIONMASK) { ++ __set_errno (EINVAL); ++ return (NULL); ++ } ++ ++ /* Allocate/initialize the stream */ ++ if ((sp = malloc((u_int)sizeof(FTS))) == NULL) ++ return (NULL); ++ memset(sp, 0, sizeof(FTS)); ++ sp->fts_compar = (int (*) (const void *, const void *)) compar; ++ sp->fts_options = options; ++ ++ /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ ++ if (ISSET(FTS_LOGICAL)) ++ SET(FTS_NOCHDIR); ++ ++ /* ++ * Start out with 1K of path space, and enough, in any case, ++ * to hold the user's paths. ++ */ ++#ifndef MAXPATHLEN ++#define MAXPATHLEN 1024 ++#endif ++ size_t maxarglen = fts_maxarglen(argv); ++ if (fts_palloc(sp, MAX(maxarglen, MAXPATHLEN))) ++ goto mem1; ++ ++ /* Allocate/initialize root's parent. */ ++ if (*argv != NULL) { ++ if ((parent = fts_alloc(sp, "", 0)) == NULL) ++ goto mem2; ++ parent->fts_level = FTS_ROOTPARENTLEVEL; ++ } ++ ++ /* Allocate/initialize root(s). */ ++ for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) { ++ /* Don't allow zero-length paths. */ ++ size_t len = strlen(*argv); ++ if (len == 0) { ++ __set_errno (ENOENT); ++ goto mem3; ++ } ++ ++ p = fts_alloc(sp, *argv, len); ++ p->fts_level = FTS_ROOTLEVEL; ++ p->fts_parent = parent; ++ p->fts_accpath = p->fts_name; ++ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); ++ ++ /* Command-line "." and ".." are real directories. */ ++ if (p->fts_info == FTS_DOT) ++ p->fts_info = FTS_D; ++ ++ /* ++ * If comparison routine supplied, traverse in sorted ++ * order; otherwise traverse in the order specified. ++ */ ++ if (compar) { ++ p->fts_link = root; ++ root = p; ++ } else { ++ p->fts_link = NULL; ++ if (root == NULL) ++ tmp = root = p; ++ else { ++ tmp->fts_link = p; ++ tmp = p; ++ } ++ } ++ } ++ if (compar && nitems > 1) ++ root = fts_sort(sp, root, nitems); ++ ++ /* ++ * Allocate a dummy pointer and make fts_read think that we've just ++ * finished the node before the root(s); set p->fts_info to FTS_INIT ++ * so that everything about the "current" node is ignored. ++ */ ++ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) ++ goto mem3; ++ sp->fts_cur->fts_link = root; ++ sp->fts_cur->fts_info = FTS_INIT; ++ ++ /* ++ * If using chdir(2), grab a file descriptor pointing to dot to ensure ++ * that we can get back here; this could be avoided for some paths, ++ * but almost certainly not worth the effort. Slashes, symbolic links, ++ * and ".." are all fairly nasty problems. Note, if we can't get the ++ * descriptor we run anyway, just more slowly. ++ */ ++ if (!ISSET(FTS_NOCHDIR) ++ && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) ++ SET(FTS_NOCHDIR); ++ ++ return (sp); ++ ++mem3: fts_lfree(root); ++ free(parent); ++mem2: free(sp->fts_path); ++mem1: free(sp); ++ return (NULL); ++} ++ ++static void ++internal_function ++fts_load(sp, p) ++ FTS *sp; ++ register FTSENT *p; ++{ ++ register int len; ++ register char *cp; ++ ++ /* ++ * Load the stream structure for the next traversal. Since we don't ++ * actually enter the directory until after the preorder visit, set ++ * the fts_accpath field specially so the chdir gets done to the right ++ * place and the user can access the first node. From fts_open it's ++ * known that the path will fit. ++ */ ++ len = p->fts_pathlen = p->fts_namelen; ++ memmove(sp->fts_path, p->fts_name, len + 1); ++ if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { ++ len = strlen(++cp); ++ memmove(p->fts_name, cp, len + 1); ++ p->fts_namelen = len; ++ } ++ p->fts_accpath = p->fts_path = sp->fts_path; ++ sp->fts_dev = p->fts_dev; ++} ++ ++int ++fts_close(sp) ++ FTS *sp; ++{ ++ register FTSENT *freep, *p; ++ int saved_errno; ++ ++ /* ++ * This still works if we haven't read anything -- the dummy structure ++ * points to the root list, so we step through to the end of the root ++ * list which has a valid parent pointer. ++ */ ++ if (sp->fts_cur) { ++ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { ++ freep = p; ++ p = p->fts_link != NULL ? p->fts_link : p->fts_parent; ++ free(freep); ++ } ++ free(p); ++ } ++ ++ /* Free up child linked list, sort array, path buffer. */ ++ if (sp->fts_child) ++ fts_lfree(sp->fts_child); ++ free(sp->fts_array); ++ free(sp->fts_path); ++ ++ /* Return to original directory, save errno if necessary. */ ++ if (!ISSET(FTS_NOCHDIR)) { ++ saved_errno = fchdir(sp->fts_rfd) ? errno : 0; ++ (void)close(sp->fts_rfd); ++ ++ /* Set errno and return. */ ++ if (saved_errno != 0) { ++ /* Free up the stream pointer. */ ++ free(sp); ++ __set_errno (saved_errno); ++ return (-1); ++ } ++ } ++ ++ /* Free up the stream pointer. */ ++ free(sp); ++ return (0); ++} ++ ++/* ++ * Special case of "/" at the end of the path so that slashes aren't ++ * appended which would cause paths to be written as "....//foo". ++ */ ++#define NAPPEND(p) \ ++ (p->fts_path[p->fts_pathlen - 1] == '/' \ ++ ? p->fts_pathlen - 1 : p->fts_pathlen) ++ ++FTSENT * ++fts_read(sp) ++ register FTS *sp; ++{ ++ register FTSENT *p, *tmp; ++ register int instr; ++ register char *t; ++ int saved_errno; ++ ++ /* If finished or unrecoverable error, return NULL. */ ++ if (sp->fts_cur == NULL || ISSET(FTS_STOP)) ++ return (NULL); ++ ++ /* Set current node pointer. */ ++ p = sp->fts_cur; ++ ++ /* Save and zero out user instructions. */ ++ instr = p->fts_instr; ++ p->fts_instr = FTS_NOINSTR; ++ ++ /* Any type of file may be re-visited; re-stat and re-turn. */ ++ if (instr == FTS_AGAIN) { ++ p->fts_info = fts_stat(sp, p, 0); ++ return (p); ++ } ++ ++ /* ++ * Following a symlink -- SLNONE test allows application to see ++ * SLNONE and recover. If indirecting through a symlink, have ++ * keep a pointer to current location. If unable to get that ++ * pointer, follow fails. ++ */ ++ if (instr == FTS_FOLLOW && ++ (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { ++ p->fts_info = fts_stat(sp, p, 1); ++ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { ++ if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { ++ p->fts_errno = errno; ++ p->fts_info = FTS_ERR; ++ } else ++ p->fts_flags |= FTS_SYMFOLLOW; ++ } ++ return (p); ++ } ++ ++ /* Directory in pre-order. */ ++ if (p->fts_info == FTS_D) { ++ /* If skipped or crossed mount point, do post-order visit. */ ++ if (instr == FTS_SKIP || ++ (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { ++ if (p->fts_flags & FTS_SYMFOLLOW) ++ (void)close(p->fts_symfd); ++ if (sp->fts_child) { ++ fts_lfree(sp->fts_child); ++ sp->fts_child = NULL; ++ } ++ p->fts_info = FTS_DP; ++ return (p); ++ } ++ ++ /* Rebuild if only read the names and now traversing. */ ++ if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) { ++ CLR(FTS_NAMEONLY); ++ fts_lfree(sp->fts_child); ++ sp->fts_child = NULL; ++ } ++ ++ /* ++ * Cd to the subdirectory. ++ * ++ * If have already read and now fail to chdir, whack the list ++ * to make the names come out right, and set the parent errno ++ * so the application will eventually get an error condition. ++ * Set the FTS_DONTCHDIR flag so that when we logically change ++ * directories back to the parent we don't do a chdir. ++ * ++ * If haven't read do so. If the read fails, fts_build sets ++ * FTS_STOP or the fts_info field of the node. ++ */ ++ if (sp->fts_child != NULL) { ++ if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { ++ p->fts_errno = errno; ++ p->fts_flags |= FTS_DONTCHDIR; ++ for (p = sp->fts_child; p != NULL; ++ p = p->fts_link) ++ p->fts_accpath = ++ p->fts_parent->fts_accpath; ++ } ++ } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { ++ if (ISSET(FTS_STOP)) ++ return (NULL); ++ return (p); ++ } ++ p = sp->fts_child; ++ sp->fts_child = NULL; ++ sp->fts_cur = p; ++ goto name; ++ } ++ ++ /* Move to the next node on this level. */ ++next: tmp = p; ++ if ((p = p->fts_link) != NULL) { ++ sp->fts_cur = p; ++ free(tmp); ++ ++ /* ++ * If reached the top, return to the original directory (or ++ * the root of the tree), and load the paths for the next root. ++ */ ++ if (p->fts_level == FTS_ROOTLEVEL) { ++ if (FCHDIR(sp, sp->fts_rfd)) { ++ SET(FTS_STOP); ++ return (NULL); ++ } ++ fts_load(sp, p); ++ return p; ++ } ++ ++ /* ++ * User may have called fts_set on the node. If skipped, ++ * ignore. If followed, get a file descriptor so we can ++ * get back if necessary. ++ */ ++ if (p->fts_instr == FTS_SKIP) ++ goto next; ++ if (p->fts_instr == FTS_FOLLOW) { ++ p->fts_info = fts_stat(sp, p, 1); ++ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { ++ if ((p->fts_symfd = ++ open(".", O_RDONLY, 0)) < 0) { ++ p->fts_errno = errno; ++ p->fts_info = FTS_ERR; ++ } else ++ p->fts_flags |= FTS_SYMFOLLOW; ++ } ++ p->fts_instr = FTS_NOINSTR; ++ } ++ ++name: t = sp->fts_path + NAPPEND(p->fts_parent); ++ *t++ = '/'; ++ memmove(t, p->fts_name, p->fts_namelen + 1); ++ return p; ++ } ++ ++ /* Move up to the parent node. */ ++ p = tmp->fts_parent; ++ sp->fts_cur = p; ++ free(tmp); ++ ++ if (p->fts_level == FTS_ROOTPARENTLEVEL) { ++ /* ++ * Done; free everything up and set errno to 0 so the user ++ * can distinguish between error and EOF. ++ */ ++ free(p); ++ __set_errno (0); ++ return (sp->fts_cur = NULL); ++ } ++ ++ /* NUL terminate the pathname. */ ++ sp->fts_path[p->fts_pathlen] = '\0'; ++ ++ /* ++ * Return to the parent directory. If at a root node or came through ++ * a symlink, go back through the file descriptor. Otherwise, cd up ++ * one directory. ++ */ ++ if (p->fts_level == FTS_ROOTLEVEL) { ++ if (FCHDIR(sp, sp->fts_rfd)) { ++ SET(FTS_STOP); ++ return (NULL); ++ } ++ } else if (p->fts_flags & FTS_SYMFOLLOW) { ++ if (FCHDIR(sp, p->fts_symfd)) { ++ saved_errno = errno; ++ (void)close(p->fts_symfd); ++ __set_errno (saved_errno); ++ SET(FTS_STOP); ++ return (NULL); ++ } ++ (void)close(p->fts_symfd); ++ } else if (!(p->fts_flags & FTS_DONTCHDIR) && ++ fts_safe_changedir(sp, p->fts_parent, -1, "..")) { ++ SET(FTS_STOP); ++ return (NULL); ++ } ++ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; ++ return p; ++} ++ ++/* ++ * Fts_set takes the stream as an argument although it's not used in this ++ * implementation; it would be necessary if anyone wanted to add global ++ * semantics to fts using fts_set. An error return is allowed for similar ++ * reasons. ++ */ ++/* ARGSUSED */ ++int ++fts_set(sp, p, instr) ++ FTS *sp; ++ FTSENT *p; ++ int instr; ++{ ++ if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW && ++ instr != FTS_NOINSTR && instr != FTS_SKIP) { ++ __set_errno (EINVAL); ++ return (1); ++ } ++ p->fts_instr = instr; ++ return (0); ++} ++ ++FTSENT * ++fts_children(sp, instr) ++ register FTS *sp; ++ int instr; ++{ ++ register FTSENT *p; ++ int fd; ++ ++ if (instr != 0 && instr != FTS_NAMEONLY) { ++ __set_errno (EINVAL); ++ return (NULL); ++ } ++ ++ /* Set current node pointer. */ ++ p = sp->fts_cur; ++ ++ /* ++ * Errno set to 0 so user can distinguish empty directory from ++ * an error. ++ */ ++ __set_errno (0); ++ ++ /* Fatal errors stop here. */ ++ if (ISSET(FTS_STOP)) ++ return (NULL); ++ ++ /* Return logical hierarchy of user's arguments. */ ++ if (p->fts_info == FTS_INIT) ++ return (p->fts_link); ++ ++ /* ++ * If not a directory being visited in pre-order, stop here. Could ++ * allow FTS_DNR, assuming the user has fixed the problem, but the ++ * same effect is available with FTS_AGAIN. ++ */ ++ if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) ++ return (NULL); ++ ++ /* Free up any previous child list. */ ++ if (sp->fts_child != NULL) ++ fts_lfree(sp->fts_child); ++ ++ if (instr == FTS_NAMEONLY) { ++ SET(FTS_NAMEONLY); ++ instr = BNAMES; ++ } else ++ instr = BCHILD; ++ ++ /* ++ * If using chdir on a relative path and called BEFORE fts_read does ++ * its chdir to the root of a traversal, we can lose -- we need to ++ * chdir into the subdirectory, and we don't know where the current ++ * directory is, so we can't get back so that the upcoming chdir by ++ * fts_read will work. ++ */ ++ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || ++ ISSET(FTS_NOCHDIR)) ++ return (sp->fts_child = fts_build(sp, instr)); ++ ++ if ((fd = open(".", O_RDONLY, 0)) < 0) ++ return (NULL); ++ sp->fts_child = fts_build(sp, instr); ++ if (fchdir(fd)) ++ return (NULL); ++ (void)close(fd); ++ return (sp->fts_child); ++} ++ ++/* ++ * This is the tricky part -- do not casually change *anything* in here. The ++ * idea is to build the linked list of entries that are used by fts_children ++ * and fts_read. There are lots of special cases. ++ * ++ * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is ++ * set and it's a physical walk (so that symbolic links can't be directories), ++ * we can do things quickly. First, if it's a 4.4BSD file system, the type ++ * of the file is in the directory entry. Otherwise, we assume that the number ++ * of subdirectories in a node is equal to the number of links to the parent. ++ * The former skips all stat calls. The latter skips stat calls in any leaf ++ * directories and for any files after the subdirectories in the directory have ++ * been found, cutting the stat calls by about 2/3. ++ */ ++static FTSENT * ++internal_function ++fts_build(sp, type) ++ register FTS *sp; ++ int type; ++{ ++ register struct dirent *dp; ++ register FTSENT *p, *head; ++ register int nitems; ++ FTSENT *cur, *tail; ++ DIR *dirp; ++ void *oldaddr; ++ int cderrno, descend, len, level, nlinks, saved_errno, ++ nostat, doadjust; ++ size_t maxlen; ++ char *cp; ++ ++ /* Set current node pointer. */ ++ cur = sp->fts_cur; ++ ++ /* ++ * Open the directory for reading. If this fails, we're done. ++ * If being called from fts_read, set the fts_info field. ++ */ ++#if defined FTS_WHITEOUT && 0 ++ if (ISSET(FTS_WHITEOUT)) ++ oflag = DTF_NODUP|DTF_REWIND; ++ else ++ oflag = DTF_HIDEW|DTF_NODUP|DTF_REWI