From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2775 invoked from network); 3 Jul 2023 02:30:23 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 3 Jul 2023 02:30:23 -0000 Received: (qmail 21519 invoked by uid 550); 3 Jul 2023 02:30:20 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20455 invoked from network); 3 Jul 2023 02:30:19 -0000 Date: Sun, 2 Jul 2023 22:30:08 -0400 From: Rich Felker To: =?utf-8?B?56iL5pm65pif?= Cc: musl@lists.openwall.com Message-ID: <20230703023008.GY4163@brightrain.aerifal.cx> References: <1688024729.28262.ezmlm@lists.openwall.com> <20230629092151.GA10969@openwall.com> <266b8af9.3c84.189192eb083.Coremail.zhixing@nj.iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <266b8af9.3c84.189192eb083.Coremail.zhixing@nj.iscas.ac.cn> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Re: Re: On the redefinition of stdin, stdout, etc. in stdio. h On Mon, Jul 03, 2023 at 08:37:17AM +0800, 程智星 wrote: > hi,friend: > > I have a question to ask: > > 1. The stdin and stdout are redefined in the stdio. h file in the Musl source code, as follows: > > extern FILE *const stdin; > extern FILE *const stdout; > extern FILE *const stderr; > > #define stdin (stdin) > #define stdout (stdout) > #define stderr (stderr) > but,In glibc, they are only redefined as themselves, as follows: > > /* Standard streams. */ > extern FILE *stdin; /* Standard input stream. */ > extern FILE *stdout; /* Standard output stream. */ > extern FILE *stderr; /* Standard error output stream. */ > /* C89/C99 say they're macros. Make them happy. */ > #define stdin stdin > #define stdout stdout > #define stderr stderr > Based on what considerations we will make this change? > > 2. Based on the above modifications, I will report the following errors when compiling packages such as lcr and lxc using Musl as the basic library for yocto embedded compilation: > -o json/.libs/liblxc_la-json_common.o > | In file included from ../../../lxc-4.0.3/src/lxc/json/read-file.h:5, > | from ../../../lxc-4.0.3/src/lxc/json/defs.c:6: > | ../../../lxc-4.0.3/src/lxc/json/defs.c: In function 'make_defs_hook': > | ../../../lxc-4.0.3/src/lxc/json/defs.c:86:26: error: expected identifier before '(' token > | 86 | if (ctx->stderr > 0) > | | ^~~~~~ > | ../../../lxc-4.0.3/src/lxc/json/defs.c:87:34: error: expected identifier before '(' token > | 87 | fprintf(ctx->stderr, "WARNING: unknown key found: %s\n", tree->u.object.keys[i]); > | | ^~~~~~ > | ../../../lxc-4.0.3/src/lxc/json/defs.c:87:21: error: too few arguments to function 'fprintf' > | 87 | fprintf(ctx->stderr, "WARNING: unknown key found: %s\n", tree->u.object.keys[i]); > | | ^~~~~~~ > | In file included from ../../../lxc-4.0.3/src/lxc/json/read-file.h:5, > | from ../../../lxc-4.0.3/src/lxc/json/defs.c:6: > > > Is there a solution to this error report; I tried to synchronize > their definitions in the Musl source code with those in Glibc, and > there was no problem compiling images. Can it be modified to be > consistent with glibc? No, this is a bug in the application. Per 7.21.1 ¶3, stdin, stdout, and stderr are macros which expand to expressions. And per 7.1.3 "Reserved Identifiers", ¶2, "If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined." An application cannot use the names stdin, stdout, or stderr in the manner above if it is including stdio.h. The names of those struct members need to be changed to something that is not in the reserved namespace. If anything, at some point we may be making changes further in the opposite direction, so that the expressions are not lvalues. This has value to catch/preclude other types of application errors. musl would not give up the ability to do things like this for the sake of compatibility with erroneous application sources that could easily be fixed. Rich