[uclibc-ng-devel] [PATCH 32/32] [ARM] rtld: Avoid crash on R_ARM_NONE relocation
R_ARM_NONE contains no data, so avoid dereferencing it. * ldso/ldso/arm/elfinterp.c (_dl_do_reloc): Handle R_ARM_NONE relocation (_dl_do_reloc_lazy): Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 3bcd675..2444ed7 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -289,7 +289,10 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct r_scope_elem *scope, #if defined (__SUPPORT_LD_DEBUG__) { - unsigned long old_val = *reloc_addr; + unsigned long old_val; + + if (reloc_type != R_ARM_NONE) + old_val = *reloc_addr; #endif switch (reloc_type) { case R_ARM_NONE: @@ -386,7 +389,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct r_scope_elem *scope, return -1; /*call _dl_exit(1) */ } #if defined (__SUPPORT_LD_DEBUG__) - if (_dl_debug_reloc && _dl_debug_detail) + if (_dl_debug_reloc && _dl_debug_detail && reloc_type != R_ARM_NONE) _dl_dprintf(_dl_debug_file, "\tpatch: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr); } @@ -407,7 +410,10 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope, #if defined (__SUPPORT_LD_DEBUG__) { - unsigned long old_val = *reloc_addr; + unsigned long old_val; + + if (reloc_type != R_ARM_NONE) + old_val = *reloc_addr; #endif switch (reloc_type) { case R_ARM_NONE: @@ -428,7 +434,7 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope, return -1; /*call _dl_exit(1) */ } #if defined (__SUPPORT_LD_DEBUG__) - if (_dl_debug_reloc && _dl_debug_detail) + if (_dl_debug_reloc && _dl_debug_detail && reloc_type != R_ARM_NONE) _dl_dprintf(_dl_debug_file, "\tpatch: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr); } -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 30/32] mbtowc: Fix non compliant behavior for end of string
Match glibc behavior. * libc/stdlib/stdlib.c (mbtowc): Fix end of string behavior. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c index 075e6e5..f593663 100644 --- a/libc/stdlib/stdlib.c +++ b/libc/stdlib/stdlib.c @@ -895,9 +895,13 @@ int mbtowc(wchar_t *__restrict pwc, register const char *__restrict s, size_t n) return is_stateful(ENCODING); } - if (*s == '\0') + if (*s == '\0') { /* According to the ISO C 89 standard this is the expected behaviour. */ + /* Standard not very clear here, so do like glibc. */ + if (pwc != NULL) + *pwc = L'\0'; return 0; +} if ((r = mbrtowc(pwc, s, n, )) == (size_t) -2) { /* TODO: Should we set an error state? */ -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 29/32] isnan: Add isnan weak alias to __isnan
* libm/s_isnan.c: Add isnan weak alias. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libm/s_isnan.c b/libm/s_isnan.c index 1bc49cb..1aabb74 100644 --- a/libm/s_isnan.c +++ b/libm/s_isnan.c @@ -26,4 +26,5 @@ int __isnan(double x) hx = 0x7ff0 - hx; return (int)(((u_int32_t)hx)>>31); } +weak_alias(__isnan, isnan) libm_hidden_def(__isnan) -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 26/32] [FDPIC] nptl: Replace sbrk with mmap
Replace sbrk with mmap since this commit disables sbrk area for FDPIC MMU-less platform: fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/binfmt_elf_fdpic.c?id=4ac313111018cb44ecc250445de5ccb93026a980 * libpthread/nptl/sysdeps/generic/libc-tls.c (__libc_setup_tls): Handle __FDPIC__. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index 5f89c91..a6df4cd 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -26,7 +26,7 @@ #include #include #include - +#include #ifdef SHARED #error makefile bug, this file is for static only @@ -155,13 +155,28 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) The initialized value of _dl_tls_static_size is provided by dl-open.c to request some surplus that permits dynamic loading of modules with IE-model TLS. */ + /* Use mmap instead of sbrk since this commit disables sbrk area + for FDPIC MMU-less platforms: + fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU + https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/binfmt_elf_fdpic.c?id=4ac313111018cb44ecc250445de5ccb93026a980 + */ # if defined(TLS_TCB_AT_TP) tcb_offset = roundup (memsz + GL(dl_tls_static_size), tcbalign); +# if defined(__FDPIC__) + tlsblock = mmap (NULL, tcb_offset + tcbsize + max_align, + PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +# else tlsblock = sbrk (tcb_offset + tcbsize + max_align); +# endif # elif defined(TLS_DTV_AT_TP) tcb_offset = roundup (tcbsize, align ?: 1); +# if defined(__FDPIC__) + tlsblock = mmap (NULL, tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size), + PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +# else tlsblock = sbrk (tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); +# endif memset(tlsblock, '\0', tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size)); tlsblock += TLS_PRE_TCB_SIZE; # else -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 27/32] nptl threads: Fix bug in using a weak variable.
In case __nptl_nthreads is not defined in the final binary then avoid dereferencing the address since it's null. Anyway this means there is no other thread and so we must exit. * libc/misc/internals/__uClibc_main.c (__uClibc_main): Handle case where &__nptl_nthreads is null. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index d8286f2..849bca8 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -544,7 +544,7 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, result = 0; unsigned int *const ptr = &__nptl_nthreads; - if (! atomic_decrement_and_test (ptr)) + if (ptr && ! atomic_decrement_and_test (ptr)) /* Not much left to do but to exit the thread, not the process. */ __exit_thread_inline (0); } -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 24/32] [FDPIC] nptl: Use vfork on MMU-less for system()
* libc/stdlib/system.c (FORK): Map to vfork if __ARCH_USE_MMU__ is defined. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/stdlib/system.c b/libc/stdlib/system.c index 771c30e..4c010bb 100644 --- a/libc/stdlib/system.c +++ b/libc/stdlib/system.c @@ -81,6 +81,7 @@ out: libc_hidden_proto(sigaction) libc_hidden_proto(waitpid) +#ifdef __ARCH_USE_MMU__ #if defined __ia64__ # define FORK() \ INLINE_SYSCALL (clone2, 6, CLONE_PARENT_SETTID | SIGCHLD, NULL, 0, \ @@ -92,6 +93,10 @@ libc_hidden_proto(waitpid) # define FORK() \ INLINE_SYSCALL (clone, 3, CLONE_PARENT_SETTID | SIGCHLD, 0, ) #endif +#else +# define FORK() \ +vfork() +#endif static void cancel_handler (void *arg); -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 22/32] [FDPIC] nptl: Allow sem_open to work on MMU-less systems
Allow both tmpfs and ramfs for shm devices. * libpthread/nptl/linux_fsinfo.h (SHMFS_SUPER_MAGIC_WITH_MMU): Define. (SHMFS_SUPER_MAGIC_WITHOUT_MMU): Define. * libpthread/nptl/sem_open.c (__where_is_shmfs): Add support for SHMFS_SUPER_MAGIC_WITHOUT_MMU. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libpthread/nptl/linux_fsinfo.h b/libpthread/nptl/linux_fsinfo.h index 8537581..4abe792 100644 --- a/libpthread/nptl/linux_fsinfo.h +++ b/libpthread/nptl/linux_fsinfo.h @@ -126,7 +126,10 @@ #define XENIX_SUPER_MAGIC 0x012ff7b4 /* Constant that identifies the `shm' filesystem. */ -#define SHMFS_SUPER_MAGIC 0x01021994 +/* Mount as tmpfs. */ +#define SHMFS_SUPER_MAGIC_WITH_MMU 0x01021994 +/* The kernel uses a ramfs file system for tmpfs. */ +#define SHMFS_SUPER_MAGIC_WITHOUT_MMU 0x858458f6 /* Constants that identify the `xfs' filesystem. */ #define XFS_SUPER_MAGIC0x58465342 diff --git a/libpthread/nptl/sem_open.c b/libpthread/nptl/sem_open.c index d811ec5..2746da1 100644 --- a/libpthread/nptl/sem_open.c +++ b/libpthread/nptl/sem_open.c @@ -72,7 +72,9 @@ __where_is_shmfs (void) /* The canonical place is /dev/shm. This is at least what the documentation tells everybody to do. */ - if (__statfs (defaultmount, ) == 0 && f.f_type == SHMFS_SUPER_MAGIC) + if (__statfs (defaultmount, ) == 0 + && (f.f_type == SHMFS_SUPER_MAGIC_WITH_MMU + || f.f_type == SHMFS_SUPER_MAGIC_WITHOUT_MMU)) { /* It is in the normal place. */ mountpoint.dir = (char *) defaultdir; @@ -106,7 +108,9 @@ __where_is_shmfs (void) /* First make sure this really is the correct entry. At least some versions of the kernel give wrong information because of the implicit mount of the shmfs for SysV IPC. */ - if (__statfs (mp->mnt_dir, ) != 0 || f.f_type != SHMFS_SUPER_MAGIC) + if (__statfs (mp->mnt_dir, ) != 0 + || (f.f_type != SHMFS_SUPER_MAGIC_WITH_MMU + && f.f_type != SHMFS_SUPER_MAGIC_WITHOUT_MMU)) continue; namelen = strlen (mp->mnt_dir); -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 23/32] [FDPIC] nptl: Add pthread_mutex_getprioceiling and pthread_mutex_setprioceiling support
* libpthread/nptl/Makefile.in (libpthread-routines-): Remove pthread_mutex_getprioceiling.c and pthread_mutex_setprioceiling.c. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libpthread/nptl/Makefile.in b/libpthread/nptl/Makefile.in index a2f30ac..bd220ba 100644 --- a/libpthread/nptl/Makefile.in +++ b/libpthread/nptl/Makefile.in @@ -18,7 +18,6 @@ libpthread-shared-only-routines-y = version.c libpthread-static-only-routines-y = pthread_atfork.c libpthread-routines- += $(notdir $(wildcard $(libpthread_DIR)/gen_*.c)) # dummy generated files libpthread-routines- += allocatestack.c # dummy included by pthread_create.c -libpthread-routines- += pthread_mutex_getprioceiling.c pthread_mutex_setprioceiling.c # XXX: delete those or use them! libpthread-routines-$(UCLIBC_SUSV4_LEGACY) += pthread_getconcurrency.c \ pthread_setconcurrency.c libpthread_CSRC = $(filter-out $(libpthread-routines-) \ -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 20/32] [FDPIC] nptl: Do not use madvise
start_thread() uses it, but it is not supported on MMU-less systems. * libpthread/nptl/pthread_create.c (start_thread): Call madvise only if __ARCH_USE_MMU__ is defined. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libpthread/nptl/pthread_create.c b/libpthread/nptl/pthread_create.c index 3064b40..5a7957d 100644 --- a/libpthread/nptl/pthread_create.c +++ b/libpthread/nptl/pthread_create.c @@ -373,8 +373,12 @@ start_thread (void *arg) size_t freesize = ((char *) pd->stackblock - sp) & ~pagesize_m1; #endif assert (freesize < pd->stackblock_size); + + /* madvise is not supported on MMU-less systems. */ +#ifdef __ARCH_USE_MMU__ if (freesize > PTHREAD_STACK_MIN) madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED); +#endif /* If the thread is detached free the TCB. */ if (IS_DETACHED (pd)) -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 19/32] [FDPIC] nptl: Disable fork and atfork on MMU-less systems.
They do not work on MMU-less systems. For atfork, implement a hidden function that always returns EPERM. * libpthread/nptl/sysdeps/unix/sysv/linux/fork.c: Disable if __ARCH_USE_MMU__ is not defined. * libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c (__libc_pthread_init): Handle __ARCH_USE_MMU__. * libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c: Likewise. * libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c: Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c index 9b96152..429fb90 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/fork.c @@ -28,6 +28,7 @@ #include #include +#ifdef __ARCH_USE_MMU__ unsigned long int *__fork_generation_pointer; @@ -206,3 +207,5 @@ fork (void) return pid; } libc_hidden_def(fork) + +#endif /* __ARCH_USE_MMU__ */ diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c b/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c index 0df9951..0cdbcfe 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c @@ -40,10 +40,14 @@ __libc_pthread_init ( void (*reclaim) (void)) { /* Remember the pointer to the generation counter in libpthread. */ +#ifdef __ARCH_USE_MMU__ __fork_generation_pointer = ptr; +#endif /* Called by a child after fork. */ +#ifdef __ARCH_USE_MMU__ __register_atfork (NULL, NULL, reclaim, NULL); +#endif #ifndef TLS_MULTIPLE_THREADS_IN_TCB return &__libc_multiple_threads; diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c index b745f9d..55835e5 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/register-atfork.c @@ -24,6 +24,7 @@ #include +#ifdef __ARCH_USE_MMU__ /* Lock to protect allocation and deallocation of fork handlers. */ int __fork_lock = LLL_LOCK_INITIALIZER; @@ -118,6 +119,18 @@ __linkin_atfork (struct fork_handler *newp) while (catomic_compare_and_exchange_bool_acq (&__fork_handlers, newp, newp->next) != 0); } +#else +int +__register_atfork ( + void (*prepare) (void), + void (*parent) (void), + void (*child) (void), + void *dso_handle) +{ +return EPERM; +} +libc_hidden_def (__register_atfork) +#endif #if 0 libc_freeres_fn (free_mem) @@ -145,4 +158,3 @@ libc_freeres_fn (free_mem) } } #endif - diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c b/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c index 69e2621..e958e71 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c @@ -22,7 +22,7 @@ #include #include - +#ifdef __ARCH_USE_MMU__ void __unregister_atfork ( void *dso_handle) @@ -120,3 +120,11 @@ __unregister_atfork ( deleted = deleted->next; } } +#else +void +__unregister_atfork ( + void *dso_handle) +{ +/* Nothing to do. */ +} +#endif -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 18/32] [FDPIC] nptl: disable mprotect usage in stack protection
Since mprotect does not work on MMU-less systems, disable it if __ARCH_USE_MMU__ is not defined. * libpthread/nptl/allocatestack.c (change_stack_perm): Call mprotect only if __ARCH_USE_MMU__ is defined. (allocate_stack): Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c index 2900517..1379795 100644 --- a/libpthread/nptl/allocatestack.c +++ b/libpthread/nptl/allocatestack.c @@ -328,8 +328,10 @@ change_stack_perm (struct pthread *pd #else # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" #endif +#ifdef __ARCH_USE_MMU__ if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) return errno; +#endif return 0; } @@ -593,6 +595,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #elif defined _STACK_GROWS_UP char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1); #endif +#ifdef __ARCH_USE_MMU__ if (mprotect (guard, guardsize, PROT_NONE) != 0) { int err; @@ -618,6 +621,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, return err; } +#endif pd->guardsize = guardsize; } @@ -630,6 +634,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1); char *oldguard = mem + (((size - pd->guardsize) / 2) & ~pagesize_m1); +#ifdef __ARCH_USE_MMU__ if (oldguard < guard && mprotect (oldguard, guard - oldguard, prot) != 0) goto mprot_error; @@ -647,6 +652,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, pd->guardsize - guardsize, prot) != 0) goto mprot_error; #endif +#endif pd->guardsize = guardsize; } -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 16/32] [ARM][FDPIC] rtld: Use ELF_RTYPE_CLASS_DLSYM
rtld must call _dl_find_hash() with ELF_RTYPE_CLASS_DLSYM since we want a function descriptor. * ldso/ldso/ldso.c (_dl_get_ready_to_run): Support __FDPIC__. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 06b0ac8..b335476 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -444,6 +444,11 @@ void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, size_t relro_size = 0; struct r_scope_elem *global_scope; struct elf_resolve **local_scope; +#if defined(__FDPIC__) + int rtype_class = ELF_RTYPE_CLASS_DLSYM; +#else + int rtype_class = ELF_RTYPE_CLASS_PLT; +#endif #if defined(USE_TLS) && USE_TLS void *tcbp = NULL; @@ -1422,21 +1427,21 @@ of this helper program; chances are you did not intend to run this program.\n\ /* Find the real malloc function and make ldso functions use that from now on */ _dl_malloc_function = (void* (*)(size_t)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "malloc", - global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + global_scope, NULL, rtype_class, NULL); #if defined(USE_TLS) && USE_TLS /* Find the real functions and make ldso functions use them from now on */ _dl_calloc_function = (void* (*)(size_t, size_t)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "calloc", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "calloc", global_scope, NULL, rtype_class, NULL); _dl_realloc_function = (void* (*)(void *, size_t)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "realloc", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "realloc", global_scope, NULL, rtype_class, NULL); _dl_free_function = (void (*)(void *)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "free", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "free", global_scope, NULL, rtype_class, NULL); _dl_memalign_function = (void* (*)(size_t, size_t)) (intptr_t) - _dl_find_hash(__C_SYMBOL_PREFIX__ "memalign", global_scope, NULL, ELF_RTYPE_CLASS_PLT, NULL); + _dl_find_hash(__C_SYMBOL_PREFIX__ "memalign", global_scope, NULL, rtype_class, NULL); #endif -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 14/32] [ARM][FDPIC] arm/clone.S: Fix threading support
Change clone.S so that in FDPIC case we take into account the fact that we are given a function descriptor. * libc/sysdeps/linux/arm/clone.S (__clone): Support __FDPIC__. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/sysdeps/linux/arm/clone.S b/libc/sysdeps/linux/arm/clone.S index 8ca50fc..eacf3db 100644 --- a/libc/sysdeps/linux/arm/clone.S +++ b/libc/sysdeps/linux/arm/clone.S @@ -130,8 +130,20 @@ PSEUDO_END (__clone) .cantunwind @ pick the function arg and call address off the stack and execute ldr r0, [sp, #4] +#if defined(__FDPIC__) + ldr r12, [sp] + mov r4, r9 + ldr r9, [r12, #4] + mov lr, pc + ldr pc, [r12] +#else mov lr, pc ldr pc, [sp] +#endif + +#if defined(__FDPIC__) + mov r9, r4 +#endif @ and we are done, passing the return value through r0 b HIDDEN_JUMPTARGET(_exit) -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 13/32] [ARM][FDPIC] rtld: Compile with -fno-unwind-tables -fno-asynchronous-unwind-tables
Otherwise we have link errors because of unresolved refs in libgcc.a: ld: /lib/gcc/arm-none-uclinuxfdpiceabi/9.0.0/libgcc.a(pr-support.o): in function `_Unwind_GetDataRelBase': /libgcc/config/arm/pr-support.c:378: undefined reference to `abort' ld: /lib/gcc/arm-none-uclinuxfdpiceabi/9.0.0/libgcc.a(unwind-arm.o): in function `unwind_phase2_forced': /libgcc/unwind-arm-common.inc:511: undefined reference to `memcpy' * ldso/ldso/Makefile.in (CFLAGS-rtld): Always use -fno-unwind-tables -fno-asynchronous-unwind-tables on arm Signed-off-by: Christophe Lyon diff --git a/ldso/ldso/Makefile.in b/ldso/ldso/Makefile.in index acb1a5b..4f2a184 100644 --- a/ldso/ldso/Makefile.in +++ b/ldso/ldso/Makefile.in @@ -14,12 +14,10 @@ ifneq ($(TARGET_ARCH),arc) CFLAGS-rtld += -fno-omit-frame-pointer endif -ifeq ($(DODEBUG),y) ifeq ($(TARGET_ARCH),arm) # This stuff will not work with -funwind-tables / -fasynchronous-unwind-tables CFLAGS-rtld += -fno-unwind-tables -fno-asynchronous-unwind-tables endif -endif CFLAGS-rtld += -I$(top_srcdir)ldso/ldso/$(TARGET_ARCH) -I$(top_srcdir)ldso/include -I$(top_srcdir)ldso/ldso CFLAGS-rtld += -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" -DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 12/32] [ARM][FDPIC] TLS: fix relocation computation
* ldso/ldso/dl-elf.c (_dl_load_elf_shared_library): Fix l_tls_initimage computation. * ldso/ldso/ldso.c (_dl_get_ready_to_run): Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 1768b5b..9cb46de 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -863,11 +863,11 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned int rflags, { # ifdef __SUPPORT_LD_DEBUG_EARLY__ char *tmp = (char *) tpnt->l_tls_initimage; - tpnt->l_tls_initimage = (char *) tlsppnt->p_vaddr + tpnt->loadaddr; + tpnt->l_tls_initimage = (char *) DL_RELOC_ADDR(tpnt->loadaddr, tlsppnt->p_vaddr; _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", tmp, tpnt->l_tls_initimage, tpnt->l_tls_initimage_size); tmp = 0; # else - tpnt->l_tls_initimage = (char *) tlsppnt->p_vaddr + tpnt->loadaddr; + tpnt->l_tls_initimage = (char *) DL_RELOC_ADDR(tpnt->loadaddr, tlsppnt->p_vaddr); # endif } } diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index c625757..06b0ac8 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -772,7 +772,7 @@ of this helper program; chances are you did not intend to run this program.\n\ char *tmp attribute_unused = (char *) app_tpnt->l_tls_initimage; app_tpnt->l_tls_initimage = - (char *) app_tpnt->l_tls_initimage + app_tpnt->loadaddr; + (char *) DL_RELOC_ADDR(app_tpnt->loadaddr, app_tpnt->l_tls_initimage); _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", tmp, app_tpnt->l_tls_initimage, app_tpnt->l_tls_initimage_size); } -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 10/32] [ARM][FDPIC] Allow to generate PIE 'static' binary
* libc/misc/internals/__uClibc_main.c (funcdesc_value): New. (fdpic_init_array_jump): New. (__uClibc_fini): Support __FDPIC__. (__uClibc_main): Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index d80565e..d8286f2 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -48,6 +48,39 @@ int _pe_secure = 0; libc_hidden_data_def(_pe_secure) +#if !defined(SHARED) && defined(__FDPIC__) +struct funcdesc_value +{ + void *entry_point; + void *got_value; +} __attribute__((__aligned__(8))); + + +/* Prevent compiler optimization that removes GOT assignment. + + Due to optimization passes (block split and move), in the rare case + where use r9 is the single instruction in a block we can have the + following behaviour: + - this block is marked as a forward block since use is not + considered as an active instruction after reload pass. + + - In this case a jump in this block can be moved to the start of the + next one and so remove use in this flow of instructions which can + lead to a removal of r9 restoration after a call. */ +#define _dl_stabilize_funcdesc(val)\ + ({ __asm__ ("" : "+m" (*(val))); (val); }) + +static void fdpic_init_array_jump(void *addr) +{ + struct funcdesc_value *fm = (struct funcdesc_value *) fdpic_init_array_jump; + struct funcdesc_value fd = {addr, fm->got_value}; + + void (*pf)(void) = (void*) _dl_stabilize_funcdesc(); + + (*pf)(); +} +#endif + #ifndef SHARED void *__libc_stack_end = NULL; @@ -307,7 +340,11 @@ void __uClibc_fini(void) # elif !defined (__UCLIBC_FORMAT_SHARED_FLAT__) size_t i = __fini_array_end - __fini_array_start; while (i-- > 0) +#if !defined(SHARED) && defined(__FDPIC__) + fdpic_init_array_jump(__fini_array_start[i]); +#else (*__fini_array_start [i]) (); +#endif # endif if (__app_fini != NULL) (__app_fini)(); @@ -436,7 +473,11 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, const size_t size = __preinit_array_end - __preinit_array_start; size_t i; for (i = 0; i < size; i++) +#if !defined(SHARED) && defined(__FDPIC__) + fdpic_init_array_jump(__preinit_array_start[i]); +#else (*__preinit_array_start [i]) (); +#endif } # endif /* Run all the application's ctors now. */ @@ -452,7 +493,11 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc, const size_t size = __init_array_end - __init_array_start; size_t i; for (i = 0; i < size; i++) +#if !defined(SHARED) && defined(__FDPIC__) + fdpic_init_array_jump(__init_array_start[i]); +#else (*__init_array_start [i]) (); +#endif } # endif #endif -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 11/32] [ARM][FDPIC] rtld: Add lazy binding support
Add support for R_ARM_FUNCDESC_VALUE and implement _dl_linux_resolver for FDPIC on ARM. * ldso/ldso/arm/elfinterp.c (_dl_linux_resolver): Support __FDPIC__. (_dl_do_lazy_reloc): Likewise. * ldso/ldso/arm/resolve.S (_dl_linux_resolve): Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 1435c2c..3bcd675 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -34,13 +34,69 @@ extern int _dl_linux_resolve(void); -unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) -{ #if __FDPIC__ - /* FIXME: implement. */ - while(1) ; - return 0; +unsigned long _dl_linux_resolver (struct elf_resolve *tpnt, int reloc_offet) +{ + ELF_RELOC *this_reloc; + char *strtab; + ElfW(Sym) *symtab; + int symtab_index; + char *rel_addr; + char *new_addr; + struct funcdesc_value funcval; + struct funcdesc_value volatile *got_entry; + char *symname; + struct symbol_ref sym_ref; + + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL]; + + this_reloc = (ELF_RELOC *)(intptr_t)(rel_addr + reloc_offet); + symtab_index = ELF_R_SYM(this_reloc->r_info); + + symtab = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *) tpnt->dynamic_info[DT_STRTAB]; + sym_ref.sym = [symtab_index]; + sym_ref.tpnt = NULL; + symname= strtab + symtab[symtab_index].st_name; + + /* Address of GOT entry fix up */ + got_entry = (struct funcdesc_value *) DL_RELOC_ADDR(tpnt->loadaddr, this_reloc->r_offset); + + /* Get the address to be used to fill in the GOT entry. */ + new_addr = _dl_find_hash(symname, &_dl_loaded_modules->symbol_scope, NULL, 0, _ref); + if (!new_addr) { + new_addr = _dl_find_hash(symname, NULL, NULL, 0, _ref); + if (!new_addr) { + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, symname); + _dl_exit(1); + } + } + + funcval.entry_point = new_addr; + funcval.got_value = sym_ref.tpnt->loadaddr.got_value; + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_bindings) { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); + if (_dl_debug_detail) + _dl_dprintf(_dl_debug_file, + "\n\tpatched (%x,%x) ==> (%x,%x) @ %x\n", + got_entry->entry_point, got_entry->got_value, + funcval.entry_point, funcval.got_value, + got_entry); + } + if (1 || !_dl_debug_nofixups) { + *got_entry = funcval; + } +#else + *got_entry = funcval; +#endif + + return got_entry; +} #else +unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) +{ ELF_RELOC *this_reloc; char *strtab; char *symname; @@ -93,8 +149,8 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) #endif return new_addr; -#endif } +#endif static int _dl_parse(struct elf_resolve *tpnt, struct r_scope_elem *scope, @@ -346,7 +402,7 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope, int reloc_type; unsigned long *reloc_addr; - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_addr = (unsigned long *) DL_RELOC_ADDR(tpnt->loadaddr, rpnt->r_offset); reloc_type = ELF_R_TYPE(rpnt->r_info); #if defined (__SUPPORT_LD_DEBUG__) @@ -356,8 +412,17 @@ _dl_do_lazy_reloc (struct elf_resolve *tpnt, struct r_scope_elem *scope, switch (reloc_type) { case R_ARM_NONE: break; + case R_ARM_JUMP_SLOT: - *reloc_addr += (unsigned long) tpnt->loadaddr; + *reloc_addr = DL_RELOC_ADDR(tpnt->loadaddr, *reloc_addr); + break; + case R_ARM_FUNCDESC_VALUE: + { + struct funcdesc_value *dst = (struct funcdesc_value *) reloc_addr; + + dst->entry_point = DL_RELOC_ADDR(tpnt->loadaddr, dst->entry_point); + dst->got_value = tpnt->loadaddr.got_value; + } break; default: return -1; /*call _dl_exit(1) */ diff --git a/ldso/ldso/arm/resolve.S b/ldso/ldso/arm/resolve.S index 2a51643..039a6b7 100644 --- a/ldso/ldso/arm/resolve.S +++ b/ldso/ldso/arm/resolve.S @@ -107,6 +107,27 @@ .type _dl_linux_resolve,%function .align 4; +#if
[uclibc-ng-devel] [PATCH 09/32] [ARM][FDPIC] Add runtime support needed for C++ exceptions
Implements __gnu_Unwind_Find_got(), which is called from libgcc while unwinding. * libc/sysdeps/linux/arm/Makefile.arch (CSRC): Add find._got.c. * libc/sysdeps/linux/arm/find_got.c: New file. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/sysdeps/linux/arm/Makefile.arch b/libc/sysdeps/linux/arm/Makefile.arch index f9ac88b..40a0184 100644 --- a/libc/sysdeps/linux/arm/Makefile.arch +++ b/libc/sysdeps/linux/arm/Makefile.arch @@ -23,7 +23,7 @@ $(eval $(call cache-output-var,IS_EABI,$(CC_IS_EABI_CHECK) -x c - -E -dM http://www.gnu.org/licenses/>. */ + +#include +#include + +#if __FDPIC__ +#include + +struct got_callback_data +{ + _Unwind_Ptr pc; + _Unwind_Ptr got; +}; + +static __always_inline int +__dl_addr_in_loadaddr(void *p, struct elf32_fdpic_loadaddr loadaddr) +{ + struct elf32_fdpic_loadmap *map = loadaddr.map; + int c; + + for (c = 0; c < map->nsegs; c++) + if ((void *)map->segs[c].addr <= p && + (char *)p < (char *)map->segs[c].addr + map->segs[c].p_memsz) + return 1; + + return 0; +} + +/* Callback to return the GOT value if the module contains PC. */ +static int +find_got_callback (struct dl_phdr_info * info, size_t size, void * ptr) +{ +int match = 0; +struct got_callback_data *data = (struct got_callback_data *) ptr; + +if (__dl_addr_in_loadaddr((void *) data->pc, info->dlpi_addr)) { +match = 1; +data->got = (_Unwind_Ptr) info->dlpi_addr.got_value; +} + +return match; +} + +/* Find the GOT that corresponds to the module containing PC. */ +_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc); +_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc) +{ + struct got_callback_data data; + + data.pc = pc; + if (dl_iterate_phdr (find_got_callback, ) <= 0) +return 0; + + return data.got; +} +#endif + -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 07/32] [ARM] Fix bug in _dl_pread when using pread64 syscall
In ARM_EABI mode, the pread64 syscall parameters are aligned on 64-bits. This syscall is used in rtld when processing FDPIC relocations. * ldso/include/dl-syscall.h (__syscall_pread): Fix definition. (__dl_pread): Fix syscall invocation. * ldso/ldso/fdpic/dl-sysdep.h (__DL_PREAD): Handle __NR_pread64. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h index 5ba8c87..9d80c6a 100644 --- a/ldso/include/dl-syscall.h +++ b/ldso/include/dl-syscall.h @@ -159,14 +159,25 @@ static __always_inline _syscall4(int, _dl_readlink, int, id, const char *, path, #ifdef __NR_pread64 #define __NR___syscall_pread __NR_pread64 +#ifdef __UCLIBC_SYSCALL_ALIGN_64BIT__ +static __always_inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf, size_t, dummy, + size_t, count, off_t, offset_hi, off_t, offset_lo) + +static __always_inline ssize_t +_dl_pread(int fd, void *buf, size_t count, off_t offset) +{ + return __syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR((offset >> 32), (offset & 0x))); +} +#else static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf, size_t, count, off_t, offset_hi, off_t, offset_lo) static __always_inline ssize_t _dl_pread(int fd, void *buf, size_t count, off_t offset) { - return __syscall_pread(fd, buf, count, offset, offset >> 31); + return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset)); } +#endif #elif defined __NR_pread #define __NR___syscall_pread __NR_pread static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf, diff --git a/ldso/ldso/fdpic/dl-sysdep.h b/ldso/ldso/fdpic/dl-sysdep.h index 546811a..6ab303b 100644 --- a/ldso/ldso/fdpic/dl-sysdep.h +++ b/ldso/ldso/fdpic/dl-sysdep.h @@ -96,7 +96,7 @@ struct funcdesc_ht; elfinterp.c. */ #define DL_SKIP_BOOTSTRAP_RELOC(SYMTAB, INDEX, STRTAB) 0 -#ifdef __NR_pread +#if defined(__NR_pread) || defined(__NR_pread64) #define _DL_PREAD(FD, BUF, SIZE, OFFSET) \ (_dl_pread((FD), (BUF), (SIZE), (OFFSET))) #endif -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 03/32] [ARM][FDPIC] rtld: Add #if defined (__FDPIC__)
Like for other FDPIC targets, add defined(__FDPIC__) where needed. * include/link.h: Include bits/elf-fdpic.h if __FDPIC__ is defined. (link_map): Use elf32_fdpic_loadaddr if __FDPIC__ is defined. (dl_phdr_info): Likewise. * ldso/include/dl-elf.h (__dl_parse_dynamic_info): Support __FDPIC__. * ldso/include/dl-hash.h (elf_resolve): Add funcdesc_ht field if __FDPIC__ is defined. * ldso/ldso/dl-hash.c (_dl_find_hash): Support __FDPIC__. * libc/misc/elf/dl-iterate-phdr.c (dl_iterate_phdr): Support __FDPIC__. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/include/link.h b/include/link.h index 711777b..ef4a016 100644 --- a/include/link.h +++ b/include/link.h @@ -79,7 +79,7 @@ extern struct r_debug _r_debug; */ extern ElfW(Dyn) _DYNAMIC[]; -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) # include #endif #ifdef __DSBT__ @@ -97,7 +97,7 @@ struct link_map /* These first few members are part of the protocol with the debugger. This is the same format used in SVR4. */ -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) struct elf32_fdpic_loadaddr l_addr; #else #ifdef __DSBT__ @@ -184,7 +184,7 @@ enum struct dl_phdr_info { -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) struct elf32_fdpic_loadaddr dlpi_addr; #else #ifdef __DSBT__ diff --git a/ldso/include/dl-elf.h b/ldso/include/dl-elf.h index a827b8d..2b99958 100644 --- a/ldso/include/dl-elf.h +++ b/ldso/include/dl-elf.h @@ -202,7 +202,7 @@ unsigned int __dl_parse_dynamic_info(ElfW(Dyn) *dpnt, unsigned long dynamic_info /* Don't adjust .dynamic unnecessarily. For FDPIC targets, we'd have to walk all the loadsegs to find out if it was actually unnecessary, so skip this optimization. */ -#if !defined __FRV_FDPIC__ && !defined __BFIN_FDPIC__ && !defined __DSBT__ +#if !defined __FRV_FDPIC__ && !defined __BFIN_FDPIC__ && !defined __DSBT__ && !defined __FDPIC__ if (load_off != 0) #endif { diff --git a/ldso/include/dl-hash.h b/ldso/include/dl-hash.h index cb46bec..d1deea9 100644 --- a/ldso/include/dl-hash.h +++ b/ldso/include/dl-hash.h @@ -134,7 +134,7 @@ struct elf_resolve { unsigned long data_words; #endif -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) /* Every loaded module holds a hashtable of function descriptors of functions defined in it, such that it's easy to release the memory when the module is dlclose()d. */ diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c index 18b3045..0fede84 100644 --- a/ldso/ldso/dl-hash.c +++ b/ldso/ldso/dl-hash.c @@ -377,7 +377,7 @@ char *_dl_find_hash(const char *name, struct r_scope_elem *scope, struct elf_res break; #endif case STB_GLOBAL: -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) if (sym_ref) sym_ref->tpnt = tpnt; #endif @@ -386,7 +386,7 @@ char *_dl_find_hash(const char *name, struct r_scope_elem *scope, struct elf_res break; } } -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) if (sym_ref) sym_ref->tpnt = tpnt; #endif diff --git a/libc/misc/elf/dl-iterate-phdr.c b/libc/misc/elf/dl-iterate-phdr.c index 27a9254..e21e88c 100644 --- a/libc/misc/elf/dl-iterate-phdr.c +++ b/libc/misc/elf/dl-iterate-phdr.c @@ -58,7 +58,7 @@ dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, /* This entry describes this statically-linked program itself. */ struct dl_phdr_info info; int ret; -#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__) info.dlpi_addr.map = NULL; info.dlpi_addr.got_value = NULL; #elif defined(__DSBT__) -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 01/32] [ARM][FDPIC] Allow to select FDPIC ELF for arm architecture
* extra/Configs/Config.in.arch: Add TARGET_arm to the target list for UCLIBC_FORMAT_FDPIC_ELF. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/extra/Configs/Config.in.arch b/extra/Configs/Config.in.arch index b51ed81..91b6394 100644 --- a/extra/Configs/Config.in.arch +++ b/extra/Configs/Config.in.arch @@ -12,7 +12,7 @@ choice prompt "Target File Format" config UCLIBC_FORMAT_FDPIC_ELF bool "FDPIC ELF" - depends on !ARCH_USE_MMU && (TARGET_bfin || TARGET_frv) + depends on !ARCH_USE_MMU && (TARGET_bfin || TARGET_frv || TARGET_arm) select DOPIC config UCLIBC_FORMAT_DSBT_ELF bool "DBST ELF" -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 02/32] [FDPIC] rtld: Do not protect RELRO segments when we don't use an MMU.
Without MMU, we cannot mark memory regions as read-only. * ldso/ldso/dl-elf.c (_dl_protect_relro): Do nothing if __ARCH_USE_MMU__ is defined. Signed-off-by: Christophe Lyon diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index d264e6a..1768b5b 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -117,6 +117,7 @@ int _dl_unmap_cache(void) void _dl_protect_relro (struct elf_resolve *l) { +#ifdef __ARCH_USE_MMU__ ElfW(Addr) base = (ElfW(Addr)) DL_RELOC_ADDR(l->loadaddr, l->relro_addr); ElfW(Addr) start = (base & PAGE_ALIGN); ElfW(Addr) end = ((base + l->relro_size) & PAGE_ALIGN); @@ -126,6 +127,7 @@ _dl_protect_relro (struct elf_resolve *l) _dl_dprintf(2, "%s: cannot apply additional memory protection after relocation", l->libname); _dl_exit(0); } +#endif } /* This function's behavior must exactly match that -- 2.6.3 ___ devel mailing list devel@uclibc-ng.org https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
[uclibc-ng-devel] [PATCH 00/32] FDPIC ABI for ARM
Hello, This patch series implements the uClibc-ng contribution of the FDPIC ABI for ARM targets. This ABI enables to run Linux on ARM MMU-less cores and supports shared libraries to reduce the memory footprint. Without MMU, text and data segments relative distances are different from one process to another, hence the need for a dedicated FDPIC register holding the start address of the data segment. One of the side effects is that function pointers require two words to be represented: the address of the code, and the data segment start address. These two words are designated as "Function Descriptor", hence the "FD PIC" name. On ARM, the FDPIC register is r9 [1], and the target name is arm-uclinuxfdpiceabi. Note that arm-uclinux exists, but uses another ABI and the BFLAT file format; it does not support code sharing. This work was developed some time ago by STMicroelectronics, and was presented during Linaro Connect SFO15 (September 2015). You can watch the discussion and read the slides [2]. This presentation was related to the toolchain published on github [3], which is based on binutils-2.22, gcc-4.7, uclibc-0.9.33.2, gdb-7.5.1 and qemu-2.3.0, and for which pre-built binaries are available [3]. The ABI itself is described in details in [1]. Our Linux kernel patches have been updated and committed by Nicolas Pitre (Linaro) in July 2017. They are required so that the loader is able to handle this new file type. Indeed, the ELF files are tagged with ELFOSABI_ARM_FDPIC. This new tag has been allocated by ARM, as well as the new relocations involved. The binutils and QEMU patch series have been merged recently. [4][5] The GCC patch series has been submitted and is under discussion. [6] This patch series consists in the original uClibc-based patches, which I have rebased and updated for uClibc-ng. Most of them are strictly related to FDPIC on ARM, while a few others address generic issues. Are the uClibc-ng patches OK for inclusion in master? Thanks, Christophe. [1] https://github.com/mickael-guene/fdpic_doc/blob/master/abi.txt [2] http://connect.linaro.org/resource/sfo15/sfo15-406-arm-fdpic-toolset-kernel-libraries-for-cortex-m-cortex-r-mmuless-cores/ [3] https://github.com/mickael-guene/fdpic_manifest [4] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=f1ac0afe481e83c9a33f247b81fa7de789edc4d9 [5] https://git.qemu.org/?p=qemu.git;a=commit;h=e8fa72957419c11984608062c7dcb204a6003a06 [6] https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01439.html Christophe Lyon (32): [ARM][FDPIC] Allow to select FDPIC ELF for arm architecture [FDPIC] rtld: Do not protect RELRO segments when we don't use an MMU. [ARM][FDPIC] rtld: Add #if defined (__FDPIC__) [ARM][FDPIC] rtld: Add FDPIC code for arm [ARM][FDPIC] rtld: Avoid FUNCDESC relocation on _start [ARM][FDPIC] rtld: Add startup code [ARM] Fix bug in _dl_pread when using pread64 syscall [ARM][FDPIC] Add application startup code for FDPIC [ARM][FDPIC] Add runtime support needed for C++ exceptions [ARM][FDPIC] Allow to generate PIE 'static' binary [ARM][FDPIC] rtld: Add lazy binding support [ARM][FDPIC] TLS: fix relocation computation [ARM][FDPIC] rtld: Compile with -fno-unwind-tables -fno-asynchronous-unwind-tables [ARM][FDPIC] arm/clone.S: Fix threading support [ARM][FDPIC] enable NPTL on TARGET_arm [ARM][FDPIC] rtld: Use ELF_RTYPE_CLASS_DLSYM [FDPIC] rtld: Initialize _dl_error_catch_tsd without FUNCDESC relocation [FDPIC] nptl: disable mprotect usage in stack protection [FDPIC] nptl: Disable fork and atfork on MMU-less systems. [FDPIC] nptl: Do not use madvise [ARM][FDPIC] nptl: Use linker-defined symbol to find start of .tdata section. [FDPIC] nptl: Allow sem_open to work on MMU-less systems [FDPIC] nptl: Add pthread_mutex_getprioceiling and pthread_mutex_setprioceiling support [FDPIC] nptl: Use vfork on MMU-less for system() nptl: Clear TLS area for static binaries. [FDPIC] nptl: Replace sbrk with mmap nptl threads: Fix bug in using a weak variable. Fix htab_delete loop counter isnan: Add isnan weak alias to __isnan mbtowc: Fix non compliant behavior for end of string Fix shm_open posix compliance error code [ARM] rtld: Avoid crash on R_ARM_NONE relocation extra/Configs/Config.in| 2 +- extra/Configs/Config.in.arch | 2 +- include/elf.h | 2 + include/link.h | 6 +- ldso/include/dl-elf.h | 2 +- ldso/include/dl-hash.h | 2 +- ldso/include/dl-string.h | 3 +- ldso/include/dl-syscall.h | 13 +- ldso/include/inline-hashtab.h | 2 +- ldso/ldso/Makefile.in | 2 - ldso/ldso/arm/dl-inlines.h | 1 + ldso/ldso/arm/dl-startup.h