Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 May 1995 21:35:49 -0400 (EDT)
From:      Richard Toren <rpt@miles.sso.loral.com>
To:        hackers <hackers@FreeBSD.org>
Subject:   GNU cpp bug with pthreads 
Message-ID:  <Pine.SUN.3.91.950502211904.11432A-100000@miles>

next in thread | raw e-mail | index | archive | help
I may have found one of the sources of my problems with pthreads. It 
appears that the cpp in 2.0R (GNU CPP version 2.6.2 (80386, BSD syntax))
may have a bug in it. If this has already been replaces in -current, 
please let me know.

cpp, when expanding the concatenate operator '##' seems to append a 
couple (3) blanks after the substitution. Here is a piece of pthreads and 
an abbreviated command line to test. Line 8 is the one munged up.

When I compile this with the following command, the assembler barfs:
  > gcc -DSYSCALL_NAME=open -c syscall-template.S -o Sopen.o -save-temps

I get:
    as: syscall-template.s:227: invalid character '_' in opcode.

If you look at the intermediate saved file, you find a line that begins 
with :
.globl _machdep_sys_open   ;    _machdep_sys_open   :;  movl $(5    ),
                                                 ^^^

There are 3 spaces after the substitution of 'open'. The assembler 
apparently does not care for this. If you edit that temp file and remove 
the three spaces, the assembles OK. From the macro definition, the colon 
was immediately after the name making up the label. If you use 
-traditional, you get a file that does assemble, but the SYSCALL_NAME is 
not substituted.

If this has been fixed with a newer release of the cpp; shrug. If not 
watch out for this in your own source.

----------syscall-template.S-----------
#include <sys/syscall.h>

#ifdef __STDC__

#define SYSCALL(x)                  \
    .globl _machdep_sys_##x;        \
                                    \
_machdep_sys_##x:;                  \
                                    \
    movl $(SYS_##x), %eax;          \
    .byte 0x9a; .long 0; .word 7;   \
    jb  1b;                         \
    ret;                            

#else

#define SYSCALL(x)                  \
    .globl _machdep_sys_/**/x;      \
                                    \
_machdep_sys_/**/x:;                \
                                    \
    movl $(SYS_/**/x), %eax;        \
    .byte 0x9a; .long 0; .word 7;   \
    jb  1b;                         \
    ret;                            

#endif


/*
 * Initial asm stuff for all functions.
 */
    .text
    .align  2


/* ==========================================================================
 * error code for all syscalls. The error value is returned as the negative
 * of the errno value.
 */

1:
    neg     %eax
    ret

#define XSYSCALL(NAME)  SYSCALL(NAME)

XSYSCALL(SYSCALL_NAME)
--------------------end src---------------------------

                         ====================================================
Rip Toren               | The bad news is that C++ is not an object-oriented |
rpt@miles.sso.loral.com | programming language. .... The good news is that   |
                        | C++ supports object-oriented programming.          |
                        |    C++ Programming & Fundamental Concepts          |
                        |     by Anderson & Heinze                           |
                         ====================================================



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.950502211904.11432A-100000>