[OpenWrt-Devel] uClibc bug: epoll_pwait broken on OpenWrt x86

Matthias Schiffer mschiffer at universe-factory.net
Fri Sep 5 08:15:31 EDT 2014


I've found commit 555ae2e88cd16a83f854634b6c3f35715b11d3d4, which works
around the issue in the current uClibc master:

> commit 555ae2e88cd16a83f854634b6c3f35715b11d3d4
> Author: Natanael Copa <natanael.copa at gmail.com>
> Date:   Thu Jul 5 11:55:19 2012 +0000
> 
>     i386/bits/syscalls.h: allow immediate values as 6th syscall arg
>     
>     Allow use of immedate values as the 6th syscall argument. Otherwise we must
>     store the arg on memory. This gives gcc more options to optimize better.
>     
>     This also works around an issue with posix_fallocate.

I guess the mentioned issue with posix_fallocate is the same I'm
experiencing with epoll_pwait.

Applying this patch to OpenWrt would workaround the issue in this
particular case, but I don't think relying on compiler behaviour that is
not guaranteed in any way is a good idea. There are a few cases where
the 6th syscall argument can't be immediate, so the workaround doesn't
help; one of these is splice(), which is still broken in the current master.

I've also attached my .config; for testing I'm using GCC 4.9.1, but as
mentioned, it also happens on OpenWrt, which uses the 4.6-linaro and
4.8-linaro toolchains.

Regards,
Matthias


On 09/01/2014 12:41 PM, Matthias Schiffer wrote:
> Sure, I've attached my testcase (source and compiled for Barrier Breaker).
> 
> Matthias
> 
> 
> On 09/01/2014 08:31 AM, Waldemar Brodkorb wrote:
>> Hi,
>> can you provide a simple testcase showing the bug?
>> best regards
>>  Waldemar
>>
>>
>>> Am 01.09.2014 um 00:53 schrieb Matthias Schiffer <mschiffer at universe-factory.net>:
>>>
>>> Hi,
>>> I'm posting this on both the OpenWrt and the uClibc lists to hopefully
>>> find someone who has an idea how the code in question might ever have
>>> worked (if it ever has...). The issue probably affects not only
>>> epoll_pwait, but also other syscall6 on i386. It can be seen on all
>>> OpenWrt versions ranging from Attitude Adjustment to Barrier Breaker
>>> (and probably also the current trunk).
>>>
>>> I noticed that epoll_pwait always returns EINVAL when I supply a signal
>>> set; analzing it with gdb I found out that %ebp contains a stack address
>>> instead of the length of the signal set (which should be 8).
>>>
>>> Looking at the generated code reveals this:
>>>
>>> 0000b360 <__libc_epoll_pwait>:
>>>    b360:       55                      push   %ebp
>>>    b361:       57                      push   %edi
>>>    b362:       56                      push   %esi
>>>    b363:       53                      push   %ebx
>>>    b364:       51                      push   %ecx
>>>    b365:       e8 eb ef ff ff          call   a355 <__x86.get_pc_thunk.bx>
>>>    b36a:       81 c3 8a 4c 04 00       add    $0x44c8a,%ebx
>>>    b370:       8b 74 24 24             mov    0x24(%esp),%esi
>>>    b374:       8b 7c 24 28             mov    0x28(%esp),%edi
>>>    b378:       c7 04 24 08 00 00 00    movl   $0x8,(%esp)       #1
>>>    b37f:       65 a1 0c 00 00 00       mov    %gs:0xc,%eax
>>>    b385:       85 c0                   test   %eax,%eax
>>>    b387:       75 33                   jne    b3bc
>>> <__libc_epoll_pwait+0x5c>
>>>    b389:       8b 44 24 18             mov    0x18(%esp),%eax
>>>    b38d:       8b 4c 24 1c             mov    0x1c(%esp),%ecx
>>>    b391:       8b 54 24 20             mov    0x20(%esp),%edx
>>>    b395:       53                      push   %ebx              #2
>>>    b396:       89 c3                   mov    %eax,%ebx
>>>    b398:       55                      push   %ebp              #3
>>>    b399:       8b 2c 24                mov    (%esp),%ebp       #4
>>>    b39c:       b8 3f 01 00 00          mov    $0x13f,%eax
>>>    b3a1:       cd 80                   int    $0x80
>>> ...
>>>
>>> As can be seen, the value 8 is moved onto the stack at #1 and is
>>> supposed to be moved to %ebp at #4. Unfortunately, #2 and #3 move the
>>> stack pointer...
>>>
>>> _______________________________________________
>>> uClibc mailing list
>>> uClibc at uclibc.org
>>> http://lists.busybox.net/mailman/listinfo/uclibc
> 
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
> 

