NetBSD Problem Report #36511

From cheusov@tut.by  Tue Jun 19 20:13:36 2007
Return-Path: <cheusov@tut.by>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 49CC963B908
	for <gnats-bugs@gnats.netbsd.org>; Tue, 19 Jun 2007 20:13:36 +0000 (UTC)
Message-Id: <s93k5tzya7c.fsf@chen.chizhovka.net>
Date: Tue, 19 Jun 2007 23:13:11 +0300
From: cheusov@tut.by
Reply-To:
To: gnats-bugs@NetBSD.org
Subject: lcc is an ANSI C compiler for a variety of platforms
X-Send-Pr-Version: 3.95

>Number:         36511
>Category:       lib
>Synopsis:       lcc is an ANSI C compiler for a variety of platforms
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 19 20:15:00 +0000 2007
>Last-Modified:  Wed Jun 27 21:00:02 +0000 2007
>Originator:     cheusov@tut.by
>Release:        NetBSD 4.0_BETA2
>Organization:
Best regards, Aleksey Cheusov.
>Environment:
System: NetBSD chen.chizhovka.net 4.0_BETA2 NetBSD 4.0_BETA2 (GENERIC) #18: Sat Jun 9 22:13:59 EEST 2007 cheusov@chen.chizhovka.net:/srv/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
While playing with LCC, an "ANSI C compiler for a variety of platforms"
I found that even Hello World application cannot be compiled with it
under NetBSD.

0 tmp>cat main.c 
#include <stdio.h>

int main (void)
{
        printf ("Hello world\n");
        return 0;
}
0 tmp>gcc main.c 
0 tmp>./a.out                                            
Hello world
0 tmp>lcc main.c 
cpp: /usr/include/sys/cdefs_elf.h:67 /usr/pkg/share/lcc/include/sys/cdefs.h:21 /usr/include/stdio.h:40 main.c:1 Syntax error in #if/#elsif
1 tmp>


Can you make NetBSD include files
a bit friendlier for C compilers other that GCC?

>Fix:

Unknown
>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: re: lib/36511: lcc is an ANSI C compiler for a variety of platforms 
Date: Wed, 20 Jun 2007 06:25:52 +1000


    0 tmp>cat main.c 
    #include <stdio.h>

    int main (void)
    {
            printf ("Hello world\n");
            return 0;
    }
    0 tmp>gcc main.c 
    0 tmp>./a.out                                            
 Hello world
    0 tmp>lcc main.c 
    cpp: /usr/include/sys/cdefs_elf.h:67 /usr/pkg/share/lcc/include/sys/cdefs.h:21 /usr/include/stdio.h:40 main.c:1 Syntax error in #if/#elsif
    1 tmp>


    Can you make NetBSD include files
    a bit friendlier for C compilers other that GCC?


 this should be valid for an ANSI C compiler.  the relevant parts are:

 from <sys/cdefs.h>:

 #ifdef __GNUC__
 #define __GNUC_PREREQ__(x, y)                                           \
         ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||                  \
 	 (__GNUC__ > (x)))
 #else
 #define __GNUC_PREREQ__(x, y)   0
 #endif


 and the usage from <sys/cdefs_elf.h>:

 #if __GNUC_PREREQ__(4, 0)


 so this should come out as "#if 0" for non GCC compilers.  does lcc
 define __GNUC__ by chance?


 .mrg.

