From 181d410ad00cddd1d6c9f4835e129136b74c5187 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Sat, 14 Feb 2015 15:25:37 +0530 Subject: ARC: Conditionalise certain relocations as provided by TLS tools only uClibc mainline supports NPTL which in turns depends on TLS support in the tools (gcc/binutils), which is yet to be merged in dev branches. However there is some non NPTL code in uClibc, added as part of NPTL effort, which relies on certain relocations only provided by NPTL binutils. As a result building the current upstream even for LT.old breaks. So conditionalize that code on tools, bu tin lack of specific versions, we use NPTL enabling as a sign the tools are equipped to handle those relos. Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/defconfigs/arc/defconfig | 2 +- ldso/ldso/arc/dl-startup.h | 7 +++++++ ldso/ldso/arc/dl-sysdep.h | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/extra/Configs/defconfigs/arc/defconfig b/extra/Configs/defconfigs/arc/defconfig index 840c59f0e..db4308f22 100644 --- a/extra/Configs/defconfigs/arc/defconfig +++ b/extra/Configs/defconfigs/arc/defconfig @@ -6,7 +6,7 @@ KERNEL_HEADERS="%KERNEL_HEADERS%" # LDSO_CACHE_SUPPORT is not set LDSO_RUNPATH=y # LDSO_SAFE_RUNPATH is not set -UCLIBC_HAS_THREADS_NATIVE=y +LINUXTHREADS_OLD=y PTHREADS_DEBUG_SUPPORT=y UCLIBC_HAS_OBSTACK=y UCLIBC_SUSV2_LEGACY=y diff --git a/ldso/ldso/arc/dl-startup.h b/ldso/ldso/arc/dl-startup.h index 8e26ae8d9..ef89b5317 100644 --- a/ldso/ldso/arc/dl-startup.h +++ b/ldso/ldso/arc/dl-startup.h @@ -33,9 +33,16 @@ __asm__( " ; If ldso ran as cmd with executable file nm as arg \n" " ; skip the extra args calc by dl_start() \n" " ld_s r1, [sp] ; orig argc from aux-vec Tbl \n" + +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ " ld r12, [pcl, _dl_skip_args@pcl] \n" " add r2, pcl, _dl_fini@pcl ; finalizer \n" +#else + " add r12, pcl, _dl_skip_args-.+(.&2) \n" + " ld r12, [r12] \n" + " add r2, pcl, _dl_fini-.+(.&2) ; finalizer \n" +#endif " add2 sp, sp, r12 ; discard argv entries from stack\n" " sub_s r1, r1, r12 ; adjusted argc, on stack \n" diff --git a/ldso/ldso/arc/dl-sysdep.h b/ldso/ldso/arc/dl-sysdep.h index d71e16b32..08b3bade8 100644 --- a/ldso/ldso/arc/dl-sysdep.h +++ b/ldso/ldso/arc/dl-sysdep.h @@ -127,6 +127,7 @@ static __always_inline Elf32_Addr elf_machine_dynamic(void) /* Return the run-time load address of the shared object. */ static __always_inline Elf32_Addr elf_machine_load_address(void) { +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ /* To find the loadaddr we subtract the runtime addr of a non-local symbol * say _DYNAMIC from it's build-time addr. * N.B., gotpc loads get optimized by the linker if it finds the symbol @@ -144,6 +145,15 @@ static __always_inline Elf32_Addr elf_machine_load_address(void) "sub %0, %0, %1 ;delta" "\n" : "=&r" (addr), "=r"(tmp) ); +#else + Elf32_Addr addr, tmp; + __asm__ ( + "ld %1, [pcl, _dl_start@gotpc] ;build addr of _dl_start \n" + "add %0, pcl, _dl_start-.+(.&2) ;runtime addr of _dl_start \n" + "sub %0, %0, %1 ;delta \n" + : "=&r" (addr), "=r"(tmp) + ); +#endif return addr; } -- cgit v1.2.3 From c049c4d872af18d668bb98094ce4334e44508fbe Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Sat, 14 Feb 2015 15:25:38 +0530 Subject: ARC: add configuration option for MMU page size ARC CPU may have MMU page size of 4/8(default)/16k. uClibc needs to have page size configured accodring to HW it will be run on. Signed-off-by: Alexey Brodkin Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/Config.arc | 17 +++++++++++++++++ libc/sysdeps/linux/arc/bits/uClibc_page.h | 17 +++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/extra/Configs/Config.arc b/extra/Configs/Config.arc index 40ff114cf..dc32ba4fb 100644 --- a/extra/Configs/Config.arc +++ b/extra/Configs/Config.arc @@ -21,3 +21,20 @@ config CONFIG_ARC_CPU_700 ARCompact ISA based ARC CPU endchoice + +choice + prompt "MMU Page Size" + default CONFIG_ARC_PAGE_SIZE_8K + +config CONFIG_ARC_PAGE_SIZE_8K + bool "8KB" + help + Choose between 4k, 8k (default) or 16k + +config CONFIG_ARC_PAGE_SIZE_16K + bool "16KB" + +config CONFIG_ARC_PAGE_SIZE_4K + bool "4KB" + +endchoice diff --git a/libc/sysdeps/linux/arc/bits/uClibc_page.h b/libc/sysdeps/linux/arc/bits/uClibc_page.h index 26cec54c9..b05c57501 100755 --- a/libc/sysdeps/linux/arc/bits/uClibc_page.h +++ b/libc/sysdeps/linux/arc/bits/uClibc_page.h @@ -9,16 +9,25 @@ /* * ARC700/linux supports 4k, 8k, 16k pages (build time). - * We rely on the kernel exported header (aka uapi headers since 3.8) - * for PAGE_SIZE and friends. This avoids hand-editing here when building - * toolchain. * * Although uClibc determines page size dynamically, from kernel's auxv which * ARC Linux does pass, still the generic code needs a fall back * _dl_pagesize = auxvt[AT_PAGESZ].a_un.a_val ? : PAGE_SIZE * */ -#include + +#include + +#if defined(__CONFIG_ARC_PAGE_SIZE_16K__) +#define PAGE_SHIFT 14 +#elif defined(__CONFIG_ARC_PAGE_SIZE_4K__) +#define PAGE_SHIFT 12 +#else +#define PAGE_SHIFT 13 +#endif + +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE-1)) /* TBD: fix this with runtime value for a PAGE_SIZE agnostic uClibc */ #define MMAP2_PAGE_SHIFT PAGE_SHIFT -- cgit v1.2.3 From c2460b9b7b8c76098dfb1313be4aa4a4a65ff619 Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Sat, 14 Feb 2015 15:25:39 +0530 Subject: ARC defconfigs: enable some items perf: UCLIBC_HAS_GLIBC_CUSTOM_STREAMS elfutils: UCLIBC_HAS_PROGRAM_INVOCATION_NAME Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/defconfigs/arc/defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extra/Configs/defconfigs/arc/defconfig b/extra/Configs/defconfigs/arc/defconfig index db4308f22..2dca4f9b3 100644 --- a/extra/Configs/defconfigs/arc/defconfig +++ b/extra/Configs/defconfigs/arc/defconfig @@ -12,6 +12,7 @@ UCLIBC_HAS_OBSTACK=y UCLIBC_SUSV2_LEGACY=y UCLIBC_SUSV3_LEGACY=y UCLIBC_SUSV4_LEGACY=y +UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y UCLIBC_HAS_OBSOLETE_BSD_SIGNAL=y UCLIBC_SV4_DEPRECATED=y UCLIBC_HAS_RPC=y @@ -19,6 +20,7 @@ UCLIBC_HAS_FULL_RPC=y UCLIBC_HAS_RESOLVER_SUPPORT=y UCLIBC_HAS_LIBRESOLV_STUB=y UCLIBC_HAS_LOCALE=y +UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y UCLIBC_HAS_NFTW=y UCLIBC_HAS_FTW=y RUNTIME_PREFIX="%RUNTIME_PREFIX%" -- cgit v1.2.3 From 7bb51423cccff0b524ba4ddd0679e8c7c1e4a7b1 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Sat, 14 Feb 2015 15:25:40 +0530 Subject: ARC: remove stale TRUNCATE64_HAS_4_ARGS Not relevant anymore since commit e8cc14e59ed3f66b84e, "libc: rename TRUNCATE64_HAS_4_ARGS to SYSCALL_ALIGN_64BIT" Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/bits/uClibc_arch_features.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h b/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h index 9313ee8f2..8af6eca4c 100755 --- a/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h +++ b/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h @@ -17,9 +17,6 @@ /* can your target use syscall6() for mmap ? */ #undef __UCLIBC_MMAP_HAS_6_ARGS__ -/* does your target use syscall4() for truncate64 ? (32bit arches only) */ -#undef __UCLIBC_TRUNCATE64_HAS_4_ARGS__ - /* does your target have a broken create_module() ? */ #undef __UCLIBC_BROKEN_CREATE_MODULE__ -- cgit v1.2.3 From 90b115c036d68c4c581ae974cdbf5352ad7daa84 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Sat, 14 Feb 2015 15:25:41 +0530 Subject: ARC: siagction: opencode memcpy Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/sigaction.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libc/sysdeps/linux/arc/sigaction.c b/libc/sysdeps/linux/arc/sigaction.c index 73c496d2a..a34c7cf4c 100644 --- a/libc/sysdeps/linux/arc/sigaction.c +++ b/libc/sysdeps/linux/arc/sigaction.c @@ -22,8 +22,9 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) { struct sigaction kact; - /* !act means caller only wants to know @oact - * Hence only otherwise, do SA_RESTORER stuff + /* + * SA_RESTORER is only relevant for act != NULL case + * (!act means caller only wants to know @oact) * * For the normal/default cases (user not providing SA_RESTORER) use * a real sigreturn stub to avoid kernel synthesizing one on user stack @@ -31,9 +32,11 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) * update) and costly cache line flushes for code modification */ if (act && !(act->sa_flags & SA_RESTORER)) { - memcpy(&kact, act, sizeof(kact)); kact.sa_restorer = __default_rt_sa_restorer; - kact.sa_flags |= SA_RESTORER; + kact.sa_flags = act->sa_flags | SA_RESTORER; + + kact.sa_handler = act->sa_handler; + kact.sa_mask = act->sa_mask; act = &kact; } -- cgit v1.2.3 From 65bc357213f1c08e339757923740f5d68212cf76 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Sat, 14 Feb 2015 15:25:43 +0530 Subject: ARC: sigaction: fold default sigrestorer into "C" Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/Makefile.arch | 3 +-- libc/sysdeps/linux/arc/sigaction.c | 14 +++++++------- libc/sysdeps/linux/arc/sigrestorer.S | 21 --------------------- 3 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 libc/sysdeps/linux/arc/sigrestorer.S diff --git a/libc/sysdeps/linux/arc/Makefile.arch b/libc/sysdeps/linux/arc/Makefile.arch index 656ea3518..1a52fc9bf 100644 --- a/libc/sysdeps/linux/arc/Makefile.arch +++ b/libc/sysdeps/linux/arc/Makefile.arch @@ -7,5 +7,4 @@ CSRC-y := syscall.c sigaction.c __syscall_error.c cacheflush.c -SSRC-y := sigrestorer.S __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \ - vfork.S clone.S +SSRC-y := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S vfork.S clone.S diff --git a/libc/sysdeps/linux/arc/sigaction.c b/libc/sysdeps/linux/arc/sigaction.c index a34c7cf4c..96c9983b1 100644 --- a/libc/sysdeps/linux/arc/sigaction.c +++ b/libc/sysdeps/linux/arc/sigaction.c @@ -10,8 +10,13 @@ #include #include -extern void __default_rt_sa_restorer(void); -//libc_hidden_proto(__default_rt_sa_restorer); +/* + * Default sigretrun stub if user doesn't specify SA_RESTORER + */ +static void __default_rt_sa_restorer(void) +{ + INTERNAL_SYSCALL_NCS(__NR_rt_sigreturn, , 0); +} #define SA_RESTORER 0x04000000 @@ -25,11 +30,6 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) /* * SA_RESTORER is only relevant for act != NULL case * (!act means caller only wants to know @oact) - * - * For the normal/default cases (user not providing SA_RESTORER) use - * a real sigreturn stub to avoid kernel synthesizing one on user stack - * at runtime, which needs PTE permissions update (hence TLB entry - * update) and costly cache line flushes for code modification */ if (act && !(act->sa_flags & SA_RESTORER)) { kact.sa_restorer = __default_rt_sa_restorer; diff --git a/libc/sysdeps/linux/arc/sigrestorer.S b/libc/sysdeps/linux/arc/sigrestorer.S deleted file mode 100644 index 24531d89d..000000000 --- a/libc/sysdeps/linux/arc/sigrestorer.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com) - * - * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. - */ - -#include -#include - -/* - * Provide a real sigreturn stub to avoid kernel synthesizing one - * on user stack at runtime, which needs PTE permissions update - * (hence TLB entry update) and costly cache line flushes for - * code modification - */ - -ENTRY(__default_rt_sa_restorer) - mov r8, __NR_rt_sigreturn - ARC_TRAP_INSN -END(__default_rt_sa_restorer) -libc_hidden_def(__default_rt_sa_restorer) -- cgit v1.2.3 From f74294bd6768af59e33dc14c6fed41f01d0adc5b Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Sat, 14 Feb 2015 15:25:42 +0530 Subject: ARC: sigaction: inline syscall trap Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/sigaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/sysdeps/linux/arc/sigaction.c b/libc/sysdeps/linux/arc/sigaction.c index 96c9983b1..4a4c9e2d0 100644 --- a/libc/sysdeps/linux/arc/sigaction.c +++ b/libc/sysdeps/linux/arc/sigaction.c @@ -41,7 +41,8 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact) act = &kact; } - return __syscall_rt_sigaction(sig, act, oact, sizeof(act->sa_mask)); + return INLINE_SYSCALL(rt_sigaction, 4, + sig, act, oact, sizeof(act->sa_mask)); } #ifndef LIBC_SIGACTION -- cgit v1.2.3 From 31b0af2da8120e2b3f176d955eeca034e434b1b7 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Sat, 14 Feb 2015 15:25:44 +0530 Subject: signal.h: elide memset from sigemptyset Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- include/signal.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/signal.h b/include/signal.h index be24cf366..38baaccfb 100644 --- a/include/signal.h +++ b/include/signal.h @@ -493,10 +493,7 @@ extern int __libc_current_sigrtmax (void) __THROW; #ifdef _LIBC extern sigset_t _sigintr attribute_hidden; -/* simplified version without parameter checking */ # include -# undef __sigemptyset -# define __sigemptyset(ss) (memset(ss, '\0', sizeof(sigset_t)), 0) #endif #endif /* signal.h */ -- cgit v1.2.3 From 9fc6da20daeac3f06116630764c36fc4943b1f3a Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Thu, 20 Feb 2014 00:30:18 -0800 Subject: Add eventfd_read() and eventfd_write() Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/Makefile.in | 2 ++ libc/sysdeps/linux/common/eventfd.c | 2 +- libc/sysdeps/linux/common/eventfd_read.c | 27 +++++++++++++++++++++++++++ libc/sysdeps/linux/common/eventfd_write.c | 28 ++++++++++++++++++++++++++++ libc/sysdeps/linux/common/sys/eventfd.h | 6 +----- libc/sysdeps/linux/sparc/bits/eventfd.h | 2 +- 6 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 libc/sysdeps/linux/common/eventfd_read.c create mode 100644 libc/sysdeps/linux/common/eventfd_write.c diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index a175ab64c..9d41771e2 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -25,6 +25,8 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \ capset.c \ dup3.c \ eventfd.c \ + eventfd_read.c \ + eventfd_write.c \ inotify.c \ ioperm.c \ iopl.c \ diff --git a/libc/sysdeps/linux/common/eventfd.c b/libc/sysdeps/linux/common/eventfd.c index 96597ab33..500b0c002 100644 --- a/libc/sysdeps/linux/common/eventfd.c +++ b/libc/sysdeps/linux/common/eventfd.c @@ -15,7 +15,7 @@ * eventfd() */ #if defined __NR_eventfd || defined __NR_eventfd2 -int eventfd (int count, int flags) +int eventfd (unsigned int count, int flags) { #if defined __NR_eventfd2 return INLINE_SYSCALL (eventfd2, 2, count, flags); diff --git a/libc/sysdeps/linux/common/eventfd_read.c b/libc/sysdeps/linux/common/eventfd_read.c new file mode 100644 index 000000000..75f2aaa11 --- /dev/null +++ b/libc/sysdeps/linux/common/eventfd_read.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2007-2014 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 + . */ + +#include +#include +#include + + +int +eventfd_read (int fd, eventfd_t *value) +{ + return read (fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0; +} diff --git a/libc/sysdeps/linux/common/eventfd_write.c b/libc/sysdeps/linux/common/eventfd_write.c new file mode 100644 index 000000000..e1509cf5c --- /dev/null +++ b/libc/sysdeps/linux/common/eventfd_write.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2007-2014 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 + . */ + +#include +#include +#include + + +int +eventfd_write (int fd, eventfd_t value) +{ + return write (fd, &value, + sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0; +} diff --git a/libc/sysdeps/linux/common/sys/eventfd.h b/libc/sysdeps/linux/common/sys/eventfd.h index 1bf785f32..a47b5fecf 100644 --- a/libc/sysdeps/linux/common/sys/eventfd.h +++ b/libc/sysdeps/linux/common/sys/eventfd.h @@ -31,9 +31,7 @@ __BEGIN_DECLS /* Return file descriptor for generic event channel. Set initial value to COUNT. */ -extern int eventfd (int __count, int __flags) __THROW; - -#if 0 /* not (yet) implemented in uClibc */ +extern int eventfd (unsigned int __count, int __flags) __THROW; /* Read event counter and possibly wait for events. */ extern int eventfd_read (int __fd, eventfd_t *__value); @@ -41,8 +39,6 @@ extern int eventfd_read (int __fd, eventfd_t *__value); /* Increment event counter. */ extern int eventfd_write (int __fd, eventfd_t __value); -#endif - __END_DECLS #endif /* sys/eventfd.h */ diff --git a/libc/sysdeps/linux/sparc/bits/eventfd.h b/libc/sysdeps/linux/sparc/bits/eventfd.h index bed9f093b..e348cc6fb 100644 --- a/libc/sysdeps/linux/sparc/bits/eventfd.h +++ b/libc/sysdeps/linux/sparc/bits/eventfd.h @@ -22,7 +22,7 @@ /* Flags for eventfd. */ enum { - EFD_SEMAPHORE = 1, + EFD_SEMAPHORE = 0x000001, #define EFD_SEMAPHORE EFD_SEMAPHORE EFD_CLOEXEC = 0x400000, #define EFD_CLOEXEC EFD_CLOEXEC -- cgit v1.2.3 From 5d5c77daae197b00f89ad1517ffb5a7a01a78cff Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Feb 2015 23:41:47 +0100 Subject: libc: add setns() Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/Makefile.in | 1 + libc/sysdeps/linux/common/bits/sched.h | 53 ++++++++++++++++++++++------------ libc/sysdeps/linux/common/setns.c | 15 ++++++++++ libc/sysdeps/linux/common/stubs.c | 4 +++ 4 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 libc/sysdeps/linux/common/setns.c diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index 9d41771e2..8ee956b6b 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -45,6 +45,7 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \ sendfile.c \ setfsgid.c \ setfsuid.c \ + setns.c \ setresgid.c \ setresuid.c \ signalfd.c \ diff --git a/libc/sysdeps/linux/common/bits/sched.h b/libc/sysdeps/linux/common/bits/sched.h index a5eb6ee55..9d05314f5 100644 --- a/libc/sysdeps/linux/common/bits/sched.h +++ b/libc/sysdeps/linux/common/bits/sched.h @@ -1,7 +1,6 @@ /* Definitions of constants and data structure for POSIX 1003.1b-1993 scheduling interface. - Copyright (C) 1996-1999,2001-2003,2005,2006,2007,2008 - Free Software Foundation, Inc. + Copyright (C) 1996-2015 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 @@ -26,14 +25,17 @@ /* Scheduling algorithms. */ -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 +#define SCHED_OTHER 0 +#define SCHED_FIFO 1 +#define SCHED_RR 2 #ifdef __USE_GNU -# define SCHED_BATCH 3 +# define SCHED_BATCH 3 +# define SCHED_IDLE 5 + +# define SCHED_RESET_ON_FORK 0x40000000 #endif -#ifdef __USE_MISC +#ifdef __USE_GNU /* Cloning flags. */ # define CSIGNAL 0x000000ff /* Signal mask to be sent at exit. */ # define CLONE_VM 0x00000100 /* Set if VM shared between processes. */ @@ -58,7 +60,6 @@ force CLONE_PTRACE on this clone. */ # define CLONE_CHILD_SETTID 0x01000000 /* Store TID in userlevel buffer in the child. */ -# define CLONE_STOPPED 0x02000000 /* Start in stopped state. */ # define CLONE_NEWUTS 0x04000000 /* New utsname group. */ # define CLONE_NEWIPC 0x08000000 /* New ipcs. */ # define CLONE_NEWUSER 0x10000000 /* New user namespace. */ @@ -75,7 +76,7 @@ struct sched_param __BEGIN_DECLS -#ifdef __USE_MISC +#ifdef __USE_GNU /* Clone current process. */ extern int clone (int (*__fn) (void *__arg), void *__child_stack, int __flags, void *__arg, ...) __THROW; @@ -85,8 +86,12 @@ extern int unshare (int __flags) __THROW; /* Get index of currently used CPU. */ extern int sched_getcpu (void) __THROW; + +/* Switch process to namespace of type NSTYPE indicated by FD. */ +extern int setns (int __fd, int __nstype) __THROW; #endif + __END_DECLS #endif /* need schedparam */ @@ -124,7 +129,11 @@ typedef struct } cpu_set_t; /* Access functions for CPU masks. */ -# define __CPU_ZERO_S(setsize, cpusetp) \ +# if __GNUC_PREREQ (2, 91) +# define __CPU_ZERO_S(setsize, cpusetp) \ + do __builtin_memset (cpusetp, '\0', setsize); while (0) +# else +# define __CPU_ZERO_S(setsize, cpusetp) \ do { \ size_t __i; \ size_t __imax = (setsize) / sizeof (__cpu_mask); \ @@ -132,47 +141,53 @@ typedef struct for (__i = 0; __i < __imax; ++__i) \ __bits[__i] = 0; \ } while (0) +# endif # define __CPU_SET_S(cpu, setsize, cpusetp) \ (__extension__ \ ({ size_t __cpu = (cpu); \ - __cpu < 8 * (setsize) \ + __cpu / 8 < (setsize) \ ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \ |= __CPUMASK (__cpu)) \ : 0; })) # define __CPU_CLR_S(cpu, setsize, cpusetp) \ (__extension__ \ ({ size_t __cpu = (cpu); \ - __cpu < 8 * (setsize) \ + __cpu / 8 < (setsize) \ ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \ &= ~__CPUMASK (__cpu)) \ : 0; })) # define __CPU_ISSET_S(cpu, setsize, cpusetp) \ (__extension__ \ ({ size_t __cpu = (cpu); \ - __cpu < 8 * (setsize) \ - ? ((((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \ + __cpu / 8 < (setsize) \ + ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \ & __CPUMASK (__cpu))) != 0 \ : 0; })) # define __CPU_COUNT_S(setsize, cpusetp) \ __sched_cpucount (setsize, cpusetp) -# define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \ +# if __GNUC_PREREQ (2, 91) +# define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \ + (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0) +# else +# define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \ (__extension__ \ - ({ __cpu_mask *__arr1 = (cpusetp1)->__bits; \ - __cpu_mask *__arr2 = (cpusetp2)->__bits; \ + ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits; \ + const __cpu_mask *__arr2 = (cpusetp2)->__bits; \ size_t __imax = (setsize) / sizeof (__cpu_mask); \ size_t __i; \ for (__i = 0; __i < __imax; ++__i) \ if (__arr1[__i] != __arr2[__i]) \ break; \ __i == __imax; })) +# endif # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \ (__extension__ \ ({ cpu_set_t *__dest = (destset); \ - __cpu_mask *__arr1 = (srcset1)->__bits; \ - __cpu_mask *__arr2 = (srcset2)->__bits; \ + const __cpu_mask *__arr1 = (srcset1)->__bits; \ + const __cpu_mask *__arr2 = (srcset2)->__bits; \ size_t __imax = (setsize) / sizeof (__cpu_mask); \ size_t __i; \ for (__i = 0; __i < __imax; ++__i) \ diff --git a/libc/sysdeps/linux/common/setns.c b/libc/sysdeps/linux/common/setns.c new file mode 100644 index 000000000..a697720b9 --- /dev/null +++ b/libc/sysdeps/linux/common/setns.c @@ -0,0 +1,15 @@ +/* vi: set sw=4 ts=4: */ +/* + * setns() for uClibc + * + * Copyright (C) 2015 Bernhard Reutner-Fischer + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include + +#ifdef __NR_setns +_syscall2(int, setns, int, fd, int, nstype) +#endif diff --git a/libc/sysdeps/linux/common/stubs.c b/libc/sysdeps/linux/common/stubs.c index 57c4664aa..2c50307aa 100644 --- a/libc/sysdeps/linux/common/stubs.c +++ b/libc/sysdeps/linux/common/stubs.c @@ -346,6 +346,10 @@ make_stub(setfsgid) make_stub(setfsuid) #endif +#if !defined __NR_setns && defined __UCLIBC_LINUX_SPECIFIC__ +make_stub(setns) +#endif + #if !defined __NR_setresgid32 && !defined __NR_setresgid && defined __UCLIBC_LINUX_SPECIFIC__ make_stub(setresgid) #endif -- cgit v1.2.3 From 89b63496e88c31c2714e42656212078388718b78 Mon Sep 17 00:00:00 2001 From: Anton Kolesov Date: Wed, 4 Feb 2015 15:34:51 +0300 Subject: ARC: Add GNU glob to ARC defconfigs GNU glob is required by make. Signed-off-by: Anton Kolesov Cc: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/defconfigs/arc/defconfig | 1 + extra/Configs/defconfigs/arc/tb10x_defconfig | 1 + 2 files changed, 2 insertions(+) diff --git a/extra/Configs/defconfigs/arc/defconfig b/extra/Configs/defconfigs/arc/defconfig index 2dca4f9b3..490bc2267 100644 --- a/extra/Configs/defconfigs/arc/defconfig +++ b/extra/Configs/defconfigs/arc/defconfig @@ -23,6 +23,7 @@ UCLIBC_HAS_LOCALE=y UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y UCLIBC_HAS_NFTW=y UCLIBC_HAS_FTW=y +UCLIBC_HAS_GNU_GLOB=y RUNTIME_PREFIX="%RUNTIME_PREFIX%" DEVEL_PREFIX="%DEVEL_PREFIX%" CROSS_COMPILER_PREFIX="arc-linux-uclibc-" diff --git a/extra/Configs/defconfigs/arc/tb10x_defconfig b/extra/Configs/defconfigs/arc/tb10x_defconfig index 60065f97d..405a4eac7 100644 --- a/extra/Configs/defconfigs/arc/tb10x_defconfig +++ b/extra/Configs/defconfigs/arc/tb10x_defconfig @@ -30,6 +30,7 @@ UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y UCLIBC_HAS_PRINTF_M_SPEC=y UCLIBC_HAS_NFTW=y UCLIBC_HAS_FTW=y +UCLIBC_HAS_GNU_GLOB=y RUNTIME_PREFIX="%RUNTIME_PREFIX%" DEVEL_PREFIX="%DEVEL_PREFIX%" CROSS_COMPILER_PREFIX="arc-linux-uclibc-" -- cgit v1.2.3 From afab56958f1cbb47b831ee3ebff231dfbae74af2 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 19 Feb 2015 19:13:59 +0530 Subject: ARCv2 ISA support This is next gen Instruction Set Architecture from Synopsys and basis for the ARC HS family of processors. http://www.synopsys.com/dw/ipdir.php?ds=arc-hs38-processor&elq_mid=5732&elq_cid=458802 http://www.synopsys.com/IP/ProcessorIP/ARCProcessors/arc-hs/Pages/default.aspx Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- Rules.mak | 1 + extra/Configs/Config.arc | 6 ++++ extra/Configs/Config.in | 1 + extra/Configs/defconfigs/arc/arcv2_defconfig | 33 ++++++++++++++++++++++ include/elf.h | 1 + ldso/ldso/arc/dl-sysdep.h | 15 ++++++++-- ldso/ldso/arc/elfinterp.c | 4 +++ libc/string/arc/memcmp.S | 29 +++++++++++++++++++ libc/sysdeps/linux/arc/bits/syscalls.h | 10 ++++++- libc/sysdeps/linux/arc/bits/uClibc_arch_features.h | 7 +++++ 10 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 extra/Configs/defconfigs/arc/arcv2_defconfig diff --git a/Rules.mak b/Rules.mak index 9f5fe8564..ea254f1a2 100644 --- a/Rules.mak +++ b/Rules.mak @@ -543,6 +543,7 @@ endif ifeq ($(TARGET_ARCH),arc) CPU_CFLAGS-y += -mlock -mswape CPU_CFLAGS-$(CONFIG_ARC_CPU_700) += -mA7 + CPU_CFLAGS-$(CONFIG_ARC_CPU_HS) += -mcpu=archs CPU_LDFLAGS-y += $(CPU_CFLAGS) -marclinux endif diff --git a/extra/Configs/Config.arc b/extra/Configs/Config.arc index dc32ba4fb..0c0bc71ce 100644 --- a/extra/Configs/Config.arc +++ b/extra/Configs/Config.arc @@ -20,6 +20,12 @@ config CONFIG_ARC_CPU_700 help ARCompact ISA based ARC CPU +config CONFIG_ARC_CPU_HS + bool "ARC-HS" + select ARCH_HAS_MMU + help + Next Generation ARCv2 ISA based Processors + endchoice choice diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 8e603b2ad..84659650b 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -255,6 +255,7 @@ config TARGET_SUBARCH default "i486" if CONFIG_486 default "i586" if CONFIG_586 default "i686" if CONFIG_686 + default "arcv2" if CONFIG_ARC_CPU_HS default "" source "extra/Configs/Config.in.arch" diff --git a/extra/Configs/defconfigs/arc/arcv2_defconfig b/extra/Configs/defconfigs/arc/arcv2_defconfig new file mode 100644 index 000000000..d3a7dc7b2 --- /dev/null +++ b/extra/Configs/defconfigs/arc/arcv2_defconfig @@ -0,0 +1,33 @@ +CONFIG_ARC_CPU_HS=y +ARCH_WANTS_LITTLE_ENDIAN=y +# UCLIBC_HAS_FPU is not set +DO_C99_MATH=y +KERNEL_HEADERS="%KERNEL_HEADERS%" +# DOPIC is not set +# LDSO_CACHE_SUPPORT is not set +LDSO_RUNPATH=y +# LDSO_SAFE_RUNPATH is not set +LINUXTHREADS_OLD=y +PTHREADS_DEBUG_SUPPORT=y +UCLIBC_HAS_OBSTACK=y +UCLIBC_SUSV2_LEGACY=y +UCLIBC_SUSV3_LEGACY=y +UCLIBC_SUSV4_LEGACY=y +UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y +UCLIBC_HAS_OBSOLETE_BSD_SIGNAL=y +UCLIBC_SV4_DEPRECATED=y +UCLIBC_HAS_RPC=y +UCLIBC_HAS_FULL_RPC=y +UCLIBC_HAS_RESOLVER_SUPPORT=y +UCLIBC_HAS_LIBRESOLV_STUB=y +UCLIBC_HAS_LOCALE=y +UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y +UCLIBC_HAS_NFTW=y +UCLIBC_HAS_FTW=y +UCLIBC_HAS_GNU_GLOB=y +RUNTIME_PREFIX="%RUNTIME_PREFIX%" +DEVEL_PREFIX="%DEVEL_PREFIX%" +CROSS_COMPILER_PREFIX="arc-linux-uclibc-" +# DOSTRIP is not set +SUPPORT_LD_DEBUG=y +UCLIBC_HAS_BACKTRACE=y diff --git a/include/elf.h b/include/elf.h index 1979209cd..facf09cd5 100644 --- a/include/elf.h +++ b/include/elf.h @@ -378,6 +378,7 @@ typedef struct /* Xilinx Microblaze (official) */ #define EM_MICROBLAZE 189 +#define EM_ARCV2 195 /* ARCv2 Cores */ /* Legal values for e_version (version). */ diff --git a/ldso/ldso/arc/dl-sysdep.h b/ldso/ldso/arc/dl-sysdep.h index 08b3bade8..ca62a2c04 100644 --- a/ldso/ldso/arc/dl-sysdep.h +++ b/ldso/ldso/arc/dl-sysdep.h @@ -69,11 +69,16 @@ do { \ } while(0) /* Here we define the magic numbers that this dynamic loader should accept */ +#ifdef __A7__ #define MAGIC1 EM_ARCOMPACT +#define ELF_TARGET "ARCompact" /* For error messages */ +#elif defined(__HS__) +#define MAGIC1 EM_ARCV2 +#define ELF_TARGET "ARCv2" /* For error messages */ +#endif + #undef MAGIC2 -/* Used for error messages */ -#define ELF_TARGET "ARC" struct elf_resolve; extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, @@ -81,6 +86,8 @@ extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, extern unsigned __udivmodsi4(unsigned, unsigned) attribute_hidden; +#ifdef __A7__ +/* using "C" causes an indirection via __umodsi3 -> __udivmodsi4 */ #define do_rem(result, n, base) ((result) = \ \ __builtin_constant_p (base) ? (n) % (unsigned) (base) : \ @@ -95,6 +102,10 @@ extern unsigned __udivmodsi4(unsigned, unsigned) attribute_hidden; r1; \ }) \ ) +#elif defined(__HS__) +/* ARCv2 has hardware assisted divide/mod */ +#define do_rem(result, n, base) ((result) = (n) % (unsigned) (base)) +#endif /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or TLS variable so PLT entries should not be allowed to define the value. diff --git a/ldso/ldso/arc/elfinterp.c b/ldso/ldso/arc/elfinterp.c index d26c94705..7c31d3ac7 100644 --- a/ldso/ldso/arc/elfinterp.c +++ b/ldso/ldso/arc/elfinterp.c @@ -11,7 +11,11 @@ */ #include "ldso.h" +#ifdef __A7__ #define ARC_PLT_SIZE 12 +#else +#define ARC_PLT_SIZE 16 +#endif unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, unsigned int plt_pc) diff --git a/libc/string/arc/memcmp.S b/libc/string/arc/memcmp.S index 4c0e39143..a60757e7a 100644 --- a/libc/string/arc/memcmp.S +++ b/libc/string/arc/memcmp.S @@ -24,14 +24,32 @@ ENTRY(memcmp) ld r4,[r0,0] ld r5,[r1,0] lsr.f lp_count,r3,3 +#ifdef __HS__ + /* In ARCv2 a branch can't be the last instruction in a zero overhead + * loop. + * So we move the branch to the start of the loop, duplicate it + * after the end, and set up r12 so that the branch isn't taken + * initially. + */ + mov_s r12,WORD2 + lpne .Loop_end + brne WORD2,r12,.Lodd + ld WORD2,[r0,4] +#else lpne .Loop_end ld_s WORD2,[r0,4] +#endif ld_s r12,[r1,4] brne r4,r5,.Leven ld.a r4,[r0,8] ld.a r5,[r1,8] +#ifdef __HS__ +.Loop_end: + brne WORD2,r12,.Lodd +#else brne WORD2,r12,.Lodd .Loop_end: +#endif asl_s SHIFT,SHIFT,3 bhs_s .Last_cmp brne r4,r5,.Leven @@ -99,14 +117,25 @@ ENTRY(memcmp) ldb r4,[r0,0] ldb r5,[r1,0] lsr.f lp_count,r3 +#ifdef __HS__ + mov r12,r3 lpne .Lbyte_end + brne r3,r12,.Lbyte_odd +#else + lpne .Lbyte_end +#endif ldb_s r3,[r0,1] ldb r12,[r1,1] brne r4,r5,.Lbyte_even ldb.a r4,[r0,2] ldb.a r5,[r1,2] +#ifdef __HS__ +.Lbyte_end: + brne r3,r12,.Lbyte_odd +#else brne r3,r12,.Lbyte_odd .Lbyte_end: +#endif bcc .Lbyte_even brne r4,r5,.Lbyte_even ldb_s r3,[r0,1] diff --git a/libc/sysdeps/linux/arc/bits/syscalls.h b/libc/sysdeps/linux/arc/bits/syscalls.h index 5da6aadb3..248ef7844 100644 --- a/libc/sysdeps/linux/arc/bits/syscalls.h +++ b/libc/sysdeps/linux/arc/bits/syscalls.h @@ -98,7 +98,11 @@ extern int __syscall_error (int); * for syscall itself. *-------------------------------------------------------------------------*/ -#define ARC_TRAP_INSN "trap0 \n\t" +#ifdef __A7__ +#define ARC_TRAP_INSN "trap0 \n\t" +#elif defined(__HS__) +#define ARC_TRAP_INSN "trap_s 0 \n\t" +#endif #define INTERNAL_SYSCALL_NCS(nm, err, nr_args, args...) \ ({ \ @@ -176,7 +180,11 @@ extern int __syscall_error (int); #else +#ifdef __A7__ #define ARC_TRAP_INSN trap0 +#elif defined(__HS__) +#define ARC_TRAP_INSN trap_s 0 +#endif #endif /* __ASSEMBLER__ */ diff --git a/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h b/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h index 8af6eca4c..451575586 100755 --- a/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h +++ b/libc/sysdeps/linux/arc/bits/uClibc_arch_features.h @@ -47,4 +47,11 @@ /* The default ';' is a comment on ARC. */ #define __UCLIBC_ASM_LINE_SEP__ ` +/* does your target align 64bit values in register pairs ? (32bit arches only) */ +#if defined(__A7__) +#undef __UCLIBC_SYSCALL_ALIGN_64BIT__ +#else +#define __UCLIBC_SYSCALL_ALIGN_64BIT__ +#endif + #endif /* _BITS_UCLIBC_ARCH_FEATURES_H */ -- cgit v1.2.3 From df273fedf4fef25983ef6ec7e42b03d54f44960d Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 19 Feb 2015 19:14:00 +0530 Subject: ARCv2: optimised string routines Signed-off-by: Claudiu Zissulescu Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/string/arc/arcv2/memcpy.S | 236 +++++++++++++++++++++++++++++++++++++++++ libc/string/arc/arcv2/memset.S | 85 +++++++++++++++ libc/string/arc/arcv2/strcmp.S | 83 +++++++++++++++ 3 files changed, 404 insertions(+) create mode 100644 libc/string/arc/arcv2/memcpy.S create mode 100644 libc/string/arc/arcv2/memset.S create mode 100644 libc/string/arc/arcv2/strcmp.S diff --git a/libc/string/arc/arcv2/memcpy.S b/libc/string/arc/arcv2/memcpy.S new file mode 100644 index 000000000..7573daf51 --- /dev/null +++ b/libc/string/arc/arcv2/memcpy.S @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include + +#ifdef __LITTLE_ENDIAN__ +# define SHIFT_1(RX,RY,IMM) asl RX, RY, IMM ; << +# define SHIFT_2(RX,RY,IMM) lsr RX, RY, IMM ; >> +# define MERGE_1(RX,RY,IMM) asl RX, RY, IMM +# define MERGE_2(RX,RY,IMM) +# define EXTRACT_1(RX,RY,IMM) and RX, RY, 0xFFFF +# define EXTRACT_2(RX,RY,IMM) lsr RX, RY, IMM +#else +# define SHIFT_1(RX,RY,IMM) lsr RX, RY, IMM ; >> +# define SHIFT_2(RX,RY,IMM) asl RX, RY, IMM ; << +# define MERGE_1(RX,RY,IMM) asl RX, RY, IMM ; << +# define MERGE_2(RX,RY,IMM) asl RX, RY, IMM ; << +# define EXTRACT_1(RX,RY,IMM) lsr RX, RY, IMM +# define EXTRACT_2(RX,RY,IMM) lsr RX, RY, 0x08 +#endif + +#ifdef __LL64__ +# define PREFETCH_READ(RX) prefetch [RX, 56] +# define PREFETCH_WRITE(RX) prefetchw [RX, 64] +# define LOADX(DST,RX) ldd.ab DST, [RX, 8] +# define STOREX(SRC,RX) std.ab SRC, [RX, 8] +# define ZOLSHFT 5 +# define ZOLAND 0x1F +#else +# define PREFETCH_READ(RX) prefetch [RX, 28] +# define PREFETCH_WRITE(RX) prefetchw [RX, 32] +# define LOADX(DST,RX) ld.ab DST, [RX, 4] +# define STOREX(SRC,RX) st.ab SRC, [RX, 4] +# define ZOLSHFT 4 +# define ZOLAND 0xF +#endif + +ENTRY(memcpy) + prefetch [r1] ; Prefetch the read location + prefetchw [r0] ; Prefetch the write location + mov.f 0, r2 +;;; if size is zero + jz.d [blink] + mov r3, r0 ; don't clobber ret val + +;;; if size <= 8 + cmp r2, 8 + bls.d @.Lsmallchunk + mov.f lp_count, r2 + + and.f r4, r0, 0x03 + rsub lp_count, r4, 4 + lpnz @.Laligndestination + ;; LOOP BEGIN + ldb.ab r5, [r1,1] + sub r2, r2, 1 + stb.ab r5, [r3,1] +.Laligndestination: + +;;; Check the alignment of the source + and.f r4, r1, 0x03 + bnz.d @.Lsourceunaligned + +;;; CASE 0: Both source and destination are 32bit aligned +;;; Convert len to Dwords, unfold x4 + lsr.f lp_count, r2, ZOLSHFT + lpnz @.Lcopy32_64bytes + ;; LOOP START + LOADX (r6, r1) + PREFETCH_READ (r1) + PREFETCH_WRITE (r3) + LOADX (r8, r1) + LOADX (r10, r1) + LOADX (r4, r1) + STOREX (r6, r3) + STOREX (r8, r3) + STOREX (r10, r3) + STOREX (r4, r3) +.Lcopy32_64bytes: + + and.f lp_count, r2, ZOLAND ;Last remaining 31 bytes +.Lsmallchunk: + lpnz @.Lcopyremainingbytes + ;; LOOP START + ldb.ab r5, [r1,1] + stb.ab r5, [r3,1] +.Lcopyremainingbytes: + + j [blink] +;;; END CASE 0 + +.Lsourceunaligned: + cmp r4, 2 + beq.d @.LunalignedOffby2 + sub r2, r2, 1 + + bhi.d @.LunalignedOffby3 + ldb.ab r5, [r1, 1] + +;;; CASE 1: The source is unaligned, off by 1 + ;; Hence I need to read 1 byte for a 16bit alignment + ;; and 2bytes to reach 32bit alignment + ldh.ab r6, [r1, 2] + sub r2, r2, 2 + ;; Convert to words, unfold x2 + lsr.f lp_count, r2, 3 + MERGE_1 (r6, r6, 8) + MERGE_2 (r5, r5, 24) + or r5, r5, r6 + + ;; Both src and dst are aligned + lpnz @.Lcopy8bytes_1 + ;; LOOP START + ld.ab r6, [r1, 4] + prefetch [r1, 28] ;Prefetch the next read location + ld.ab r8, [r1,4] + prefetchw [r3, 32] ;Prefetch the next write location + + SHIFT_1 (r7, r6, 24) + or r7, r7, r5 + SHIFT_2 (r5, r6, 8) + + SHIFT_1 (r9, r8, 24) + or r9, r9, r5 + SHIFT_2 (r5, r8, 8) + + st.ab r7, [r3, 4] + st.ab r9, [r3, 4] +.Lcopy8bytes_1: + + ;; Write back the remaining 16bits + EXTRACT_1 (r6, r5, 16) + sth.ab r6, [r3, 2] + ;; Write back the remaining 8bits + EXTRACT_2 (r5, r5, 16) + stb.ab r5, [r3, 1] + + and.f lp_count, r2, 0x07 ;Last 8bytes + lpnz @.Lcopybytewise_1 + ;; LOOP START + ldb.ab r6, [r1,1] + stb.ab r6, [r3,1] +.Lcopybytewise_1: + j [blink] + +.LunalignedOffby2: +;;; CASE 2: The source is unaligned, off by 2 + ldh.ab r5, [r1, 2] + sub r2, r2, 1 + + ;; Both src and dst are aligned + ;; Convert to words, unfold x2 + lsr.f lp_count, r2, 3 +#ifdef __BIG_ENDIAN__ + asl.nz r5, r5, 16 +#endif + lpnz @.Lcopy8bytes_2 + ;; LOOP START + ld.ab r6, [r1, 4] + prefetch [r1, 28] ;Prefetch the next read location + ld.ab r8, [r1,4] + prefetchw [r3, 32] ;Prefetch the next write location + + SHIFT_1 (r7, r6, 16) + or r7, r7, r5 + SHIFT_2 (r5, r6, 16) + + SHIFT_1 (r9, r8, 16) + or r9, r9, r5 + SHIFT_2 (r5, r8, 16) + + st.ab r7, [r3, 4] + st.ab r9, [r3, 4] +.Lcopy8bytes_2: + +#ifdef __BIG_ENDIAN__ + lsr.nz r5, r5, 16 +#endif + sth.ab r5, [r3, 2] + + and.f lp_count, r2, 0x07 ;Last 8bytes + lpnz @.Lcopybytewise_2 + ;; LOOP START + ldb.ab r6, [r1,1] + stb.ab r6, [r3,1] +.Lcopybytewise_2: + j [blink] + +.LunalignedOffby3: +;;; CASE 3: The source is unaligned, off by 3 +;;; Hence, I need to read 1byte for achieve the 32bit alignment + + ;; Both src and dst are aligned + ;; Convert to words, unfold x2 + lsr.f lp_count, r2, 3 +#ifdef __BIG_ENDIAN__ + asl.ne r5, r5, 24 +#endif + lpnz @.Lcopy8bytes_3 + ;; LOOP START + ld.ab r6, [r1, 4] + prefetch [r1, 28] ;Prefetch the next read location + ld.ab r8, [r1,4] + prefetchw [r3, 32] ;Prefetch the next write location + + SHIFT_1 (r7, r6, 8) + or r7, r7, r5 + SHIFT_2 (r5, r6, 24) + + SHIFT_1 (r9, r8, 8) + or r9, r9, r5 + SHIFT_2 (r5, r8, 24) + + st.ab r7, [r3, 4] + st.ab r9, [r3, 4] +.Lcopy8bytes_3: + +#ifdef __BIG_ENDIAN__ + lsr.nz r5, r5, 24 +#endif + stb.ab r5, [r3, 1] + + and.f lp_count, r2, 0x07 ;Last 8bytes + lpnz @.Lcopybytewise_3 + ;; LOOP START + ldb.ab r6, [r1,1] + stb.ab r6, [r3,1] +.Lcopybytewise_3: + j [blink] + +END(memcpy) +libc_hidden_def(memcpy) diff --git a/libc/string/arc/arcv2/memset.S b/libc/string/arc/arcv2/memset.S new file mode 100644 index 000000000..d076ad1cd --- /dev/null +++ b/libc/string/arc/arcv2/memset.S @@ -0,0 +1,85 @@ + +/* + * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include + +#ifdef DONT_USE_PREALLOC +#define PREWRITE(A,B) prefetchw [(A),(B)] +#else +#define PREWRITE(A,B) prealloc [(A),(B)] +#endif + +ENTRY(memset) + prefetchw [r0] ; Prefetch the write location + mov.f 0, r2 +;;; if size is zero + jz.d [blink] + mov r3, r0 ; don't clobber ret val + +;;; if length < 8 + brls.d.nt r2, 8, .Lsmallchunk + mov.f lp_count,r2 + + and.f r4, r0, 0x03 + rsub lp_count, r4, 4 + lpnz @.Laligndestination + ;; LOOP BEGIN + stb.ab r1, [r3,1] + sub r2, r2, 1 +.Laligndestination: + +;;; Destination is aligned + and r1, r1, 0xFF + asl r4, r1, 8 + or r4, r4, r1 + asl r5, r4, 16 + or r5, r5, r4 + mov r4, r5 + + sub3 lp_count, r2, 8 + cmp r2, 64 + bmsk.hi r2, r2, 5 + mov.ls lp_count, 0 + add3.hi r2, r2, 8 + +;;; Convert len to Dwords, unfold x8 + lsr.f lp_count, lp_count, 6 + lpnz @.Lset64bytes + ;; LOOP START + PREWRITE(r3, 64) ;Prefetch the next write location + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] +.Lset64bytes: + + lsr.f lp_count, r2, 5 ;Last remaining max 124 bytes + lpnz .Lset32bytes + ;; LOOP START + prefetchw [r3, 32] ;Prefetch the next write location + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] + std.ab r4, [r3, 8] +.Lset32bytes: + + and.f lp_count, r2, 0x1F ;Last remaining 31 bytes +.Lsmallchunk: + lpnz .Lcopy3bytes + ;; LOOP START + stb.ab r1, [r3, 1] +.Lcopy3bytes: + + j [blink] + +END(memset) +libc_hidden_def(memset) diff --git a/libc/string/arc/arcv2/strcmp.S b/libc/string/arc/arcv2/strcmp.S new file mode 100644 index 000000000..2e0e64a0c --- /dev/null +++ b/libc/string/arc/arcv2/strcmp.S @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include + +ENTRY(strcmp) + or r2, r0, r1 + bmsk_s r2, r2, 1 + brne r2, 0, @.Lcharloop + +;;; s1 and s2 are word aligned + ld.ab r2, [r0, 4] + + mov_s r12, 0x01010101 + ror r11, r12 + .align 4 +.LwordLoop: + ld.ab r3, [r1, 4] + ;; Detect NULL char in str1 + sub r4, r2, r12 + ld.ab r5, [r0, 4] + bic r4, r4, r2 + and r4, r4, r11 + brne.d.nt r4, 0, .LfoundNULL + ;; Check if the read locations are the same + cmp r2, r3 + beq.d .LwordLoop + mov.eq r2, r5 + + ;; A match is found, spot it out +#ifdef __LITTLE_ENDIAN__ + swape r3, r3 + mov_s r0, 1 + swape r2, r2 +#else + mov_s r0, 1 +#endif + cmp_s r2, r3 + j_s.d [blink] + bset.lo r0, r0, 31 + + .align 4 +.LfoundNULL: +#ifdef __BIG_ENDIAN__ + swape r4, r4 + swape r2, r2 + swape r3, r3 +#endif + ;; Find null byte + ffs r0, r4 + bmsk r2, r2, r0 + bmsk r3, r3, r0 + swape r2, r2 + swape r3, r3 + ;; make the return value + sub.f r0, r2, r3 + mov.hi r0, 1 + j_s.d [blink] + bset.lo r0, r0, 31 + + .align 4 +.Lcharloop: + ldb.ab r2, [r0, 1] + ldb.ab r3, [r1, 1] + nop + breq r2, 0, .Lcmpend + breq r2, r3, .Lcharloop + + .align 4 +.Lcmpend: + j_s.d [blink] + sub r0, r2, r3 +END(strcmp) +libc_hidden_def(strcmp) + +#ifndef __UCLIBC_HAS_LOCALE__ +strong_alias(strcmp,strcoll) +libc_hidden_def(strcoll) +#endif -- cgit v1.2.3 From 2a2b1d2a3e97b4353eec5a40c0de4b932340b3fc Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 19 Feb 2015 19:14:01 +0530 Subject: posix_fadvise: handle 2 variants for SYSCALL_ALIGN_64BIT arm/powerpc/xtensa pass @advice as 2nd arg to syscall (vs. canonical 4th) Current code however does this for UCLIBC_SYSCALL_ALIGN_64BIT which powerpc/xtensa also happen to define. This is not true for ARCv2 ISA and possibly other arch of future with 64-bit even register requirement, which uses the standard syscall handler in kernel. Fix that by providing 2 variants of SYSCALL_ALIGN_64BIT Signed-off-by: Vineet Gupta Cc: Baruch Siach Cc: Max Filippov Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/posix_fadvise.c | 10 +++++++++- libc/sysdeps/linux/common/posix_fadvise64.c | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libc/sysdeps/linux/common/posix_fadvise.c b/libc/sysdeps/linux/common/posix_fadvise.c index 14bbeeea1..74d8409c0 100644 --- a/libc/sysdeps/linux/common/posix_fadvise.c +++ b/libc/sysdeps/linux/common/posix_fadvise.c @@ -41,9 +41,17 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice) # if __WORDSIZE == 64 ret = INTERNAL_SYSCALL(fadvise64_64, err, 4, fd, offset, len, advice); # else -# if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) || defined(__arm__) +# if defined (__arm__) || \ + (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && (defined(__powerpc__) || defined(__xtensa__))) + /* arch with 64-bit data in even reg alignment #1: [powerpc/xtensa] + * custom syscall handler (rearranges @advice to avoid register hole punch) */ ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd, advice, OFF_HI_LO (offset), OFF_HI_LO (len)); +# elif defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) + /* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future] + * stock syscall handler in kernel (reg hole punched) */ + ret = INTERNAL_SYSCALL(fadvise64_64, err, 7, fd, 0, + OFF_HI_LO (offset), OFF_HI_LO (len), advice); # else ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd, OFF_HI_LO (offset), OFF_HI_LO (len), advice); diff --git a/libc/sysdeps/linux/common/posix_fadvise64.c b/libc/sysdeps/linux/common/posix_fadvise64.c index 5d8989121..37fb269ca 100644 --- a/libc/sysdeps/linux/common/posix_fadvise64.c +++ b/libc/sysdeps/linux/common/posix_fadvise64.c @@ -24,9 +24,18 @@ int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice) { INTERNAL_SYSCALL_DECL (err); /* ARM has always been funky. */ -# if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) || defined(__arm__) +#if defined (__arm__) || \ + (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && (defined(__powerpc__) || defined(__xtensa__))) + /* arch with 64-bit data in even reg alignment #1: [powerpc/xtensa] + * custom syscall handler (rearranges @advice to avoid register hole punch) */ int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd, advice, OFF64_HI_LO (offset), OFF64_HI_LO (len)); +#elif defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) + /* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future] + * stock syscall handler in kernel (reg hole punched) */ + int ret = INTERNAL_SYSCALL (fadvise64_64, err, 7, fd, 0, + OFF64_HI_LO (offset), OFF64_HI_LO (len), + advice); # else int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd, OFF64_HI_LO (offset), OFF64_HI_LO (len), -- cgit v1.2.3 From cd03281d3c2c168f32e42783ee78995772a1763a Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 19 Feb 2015 19:14:02 +0530 Subject: sync_file_range: fix standard UCLIBC_SYSCALL_ALIGN_64BIT handling Currently UCLIBC_SYSCALL_ALIGN_64BIT is not explicitly handled. Fix that and make sure the special handling is done for powerpc/xtensa which use UCLIBC_SYSCALL_ALIGN_64BIT but don't use hole punched syscall handler in kernel. Signed-off-by: Vineet Gupta Cc: Baruch Siach Cc: Max Filippov Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/sync_file_range.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libc/sysdeps/linux/common/sync_file_range.c b/libc/sysdeps/linux/common/sync_file_range.c index 6cd7e94d6..db797de62 100644 --- a/libc/sysdeps/linux/common/sync_file_range.c +++ b/libc/sysdeps/linux/common/sync_file_range.c @@ -24,7 +24,11 @@ static int __NC(sync_file_range)(int fd, off64_t offset, off64_t nbytes, unsigne { # if defined __powerpc__ && __WORDSIZE == 64 return INLINE_SYSCALL(sync_file_range, 4, fd, flags, offset, nbytes); -# elif defined __mips__ && _MIPS_SIM == _ABIO32 +# elif (defined __mips__ && _MIPS_SIM == _ABIO32) || \ + (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && !(defined(__powerpc__) || defined(__xtensa__))) + /* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future] + * stock syscall handler in kernel (reg hole punched) + * see libc/sysdeps/linux/common/posix_fadvise.c for more details */ return INLINE_SYSCALL(sync_file_range, 7, fd, 0, OFF64_HI_LO(offset), OFF64_HI_LO(nbytes), flags); # elif defined __NR_sync_file_range2 -- cgit v1.2.3 From be58779614b2fe9aa57a9315be9dc004dfd77b3b Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Fri, 20 Feb 2015 15:27:08 +0530 Subject: elf: Add STT_GNU_IFUNC from glibc perf in upstream Linux kernel 3.17 onwards expects STT_GNU_IFUNC replicate it from glibc Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- include/elf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/elf.h b/include/elf.h index facf09cd5..917930b18 100644 --- a/include/elf.h +++ b/include/elf.h @@ -566,6 +566,7 @@ typedef struct #define STB_WEAK 2 /* Weak symbol */ #define STB_NUM 3 /* Number of defined types. */ #define STB_LOOS 10 /* Start of OS-specific */ +#define STB_GNU_UNIQUE 10 /* Unique symbol. */ #define STB_HIOS 12 /* End of OS-specific */ #define STB_LOPROC 13 /* Start of processor-specific */ #define STB_HIPROC 15 /* End of processor-specific */ @@ -581,6 +582,7 @@ typedef struct #define STT_TLS 6 /* Symbol is thread-local data object*/ #define STT_NUM 7 /* Number of defined types. */ #define STT_LOOS 10 /* Start of OS-specific */ +#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */ #define STT_HIOS 12 /* End of OS-specific */ #define STT_LOPROC 13 /* Start of processor-specific */ #define STT_HIPROC 15 /* End of processor-specific */ -- cgit v1.2.3 From cf8e466f8959fb22ab41cfe5e16951ef4bd19a80 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 20 Feb 2015 12:35:36 +0100 Subject: include/elf.h: bump EM_NUM and remove a few ancient entries Signed-off-by: Bernhard Reutner-Fischer --- include/elf.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/include/elf.h b/include/elf.h index 917930b18..91fe9f931 100644 --- a/include/elf.h +++ b/include/elf.h @@ -267,8 +267,13 @@ typedef struct #define EM_BLACKFIN 106 /* Analog Devices Blackfin */ #define EM_ALTERA_NIOS2 113 /* Altera Nios II soft-core processor */ #define EM_CRX 114 /* National Semiconductor CRX */ -#define EM_NUM 95 #define EM_TI_C6000 140 +#define EM_METAG 174 /* Imagination Technologies Meta */ +#define EM_MICROBLAZE 189 /* Xilinx Microblaze */ +#define EM_ARCV2 195 /* ARCv2 Cores */ + +/* NEXT FREE NUMBER: Increment this after adding your official arch number */ +#define EM_NUM 196 /* If it is necessary to assign new unofficial EM_* values, please pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the chances of collision @@ -282,22 +287,9 @@ typedef struct unofficial e_machine number should eventually ask registry@caldera.com for an officially blessed number to be added to the list above. */ -/* Imagination Technologies Meta */ -#define EM_METAG 174 - -/* picoJava */ -#define EM_PJ_OLD 99 - /* Cygnus PowerPC ELF backend. Written in the absence of an ABI. */ #define EM_CYGNUS_POWERPC 0x9025 -/* Old version of Sparc v9, from before the ABI; this should be - removed shortly. */ -#define EM_OLD_SPARCV9 11 - -/* Old version of PowerPC, this should be removed shortly. */ -#define EM_PPC_OLD 17 - /* (Deprecated) Temporary number for the OpenRISC processor. */ #define EM_OR32 0x8472 @@ -376,10 +368,6 @@ typedef struct */ #define EM_MICROBLAZE_OLD 0xbaab -/* Xilinx Microblaze (official) */ -#define EM_MICROBLAZE 189 -#define EM_ARCV2 195 /* ARCv2 Cores */ - /* Legal values for e_version (version). */ #define EV_NONE 0 /* Invalid ELF version */ -- cgit v1.2.3 From 30a92760abebf268c255aa8a15c35ca0c865fe88 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Fri, 20 Feb 2015 17:13:26 +0530 Subject: ARC: Remove unused EM_ARC_A5 Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- include/elf.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/elf.h b/include/elf.h index 91fe9f931..39208ea3c 100644 --- a/include/elf.h +++ b/include/elf.h @@ -258,7 +258,6 @@ typedef struct #define EM_MN10200 90 /* Matsushita MN10200 */ #define EM_PJ 91 /* picoJava */ #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ -#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ #define EM_ARCOMPACT 93 /* ARCompact ISA based Cores: ARC 700 */ #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_IP2K 101 /* Ubicom IP2022 micro controller */ -- cgit v1.2.3 From 409f14d9b5e47513d5c939120a33965997c8ceb2 Mon Sep 17 00:00:00 2001 From: Steve Ellcey Date: Thu, 19 Feb 2015 16:03:26 -0800 Subject: Allow use of executable RUNPATH/RPATH when finding libraries. This option will modify ldso so that it will use the executables RUNPATH/RPATH to find to find libraries even though this behavour is not standard. Setting this option causes the uclibc dynamic linker behavour to match the glibc dynamic linker. Signed-off-by: Steve Ellcey Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/Config.in | 9 +++++++++ ldso/ldso/dl-elf.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 84659650b..f5210cdf9 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -419,6 +419,15 @@ config LDSO_RUNPATH Usage of RUNPATH tags is not too common, so disabling this feature should be safe for most people. +config LDSO_RUNPATH_OF_EXECUTABLE + bool "Use executables RUNPATH/RPATH when searching for libraries." + depends on LDSO_RUNPATH + default n + help + Use the executables RUNPATH/RPATH to find to find libraries even + though this behavour is not standard. Setting this option causes + the uclibc dynamic linker behavour to match the glibc dynamic linker. + config LDSO_SAFE_RUNPATH bool "Allow only RUNPATH beginning with /" depends on LDSO_RUNPATH diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 54501d143..56319056d 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -308,6 +308,38 @@ struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rp if (tpnt1 != NULL) return tpnt1; +#ifdef __LDSO_RUNPATH_OF_EXECUTABLE__ + /* Very last resort, try the executable's DT_RUNPATH and DT_RPATH */ + /* http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#shobj_dependencies + * The set of directories specified by a given DT_RUNPATH entry is + * used to find only the immediate dependencies of the executable or + * shared object containing the DT_RUNPATH entry. That is, it is + * used only for those dependencies contained in the DT_NEEDED + * entries of the dynamic structure containing the DT_RUNPATH entry, + * itself. One object's DT_RUNPATH entry does not affect the search + * for any other object's dependencies. + * + * glibc (around 2.19) violates this and the usual suspects are + * abusing this bug^Wrelaxed, user-friendly behaviour. + */ + + pnt = (char *) _dl_loaded_modules->dynamic_info[DT_RUNPATH]; + if (pnt) { + pnt += (unsigned long) _dl_loaded_modules->dynamic_info[DT_STRTAB]; + _dl_if_debug_dprint("\tsearching exe's RUNPATH='%s'\n", pnt); + if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL) + return tpnt1; + } + pnt = (char *) _dl_loaded_modules->dynamic_info[DT_RPATH]; + if (pnt) { + pnt += (unsigned long) _dl_loaded_modules->dynamic_info[DT_STRTAB]; + _dl_if_debug_dprint("\tsearching exe's RPATH='%s'\n", pnt); + if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL) + return tpnt1; + } +#endif + + goof: /* Well, we shot our wad on that one. All we can do now is punt */ if (_dl_internal_error_number) -- cgit v1.2.3