From patchwork Wed Nov 29 14:17:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 748099 Delivered-To: patch@linaro.org Received: by 2002:adf:e9c2:0:b0:32d:baff:b0ca with SMTP id l2csp331670wrn; Wed, 29 Nov 2023 06:17:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKqcvRKRtz5QF3jG4MTJl06I8M2+dXLzGM8UyfdDlF97xriG8803MQNvwxcs/kgFs8v/VT X-Received: by 2002:ad4:4bad:0:b0:67a:195e:5bce with SMTP id i13-20020ad44bad000000b0067a195e5bcemr18561393qvw.60.1701267458821; Wed, 29 Nov 2023 06:17:38 -0800 (PST) Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d4-20020a056214184400b006594b2aa680si13398778qvy.491.2023.11.29.06.17.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:17:38 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IGLY9ZmH; arc=fail (signature failed); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EA33388301D for ; Wed, 29 Nov 2023 14:17:38 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id C0B2D386D62B for ; Wed, 29 Nov 2023 14:17:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0B2D386D62B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C0B2D386D62B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701267454; cv=none; b=Xw+OV6Wt5EtsdkDWiwCnUO0U3oSiCbRAAt2UVZx9J52361N+40s+TpI2nw98ODlGfXWgf62MCLbUD29zAmos380xZ7CnlNS8EwQsyO9HxH9v5jIqatBzlEJ4D1WDueMbX2r976evwA4fsRhnRvAC5z8KITOgrMqiVLAGs/gpssY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701267454; c=relaxed/simple; bh=HhyCB+1jobWXbgXk30PShVGWDTbmb/L/iaQXe1Qixpg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ASf9YVwIz2mRf/wL+fTmT/bkVw7fV7Hcv+UklkDvtZI3NLPvu2bZenwdxLMd7adoBiwkJpGA1ndjhpbbbMIj6i9UNHXOxhCFThAmPVPv7zIoadeIblHrbI9ItcRL/sBnzlzRHsB7AWrARScCOefjF/H6R3kNCVVjLDV3FMcrzNc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6cbe716b511so5228789b3a.3 for ; Wed, 29 Nov 2023 06:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701267451; x=1701872251; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=iR2epVstRphtOkAHZsLWSmoPrpfBNXYGJsWErnugAaI=; b=IGLY9ZmHA/rUM6lQjuSLpbX25hfmToeByLdTgGDuzAu8pS8gvjbOFUahsw/I4PqOOw SsHRvv+Usc32NZmxLl4visyMvPKzUjHIpm+I+gcnV/dXDq5AEwiP7fMOZA4TQrT5SjVW s5re6VjWhC1a67MFDgZy6W3J+mpgY72cbfxh4g9eEHVQp+8CE8jkxUUkTAOxBiqr2lj0 3025/0G1nQwHsMsipv7mbwFnZLjj7D4srLr6/mMzJyWkUWwvsKALWBE373hmhuwAFXpD zoVaObi7Jmu2IswG1NJhIYMcVw38CFKl7fJhzEXW8uZ+iVCqt8bbHGs9OSuFz5/lHVzh 4Yvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267451; x=1701872251; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iR2epVstRphtOkAHZsLWSmoPrpfBNXYGJsWErnugAaI=; b=vDEXYp60jrkHUlFRwP1uJ36gBgfjCpMYNBGkWV5bEqvHWDlmxVj+iG6fexJHQyu2du kVzJqMjh9xk/Qgxbu62SoYpoUfvK+pxtMvKJUmP3lVdZSixAwaSr5+pqJZSQSKD1LvFY YKVoTENlksfZzwMrIen0zbbkTd66tWxTj66MMw3YQz4Hg2dCFcB/ouk7IvQ6a2CDwhse PqS+mCPE7/yEQ+s9GzGVVygP/HPVHLj6w4Qr6w5k7xaCMVWttQnIHMc4adeYh9BLP8xx BIhjFbSHS4ddcT2t9kk3RilKJnLHTw/eHADhBjmYCPh2CQCEjisuylIO146u1bBmq6mZ xkVw== X-Gm-Message-State: AOJu0YylkVz4X3v2bzBEG8YYUKoP3Usb0RXJMFls5sHR61+s+4CQ1zTZ Zk08sXpsLzEnK7/BLvng7Q3mbPJS7G8kypCpnK0= X-Received: by 2002:a05:6a00:1797:b0:6cb:d28f:d91e with SMTP id s23-20020a056a00179700b006cbd28fd91emr20572737pfg.25.1701267450781; Wed, 29 Nov 2023 06:17:30 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:bcdb:81ba:2a75:31bd:f1fc]) by smtp.gmail.com with ESMTPSA id it14-20020a056a00458e00b006cde12bd590sm10109pfb.15.2023.11.29.06.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:17:30 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie Subject: [PATCH] elf: Avoid type aliasing violation on __tunable_get_{default, val} Date: Wed, 29 Nov 2023 11:17:26 -0300 Message-Id: <20231129141726.3325945-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org Checked on x86_64-linux-gnu. --- elf/dl-tunables.c | 54 ++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index 644d21d1b0..85af249bb2 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -340,37 +340,47 @@ __tunables_print (void) } } -void -__tunable_get_default (tunable_id_t id, void *valp) +static void +get_tunable (tunable_type_code_t type_code, void *valp, + const tunable_val_t *tunable) { - tunable_t *cur = &tunable_list[id]; - - switch (cur->type.type_code) + switch (type_code) { case TUNABLE_TYPE_UINT_64: { - *((uint64_t *) valp) = (uint64_t) cur->def.numval; + uint64_t v = tunable->numval; + memcpy (valp, &v, sizeof v); break; } case TUNABLE_TYPE_INT_32: { - *((int32_t *) valp) = (int32_t) cur->def.numval; + uint32_t v = tunable->numval; + memcpy (valp, &v, sizeof v); break; } case TUNABLE_TYPE_SIZE_T: { - *((size_t *) valp) = (size_t) cur->def.numval; + size_t v = tunable->numval; + memcpy (valp, &v, sizeof v); break; } case TUNABLE_TYPE_STRING: { - *((const char **)valp) = cur->def.strval; + memcpy (valp, &tunable->strval, sizeof (char *)); break; } default: __builtin_unreachable (); } } + +void +__tunable_get_default (tunable_id_t id, void *valp) +{ + tunable_t *cur = &tunable_list[id]; + + get_tunable (cur->type.type_code, valp, &cur->def); +} rtld_hidden_def (__tunable_get_default) /* Set the tunable value. This is called by the module that the tunable exists @@ -380,31 +390,7 @@ __tunable_get_val (tunable_id_t id, void *valp, tunable_callback_t callback) { tunable_t *cur = &tunable_list[id]; - switch (cur->type.type_code) - { - case TUNABLE_TYPE_UINT_64: - { - *((uint64_t *) valp) = (uint64_t) cur->val.numval; - break; - } - case TUNABLE_TYPE_INT_32: - { - *((int32_t *) valp) = (int32_t) cur->val.numval; - break; - } - case TUNABLE_TYPE_SIZE_T: - { - *((size_t *) valp) = (size_t) cur->val.numval; - break; - } - case TUNABLE_TYPE_STRING: - { - *((const char **)valp) = cur->val.strval; - break; - } - default: - __builtin_unreachable (); - } + get_tunable (cur->type.type_code, valp, &cur->val); if (cur->initialized && callback != NULL) callback (&cur->val);