http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58075

--- Comment #1 from Ian Lance Taylor <ian at airs dot com> ---
That compilation error means that a configure test detected that the setcontext
call modified TLS variables, which should not happen.  That does happen on some
older versions of Solaris and NetBSD, and the code in libgo/runtime/proc.c has
a workaround for those versions.  Apparently HP/UX also has this bug, and
somebody will need to write a workaround there as well.

The test case can be found in libgo/configure.ac, and I've appended it below. 
The test case should compile and run and exit with a zero exit status (you may
need to provide the -pthread option when compiling and linking, I don't know
what HP/UX requires in that regard).  If the program does not exit with a zero
status, there is a bug in the implementation of setcontext.  I encourage you to
report that bug to HP.

#include <pthread.h>
#include <stdlib.h>
#include <ucontext.h>
#include <unistd.h>

__thread int tls;

static char stack[10 * 1024 * 1024];
static ucontext_t c;

/* Called via makecontext/setcontext.  */

static void
cfn (void)
{
  exit (tls);
}

/* Called via pthread_create.  */

static void *
tfn (void *dummy)
{
  /* The thread should still see this value after calling
     setcontext.  */
  tls = 0;

  setcontext (&c);

  /* The call to setcontext should not return.  */
  abort ();
}

int
main ()
{
  pthread_t tid;

  /* The thread should not see this value.  */
  tls = 1;

  if (getcontext (&c) < 0)
    abort ();

  c.uc_stack.ss_sp = stack;
  c.uc_stack.ss_flags = 0;
  c.uc_stack.ss_size = sizeof stack;
  c.uc_link = NULL;
  makecontext (&c, cfn, 0);

  if (pthread_create (&tid, NULL, tfn, NULL) != 0)
    abort ();

  if (pthread_join (tid, NULL) != 0)
    abort ();

  /* The thread should have called exit.  */
  abort ();
}

Reply via email to