From 464dc022eb0be4950e2f3a90fe4de6a17dc3d7d7 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 20 Aug 2009 15:31:08 -0700 Subject: [PATCH 01/11] Improve backtrace_symbols{,_fd} output when missing symbols. --- ChangeLog | 9 ++++ sysdeps/generic/elf/backtracesyms.c | 71 +++++++++++++++++---------- sysdeps/generic/elf/backtracesymsfd.c | 58 ++++++++++++++-------- 3 files changed, 92 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39bbb2ab9c..6ace54badd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-08-20 Roland McGrath + + * sysdeps/generic/elf/backtracesyms.c (__backtrace_symbols): + Use l_addr instead of l_map_start (dli_fbase). + Print "FILE([+-]OFFSET) [ADDRESS]" with the file-relative + address when there is no proximate symbol. + * sysdeps/generic/elf/backtracesymsfd.c (__backtrace_symbols_fd): + Likewise. + 2009-08-16 Ulrich Drepper * scripts/gen-as-const.awk: Fix test for 64-bit platform. diff --git a/sysdeps/generic/elf/backtracesyms.c b/sysdeps/generic/elf/backtracesyms.c index b31be6ac5d..319b207605 100644 --- a/sysdeps/generic/elf/backtracesyms.c +++ b/sysdeps/generic/elf/backtracesyms.c @@ -1,5 +1,5 @@ /* Return list with names for address in backtrace. - Copyright (C) 1998,1999,2000,2001,2003 Free Software Foundation, Inc. + Copyright (C) 1998,1999,2000,2001,2003,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1998. @@ -48,15 +48,22 @@ __backtrace_symbols (array, size) /* Fill in the information we can get from `dladdr'. */ for (cnt = 0; cnt < size; ++cnt) { - status[cnt] = _dl_addr (array[cnt], &info[cnt], NULL, NULL); + struct link_map *map; + status[cnt] = _dl_addr (array[cnt], &info[cnt], &map, NULL); if (status[cnt] && info[cnt].dli_fname && info[cnt].dli_fname[0] != '\0') - /* We have some info, compute the length of the string which will be - "() [+offset]. */ - total += (strlen (info[cnt].dli_fname ?: "") - + (info[cnt].dli_sname - ? strlen (info[cnt].dli_sname) + 3 + WORD_WIDTH + 3 - : 1) - + WORD_WIDTH + 5); + { + /* We have some info, compute the length of the string which will be + "(+offset) [address]. */ + total += (strlen (info[cnt].dli_fname ?: "") + + strlen (info[cnt].dli_sname ?: "") + + 3 + WORD_WIDTH + 3 + WORD_WIDTH + 5); + + /* The load bias is more useful to the user than the load + address. The use of these addresses is to calculate an + address in the ELF file, so its prelinked bias is not + something we want to subtract out. */ + info[cnt].dli_fbase = (void *) map->l_addr; + } else total += 5 + WORD_WIDTH; } @@ -71,25 +78,39 @@ __backtrace_symbols (array, size) { result[cnt] = last; - if (status[cnt] && info[cnt].dli_fname - && info[cnt].dli_fname[0] != '\0') + if (status[cnt] + && info[cnt].dli_fname != NULL && info[cnt].dli_fname[0] != '\0') { - char buf[20]; + if (info[cnt].dli_sname == NULL) + /* We found no symbol name to use, so describe it as + relative to the file. */ + info[cnt].dli_saddr = info[cnt].dli_fbase; - if (array[cnt] >= (void *) info[cnt].dli_saddr) - sprintf (buf, "+%#lx", - (unsigned long)(array[cnt] - info[cnt].dli_saddr)); + if (info[cnt].dli_sname == NULL && info[cnt].dli_saddr == 0) + last += 1 + sprintf (last, "%s(%s) [%p]", + info[cnt].dli_fname ?: "", + info[cnt].dli_sname ?: "", + array[cnt]); else - sprintf (buf, "-%#lx", - (unsigned long)(info[cnt].dli_saddr - array[cnt])); - - last += 1 + sprintf (last, "%s%s%s%s%s[%p]", - info[cnt].dli_fname ?: "", - info[cnt].dli_sname ? "(" : "", - info[cnt].dli_sname ?: "", - info[cnt].dli_sname ? buf : "", - info[cnt].dli_sname ? ") " : " ", - array[cnt]); + { + char sign; + ptrdiff_t offset; + if (array[cnt] >= (void *) info[cnt].dli_saddr) + { + sign = '+'; + offset = array[cnt] - info[cnt].dli_saddr; + } + else + { + sign = '-'; + offset = info[cnt].dli_saddr - array[cnt]; + } + + last += 1 + sprintf (last, "%s(%s%c%#tx) [%p]", + info[cnt].dli_fname ?: "", + info[cnt].dli_sname ?: "", + sign, offset, array[cnt]); + } } else last += 1 + sprintf (last, "[%p]", array[cnt]); diff --git a/sysdeps/generic/elf/backtracesymsfd.c b/sysdeps/generic/elf/backtracesymsfd.c index 6754d145b0..f0ab71587f 100644 --- a/sysdeps/generic/elf/backtracesymsfd.c +++ b/sysdeps/generic/elf/backtracesymsfd.c @@ -1,5 +1,5 @@ /* Write formatted list with names for addresses in backtrace to a file. - Copyright (C) 1998, 2000, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1998,2000,2003,2005,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1998. @@ -46,47 +46,63 @@ __backtrace_symbols_fd (array, size, fd) { char buf[WORD_WIDTH]; Dl_info info; + struct link_map *map; size_t last = 0; - if (_dl_addr (array[cnt], &info, NULL, NULL) - && info.dli_fname && info.dli_fname[0] != '\0') + if (_dl_addr (array[cnt], &info, &map, NULL) + && info.dli_fname != NULL && info.dli_fname[0] != '\0') { /* Name of the file. */ iov[0].iov_base = (void *) info.dli_fname; iov[0].iov_len = strlen (info.dli_fname); last = 1; - /* Symbol name. */ - if (info.dli_sname != NULL) + if (info.dli_sname != NULL || map->l_addr != 0) { char buf2[WORD_WIDTH]; size_t diff; - iov[1].iov_base = (void *) "("; - iov[1].iov_len = 1; - iov[2].iov_base = (void *) info.dli_sname; - iov[2].iov_len = strlen (info.dli_sname); + iov[last].iov_base = (void *) "("; + iov[last].iov_len = 1; + ++last; + + if (info.dli_sname != NULL) + { + /* We have a symbol name. */ + iov[last].iov_base = (void *) info.dli_sname; + iov[last].iov_len = strlen (info.dli_sname); + ++last; + } + else + /* We have no symbol, so describe it as relative to the file. + The load bias is more useful to the user than the load + address. The use of these addresses is to calculate an + address in the ELF file, so its prelinked bias is not + something we want to subtract out. */ + info.dli_saddr = (void *) map->l_addr; if (array[cnt] >= (void *) info.dli_saddr) { - iov[3].iov_base = (void *) "+0x"; + iov[last].iov_base = (void *) "+0x"; diff = array[cnt] - info.dli_saddr; } else { - iov[3].iov_base = (void *) "-0x"; + iov[last].iov_base = (void *) "-0x"; diff = info.dli_saddr - array[cnt]; } - iov[3].iov_len = 3; - - iov[4].iov_base = _itoa_word ((unsigned long int) diff, - &buf2[WORD_WIDTH], 16, 0); - iov[4].iov_len = &buf2[WORD_WIDTH] - (char *) iov[4].iov_base; - - iov[5].iov_base = (void *) ")"; - iov[5].iov_len = 1; - - last = 6; + iov[last].iov_len = 3; + ++last; + + iov[last].iov_base = _itoa_word ((unsigned long int) diff, + &buf2[WORD_WIDTH], 16, 0); + iov[last].iov_len = (&buf2[WORD_WIDTH] + - (char *) iov[last].iov_base); + ++last; + + iov[last].iov_base = (void *) ")"; + iov[last].iov_len = 1; + ++last; } } From 15efafdf07789322219cc8f938ac758f932fe208 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sat, 22 Aug 2009 02:01:51 -0700 Subject: [PATCH 02/11] Add sigstack handling to Linux ____longjmp_chk on powerpc. --- ChangeLog | 9 ++ nptl/pthread_rwlock_init.c | 13 +- .../sysv/linux/x86_64/pthread_rwlock_rdlock.S | 122 ++++++++++++++++ .../linux/x86_64/pthread_rwlock_timedrdlock.S | 138 ++++++++++++++++++ .../linux/x86_64/pthread_rwlock_timedwrlock.S | 104 +++++++++++++ .../sysv/linux/x86_64/pthread_rwlock_unlock.S | 92 ++++++++++++ .../sysv/linux/x86_64/pthread_rwlock_wrlock.S | 89 +++++++++++ sysdeps/powerpc/powerpc32/__longjmp-common.S | 15 +- .../powerpc/powerpc32/fpu/__longjmp-common.S | 15 +- .../powerpc/powerpc32/____longjmp_chk.S | 31 +++- .../powerpc/powerpc64/____longjmp_chk.S | 32 +++- 11 files changed, 633 insertions(+), 27 deletions(-) rename sysdeps/{ => unix/sysv/linux}/powerpc/powerpc32/____longjmp_chk.S (69%) rename sysdeps/{ => unix/sysv/linux}/powerpc/powerpc64/____longjmp_chk.S (63%) diff --git a/ChangeLog b/ChangeLog index 6ace54badd..7e88049818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-08-21 Andreas Schwab + + * sysdeps/powerpc/powerpc32/____longjmp_chk.S: Removed. + * sysdeps/powerpc/powerpc64/____longjmp_chk.S: Removed. + * sysdeps/unix/sysv/linux/powerpc/powerpc32/____longjmp_chk.S: New file. + * sysdeps/unix/sysv/linux/powerpc/powerpc64/____longjmp_chk.S: New file. + * sysdeps/powerpc/powerpc32/__longjmp-common.S: Move CHECK_SP earlier. + * sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S: Likewise. + 2009-08-20 Roland McGrath * sysdeps/generic/elf/backtracesyms.c (__backtrace_symbols): diff --git a/nptl/pthread_rwlock_init.c b/nptl/pthread_rwlock_init.c index 27f25ac2ab..95d9da4005 100644 --- a/nptl/pthread_rwlock_init.c +++ b/nptl/pthread_rwlock_init.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -37,13 +37,7 @@ __pthread_rwlock_init (rwlock, attr) iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_attr; - rwlock->__data.__lock = 0; - rwlock->__data.__nr_readers = 0; - rwlock->__data.__readers_wakeup = 0; - rwlock->__data.__writer_wakeup = 0; - rwlock->__data.__nr_readers_queued = 0; - rwlock->__data.__nr_writers_queued = 0; - rwlock->__data.__writer = 0; + memset (rwlock, '\0', sizeof (*rwlock)); rwlock->__data.__flags = iattr->lockkind == PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP; @@ -74,9 +68,6 @@ __pthread_rwlock_init (rwlock, attr) header.private_futex)); #endif - rwlock->__data.__pad1 = 0; - rwlock->__data.__pad2 = 0; - return 0; } strong_alias (__pthread_rwlock_init, pthread_rwlock_init) diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S index 35eb09cd0c..54a47e111f 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S @@ -31,6 +31,127 @@ .align 16 __pthread_rwlock_rdlock: cfi_startproc + movq $NRW_RC, %rax + LOCK + xaddq %rax, NRW_WORD(%rdi) + js .Lundo + +.Lagain1: + movq $(NRW_WL|NRW_WP), %rcx + movq $(NRW_WL|NRW_WW_MASK), %rdx + testq %rax, %rcx + setnz %cl + testq %rax, %rdx + setnz %dl + orb %cl, %dl + jnz .Lwait + + xorl %eax, %eax + ret + +.Lwait: movq $NRW_WL, %rcx + testq %rcx, %rax + jz 4f + + movl %fs:TID, %ecx + cmpl %ecx, WRITER(%rdi) + je .Ldeadlk + +4: xorq %r8, %r8 + movq $NRW_RC, %rdx + addq %rdx, %rax + movq $(NRW_WL|NRW_AR), %rcx + movq $(NRW_WP|NRW_WW_MASK), %rdx + testq %rax, %rcx + setz %cl + testq %rax, %rdx + setnz %dl + testb %dl, %cl + jz 1f + + movq $NRW_RW-NRW_RC, %rdx + addq %rax, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain1 + + movq $NRW_RC_MASK, %rax + testq %rdx, %rax + movl $1, %r8d + jz .Lwake_waiter + +1: xorq %r10, %r10 + movl $NRW_R_WAKEUP, %r9d + movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG), %esi + xorl PSHARED(%rdi), %esi + leaq NRW_WORD+4(%rdi), %rdi +2: shldq $32, %rax, %rdx + movl $__NR_futex, %eax + syscall + movq -4(%rdi), %rax + +5: movq $(NRW_WL|NRW_WP), %rcx + movq $(NRW_WL|NRW_WW_MASK), %rdx + testq %rax, %rcx + setnz %cl + testq %rax, %rdx + setnz %dl + orb %cl, %dl + jnz 2b + + testl %r8d, %r8d + jz 3f + + movq $NRW_RC-NRW_RW, %rcx + addq %rcx, %rdx + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz 5b + +3: xorl %eax, %eax + ret + +.Lwake_waiter: + movq %rdx, %r10 + movl $__NR_futex, %eax + movl $(FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG), %esi + xorl PSHARED(%rdi), %esi + leaq NRW_WORD(%rdi), %rdi + movl $1, %edx + movl $NRW_W_WAKEUP, %r9d + syscall + leaq -NRW_WORD(%rdi), %rdi + movq %r10, %rdx + jmp 1b + +.Lundo: movq $-NRW_RC, %rcx + movq %rax, %rdx + subq %rcx, %rax + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jz .Lret + + movq $NRW_RC_OVFL, %r8 +.Lagain2: + testq %r8, %rax + jz .Lagain1 + leaq (%rax,%rcx), %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain2 + +.Lret: movl $EAGAIN, %eax + ret + +.Ldeadlk: + movq $NRW_RC, %rdx + LOCK + subq %rdx, NRW_WORD(%rdi) + + movl $EDEADLK, %eax + ret + +#if 0 xorq %r10, %r10 /* Get the lock. */ @@ -168,6 +289,7 @@ __pthread_rwlock_rdlock: subq $MUTEX, %rdi #endif jmp 13b +#endif cfi_endproc .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S index 23b218af34..0fb925ceec 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S @@ -34,6 +34,143 @@ .align 16 pthread_rwlock_timedrdlock: cfi_startproc + movq %rsi, %r10 + movq $NRW_RC, %rax + LOCK + xaddq %rax, NRW_WORD(%rdi) + js .Lundo + +.Lagain1: + movq $(NRW_WL|NRW_WP), %rcx + movq $(NRW_WL|NRW_WW_MASK), %rdx + testq %rax, %rcx + setnz %cl + testq %rax, %rdx + setnz %dl + orb %cl, %dl + jnz .Lwait + + xorl %eax, %eax + ret + +.Lwait: movq $NRW_WL, %rcx + testq %rcx, %rax + jz 4f + + movl %fs:TID, %ecx + cmpl %ecx, WRITER(%rdi) + je .Ldeadlk + +4: xorq %r8, %r8 + movq $NRW_RC, %rdx + addq %rdx, %rax + movq $(NRW_WL|NRW_AR), %rcx + movq $(NRW_WP|NRW_WW_MASK), %rdx + testq %rax, %rcx + setz %cl + testq %rax, %rdx + setnz %dl + testb %dl, %cl + jz 1f + + movq $NRW_RW-NRW_RC, %rdx + addq %rax, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain1 + + movq $NRW_RC_MASK, %rax + testq %rdx, %rax + movq $NRW_RW-NRW_RC, %r8 + jz .Lwake_waiter + +1: movl $NRW_R_WAKEUP, %r9d + leaq NRW_WORD+4(%rdi), %rdi +2: movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME), %esi + xorl PSHARED-(NRW_WORD+4)(%rdi), %esi + shldq $32, %rax, %rdx + movl $__NR_futex, %eax + syscall + movl %eax, %esi + movq -4(%rdi), %rax + +6: movq $(NRW_WL|NRW_WP), %rcx + movq $(NRW_WL|NRW_WW_MASK), %rdx + testq %rax, %rcx + setnz %cl + testq %rax, %rdx + setnz %dl + orb %cl, %dl + jz 5f + + cmpl $-EWOULDBLOCK, %esi + je 2b + + movq $-NRW_RC, %rdx + subq %r8, %rdx + addq %rax, %rdx + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz 6b + + negl %esi + movl %esi, %eax + ret + +5: testl %r8d, %r8d + jz 3f + + movq $NRW_RC-NRW_RW, %rcx + addq %rcx, %rdx + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz 6b + +3: xorl %eax, %eax + ret + +.Lwake_waiter: + movq %rdx, %r10 + movl $__NR_futex, %eax + movl $(FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG), %esi + xorl PSHARED(%rdi), %esi + leaq NRW_WORD(%rdi), %rdi + movl $1, %edx + movl $NRW_W_WAKEUP, %r9d + syscall + leaq -NRW_WORD(%rdi), %rdi + movq %r10, %rdx + jmp 1b + +.Lundo: movq $-NRW_RC, %rcx + movq %rax, %rdx + subq %rcx, %rax + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jz .Lret + + movq $NRW_RC_OVFL, %r8 +.Lagain2: + testq %r8, %rax + jz .Lagain1 + leaq (%rax,%rcx), %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain2 + +.Lret: movl $EAGAIN, %eax + ret + +.Ldeadlk: + movq $NRW_RC, %rdx + LOCK + subq %rdx, NRW_WORD(%rdi) + + movl $EDEADLK, %eax + ret + + +#if 0 pushq %r12 cfi_adjust_cfa_offset(8) cfi_rel_offset(%r12, 0) @@ -271,5 +408,6 @@ pthread_rwlock_timedrdlock: 19: movl $EINVAL, %edx jmp 9b +#endif cfi_endproc .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S index cd867b60dc..14d7637429 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S @@ -34,6 +34,109 @@ .align 16 pthread_rwlock_timedwrlock: cfi_startproc + movq %rsi, %r10 + movq NRW_WORD(%rdi), %rax +.Lagain: + movq $(NRW_WW_MASK|NRW_WL|NRW_RC_MASK), %rdx + testq %rdx, %rax + jnz .Lwait + + // XXX Probably make AR a don't-care for !WP. Unconditionally set it + movq $(NRW_AR|NRW_WL), %rdx + movq $NRW_WL, %rcx + testq $NRW_WP, %rax + cmovz %rcx, %rdx + orq %rax, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain + + movl %fs:TID, %eax + movl %eax, WRITER(%rdi) + + xorl %eax, %eax + ret + +.Lwait: movq $NRW_WL, %rcx + testq %rcx, %rax + jz 1f + + movl %fs:TID, %eax + cmpl %eax, WRITER(%rdi) + je .Ldeadlk + +1: leaq NRW_WORD+4(%rdi), %rdi + + movq $NRW_WW, %rdx + movq $NRW_WW_MASK, %rcx + addq %rax, %rdx + testq %rcx, %rdx + jz .Lovfl + + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz .Lagain + + movl $NRW_W_WAKEUP, %r9d +.Lwait2: + movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME), %esi + movl $__NR_futex, %eax + xorl PSHARED-(NRW_WORD+4)(%rdi), %esi + syscall + movl %eax, %esi + movq -4(%rdi), %rax + +.Lagain2: + movq $(NRW_WL|NRW_RC_MASK), %rdx + movq $(NRW_WL|NRW_AR), %rcx + testq %rdx, %rax + movq $NRW_AR, %rsi + setz %cl + andq %rax, %rcx + cmpq %rsi, %rcx + sete %cl + orb %dl, %cl + jnz 2f + + cmpl $-EWOULDBLOCK, %esi + jne .Lwait2 + + movq $-NRW_WW, %rdx + addq %rax, %rdx + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz .Lagain2 + + negl %esi + movl %esi, %eax + ret + +2: movq $-NRW_WW, %rdx + addq %rax, %rdx + xorl %ecx, %ecx + testq $NRW_WP, %rax + cmovz %rcx, %rsi + orq %rsi, %rdx + + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz .Lagain2 + + movl %fs:TID, %eax + movl %eax, WRITER(%rdi) + + xorl %eax, %eax + ret + +.Lovfl: movl $EAGAIN, %eax + ret + +.Ldeadlk: + movl $EDEADLK, %eax + ret + + +#if 0 pushq %r12 cfi_adjust_cfa_offset(8) cfi_rel_offset(%r12, 0) @@ -263,5 +366,6 @@ pthread_rwlock_timedwrlock: 19: movl $EINVAL, %edx jmp 9b +#endif cfi_endproc .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S index 03391d0fc2..1953637055 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S @@ -30,6 +30,97 @@ .align 16 __pthread_rwlock_unlock: cfi_startproc + movq NRW_WORD(%rdi), %rax + movq $NRW_WL, %rdx + testq %rdx, %rax + jnz .Lunlock_writer + +.Lagain: + movq $-NRW_RC, %rdx + addq %rax, %rdx + movq $NRW_RC_MASK, %rcx + testq %rcx, %rdx + jz .Llast_reader + +1: LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain + + xorl %eax, %eax + ret + +.Llast_reader: + movq $NRW_WW_MASK, %rcx + testq %rax, %rcx + jz 1b + + movq $NRW_AR, %rcx + xorl %esi, %esi + testq $NRW_WP, %rax + cmovz %esi, %ecx + orq %rcx, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain + +.Lwake_writer: + movl $1, %edx + movl $NRW_W_WAKEUP, %r9d +.Lwake: movl $(FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG), %esi + xorl PSHARED(%rdi), %esi + leaq NRW_WORD(%rdi), %rdi + movl $__NR_futex, %eax + syscall + +.Lout: xorl %eax, %eax + ret + +.Lunlock_writer: + movq %rax, %rdx + movq $NRW_WW_MASK, %rcx + testq %rcx, %rax + jz .Lno_writers + movq $NRW_RC_MASK, %rcx + testq %rcx, %rax + jz 2f + testq $NRW_WP, %rax + jz .Lwake_readers + +2: movq $~NRW_WL, %rcx + andq %rcx, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lunlock_writer + jmp .Lwake_writer + +.Lno_writers: + movq $~(NRW_WL|NRW_AR), %rcx + andq %rcx, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lunlock_writer + + movq $(NRW_RW_MASK|NRW_RC_MASK), %rcx + testq %rcx, %rax + jz .Lout + + movl $0x7fffffff, %edx + movl $NRW_R_WAKEUP, %r9d + jmp .Lwake + +.Lwake_readers: + movq $~NRW_WL, %rcx + andq %rcx, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lunlock_writer + + movl $0x7fffffff, %edx + movl $NRW_R_WAKEUP, %r9d + jmp .Lwake + + +#if 0 /* Get the lock. */ movl $1, %esi xorl %eax, %eax @@ -120,6 +211,7 @@ __pthread_rwlock_unlock: #endif callq __lll_unlock_wake jmp 8b +#endif cfi_endproc .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S index be6b8d8e20..63fc2dfd91 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S @@ -31,6 +31,94 @@ .align 16 __pthread_rwlock_wrlock: cfi_startproc + movq NRW_WORD(%rdi), %rax +.Lagain: + movq $(NRW_WW_MASK|NRW_WL|NRW_RC_MASK), %rdx + testq %rdx, %rax + jnz .Lwait + + // XXX Probably make AR a don't-care for !WP. Unconditionally set it + movq $(NRW_AR|NRW_WL), %rdx + movq $NRW_WL, %rcx + testq $NRW_WP, %rax + cmovz %rcx, %rdx + orq %rax, %rdx + LOCK + cmpxchgq %rdx, NRW_WORD(%rdi) + jnz .Lagain + + movl %fs:TID, %eax + movl %eax, WRITER(%rdi) + + xorl %eax, %eax + ret + +.Lwait: movq $NRW_WL, %rcx + testq %rcx, %rax + jz 1f + + movl %fs:TID, %eax + cmpl %eax, WRITER(%rdi) + je .Ldeadlk + +1: leaq NRW_WORD+4(%rdi), %rdi + + movq $NRW_WW, %rdx + movq $NRW_WW_MASK, %rcx + addq %rax, %rdx + testq %rcx, %rdx + jz .Lovfl + + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz .Lagain + + xorq %r10, %r10 + movl $NRW_W_WAKEUP, %r9d +.Lwait2: + movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG), %esi + movl $__NR_futex, %eax + xorl PSHARED-(NRW_WORD+4)(%rdi), %esi + syscall + movq -4(%rdi), %rax + +.Lagain2: + movq $(NRW_WL|NRW_RC_MASK), %rdx + movq $(NRW_WL|NRW_AR), %rcx + testq %rdx, %rax + movq $NRW_AR, %rsi + setz %cl + andq %rax, %rcx + cmpq %rsi, %rcx + sete %cl + orb %dl, %cl + jz .Lwait2 + + movq $-NRW_WW, %rdx + addq %rax, %rdx + xorl %ecx, %ecx + testq $NRW_WP, %rax + cmovz %rcx, %rsi + orq %rsi, %rdx + + LOCK + cmpxchgq %rdx, -4(%rdi) + jnz .Lagain2 + + movl %fs:TID, %eax + movl %eax, WRITER(%rdi) + + xorl %eax, %eax + ret + +.Lovfl: movl $EAGAIN, %eax + ret + +.Ldeadlk: + movl $EDEADLK, %eax + ret + +#if 0 xorq %r10, %r10 /* Get the lock. */ @@ -156,6 +244,7 @@ __pthread_rwlock_wrlock: subq $MUTEX, %rdi #endif jmp 13b +#endif cfi_endproc .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock diff --git a/sysdeps/powerpc/powerpc32/__longjmp-common.S b/sysdeps/powerpc/powerpc32/__longjmp-common.S index 7b1c017837..955161ef2b 100644 --- a/sysdeps/powerpc/powerpc32/__longjmp-common.S +++ b/sysdeps/powerpc/powerpc32/__longjmp-common.S @@ -33,6 +33,13 @@ ENTRY (BP_SYM (__longjmp)) #if defined PTR_DEMANGLE || defined CHECK_SP lwz r24,(JB_GPR1*4)(r3) +# ifdef CHECK_SP +# ifdef PTR_DEMANGLE + PTR_DEMANGLE3 (r24, r24, r25) +# endif + CHECK_SP (r24) + mr r1,r24 +# endif #else lwz r1,(JB_GPR1*4)(r3) #endif @@ -45,16 +52,10 @@ ENTRY (BP_SYM (__longjmp)) lwz r19,((JB_GPRS+5)*4)(r3) lwz r20,((JB_GPRS+6)*4)(r3) #ifdef PTR_DEMANGLE -# ifdef CHECK_SP - PTR_DEMANGLE3 (r24, r24, r25) -# else +# ifndef CHECK_SP PTR_DEMANGLE3 (r1, r24, r25) # endif PTR_DEMANGLE2 (r0, r25) -#endif -#ifdef CHECK_SP - CHECK_SP (r24) - mr r1,r24 #endif mtlr r0 lwz r21,((JB_GPRS+7)*4)(r3) diff --git a/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S b/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S index f105815b9c..04ed6da68b 100644 --- a/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S +++ b/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S @@ -116,6 +116,13 @@ L(no_vmx): #endif #if defined PTR_DEMANGLE || defined CHECK_SP lwz r24,(JB_GPR1*4)(r3) +# ifdef CHECK_SP +# ifdef PTR_DEMANGLE + PTR_DEMANGLE3 (r24, r24, r25) +# endif + CHECK_SP (r24) + mr r1,r24 +# endif #else lwz r1,(JB_GPR1*4)(r3) #endif @@ -135,16 +142,10 @@ L(no_vmx): lwz r20,((JB_GPRS+6)*4)(r3) lfd fp20,((JB_FPRS+6*2)*4)(r3) #ifdef PTR_DEMANGLE -# ifdef CHECK_SP - PTR_DEMANGLE3 (r24, r24, r25) -# else +# ifndef CHECK_SP PTR_DEMANGLE3 (r1, r24, r25) # endif PTR_DEMANGLE2 (r0, r25) -#endif -#ifdef CHECK_SP - CHECK_SP (r24) - mr r1,r24 #endif mtlr r0 lwz r21,((JB_GPRS+7)*4)(r3) diff --git a/sysdeps/powerpc/powerpc32/____longjmp_chk.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/____longjmp_chk.S similarity index 69% rename from sysdeps/powerpc/powerpc32/____longjmp_chk.S rename to sysdeps/unix/sysv/linux/powerpc/powerpc32/____longjmp_chk.S index 510ce5250d..4cb968505d 100644 --- a/sysdeps/powerpc/powerpc32/____longjmp_chk.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/____longjmp_chk.S @@ -19,7 +19,8 @@ #include #include - .section .rodata.str1.1,"aMS",@progbits,1 + .section .rodata.str1.4,"aMS",@progbits,1 + .align 2 .LC0: .string "longjmp causes uninitialized stack frame" .text @@ -49,8 +50,36 @@ #define CHECK_SP(reg) \ cmplw reg, r1; \ bge+ .Lok; \ + mflr r0; \ + stwu r1,-32(r1); \ + cfi_remember_state; \ + cfi_adjust_cfa_offset (32); \ + stw r0,36(r1); \ + cfi_offset (lr, 4); \ + mr r31,r3; \ + mr r30,r4; \ + li r3,0; \ + addi r4,r1,8; \ + li r0,__NR_sigaltstack; \ + sc; \ + /* Without working sigaltstack we cannot perform the test. */ \ + bso .Lok2; \ + lwz r0,12(r1); \ + andi. r3,r0,1; \ + beq .Lfail; \ + lwz r0,16(r1); \ + lwz r3,8(r1); \ + add r3,r3,r0; \ + sub r3,r3,reg; \ + cmplw r3,r0; \ + bge+ .Lok2; \ +.Lfail: \ LOAD_ARG; \ bl HIDDEN_JUMPTARGET (__fortify_fail); \ +.Lok2: \ + mr r3,r31; \ + mr r4,r30; \ + cfi_restore_state; \ .Lok: #include <__longjmp-common.S> diff --git a/sysdeps/powerpc/powerpc64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/____longjmp_chk.S similarity index 63% rename from sysdeps/powerpc/powerpc64/____longjmp_chk.S rename to sysdeps/unix/sysv/linux/powerpc/powerpc64/____longjmp_chk.S index 56549021aa..936ace5f69 100644 --- a/sysdeps/powerpc/powerpc64/____longjmp_chk.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/____longjmp_chk.S @@ -19,7 +19,8 @@ #include #include - .section .rodata.str1.1,"aMS",@progbits,1 + .section .rodata.str1.8,"aMS",@progbits,1 + .align 3 .LC0: .string "longjmp causes uninitialized stack frame" .section .toc,"aw" @@ -32,8 +33,37 @@ #define CHECK_SP(reg) \ cmpld reg, r1; \ bge+ .Lok; \ + mflr r0; \ + std r0,16(r1); \ + mr r31,r3; \ + mr r30,r4; \ + stdu r1,-144(r1); \ + cfi_remember_state; \ + cfi_adjust_cfa_offset (144); \ + cfi_offset (lr, 16); \ + li r3,0; \ + addi r4,r1,112; \ + li r0,__NR_sigaltstack; \ + sc; \ + /* Without working sigaltstack we cannot perform the test. */ \ + bso .Lok2; \ + lwz r0,112+8(r1); \ + andi. r4,r0,1; \ + beq .Lfail; \ + ld r0,112+16(r1); \ + ld r4,112(r1); \ + add r4,r4,r0; \ + sub r3,r3,reg; \ + cmpld r3,r0; \ + bge+ .Lok2; \ +.Lfail: \ ld r3,.LC1@toc(2); \ bl HIDDEN_JUMPTARGET (__fortify_fail); \ + nop; \ +.Lok2: \ + mr r3,r31; \ + mr r4,r30; \ + cfi_restore_state; \ .Lok: #include <__longjmp-common.S> From cd16986ee3a4fa92c7e6b3f5a601a635a7cdd21a Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 22 Aug 2009 17:58:04 -0700 Subject: [PATCH 03/11] Rvert accidental checkins. --- nptl/pthread_rwlock_init.c | 13 +- .../sysv/linux/x86_64/pthread_rwlock_rdlock.S | 122 ---------------- .../linux/x86_64/pthread_rwlock_timedrdlock.S | 138 ------------------ .../linux/x86_64/pthread_rwlock_timedwrlock.S | 104 ------------- .../sysv/linux/x86_64/pthread_rwlock_unlock.S | 92 ------------ .../sysv/linux/x86_64/pthread_rwlock_wrlock.S | 89 ----------- 6 files changed, 11 insertions(+), 547 deletions(-) diff --git a/nptl/pthread_rwlock_init.c b/nptl/pthread_rwlock_init.c index 95d9da4005..27f25ac2ab 100644 --- a/nptl/pthread_rwlock_init.c +++ b/nptl/pthread_rwlock_init.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2007, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -37,7 +37,13 @@ __pthread_rwlock_init (rwlock, attr) iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_attr; - memset (rwlock, '\0', sizeof (*rwlock)); + rwlock->__data.__lock = 0; + rwlock->__data.__nr_readers = 0; + rwlock->__data.__readers_wakeup = 0; + rwlock->__data.__writer_wakeup = 0; + rwlock->__data.__nr_readers_queued = 0; + rwlock->__data.__nr_writers_queued = 0; + rwlock->__data.__writer = 0; rwlock->__data.__flags = iattr->lockkind == PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP; @@ -68,6 +74,9 @@ __pthread_rwlock_init (rwlock, attr) header.private_futex)); #endif + rwlock->__data.__pad1 = 0; + rwlock->__data.__pad2 = 0; + return 0; } strong_alias (__pthread_rwlock_init, pthread_rwlock_init) diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S index 54a47e111f..35eb09cd0c 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S @@ -31,127 +31,6 @@ .align 16 __pthread_rwlock_rdlock: cfi_startproc - movq $NRW_RC, %rax - LOCK - xaddq %rax, NRW_WORD(%rdi) - js .Lundo - -.Lagain1: - movq $(NRW_WL|NRW_WP), %rcx - movq $(NRW_WL|NRW_WW_MASK), %rdx - testq %rax, %rcx - setnz %cl - testq %rax, %rdx - setnz %dl - orb %cl, %dl - jnz .Lwait - - xorl %eax, %eax - ret - -.Lwait: movq $NRW_WL, %rcx - testq %rcx, %rax - jz 4f - - movl %fs:TID, %ecx - cmpl %ecx, WRITER(%rdi) - je .Ldeadlk - -4: xorq %r8, %r8 - movq $NRW_RC, %rdx - addq %rdx, %rax - movq $(NRW_WL|NRW_AR), %rcx - movq $(NRW_WP|NRW_WW_MASK), %rdx - testq %rax, %rcx - setz %cl - testq %rax, %rdx - setnz %dl - testb %dl, %cl - jz 1f - - movq $NRW_RW-NRW_RC, %rdx - addq %rax, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain1 - - movq $NRW_RC_MASK, %rax - testq %rdx, %rax - movl $1, %r8d - jz .Lwake_waiter - -1: xorq %r10, %r10 - movl $NRW_R_WAKEUP, %r9d - movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG), %esi - xorl PSHARED(%rdi), %esi - leaq NRW_WORD+4(%rdi), %rdi -2: shldq $32, %rax, %rdx - movl $__NR_futex, %eax - syscall - movq -4(%rdi), %rax - -5: movq $(NRW_WL|NRW_WP), %rcx - movq $(NRW_WL|NRW_WW_MASK), %rdx - testq %rax, %rcx - setnz %cl - testq %rax, %rdx - setnz %dl - orb %cl, %dl - jnz 2b - - testl %r8d, %r8d - jz 3f - - movq $NRW_RC-NRW_RW, %rcx - addq %rcx, %rdx - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz 5b - -3: xorl %eax, %eax - ret - -.Lwake_waiter: - movq %rdx, %r10 - movl $__NR_futex, %eax - movl $(FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG), %esi - xorl PSHARED(%rdi), %esi - leaq NRW_WORD(%rdi), %rdi - movl $1, %edx - movl $NRW_W_WAKEUP, %r9d - syscall - leaq -NRW_WORD(%rdi), %rdi - movq %r10, %rdx - jmp 1b - -.Lundo: movq $-NRW_RC, %rcx - movq %rax, %rdx - subq %rcx, %rax - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jz .Lret - - movq $NRW_RC_OVFL, %r8 -.Lagain2: - testq %r8, %rax - jz .Lagain1 - leaq (%rax,%rcx), %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain2 - -.Lret: movl $EAGAIN, %eax - ret - -.Ldeadlk: - movq $NRW_RC, %rdx - LOCK - subq %rdx, NRW_WORD(%rdi) - - movl $EDEADLK, %eax - ret - -#if 0 xorq %r10, %r10 /* Get the lock. */ @@ -289,7 +168,6 @@ __pthread_rwlock_rdlock: subq $MUTEX, %rdi #endif jmp 13b -#endif cfi_endproc .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S index 0fb925ceec..23b218af34 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S @@ -34,143 +34,6 @@ .align 16 pthread_rwlock_timedrdlock: cfi_startproc - movq %rsi, %r10 - movq $NRW_RC, %rax - LOCK - xaddq %rax, NRW_WORD(%rdi) - js .Lundo - -.Lagain1: - movq $(NRW_WL|NRW_WP), %rcx - movq $(NRW_WL|NRW_WW_MASK), %rdx - testq %rax, %rcx - setnz %cl - testq %rax, %rdx - setnz %dl - orb %cl, %dl - jnz .Lwait - - xorl %eax, %eax - ret - -.Lwait: movq $NRW_WL, %rcx - testq %rcx, %rax - jz 4f - - movl %fs:TID, %ecx - cmpl %ecx, WRITER(%rdi) - je .Ldeadlk - -4: xorq %r8, %r8 - movq $NRW_RC, %rdx - addq %rdx, %rax - movq $(NRW_WL|NRW_AR), %rcx - movq $(NRW_WP|NRW_WW_MASK), %rdx - testq %rax, %rcx - setz %cl - testq %rax, %rdx - setnz %dl - testb %dl, %cl - jz 1f - - movq $NRW_RW-NRW_RC, %rdx - addq %rax, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain1 - - movq $NRW_RC_MASK, %rax - testq %rdx, %rax - movq $NRW_RW-NRW_RC, %r8 - jz .Lwake_waiter - -1: movl $NRW_R_WAKEUP, %r9d - leaq NRW_WORD+4(%rdi), %rdi -2: movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME), %esi - xorl PSHARED-(NRW_WORD+4)(%rdi), %esi - shldq $32, %rax, %rdx - movl $__NR_futex, %eax - syscall - movl %eax, %esi - movq -4(%rdi), %rax - -6: movq $(NRW_WL|NRW_WP), %rcx - movq $(NRW_WL|NRW_WW_MASK), %rdx - testq %rax, %rcx - setnz %cl - testq %rax, %rdx - setnz %dl - orb %cl, %dl - jz 5f - - cmpl $-EWOULDBLOCK, %esi - je 2b - - movq $-NRW_RC, %rdx - subq %r8, %rdx - addq %rax, %rdx - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz 6b - - negl %esi - movl %esi, %eax - ret - -5: testl %r8d, %r8d - jz 3f - - movq $NRW_RC-NRW_RW, %rcx - addq %rcx, %rdx - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz 6b - -3: xorl %eax, %eax - ret - -.Lwake_waiter: - movq %rdx, %r10 - movl $__NR_futex, %eax - movl $(FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG), %esi - xorl PSHARED(%rdi), %esi - leaq NRW_WORD(%rdi), %rdi - movl $1, %edx - movl $NRW_W_WAKEUP, %r9d - syscall - leaq -NRW_WORD(%rdi), %rdi - movq %r10, %rdx - jmp 1b - -.Lundo: movq $-NRW_RC, %rcx - movq %rax, %rdx - subq %rcx, %rax - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jz .Lret - - movq $NRW_RC_OVFL, %r8 -.Lagain2: - testq %r8, %rax - jz .Lagain1 - leaq (%rax,%rcx), %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain2 - -.Lret: movl $EAGAIN, %eax - ret - -.Ldeadlk: - movq $NRW_RC, %rdx - LOCK - subq %rdx, NRW_WORD(%rdi) - - movl $EDEADLK, %eax - ret - - -#if 0 pushq %r12 cfi_adjust_cfa_offset(8) cfi_rel_offset(%r12, 0) @@ -408,6 +271,5 @@ pthread_rwlock_timedrdlock: 19: movl $EINVAL, %edx jmp 9b -#endif cfi_endproc .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S index 14d7637429..cd867b60dc 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S @@ -34,109 +34,6 @@ .align 16 pthread_rwlock_timedwrlock: cfi_startproc - movq %rsi, %r10 - movq NRW_WORD(%rdi), %rax -.Lagain: - movq $(NRW_WW_MASK|NRW_WL|NRW_RC_MASK), %rdx - testq %rdx, %rax - jnz .Lwait - - // XXX Probably make AR a don't-care for !WP. Unconditionally set it - movq $(NRW_AR|NRW_WL), %rdx - movq $NRW_WL, %rcx - testq $NRW_WP, %rax - cmovz %rcx, %rdx - orq %rax, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain - - movl %fs:TID, %eax - movl %eax, WRITER(%rdi) - - xorl %eax, %eax - ret - -.Lwait: movq $NRW_WL, %rcx - testq %rcx, %rax - jz 1f - - movl %fs:TID, %eax - cmpl %eax, WRITER(%rdi) - je .Ldeadlk - -1: leaq NRW_WORD+4(%rdi), %rdi - - movq $NRW_WW, %rdx - movq $NRW_WW_MASK, %rcx - addq %rax, %rdx - testq %rcx, %rdx - jz .Lovfl - - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz .Lagain - - movl $NRW_W_WAKEUP, %r9d -.Lwait2: - movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME), %esi - movl $__NR_futex, %eax - xorl PSHARED-(NRW_WORD+4)(%rdi), %esi - syscall - movl %eax, %esi - movq -4(%rdi), %rax - -.Lagain2: - movq $(NRW_WL|NRW_RC_MASK), %rdx - movq $(NRW_WL|NRW_AR), %rcx - testq %rdx, %rax - movq $NRW_AR, %rsi - setz %cl - andq %rax, %rcx - cmpq %rsi, %rcx - sete %cl - orb %dl, %cl - jnz 2f - - cmpl $-EWOULDBLOCK, %esi - jne .Lwait2 - - movq $-NRW_WW, %rdx - addq %rax, %rdx - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz .Lagain2 - - negl %esi - movl %esi, %eax - ret - -2: movq $-NRW_WW, %rdx - addq %rax, %rdx - xorl %ecx, %ecx - testq $NRW_WP, %rax - cmovz %rcx, %rsi - orq %rsi, %rdx - - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz .Lagain2 - - movl %fs:TID, %eax - movl %eax, WRITER(%rdi) - - xorl %eax, %eax - ret - -.Lovfl: movl $EAGAIN, %eax - ret - -.Ldeadlk: - movl $EDEADLK, %eax - ret - - -#if 0 pushq %r12 cfi_adjust_cfa_offset(8) cfi_rel_offset(%r12, 0) @@ -366,6 +263,5 @@ pthread_rwlock_timedwrlock: 19: movl $EINVAL, %edx jmp 9b -#endif cfi_endproc .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S index 1953637055..03391d0fc2 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S @@ -30,97 +30,6 @@ .align 16 __pthread_rwlock_unlock: cfi_startproc - movq NRW_WORD(%rdi), %rax - movq $NRW_WL, %rdx - testq %rdx, %rax - jnz .Lunlock_writer - -.Lagain: - movq $-NRW_RC, %rdx - addq %rax, %rdx - movq $NRW_RC_MASK, %rcx - testq %rcx, %rdx - jz .Llast_reader - -1: LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain - - xorl %eax, %eax - ret - -.Llast_reader: - movq $NRW_WW_MASK, %rcx - testq %rax, %rcx - jz 1b - - movq $NRW_AR, %rcx - xorl %esi, %esi - testq $NRW_WP, %rax - cmovz %esi, %ecx - orq %rcx, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain - -.Lwake_writer: - movl $1, %edx - movl $NRW_W_WAKEUP, %r9d -.Lwake: movl $(FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG), %esi - xorl PSHARED(%rdi), %esi - leaq NRW_WORD(%rdi), %rdi - movl $__NR_futex, %eax - syscall - -.Lout: xorl %eax, %eax - ret - -.Lunlock_writer: - movq %rax, %rdx - movq $NRW_WW_MASK, %rcx - testq %rcx, %rax - jz .Lno_writers - movq $NRW_RC_MASK, %rcx - testq %rcx, %rax - jz 2f - testq $NRW_WP, %rax - jz .Lwake_readers - -2: movq $~NRW_WL, %rcx - andq %rcx, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lunlock_writer - jmp .Lwake_writer - -.Lno_writers: - movq $~(NRW_WL|NRW_AR), %rcx - andq %rcx, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lunlock_writer - - movq $(NRW_RW_MASK|NRW_RC_MASK), %rcx - testq %rcx, %rax - jz .Lout - - movl $0x7fffffff, %edx - movl $NRW_R_WAKEUP, %r9d - jmp .Lwake - -.Lwake_readers: - movq $~NRW_WL, %rcx - andq %rcx, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lunlock_writer - - movl $0x7fffffff, %edx - movl $NRW_R_WAKEUP, %r9d - jmp .Lwake - - -#if 0 /* Get the lock. */ movl $1, %esi xorl %eax, %eax @@ -211,7 +120,6 @@ __pthread_rwlock_unlock: #endif callq __lll_unlock_wake jmp 8b -#endif cfi_endproc .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S index 63fc2dfd91..be6b8d8e20 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S @@ -31,94 +31,6 @@ .align 16 __pthread_rwlock_wrlock: cfi_startproc - movq NRW_WORD(%rdi), %rax -.Lagain: - movq $(NRW_WW_MASK|NRW_WL|NRW_RC_MASK), %rdx - testq %rdx, %rax - jnz .Lwait - - // XXX Probably make AR a don't-care for !WP. Unconditionally set it - movq $(NRW_AR|NRW_WL), %rdx - movq $NRW_WL, %rcx - testq $NRW_WP, %rax - cmovz %rcx, %rdx - orq %rax, %rdx - LOCK - cmpxchgq %rdx, NRW_WORD(%rdi) - jnz .Lagain - - movl %fs:TID, %eax - movl %eax, WRITER(%rdi) - - xorl %eax, %eax - ret - -.Lwait: movq $NRW_WL, %rcx - testq %rcx, %rax - jz 1f - - movl %fs:TID, %eax - cmpl %eax, WRITER(%rdi) - je .Ldeadlk - -1: leaq NRW_WORD+4(%rdi), %rdi - - movq $NRW_WW, %rdx - movq $NRW_WW_MASK, %rcx - addq %rax, %rdx - testq %rcx, %rdx - jz .Lovfl - - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz .Lagain - - xorq %r10, %r10 - movl $NRW_W_WAKEUP, %r9d -.Lwait2: - movl $(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG), %esi - movl $__NR_futex, %eax - xorl PSHARED-(NRW_WORD+4)(%rdi), %esi - syscall - movq -4(%rdi), %rax - -.Lagain2: - movq $(NRW_WL|NRW_RC_MASK), %rdx - movq $(NRW_WL|NRW_AR), %rcx - testq %rdx, %rax - movq $NRW_AR, %rsi - setz %cl - andq %rax, %rcx - cmpq %rsi, %rcx - sete %cl - orb %dl, %cl - jz .Lwait2 - - movq $-NRW_WW, %rdx - addq %rax, %rdx - xorl %ecx, %ecx - testq $NRW_WP, %rax - cmovz %rcx, %rsi - orq %rsi, %rdx - - LOCK - cmpxchgq %rdx, -4(%rdi) - jnz .Lagain2 - - movl %fs:TID, %eax - movl %eax, WRITER(%rdi) - - xorl %eax, %eax - ret - -.Lovfl: movl $EAGAIN, %eax - ret - -.Ldeadlk: - movl $EDEADLK, %eax - ret - -#if 0 xorq %r10, %r10 /* Get the lock. */ @@ -244,7 +156,6 @@ __pthread_rwlock_wrlock: subq $MUTEX, %rdi #endif jmp 13b -#endif cfi_endproc .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock From 659a63fb7ba0b2c9bc45034283a302afe56a6ebe Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 10:56:08 -0700 Subject: [PATCH 04/11] Thread-local locale handling part of XPG7. I incorrectly enabled the definitions for XPG6. --- ChangeLog | 5 +++++ locale/locale.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7e88049818..c48442d988 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-08-23 Ulrich Drepper + + * locale/locale.h: Include xlocale.h and the thread-local locale + declarations for XPG7, not XPG6. + 2009-08-21 Andreas Schwab * sysdeps/powerpc/powerpc32/____longjmp_chk.S: Removed. diff --git a/locale/locale.h b/locale/locale.h index b24ae245fe..2aa19e76ac 100644 --- a/locale/locale.h +++ b/locale/locale.h @@ -130,7 +130,7 @@ extern struct lconv *localeconv (void) __THROW; __END_NAMESPACE_STD -#ifdef __USE_XOPEN2K +#ifdef __USE_XOPEN2K8 /* The concept of one static locale per category is not very well thought out. Many applications will need to process its data using information from several different locales. Another application is From 003c9895a89e71767ad64bafac1ca99622be2eb7 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 11:57:52 -0700 Subject: [PATCH 05/11] Print sign of NaN values. --- ChangeLog | 5 ++ stdio-common/printf_fp.c | 9 ++- stdio-common/printf_fphex.c | 4 +- stdio-common/tstdiomisc.c | 132 +++++++++++++++++++++++++++++++----- 4 files changed, 127 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index c48442d988..fde9f03f76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-08-23 Ulrich Drepper + * stdio-common/printf_fp.c: ISO C expects to print the sign of NaN + as well. + * stdio-common/printf_fphex.c: Likewise. + * stdio-common/tstdiomisc.c: Add more tests. + * locale/locale.h: Include xlocale.h and the thread-local locale declarations for XPG7, not XPG6. diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index 43c43c2039..cd3ada6441 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -335,6 +336,8 @@ ___printf_fp (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnanl (fpnum.ldbl)) { + union ieee854_long_double u = { .d = fpnum.ldbl }; + is_neg = u.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -345,10 +348,10 @@ ___printf_fp (FILE *fp, special = "nan"; wspecial = L"nan"; } - is_neg = 0; } else if (__isinfl (fpnum.ldbl)) { + is_neg = fpnum.ldbl < 0; if (isupper (info->spec)) { special = "INF"; @@ -359,7 +362,6 @@ ___printf_fp (FILE *fp, special = "inf"; wspecial = L"inf"; } - is_neg = fpnum.ldbl < 0; } else { @@ -379,7 +381,8 @@ ___printf_fp (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnan (fpnum.dbl)) { - is_neg = 0; + union ieee754_double u = { .d = fpnum.dbl }; + is_neg = u.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c index 4e30d94c61..551c873c5e 100644 --- a/stdio-common/printf_fphex.c +++ b/stdio-common/printf_fphex.c @@ -172,6 +172,7 @@ __printf_fphex (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnanl (fpnum.ldbl.d)) { + negative = fpnum.ldbl.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -182,7 +183,6 @@ __printf_fphex (FILE *fp, special = "nan"; wspecial = L"nan"; } - negative = 0; } else { @@ -211,6 +211,7 @@ __printf_fphex (FILE *fp, /* Check for special values: not a number or infinity. */ if (__isnan (fpnum.dbl.d)) { + negative = fpnum.dbl.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -221,7 +222,6 @@ __printf_fphex (FILE *fp, special = "nan"; wspecial = L"nan"; } - negative = 0; } else { diff --git a/stdio-common/tstdiomisc.c b/stdio-common/tstdiomisc.c index db038fa2b0..c1c68955bd 100644 --- a/stdio-common/tstdiomisc.c +++ b/stdio-common/tstdiomisc.c @@ -47,33 +47,129 @@ t2 (void) } volatile double nanval; +volatile double infval; +volatile long double lnanval; +volatile long double linfval; static int F (void) { - char buf[20]; - wchar_t wbuf[10]; + char buf[80]; + wchar_t wbuf[40]; int result; nanval = NAN; - snprintf (buf, sizeof buf, "%f %F", nanval, nanval); - result = strcmp (buf, "nan NAN") != 0; - printf ("expected \"nan NAN\", got \"%s\"\n", buf); - - snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX); - result |= strcmp (buf, "inf INF") != 0; - printf ("expected \"inf INF\", got \"%s\"\n", buf); - - swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", nanval, nanval); - result |= wcscmp (wbuf, L"nan NAN") != 0; - printf ("expected L\"nan NAN\", got L\"%S\"\n", wbuf); - - swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F", - DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX); - result |= wcscmp (wbuf, L"inf INF") != 0; - printf ("expected L\"inf INF\", got L\"%S\"\n", wbuf); + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + nanval, nanval, nanval, nanval, nanval, nanval, nanval, nanval); + result = strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + -nanval, -nanval, -nanval, -nanval, + -nanval, -nanval, -nanval, -nanval); + result = strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n", + buf); + + infval = DBL_MAX * DBL_MAX; + + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + infval, infval, infval, infval, infval, infval, infval, infval); + result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0; + printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G", + -infval, -infval, -infval, -infval, + -infval, -infval, -infval, -infval); + result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n", + buf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + nanval, nanval, nanval, nanval, nanval, nanval, nanval, nanval); + result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + -nanval, -nanval, -nanval, -nanval, + -nanval, -nanval, -nanval, -nanval); + result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n", + wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + infval, infval, infval, infval, infval, infval, infval, infval); + result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0; + printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G", + -infval, -infval, -infval, -infval, + -infval, -infval, -infval, -infval); + result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n", + wbuf); + + lnanval = NAN; + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + lnanval, lnanval, lnanval, lnanval, + lnanval, lnanval, lnanval, lnanval); + result = strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + -lnanval, -lnanval, -lnanval, -lnanval, + -lnanval, -lnanval, -lnanval, -lnanval); + result = strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n", + buf); + + linfval = LDBL_MAX * LDBL_MAX; + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + linfval, linfval, linfval, linfval, + linfval, linfval, linfval, linfval); + result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0; + printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf); + + snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG", + -linfval, -linfval, -linfval, -linfval, + -linfval, -linfval, -linfval, -linfval); + result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n", + buf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + lnanval, lnanval, lnanval, lnanval, + lnanval, lnanval, lnanval, lnanval); + result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0; + printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + -lnanval, -lnanval, -lnanval, -lnanval, + -lnanval, -lnanval, -lnanval, -lnanval); + result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0; + printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n", + wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + linfval, linfval, linfval, linfval, + linfval, linfval, linfval, linfval); + result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0; + printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf); + + swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), + L"%La %LA %Le %LE %Lf %LF %Lg %LG", + -linfval, -linfval, -linfval, -linfval, + -linfval, -linfval, -linfval, -linfval); + result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0; + printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n", + wbuf); return result; } From c6b6723e6b756d36d9912a1c430459634e15758b Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 12:27:09 -0700 Subject: [PATCH 06/11] Define _POSIX_VERSION correctly when older POSIX versions are selected. --- ChangeLog | 3 +++ posix/unistd.h | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fde9f03f76..280afff9be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2009-08-23 Ulrich Drepper + * posix/unistd.h: Define _POSIX_VERSION correctly if older POSIX + versions are selected. + * stdio-common/printf_fp.c: ISO C expects to print the sign of NaN as well. * stdio-common/printf_fphex.c: Likewise. diff --git a/posix/unistd.h b/posix/unistd.h index cbab9f939e..2de9a68b39 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -30,8 +30,22 @@ __BEGIN_DECLS /* These may be used to determine what facilities are present at compile time. Their values can be obtained at run time from `sysconf'. */ +#ifdef __USE_XOPEN2K8 /* POSIX Standard approved as ISO/IEC 9945-1 as of September 2008. */ -#define _POSIX_VERSION 200809L +# define _POSIX_VERSION 200809L +#elif defined __USE_XOPEN2K +/* POSIX Standard approved as ISO/IEC 9945-1 as of December 2001. */ +# define _POSIX_VERSION 200112L +#elif defined __USE_POSIX199506 +/* POSIX Standard approved as ISO/IEC 9945-1 as of June 1995. */ +# define _POSIX_VERSION 199506L +#elif defined __USE_POSIX199309 +/* POSIX Standard approved as ISO/IEC 9945-1 as of September 1993. */ +# define _POSIX_VERSION 199309L +#else +/* POSIX Standard approved as ISO/IEC 9945-1 as of September 1990. */ +# define _POSIX_VERSION 199009L +#endif /* These are not #ifdef __USE_POSIX2 because they are in the theoretically application-owned namespace. */ From 2d094b739598d2e1718d3cc4c5af7e95787bd463 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 13:59:41 -0700 Subject: [PATCH 07/11] More namespace cleanups. --- nptl/ChangeLog | 4 ++++ nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 88975a76e0..098ef3ba2d 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,7 @@ +2009-08-23 Ulrich Drepper + + * sysdeps/unix/sysv/linux/bits/posix_opt.h: Clean up namespace. + 2009-08-11 Ulrich Drepper * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S: Add CFI diff --git a/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h b/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h index f9fa4e52eb..2550355cdc 100644 --- a/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h +++ b/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h @@ -85,15 +85,17 @@ /* We support priority inheritence. */ #define _POSIX_THREAD_PRIO_INHERIT 200809L -/* We support priority inheritence for robust mutexes. */ -#define _POSIX_THREAD_ROBUST_PRIO_INHERIT 200809L - /* We support priority protection, though only for non-robust mutexes. */ #define _POSIX_THREAD_PRIO_PROTECT 200809L +#ifdef __USE_XOPEN2K8 +/* We support priority inheritence for robust mutexes. */ +# define _POSIX_THREAD_ROBUST_PRIO_INHERIT 200809L + /* We do not support priority protection for robust mutexes. */ -#define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1 +# define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1 +#endif /* We support POSIX.1b semaphores. */ #define _POSIX_SEMAPHORES 200809L From bdc7f5d76b4f284475595dddc79f0e0f9720ec20 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 14:55:51 -0700 Subject: [PATCH 08/11] Also correct _POSIX2_* constants in case older standards are selected. --- ChangeLog | 4 ++-- posix/unistd.h | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 280afff9be..a42e20b0be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2009-08-23 Ulrich Drepper - * posix/unistd.h: Define _POSIX_VERSION correctly if older POSIX - versions are selected. + * posix/unistd.h: Define _POSIX_VERSION and _POSIX2_* correctly if + older POSIX versions are selected. * stdio-common/printf_fp.c: ISO C expects to print the sign of NaN as well. diff --git a/posix/unistd.h b/posix/unistd.h index 2de9a68b39..d9ecb5e788 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -50,24 +50,38 @@ __BEGIN_DECLS /* These are not #ifdef __USE_POSIX2 because they are in the theoretically application-owned namespace. */ +#ifdef __USE_XOPEN2K8 +# define __POSIX2_THIS_VERSION 200809L +/* The utilities on GNU systems also correspond to this version. */ +#elif defined __USE_XOPEN2K +/* The utilities on GNU systems also correspond to this version. */ +# define __POSIX2_THIS_VERSION 200112L +#elif defined __USE_POSIX199506 +/* The utilities on GNU systems also correspond to this version. */ +# define __POSIX2_THIS_VERSION 199506L +#else +/* The utilities on GNU systems also correspond to this version. */ +# define __POSIX2_THIS_VERSION 199209L +#endif + /* The utilities on GNU systems also correspond to this version. */ -#define _POSIX2_VERSION 200809L +#define _POSIX2_VERSION __POSIX2_THIS_VERSION /* If defined, the implementation supports the C Language Bindings Option. */ -#define _POSIX2_C_BIND 200809L +#define _POSIX2_C_BIND __POSIX2_THIS_VERSION /* If defined, the implementation supports the C Language Development Utilities Option. */ -#define _POSIX2_C_DEV 200809L +#define _POSIX2_C_DEV __POSIX2_THIS_VERSION /* If defined, the implementation supports the Software Development Utilities Option. */ -#define _POSIX2_SW_DEV 200809L +#define _POSIX2_SW_DEV __POSIX2_THIS_VERSION /* If defined, the implementation supports the creation of locales with the localedef utility. */ -#define _POSIX2_LOCALEDEF 200809L +#define _POSIX2_LOCALEDEF __POSIX2_THIS_VERSION /* X/Open version number to which the library conforms. It is selectable. */ #ifdef __USE_XOPEN2K8 From 52db8039f54672abe6a6da5fb107fa52aca42547 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 15:22:00 -0700 Subject: [PATCH 09/11] Recognize ill-formed { } expressions in regcomp. --- ChangeLog | 3 +++ posix/regcomp.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a42e20b0be..37cd868c19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2009-08-23 Ulrich Drepper + * posix/regcomp.c (parse_dup_op): Verify the expression is correctly + terminated. + * posix/unistd.h: Define _POSIX_VERSION and _POSIX2_* correctly if older POSIX versions are selected. diff --git a/posix/regcomp.c b/posix/regcomp.c index 4843cfea33..446fed5445 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -2481,7 +2481,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, return elem; } - if (BE (end != -1 && start > end, 0)) + if (BE ((end != -1 && start > end) || token->type != OP_CLOSE_DUP_NUM, 0)) { /* First number greater than second. */ *err = REG_BADBR; From 8a7cea019947a68e641e9201813fe01ba35cfd1a Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 23 Aug 2009 15:33:40 -0700 Subject: [PATCH 10/11] Add test case for last fixed regex bug. --- ChangeLog | 2 ++ posix/Makefile | 1 + posix/bug-regex29.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 posix/bug-regex29.c diff --git a/ChangeLog b/ChangeLog index 37cd868c19..9f63c4db05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * posix/regcomp.c (parse_dup_op): Verify the expression is correctly terminated. + * posix/Makefile (tests): Add bug-regex29. + * posix/bug-regex29.c: New file. * posix/unistd.h: Define _POSIX_VERSION and _POSIX2_* correctly if older POSIX versions are selected. diff --git a/posix/Makefile b/posix/Makefile index 8d8fbe5234..c9ce18b94e 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -82,6 +82,7 @@ tests := tstgetopt testfnm runtests runptests \ bug-regex17 bug-regex18 bug-regex19 bug-regex20 \ bug-regex21 bug-regex22 bug-regex23 bug-regex24 \ bug-regex25 bug-regex26 bug-regex27 bug-regex28 \ + bug-regex29 \ tst-nice tst-nanosleep tst-regex2 \ transbug tst-rxspencer tst-pcre tst-boost \ bug-ga1 tst-vfork1 tst-vfork2 tst-vfork3 tst-waitid \ diff --git a/posix/bug-regex29.c b/posix/bug-regex29.c new file mode 100644 index 0000000000..70a6c94cc6 --- /dev/null +++ b/posix/bug-regex29.c @@ -0,0 +1,15 @@ +#include + +static int +do_test (void) +{ + regex_t r; + int e = regcomp(&r, "xy\\{4,5,7\\}zabc", 0); + char buf[100]; + regerror(e, &r, buf, sizeof (buf)); + printf ("e = %d (%s)\n", e, buf); + return e != REG_BADBR; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" From a0e25a886a9128b280b4c05bc9c6dd12377ea868 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 23 Aug 2009 16:33:50 -0700 Subject: [PATCH 11/11] Fix td_ta_map_lwp2thr logging and early sanity check. --- nptl_db/ChangeLog | 7 +++++++ nptl_db/td_ta_map_lwp2thr.c | 14 +++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/nptl_db/ChangeLog b/nptl_db/ChangeLog index 1ade1968a7..f79fc18e4b 100644 --- a/nptl_db/ChangeLog +++ b/nptl_db/ChangeLog @@ -1,3 +1,10 @@ +2009-08-23 Roland McGrath + + * td_ta_map_lwp2thr.c (__td_ta_lookup_th_unique): Move ta_ok check + and LOG call back to ... + (td_ta_map_lwp2thr): ... here. + Reported by Maciej W. Rozycki . + 2009-05-25 Aurelien Jarno [BZ #10200] diff --git a/nptl_db/td_ta_map_lwp2thr.c b/nptl_db/td_ta_map_lwp2thr.c index 78cfcab769..4835f31f94 100644 --- a/nptl_db/td_ta_map_lwp2thr.c +++ b/nptl_db/td_ta_map_lwp2thr.c @@ -1,5 +1,5 @@ /* Which thread is running on an LWP? - Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc. + Copyright (C) 2003,2004,2007,2009 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 @@ -33,12 +33,6 @@ __td_ta_lookup_th_unique (const td_thragent_t *ta_arg, prgregset_t regs; psaddr_t addr; - LOG ("td_ta_map_lwp2thr"); - - /* Test whether the TA parameter is ok. */ - if (! ta_ok (ta)) - return TD_BADTA; - if (ta->ta_howto == ta_howto_unknown) { /* We need to read in from the inferior the instructions what to do. */ @@ -181,6 +175,12 @@ td_ta_map_lwp2thr (const td_thragent_t *ta_arg, { td_thragent_t *const ta = (td_thragent_t *) ta_arg; + LOG ("td_ta_map_lwp2thr"); + + /* Test whether the TA parameter is ok. */ + if (! ta_ok (ta)) + return TD_BADTA; + /* We cannot rely on thread registers and such information at all before __pthread_initialize_minimal has gotten far enough. They sometimes contain garbage that would confuse us, left by the kernel