From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19014 invoked by alias); 27 May 2002 04:35:00 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 19007 invoked from network); 27 May 2002 04:34:55 -0000 Received: from unknown (HELO mail3.panix.com) (166.84.1.74) by sources.redhat.com with SMTP; 27 May 2002 04:34:55 -0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mail3.panix.com (Postfix) with ESMTP id 09E8A982AE for ; Mon, 27 May 2002 00:33:29 -0400 (EDT) Received: (from librik@localhost) by panix2.panix.com (8.11.3nb1/8.8.8/PanixN1.0) id g4R4XSX02947 for cygwin@cygwin.com; Mon, 27 May 2002 00:33:28 -0400 (EDT) Date: Mon, 27 May 2002 05:31:00 -0000 From: Message-Id: <200205270433.g4R4XSX02947@panix2.panix.com> To: cygwin@cygwin.com Subject: 1.3.10: Bug: -undef does not work in cpp (gcc 2.95.3-5) X-SW-Source: 2002-05/txt/msg01629.txt.bz2 1.3.10: Bug: -undef does not work in cpp (gcc 2.95.3-5) DESCRIPTION OF THE BUG: The -undef flag, "do not predefine any macros," fails in CPP (GCC) for Cygwin. This is version 2.95.3-5 of GCC. This flag is supposed to invoke the preprocessor without any built-in macros defined. Cygwin's special CPP defines several macros which rewrite Microsoft keywords (such as __cdecl and __declspec) to GCC form (using the __attribute__ syntax). The -undef flag fails to undefine any of these automatically defined CPP macros. Thus it is difficult to use Cygwin's CPP with the IMAKE make system (which uses CPP to preprocess Makefiles) or with a "cross compilation" preprocess targeted at a non- GCC compiler. DEMONSTRATION OF THE BUG: On Linux, the CPP -undef flag works. Here we invoke CPP with the -dM flag, which dumps the values of all predefined macros: linux% /lib/cpp -dM /dev/null #define linux 1 #define __i386__ 1 #define i386 1 #define __ELF__ 1 #define unix 1 linux% When -undef is added, all these predefined macros go away: linux% /lib/cpp -dM -undef /dev/null linux% On Cygwin, most of the predefined macros do not go away when you use -undef. Here is a dump without -undef: cygwin$ cpp -dM /dev/null #define _stdcall __attribute__((__stdcall__)) #define __i386__ 1 #define _X86_ 1 #define __i386 1 #define __i686 1 #define __declspec(x) __attribute__((x)) #define pentiumpro 1 #define __CYGWIN__ 1 #define _cdecl __attribute__((__cdecl__)) #define __pentiumpro 1 #define i386 1 #define i686 1 #define __pentiumpro__ 1 #define __stdcall __attribute__((__stdcall__)) #define __unix 1 #define __unix__ 1 #define __i686__ 1 #define __cdecl __attribute__((__cdecl__)) #define __CYGWIN32__ 1 #define unix 1 When -undef is added, predefined macros remain: cygwin$ cpp -dM -undef /dev/null #define _stdcall __attribute__((__stdcall__)) #define __i386__ 1 #define __i386 1 #define __i686 1 #define __declspec(x) __attribute__((x)) #define pentiumpro 1 #define __CYGWIN__ 1 #define _cdecl __attribute__((__cdecl__)) #define __pentiumpro 1 #define i386 1 #define i686 1 #define __pentiumpro__ 1 #define __stdcall __attribute__((__stdcall__)) #define __unix 1 #define __unix__ 1 #define __i686__ 1 #define __cdecl __attribute__((__cdecl__)) #define __CYGWIN32__ 1 #define unix 1 In particular, the transformations of __cdecl, __stdcall, __declspec, etc. are retained. There seems to be no way to turn off all predefined macros, despite the documentation for -undef. Cygwin version is 1.3.10. GCC version is 2.95.3-5. Host OS is Windows 2000. DISCUSSION OF THE BUG: Apparently CPP predefines these flags by passing them as command-line arguments to /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/cpp0.exe. The -v flag reveals that cpp0 is invoked as follows: cygwin$ cpp -v -undef Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs gcc version 2.95.3-5 (cygwin special) /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/cpp0.exe -lang-c -v -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D_stdcall=__attribute__((__stdcall__)) -D_cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -D__CYGWIN32__ -D__CYGWIN__ -Dunix -D__unix__ -D__unix -isystem /usr/local/include -idirafter /usr/include -idirafter /usr/include/w32api - The -undef flag should cause CPP to not pass all those -D macros to cpp0. FIX FOR THE BUG: Sorry I don't have a patch. (I've been told that really understanding GCC takes six months of intense study. Hopefully someone who's put in the six months can easily spot how to patch the sources to fix this bug.) It looks like /usr/src/gcc-2.95.3-5/gcc/config/i386/cygwin.h is the right place to make the change. Perhaps {!undef:...} should be wrapped around all of the options in CPP_SPEC? One workaround is to use a lot of -U options, to turn off each macro individually. But that is not upwardly compatible with potential later additions to the predefined macros. -undef is the only way to turn them all off at once. This is breaking an IMAKE-based build system I'm trying to port to Cygwin. Thanks for any help, - David Librik librik@panix.com -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/