[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Cthreads testing suite - a cthread_self() bug



I was asked to make a test suite for Hurd cthreads library.
So, I made a few tests, and one of them failed.
Here it is, only neccesary details left.
Read the entire session for details.

I think than _EXTERN_INLINE mean that both inline form and
library function are provided. Gcc probably thinks the same,
as it uses inline form with -O flag, but tries to
take function from library without -O.

IMHO, this function should be added to libthreads or libc0.2.

Test was done on old instalation and then after major update,
both with the same results.

$ cat self.c
#include <cthreads.h>
#include <stdlib.h>
#include <stdio.h>

cthread_t self;

any_t some_thread (any_t data) {
  self = cthread_self ();
  return NULL;
}

int main () {
  cthread_t expected = cthread_fork (some_thread, NULL);
  cthread_join (expected);

  printf ("Expected = 0x%x, returned = 0x%x\n", expected, self);
  if (expected != self) {
     printf ("ctheard_self() BROKEN !!!\n");
     return 1;
  }
  printf ("ctheard_self() ok.\n");
  return 0;
}
$ gcc self.c -lthreads
/usr/tmp/ccKJfbVD.o: In function `some_thread':
/usr/tmp/ccKJfbVD.o(.text+0x4): undefined reference to `__thread_stack_pointer'
collect2: ld returned 1 exit status
$ gcc -O self.c -lthreads
$ ./a.out
Expected = 0x8049b30, returned = 0x8049b30
ctheard_self() ok.
$ cpp self.c | head -262 | tail -7
extern __inline  void *
__thread_stack_pointer (void)
{
  void *__sp__;
  __asm__ ("movl %%esp, %0" : "=r" (__sp__));
  return __sp__;
}
$ cat /include/machine-sp.h
/* Machine-specific function to return the stack pointer.  i386 version.
   Copyright (C) 1994, 1997 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
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#ifndef _MACHINE_SP_H
#define _MACHINE_SP_H

/* Return the current stack pointer.  */

#ifndef _EXTERN_INLINE
#define _EXTERN_INLINE extern __inline
#endif

_EXTERN_INLINE void *
__thread_stack_pointer (void)
{
  void *__sp__;
  __asm__ ("movl %%esp, %0" : "=r" (__sp__));
  return __sp__;
}

#endif	/* machine-sp.h */
$ exit



Reply to: