All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] backtrace() not working on ARMv7a
@ 2014-07-31  6:30 prafullakota
  2014-07-31  6:39 ` Thomas Petazzoni
  0 siblings, 1 reply; 4+ messages in thread
From: prafullakota @ 2014-07-31  6:30 UTC (permalink / raw)
  To: buildroot

Hi,

I am trying to generate a call stack trace using backtrace() API which is
part of libbacktrace. The idea is to catch a SIGSEGV signal and call
backtrace() to print all the address values and compare the obtained
addresses from objdump -D of executable. Following is the output seen on
ARMv7a platform with buildroot cross-toolchain (gcc- 4.8.2, binutis-2.18.1).

To compile the application:
${CROSS_COMPILE}gcc -o crash_test -O0 -funwind-tables -rdynamic crash_test.c

ARMv7a# ./crash_test
Trying to access NULL pointer!
SIGSEGV Handler!
Got Backtrace Size=2
0x00008724
0x000087c4
ARMv7a#

The above function call trace is only that of the signal hander
(print_back_trace, sigsegv_handler) and does not show the entire call stack
for the function where program crashed (print_back_trace, sigsegv_handler,
func2, main).

On x86 host same program shows a deeper function call trace right up to the
main function and even beyond:
x86-RHEL5-host$./crash_test
Trying to access NULL pointer!
SIGSEGV Handler!
Got Backtrace Size=7
0x00400939
0x004009ab
0x30930302f0
0x004009d3
0x00400a7b
0x309301d994
0x00400889
x86-RHEL5-host$

Can someone please comment on what is going wrong. Any special flags that
need to be used while compiling/linking the program.

For other issues like NULL pointer access or invalid memory access,
backtrace is working fine in glibc but not for below type of issues.

void func1() {
  int    val;
  char buf[256];
  val = 100;
  printf("\nTrying to construct invalid buffer!\n");
  snprintf(buf, sizeof (buf), "%s", val);
  printf("The content of buf: %s\n", buf);

}

For above issue uclibc forum has given fix in below link
http://lists.uclibc.org/pipermail/uclibc/2013-September/047932.html

Similar issue in uclibc was solved by creating a patch to uclibc files, can
some one let me know if there is any existing patch is available for glibc
similar to this?, if not can anyone help me in providing the similar patch
for glibc.

Please let me know if i can provide any info.

/Thanks
Prafulla

-------------code------------------------------
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>

void print_back_trace() {
  void *array[32];
  int index, size;

  size = backtrace (array, 32);
  printf("Got Backtrace Size=%d\n", size);
  for (index = 0; index < size; index++)
  {
    printf ("0x%08lx\n", (unsigned long) array[index]);
  }
}

static void sigsegv_handler (int sig, siginfo_t * info, void *v)
{
  printf("SIGSEGV Handler!\n");
  print_back_trace();
  exit (0);
}

void func2() {
   int val;
   unsigned int *ptr;
   ptr = 0;
   printf("Trying to access NULL pointer!\n");
   val = *ptr;
   printf ("Read 0x%x from %p\n", val, ptr);
}

void func1() {
  int    val;
  char buf[256];
  val = 100;
  printf("\nTrying to construct invalid buffer!\n");
  snprintf(buf, sizeof (buf), "%s", val);
  printf("The content of buf: %s\n", buf);

}

int main()
{
  struct sigaction sig_act;
  int    rc;

  sig_act.sa_sigaction = sigsegv_handler;
  rc = sigaction (SIGSEGV, &sig_act, 0);

  func1(); 
  return 0;
}




--
View this message in context: http://buildroot-busybox.2317881.n4.nabble.com/backtrace-not-working-on-ARMv7a-tp76350.html
Sent from the Buildroot (busybox) mailing list archive@Nabble.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] backtrace() not working on ARMv7a
  2014-07-31  6:30 [Buildroot] backtrace() not working on ARMv7a prafullakota
@ 2014-07-31  6:39 ` Thomas Petazzoni
  2014-07-31  7:47   ` prafulla_kota
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2014-07-31  6:39 UTC (permalink / raw)
  To: buildroot

Dear prafullakota,

On Wed, 30 Jul 2014 23:30:55 -0700 (PDT), prafullakota wrote:

> I am trying to generate a call stack trace using backtrace() API which is
> part of libbacktrace. The idea is to catch a SIGSEGV signal and call
> backtrace() to print all the address values and compare the obtained
> addresses from objdump -D of executable. Following is the output seen on
> ARMv7a platform with buildroot cross-toolchain (gcc- 4.8.2, binutis-2.18.1).

Thanks for the report. Could you provide your Buildroot .config so we
can see in more details what is your toolchain configuration
(especially which C library is used, and which version of it).

> For above issue uclibc forum has given fix in below link
> http://lists.uclibc.org/pipermail/uclibc/2013-September/047932.html

Right, but from a quick look, this patch was never applied.

> Similar issue in uclibc was solved by creating a patch to uclibc files, can
> some one let me know if there is any existing patch is available for glibc
> similar to this?, if not can anyone help me in providing the similar patch
> for glibc.

Are you sure you're using glibc ? Could you provide your
Buildroot .config file ?

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] backtrace() not working on ARMv7a
  2014-07-31  6:39 ` Thomas Petazzoni
@ 2014-07-31  7:47   ` prafulla_kota
  2014-07-31 11:58     ` Thomas Petazzoni
  0 siblings, 1 reply; 4+ messages in thread
From: prafulla_kota @ 2014-07-31  7:47 UTC (permalink / raw)
  To: buildroot

Hi Thomas, 

Thanks for quick reply and i have attached the .config file. 

We have applied below patch in ulibc and it worked fine for below
requirement and we do have requirement on GLIBC as well and requesting the
same here. 

Thanks, 
Prafulla kota

buildroot_dot_config.buildroot_dot_config
<http://buildroot-busybox.2317881.n4.nabble.com/file/n76360/buildroot_dot_config.buildroot_dot_config>  



--
View this message in context: http://buildroot-busybox.2317881.n4.nabble.com/backtrace-not-working-on-ARMv7a-tp76350p76360.html
Sent from the Buildroot (busybox) mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] backtrace() not working on ARMv7a
  2014-07-31  7:47   ` prafulla_kota
@ 2014-07-31 11:58     ` Thomas Petazzoni
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Petazzoni @ 2014-07-31 11:58 UTC (permalink / raw)
  To: buildroot

Dear prafulla_kota,

On Thu, 31 Jul 2014 00:47:34 -0700 (PDT), prafulla_kota wrote:

> Thanks for quick reply and i have attached the .config file. 
> 
> We have applied below patch in ulibc and it worked fine for below
> requirement and we do have requirement on GLIBC as well and requesting the
> same here. 

I think I would suggest to ask on the glibc mailing list instead. There
has been some discussion about this back in 2011
(http://gcc.1065356.n5.nabble.com/ARM-Linux-EABI-unwinding-through-a-segfault-handler-td692287.html),
not sure what the conclusion was. Buildroot uses recent versions of
glibc, so you can perfectly contact upstream and report this issue.

Let us know what the outcome of the discussion is, or maybe even Cc:
the Buildroot mailing list so that if there's any Buildroot specific
question, we can answer.

Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-31 11:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-31  6:30 [Buildroot] backtrace() not working on ARMv7a prafullakota
2014-07-31  6:39 ` Thomas Petazzoni
2014-07-31  7:47   ` prafulla_kota
2014-07-31 11:58     ` Thomas Petazzoni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.