-------------- next part --------------
#
# Automatically generated file; DO NOT EDIT.
# uClibc 0.9.34-git C Library Configuration
#
# TARGET_alpha is not set
# TARGET_arc is not set
# TARGET_arm is not set
# TARGET_avr32 is not set
# TARGET_bfin is not set
# TARGET_c6x is not set
# TARGET_cris is not set
# TARGET_e1 is not set
# TARGET_frv is not set
# TARGET_h8300 is not set
# TARGET_hppa is not set
TARGET_i386=y
# TARGET_i960 is not set
# TARGET_ia64 is not set
# TARGET_m68k is not set
# TARGET_metag is not set
# TARGET_microblaze is not set
# TARGET_mips is not set
# TARGET_nios is not set
# TARGET_nios2 is not set
# TARGET_powerpc is not set
# TARGET_sh is not set
# TARGET_sh64 is not set
# TARGET_sparc is not set
# TARGET_v850 is not set
# TARGET_vax is not set
# TARGET_x86_64 is not set
# TARGET_xtensa is not set

#
# Target Architecture Features and Options
#
TARGET_ARCH="i386"
FORCE_OPTIONS_FOR_ARCH=y
# CONFIG_386 is not set
CONFIG_486=y
# CONFIG_586 is not set
# CONFIG_686 is not set
TARGET_SUBARCH="i486"

#
# Using ELF file format
#
ARCH_HAS_DEPRECATED_SYSCALLS=y
ARCH_LITTLE_ENDIAN=y

#
# Using Little Endian
#
ARCH_HAS_MMU=y
ARCH_USE_MMU=y
UCLIBC_HAS_FLOATS=y
UCLIBC_HAS_FPU=y
DO_C99_MATH=y
# DO_XSI_MATH is not set
# UCLIBC_HAS_FENV is not set
UCLIBC_HAS_LONG_DOUBLE_MATH=y
KERNEL_HEADERS="/usr/include"
HAVE_DOT_CONFIG=y

