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 +- .../linuxthreads/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h | 4 ++-- .../linuxthreads/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h | 4 ++-- .../linuxthreads/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h | 8 ++++---- .../linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h | 6 +++--- .../linuxthreads/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h | 8 ++++---- libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/vfork.S | 2 +- .../sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h | 4 ++-- .../linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h | 6 +++--- 11 files changed, 25 insertions(+), 25 deletions(-) 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. */ diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h index 9ea779e0d..5d686299c 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h @@ -118,7 +118,7 @@ __LABEL($syscall_error) \ # define __local_multiple_threads __libc_multiple_threads # endif -# ifdef PIC +# ifdef __PIC__ # define CENABLE bsr ra, __local_enable_asynccancel !samegp # define CDISABLE bsr ra, __local_disable_asynccancel !samegp # else @@ -130,7 +130,7 @@ __LABEL($syscall_error) \ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P \ __builtin_expect (__local_multiple_threads == 0, 1) -# elif defined(PIC) +# elif defined(__PIC__) # define SINGLE_THREAD_P(reg) ldl reg, __local_multiple_threads(gp) !gprel # else # define SINGLE_THREAD_P(reg) \ diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h index 75fcf54fa..3937808d5 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h @@ -27,7 +27,7 @@ /* We push lr onto the stack, so we have to use ldmib instead of ldmia to find the saved arguments. */ -# ifdef PIC +# ifdef __PIC__ # undef DOARGS_5 # undef DOARGS_6 # undef DOARGS_7 @@ -105,7 +105,7 @@ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # else -# if !defined PIC +# if !defined __PIC__ # define SINGLE_THREAD_P \ ldr ip, =__local_multiple_threads; \ ldr ip, [ip]; \ diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h index 134977e07..7b210ff11 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h @@ -104,7 +104,7 @@ # define POPARGS_6 POPARGS_5 ldw -54(%sr0,%sp), %r21 ASM_LINE_SEP # ifdef IS_IN_libpthread -# ifdef PIC +# ifdef __PIC__ # define CENABLE .import __pthread_enable_asynccancel,code ASM_LINE_SEP \ bl __pthread_enable_asynccancel,%r2 ASM_LINE_SEP # define CDISABLE .import __pthread_disable_asynccancel,code ASM_LINE_SEP \ @@ -116,7 +116,7 @@ bl __pthread_disable_asynccancel,%r2 ASM_LINE_SEP # endif # elif !defined NOT_IN_libc -# ifdef PIC +# ifdef __PIC__ # define CENABLE .import __libc_enable_asynccancel,code ASM_LINE_SEP \ bl __libc_enable_asynccancel,%r2 ASM_LINE_SEP # define CDISABLE .import __libc_disable_asynccancel,code ASM_LINE_SEP \ @@ -128,7 +128,7 @@ bl __libc_disable_asynccancel,%r2 ASM_LINE_SEP # endif # else -# ifdef PIC +# ifdef __PIC__ # define CENABLE .import __librt_enable_asynccancel,code ASM_LINE_SEP \ bl __librt_enable_asynccancel,%r2 ASM_LINE_SEP # define CDISABLE .import __librt_disable_asynccancel,code ASM_LINE_SEP \ @@ -167,7 +167,7 @@ nop ASM_LINE_SEP \ ldw MULTIPLE_THREADS_OFFSET(%sr0,%ret0),%ret0 ASM_LINE_SEP \ Lstp: ASM_LINE_SEP -# ifdef PIC +# ifdef __PIC__ /* Slower version uses GOT to get value of __local_multiple_threads */ # define SINGLE_THREAD_P \ addil LT%__local_multiple_threads, %r19 ASM_LINE_SEP \ diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h index a5dbeff1e..0bb16e453 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h @@ -101,7 +101,7 @@ # define CENABLE call __pthread_enable_asynccancel; # define CDISABLE call __pthread_disable_asynccancel # elif defined IS_IN_librt -# ifdef PIC +# ifdef __PIC__ # define CENABLE pushl %ebx; \ call __i686.get_pc_thunk.bx; \ addl $_GLOBAL_OFFSET_TABLE_, %ebx; \ @@ -139,7 +139,7 @@ #endif # ifndef __ASSEMBLER__ -# if defined FLOATING_STACKS && USE___THREAD && defined PIC +# if defined FLOATING_STACKS && USE___THREAD && defined __PIC__ # define SINGLE_THREAD_P \ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ p_header.data.multiple_threads) == 0, 1) @@ -153,7 +153,7 @@ extern int __local_multiple_threads # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # endif # else -# if !defined PIC +# if !defined __PIC__ # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads # elif defined FLOATING_STACKS && USE___THREAD # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h index bb798e40d..9cd56755e 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h @@ -77,7 +77,7 @@ # define UNDOCARGS_5 UNDOCARGS_4; move.l (%sp)+, %d5; # ifdef IS_IN_libpthread -# ifdef PIC +# ifdef __PIC__ # define CENABLE jbsr __pthread_enable_asynccancel@PLTPC # define CDISABLE jbsr __pthread_disable_asynccancel@PLTPC # else @@ -85,7 +85,7 @@ # define CDISABLE jbsr __pthread_disable_asynccancel # endif # elif !defined NOT_IN_libc -# ifdef PIC +# ifdef __PIC__ # define CENABLE jbsr __libc_enable_asynccancel@PLTPC # define CDISABLE jbsr __libc_disable_asynccancel@PLTPC # else @@ -93,7 +93,7 @@ # define CDISABLE jbsr __libc_disable_asynccancel # endif # else -# ifdef PIC +# ifdef __PIC__ # define CENABLE jbsr __librt_enable_asynccancel@PLTPC # define CDISABLE jbsr __librt_disable_asynccancel@PLTPC # else @@ -114,7 +114,7 @@ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # else -# if !defined PIC +# if !defined __PIC__ # define SINGLE_THREAD_P tst.l __local_multiple_threads # else # define SINGLE_THREAD_P tst.l (__local_multiple_threads, %pc) diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/vfork.S b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/vfork.S index 9f304abbe..8a43ea0db 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/vfork.S +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/m68k/vfork.S @@ -56,7 +56,7 @@ ENTRY (__vfork) movel %a0,%sp@- # ifdef __ASSUME_VFORK_SYSCALL -# ifndef PIC +# ifndef __PIC__ jbra SYSCALL_ERROR_LABEL # endif # else diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h index 865da8e8c..9925a2f53 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h @@ -89,7 +89,7 @@ # else # define CENABLE bl JUMPTARGET(__librt_enable_asynccancel) # define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel) -# if defined HAVE_AS_REL16 && defined PIC +# if defined HAVE_AS_REL16 && defined __PIC__ # undef CGOTSETUP # define CGOTSETUP \ bcl 20,31,1f; \ @@ -122,7 +122,7 @@ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # else -# if !defined PIC +# if !defined __PIC__ # define SINGLE_THREAD_P \ lis 10,__local_multiple_threads@ha; \ lwz 10,__local_multiple_threads@l(10); \ diff --git a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h index 03c6fedbf..48b2caadd 100644 --- a/libpthread/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h +++ b/libpthread/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h @@ -102,7 +102,7 @@ # define __local_multiple_threads __librt_multiple_threads # endif -# if defined IS_IN_librt && defined PIC +# if defined IS_IN_librt && defined __PIC__ # define CENABLE \ mov.l r12,@-r15; \ mov.l 1f,r12; \ @@ -155,7 +155,7 @@ # endif # ifndef __ASSEMBLER__ -# if defined FLOATING_STACKS && USE___THREAD && defined PIC +# if defined FLOATING_STACKS && USE___THREAD && defined __PIC__ # define SINGLE_THREAD_P \ __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1) # else @@ -163,7 +163,7 @@ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # endif # else -# if !defined PIC +# if !defined __PIC__ # define SINGLE_THREAD_P \ mov.l 1f,r0; \ mov.l @r0,r0; \ -- 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(-) 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(-) 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 --- include/link.h | 2 +- ldso/include/dl-hash.h | 4 ++-- ldso/ldso/dl-elf.c | 8 ++++---- ldso/ldso/dl-hash.c | 4 ++-- ldso/ldso/dl-startup.c | 2 +- ldso/ldso/ldso.c | 18 +++++++++--------- ldso/libdl/libdl.c | 20 ++++++++++---------- libc/misc/elf/dl-support.c | 6 +++--- libpthread/linuxthreads.old/pthread.c | 6 +++--- libpthread/linuxthreads.old_db/td_thr_tls_get_addr.c | 2 +- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/link.h b/include/link.h index ec863c989..cbef6165a 100644 --- a/include/link.h +++ b/include/link.h @@ -104,7 +104,7 @@ struct link_map ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */ struct link_map *l_next, *l_prev; /* Chain of loaded objects. */ -#ifdef USE_TLS +#if defined(USE_TLS) && USE_TLS /* Thread-local storage related info. */ /* Start of the initialization image. */ diff --git a/ldso/include/dl-hash.h b/ldso/include/dl-hash.h index 22042145e..34333f40f 100644 --- a/ldso/include/dl-hash.h +++ b/ldso/include/dl-hash.h @@ -35,7 +35,7 @@ struct elf_resolve { struct elf_resolve * prev; /* Nothing after this address is used by gdb. */ -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* Thread-local storage related info. */ /* Start of the initialization image. */ @@ -138,7 +138,7 @@ extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname, unsigned long dynamic_addr, unsigned long dynamic_size); /* Only need extra arg with some configurations */ -#if !(USE_TLS || defined __FDPIC__) +#if !((defined(USE_TLS) && USE_TLS) || defined __FDPIC__) # define _dl_lookup_hash(n, r, m, c, t) _dl_lookup_hash(n, r, m, c) #endif extern char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 6bf5bbd6a..a0db63750 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -329,7 +329,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, ElfW(Dyn) *dpnt; struct elf_resolve *tpnt; ElfW(Phdr) *ppnt; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS ElfW(Phdr) *tlsppnt = NULL; #endif char *status, *header; @@ -437,7 +437,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, } } if (ppnt->p_type == PT_TLS) { -#if USE_TLS +#if defined(USE_TLS) && USE_TLS if (ppnt->p_memsz == 0) /* Nothing to do for an empty segment. */ continue; @@ -733,7 +733,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, tpnt->ppnt = (ElfW(Phdr) *) DL_RELOC_ADDR(tpnt->loadaddr, epnt->e_phoff); tpnt->n_phent = epnt->e_phnum; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS if (tlsppnt) { _dl_debug_early("Found TLS header for %s\n", libname); #if NO_TLS_OFFSET != 0 @@ -875,7 +875,7 @@ int _dl_fixup(struct dyn_elf *rpnt, int now_flag) #if 0 /* _dl_add_to_slotinfo is called by init_tls() for initial DSO or by dlopen() for dynamically loaded DSO. */ -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* Add object to slot information data if necessasy. */ if (tpnt->l_tls_blocksize != 0 && tls_init_tp_called) _dl_add_to_slotinfo ((struct link_map *) tpnt); diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c index 6d54f37b9..0048734ba 100644 --- a/ldso/ldso/dl-hash.c +++ b/ldso/ldso/dl-hash.c @@ -158,7 +158,7 @@ static __attribute_noinline__ const ElfW(Sym) * check_match (const ElfW(Sym) *sym, char *strtab, const char* undef_name, int type_class) { -#if USE_TLS +#if defined(USE_TLS) && USE_TLS if ((sym->st_value == 0 && (ELF_ST_TYPE(sym->st_info) != STT_TLS)) || (type_class & (sym->st_shndx == SHN_UNDEF))) /* No value or undefined symbol itself */ @@ -335,7 +335,7 @@ char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve if (sym) { /* At this point we have found the requested symbol, do binding */ -#if USE_TLS +#if defined(USE_TLS) && USE_TLS if (ELF_ST_TYPE(sym->st_info) == STT_TLS) { _dl_assert(tpntp != NULL); *tpntp = tpnt; diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c index 91b11dc7f..a51b583a4 100644 --- a/ldso/ldso/dl-startup.c +++ b/ldso/ldso/dl-startup.c @@ -215,7 +215,7 @@ DL_START(unsigned long args) * more work than what is done below for the * loader will have to happen. */ -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* This was done by _dl_memset above. */ /* tpnt->l_tls_modid = 0; */ # if NO_TLS_OFFSET != 0 diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index bb414b14a..1f5c87a0d 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -38,7 +38,7 @@ #define ALLOW_ZERO_PLTGOT -#if USE_TLS +#if defined(USE_TLS) && USE_TLS #include "dl-tls.c" #endif @@ -225,7 +225,7 @@ void _dl_free(void *p) (*_dl_free_function) (p); } -#if USE_TLS +#if defined(USE_TLS) && USE_TLS void *_dl_memalign(size_t __boundary, size_t __size) { void *result; @@ -294,7 +294,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, ElfW(Addr) relro_addr = 0; size_t relro_size = 0; struct stat st; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS void *tcbp = NULL; #endif @@ -371,7 +371,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, unlazy = RTLD_NOW; } -#if USE_TLS +#if defined(USE_TLS) && USE_TLS _dl_error_catch_tsd = &_dl_initial_error_catch_tsd; _dl_init_static_tls = &_dl_nothread_init_static_tls; #endif @@ -504,7 +504,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, /* Discover any TLS sections if the target supports them. */ if (ppnt->p_type == PT_TLS) { -#if USE_TLS +#if defined(USE_TLS) && USE_TLS if (ppnt->p_memsz > 0) { app_tpnt->l_tls_blocksize = ppnt->p_memsz; app_tpnt->l_tls_align = ppnt->p_align; @@ -531,7 +531,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, app_tpnt->relro_addr = relro_addr; app_tpnt->relro_size = relro_size; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* * Adjust the address of the TLS initialization image in * case the executable is actually an ET_DYN object. @@ -931,7 +931,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, } #endif -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* We do not initialize any of the TLS functionality unless any of the * initial modules uses TLS. This makes dynamic loading of modules with * TLS impossible, but to support it requires either eagerly doing setup @@ -971,7 +971,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, _dl_protect_relro (tpnt); } -#if USE_TLS +#if defined(USE_TLS) && USE_TLS if (!was_tls_init_tp_called && _dl_tls_max_dtv_idx > 0) ++_dl_tls_generation; @@ -1058,7 +1058,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, _dl_malloc_function = (void* (*)(size_t)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "malloc", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL); -#if USE_TLS +#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", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL); diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c index 22b622d28..05a68ddcc 100644 --- a/ldso/libdl/libdl.c +++ b/ldso/libdl/libdl.c @@ -39,14 +39,14 @@ #include #endif -#if USE_TLS +#if defined(USE_TLS) && USE_TLS #include extern void (*_dl_init_static_tls) (struct link_map *); extern void _dl_add_to_slotinfo(struct link_map *l); #endif #ifdef SHARED -# if USE_TLS +# if defined(USE_TLS) && USE_TLS # include extern struct link_map *_dl_update_slotinfo(unsigned long int req_modid); # endif @@ -112,7 +112,7 @@ struct r_debug *_dl_debug_addr = NULL; #include "../ldso/dl-debug.c" -# if USE_TLS +# if defined(USE_TLS) && USE_TLS /* * Giving this initialized value preallocates some surplus bytes in the * static TLS area, see __libc_setup_tls (libc-tls.c). @@ -166,7 +166,7 @@ static const char *const dl_error_names[] = { }; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS #ifdef SHARED /* * Systems which do not have tls_index also probably have to define @@ -284,7 +284,7 @@ void *dlopen(const char *libname, int flag) unsigned int nlist, i; struct elf_resolve **init_fini_list; static bool _dl_init; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS bool any_tls = false; #endif @@ -519,7 +519,7 @@ void *dlopen(const char *libname, int flag) /* TODO: Should we set the protections of all pages back to R/O now ? */ -#if USE_TLS +#if defined(USE_TLS) && USE_TLS for (i=0; i < nlist; i++) { struct elf_resolve *tmp_tpnt = init_fini_list[i]; @@ -670,7 +670,7 @@ void *dlsym(void *vhandle, const char *name) tpnt = handle->dyn; /* Only search RTLD_GLOBAL objs if global object */ ret = _dl_find_hash(name2, handle, NULL, 0, &tls_tpnt); -#if defined USE_TLS && defined SHARED +#if defined(USE_TLS) && USE_TLS && defined SHARED if (tls_tpnt) { /* The found symbol is a thread-local storage variable. Return the address for to the current thread. */ @@ -709,7 +709,7 @@ static int do_dlclose(void *vhandle, int need_fini) struct dyn_elf *handle; unsigned int end; unsigned int i, j; -#if USE_TLS +#if defined(USE_TLS) && USE_TLS bool any_tls = false; size_t tls_free_start = NO_TLS_OFFSET; size_t tls_free_end = NO_TLS_OFFSET; @@ -771,7 +771,7 @@ static int do_dlclose(void *vhandle, int need_fini) end = ppnt->p_vaddr + ppnt->p_memsz; } -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* Do the cast to make things easy. */ tls_lmap = (struct link_map *) tpnt; @@ -924,7 +924,7 @@ static int do_dlclose(void *vhandle, int need_fini) free(handle->init_fini.init_fini); free(handle); -#if USE_TLS +#if defined(USE_TLS) && USE_TLS /* If we removed any object which uses TLS bump the generation counter. */ if (any_tls) { if (__builtin_expect(++_dl_tls_generation == 0, 0)) { 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. */ diff --git a/libpthread/linuxthreads.old/pthread.c b/libpthread/linuxthreads.old/pthread.c index c988131fc..ad392e34e 100644 --- a/libpthread/linuxthreads.old/pthread.c +++ b/libpthread/linuxthreads.old/pthread.c @@ -537,7 +537,7 @@ int __pthread_initialize_manager(void) } /* Start the thread manager */ pid = 0; -#ifdef USE_TLS +#if defined(USE_TLS) && USE_TLS if (__linuxthreads_initial_report_events != 0) THREAD_SETMEM (((pthread_descr) NULL), p_report_events, __linuxthreads_initial_report_events); @@ -710,7 +710,7 @@ static pthread_descr thread_self_stack(void) if (sp >= __pthread_manager_thread_bos && sp < __pthread_manager_thread_tos) return manager_thread; h = __pthread_handles + 2; -# ifdef USE_TLS +# if defined(USE_TLS) && USE_TLS while (h->h_descr == NULL || ! (sp <= (char *) h->h_descr->p_stackaddr && sp >= h->h_bottom)) h++; @@ -845,7 +845,7 @@ static void pthread_handle_sigcancel(int sig) /* Main thread should accumulate times for thread manager and its children, so that timings for main thread account for all threads. */ if (self == __pthread_main_thread) { -#ifdef USE_TLS +#if defined(USE_TLS) && USE_TLS waitpid(__pthread_manager_thread->p_pid, NULL, __WCLONE); #else waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE); diff --git a/libpthread/linuxthreads.old_db/td_thr_tls_get_addr.c b/libpthread/linuxthreads.old_db/td_thr_tls_get_addr.c index 19821d6e7..8e38b6904 100644 --- a/libpthread/linuxthreads.old_db/td_thr_tls_get_addr.c +++ b/libpthread/linuxthreads.old_db/td_thr_tls_get_addr.c @@ -31,7 +31,7 @@ td_thr_tls_get_addr (const td_thrhandle_t *th __attribute__ ((unused)), size_t offset __attribute__ ((unused)), void **address __attribute__ ((unused))) { -#ifdef USE_TLS +#if defined(USE_TLS) && USE_TLS size_t modid; union dtv pdtv, *dtvp; -- 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(-) 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(-) 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