Fix BZ #18084 -- backtrace (..., 0) dumps core on x86.

Other architectures also had bugs, or did unnecessary work.
This commit is contained in:
Paul Pluzhnikov 2015-08-15 11:42:43 -07:00
parent 3cda1b6d56
commit d5dff793af
11 changed files with 57 additions and 16 deletions

View File

@ -1,3 +1,16 @@
2015-08-15 Paul Pluzhnikov <ppluzhnikov@google.com>
[BZ #18084]
* debug/tst-backtrace2.c (do_test): Add test for BZ #18084.
* sysdeps/arm/backtrace.c (__backtrace): Handle size <= 0.
* sysdeps/i386/backtrace.c (__backtrace): Likewise.
* sysdeps/m68k/backtrace.c (__backtrace): Likewise.
* sysdeps/microblaze/backtrace.c (__backtrace): Likewise.
* sysdeps/s390/s390-32/backtrace.c (__backtrace): Likewise.
* sysdeps/s390/s390-64/backtrace.c (__backtrace): Likewise.
* sysdeps/sparc/backtrace.c (__backtrace): Likewise.
* sysdeps/x86_64/backtrace.c (__backtrace): Likewise.
2015-08-15 Zack Weinberg <zackw@panix.com>
[BZ #18795]

7
NEWS
View File

@ -9,9 +9,10 @@ Version 2.23
* The following bugs are resolved with this release:
16517, 16519, 16520, 16734, 17905, 18086, 18265, 18480, 18525, 18618,
18647, 18661, 18674, 18778, 18781, 18787, 18789, 18790, 18795, 18820,
18824.
16517, 16519, 16520, 16734, 17905, 18084, 18086, 18265, 18480, 18525,
18618, 18647, 18661, 18674, 18778, 18781, 18787, 18789, 18790, 18795,
18820, 18824.
Version 2.22

View File

@ -94,6 +94,12 @@ fn3 (void)
NO_INLINE static int
do_test (void)
{
/* Test BZ #18084. */
void *buffer[1];
if (backtrace (buffer, 0) != 0)
FAIL ();
fn3 ();
return ret;
}

View File

@ -92,6 +92,10 @@ __backtrace (array, size)
int size;
{
struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
if (size <= 0)
return 0;
#ifdef SHARED
__libc_once_define (static, once);
@ -100,8 +104,7 @@ __backtrace (array, size)
return 0;
#endif
if (size >= 1)
unwind_backtrace (backtrace_helper, &arg);
unwind_backtrace (backtrace_helper, &arg);
if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL)
--arg.cnt;

View File

@ -114,6 +114,10 @@ __backtrace (array, size)
int size;
{
struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
if (size <= 0)
return 0;
#ifdef SHARED
__libc_once_define (static, once);
@ -122,8 +126,7 @@ __backtrace (array, size)
return 0;
#endif
if (size >= 1)
unwind_backtrace (backtrace_helper, &arg);
unwind_backtrace (backtrace_helper, &arg);
if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL)
--arg.cnt;

View File

@ -111,6 +111,10 @@ int
__backtrace (void **array, int size)
{
struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
if (size <= 0)
return 0;
#ifdef SHARED
__libc_once_define (static, once);
@ -119,8 +123,7 @@ __backtrace (void **array, int size)
return 0;
#endif
if (size >= 1)
unwind_backtrace (backtrace_helper, &arg);
unwind_backtrace (backtrace_helper, &arg);
if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL)
--arg.cnt;

View File

@ -114,6 +114,9 @@ __backtrace (void **array, int size)
int count;
int rc = 0;
if (size <= 0)
return 0;
__asm__ __volatile__ ("mfs %0, rpc"
: "=r"(pc));

View File

@ -126,6 +126,10 @@ int
__backtrace (void **array, int size)
{
struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
if (size <= 0)
return 0;
#ifdef SHARED
__libc_once_define (static, once);
@ -135,8 +139,7 @@ __backtrace (void **array, int size)
return __backchain_backtrace (array, size);
#endif
if (size >= 1)
unwind_backtrace (backtrace_helper, &arg);
unwind_backtrace (backtrace_helper, &arg);
return arg.cnt != -1 ? arg.cnt : 0;
}

View File

@ -125,6 +125,10 @@ int
__backtrace (void **array, int size)
{
struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
if (size <= 0)
return 0;
#ifdef SHARED
__libc_once_define (static, once);
@ -134,8 +138,7 @@ __backtrace (void **array, int size)
return __backchain_backtrace (array, size);
#endif
if (size >= 1)
unwind_backtrace (backtrace_helper, &arg);
unwind_backtrace (backtrace_helper, &arg);
return arg.cnt != -1 ? arg.cnt : 0;
}

View File

@ -108,7 +108,7 @@ __backtrace (void **array, int size)
bool use_unwinder;
int count;
if (!size)
if (size <= 0)
return 0;
use_unwinder = true;

View File

@ -97,6 +97,10 @@ __backtrace (array, size)
int size;
{
struct trace_arg arg = { .array = array, .cfa = 0, .size = size, .cnt = -1 };
if (size <= 0)
return 0;
#ifdef SHARED
__libc_once_define (static, once);
@ -105,8 +109,7 @@ __backtrace (array, size)
return 0;
#endif
if (size >= 1)
unwind_backtrace (backtrace_helper, &arg);
unwind_backtrace (backtrace_helper, &arg);
/* _Unwind_Backtrace seems to put NULL address above
_start. Fix it up here. */