Re: [PATCH] buildsys: clean up libubacktrace linker script handling

2012-06-15 Thread Kevin Cernekee
FWIW here is what I wound up using locally to work around the issue.  It
mostly reverts back to the original logic (write out lib/libc.so sans
libubacktrace reference in libc/Makefile.in, then hack the final
installed version to reference libubacktrace.so).  But it does respect
the HARDWIRED_ABSPATH setting now, and introduces slightly less cruft in
Makefile.in.

-- 8< --

From: Kevin Cernekee 

Commit 01c125c3bd8f949f8e5711e09152859eecd1b004 (buildsys: clean up
libubacktrace linker script handling) caused a regression seen when
bootstrapping a new compiler: the libc.so linker script referenced
libubacktrace.so.0, which had not yet been installed.  Therefore, it
is necessary to partially revert the change, and go back to the old
method of appending $(UBACKTRACE_ASNEEDED) to the installed libc.so
script instead of the copy under lib/ in the source tree.

Signed-off-by: Kevin Cernekee 
---
 Makefile.in  |2 +-
 Rules.mak|   11 +--
 libc/Makefile.in |1 -
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 9d18cfe..612cc9b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -345,13 +345,13 @@ ifeq ($(HARDWIRED_ABSPATH),y)
$(SED) -e 
's:$(NONSHARED_LIBNAME):$(DEVEL_PREFIX)$(MULTILIB_DIR)/$(NONSHARED_LIBNAME):' \
-e 
's:$(SHARED_LIBNAME):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(SHARED_LIBNAME):' \
-e 
's:$(UCLIBC_LDSO):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UCLIBC_LDSO):' \
-   -e 
's:$(UBACKTRACE_DSO):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UBACKTRACE_DSO):' \
$(top_builddir)lib/libc.so > 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
$(SED) -i -e 's://:/:g' 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
fi
 else
-$(INSTALL) -m 755 $(top_builddir)lib/libc.so 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/
 endif
+   echo "$(UBACKTRACE_ASNEEDED)" >> 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so
 ifeq ($(UCLIBC_HAS_THREADS),y)
 ifneq ($(LINUXTHREADS_OLD),y)
 ifeq ($(HARDWIRED_ABSPATH),y)
diff --git a/Rules.mak b/Rules.mak
index 320b952..58968ae 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -578,9 +578,16 @@ export ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep 
-q -- --as-needed && ec
 
 # Only used in installed libc.so linker script
 ifeq ($(UCLIBC_HAS_BACKTRACE),y)
+
+ifeq ($(HARDWIRED_ABSPATH),y)
+UBACKTRACE_FULL_NAME := $(subst 
//,/,$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UBACKTRACE_DSO))
+else
+UBACKTRACE_FULL_NAME := $(UBACKTRACE_DSO)
+endif
+
 export UBACKTRACE_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- 
--as-needed && \
-   echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_DSO) ) )" || \
-   echo "GROUP ( $(UBACKTRACE_DSO) )")
+   echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_FULL_NAME) ) )" || \
+   echo "GROUP ( $(UBACKTRACE_FULL_NAME) )")
 else
 export UBACKTRACE_ASNEEDED:=""
 endif
diff --git a/libc/Makefile.in b/libc/Makefile.in
index d8ea7bd..3b6a17b 100644
--- a/libc/Makefile.in
+++ b/libc/Makefile.in
@@ -74,7 +74,6 @@ ifeq ($(COMPAT_ATEXIT),y)
 else
$(Q)echo "GROUP ( $(SHARED_LIBNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" 
>> $@.tmp
 endif
-   $(Q)echo "$(UBACKTRACE_ASNEEDED)" >> $@.tmp
$(Q)mv $@.tmp $@
 
 $(libc_OUT)/libc_so.a: $(libc-so-y) | $(top_builddir)lib/libc.a 
$(top_builddir)lib/$(NONSHARED_LIBNAME)
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH] buildsys: clean up libubacktrace linker script handling

2012-06-14 Thread Kevin Cernekee
On Wed, Jun 13, 2012 at 12:58 AM, Bernhard Reutner-Fischer
 wrote:
> On Tue, Jun 12, 2012 at 04:52:21PM +0100, Carmelo AMOROSO wrote:
>>On 07/06/2012 19.32, Kevin Cernekee wrote:
>>> Move the AS_NEEDED insertion into libc/Makefile.in, and add a case to
>>> the HARDWIRED_ABSPATH substitution command so libubacktrace is handled
>>> the same way as the other libraries listed in the script.
>>
>>Looks fine to me.
>>
>
> Applied, thanks!

Unfortunately it looks like this could cause some problems when
bootstrapping a new toolchain.  If the libc.so script references
libubacktrace, but libubacktrace.so.0 is not yet installed anywhere,
gcc will throw an error during the final link on the other shared
libraries:

rm -f lib/libdl.so lib/libdl.so.0 lib/libdl-0.9.32.1.so
arm-linux-uclibcgnueabi-gcc -Wl,-EL -shared -Wl,--warn-common
-Wl,--warn-once -Wl,-z,combreloc -Wl,-z,relro -Wl,-z,defs
-Wl,-fini,dl_cleanup  -Wl,-soname=libdl.so.0 -nostdlib -o
lib/libdl-0.9.32.1.so  -Wl,--whole-archive ldso/libdl/libdl_so.a
-Wl,--no-whole-archive ./lib/interp.os -L./lib ./lib/libc.so
./lib/ld-uClibc.so.0
/ssd/test/bin/../lib/gcc/arm-linux-uclibcgnueabi/4.5.3/libgcc.a
/ssd/test/bin/../lib/gcc/arm-linux-uclibcgnueabi/4.5.3/libgcc_eh.a
/ssd/test/bin/../lib/gcc/arm-linux-uclibcgnueabi/4.5.3/../../../../arm-linux-uclibcgnueabi/bin/ld:
cannot find libubacktrace.so.0
collect2: ld returned 1 exit status
make[1]: *** [lib/libdl.so] Error 1


I did not see this earlier because -nostdlib doesn't actually keep gcc
from passing ld "-L" arguments pointing into the sysroot directories.
So it saw my existing libubacktrace.so.0 from the installed sysroot
and did not complain that libubacktrace.so.0 was missing from the
uClibc build tree.

Maybe we will need to revert back to this technique, at least in some form?

-# Add the AS_NEEDED entry for libubacktrace.so
-   if [ -f $(top_builddir)lib/libc.so -a -f
$(PREFIX)$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(SHARED_LIBNAME) ] ; then \
-   echo "GROUP ( $(UBACKTRACE_ASNEEDED) )" >>
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
-   fi
-endif

I would appreciate any feedback/suggestions.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH] buildsys: clean up libubacktrace linker script handling

2012-06-07 Thread Kevin Cernekee
Currently, the installed libubacktrace linker script entry always uses
HARDWIRED_ABSPATH semantics, even if HARDWIRED_ABSPATH is disabled:

$ grep GROUP $PREFIX/mipsel-linux-uclibc/sys-root/usr/lib/libc.so
GROUP ( libc.so.0 uclibc_nonshared.a AS_NEEDED ( ld-uClibc.so.0 ) )
GROUP ( AS_NEEDED ( /lib/libubacktrace.so.0 ) )

This causes problems when building a non-sysroot toolchain.

Move the AS_NEEDED insertion into libc/Makefile.in, and add a case to
the HARDWIRED_ABSPATH substitution command so libubacktrace is handled
the same way as the other libraries listed in the script.

Signed-off-by: Kevin Cernekee 
---
 Makefile.in  |7 +--
 Rules.mak|8 +---
 libc/Makefile.in |1 +
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index fb118c0..8405f43 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -341,18 +341,13 @@ ifeq ($(HARDWIRED_ABSPATH),y)
$(SED) -e 
's:$(NONSHARED_LIBNAME):$(DEVEL_PREFIX)$(MULTILIB_DIR)/$(NONSHARED_LIBNAME):' \
-e 
's:$(SHARED_LIBNAME):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(SHARED_LIBNAME):' \
-e 
's:$(UCLIBC_LDSO):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UCLIBC_LDSO):' \
+   -e 
's:$(UBACKTRACE_DSO):$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UBACKTRACE_DSO):' \
$(top_builddir)lib/libc.so > 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
$(SED) -i -e 's://:/:g' 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
fi
 else
-$(INSTALL) -m 755 $(top_builddir)lib/libc.so 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/
 endif
-ifeq ($(UCLIBC_HAS_BACKTRACE),y)
-# Add the AS_NEEDED entry for libubacktrace.so
-   if [ -f $(top_builddir)lib/libc.so -a -f 
$(PREFIX)$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(SHARED_LIBNAME) ] ; then \
-   echo "GROUP ( $(UBACKTRACE_ASNEEDED) )" >> 
$(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so; \
-   fi
-endif
 ifeq ($(UCLIBC_HAS_THREADS),y)
 ifneq ($(LINUXTHREADS_OLD),y)
 ifeq ($(HARDWIRED_ABSPATH),y)
diff --git a/Rules.mak b/Rules.mak
index 00e8481..320b952 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -575,10 +575,12 @@ link.asneeded = $(if $(findstring 
yy,$(CC_FLAG_ASNEEDED)$(CC_FLAG_NO_ASNEEDED)),
 # Check for AS_NEEDED support in linker script (binutils>=2.16.1 has it)
 ifndef ASNEEDED
 export ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && 
echo "AS_NEEDED ( $(UCLIBC_LDSO) )" || echo "$(UCLIBC_LDSO)")
-ifeq ($(UCLIBC_HAS_BACKTRACE),y)
+
 # Only used in installed libc.so linker script
-UBACKTRACE_FULL_NAME := $(RUNTIME_PREFIX)lib/$(UBACKTRACE_DSO)
-export UBACKTRACE_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- 
--as-needed && echo "AS_NEEDED ( $(UBACKTRACE_FULL_NAME) )" || echo 
"$(UBACKTRACE_FULL_NAME)")
+ifeq ($(UCLIBC_HAS_BACKTRACE),y)
+export UBACKTRACE_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- 
--as-needed && \
+   echo "GROUP ( AS_NEEDED ( $(UBACKTRACE_DSO) ) )" || \
+   echo "GROUP ( $(UBACKTRACE_DSO) )")
 else
 export UBACKTRACE_ASNEEDED:=""
 endif
diff --git a/libc/Makefile.in b/libc/Makefile.in
index 3b6a17b..d8ea7bd 100644
--- a/libc/Makefile.in
+++ b/libc/Makefile.in
@@ -74,6 +74,7 @@ ifeq ($(COMPAT_ATEXIT),y)
 else
$(Q)echo "GROUP ( $(SHARED_LIBNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" 
>> $@.tmp
 endif
+   $(Q)echo "$(UBACKTRACE_ASNEEDED)" >> $@.tmp
$(Q)mv $@.tmp $@
 
 $(libc_OUT)/libc_so.a: $(libc-so-y) | $(top_builddir)lib/libc.a 
$(top_builddir)lib/$(NONSHARED_LIBNAME)
-- 
1.7.5.2

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH 2/2] MIPS: Use $a0 instead of $v0 for __syscall_error() argument

2012-06-06 Thread Kevin Cernekee
On Wed, Jun 6, 2012 at 12:06 PM, Rich Felker  wrote:
> Why would lazy binding ever be used for __syscall_error? Shouldn't
> this be bound at link time via appropriate visibility or otherwise? I
> can't think of any reason you'd want it to be possible to override
> it...

Within libc.so itself, I believe that is accurate.  I haven't seen any
errno anomalies involving functions that live inside libc.so.

But I also did not see anything that would provide special binding
treatment for the case of librt.so functions calling libc.so's
__syscall_error().  AFAICT __syscall_error() was treated as "just
another libc export."

Is there a way to mark an individual symbol so that it always uses
"BIND_NOW" semantics when satisfying another module's dependency?
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH 1/2] MIPS: Convert __syscall_error() callers to use $a0 for argument

2012-06-06 Thread Kevin Cernekee
On Wed, Jun 6, 2012 at 12:38 AM, Bernhard Reutner-Fischer
 wrote:
> On Tue, Jun 05, 2012 at 03:05:19PM -0700, Kevin Cernekee wrote:
>>Some callers passed the first argument in $v0, while others used $a0.
>>Change the callers to use $a0 consistently.
>
> Applied the series, thanks!
> Are linuxthreads.old and nptl consistent with this linuxthreads change?

I am running NPTL libpthread, whose call sites were fixed a while back
in commit 9a4c8a3f2 (mips: fix errno setting after syscall).

I did not see any __syscall_error() calls in linuxthreads.old .  I did
grep for all __syscall_error() callers on MIPS, to ensure that all of
them were using $a0 now.

Normally __syscall_error() isn't called explicitly from
librt/libpthread/etc. except for special cases; instead, it is called
from a wrapper like PSEUDO.  The wrappers were already in good shape,
but my first patch was required to fix up some of the special cases.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 2/2] MIPS: Use $a0 instead of $v0 for __syscall_error() argument

2012-06-05 Thread Kevin Cernekee
$a0 is saved across _dl_runtime_resolve(); $v0 is not.  Unfortunately,
__syscall_error() uses $v0 for its argument, not $a0 as is the MIPS ABI
standard.  This means that if lazy binding was used for __syscall_error(),
the errno value in $v0 could get corrupted.

