From 9849c407e8e6732fbf417cb447937e3b3b9a54ec Mon Sep 17 00:00:00 2001 From: Carmelo Amoroso Date: Wed, 16 Dec 2009 09:09:38 +0100 Subject: build: Get rids of PIC macro using compiler flag __PIC__ instead Based on Peter Mazinger's comments on a recent commit, I decided to get rids of all occurrences of PIC changing them to __PIC__ Signed-off-by: Carmelo Amoroso --- libc/string/x86_64/memcpy.S | 2 +- libc/string/x86_64/memset.S | 4 ++-- libc/sysdeps/linux/xtensa/sysdep.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libc') diff --git a/libc/string/x86_64/memcpy.S b/libc/string/x86_64/memcpy.S index 697b992d0..011291447 100644 --- a/libc/string/x86_64/memcpy.S +++ b/libc/string/x86_64/memcpy.S @@ -26,7 +26,7 @@ #define MEMPCPY_P (defined memcpy) .text -#if defined PIC && !defined NOT_IN_libc +#if defined __PIC__ && !defined NOT_IN_libc ENTRY (__memcpy_chk) cmpq %rdx, %rcx jb HIDDEN_JUMPTARGET (__chk_fail) diff --git a/libc/string/x86_64/memset.S b/libc/string/x86_64/memset.S index 46751006b..562574a4d 100644 --- a/libc/string/x86_64/memset.S +++ b/libc/string/x86_64/memset.S @@ -29,7 +29,7 @@ #define LARGE $120000 .text -#if !BZERO_P && defined PIC && !defined NOT_IN_libc +#if !BZERO_P && defined __PIC__ && !defined NOT_IN_libc ENTRY (__memset_chk) cmpq %rdx, %rcx jb HIDDEN_JUMPTARGET (__chk_fail) @@ -142,6 +142,6 @@ END (memset) libc_hidden_def(memset) #endif -#if !BZERO_P && defined PIC && !defined NOT_IN_libc +#if !BZERO_P && defined __PIC__ && !defined NOT_IN_libc strong_alias (__memset_chk, __memset_zero_constant_len_parameter) #endif diff --git a/libc/sysdeps/linux/xtensa/sysdep.h b/libc/sysdeps/linux/xtensa/sysdep.h index 5708a8114..bd16b81a0 100644 --- a/libc/sysdeps/linux/xtensa/sysdep.h +++ b/libc/sysdeps/linux/xtensa/sysdep.h @@ -45,7 +45,7 @@ #define LITERAL_POSITION .literal_position #undef JUMPTARGET -#ifdef PIC +#ifdef __PIC__ /* The "@PLT" suffix is currently a no-op for non-shared linking, but it doesn't hurt to use it conditionally for PIC code in case that changes someday. */ -- cgit v1.2.3 From cbff4254e48ff39f5930f972edc6dc9213161727 Mon Sep 17 00:00:00 2001 From: Carmelo Amoroso Date: Wed, 16 Dec 2009 12:07:43 +0100 Subject: libc: Add missing header for memset Silence compiler warning by adding the missing string.h header to include memset prototype. Do some code tidy-up removing commented out libc_hidden_proto macros in the meanwhile. Signed-off-by: Carmelo Amoroso --- libc/signal/sigblock.c | 2 -- libc/signal/sigpause.c | 1 - libc/signal/sigset-cvt-mask.h | 2 ++ libc/signal/sigsetmask.c | 2 -- 4 files changed, 2 insertions(+), 5 deletions(-) (limited to 'libc') diff --git a/libc/signal/sigblock.c b/libc/signal/sigblock.c index c3b79d9ab..ad3acb0be 100644 --- a/libc/signal/sigblock.c +++ b/libc/signal/sigblock.c @@ -19,8 +19,6 @@ #define __UCLIBC_HIDE_DEPRECATED__ #include #include -#include - #include "sigset-cvt-mask.h" diff --git a/libc/signal/sigpause.c b/libc/signal/sigpause.c index e465fac7a..5280ee0a6 100644 --- a/libc/signal/sigpause.c +++ b/libc/signal/sigpause.c @@ -25,7 +25,6 @@ #include /* For NULL. */ #include - #include "sigset-cvt-mask.h" /* Set the mask of blocked signals to MASK, diff --git a/libc/signal/sigset-cvt-mask.h b/libc/signal/sigset-cvt-mask.h index 76dd01c7e..d4c2dc7ca 100644 --- a/libc/signal/sigset-cvt-mask.h +++ b/libc/signal/sigset-cvt-mask.h @@ -19,6 +19,8 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include + static __inline__ void __attribute__ ((unused)) sigset_set_old_mask (sigset_t *set, int mask) { diff --git a/libc/signal/sigsetmask.c b/libc/signal/sigsetmask.c index 6d0a505a7..64c8ad687 100644 --- a/libc/signal/sigsetmask.c +++ b/libc/signal/sigsetmask.c @@ -19,8 +19,6 @@ #define __UCLIBC_HIDE_DEPRECATED__ #include #include -#include - #include "sigset-cvt-mask.h" -- cgit v1.2.3 From 197b2de50d7c025b6a25e7e1cde7a5667728c15c Mon Sep 17 00:00:00 2001 From: Carmelo Amoroso Date: Wed, 16 Dec 2009 12:37:07 +0100 Subject: libc: Remove pointless header string.h It is already include from the internal header sigset-cvt-mask.h Signed-off-by: Carmelo Amoroso --- libc/signal/sigpause.c | 1 - 1 file changed, 1 deletion(-) (limited to 'libc') diff --git a/libc/signal/sigpause.c b/libc/signal/sigpause.c index 5280ee0a6..5f7ed699a 100644 --- a/libc/signal/sigpause.c +++ b/libc/signal/sigpause.c @@ -23,7 +23,6 @@ #define __FAVOR_BSD #include #include /* For NULL. */ -#include #include "sigset-cvt-mask.h" -- cgit v1.2.3 From e092e7c30464555b3fb81adc8f2f479e892b0786 Mon Sep 17 00:00:00 2001 From: Hans-Christian Egtvedt Date: Wed, 16 Dec 2009 13:12:00 +0100 Subject: check if USE_TLS is defined before use This patch will convert all the #ifdef USE_TLS and #if USE_TLS to #if defined(USE_TLS) && USE_TLS. By checking if the USE_TLS is defined before checking its value will result in correct behavior for architectures not defining this config symbol. Signed-off-by: Hans-Christian Egtvedt Acked-by: Carmelo AMOROSO --- libc/misc/elf/dl-support.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libc') diff --git a/libc/misc/elf/dl-support.c b/libc/misc/elf/dl-support.c index 3f5248128..665b62a24 100644 --- a/libc/misc/elf/dl-support.c +++ b/libc/misc/elf/dl-support.c @@ -13,14 +13,14 @@ #include #include -#if USE_TLS +#if defined(USE_TLS) && USE_TLS #include #include #include #include #endif -#if USE_TLS +#if defined(USE_TLS) && USE_TLS void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls; @@ -39,7 +39,7 @@ void internal_function _dl_aux_init (ElfW(auxv_t) *av) _dl_phnum = (size_t) av[AT_PHNUM].a_un.a_val; } -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* Initialize static TLS area and DTV for current (only) thread. libpthread implementations should provide their own hook to handle all threads. */ -- cgit v1.2.3 From 7dcd83e8bded560b6a2c658889995390d3021a92 Mon Sep 17 00:00:00 2001 From: Austin Foxley Date: Sat, 19 Dec 2009 13:35:52 -0800 Subject: x86_64: fix multiple definition of chk functions also enable __chk_fail and only try to call it when SSP is on Signed-off-by: Austin Foxley --- libc/string/x86_64/bzero.S | 1 + libc/string/x86_64/memcpy.S | 2 ++ libc/string/x86_64/mempcpy.S | 1 + libc/string/x86_64/memset.S | 4 +++- libc/sysdeps/linux/common/ssp.c | 3 +-- 5 files changed, 8 insertions(+), 3 deletions(-) (limited to 'libc') diff --git a/libc/string/x86_64/bzero.S b/libc/string/x86_64/bzero.S index 4d179ec4e..231d7cb41 100644 --- a/libc/string/x86_64/bzero.S +++ b/libc/string/x86_64/bzero.S @@ -1,5 +1,6 @@ #include #ifdef __UCLIBC_SUSV3_LEGACY__ # define memset bzero +# define __memset_chk __bzero_chk # include "memset.S" #endif diff --git a/libc/string/x86_64/memcpy.S b/libc/string/x86_64/memcpy.S index 011291447..6d941e0f2 100644 --- a/libc/string/x86_64/memcpy.S +++ b/libc/string/x86_64/memcpy.S @@ -29,7 +29,9 @@ #if defined __PIC__ && !defined NOT_IN_libc ENTRY (__memcpy_chk) cmpq %rdx, %rcx +#if defined __UCLIBC_HAS_SSP__ jb HIDDEN_JUMPTARGET (__chk_fail) +#endif END (__memcpy_chk) #endif ENTRY (BP_SYM (memcpy)) diff --git a/libc/string/x86_64/mempcpy.S b/libc/string/x86_64/mempcpy.S index 3816d9f72..b0607aa57 100644 --- a/libc/string/x86_64/mempcpy.S +++ b/libc/string/x86_64/mempcpy.S @@ -1,3 +1,4 @@ #define memcpy mempcpy +#define __memcpy_chk __mempcpy_chk #include "memcpy.S" libc_hidden_def(mempcpy) diff --git a/libc/string/x86_64/memset.S b/libc/string/x86_64/memset.S index 562574a4d..df265f394 100644 --- a/libc/string/x86_64/memset.S +++ b/libc/string/x86_64/memset.S @@ -29,10 +29,12 @@ #define LARGE $120000 .text -#if !BZERO_P && defined __PIC__ && !defined NOT_IN_libc +#if defined __PIC__ && !defined NOT_IN_libc ENTRY (__memset_chk) cmpq %rdx, %rcx +#if defined __UCLIBC_HAS_SSP__ jb HIDDEN_JUMPTARGET (__chk_fail) +#endif END (__memset_chk) #endif ENTRY (memset) diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c index 69611cab5..a2d7ff2ca 100644 --- a/libc/sysdeps/linux/common/ssp.c +++ b/libc/sysdeps/linux/common/ssp.c @@ -100,7 +100,6 @@ void __stack_chk_fail(void) terminate(); } -#if 0 void __chk_fail(void) attribute_noreturn; void __chk_fail(void) { @@ -115,4 +114,4 @@ void __chk_fail(void) while(1) terminate(); } -#endif + -- cgit v1.2.3 From 23528282b771d1af3df0fa17f1e909ad3b663f59 Mon Sep 17 00:00:00 2001 From: Freeman Wang Date: Sat, 19 Dec 2009 13:43:00 -0800 Subject: malloc: fix race condition and other bugs in the no-mmu malloc Fixes multiple race conditions on mmb list. This was done by making the mmb_heap_lock into a recursive lock and making the regular heap_lock extend to cover the mmb heap handling. Also move the new_mmb allocation up to before the mmb list is iterated through to find the insertion point. When the mmb_heap also runs out and needs to be extended when the regular heap is just extended, the mmb list could be messed up. Signed-off-by: Freeman Wang Signed-off-by: Austin Foxley --- libc/stdlib/malloc/free.c | 6 +++--- libc/stdlib/malloc/malloc.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'libc') diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c index c17e7ec2a..e7b6a290a 100644 --- a/libc/stdlib/malloc/free.c +++ b/libc/stdlib/malloc/free.c @@ -177,14 +177,14 @@ __free_to_heap (void *mem, struct heap_free_area **heap /* Start searching again from the end of this block. */ start = mmb_end; + /* Release the descriptor block we used. */ + free_to_heap (mmb, &__malloc_mmb_heap, &__malloc_mmb_heap_lock); + /* We have to unlock the heap before we recurse to free the mmb descriptor, because we might be unmapping from the mmb heap. */ __heap_unlock (heap_lock); - /* Release the descriptor block we used. */ - free_to_heap (mmb, &__malloc_mmb_heap, &__malloc_mmb_heap_lock); - /* Do the actual munmap. */ munmap ((void *)mmb_start, mmb_end - mmb_start); diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index 337206f09..d58a7d0ee 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/libc/stdlib/malloc/malloc.c @@ -46,7 +46,7 @@ struct malloc_mmb *__malloc_mmapped_blocks = 0; HEAP_DECLARE_STATIC_FREE_AREA (initial_mmb_fa, 48); /* enough for 3 mmbs */ struct heap_free_area *__malloc_mmb_heap = HEAP_INIT_WITH_FA (initial_mmb_fa); #ifdef HEAP_USE_LOCKING -malloc_mutex_t __malloc_mmb_heap_lock = PTHREAD_MUTEX_INITIALIZER; +malloc_mutex_t __malloc_mmb_heap_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; #endif #endif /* __UCLIBC_UCLINUX_BROKEN_MUNMAP__ */ @@ -149,19 +149,19 @@ __malloc_from_heap (size_t size, struct heap_free_area **heap /* Try again to allocate. */ mem = __heap_alloc (heap, &size); - __heap_unlock (heap_lock); #if !defined(MALLOC_USE_SBRK) && defined(__UCLIBC_UCLINUX_BROKEN_MUNMAP__) /* Insert a record of BLOCK in sorted order into the __malloc_mmapped_blocks list. */ + new_mmb = malloc_from_heap (sizeof *new_mmb, &__malloc_mmb_heap, &__malloc_mmb_heap_lock); + for (prev_mmb = 0, mmb = __malloc_mmapped_blocks; mmb; prev_mmb = mmb, mmb = mmb->next) if (block < mmb->mem) break; - new_mmb = malloc_from_heap (sizeof *new_mmb, &__malloc_mmb_heap, &__malloc_mmb_heap_lock); new_mmb->next = mmb; new_mmb->mem = block; new_mmb->size = block_size; @@ -175,6 +175,7 @@ __malloc_from_heap (size_t size, struct heap_free_area **heap (unsigned)new_mmb, (unsigned)new_mmb->mem, block_size); #endif /* !MALLOC_USE_SBRK && __UCLIBC_UCLINUX_BROKEN_MUNMAP__ */ + __heap_unlock (heap_lock); } } -- cgit v1.2.3