From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Tue, 19 Jun 2007 23:46:09 +0300

 >  this should be valid for an ANSI C compiler.  the relevant parts are:
 >  
 >  from <sys/cdefs.h>:
 >  
 >  #ifdef __GNUC__
           ^^^^^^^^
           __STDC__ here

 >  #define __GNUC_PREREQ__(x, y)                                           \
 >          ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||                  \
 >  	 (__GNUC__ > (x)))
 >  #else
 >  #define __GNUC_PREREQ__(x, y)   0
 >  #endif
 >  
 >  
 >  and the usage from <sys/cdefs_elf.h>:
 >  
 >  #if __GNUC_PREREQ__(4, 0)
 >  
 >  
 >  so this should come out as "#if 0" for non GCC compilers.  does lcc
 >  define __GNUC__ by chance?
 No it doesn't not. It defines its own __LCC__

 -- 
 Best regards, Aleksey Cheusov.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Tue, 19 Jun 2007 17:09:03 -0400

 On Jun 19,  8:15pm, cheusov@tut.by (cheusov@tut.by) wrote:
 -- Subject: lib/36511: lcc is an ANSI C compiler for a variety of platforms

 | 0 tmp>cat main.c 
 | #include <stdio.h>
 | 
 | int main (void)
 | {
 |         printf ("Hello world\n");
 |         return 0;
 | }
 | 0 tmp>gcc main.c 
 | 0 tmp>./a.out                                            
 | Hello world
 | 0 tmp>lcc main.c 
 | cpp: /usr/include/sys/cdefs_elf.h:67 /usr/pkg/share/lcc/include/sys/cdefs.h:21 /usr/include/stdio.h:40 main.c:1 Syntax error in #if/#elsif
 | 1 tmp>

 Works fine for me after I change <sys/cdefs.h> to read:

 #if !defined(_STANDALONE) && !defined(_KERNEL)
 #ifdef __GNUC__
 #define __RENAME(x)     ___RENAME(x)
 #else
 #ifdef __lint__
 #define __RENAME(x)     __symbolrename(x)
 #else
 +#ifdef __LCC__
 +#define __RENAME(x)
 +#else
 #error "No function renaming possible"
 +#endif /* __lcc__ */    
 #endif /* __lint__ */
 #endif /* __GNUC__ */
 #else /* _STANDALONE || _KERNEL */
 #define __RENAME(x)     no renaming in kernel or standalone environment
 #endif

 My etc/netbsd.c is in http://www.zoulas.com/NetBSD/lcc/netbsd.c and:

 [5:08pm] 10308>lcc -v hello.c
 lcc $Id: lcc.c,v 4.33 2001/06/28 22:19:58 drh Exp $
 /u/christos/lcc/x86-netbsd/cpp -U__GNUC__ -D_POSIX_SOURCE -D__STDC__=1 -D__STRICT_ANSI__ -Dunix -Di386 -Dlinux -D__unix__ -D__i386__ -D__NetBSD__ -D__signed__=signed -D__LCC__ -I/u/christos/lcc/x86-netbsd/include -I/usr/include hello.c /tmp/lcc123110.i
 /u/christos/lcc/x86-netbsd/rcc -target=x86/linux -v /tmp/lcc123110.i /tmp/lcc123111.s
 /u/christos/lcc/x86-netbsd/rcc $Name:  $($Id: main.c,v 1.2 2003/10/20 17:54:27 drh Exp $)
 /usr/bin/as -o /tmp/lcc123112.o /tmp/lcc123111.s
 /usr/bin/ld -m elf_i386 -dynamic-linker /usr/libexec/ld.elf_so -o a.out /usr/lib/crt0.o /usr/lib/crti.o /usr/lib/crtbegin.o /tmp/lcc123112.o -L/u/christos/lcc/x86-netbsd/ -llcc -L/usr/lib -lgcc -lc -lm /usr/lib/crtend.o /usr/lib/crtn.o
 rm /tmp/lcc123112.o /tmp/lcc123110.i /tmp/lcc123111.s
 [5:08pm] 10309>./a.out 
 hello world

 christos

From: matthew green <mrg@eterna.com.au>
To: Aleksey Cheusov <cheusov@tut.by>
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org, gnats-bugs@NetBSD.org
Subject: re: lib/36511: lcc is an ANSI C compiler for a variety of platforms 
Date: Wed, 20 Jun 2007 09:47:21 +1000

 the lcc package needs to have it's own sys/cdefs.h updated to a modern
 netbsd.  (and perhaps some magic to make it work on older release?)

 see pkgsrc/devel/lcc/files/cdefs.h.


 .mrg.

From: christos@zoulas.com (Christos Zoulas)
To: matthew green <mrg@eterna.com.au>,
	Aleksey Cheusov <cheusov@tut.by>
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org, gnats-bugs@NetBSD.org
Subject: re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Tue, 19 Jun 2007 21:36:14 -0400

 On Jun 20,  9:47am, mrg@eterna.com.au (matthew green) wrote:
 -- Subject: re: lib/36511: lcc is an ANSI C compiler for a variety of platfor

 | 
 | the lcc package needs to have it's own sys/cdefs.h updated to a modern
 | netbsd.  (and perhaps some magic to make it work on older release?)
 | 
 | see pkgsrc/devel/lcc/files/cdefs.h.

 I think that we can add an #ifdef __LCC__ and fix the RENAME() macro
 in cdefs.h.

 christos