The problem can be easily seen in testcases where syscalls in librt fail;
when librt tries to call __syscall_error() in libc, the argument gets
lost and errno gets set to a bogus value:

# ./tst-mqueue1 ; echo $?
mq_receive on O_WRONLY mqd_t did not fail with EBADF: Unknown error 
2004684208
1
# ./tst-mqueue2 ; echo $?
mq_timedreceive with too small msg_len did not fail with EMSGSIZE: Unknown 
error 1997360560
1
# ./tst-mqueue4 ; echo $?
mq_timedsend did not fail with ETIMEDOUT: Unknown error 2008747440
1

When _dl_runtime_resolve() was taken out of the equation, the same test
cases passed:

# LD_BIND_NOW=y ./tst-mqueue1 ; echo $?
0
# LD_BIND_NOW=y ./tst-mqueue2 ; echo $?
0
# LD_BIND_NOW=y ./tst-mqueue4 ; echo $?
0

Changing __syscall_error() to look at $a0 instead of $v0 fixed the
problem.

(Note that there is also a "__syscall_error.c" file which presumably
uses the standard C calling conventions, but I do not think it is used
on MIPS.)

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/mips/syscall_error.S |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libc/sysdeps/linux/mips/syscall_error.S 
b/libc/sysdeps/linux/mips/syscall_error.S
index 51a8efa..0cc20da 100644
--- a/libc/sysdeps/linux/mips/syscall_error.S
+++ b/libc/sysdeps/linux/mips/syscall_error.S
@@ -43,7 +43,7 @@ ENTRY(__syscall_error)
 #ifdef __PIC__
SAVE_GP(GPOFF)
 #endif
-   REG_S   v0, V0OFF(sp)
+   REG_S   a0, V0OFF(sp)
REG_S   ra, RAOFF(sp)
 
/* Find our per-thread errno address  */
-- 
1.7.9

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 1/2] MIPS: Convert __syscall_error() callers to use $a0 for argument

2012-06-05 Thread Kevin Cernekee
Some callers passed the first argument in $v0, while others used $a0.
Change the callers to use $a0 consistently.

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/mips/vfork.S|1 +
 .../unix/sysv/linux/mips/mips64/sysdep-cancel.h|2 +-
 .../sysdeps/unix/sysv/linux/mips/vfork.S   |1 +
 3 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libc/sysdeps/linux/mips/vfork.S b/libc/sysdeps/linux/mips/vfork.S
index b307447..00cc675 100644
--- a/libc/sysdeps/linux/mips/vfork.S
+++ b/libc/sysdeps/linux/mips/vfork.S
@@ -84,6 +84,7 @@ NESTED(__vfork,FRAMESZ,sp)
 
/* Something bad happened -- no child created.  */
 L(error):
+   movea0, v0
 #ifdef __PIC__
PTR_LA  t9, __syscall_error
RESTORE_GP64
diff --git 
a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h 
b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
index fc51774..4d2c405 100644
--- 
a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
+++ 
b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
@@ -31,7 +31,7 @@
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)\
   .align 2;  \
-  99:\
+  99: move a0, v0;   \
   PTR_LA t9,__syscall_error; \
   /* manual cpreturn.  */\
   REG_L gp, STKOFF_GP(sp);   \
diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/vfork.S 
b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/vfork.S
index 7bbab5c..238d798 100644
--- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/vfork.S
+++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/mips/vfork.S
@@ -80,6 +80,7 @@ NESTED(__vfork,FRAMESZ,sp)
 
/* Something bad happened -- no child created.  */
 L(error):
+   movea0, v0
 #ifdef __PIC__
PTR_LA  t9, __syscall_error
RESTORE_GP64
-- 
1.7.9

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 4/4] signalfd.h: Use new "bits/" scheme for arch-specific flags

2012-04-08 Thread Kevin Cernekee
glibc has split off the arch-specific flag definitions (like
SFD_NONBLOCK) into /bits/signalfd.h, so that there are no longer
multiple redundant copies of the entire header file.  We will adopt the
same scheme in uClibc.

Special cases are included for: alpha mips sparc

hppa was omitted because it has not been updated in glibc.

All others use the common definition.

Signed-off-by: Kevin Cernekee 
---
 Makefile.in|1 +
 include/.gitignore |1 +
 libc/sysdeps/linux/alpha/bits/signalfd.h   |   29 +++
 libc/sysdeps/linux/common/bits/signalfd.h  |   29 +++
 .../sysdeps/linux/common}/sys/signalfd.h   |   53 +++-
 libc/sysdeps/linux/mips/bits/signalfd.h|   29 +++
 libc/sysdeps/linux/sparc/bits/signalfd.h   |   29 +++
 7 files changed, 126 insertions(+), 45 deletions(-)
 create mode 100644 libc/sysdeps/linux/alpha/bits/signalfd.h
 create mode 100644 libc/sysdeps/linux/common/bits/signalfd.h
 rename {include => libc/sysdeps/linux/common}/sys/signalfd.h (57%)
 create mode 100644 libc/sysdeps/linux/mips/bits/signalfd.h
 create mode 100644 libc/sysdeps/linux/sparc/bits/signalfd.h

diff --git a/Makefile.in b/Makefile.in
index ccb988a..9af8498 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -279,6 +279,7 @@ HEADERS_RM-$(UCLIBC_LINUX_SPECIFIC)  += 
sys/eventfd.h sys/fsuid.h \
sys/prctl.h \
sys/reboot.h \
sys/sendfile.h \
+   bits/signalfd.h \
sys/signalfd.h \
bits/statfs.h \
sys/statfs.h \
diff --git a/include/.gitignore b/include/.gitignore
index 2d096d1..34589e3 100644
--- a/include/.gitignore
+++ b/include/.gitignore
@@ -36,6 +36,7 @@
 /sys/ptrace.h
 /sys/reg.h
 /sys/regdef.h
+/sys/signalfd.h
 /sys/sysmips.h
 /sys/tas.h
 /sys/timerfd.h
diff --git a/libc/sysdeps/linux/alpha/bits/signalfd.h 
b/libc/sysdeps/linux/alpha/bits/signalfd.h
new file mode 100644
index 000..7ea70fa
--- /dev/null
+++ b/libc/sysdeps/linux/alpha/bits/signalfd.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2007-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef_SYS_SIGNALFD_H
+# error "Never use  directly; include  
instead."
+#endif
+
+/* Flags for signalfd.  */
+enum
+  {
+SFD_CLOEXEC  = 01000,
+#define SFD_CLOEXEC SFD_CLOEXEC
+SFD_NONBLOCK = 4
+#define SFD_NONBLOCK SFD_NONBLOCK
+  };
diff --git a/libc/sysdeps/linux/common/bits/signalfd.h 
b/libc/sysdeps/linux/common/bits/signalfd.h
new file mode 100644
index 000..f2c0dde
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/signalfd.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2007-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef_SYS_SIGNALFD_H
+# error "Never use  directly; include  
instead."
+#endif
+
+/* Flags for signalfd.  */
+enum
+  {
+SFD_CLOEXEC = 0200,
+#define SFD_CLOEXEC SFD_CLOEXEC
+SFD_NONBLOCK = 4000
+#define SFD_NONBLOCK SFD_NONBLOCK
+  };
diff --git a/include/sys/signalfd.h b/libc/sysdeps/linux/common/sys/signalfd.h
similarity index 57%
rename from include/sys/signalfd.h
rename to libc/sysdeps/linux/common/sys/signalfd.h
index f1cb63a..46a8d47 100644
--- a/include/sys/signalfd.h
+++ b/libc/sysdeps/linux/common/sys/signalfd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2007-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU 

[PATCH 3/4] timerfd.h: Use new "bits/" scheme for arch-specific flags

2012-04-08 Thread Kevin Cernekee
glibc has split off the arch-specific flag definitions (like
TFD_NONBLOCK) into /bits/timerfd.h, so that there are no longer
multiple redundant copies of the entire header file.  We will adopt the
same scheme in uClibc.

Special cases are included for: alpha mips sparc

hppa was omitted because it has not been updated in glibc.

All others use the common definition.

Signed-off-by: Kevin Cernekee 
---
 Makefile.in  |1 +
 libc/sysdeps/linux/alpha/bits/timerfd.h  |   29 +
 libc/sysdeps/linux/common/bits/timerfd.h |   29 +
 libc/sysdeps/linux/common/sys/timerfd.h  |   20 ++--
 libc/sysdeps/linux/mips/bits/timerfd.h   |   29 +
 libc/sysdeps/linux/sparc/bits/timerfd.h  |   29 +
 6 files changed, 123 insertions(+), 14 deletions(-)
 create mode 100644 libc/sysdeps/linux/alpha/bits/timerfd.h
 create mode 100644 libc/sysdeps/linux/common/bits/timerfd.h
 create mode 100644 libc/sysdeps/linux/mips/bits/timerfd.h
 create mode 100644 libc/sysdeps/linux/sparc/bits/timerfd.h

diff --git a/Makefile.in b/Makefile.in
index 5cedaa8..ccb988a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -285,6 +285,7 @@ HEADERS_RM-$(UCLIBC_LINUX_SPECIFIC)  += 
sys/eventfd.h sys/fsuid.h \
sys/swap.h \
sys/sysctl.h \
sys/sysinfo.h \
+   bits/timerfd.h \
sys/timerfd.h \
sys/vfs.h
 HEADERS_RM-$(UCLIBC_SUPPORT_AI_ADDRCONFIG)   += ifaddrs.h
diff --git a/libc/sysdeps/linux/alpha/bits/timerfd.h 
b/libc/sysdeps/linux/alpha/bits/timerfd.h
new file mode 100644
index 000..f04833d
--- /dev/null
+++ b/libc/sysdeps/linux/alpha/bits/timerfd.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef_SYS_TIMERFD_H
+# error "Never use  directly; include  instead."
+#endif
+
+/* Bits to be set in the FLAGS parameter of `timerfd_create'.  */
+enum
+  {
+TFD_CLOEXEC  = 01000,
+#define TFD_CLOEXEC TFD_CLOEXEC
+TFD_NONBLOCK = 4
+#define TFD_NONBLOCK TFD_NONBLOCK
+  };
diff --git a/libc/sysdeps/linux/common/bits/timerfd.h 
b/libc/sysdeps/linux/common/bits/timerfd.h
new file mode 100644
index 000..93e8c76
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/timerfd.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef_SYS_TIMERFD_H
+# error "Never use  directly; include  instead."
+#endif
+
+/* Bits to be set in the FLAGS parameter of `timerfd_create'.  */
+enum
+  {
+TFD_CLOEXEC = 0200,
+#define TFD_CLOEXEC TFD_CLOEXEC
+TFD_NONBLOCK = 4000
+#define TFD_NONBLOCK TFD_NONBLOCK
+  };
diff --git a/libc/sysdeps/linux/common/sys/timerfd.h 
b/libc/sysdeps/linux/common/sys/timerfd.h
index c1bb06f..989382a 100644
--- a/libc/sysdeps/linux/common/sys/timerfd.h
+++ b/libc/sysdeps/linux/common/sys/timerfd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU C Library is free software; you can redistribute it and/or
@@ -12,24 +12,16 @@
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  *

[PATCH 2/4] inotify.h: Use new "bits/" scheme for arch-specific flags

2012-04-08 Thread Kevin Cernekee
glibc has split off the arch-specific flag definitions (like
IN_NONBLOCK) into /bits/inotify.h, so that there are no longer
multiple redundant copies of the entire header file.  We will adopt the
same scheme in uClibc.

Special cases are included for: alpha mips sparc

hppa was omitted because it has not been updated in glibc.

All others use the common definition.

Signed-off-by: Kevin Cernekee 
---
 Makefile.in  |1 +
 libc/sysdeps/linux/alpha/bits/inotify.h  |   29 +
 libc/sysdeps/linux/common/bits/inotify.h |   29 +
 libc/sysdeps/linux/common/sys/inotify.h  |   20 +++-
 libc/sysdeps/linux/mips/bits/inotify.h   |   29 +
 libc/sysdeps/linux/sparc/bits/inotify.h  |   29 +
 6 files changed, 124 insertions(+), 13 deletions(-)
 create mode 100644 libc/sysdeps/linux/alpha/bits/inotify.h
 create mode 100644 libc/sysdeps/linux/common/bits/inotify.h
 create mode 100644 libc/sysdeps/linux/mips/bits/inotify.h
 create mode 100644 libc/sysdeps/linux/sparc/bits/inotify.h

diff --git a/Makefile.in b/Makefile.in
index 82a2eff..5cedaa8 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -271,6 +271,7 @@ HEADERS_RM-$(UCLIBC_HAS_WORDEXP) += wordexp.h
 HEADERS_RM-$(UCLIBC_HAS_XATTR)   += sys/xattr.h
 HEADERS_RM-$(UCLIBC_HAS_XLOCALE) += xlocale.h
 HEADERS_RM-$(UCLIBC_LINUX_SPECIFIC)  += sys/eventfd.h sys/fsuid.h \
