ldso: include dlfcn.h for RTLD_NODELETE

Building with NPTL enabled and shared library support disabled we hit:
In file included from libpthread/nptl/sysdeps/generic/dl-tls.c:30:0:
./ldso/include/dl-elf.h: In function '__dl_parse_dynamic_info':
./ldso/include/dl-elf.h:173:20: error: 'RTLD_NODELETE' undeclared (first use in this function)
./ldso/include/dl-elf.h:173:20: note: each undeclared identifier is reported only once for each function it appears in
make: *** [libpthread/nptl/sysdeps/generic/dl-tls.os] Error 1

A previous commit (f26c5f6952ce9bf8edec9c1571c47addb1bcc442) touched
on a similar issue, but added the include to the incorrect location.

Reported-by: Christophe Lyon <christophe.lyon@st.com> [arm nommu]
Reported-by: Daniel Beecham <daniel@lunix.se> [static x86_64]
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
libc/stdlib: add mkostemp helpers

Some projects (like udev) are starting to use this.

Imported from glibc.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
include/elf.h: update for ELFOSABI_* changes.

ELFOSABI_GNU replaces ELFOSABI_LINUX, the latter is kept as a compatibility
alias, and ELFOSABI_HURD is removed.  See the table on
<http://www.sco.com/developers/gabi/latest/ch4.eheader.html#osabi> for
reference.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
update ptrace.h to latest from glibc

Update libc/sysdeps/linux/common/sys/ptrace.h to latest from glibc's
sysdeps/unix/sysv/linux/sys/ptrace.h.

This adds definitions for operations:
 - PTRACE_GETREGSET
 - PTRACE_SETREGSET
 - PTRACE_SEIZE
 - PTRACE_INTERRUPT
 - PTRACE_LISTEN

And adds flags:
 - PTRACE_SEIZE_DEVEL

And adds event codes:
 - PTRACE_EVENT_SECCOMP

This is to allow access to the generic interface for accessing
architecture specific regsets using the corresponding NT_* types,
required for new Linux kernel architecture ports.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
sched.h: include stdlib.h for malloc/free

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
include/: ignore more symlinks

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
arm: workaround GCC PR target/53735 with fork()

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
pread/pwrite: fix for !threads

This is done properly via cancel.h on master.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
buildsys: prevent make from searching for .config

Fixes:
make distclean
mkdir /.config
make -C test/API clean
Reading makefile `../../.config' (search path) (don't care) (no ~ expansion)...
make: *** ../../.config: Is a directory.  Stop.

write(1, "Reading makefile `../../.config'"..., 80) = 80
open("../../.config", O_RDONLY)         = -1 ENOENT (No such file or directory)
open("/usr/include/../../.config", O_RDONLY) = 6
fstat(6, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
read(6, 0x7f2fe3bfc000, 4096)           = -1 EISDIR (Is a directory)

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
inet:rpc: fix authnone_marshal in multithreading context

This is a port of glibc's fix by Zack Weinberg as reported
in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=142312,
and discussed in http://sourceware.org/ml/libc-alpha/2002-04/msg00069.html
and following.

Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
MIPS: Convert __syscall_error() callers to use $a0 for argument

Some callers passed the first argument in $v0, while others used $a0.
Change the callers to use $a0 consistently.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
MIPS: Use $a0 instead of $v0 for __syscall_error() argument

$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 <cernekee@gmail.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
ldso: use .arm mode for resolver unconditionally

as per comment in the file.
Fixes runtime with __THUMB_INTERWORK__ enabled.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
make NPTL's getpid behave similar to the common one

make __getpid static
provide getppid alias if needed
remove unneeded libc_hidden_proto

Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
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.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
libc/sysdeps: add __kernel_long and __kernel_ulong

Linux 3.4 added __kernel_long_t and __kernel_ulong_t and various
exported header files were updated to use these new types. Add the
definitions for __kernel_long_t and __kernel_ulong_t to the relevant
kernel_types.h headers.

This change was automated with the following scriptlet

  git grep --name-only 'typedef.*__kernel_old_dev_t' \
    | xargs sed -i '/typedef.*__kernel_old_dev_t/ a\
  typedef long\t\t__kernel_long_t;\
  typedef unsigned long\t__kernel_ulong_t;'

Whitespace in arm, avr32, hppa, sparc was then manually fixed up.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
--
Here's a cleaned up patch which should get the whitespace right. I'm a
bit iffy about the sparc changes they make sense to me but it's not a
platform I have access to.

I can break this up per arch or per maintainer if requested.

 libc/sysdeps/linux/alpha/bits/kernel_types.h      |    2 ++
 libc/sysdeps/linux/arm/bits/kernel_types.h        |    2 ++
 libc/sysdeps/linux/avr32/bits/kernel_types.h      |    2 ++
 libc/sysdeps/linux/bfin/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/c6x/bits/kernel_types.h        |    2 ++
 libc/sysdeps/linux/cris/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/e1/bits/kernel_types.h         |    2 ++
 libc/sysdeps/linux/h8300/bits/kernel_types.h      |    2 ++
 libc/sysdeps/linux/hppa/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/i386/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/ia64/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/m68k/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/microblaze/bits/kernel_types.h |    2 ++
 libc/sysdeps/linux/mips/bits/kernel_types.h       |    4 ++++
 libc/sysdeps/linux/nios2/bits/kernel_types.h      |    2 ++
 libc/sysdeps/linux/powerpc/bits/kernel_types.h    |    4 ++++
 libc/sysdeps/linux/sh/bits/kernel_types.h         |    2 ++
 libc/sysdeps/linux/sh64/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/sparc/bits/kernel_types.h      |    4 ++++
 libc/sysdeps/linux/v850/bits/kernel_types.h       |    2 ++
 libc/sysdeps/linux/x86_64/bits/kernel_types.h     |    2 ++
 libc/sysdeps/linux/xtensa/bits/kernel_types.h     |    2 ++
 22 files changed, 50 insertions(+)
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
microblaze/bits/setjmp.h: Fix stray #endif

Introduced in c53099f7

Signed-off-by: Steve Bennett <steveb@workware.net.au>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
string/microblaze: Fix for little-endian

Fix the asm-optimised memcpy and memmove so they
work for little-endian as well as big-endian.

Testing has shown no issues, but I am not a microblaze
asm expert so YMMV.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
AVR32: declare missing result variable

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
dl: fix dlsym lookups with RTLD_NEXT

The current code for dlsym() when invoked with RTLD_NEXT lookup
searches for the module where it's being called from, and executes the
_dl_find_hash only for the next module in the chain. However, if the
looked symbol is not there, the rest of the modules are not checked.

Generally this is not a problem as symbols are merged for the parent
modules; so this affects only RTLD_NEXT.

This patch adds a loop iterating through all the following modules.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Reviewed-by: Filippo ARCIDIACONO <filippo.arcidiacono@st.com>
Tested-by: Florian Fainelli <florian@openwrt.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>