#
# General Library Settings
#
DOPIC=y
ARCH_HAS_UCONTEXT=y
HAVE_SHARED=y
# FORCE_SHAREABLE_TEXT_SEGMENTS is not set
LDSO_LDD_SUPPORT=y
LDSO_CACHE_SUPPORT=y
# LDSO_PRELOAD_ENV_SUPPORT is not set
# LDSO_PRELOAD_FILE_SUPPORT is not set
LDSO_BASE_FILENAME="ld.so"
# LDSO_STANDALONE_SUPPORT is not set
# LDSO_PRELINK_SUPPORT is not set
# UCLIBC_STATIC_LDCONFIG is not set
LDSO_RUNPATH=y
LDSO_SAFE_RUNPATH=y
# LDSO_SEARCH_INTERP_PATH is not set
LDSO_LD_LIBRARY_PATH=y
# LDSO_NO_CLEANUP is not set
UCLIBC_CTOR_DTOR=y
# LDSO_GNU_HASH_SUPPORT is not set
# HAS_NO_THREADS is not set
# LINUXTHREADS_OLD is not set
# LINUXTHREADS_NEW is not set
UCLIBC_HAS_THREADS_NATIVE=y
UCLIBC_HAS_THREADS=y
UCLIBC_HAS_TLS=y
PTHREADS_DEBUG_SUPPORT=y
UCLIBC_HAS_SYSLOG=y
UCLIBC_HAS_LFS=y
# MALLOC is not set
# MALLOC_SIMPLE is not set
MALLOC_STANDARD=y
MALLOC_GLIBC_COMPAT=y
# UCLIBC_HAS_OBSTACK is not set
UCLIBC_DYNAMIC_ATEXIT=y
# COMPAT_ATEXIT is not set
# UCLIBC_SUSV2_LEGACY is not set
UCLIBC_SUSV3_LEGACY=y
# UCLIBC_HAS_CONTEXT_FUNCS is not set
UCLIBC_SUSV3_LEGACY_MACROS=y
UCLIBC_SUSV4_LEGACY=y
# UCLIBC_STRICT_HEADERS is not set
# UCLIBC_HAS_STUBS is not set
UCLIBC_HAS_SHADOW=y
UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y
UCLIBC_HAS___PROGNAME=y
UCLIBC_HAS_PTY=y
ASSUME_DEVPTS=y
# UNIX98PTY_ONLY is not set
UCLIBC_HAS_GETPT=y
UCLIBC_HAS_LIBUTIL=y
UCLIBC_HAS_TM_EXTENSIONS=y
UCLIBC_HAS_TZ_CACHING=y
UCLIBC_HAS_TZ_FILE=y
UCLIBC_HAS_TZ_FILE_READ_MANY=y
UCLIBC_TZ_FILE_PATH="/etc/TZ"
# UCLIBC_FALLBACK_TO_ETC_LOCALTIME is not set

#
# Advanced Library Settings
#
UCLIBC_PWD_BUFFER_SIZE=256
UCLIBC_GRP_BUFFER_SIZE=256

#
# Support various families of functions
#
UCLIBC_LINUX_MODULE_26=y
# UCLIBC_LINUX_MODULE_24 is not set
UCLIBC_LINUX_SPECIFIC=y
UCLIBC_HAS_GNU_ERROR=y
UCLIBC_BSD_SPECIFIC=y
UCLIBC_HAS_BSD_ERR=y
# UCLIBC_HAS_OBSOLETE_BSD_SIGNAL is not set
# UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL is not set
# UCLIBC_NTP_LEGACY is not set
# UCLIBC_SV4_DEPRECATED is not set
UCLIBC_HAS_REALTIME=y
UCLIBC_HAS_ADVANCED_REALTIME=y
UCLIBC_HAS_EPOLL=y
# UCLIBC_HAS_XATTR is not set
# UCLIBC_HAS_PROFILING is not set
UCLIBC_HAS_CRYPT_IMPL=y
# UCLIBC_HAS_SHA256_CRYPT_IMPL is not set
# UCLIBC_HAS_SHA512_CRYPT_IMPL is not set
UCLIBC_HAS_CRYPT=y
UCLIBC_HAS_NETWORK_SUPPORT=y
UCLIBC_HAS_SOCKET=y
UCLIBC_HAS_IPV4=y
UCLIBC_HAS_IPV6=y
# UCLIBC_HAS_RPC is not set
UCLIBC_USE_NETLINK=y
UCLIBC_SUPPORT_AI_ADDRCONFIG=y
UCLIBC_HAS_BSD_RES_CLOSE=y
UCLIBC_HAS_COMPAT_RES_STATE=y
# UCLIBC_HAS_EXTRA_COMPAT_RES_STATE is not set
UCLIBC_HAS_RESOLVER_SUPPORT=y
UCLIBC_HAS_LIBRESOLV_STUB=y
UCLIBC_HAS_LIBNSL_STUB=y