+   bits/inotify.h \
sys/inotify.h \
sys/kdaemon.h \
sys/perm.h \
diff --git a/libc/sysdeps/linux/alpha/bits/inotify.h 
b/libc/sysdeps/linux/alpha/bits/inotify.h
new file mode 100644
index 000..3fbe3b8
--- /dev/null
+++ b/libc/sysdeps/linux/alpha/bits/inotify.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2005-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef_SYS_INOTIFY_H
+# error "Never use  directly; include  instead."
+#endif
+
+/* Flags for the parameter of inotify_init1.  */
+enum
+  {
+IN_CLOEXEC  = 01000,
+#define IN_CLOEXEC IN_CLOEXEC
+IN_NONBLOCK = 4
+#define IN_NONBLOCK IN_NONBLOCK
+  };
diff --git a/libc/sysdeps/linux/common/bits/inotify.h 
b/libc/sysdeps/linux/common/bits/inotify.h
new file mode 100644
index 000..291f008
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/inotify.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2005-2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef_SYS_INOTIFY_H
+# error "Never use  directly; include  instead."
+#endif
+
+/* Flags for the parameter of inotify_init1.  */
+enum
+  {
+IN_CLOEXEC = 0200,
+#define IN_CLOEXEC IN_CLOEXEC
+IN_NONBLOCK = 4000
+#define IN_NONBLOCK IN_NONBLOCK
+  };
diff --git a/libc/sysdeps/linux/common/sys/inotify.h 
b/libc/sysdeps/linux/common/sys/inotify.h
index 07be37d..a1d74d6 100644
--- a/libc/sysdeps/linux/common/sys/inotify.h
+++ b/libc/sysdeps/linux/common/sys/inotify.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2005-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU C Library is free software; you can redistribute it and/or
@@ -12,24 +12,16 @@
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 33

[PATCH 1/4] inotify_rm_watch: Change second argument to int

2012-04-08 Thread Kevin Cernekee
>From glibc:

2009-01-30  Ulrich Drepper  

[BZ #7040]
* sysdeps/unix/sysv/linux/sys/inotify.h: Second parameter of
inotify_rm_watch should have type int.

This change allows us to copy inotify.h verbatim from glibc into uClibc.

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/common/inotify.c |2 +-
 libc/sysdeps/linux/common/sys/inotify.h |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/inotify.c 
b/libc/sysdeps/linux/common/inotify.c
index e35f043..e2f3836 100644
--- a/libc/sysdeps/linux/common/inotify.c
+++ b/libc/sysdeps/linux/common/inotify.c
@@ -24,5 +24,5 @@ _syscall3(int, inotify_add_watch, int, fd, const char *, 
path, uint32_t, mask)
 #endif
 
 #ifdef __NR_inotify_rm_watch
-_syscall2(int, inotify_rm_watch, int, fd, uint32_t, wd)
+_syscall2(int, inotify_rm_watch, int, fd, int, wd)
 #endif
diff --git a/libc/sysdeps/linux/common/sys/inotify.h 
b/libc/sysdeps/linux/common/sys/inotify.h
index dc4e19d..07be37d 100644
--- a/libc/sysdeps/linux/common/sys/inotify.h
+++ b/libc/sysdeps/linux/common/sys/inotify.h
@@ -98,7 +98,7 @@ extern int inotify_add_watch (int __fd, const char *__name, 
uint32_t __mask)
   __THROW;
 
 /* Remove the watch specified by WD from the inotify instance FD.  */
-extern int inotify_rm_watch (int __fd, uint32_t __wd) __THROW;
+extern int inotify_rm_watch (int __fd, int __wd) __THROW;
 
 __END_DECLS
 
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH V2 8/8] MIPS: Fix more *_NONBLOCK definitions

2012-04-07 Thread Kevin Cernekee
On Sat, Apr 7, 2012 at 10:32 PM, Mike Frysinger  wrote:
> On Saturday 07 April 2012 16:31:32 Kevin Cernekee wrote:
>> The proposed change is to add #ifdef clauses for __mips__, similar to
>> what was done for SFD_NONBLOCK in include/sys/signalfd.h .  This fixes
>> the two failing test cases.
>
> we don't want arch ifdefs in these common files, nor do we want to diverge 
> from
> glibc.  upstream glibc has finally gotten sane and converted to bits/inotify.h
> for handling arch-specific stuff.  let's import those updates instead.

Thanks for the quick review.  The original non-ifdef submission is here:

http://lists.uclibc.org/pipermail/uclibc/2012-February/046409.html

Some discussion which led to V2:

http://lists.uclibc.org/pipermail/uclibc/2012-February/046418.html
http://lists.uclibc.org/pipermail/uclibc/2012-February/046419.html

Re: documentation - is it worth explicitly mentioning these oddball
headers/definitions in docs/PORTING or is the current verbiage
sufficient?
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Re: [PATCH V2 8/8] MIPS: Fix more *_NONBLOCK definitions

2012-04-07 Thread Kevin Cernekee
On Sat, Apr 7, 2012 at 2:09 PM, Khem Raj  wrote:
>> After seeing a problem report involving one of the O_NONBLOCK
>> "derivatives," I looked through the tree to see what else might be
>> affected.  Here is what I found:
>
> We already have this kind of patch in future branch IIRC

I think TFD_NONBLOCK and IN_NONBLOCK are still missing on both master
and future?
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

[PATCH V2 8/8] MIPS: Fix more *_NONBLOCK definitions

2012-04-07 Thread Kevin Cernekee
MIPS defines O_NONBLOCK differently from most other architectures.  The
common definitions use 04000 / 0x800, but MIPS uses 0200 / 0x80 instead.

After seeing a problem report involving one of the O_NONBLOCK
"derivatives," I looked through the tree to see what else might be
affected.  Here is what I found:

O_NONBLOCK: correct
SOCK_NONBLOCK: correct (tst-sock-nonblock passes)
EPOLL_NONBLOCK: correct
SFD_NONBLOCK: correct (fixed in commit f87898ca; tst-signalfd passes)
TFD_NONBLOCK: incorrect (tst-timerfd fails)
IN_NONBLOCK: incorrect (tst-inotify fails)

The proposed change is to add #ifdef clauses for __mips__, similar to
what was done for SFD_NONBLOCK in include/sys/signalfd.h .  This fixes
the two failing test cases.

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/common/sys/inotify.h |   11 +++
 libc/sysdeps/linux/common/sys/timerfd.h |   11 +++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/libc/sysdeps/linux/common/sys/inotify.h 
b/libc/sysdeps/linux/common/sys/inotify.h
index dc4e19d..4a10d6b 100644
--- a/libc/sysdeps/linux/common/sys/inotify.h
+++ b/libc/sysdeps/linux/common/sys/inotify.h
@@ -23,6 +23,16 @@
 
 
 /* Flags for the parameter of inotify_init1.  */
+#if defined __mips__
+enum
+  {
+IN_CLOEXEC = 0200,
+#define IN_CLOEXEC IN_CLOEXEC
+IN_NONBLOCK = 0200
+#define IN_NONBLOCK IN_NONBLOCK
+  };
+
+#else
 enum
   {
 IN_CLOEXEC = 0200,
@@ -30,6 +40,7 @@ enum
 IN_NONBLOCK = 04000
 #define IN_NONBLOCK IN_NONBLOCK
   };
+#endif
 
 
 /* Structure describing an inotify event.  */
diff --git a/libc/sysdeps/linux/common/sys/timerfd.h 
b/libc/sysdeps/linux/common/sys/timerfd.h
index c1bb06f..141338e 100644
--- a/libc/sysdeps/linux/common/sys/timerfd.h
+++ b/libc/sysdeps/linux/common/sys/timerfd.h
@@ -23,6 +23,16 @@
 
 
 /* Bits to be set in the FLAGS parameter of `timerfd_create'.  */
+#if defined __mips__
+enum
+  {
+TFD_CLOEXEC = 0200,
+#define TFD_CLOEXEC TFD_CLOEXEC
+TFD_NONBLOCK = 0200
+#define TFD_NONBLOCK TFD_NONBLOCK
+  };
+
+#else
 enum
   {
 TFD_CLOEXEC = 0200,
@@ -30,6 +40,7 @@ enum
 TFD_NONBLOCK = 04000
 #define TFD_NONBLOCK TFD_NONBLOCK
   };
+#endif
 
 
 /* Bits to be set in the FLAGS parameter of `timerfd_settime'.  */
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 7/8] test/misc: Add tst-inotify

2012-04-07 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 test/.gitignore |1 +
 test/misc/tst-inotify.c |   66 +++
 2 files changed, 67 insertions(+), 0 deletions(-)
 create mode 100644 test/misc/tst-inotify.c

diff --git a/test/.gitignore b/test/.gitignore
index 2b03543..65490c2 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -151,6 +151,7 @@ misc/popen
 misc/seek
 misc/sem
 misc/stdarg
+misc/tst-inotify
 misc/tst-scandir
 misc/tst-seekdir
 misc/tst-utmp
diff --git a/test/misc/tst-inotify.c b/test/misc/tst-inotify.c
new file mode 100644
index 000..9d940f7
--- /dev/null
+++ b/test/misc/tst-inotify.c
@@ -0,0 +1,66 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * inotify test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee 
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int
+do_test(void)
+{
+   int ifd, fd, ret, result = 0;
+   struct inotify_event e;
+   char tfile[] = "/tmp/inotify.XX";
+
+   fd = mkstemp(tfile);
+   close(fd);
+
+   ifd = inotify_init1(IN_NONBLOCK);
+   if (ifd < 0) {
+   perror("inotify_init1()");
+   result = 1;
+   }
+   if (inotify_add_watch(ifd, tfile, IN_DELETE_SELF) < 0) {
+   perror("inotify_add_watch()");
+   result = 1;
+   }
+
+   /* nonblocking inotify should return immediately with no events */
+   ret = read(ifd, &e, sizeof(e));
+   if (ret != -1 || errno != EAGAIN) {
+   error(0, 0, "first read() returned %d", ret);
+   result = 1;
+   }
+
+   /* generate an event */
+   unlink(tfile);
+
+   /* now check whether our event was seen */
+   ret = read(ifd, &e, sizeof(e));
+   if (ret != sizeof(e)) {
+   error(0, 0, "second read() returned %d", ret);
+   result = 1;
+   }
+
+   if (!(e.mask & IN_DELETE_SELF)) {
+   error(0, 0, "incorrect event mask: %" PRIx32, e.mask);
+   result = 1;
+   }
+
+   return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 6/8] test/inet: Add tst-sock-nonblock

2012-04-07 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 test/.gitignore   |1 +
 test/inet/tst-sock-nonblock.c |   53 +
 2 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 test/inet/tst-sock-nonblock.c

diff --git a/test/.gitignore b/test/.gitignore
index 4abedb1..2b03543 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -47,6 +47,7 @@ inet/tst-ethers
 inet/tst-ethers-line
 inet/tst-network
 inet/tst-ntoa
+inet/tst-sock-nonblock
 inet/gethostid
 inet/getnetent
 librt/shmtest
diff --git a/test/inet/tst-sock-nonblock.c b/test/inet/tst-sock-nonblock.c
new file mode 100644
index 000..54a7ee2
--- /dev/null
+++ b/test/inet/tst-sock-nonblock.c
@@ -0,0 +1,53 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * Nonblocking socket test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee 
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int
+do_test(void)
+{
+   int fd, ret, result = 0;
+   struct sockaddr_un sa;
+   char buf;
+
+   fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+   if (fd < 0) {
+   perror("socket()");
+   result = 1;
+   }
+
+   memset(&sa, 0, sizeof(sa));
+   sa.sun_family = AF_UNIX;
+   strcpy(sa.sun_path, "socktest");
+   unlink("socktest");
+   if (bind(fd, (const struct sockaddr *)&sa, sizeof(sa)) < 0) {
+   perror("bind()");
+   result = 1;
+   }
+
+   ret = read(fd, &buf, sizeof(buf));
+   if (ret != -1 || errno != EAGAIN) {
+   error(0, 0, "Nonblocking read returned %d", ret);
+   result = 1;
+   }
+
+   return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 5/8] test/time: Add tst-timerfd

2012-04-07 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 test/.gitignore |1 +
 test/time/tst-timerfd.c |   71 +++
 2 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 test/time/tst-timerfd.c

diff --git a/test/.gitignore b/test/.gitignore
index a86135d..4abedb1 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -288,6 +288,7 @@ time/tst-futimens1
 time/tst-mktime
 time/tst-mktime3
 time/tst-strptime2
+time/tst-timerfd
 time/tst_wcsftime
 tls/tst-tls[1-9]
 tls/tst-tls1[0-8]
diff --git a/test/time/tst-timerfd.c b/test/time/tst-timerfd.c
new file mode 100644
index 000..5562ed7
--- /dev/null
+++ b/test/time/tst-timerfd.c
@@ -0,0 +1,71 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * timerfd test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee 
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int
+do_test(void)
+{
+   int fd, ret, result = 0;
+   struct itimerspec s;
+   uint64_t val;
+   time_t start, now;
+
+   fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
+   if (fd < 0) {
+   perror("timerfd() failed");
+   result = 1;
+   }
+   s.it_value.tv_sec = 1;
+   s.it_value.tv_nsec = 0;
+   s.it_interval.tv_sec = 0;
+   s.it_interval.tv_nsec = 0;
+   timerfd_settime(fd, 0, &s, NULL);
+   start = time(NULL);
+
+   /* this should return immediately with EAGAIN due to TFD_NONBLOCK */
+   ret = read(fd, &val, sizeof(val));
+   if (ret != -1 || errno != EAGAIN) {
+   error(0, 0, "first read() returned %d", ret);
+   result = 1;
+   }
+
+   /* let the timer expire, then check it again */
+   do {
+   now = time(NULL);
+   } while (now - start < 2);
+
+   ret = read(fd, &val, sizeof(val));
+   if (ret != sizeof(val)) {
+   error(0, 0, "second read() returned %d", ret);
+   result = 1;
+   }
+
+   /* we are expecting a single expiration, since it_interval is 0 */
+   if (val != 1) {
+   error(0, 0, "wrong number of expirations: %" PRIx64, val);
+   result = 1;
+   }
+
+   return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 4/8] test/signal: Add tst-signalfd

