# how to identify a segfault in a long emerge ?

## alex.blackbit

during emerging of sys-devel/gcc-4.3.4 a segfault happens, every time.

```
[157216.113030] conftest[7112]: segfault at 7fff1d667ff8 ip 00007f9de01be1dc sp 00007fff1d668000 error 6 in ld-2.10.1.so[7f9de01bd000+1d000]

```

i only see that this happened. how can i find out what exactly happened then ?

i.e. what configure test was executed then ?

i.e. which configure file, while line...

----------

## xaviermiller

Hello,

Take a look at the build logs in /var/tmp/portage/CATEGORY/PACKAGE/tmp/

What is your CFLAG ?

Is your memory OK ?

----------

## alex.blackbit

ok, i'll recompile it with FEATURES="keeptemp keepwork".

maybe i should have expressed before that emerge finishes successfully. no abort.

my memory is definitely okay. i emerge a lot of stuff every day, no problems.

CFLAGS="-O2 -pipe -march=nocona"

----------

## xaviermiller

Normally, you don't need those features.

If there were segfaults, the emerge would stop and keep all temporary files in /var/tmp/portage

----------

## alex.blackbit

again, emerge does _not_ stop when this segfault happens.

i just found out that the error does _not_ happen every time. i had emerge runs without the segfault.

this time i found in the emerge output:

```
/var/tmp/portage/sys-devel/gcc-4.3.4/work/gcc-4.3.4/libjava/configure.host: line 200: 14417 Segmentation fault      ./conftest ./conftest
```

the relevant code snippet is:

```
# This case statement supports generic port properties and may refine

# the above per-CPU defaults.  Note: If your OS implements

# MD_FALLBACK_FRAME_STATE_FOR, then you want to set can_unwind_signal

# here.

case "${host}" in

  i[34567]86*-linux* | \

  powerpc*-linux* | \

  alpha*-linux* | \

  s390*-linux* | \

  sparc*-linux* | \

  ia64-* | \

  x86_64*-linux* | \

  hppa*-linux* | \

  m68k*-linux* | \

  sh-linux* | sh[34]*-linux*)

        can_unwind_signal=yes

        libgcj_ld_symbolic='-Wl,-Bsymbolic'

        if test x$slow_pthread_self = xyes \

           && test x$cross_compiling != xyes; then

          cat > conftest.c <<EOF

#define _GNU_SOURCE 1

#include <pthread.h>

#include <stdlib.h>

#include <sys/resource.h>

#include <limits.h>

void *

tf (void *arg __attribute__ ((unused)))

{

  pthread_attr_t a;

  size_t s;

  if (pthread_getattr_np (pthread_self (), &a)

      || pthread_attr_getstacksize (&a, &s)

      || s > 2 * PTHREAD_STACK_MIN)

    exit (1);

  exit (0);

}

int

main (int argc, char **argv)

{

  pthread_t p;

  void *ret;

  struct rlimit r;

  if (argc == 2)

    { 

      r.rlim_cur = 2 * PTHREAD_STACK_MIN;

      r.rlim_max = 2 * PTHREAD_STACK_MIN;

      if (setrlimit (RLIMIT_STACK, &r))

        exit (1);

      execl (argv[1], argv[0], NULL);

      exit (1);

    }

  if (pthread_create (&p, NULL, tf, NULL)

      || pthread_join (p, &ret))

    exit (1);

  exit (1);

}

EOF

          $CC -o conftest conftest.c -lpthread > /dev/null 2>&1 && \

          ./conftest ./conftest && slow_pthread_self=

          rm -f conftest conftest.c

        fi

        ;;
```

i compiled that by hand and got

```
conftest.c: In function 'main':

conftest.c:31: warning: incompatible implicit declaration of built-in function 'execl'
```

but no segfault. neither on execution.

i try to reproduce the segfault.

----------

## alex.blackbit

the point is that those segfaults do not appear in the PORT_LOGDIR.

maybe there only stdout is logged and the message was sent to stderr or something.

----------

## xaviermiller

Hello,

Please check if you have enough free space on /var/tmp (df -ah /var/tmp)

----------

## alex.blackbit

yes, i have enough free space on /var/tmp.

----------