#
# String and Stdio Support
#
UCLIBC_HAS_STRING_GENERIC_OPT=y
UCLIBC_HAS_STRING_ARCH_OPT=y
UCLIBC_HAS_CTYPE_TABLES=y
UCLIBC_HAS_CTYPE_SIGNED=y
# UCLIBC_HAS_CTYPE_UNSAFE is not set
UCLIBC_HAS_CTYPE_CHECKED=y
# UCLIBC_HAS_CTYPE_ENFORCED is not set
UCLIBC_HAS_WCHAR=y
# UCLIBC_HAS_LOCALE is not set
UCLIBC_HAS_HEXADECIMAL_FLOATS=y
UCLIBC_HAS_GLIBC_CUSTOM_PRINTF=y
UCLIBC_PRINTF_SCANF_POSITIONAL_ARGS=9
# UCLIBC_HAS_STDIO_BUFSIZ_256 is not set
# UCLIBC_HAS_STDIO_BUFSIZ_512 is not set
# UCLIBC_HAS_STDIO_BUFSIZ_1024 is not set
# UCLIBC_HAS_STDIO_BUFSIZ_2048 is not set
UCLIBC_HAS_STDIO_BUFSIZ_4096=y
# UCLIBC_HAS_STDIO_BUFSIZ_8192 is not set
UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE=y
# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4 is not set
# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8 is not set
# UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT is not set
UCLIBC_HAS_STDIO_GETC_MACRO=y
UCLIBC_HAS_STDIO_PUTC_MACRO=y
UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION=y
# UCLIBC_HAS_FOPEN_LARGEFILE_MODE is not set
UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE=y
# UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE is not set
UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y
UCLIBC_HAS_PRINTF_M_SPEC=y
UCLIBC_HAS_ERRNO_MESSAGES=y
# UCLIBC_HAS_SYS_ERRLIST is not set
UCLIBC_HAS_SIGNUM_MESSAGES=y
# UCLIBC_HAS_SYS_SIGLIST is not set
UCLIBC_HAS_GNU_GETOPT=y
UCLIBC_HAS_STDIO_FUTEXES=y
UCLIBC_HAS_GNU_GETSUBOPT=y

#
# Big and Tall
#
UCLIBC_HAS_REGEX=y
UCLIBC_HAS_REGEX_OLD=y
UCLIBC_HAS_FNMATCH=y
UCLIBC_HAS_FNMATCH_OLD=y
UCLIBC_HAS_WORDEXP=y
UCLIBC_HAS_NFTW=y
UCLIBC_HAS_FTW=y
UCLIBC_HAS_FTS=y
UCLIBC_HAS_GLOB=y
UCLIBC_HAS_GNU_GLOB=y
# UCLIBC_HAS_UTMPX is not set

#
# Library Installation Options
#
RUNTIME_PREFIX="/"
DEVEL_PREFIX="/usr/"
MULTILIB_DIR="lib"
# HARDWIRED_ABSPATH is not set

#
# Security options
#
# UCLIBC_BUILD_PIE is not set
# UCLIBC_HAS_ARC4RANDOM is not set
# UCLIBC_HAS_SSP is not set
UCLIBC_BUILD_RELRO=y
# UCLIBC_BUILD_NOW is not set
UCLIBC_BUILD_NOEXECSTACK=y

#
# Development/debugging options
#
CROSS_COMPILER_PREFIX=""
UCLIBC_EXTRA_CFLAGS=""
# DODEBUG is not set
DOSTRIP=y
# DOASSERTS is not set
# SUPPORT_LD_DEBUG is not set
# SUPPORT_LD_DEBUG_EARLY is not set
# UCLIBC_MALLOC_DEBUGGING is not set
# UCLIBC_HAS_BACKTRACE is not set
WARNINGS="-Wall"
# EXTRA_WARNINGS is not set
# DOMULTI is not set
# UCLIBC_MJN3_ONLY is not set
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20140905/c25f3a82/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list