From patchwork Thu Sep 19 15:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 1987471 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Y3ZVogqO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X8fBc1sc3z1y1g for ; Fri, 20 Sep 2024 01:12:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63FC73858C41 for ; Thu, 19 Sep 2024 15:12:06 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 2E0013858D28 for ; Thu, 19 Sep 2024 15:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E0013858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2E0013858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726758707; cv=none; b=dIfpv594ixiDpB8UDgitfjbxDfOz4iRwYCkrRs7Va+hkebGX3YWzYHcvb3VES8JJinP0XP/bZnv0l84RQ9Hfv2y/yELGdqDIndHyQtv3k/nlfd93GmkCKOwcZxiwmNLT1vKGU5iyEAFOSD+4ETzs7JO0+tmQAiWHN24cEq6TVNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726758707; c=relaxed/simple; bh=92OBDPcOmhlVg88bfH0jPid/sm5OJttNPDS34U7+glw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fFUbp9QQMzCT86LHKScnrQQVDi8K2S5VjwwbtpyJZWLfph9n8WhyGP98veQlN/DivJmi2dMi+lcaJbhrF8o8A/J6LQsUpvbSo7hj6iEHpahqN+HvzVCPBvMv6E37gQwHz+te5ndnlyE1YZV2k+HMN5Uxyn8G2jSNeNvllHVFsJQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726758704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dkpNcMAqeUYF/EQiUA+12ZBtBWK+nSVWTjULDj8ZcKM=; b=Y3ZVogqOkFkK5VRzqCr0SKi2kKt06TKcwCnXzQ5X2jy8zeC9eqBAxEu3+CoFRckT7t9KxH TvoIhoW3THtCsDWk94UUt8nCZVPnpk8me4p2Ly4DmtK8+ic9H4Vvdr8LqDa8OG81zT5rS3 33InVUux5QLrNti6N9gRrVDdmBTMiQ4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-w46Y4PXcNYu6Nv8TxFSVKA-1; Thu, 19 Sep 2024 11:11:43 -0400 X-MC-Unique: w46Y4PXcNYu6Nv8TxFSVKA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCC131956088 for ; Thu, 19 Sep 2024 15:11:42 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.9.34]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 301BB19560A3; Thu, 19 Sep 2024 15:11:42 +0000 (UTC) From: Aaron Merey To: libc-alpha@sourceware.org Cc: Aaron Merey Subject: [PATCH v2] Test that errno is set to 0 at program startup Date: Thu, 19 Sep 2024 11:11:39 -0400 Message-ID: <20240919151139.21163-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Add new testcase elf/tst-startup-errno.c which tests that errno is set to 0 at first ELF constructor execution and at the start of the program's main function. Tested for x86_64 Reviewed-by: Carlos O'Donell --- v1: https://sourceware.org/pipermail/libc-alpha/2024-September/159857.html v2 changes: Testcase calls main() directly and no longer includes test-driver.c. elf/Makefile | 1 + elf/tst-startup-errno.c | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 elf/tst-startup-errno.c diff --git a/elf/Makefile b/elf/Makefile index 00622ace9d..be1a99ea26 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -457,6 +457,7 @@ tests += \ tst-single_threaded-pthread \ tst-sonamemove-dlopen \ tst-sonamemove-link \ + tst-startup-errno \ tst-thrlock \ tst-tls-dlinfo \ tst-tls-ie \ diff --git a/elf/tst-startup-errno.c b/elf/tst-startup-errno.c new file mode 100644 index 0000000000..59a1005fb6 --- /dev/null +++ b/elf/tst-startup-errno.c @@ -0,0 +1,58 @@ +/* Test the value of errno at program startup. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +/* Verify that errno is 0 at first ELF constructor execution and at + the start of main. */ + +static void set_ctor_errno (void) __attribute__((constructor)); +static int ctor_errno = -1; + +static void +set_ctor_errno (void) +{ + ctor_errno = errno; +} + +static int +get_ctor_errno (void) +{ + return ctor_errno; +} + +int +main (void) +{ + if (errno != 0) + { + printf ("At start of main errno set to %d != 0\n", errno); + exit (1); + } + + if (get_ctor_errno () != 0) + { + printf ("At ctor exec errno set to %d != 0\n", get_ctor_errno ()); + exit (1); + } + + return 0; +} +