2012-04-07 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 test/.gitignore|1 +
 test/signal/tst-signalfd.c |   63 
 2 files changed, 64 insertions(+), 0 deletions(-)
 create mode 100644 test/signal/tst-signalfd.c

diff --git a/test/.gitignore b/test/.gitignore
index a39fbec..a86135d 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -247,6 +247,7 @@ signal/sigchld
 signal/signal
 signal/tst-raise
 signal/tst-signal
+signal/tst-signalfd
 signal/tst-sigset
 signal/tst-sigsimple
 silly/hello
diff --git a/test/signal/tst-signalfd.c b/test/signal/tst-signalfd.c
new file mode 100644
index 000..1fbb748
--- /dev/null
+++ b/test/signal/tst-signalfd.c
@@ -0,0 +1,63 @@
+/* vi: set sw=4 ts=4 sts=4: */
+/*
+ * signalfd test for uClibc
+ * Copyright (C) 2012 by Kevin Cernekee 
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int
+do_test(void)
+{
+   int fd, ret, result = 0;
+   struct signalfd_siginfo ssi;
+   sigset_t mask;
+
+   sigemptyset(&mask);
+   sigaddset(&mask, SIGUSR1);
+   sigprocmask(SIG_BLOCK, &mask, NULL);
+
+   fd = signalfd(-1, &mask, SFD_NONBLOCK);
+   if (fd < 0) {
+   printf("signalfd() failed: %s\n", strerror(errno));
+   result = 1;
+   }
+
+   /* this should return immediately with EAGAIN due to SFD_NONBLOCK */
+   memset(&ssi, 0, sizeof(ssi));
+   ret = read(fd, &ssi, sizeof(ssi));
+   if (ret != -1 || errno != EAGAIN) {
+   error(0, 0, "first read() returned %d", ret);
+   result = 1;
+   }
+
+   kill(getpid(), SIGUSR1);
+
+   /* this should return a struct ssi indicating receipt of SIGUSR1 */
+   ret = read(fd, &ssi, sizeof(ssi));
+   if (ret != sizeof(ssi)) {
+   error(0, 0, "second read() returned %d", ret);
+   result = 1;
+   }
+
+   if (ssi.ssi_signo != SIGUSR1) {
+   error(0, 0, "ssi contains bogus signo");
+   result = 1;
+   }
+
+   return result;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 3/8] test/signal: Fix compile warning in tst-sigset

2012-04-07 Thread Kevin Cernekee
Move up the variable declaration, to fix this:

tst-sigset.c: In function 'do_test':
tst-sigset.c:28:3: warning: ISO C90 forbids mixed declarations and code

Signed-off-by: Kevin Cernekee 
---
 test/signal/tst-sigset.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/test/signal/tst-sigset.c b/test/signal/tst-sigset.c
index bc1b057..bfbab77 100644
--- a/test/signal/tst-sigset.c
+++ b/test/signal/tst-sigset.c
@@ -21,15 +21,15 @@ do_test (void)
   else
 
 
-  sigset_t set;
-  TRY (sigemptyset (&set) != 0);
-
 #ifdef SIGRTMAX
   int max_sig = SIGRTMAX;
 #else
   int max_sig = NSIG - 1;
 #endif
 
+  sigset_t set;
+  TRY (sigemptyset (&set) != 0);
+
   for (sig = 1; sig <= max_sig; ++sig)
 {
   TRY (sigismember (&set, sig) != 0);
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 1/8] test: Ignore various test objects

2012-04-07 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 test/.gitignore |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/test/.gitignore b/test/.gitignore
index c892816..a39fbec 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -29,11 +29,15 @@ dlopen/dltest2
 dlopen/dlundef
 dlopen/libafk.so
 dlopen/libafk-temp.so
+dlopen/libA.so
+dlopen/libB.so
+dlopen/libC.so
 dlopen/libstatic.so
 dlopen/libtest[123].so
 dlopen/libtest.so
 dlopen/libundef.so
 dlopen/test[1-3]
+dlopen/testscope
 inet/bug-if1
 inet/gethost_r-align
 inet/if_nameindex
@@ -250,6 +254,7 @@ silly/tiny
 stat/memcmp-stat
 stat/stat
 stat/stat64
+stat/stat-loop256
 stdio/64bit
 stdio/fclose-loop
 stdlib/ptytest
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH] prevent retries on fclose/fflush after write errors

2012-03-11 Thread Kevin Cernekee
Some test results:

The longer patch posted at Sun 14:46:24 +0100 made my target system
unbootable.  I did not attempt to troubleshoot it, as we are focusing
our efforts on the shorter patch now.

The shorter patch posted at Mon 01:50:27 +0100 is a good start, but it
didn't completely fix the problem for me.  I am posting an updated
version with a few changes at the end of this message; the patched
uClibc 0.9.32.1 tree passes both of my test cases.

My changes:

1) Need to break out of the loop on "hard" errors.  Otherwise the
library call never returns:

open("/dev/null", O_RDONLY) = 4
dup2(4, 1)  = 1
write(1, "hello world\n", 12)   = -1 EBADF (Bad file descriptor)
write(1, "hello world\n", 12)   = -1 EBADF (Bad file descriptor)
write(1, "hello world\n", 12)   = -1 EBADF (Bad file descriptor)
write(1, "hello world\n", 12)   = -1 EBADF (Bad file descriptor)
...

2) Move all of the error handling logic back into the "else" clause.  In
particular, I believe we do not want to be checking errno unless
__WRITE() had indicated a failure, since the value may be undefined:

if (errno == EINTR
 || errno == EAGAIN
 /* do we have other "soft" errors? */
) {

3) Whitespace/indentation consistency.

-- 8< --

From: Denys Vlasenko 

Currently, uclibc retains buffered data on stdio write errors,
and subsequent fclose and fflush will try to write it out again
(in most cases, in vain).

Which results in something like this:

On Wednesday 26 January 2011 13:21, Baruch Siach wrote:
> Hi busybox list,
>
> I'm running the following command under strace (thanks Rob):
>
> echo 56 > /sys/class/gpio/export
>
> and I see the following output:
>
> write(1, "56\n", 3) = -1 EBUSY (Device or resource busy)
> write(1, "5", 1)= 1
>
> The first EBUSY is OK, since GPIO 56 is already requested. But the second
> write() attempt seems strange, and leads to an unwanted outcome. GPIO 5 gets
> exported.

This patch prevents that.

Signed-off-by: Denys Vlasenko 
Signed-off-by: Kevin Cernekee 
---
 libc/stdio/_WRITE.c |   30 --
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c
index 10b3b95..e6b167b 100644
--- a/libc/stdio/_WRITE.c
+++ b/libc/stdio/_WRITE.c
@@ -60,14 +60,32 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
 #endif
todo -= rv;
buf += rv;
-   } else
-#ifdef __UCLIBC_MJN3_ONLY__
-#warning EINTR?
-#endif
-/* if (errno != EINTR) */
-   {
+   } else {
+
__STDIO_STREAM_SET_ERROR(stream);
 
+   /* We buffer data on "transient" errors, but discard it
+* on "hard" ones. Example of a hard error:
+*
+* close(fileno(stdout));
+* printf("Hi there 1\n"); // EBADF
+* dup2(good_fd, fileno(stdout));
+* printf("Hi there 2\n"); // buffers new data
+*
+* This program should not print "Hi there 1" to 
good_fd.
+* The rationale is that the caller of writing operation
+* should check for error and act on it.
+* If he didn't, then future users of the stream
+* have no idea what to do.
+* It's least confusing to at least not burden them with
+* some hidden buffered crap in the buffer.
+*/
+   if (errno != EINTR
+   && errno != EAGAIN
+   /* do we have other "soft" errors? */
+   ) {
+   break;
+   }
 #ifdef __STDIO_BUFFERS
if ((stodo = __STDIO_STREAM_BUFFER_SIZE(stream)) != 0) {
unsigned char *s;
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH] prevent retries on fclose/fflush after write errors

2012-03-10 Thread Kevin Cernekee
On Sat, Feb 12, 2011 at 6:31 PM, Denys Vlasenko
 wrote:
>> >Currently, uclibc retains buffered data on stdio write errors,
>> >and subsequent fclose and fflush will try to write it out again
>> >(in most cases, in vain).

This seems to be causing some strange problems on bash as well.  Is
there any interest in trying to mimic the glibc behavior?

uClibc version is 0.9.32.1.


bash problem:

# bash --version
GNU bash, version 3.2.0(1)-release (mipsel-unknown-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
# echo "none of the above" > /sys/power/state
sh: echo: write error: Invalid argument
# a
sh: a: command not found
none of the abov# b
sh: b: command not found
none of the abov#
# echo mem > /sys/power/state
sh: echo: write error: Invalid argument
# echo mem > /sys/power/state
sh: echo: write error: Invalid argument
# busybox echo mem > /sys/power/state
PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.01 seconds) done.
Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done.
Suspending console(s) (use no_console_suspend to debug)


Simple test case to show that the buffered data persists (albeit in
truncated form) even after calling fflush() and clearerr():

-- 8< --

#include 
#include 
#include 

int main(int argc, char **argv)
{
int tmpfd, fd;

tmpfd = fcntl(fileno(stdout), F_DUPFD, 0);
fd = open("/dev/null", O_RDONLY);

dup2(fd, fileno(stdout));

printf("hello world\n");
fflush(stdout);
if (ferror(stdout))
clearerr(stdout);

dup2(tmpfd, fileno(stdout));

printf("goodbye world\n");

return 0;
}

-- 8< --

Output:

# ./test
hello worlgoodbye world
#
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH 2/2] MIPS: Fix more *_NONBLOCK definitions

2012-02-08 Thread Kevin Cernekee
On Wed, Feb 8, 2012 at 10:12 PM, Kevin Cernekee  wrote:
> SOCK_NONBLOCK: correct
> SFD_NONBLOCK: correct (fixed in recent commit f87898ca)
> TFD_NONBLOCK: incorrect
> IN_NONBLOCK: incorrect

Attaching the test cases I wrote to validate that these four syscalls
work correctly on my new toolchain.

If it looks like they might be useful, I could clean them up and
integrate them into the uClibc testsuite.


uclibc-tests.tar.bz2
Description: BZip2 compressed data
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

[PATCH 2/2] MIPS: Fix more *_NONBLOCK definitions

2012-02-08 Thread Kevin Cernekee
MIPS defines O_NONBLOCK differently from most other architectures.  The
common definitions use 04000 / 0x800, but MIPS uses 0200 / 0x80 instead.

After seeing a problem report involving one of the O_NONBLOCK
"derivatives," I looked through the tree to see what else might be
affected.  Here is what I found:

O_NONBLOCK: correct
SOCK_NONBLOCK: correct
EPOLL_NONBLOCK: correct
SFD_NONBLOCK: correct (fixed in recent commit f87898ca)
TFD_NONBLOCK: incorrect
IN_NONBLOCK: incorrect

The proposed fix, cribbed from glibc, is to fork {timerfd,inotify}.h
for each architecture that needs special treatment.

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/mips/sys/inotify.h |  105 +
 libc/sysdeps/linux/mips/sys/timerfd.h |   60 +++
 2 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 libc/sysdeps/linux/mips/sys/inotify.h
 create mode 100644 libc/sysdeps/linux/mips/sys/timerfd.h

diff --git a/libc/sysdeps/linux/mips/sys/inotify.h 
b/libc/sysdeps/linux/mips/sys/inotify.h
new file mode 100644
index 000..1d5e768
--- /dev/null
+++ b/libc/sysdeps/linux/mips/sys/inotify.h
@@ -0,0 +1,105 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef_SYS_INOTIFY_H
+#define_SYS_INOTIFY_H  1
+
+#include 
+
+
+/* Flags for the parameter of inotify_init1.  */
+enum
+  {
+IN_CLOEXEC = 0200,
+#define IN_CLOEXEC IN_CLOEXEC
+IN_NONBLOCK = 0200
+#define IN_NONBLOCK IN_NONBLOCK
+  };
+
+
+/* Structure describing an inotify event.  */
+struct inotify_event
+{
+  int wd;  /* Watch descriptor.  */
+  uint32_t mask;   /* Watch mask.  */
+  uint32_t cookie; /* Cookie to synchronize two events.  */
+  uint32_t len;/* Length (including NULs) of name.  */
+  char name __flexarr; /* Name.  */
+};
+
+
+/* Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH.  */
+#define IN_ACCESS   0x0001 /* File was accessed.  */
+#define IN_MODIFY   0x0002 /* File was modified.  */
+#define IN_ATTRIB   0x0004 /* Metadata changed.  */
+#define IN_CLOSE_WRITE  0x0008 /* Writtable file was closed.  */
+#define IN_CLOSE_NOWRITE 0x0010/* Unwrittable file closed.  */
+#define IN_CLOSE(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close.  */
+#define IN_OPEN 0x0020 /* File was opened.  */
+#define IN_MOVED_FROM   0x0040 /* File was moved from X.  */
+#define IN_MOVED_TO  0x0080/* File was moved to Y.  */
+#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves.  */
+#define IN_CREATE   0x0100 /* Subfile was created.  */
+#define IN_DELETE   0x0200 /* Subfile was deleted.  */
+#define IN_DELETE_SELF  0x0400 /* Self was deleted.  */
+#define IN_MOVE_SELF0x0800 /* Self was moved.  */
+
+/* Events sent by the kernel.  */
+#define IN_UNMOUNT  0x2000 /* Backing fs was unmounted.  */
+#define IN_Q_OVERFLOW   0x4000 /* Event queued overflowed.  */
+#define IN_IGNORED  0x8000 /* File was ignored.  */
+
+/* Helper events.  */
+#define IN_CLOSE(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)/* Close.  */
+#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO)  /* 
Moves.  */
+
+/* Special flags.  */
+#define IN_ONLYDIR  0x0100 /* Only watch the path if it is a
+  directory.  */
+#define IN_DONT_FOLLOW  0x0200 /* Do not follow a sym link.  */
+#define IN_MASK_ADD 0x2000 /* Add to the mask of an already
+  existing watch.  */
+#define IN_ISDIR0x4000 /* Event occurred against dir.  */
+#define IN_ONESHOT  0x8000 /* Only send event once.  */
+
+/* All events which a program can wait on.  */
+#define IN_ALL_EVENTS   (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE  \
+ | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM\
+ | IN_MOVED_TO | IN_CREATE | IN_DELETE   \
+ | IN_DELETE_SELF | IN