From: Aleksey Cheusov <cheusov@tut.by>
To: christos@zoulas.com (Christos Zoulas)
Cc: matthew green <mrg@eterna.com.au>, lib-bug-people@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, gnats-bugs@NetBSD.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Wed, 20 Jun 2007 20:24:53 +0300

 > On Jun 20,  9:47am, mrg@eterna.com.au (matthew green) wrote:
 > -- Subject: re: lib/36511: lcc is an ANSI C compiler for a variety of platfor

 > | 
 > | the lcc package needs to have it's own sys/cdefs.h updated to a modern
 > | netbsd.  (and perhaps some magic to make it work on older release?)
 > | 
 > | see pkgsrc/devel/lcc/files/cdefs.h.

 > I think that we can add an #ifdef __LCC__ and fix the RENAME() macro
 > in cdefs.h.

 RENAME macro is defined in lcc's cdefs.h but after #including cdecl_elf.h.

 How about about fixing
       #if __STDC__
 !         ^^^^^^^^
       #define ___RENAME(x)    __asm(___STRING(_C_LABEL(x)))
       #else
       #ifdef __LEADING_UNDERSCORE
       ...

 and 

       #if __STDC__
 !         ^^^^^^^^
       #define __strong_alias(alias,sym)                      \
       __asm(".global " _C_LABEL_STRING(#alias) "\n"          \
       _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));


 P.S.
 wip/tcc has the same problem

 0 ~>tcc -c -o main.o main.c 
 In file included from main.c:1:
 In file included from /usr/include/stdio.h:40:
 /usr/include/sys/cdefs.h:254: #error "No function renaming possible"
 1 ~>tcc -v 
 tcc version 0.9.22
 0 ~>

 -- 
 Best regards, Aleksey Cheusov.

