From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C80CA3858C56; Wed, 28 Sep 2022 10:31:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C80CA3858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664361117; bh=hqqq6OyIe8DD/z6iNFIYX/cMJD+1KFrEGr98/M+vMAk=; h=From:To:Subject:Date:From; b=OEIHjtnwFoKxucPOYP2UKDfKEZTkYlENWrFA4oyVbT3xH93gbMJlzHBOslkMvHk98 DvFltIHPuil9/lONRN348a0e/5sQqONyLsMPtor7MYSSHkPgi+VOlgBt8kcC50I0p1 5N6iivyx6o0inHe8ZhX3fDp8tFBVifujrm7/mOd4= From: "ycliang at andestech dot com" To: glibc-bugs@sourceware.org Subject: [Bug malloc/29624] New: errno is not cleared when entering main Date: Wed, 28 Sep 2022 10:31:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: malloc X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ycliang at andestech dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29624 Bug ID: 29624 Summary: errno is not cleared when entering main Product: glibc Version: 2.35 Status: UNCONFIRMED Severity: normal Priority: P2 Component: malloc Assignee: unassigned at sourceware dot org Reporter: ycliang at andestech dot com Target Milestone: --- According to the ANSI C standard "7.5 Errors " section 3[1],=20 "The value of errno is zero at program startup, but is never set to zero by any library function." The "program startup" is also defined in ANSI C standard=20 "5.1.2.2.1 Program startup" section 1[2], "The function called at program startup is named main." Therefore, it should be reasonable to expect=20 errno be zero when main is executed. However, we found that=20 the following program would get non-zero errno under some circumstances. ``` /* errno.c */ #include #include int main() { printf("errno: %d\n", errno); return 0; } $ riscv64-linux-gcc -O0 -g -static -o errno_st errno.c [ 51.968765] random: fast init done /mnt # ./errno errno: 11 [ 51.968765] random: fast init done [ 262.517056] crng init done /mnt # ./errno errno: 0 ``` If the above program is statically-linked,=20 and if the program is executed before "crng init done", the errno will not be zero when entering main. There seems to be syscall (__getrandom) before main is entered, and if the crng is not initialized,=20 the syscall will fail causing the errno to be set. (_dl_get_origin -> __libc_malloc -> ptmalloc_init -> tcache_key_initialize = -> __getrandom) Thanks to Florian's suggestion: "Hiding the getrandom failure is probably sufficient. All other failures in malloc will lead to the process failing to start, so those errors don't need to be masked." We should clear the errno for the getrandom failure Related discussion: https://sourceware.org/pipermail/libc-help/2022-September/006301.html --=20 You are receiving this mail because: You are on the CC list for the bug.=