[PATCH 1/2] test/README: Trivial fixes for spelling error and long lines

2012-02-08 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 test/README |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/test/README b/test/README
index 8fb12d9..7d0fe52 100644
--- a/test/README
+++ b/test/README
@@ -1,7 +1,7 @@
 ---
  For: User
 ---
-Following make targets are avaialable
+Following make targets are available
 
 make compile
 
@@ -54,12 +54,14 @@ The structure of this test system is:
   makefiles plus Makefile.in
  test/subdir/*.c  the tests
 
-Each subdir has a Makefile (same for any subdir) that must include in strict 
order:
+Each subdir has a Makefile (same for any subdir) that must include in strict
+order:
   - the upper-level Rules.mak file
   - the Makefile.in
   - the upper-level Test.mak file
 Makefile.in may be used to define the TESTS and TESTS_DISABLED variables.
-If you do not, TESTS is built automatically based upon all the .c files in the 
subdir.
+If you do not, TESTS is built automatically based upon all the .c files in
+the subdir.
 TESTS := foo
 TESTS_DISABLED := bar
 Each test must use a similar .c name; so the "foo" test needs a "foo.c".
-- 
1.7.8.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: negative memcpy

2011-08-10 Thread Kevin Cernekee
On a MIPS 74K I would expect it to end up here:

>>   400338:     28c80008        slti    t0,a2,8
>>   40033c:     1535        bnez    t0,400414 <__BMIPS3300_memcpy_last8>
>>   400340:     00801021        move    v0,a0

...

>> 00400414 <__BMIPS3300_memcpy_last8>:
>>   400414:     18c6        blez    a2,400430 <__BMIPS3300_memcpy_lst8e>
>>   400418:     00c53821        addu    a3,a2,a1

...

>> 00400430 <__BMIPS3300_memcpy_lst8e>:
>>   400430:     03e8        jr      ra
>>   400434:             nop

blez = branch if less than or equal to zero.

It would be a good idea to read through the whole function and figure
out whether $a2 can ever become negative in normal operation, before
changing the signed comparisons to unsigned.

Another possible hack is to AND $a2 with 0x7fff on entry.  This
would probably not catch cases like passing in a length of 0x8010,
but it would catch lengths like 0x.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

[PATCH 3/3] ldso/mips: Clean up warnings

2011-07-24 Thread Kevin Cernekee
Trivial fixes for these warnings:

  CC ldso/libdl/libdl.oS
In file included from ldso/ldso/ldso.c:46:0:
ldso/ldso/mips/elfinterp.c:88:1: warning: no previous prototype for 
'__dl_runtime_pltresolve'
ldso/ldso/ldso.c: In function '_dl_get_ready_to_run':
ldso/ldso/ldso.c:475:5: warning: assignment makes pointer from integer without 
a cast
In file included from ldso/ldso/ldso.c:1097:0:
ldso/ldso/dl-elf.c: In function '_dl_load_elf_shared_library':
ldso/ldso/dl-elf.c:811:3: warning: assignment makes pointer from integer 
without a cast

Signed-off-by: Kevin Cernekee 
---
 ldso/ldso/mips/dl-sysdep.h |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/ldso/ldso/mips/dl-sysdep.h b/ldso/ldso/mips/dl-sysdep.h
index e61c6ec..6041245 100644
--- a/ldso/ldso/mips/dl-sysdep.h
+++ b/ldso/ldso/mips/dl-sysdep.h
@@ -130,7 +130,7 @@ do {
\
GOT_BASE[0] = (unsigned long) _dl_runtime_resolve;  
\
GOT_BASE[1] = (unsigned long) MODULE;   
\

\
-   pltgot = MODULE->dynamic_info[DT_MIPS_PLTGOT_IDX];  
\
+   pltgot = (unsigned long *) MODULE->dynamic_info[DT_MIPS_PLTGOT_IDX];
\
if (pltgot) {   
\
pltgot[0] = (unsigned long) _dl_runtime_pltresolve; 
\
pltgot[1] = (unsigned long) MODULE; 
\
@@ -159,6 +159,9 @@ unsigned long __dl_runtime_resolve(unsigned long sym_index,
unsigned long old_gpreg);
 
 struct elf_resolve;
+unsigned long __dl_runtime_pltresolve(struct elf_resolve *tpnt,
+   int reloc_entry);
+
 void _dl_perform_mips_global_got_relocations(struct elf_resolve *tpnt, int 
lazy);
 
 /* 4096 bytes alignment */
-- 
1.7.6

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 2/3] ldso/mips: dlsym() incorrectly matches undefined symbols

2011-07-24 Thread Kevin Cernekee
check_match() relies on checking for (sym->st_value == 0) to see if the
symbol is undefined.  This works reasonably well on most architectures,
such as ARM or i386:

$ readelf -s /lib32/libcap.so.2 | grep -E "\"
17:  0 FUNCGLOBAL DEFAULT  UND malloc@GLIBC_2.0 (2)

However, on MIPS, libbfd puts nonzero data in the st_value field to
facilitate resetting the symbol's GOT entry if the library that defines
the symbol gets unloaded:

$ mipsel-linux-readelf -s libfoo.so | grep -E "\"
74: 3140 0 FUNCGLOBAL DEFAULT  UND malloc

This can cause check_match to report a false positive when examining the
external symbol reference.  Consequently dlsym() will return a bad pointer
to the caller.

Use the special MIPS logic from glibc-ports-2.13 to avoid this situation.

Signed-off-by: Kevin Cernekee 
---
 ldso/ldso/dl-hash.c|4 
 ldso/ldso/mips/dl-sysdep.h |3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c
index 2ec883a..9b67156 100644
--- a/ldso/ldso/dl-hash.c
+++ b/ldso/ldso/dl-hash.c
@@ -188,6 +188,10 @@ check_match (const ElfW(Sym) *sym, char *strtab, const 
char* undef_name, int typ
 */
return NULL;
 #endif
+#ifdef ARCH_SKIP_RELOC
+   if (ARCH_SKIP_RELOC(type_class, sym))
+   return NULL;
+#endif
if (_dl_strcmp(strtab + sym->st_name, undef_name) != 0)
return NULL;
 
diff --git a/ldso/ldso/mips/dl-sysdep.h b/ldso/ldso/mips/dl-sysdep.h
index 80c089a..e61c6ec 100644
--- a/ldso/ldso/mips/dl-sysdep.h
+++ b/ldso/ldso/mips/dl-sysdep.h
@@ -113,6 +113,9 @@ else if ((dpnt->d_tag == DT_MIPS_RLD_MAP) && 
(dpnt->d_un.d_ptr)) \
  *(ElfW(Addr) *)(dpnt->d_un.d_ptr) =  (ElfW(Addr)) debug_addr; \
 } while (0)
 
+#define ARCH_SKIP_RELOC(type_class, sym) \
+ ((sym)->st_shndx == SHN_UNDEF && !((sym)->st_other & STO_MIPS_PLT))
+
 /* Initialization sequence for the application/library GOT.  */
 #define INIT_GOT(GOT_BASE,MODULE)  
\
 do {   
\
-- 
1.7.6

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 1/3] ldso/mips: Enable bootstrap relocations

2011-07-24 Thread Kevin Cernekee
_dl_reltypes_tab[] is an array of pointers to constant strings:

Contents of section .data:
 2 0100 0200    
 20010 70e5 7ce5 88e5 94e5  p...|...
      

(pointers are LE)

Contents of section .rodata:
 e570 525f4d49 50535f4e 4f4e4500 525f4d49  R_MIPS_NONE.R_MI
 e580 50535f31 3600 525f4d49 50535f33  PS_16...R_MIPS_3
 e590 3200 525f4d49 50535f52 454c3332  2...R_MIPS_REL32

These pointers require relocation:

DYNAMIC RELOCATION RECORDS
OFFSET   TYPE  VALUE
 R_MIPS_NONE   *ABS*
0001fffc R_MIPS_REL32  *ABS*
00020010 R_MIPS_REL32  *ABS*
00020014 R_MIPS_REL32  *ABS*
00020018 R_MIPS_REL32  *ABS*

On MIPS, only GOT relocations are currently handled by ldso during
startup.  The net effect is that when running with "LD_DEBUG=reloc",
ldso itself crashes before the program even starts.  This is caused
by _dl_dprintf() dereferencing an unadjusted string pointer such as
0xe570.

This patch enables the missing relocations and allows LD_DEBUG to work
as designed.

Signed-off-by: Kevin Cernekee 
---
 ldso/ldso/dl-startup.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
index fa7972d..75ea564 100644
--- a/ldso/ldso/dl-startup.c
+++ b/ldso/ldso/dl-startup.c
@@ -251,7 +251,7 @@ DL_START(unsigned long args)
PERFORM_BOOTSTRAP_GOT(tpnt);
 #endif
 
-#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__)
+#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__) || defined(__mips__)
 
/* OK, now do the relocations.  We do not do a lazy binding here, so
   that once we are done, we have considerably more flexibility. */
-- 
1.7.6

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: dlsym call fails

2011-07-21 Thread Kevin Cernekee
On Thu, Jul 21, 2011 at 2:52 AM, manish kumar  wrote:
>        if(!libc_malloc)
>                libc_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc"); 
> dlerror();

You probably want braces here, but that is not a likely cause of the
reported problem.

I have seen cases where uClibc dlsym(RTLD_NEXT, ...) will find an
undefined symbol and return an unusable pointer.  I suspect that this
is not the behavior intended by the authors.  For example, on an
application linked with these libraries:

$ readelf -s libuClibc-0.9.32.so  | grep -E "\"
  1225: 00036c90  2488 FUNCGLOBAL DEFAULT7 malloc

$ readelf -s libfoo.so  | grep malloc
74: 3140 0 FUNCGLOBAL DEFAULT  UND malloc

dlsym(RTLD_NEXT, ...) might find the libfoo entry instead of the
libuClibc entry.  The returned pointer will not really reach malloc().

I noticed that when dlsym() calls _dl_find_hash(), it uses type_class
0.  If it used type_class ELF_RTYPE_CLASS_DLSYM that would make more
sense to me (although it would not fix this problem), because nobody
else seems to pass in ELF_RTYPE_CLASS_DLSYM.  If it used type_class
ELF_RTYPE_CLASS_PLT I do suspect it would fix your problem, but it
might break other things like data references.  check_match() will not
match an undefined symbol, as long as (type_class & 1) == 1.

Would it be safe to pass in a bitmask of the desired types?  ala:

diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
index 52c77b0..e256f86 100644
--- a/ldso/libdl/libdl.c
+++ b/ldso/libdl/libdl.c
@@ -667,7 +667,7 @@ void *dlsym(void *vhandle, const char *name)
tpnt = NULL;
if (handle == _dl_symbol_tables)
tpnt = handle->dyn; /* Only search RTLD_GLOBAL objs if
global object */
-   ret = _dl_find_hash(name2, handle, tpnt, 0, &sym_ref);
+   ret = _dl_find_hash(name2, handle, tpnt, ELF_RTYPE_CLASS_PLT |
ELF_RTYPE_CLASS_COPY, &sym_ref);

 #if defined(USE_TLS) && USE_TLS && defined SHARED