From: christos@zoulas.com (Christos Zoulas)
To: Aleksey Cheusov <cheusov@tut.by>
Cc: matthew green <mrg@eterna.com.au>, lib-bug-people@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, gnats-bugs@NetBSD.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Wed, 20 Jun 2007 13:27:46 -0400

 On Jun 20,  8:24pm, cheusov@tut.by (Aleksey Cheusov) wrote:
 -- Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platfor

 | > On Jun 20,  9:47am, mrg@eterna.com.au (matthew green) wrote:
 | > -- Subject: re: lib/36511: lcc is an ANSI C compiler for a variety of platfor
 | 
 | > | 
 | > | the lcc package needs to have it's own sys/cdefs.h updated to a modern
 | > | netbsd.  (and perhaps some magic to make it work on older release?)
 | > | 
 | > | see pkgsrc/devel/lcc/files/cdefs.h.
 | 
 | > I think that we can add an #ifdef __LCC__ and fix the RENAME() macro
 | > in cdefs.h.
 | 
 | RENAME macro is defined in lcc's cdefs.h but after #including cdecl_elf.h.

 That is why we should not make local copies of those file.

 | How about about fixing
 |       #if __STDC__
 | !         ^^^^^^^^
 |       #define ___RENAME(x)    __asm(___STRING(_C_LABEL(x)))
 |       #else
 |       #ifdef __LEADING_UNDERSCORE
 |       ...
 | 
 | and 
 | 
 |       #if __STDC__
 | !         ^^^^^^^^
 |       #define __strong_alias(alias,sym)                      \
 |       __asm(".global " _C_LABEL_STRING(#alias) "\n"          \
 |       _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
 | 
 | 
 | P.S.
 | wip/tcc has the same problem
 | 
 | 0 ~>tcc -c -o main.o main.c 
 | In file included from main.c:1:
 | In file included from /usr/include/stdio.h:40:
 | /usr/include/sys/cdefs.h:254: #error "No function renaming possible"
 | 1 ~>tcc -v 
 | tcc version 0.9.22
 | 0 ~>

 I don't understand what to fix here....

 christos

From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Wed, 27 Jun 2007 20:18:40 +0300

 >  | How about about fixing
 >  |       #if __STDC__
 >  | !         ^^^^^^^^
 >  |       #define ___RENAME(x)    __asm(___STRING(_C_LABEL(x)))
 >  |       #else
 >  |       #ifdef __LEADING_UNDERSCORE
 >  |       ...
 >  | 
 >  | and 
 >  | 
 >  |       #if __STDC__
 >  | !         ^^^^^^^^
 >  |       #define __strong_alias(alias,sym)                      \
 >  |       __asm(".global " _C_LABEL_STRING(#alias) "\n"          \
 >  |       _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
 >  | 
 >  | 

 >  I don't understand what to fix here....

 I'm not sure that *non-standard* __asm directive can be allowed if
 __STDC__ is defined. Can you explain this?

 P.S.
 It's not clear for me what things should be fixed?
 LCC itself or NetBSD includes or both?

 P.S.
 Should I report PR about wip/tcc separately?

 -- 
 Best regards, Aleksey Cheusov.

From: Martin Husemann <martin@duskware.de>
To: Aleksey Cheusov <cheusov@tut.by>
Cc: gnats-bugs@NetBSD.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Wed, 27 Jun 2007 22:19:27 +0200

 On Wed, Jun 27, 2007 at 08:18:40PM +0300, Aleksey Cheusov wrote:
 > I'm not sure that *non-standard* __asm directive can be allowed if
 > __STDC__ is defined. Can you explain this?

 I'm not sure what code you quote - it is not in NetBSD AFAICS.

 > P.S.
 > It's not clear for me what things should be fixed?
 > LCC itself or NetBSD includes or both?

 I think both.

 How about we protect the whole __RENAME(x) block in NetBSD's cdefs.h by

   #ifndef __RENAME / #endif

 and modify lcc to provide a working __RENAME(x) macro? We don't need to special
 case __LCC__ then and can use the same for other compilers.

 Martin

From: christos@zoulas.com (Christos Zoulas)
To: Aleksey Cheusov <cheusov@tut.by>, gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Wed, 27 Jun 2007 16:49:29 -0400

 On Jun 27,  8:18pm, cheusov@tut.by (Aleksey Cheusov) wrote:
 -- Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platfor

 | 
 | >  | How about about fixing
 | >  |       #if __STDC__
 | >  | !         ^^^^^^^^
 | >  |       #define ___RENAME(x)    __asm(___STRING(_C_LABEL(x)))
 | >  |       #else
 | >  |       #ifdef __LEADING_UNDERSCORE
 | >  |       ...
 | >  | 
 | >  | and 
 | >  | 
 | >  |       #if __STDC__
 | >  | !         ^^^^^^^^
 | >  |       #define __strong_alias(alias,sym)                      \
 | >  |       __asm(".global " _C_LABEL_STRING(#alias) "\n"          \
 | >  |       _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
 | >  | 
 | >  | 
 | 
 | >  I don't understand what to fix here....
 | 
 | I'm not sure that *non-standard* __asm directive can be allowed if
 | __STDC__ is defined. Can you explain this?
 | 
 | P.S.
 | It's not clear for me what things should be fixed?
 | LCC itself or NetBSD includes or both?
 | 
 | P.S.
 | Should I report PR about wip/tcc separately?
 | 
 | -- 
 | Best regards, Aleksey Cheusov.

 LCC does not support renaming from what I see. So if in cdefs.h
 we just #define __RENAME(x) to nothing, the code will compile.
 The problem is that it will fail to work for renamed functions.
 We need to find a portable way of doing renaming for other compilers
 and there seems to be none. 

 christos

From: Aleksey Cheusov <cheusov@tut.by>
To: Martin Husemann <martin@duskware.de>
Cc: gnats-bugs@NetBSD.org
Subject: Re: lib/36511: lcc is an ANSI C compiler for a variety of platforms
Date: Wed, 27 Jun 2007 23:56:59 +0300

 > On Wed, Jun 27, 2007 at 08:18:40PM +0300, Aleksey Cheusov wrote:
  >> I'm not sure that *non-standard* __asm directive can be allowed if
  >> __STDC__ is defined. Can you explain this?

 > I'm not sure what code you quote - it is not in NetBSD AFAICS.
 sys/sys/cdefs_elf.h revision 1.27

      41 #if __STDC__
      42 #define ___RENAME(x)    __asm(___STRING(_C_LABEL(x)))
      43 #else
      44 #ifdef __LEADING_UNDERSCORE

      54 #if __STDC__
      55 #define __strong_alias(alias,sym)
      56     __asm(".global " _C_LABEL_STRING(#alias) "\n"
      57             _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));

      99 #if __STDC__
     100 #define __SECTIONSTRING(_sec, _str)
     101         __asm(".section " #_sec "\n\t.asciz \"" _str "\"\n\t.previous")
     102 #else
     103 #define __SECTIONSTRING(_sec, _str)
     104         __asm(".section _sec\n\t.asciz _str\n\t.previous")
     105 #endif

  >> P.S.
  >> It's not clear for me what things should be fixed?
  >> LCC itself or NetBSD includes or both?

 > I think both.

 > How about we protect the whole __RENAME(x) block in NetBSD's cdefs.h by

 >   #ifndef __RENAME / #endif

 > and modify lcc to provide a working __RENAME(x) macro? We don't need
 > to special case __LCC__ then and can use the same for other
 > compilers.

 This sounds reasoble but I don't know what is this __RENAME macro and
 "function renaming" for.
 And why an absense of it is a fatal error

 sys/cdefs.h:
     254 #error "No function renaming possible"

 wip/tcc fails because of this.

 -- 
 Best regards, Aleksey Cheusov.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.