if (sym_ref.tpnt) {
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Re: Buildroot and bitbake

2011-06-11 Thread Kevin Cernekee
On Sat, Jun 11, 2011 at 12:58 PM, Thomas Petazzoni
 wrote:
> Rob Landley  a écrit :
>> I dunno about "recommended".  By who?  There are people using
>> buildroot (which is a repository accumulating build descriptions for
>> the "bitbake" build tool)
>
> Sorry to contradict, Buildroot is not related to bitbake in anyway.
> Buildroot is completely written in make and does not use any other
> external tool to process the package recipes.

BitBake is the tool around which the OpenEmbedded project was built.

I don't know which libc OE is using by default, but buildroot itself
only knows how to build uClibc based toolchains.  (Although it can
optionally use a prebuilt external toolchain or invoke crosstool-ng,
so you can still use it with glibc/eglibc.)

I suspect that buildroot is uClibc's biggest "customer."
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Re: New libgcc_eh dependency for ARM_EABI targets

2011-06-10 Thread Kevin Cernekee
> Sorry, my patch actually not meant to address your exact situation,
> but rather the unconditional linking of gcc_eh when libubacktrace is
> not enabled.

One possibility is to apply your patch, build the first stage uClibc
with UCLIBC_HAS_BACKTRACE disabled, then re-enable it and rebuild once
gcc stage 2 is ready.

I just wound up patching gcc to build libgcc_eh in stage 1.  I don't
know what the right solution is but this was easiest.

-- 8< --

--- gcc-4.5.2/libgcc/Makefile.in2010-03-30 06:08:52.0 -0700
+++ gcc-4.5.2.new/libgcc/Makefile.in2011-06-10 16:57:20.471925132 -0700
@@ -765,8 +765,9 @@
 libgcc_s$(SHLIB_EXT): libunwind$(SHLIB_EXT)
 endif
 
+all: libgcc_eh.a
 ifeq ($(enable_shared),yes)
-all: libgcc_eh.a libgcc_s$(SHLIB_EXT)
+all: libgcc_s$(SHLIB_EXT)
 ifneq ($(LIBUNWIND),)
 all: libunwind$(SHLIB_EXT)
 endif
@@ -935,10 +936,6 @@
 install-shared:
$(mkinstalldirs) $(DESTDIR)$(inst_libdir)
 
-   $(INSTALL_DATA) libgcc_eh.a $(DESTDIR)$(inst_libdir)/
-   chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_eh.a
-   $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_eh.a
-
$(subst @multilib_dir@,$(MULTIDIR),$(subst \
@shlib_base_name@,libgcc_s,$(subst \
@shlib_slibdir_qual@,$(MULTIOSSUBDIR),$(SHLIB_INSTALL
@@ -952,6 +949,9 @@
$(INSTALL_DATA) libgcov.a $(DESTDIR)$(inst_libdir)/
chmod 644 $(DESTDIR)$(inst_libdir)/libgcov.a
$(RANLIB) $(DESTDIR)$(inst_libdir)/libgcov.a
+   $(INSTALL_DATA) libgcc_eh.a $(DESTDIR)$(inst_libdir)/
+   chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_eh.a
+   $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_eh.a
 
parts="$(INSTALL_PARTS)";   \
for file in $$parts; do \
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


New libgcc_eh dependency for ARM_EABI targets

2011-06-10 Thread Kevin Cernekee
Commit 4916fd88 (present in v0.9.32, but not in v0.9.32-rc3) created a
new dependency on libgcc_eh.a for the final link stage:

uClibc-0.9.32/libubacktrace/Makefile.in:

ifeq ($(CONFIG_ARM_EABI),y)
LIBGCC += $(shell $(CC) -print-file-name=libgcc_eh.a)
endif

I build gcc stage 1 with --disable-shared, which causes libgcc_eh.a
not to be built:

gcc-4.5.2/libgcc/Makefile.in:

ifeq ($(enable_shared),yes)
all: libgcc_eh.a libgcc_s$(SHLIB_EXT)
...

Therefore, I am not able to build uClibc 0.9.32 with my gcc stage 1
compiler.  This worked fine on uClibc 0.9.32-rc3.

I see that Rob Landley has patched his gcc source tree so that it
always builds libgcc_eh.a.  Is this the recommended procedure going
forward?

Rob:

> I'm building stock gcc 4.2.1 with binutils 2.17 (last GPLv2 release of
> each, I await either LLVM or PCC maturing to usability with bated
> breath).  I am applying a few patches but none of them are sparc
> stuff.  (Half of them fix various issues with arm, one makes
> libgcc_eh.a build during the --disable- shared pass, and the rest fix
> OBVIOUS breakage with sh4, alpha, and mips64 of the "how did they ever
> use those targets" variety).
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH/RFC future] nptl: reinstate SIGCANCEL/SIGSETXID safeguards

2011-05-10 Thread Kevin Cernekee
On Tue, May 10, 2011 at 2:06 PM, Peter Mazinger  wrote:
> I am for only one implementation (that should go only into libc), else you 
> have unpredictable/different results depending on which linking order you 
> choose libc/libpthread

Austin's patch in the -future branch does accomplish this, but as it
stands, it completely eliminates the special handling of the
SIGCANCEL/SIGSETXID bits in sigfillset() and sigprocmask().

For sigfillset() this causes a mismatch between glibc behavior (N-2
bits set) and uClibc behavior (N bits set).

My patch reinstates the special handling for both functions, although
this causes the sigprocmask() behavior to no longer match glibc.  If
that is a problem, I can change it and resubmit.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH/RFC future] nptl: reinstate SIGCANCEL/SIGSETXID safeguards

2011-05-08 Thread Kevin Cernekee
Couple more data points to muddy the waters:

x86 glibc 2.11.1 (same result for -pthread and non -pthread):

sigfillset refused to set: 32 (Unknown signal 32)
sigfillset refused to set: 33 (Unknown signal 33)
sigprocmask refused to mask: 9 (Killed)
sigprocmask refused to mask: 19 (Stopped (signal))
sending SIGINT
sending SIGQUIT
caught sig 3 (Quit)

MIPS uClibc 0.9.32-rc3 unpatched, built with -pthread:

sigfillset refused to set: 32 (Unknown signal 32)
sigfillset refused to set: 33 (Unknown signal 33)
sigprocmask refused to mask: 9 (Killed)
sigprocmask refused to mask: 23 (Stopped (signal))
sigprocmask refused to mask: 32 (Unknown signal 32)
sigprocmask refused to mask: 33 (Unknown signal 33)
sending SIGINT
sending SIGQUIT
caught sig 3 (Quit)

MIPS uClibc 0.9.32-rc3 unpatched, built without -pthread:

sigprocmask refused to mask: 9 (Killed)
sigprocmask refused to mask: 23 (Stopped (signal))
sending SIGINT
sending SIGQUIT
caught sig 3 (Quit)

MIPS uClibc 0.9.32-rc3 with Austin's patch + my patch (same result for
-pthread and non -pthread):

sigfillset refused to set: 32 (Unknown signal 32)
sigfillset refused to set: 33 (Unknown signal 33)
sigprocmask refused to mask: 9 (Killed)
sigprocmask refused to mask: 23 (Stopped (signal))
sigprocmask refused to mask: 32 (Unknown signal 32)
sigprocmask refused to mask: 33 (Unknown signal 33)
sending SIGINT
sending SIGQUIT
caught sig 3 (Quit)


glibc has two sigprocmask implementations:

./sysdeps/unix/sysv/linux/sigprocmask.c - this has the same SIGCANCEL
and SIGSETXID code as uClibc but does not include pthreadP.h, so the
extra checks remain inactive.

./nptl/sysdeps/pthread/sigprocmask.c is just:

#include 
#include 

So the latter implementation will refuse to mask SIGCANCEL +
SIGSETXID.  But the former implementation gets built into libc, and
the latter implementation never gets built.  Therefore glibc
sigprocmask() does NOT block tampering with SIGCANCEL/SIGSETXID.


glibc also has two sigfillset implementations:

./signal/sigfillset.c - this has the same SIGCANCEL and SIGSETXID code
as uClibc but does not include pthreadP.h, so the extra checks remain
inactive.

./nptl/sysdeps/pthread/sigfillset.c is just:

#include 
#include 

So the latter implementation will refuse to mask SIGCANCEL +
SIGSETXID.  The latter implementation gets built into libc, and the
former implementation never gets built by itself.  Therefore glibc
sigfillset() DOES avoid setting bits for SIGCANCEL/SIGSETXID.


I am left wondering:

1) How much of the observed glibc behavior is the result of an
explicit design decision?  Or did it wind up working this way by
accident?

2) How much of the observed glibc behavior should we try to emulate in uClibc?


Updated test program:

-- 8< --

#include 
#include 
#include 
#include 
#include 

void fn(int sig, siginfo_t *si, void *vctx)
{
printf("caught sig %d (%s)\n", sig, strsignal(sig));
exit(0);
}

int main(int argc, char **argv)
{
sigset_t s, old;
struct sigaction sa, sa_old;
int i;

/* see if sigfillset/sigaddset/sigprocmask skip certain signals */

sigfillset(&s);
for (i = 1; i <= SIGRTMAX; i++)
if (!sigismember(&s, i))
printf("sigfillset refused to set: %d (%s)\n",
i, strsignal(i));

/* try to fill in the holes left by sigfillset() */
for (i = 1; i <= SIGRTMAX; i++) {
sigaddset(&s, i);
if (!sigismember(&s, i))
printf("sigaddset refused to set: %d (%s)\n",
i, strsignal(i));
}
sigprocmask(SIG_BLOCK, &s, &old);
sigprocmask(SIG_BLOCK, NULL, &s);
for (i = 1; i <= SIGRTMAX; i++) {
if (!sigismember(&s, i))
printf("sigprocmask refused to mask: %d (%s)\n",
i, strsignal(i));
}

/* send ourselves a signal to see if sigaction works properly */

sigfillset(&s);
sigdelset(&s, SIGQUIT);
sigprocmask(SIG_SETMASK, &s, &old);

memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = fn;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGQUIT, &sa, &sa_old);

printf("sending SIGINT\n");
usleep(10);
kill(0, SIGINT);
usleep(10);

printf("sending SIGQUIT\n");
usleep(10);
kill(0, SIGQUIT);
usleep(10);

printf("failed to catch SIGQUIT\n");
exit(1);
}
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH/RFC future] nptl: reinstate SIGCANCEL/SIGSETXID safeguards

2011-05-08 Thread Kevin Cernekee
On Sun, May 8, 2011 at 8:19 AM, Peter Mazinger  wrote:
>> libc sigfillset() returns a full set: all 128 bits are set.  libpthread
>> sigfillset() sets only 126 bits: everything except SIGCANCEL/SIGSETXID.
>>
>> libpthread sigprocmask() has extra code to prevent the caller from
>> blocking
>> SIGCANCEL/SIGSETXID.  libc sigprocmask() does not.
>
> If you did your tests on mips, couldn't it be, that this is influenced by the 
> change of using kernel sigset_t size for mips on all "generic" syscall 
> implementations (see KERNEL_SIGSET_T_SIZE macro)?

While the vector is sized differently on MIPS, I ran my test program
on an x86/glibc PC and saw that sigfillset() was still clearing the
bits for SIGCANCEL and SIGSETXID:

$ ./sigaction-test
Not masked: 3
Not masked: 32
Not masked: 33
sending SIGINT
sending SIGQUIT
caught sig 3

On the Linux PC, this behavior is seen regardless of whether
libpthread is linked in.

(Interestingly, on the PC, __sigaction() is duplicated in libc and
libpthread, but sigprocmask() and sigfillset() are not.)

After applying Austin's patch and my patch to uClibc 0.9.32-rc3, I was
able to verify that the sigfillset() behavior on the uClibc MIPS
target matches the behavior on the glibc PC.  This seems like it would
be a good thing.

Before applying my patch, SIGCANCEL and SIGSETXID were not defined so
the special libpthread behavior was not compiled into libc.  I do not
think there is a MIPS dependency involved.

I guess it probably would make sense to check the sigprocmask()
behavior at some point, as well.

Test program:

#include 
#include 
#include 
#include 
#include 

void fn(int sig, siginfo_t *si, void *vctx)
{
printf("caught sig %d\n", sig);
exit(0);
}

int main(int argc, char **argv)
{
sigset_t s, old;
struct sigaction sa, sa_old;
int i;

sigfillset(&s);
sigdelset(&s, SIGQUIT);
sigprocmask(SIG_BLOCK, &s, &old);

for (i = 1; i <= SIGRTMAX; i++)
if (!sigismember(&s, i))
printf("Not masked: %d\n", i);

memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = fn;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGQUIT, &sa, &sa_old);

printf("sending SIGINT\n");
usleep(10);
kill(0, SIGINT);
usleep(10);

printf("sending SIGQUIT\n");
usleep(10);
kill(0, SIGQUIT);
usleep(10);

printf("failed to catch SIGQUIT\n");
exit(1);
}
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Re: [PATCH/RFC future] nptl: reinstate SIGCANCEL/SIGSETXID safeguards

2011-05-07 Thread Kevin Cernekee
On Sat, May 7, 2011 at 7:16 PM, Rich Felker  wrote:
>> libc sigfillset() returns a full set: all 128 bits are set.  libpthread
>> sigfillset() sets only 126 bits: everything except SIGCANCEL/SIGSETXID.
>
> I fail to see how having sigfillset/sigaddset do the blocking of these
> signals makes sense. As long as sigprocmask and sigaction treat them
> specially, that should be enough...

FWIW, it looks like that part of the function was copied verbatim from glibc.

I do not see these exclusions in sigaddset().
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

[PATCH/RFC future] nptl: reinstate SIGCANCEL/SIGSETXID safeguards

2011-05-07 Thread Kevin Cernekee
Commit 8ab3145f (remove sigaction, sigprocmask, and sigfillset from
libpthread) removed duplicated implementations of the three aforementioned
functions from libpthread.  However, as Rich Felker pointed out, the
libc and libpthread versions are not always 100% identical.  A closer
examination of the pre-8ab3145f disassemblies showed the following:

libc sigfillset() returns a full set: all 128 bits are set.  libpthread
sigfillset() sets only 126 bits: everything except SIGCANCEL/SIGSETXID.

libpthread sigprocmask() has extra code to prevent the caller from blocking
SIGCANCEL/SIGSETXID.  libc sigprocmask() does not.

No differences were observed in __sigaction(), since the NPTL version of
this function was always built into libc anyway.

This patch pulls in the SIGCANCEL/SIGSETXID definitions via pthreadP.h
when NPTL is enabled, restoring the special signal exclusions needed
by libpthread.

Signed-off-by: Kevin Cernekee 
---
 libc/signal/sigfillset.c|4 
 libc/sysdeps/linux/common/sigprocmask.c |4 
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/libc/signal/sigfillset.c b/libc/signal/sigfillset.c
index ef60f10..e041f08 100644
--- a/libc/signal/sigfillset.c
+++ b/libc/signal/sigfillset.c
@@ -23,6 +23,10 @@
 #include 
 #endif
 
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+#include 
+#endif
+
 /* Set all signals in SET.  */
 int
 sigfillset (sigset_t *set)
diff --git a/libc/sysdeps/linux/common/sigprocmask.c 
b/libc/sysdeps/linux/common/sigprocmask.c
index 6230033..a60fa49 100644
--- a/libc/sysdeps/linux/common/sigprocmask.c
+++ b/libc/sysdeps/linux/common/sigprocmask.c
@@ -9,6 +9,10 @@
 
 #include 
 
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+#include 
+#endif
+
 #if defined __USE_POSIX
 #include 
 
-- 
1.7.5

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH 3/3] libc_elf_mips: specific auxiliary vector handling for MIPS

2011-05-02 Thread Kevin Cernekee
On Mon, May 2, 2011 at 9:44 AM, Carmelo AMOROSO  wrote:
> Extend aux vect handling for MIPS to retrieve DCache shape information
> and platform string.

I had to add a (verbatim) copy of the SH Makefile.arch, for MIPS, in
order to get the new dl-support.c file added to the build.

> +attribute_hidden const char* __platform  = NULL;

Extra space before "= NULL".

NULL is not defined here.  I had to #include  to fix the build error.

> +#define DL_PLATFORM_AUXV 
>\
> + case AT_L1D_CACHESHAPE: 
>\
> + __l1d_cache_shape = (int) av[AT_L1D_CACHESHAPE].a_un.a_val; 
>\
> + break;  
>\
> + case AT_PLATFORM:   
>\

The '\' characters line up at column 80 if I use 4-space tabstops, but
with standard 8-space tabs they're kind of all over the place...

Is 4-space the standard for uClibc?  I did not see anything under
docs/ which indicated either way.

MIPS:

> +attribute_hidden int __l1d_cache_shape = 0;
> +attribute_hidden const char* __platform  = NULL;

SH:

> +static int __dcache_way_size;

Might want to make the initialization more consistent between the two
architectures.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH 2/3] libc_elf_sh: specific auxiliary vector handling for SH

2011-05-02 Thread Kevin Cernekee
On Mon, May 2, 2011 at 9:44 AM, Carmelo AMOROSO  wrote:
> +/* Decode the cpu dcache way size from the dcache shape */
> +/* Bits 0-3 contains associativity; bits 4-7 contains log2 of line size */
> +
> +#define shape_to_waysize(__shape)((__shape & ~0xff) / (__shape & 0xf))

It may be useful to add helper macros/functions for CACHESHAPE
decoding to a common header file, and try to establish the Alpha/SH
encoding as a de-facto standard on MIPS and other architectures.

(I guess it goes without saying that the SH D$ will never be fully
associative, and av[AT_L1D_CACHESHAPE] will never be 0?)
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH 1/3] libc_elf: improve auxiliary vector handling

2011-05-02 Thread Kevin Cernekee
On Mon, May 2, 2011 at 9:44 AM, Carmelo AMOROSO  wrote:
> This patch is aimed to improve the aux vect handling to gather some useful
> information from the system through the aux vect. It is achieved by:

Thanks for working on this - it looks like we're on the right track.
A few cosmetic nitpicks:

> +/* Minimum number of AT entries from auxiliar vector */

"auxiliary"

> +# error "AT_EXTRA_UPTO has to be defined (0 if not extra AT entried are 
> needed)"

"no extra AT entries"

> +/* For the ld.so we are interested to the minimum entries from the auxvect */

"interested in"

It's a personal preference, but it might be a tiny bit more
straightforward to define libc AT_NUM in terms of AT_EXTRA_UPTO
directly.  e.g.

#define AT_BASE_NUM (AT_EGID + 1)

# if AT_EXTRA_UPTO == 0
#  define AT_LIBC_NUM   AT_BASE_NUM
# else
#  define AT_LIBC_NUM   (AT_EXTRA_UPTO + 1)
# endif

> +extern size_t __pagesize;

I see this getting declared as an extern in: dl-support.c, malloc.h,
getpagesize.c, and linuxthreads.old/internals.h .

Do you think it would be a good idea to move the declaration into
 or another common header file?

> -   /* Get the number of program headers from the aux vect */
> -   _dl_phnum = (size_t) av[AT_PHNUM].a_un.a_val;
> + for (; av->a_type < AT_NUM; ++av) {
> + switch (av->a_type) {

FWIW, that does result in mixed indentation styles in dl-support.c .

> + for (; av->a_type < AT_NUM; ++av) {

...

> + __pagesize = (size_t) (av[AT_PAGESZ].a_un.a_val) ?

All of these cases should probably look more like "av->a_un.a_val",
since av gets incremented on each iteration of the loop.  Without this
fix, the patch set does not work at all for me.

There is another problem with setting __pagesize up in _dl_aux_init()
- it causes __uClibc_init() to skip initialization:

void __uClibc_init(void)
{
/* Don't recurse */
if (__pagesize)
return;

The most obvious symptom that I noticed was that statically linked TLS
binaries crashed here:

if (likely(not_null_ptr(__errno_location)))
*(__errno_location()) = 0;

> +#ifndef SHARED
> + case AT_PHDR:
> +/* Get the program headers base address from the aux 
> vect */

Maybe wouldn't hurt anything to leave these cases/variables enabled in
the SHARED builds?
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH/RFC 2/2] Cache AT_PLATFORM and AT_L1D_CACHESHAPE from auxvec

2011-04-17 Thread Kevin Cernekee
On Sun, Apr 17, 2011 at 1:56 AM, Carmelo Amoroso  wrote:
> I'm really interested into such a thing. I've posted months ago a patch for 
> SH4 to retrieve Cache info through auxvect
> as well (also pagesize).

I do remember seeing your patch on the list.  Didn't realize it was
never merged.

> I think we should do this in a dl_aux_init as in my patch instead of polluting
> all these stuff in __uClibc_main.

I agree conceptually with reading all auxvect variables in a dedicated
function instead of putting an ever-growing list in __uClibc_main().
And I did originally consider _dl_aux_init(), until I saw that
dl-support.c is only used for static builds of libc.  Maybe there is
another place to put the code?

One thing to consider is how much of this code can (and should) be
shared between ld.so and libc.  There were a couple of different
places where the auxvect information was getting grabbed/parsed and
maybe it does make sense to consolidate it somehow.

In the case of memcpy(), one would want to be able to retrieve the
auxvect values on both shared and static versions of libc.  This might
wind up looking a little different from what needs to be done to
extract your SHMLBA value for dynamic linking purposes.

Regarding this part of your patch:

+/* Starting with version 2.6.25-rc1, dcache shape info are passed in auxvect */
+#if __LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,25) && defined __sh__
+#define __ASSUME_DCACHESHAPE_AUXVECT   1
+#endif

Is that something that could be figured out at runtime instead, based
on whether there is an auxvect entry with the AT_L1D_CACHESHAPE tag?

I ask, because my architecture doesn't have AT_L1D_CACHESHAPE
implemented in mainline yet...
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH/RFC 2/2] Cache AT_PLATFORM and AT_L1D_CACHESHAPE from auxvec

2011-04-16 Thread Kevin Cernekee
Allow uClibc internal functions to make optimizations at runtime, based
on the CPU type or D$ line size retrieved from the auxiliary vector.
This would nominally be used for functions like memcpy(), on processors
that do not have an unprivileged instruction along the lines of "CPUID".

Signed-off-by: Kevin Cernekee 
---
 include/libc-internal.h |4 
 libc/misc/internals/__uClibc_main.c |   13 +++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/libc-internal.h b/include/libc-internal.h
index 3ac0b05..ef5ce59 100644
--- a/include/libc-internal.h
+++ b/include/libc-internal.h
@@ -65,6 +65,10 @@ libc_hidden_proto(__glibc_strerror_r)
 /* internal access to program name */
 extern const char *__uclibc_progname attribute_hidden;
 
+/* internal access to auxvec AT_PLATFORM, cache info */
+extern const char *__auxv_platform attribute_hidden;
+extern int __auxv_l1d_cacheshape attribute_hidden;
+
 #  ifdef __UCLIBC_HAS_FORTIFY__
 extern void __chk_fail(void) attribute_noreturn;
 libc_hidden_proto(__chk_fail)
diff --git a/libc/misc/internals/__uClibc_main.c 
b/libc/misc/internals/__uClibc_main.c
index 315365a..bc2e253 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
 #include 
 #include 
@@ -156,6 +157,12 @@ weak_alias (program_invocation_short_name, __progname)
 weak_alias (program_invocation_name, __progname_full)
 #endif
 
+/* Highest numbered auxvec entry to copy into auxvt[] */
+#define AT_MAX AT_L3_CACHESHAPE
+
+attribute_hidden const char *__auxv_platform = NULL;
+attribute_hidden int __auxv_l1d_cacheshape = 0;
+
 /*
  * Declare the __environ global variable and create a weak alias environ.
  * This must be initialized; we cannot have a weak alias into bss.
@@ -321,7 +328,7 @@ void __uClibc_main(int (*main)(int, char **, char **), int 
argc,
 {
 #ifndef __ARCH_HAS_NO_LDSO__
 unsigned long *aux_dat;
-ElfW(auxv_t) auxvt[AT_EGID + 1];
+ElfW(auxv_t) auxvt[AT_MAX + 1];
 #endif
 
 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
@@ -355,7 +362,7 @@ void __uClibc_main(int (*main)(int, char **, char **), int 
argc,
 aux_dat++;
 while (*aux_dat) {
ElfW(auxv_t) *auxv_entry = (ElfW(auxv_t) *) aux_dat;
-   if (auxv_entry->a_type <= AT_EGID) {
+   if (auxv_entry->a_type <= AT_MAX) {
memcpy(&(auxvt[auxv_entry->a_type]), auxv_entry, 
sizeof(ElfW(auxv_t)));
}
aux_dat += 2;
@@ -376,6 +383,8 @@ void __uClibc_main(int (*main)(int, char **, char **), int 
argc,
 #ifndef __ARCH_HAS_NO_LDSO__
 /* Make certain getpagesize() gives the correct answer */
 __pagesize = (auxvt[AT_PAGESZ].a_un.a_val)? auxvt[AT_PAGESZ].a_un.a_val : 
PAGE_SIZE;
+__auxv_platform = (char *)auxvt[AT_PLATFORM].a_un.a_val;
+__auxv_l1d_cacheshape = (int)auxvt[AT_L1D_CACHESHAPE].a_un.a_val;
 
 /* Prevent starting SUID binaries where the stdin. stdout, and
  * stderr file descriptors are not already opened. */
-- 
1.7.4.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH 1/2] dl-startup: fix typos in block comment

2011-04-16 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 ldso/ldso/dl-startup.c |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c
index a51b583..4492660 100644
--- a/ldso/ldso/dl-startup.c
+++ b/ldso/ldso/dl-startup.c
@@ -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
-- 
1.7.4.3

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH] Drop GNU make 3.80 compatibility

2011-04-09 Thread Kevin Cernekee
On Fri, Apr 8, 2011 at 5:34 PM, Khem Raj  wrote:
> I think it would be nice to keep it working with make 3.80 even though
> its 10 years old. Are these problems widespread ? if not then consider
> cooking up a patch :)

Done.

There is one more occurrence in the link.asneeded function (Rules.mak)
which I was not sure what to do with.  It was introduced over 2 years
ago and I have not noticed any ill effects, but I guess it should
probably be sorted out at some point since it will eventually bite
somebody.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH] buildsys: fix GNU make v3.80 compatibility again

2011-04-09 Thread Kevin Cernekee
GNU make 3.80 cannot handle "$(and)" or "$(or)" from commit 18e7136e
(buildsys: use kbuild style).  Replace them with ifeq/ifneq.

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/common/Makefile.in |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/Makefile.in 
b/libc/sysdeps/linux/common/Makefile.in
index 3f97911..b0754df 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -15,7 +15,9 @@ CSRC_LFS := $(notdir $(wildcard $(COMMON_DIR)/*64.c))
 CSRC-y := $(filter-out llseek.c $(CSRC_LFS),$(CSRC-y))
 CSRC-$(UCLIBC_HAS_LFS) += llseek.c $(CSRC_LFS)
 
-CSRC-$(if $(or $(UCLIBC_HAS_SSP),$(UCLIBC_HAS_FORTIFY)),y) += ssp.c
+ifneq ($(UCLIBC_HAS_SSP)$(UCLIBC_HAS_FORTIFY),)
+CSRC-y += ssp.c
+endif
 CSRC-$(UCLIBC_LINUX_MODULE_24) += create_module.c query_module.c \
get_kernel_syms.c
 # we need these internally: fstatfs.c statfs.c
@@ -25,7 +27,9 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += capget.c capset.c inotify.c 
ioperm.c iopl.c \
sendfile64.c sendfile.c setfsgid.c setfsuid.c setresuid.c \
splice.c vmsplice.c tee.c signalfd.c swapoff.c swapon.c \
sync_file_range.c sysctl.c sysinfo.c timerfd.c uselib.c vhangup.c
-CSRC-$(if $(and $(UCLIBC_LINUX_SPECIFIC),$(UCLIBC_HAS_THREADS_NATIVE)),y) += 
madvise.c
+ifeq ($(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_THREADS_NATIVE),yy)
+CSRC-y += madvise.c
+endif
 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
 CSRC- += fork.c getpid.c raise.c open.c close.c read.c write.c
 CSRC- += $(if $(findstring =arm=,=$(TARGET_ARCH)=),vfork.c)
-- 
1.7.4.2

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH] Drop GNU make 3.80 compatibility

2011-04-01 Thread Kevin Cernekee
On Fri, Apr 1, 2011 at 1:43 PM, Mike Frysinger  wrote:
> On Fri, Apr 1, 2011 at 11:23 AM, Kevin Cernekee wrote:
>> The "$(and" operator requires GNU make 3.81.  On 3.80 it is a no-op.
>> Consequently, strange build problems (failure to compile madvise.c) pop
>> up when using make 3.80.
>>
>> Since nobody else is reporting these types of problems, I'm going to
>> guess that I am one of the last remaining holdouts still running 3.80.
>> So we might as well officially require 3.81.
>
> if that's the only reason, then let's drop the $(and) usage instead.

A month or two ago, "else ifeq" broke make 3.80.

I suspect that everybody else is using 3.81/3.82 and so 3.80 is not
getting any test coverage.  This allows small incompatibilities to
creep into the Makefiles.

Personally, I'd rather not upgrade because I try to make my release
buildable on any stock RHEL4/RHEL5 system.  But I don't want to have
to keep debugging things that only break because I'm using make 3.80.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

[PATCH] Drop GNU make 3.80 compatibility

2011-04-01 Thread Kevin Cernekee
The "$(and" operator requires GNU make 3.81.  On 3.80 it is a no-op.
Consequently, strange build problems (failure to compile madvise.c) pop
up when using make 3.80.

Since nobody else is reporting these types of problems, I'm going to
guess that I am one of the last remaining holdouts still running 3.80.
So we might as well officially require 3.81.

Signed-off-by: Kevin Cernekee 
---
 Rules.mak |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rules.mak b/Rules.mak
index 0aa6843..70fb851 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -17,8 +17,8 @@
 
 
 # check for proper make version
-ifneq ($(findstring x3.7,x$(MAKE_VERSION)),)
-$(error Your make is too old $(MAKE_VERSION). Go get at least 3.80)
+ifneq ($(filter 3.7% 3.80,$(MAKE_VERSION)),)
+$(error Your make is too old $(MAKE_VERSION). Go get at least 3.81)
 endif
 
 #---
-- 
1.7.4.2

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: static linking failed with sigaction testing program

2011-03-27 Thread Kevin Cernekee
On Sat, Mar 26, 2011 at 10:26 PM, Mike Frysinger  wrote:
> really you should be looking at how the linker processes things.  use
> -Wl,-M for both.

Thanks for the tip.  That is useful.

So, for "-static -lpthread -lc" on uClibc:

The test program needs sigaction(), and this pulls in
libpthread.a(pt-sigaction.os).  So far so good.

But later on, libc.a(abort.os) needs __GI_sigaction().  This symbol
exists in libc.a(sigaction.os) but not in
libpthread.a(pt-sigaction.os).  So the linker winds up grabbing both
.os files.  A few strong symbols are duplicated in both
libc.a(sigaction.os) and libpthread.a(pt-sigaction.os), which causes
the link to fail.

For "-static -lpthread -lc" on glibc, there is no __GI_sigaction() to
complicate matters.  abort() calls __sigaction().  Either
libc.a(sigaction.o) or libpthread.a(sigaction.o) can satisfy this
dependency, so there is no reason why the linker would ever try to
grab both copies of sigaction.o .

Interestingly, if I rebuild uClibc with DOPIC disabled,
libpthread.a(pt-sigaction.o) now contains __GI_sigaction() and thus
the conflict vanishes.

I don't know why DOPIC was enabled in the first place, or what else
might break due to the change.  Time to run some more tests.
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Re: static linking failed with sigaction testing program

2011-03-26 Thread Kevin Cernekee
On Fri, Mar 25, 2011 at 6:33 PM, Peter Mazinger  wrote:
> I assume you are using NPTL as threads, NPTL devs, one of the __sigactions 
> needs probably be weak



> I would say, do not use that syntax, the compiler defaults should be correct 
> (speak, -lc is added at the end of linking, if any earlier
> __sigaction was seen in a library provided on command line by
> -l, libc should provide a weak to not conflict



> To really fix it, we have to get rid of all duplicated *sigactions, only one 
> should stay (preferably in libc IMHO)

Since my glibc-based host PC has no problem compiling the test program
regardless of the link order, I checked to see how glibc implements
the symbol types:

libc.a: sigaction.o:
0220 T __sigaction
0220 W sigaction

libpthread.a: sigaction.o:
0220 T __sigaction
0220 W sigaction

What is the general consensus on how closely uClibc should try to
mirror glibc on these sorts of issues?  Is it worth figuring out what
they did differently?
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH] Fix GNU make v3.80 compatibility

2011-02-10 Thread Kevin Cernekee
Commits 1f6601a and 094d82d introduced the "else ifeq" construct, which
requires GNU make v3.81 or higher.  This breaks the build on RHEL4 hosts.

Signed-off-by: Kevin Cernekee 
---
 libc/sysdeps/linux/common/Makefile.in |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/Makefile.in 
b/libc/sysdeps/linux/common/Makefile.in
index cf4cf87..bd45d94 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -42,9 +42,11 @@ ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
 CSRC := $(filter-out fork.c getpid.c raise.c open.c close.c read.c write.c, 
$(CSRC))
 ifeq ($(TARGET_ARCH),arm)
 CSRC := $(filter-out vfork.c, $(CSRC))
-else ifeq ($(TARGET_ARCH),x86_64)
+else
+ifeq ($(TARGET_ARCH),x86_64)
 CSRC := $(filter-out vfork.c, $(CSRC))
-else ifeq ($(TARGET_ARCH),mips)
+else
+ifeq ($(TARGET_ARCH),mips)
 ifeq ($(CONFIG_MIPS_O32_ABI),y)
 CSRC := $(filter-out waitpid.c, $(CSRC))
 endif
@@ -52,6 +54,8 @@ else
 CSRC := $(filter-out waitpid.c, $(CSRC))
 endif
 endif
+endif
+endif
 
 ifneq ($(ARCH_USE_MMU),y)
 # stubbed out in mman.h
-- 
1.7.0.4

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH] MIPS NPTL: Clean up _ABI64 warnings

2009-09-26 Thread Kevin Cernekee
Signed-off-by: Kevin Cernekee 
---
 ldso/ldso/mips/elfinterp.c |2 +-
 libc/sysdeps/linux/mips/sys/regdef.h   |2 ++
 .../unix/sysv/linux/mips/bits/pthreadtypes.h   |2 ++
 3 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/ldso/ldso/mips/elfinterp.c b/ldso/ldso/mips/elfinterp.c
index 97a86a1..78cc4c1 100644
--- a/ldso/ldso/mips/elfinterp.c
+++ b/ldso/ldso/mips/elfinterp.c
@@ -247,7 +247,7 @@ _dl_dprintf(2, "TLS_TPREL  : %s, %x, %x\n", (strtab + 
symtab[symtab_index].st_na
break;
}
 #endif /* USE_TLS */
-#if _MIPS_SIM == _MIS_SIM_ABI64
+#if _MIPS_SIM == _MIPS_SIM_ABI64
case (R_MIPS_64 << 8) | R_MIPS_REL32:
 #else  /* O32 || N32 */
case R_MIPS_REL32:
diff --git a/libc/sysdeps/linux/mips/sys/regdef.h 
b/libc/sysdeps/linux/mips/sys/regdef.h
index 9d2c4c1..2d94130 100644
--- a/libc/sysdeps/linux/mips/sys/regdef.h
+++ b/libc/sysdeps/linux/mips/sys/regdef.h
@@ -20,6 +20,8 @@
 #ifndef _SYS_REGDEF_H
 #define _SYS_REGDEF_H
 
+#include 
+
 /*
  * Symbolic register names for 32 bit ABI
  */
diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/mips/bits/pthreadtypes.h 
b/libpthread/nptl/sysdeps/unix/sysv/linux/mips/bits/pthreadtypes.h
index 54f1a06..f112b8a 100644
--- a/libpthread/nptl/sysdeps/unix/sysv/linux/mips/bits/pthreadtypes.h
+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/mips/bits/pthreadtypes.h
@@ -20,6 +20,8 @@
 #ifndef _BITS_PTHREADTYPES_H
 #define _BITS_PTHREADTYPES_H   1
 
+#include 
+
 #if _MIPS_SIM == _ABI64
 # define __SIZEOF_PTHREAD_ATTR_T 56
 # define __SIZEOF_PTHREAD_MUTEX_T 40
-- 
1.6.3.1

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH] wprintf overflow

2008-02-25 Thread Kevin Cernekee

On Thu, 7 Feb 2008, Carmelo AMOROSO wrote:

> The fix I committed I think it's better... because solve the stack
> overflow but keep the check against
> higher character.
> I tested it and it works. Let me know your comments.

Hi,

One of the concerns I had with that loop is that it always aborts the
parser if it trips on a "wider" character during the copy, even if it
wasn't part of the format specifier.  For instance:

wprintf(L"%d %d %d \x0101\n", 1, 2, 3);

I don't know if this is a problem in real life, but I erred on the side of
caution and wound up using this fix:

--- uClibc-nptl-0.9.29-20070423.orig/libc/stdio/_vfprintf.c 2006-06-19 
19:32:05.0 -0700
+++ uClibc-nptl-0.9.29-20070423/libc/stdio/_vfprintf.c  2008-01-16 
15:18:19.0 -0800
@@ -893,10 +893,13 @@
fmt = buf + 1;
i = 0;
do {
+   if(i == sizeof(buf))
+   break;
if ((buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1]))
!= (((wchar_t *) ppfs->fmtpos)[i-1])
) {
-   return -1;
+   buf[i] = 0;
+   break;
}
} while (buf[i++]);
buf[sizeof(buf)-1] = 0;
___
uClibc mailing list
uClibc@uclibc.org
http://busybox.net/cgi-bin/mailman/listinfo/uclibc


[PATCH] wprintf overflow

2007-12-11 Thread Kevin Cernekee
Hi,

I am seeing a buffer overflow in uClibc-0.9.28 on mipsel, illustrated by
the following test program:


#include 
#include 

int main(int argc, char **argv)
{
wprintf(L"This line is OK\n");
wprintf(L"This line is no problem either because the format spec
is at the end: %d\n", 1);
wprintf(L"%d: This line will segfault because the format spec is
too far from the end\n", 1);
return(0);
}


In uClibc/libc/stdio/vfprintf.c or _vfprintf.c, function
_ppfs_parsespec(), there is a loop that copies the const wchar_t format
specifier into a char buffer so that it can be parsed using the same code.
However, this loop terminates at the end of the string, rather than the
end of the format spec, causing a buffer overflow for strings in which the
format specifier begins more than 32 characters from the end of the
string.

I don't see any evidence that this has been fixed in the SVN sources, but
admittedly I have not tried building/running them either.

My workaround is attached.  A better solution might be to figure out when
the format spec ends, and stop copying at that point.  This would allow us
to reinstate the "char != wchar_t" check that errors out if the user puts
a high character in the format spec.  Another option would be to just
store a NUL byte and quit copying if a high character is encountered,
letting the format spec parser sort out any issues.  Something like:

do {
if(i == sizeof(buf))
break;
if ((buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1]))
!= (((wchar_t *) ppfs->fmtpos)[i-1])
) {
buf[i] = 0;
break;
}
} while (buf[i++]);--- uClibc.orig/libc/stdio/vfprintf.c   2007-09-10 18:19:31.0 -0700
+++ uClibc/libc/stdio/vfprintf.c2007-12-11 15:26:09.0 -0800
@@ -873,11 +873,27 @@
fmt = buf + 1;
i = 0;
do {
+#if 1
+   /*
+* WORKAROUND: the original code assumes that the
+* end of the format specifier is the same as the
+* end of the format string.
+*
+* This workaround prevents the stack overflow, but
+* we can no longer check to make sure that
+* the format string doesn't contain characters
+* outside the normal char range.
+*/
+   if(i == sizeof(buf))
+   break;
+   buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1]);
+#else
if ((buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1]))
!= (((wchar_t *) ppfs->fmtpos)[i-1])
) {
return -1;
}
+#endif
} while (buf[i++]);
buf[sizeof(buf)-1] = 0;
}
___
uClibc mailing list
uClibc@uclibc.org
http://busybox.net/cgi-bin/mailman/listinfo/uclibc