Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp361872rdb; Sat, 27 Jan 2024 09:28:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6bYPvbX6dA2rah0/dHIJrIJBkE5Fjb+TjABKfxBFDrauXtKi3Dr1KdnVhf4EHls1Q67+s X-Received: by 2002:a17:906:3955:b0:a34:ab60:d177 with SMTP id g21-20020a170906395500b00a34ab60d177mr1308903eje.39.1706376526671; Sat, 27 Jan 2024 09:28:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706376526; cv=pass; d=google.com; s=arc-20160816; b=BuEw999zQsRGktN4dBSU7P7+bM//lKaL0IeuyhwIRGkHfeOzsL8yteaTdYlJNlBlO6 E1V+AhgbKTWuXH0vTAkTo4biaBWDp0sAElQRN6k7wyGPWJkCRLSwM7axwsGFu60lI4qh nbwz1bjpSzmkVpebUlclSz8QNerzYarzH7UkpM0nsNPRcfSLdXz733PfzZvG85yp99n0 PELefSjn/TnAZwmEqJPOhuTNG9WG+8g/Msjd+NJknIcPzWnkau9Zuzwher3DVwx/St+E EY2QRvwcOLH3YhhgL7b2J4sCKP3B7sKN5E0E/2hZiHqyzEhwsqWsnTlBmFzqZhNDQX5U M0gA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=GsNSM8BwIJOBsIwkaMTr437siLDjYjyAhXgi6ulkJJc=; fh=igtWDmm60P5rm81CKcMwLcCma6JXLc26aqGGkyUd5f4=; b=k7Aikhm1nZX6xiyNOaO7jJ+d2dZOG57fSDnuWgG1IyyAxrynG69ei/3lr9W9esmfxi 4sFIO6peYu78pKaT4XRseMdXenaWoMZQSw0tTY9V7Y6vb6KS2QjX23LmvM97Ul4HGsRd lnhXWEk2ksFQB1WaFRklz1uTrdTgfXU11SFM1axyLSSYhBWh8jmbegyjBjAhtWJPizN5 0k+JQJKgnQnS+2Asi2NXM1ygBhyho/04CUiJyCkFJzFi+JYeJ0NFz2pQ34IPactjF/Ko ruwivpAHZDlxlNot/Ejcc0EOolwwForZ3V9tbnFIHrAodBfirNsE2wTiyDiSuK/RmCEv a18g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sdfg.com.ar); spf=pass (google.com: domain of linux-kernel+bounces-41343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41343-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r15-20020a170906350f00b00a349a5f4c6dsi1733157eja.96.2024.01.27.09.28.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 09:28:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sdfg.com.ar); spf=pass (google.com: domain of linux-kernel+bounces-41343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41343-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6D2541F222C0 for ; Sat, 27 Jan 2024 17:28:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 360AD2D046; Sat, 27 Jan 2024 17:28:38 +0000 (UTC) Received: from alerce.blitiri.com.ar (alerce.blitiri.com.ar [49.12.208.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93BDF2CCBA for ; Sat, 27 Jan 2024 17:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=49.12.208.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706376517; cv=none; b=X4ExMNuAGYKkbPF5KwYMtjN940/Z3ISTlR4+Gv5+cv8OWw0pejmCOMSbFs+KdooVyBkBizoHHndgW39/pRLW8pY8gTqbMsvrxlvbuMeAeueUNtF7kcuPdznKM4Q396gs/WsHBbicQJnTIgQ9NkO6zBMZUIZFOuLde5YnM1eFIeQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706376517; c=relaxed/simple; bh=FitbO8MCaHW5HJwzn2tUgZRT1fw26fTzyBZBRZ5CpK0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MxRWI1SupTpYcFOz3TdLjSFAUsx/2ta7fWd6D2n8lfDpreLYUSufaiNY/oB9zgNy+F0bZOBGj1Koo5VYbm1jaOsk5StlMxeWWqsDugKbY70U/0Qg2ivxjLav0yEBSzXe9gDUOkGhUz2zW+11rcbdR/EZBHcr+qI7wg3QKAUIQF0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sdfg.com.ar; spf=pass smtp.mailfrom=sdfg.com.ar; arc=none smtp.client-ip=49.12.208.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sdfg.com.ar Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sdfg.com.ar Received: from [IPV6:2a02:8109:aa26:4b00:1a1e:9a1e:44f7:a3cd] by sdfg.com.ar (chasquid) with ESMTPSA tls TLS_AES_128_GCM_SHA256 (over submission+TLS, TLS-1.3, envelope from "rodrigo@sdfg.com.ar") ; Sat, 27 Jan 2024 17:28:26 +0000 Message-ID: <9538a8fe-b92f-42a5-99d1-25969cf51647@sdfg.com.ar> Date: Sat, 27 Jan 2024 18:28:25 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/1] tools/nolibc/string: export strlen() Content-Language: en-US To: Willy Tarreau , =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org References: <20240126142411.22972-1-rodrigo@sdfg.com.ar> <9abed5e3-cd61-474e-bb16-13243709f5c5@t-8ch.de> <20240127162400.GA14079@1wt.eu> From: Rodrigo Campos In-Reply-To: <20240127162400.GA14079@1wt.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/27/24 17:24, Willy Tarreau wrote: > On Sat, Jan 27, 2024 at 03:53:32PM +0100, Thomas Weißschuh wrote: >> On 2024-01-26 15:24:10+0100, Rodrigo Campos wrote: >>> Please note that this code is not using strlen() and strlcat() doesn't seems to use it either. >> >> I think the comment in strlen() explains it: >> >> Note that gcc12 recognizes an strlen() pattern and replaces it with a >> jump to strlen(). >> >> strlcat() indeed contains this pattern. >> >> I was able to fix the issue by replacing the open-coded strlen() in >> strlcat() with a call to the function and that also fixed the issue. >> >> It seems nicer to me as a fix, on the other hand the change to a weak >> definition will also catch other instances of the issue. >> Maybe we do both. > > Yes, once we have the proof that the compiler may produce such a call, it > can also happen in whatever user code so we need to export the function, > there's no other solution. Makes sense, thanks! > >>> First I noted that removing the attribute unused in strlen(), the compilation worked fine. And then >>> I noticied that other functions had the attribute weak, a custom section and export the function. >>> >>> In particular, what happens here seems to be the same as in commit "tools/nolibc/string: export memset() and >>> memmove()" (8d304a374023), as removing the -Os or adding the -ffreestanding seem to fix the issue. >>> So, I did the same as that commit, for strlen(). >>> >>> However, I'm not 100% confident on how to check that this is done by the compiler to later replace >>> it and provide a builtin. I'm not sure how that was verified for commit 8d304a374023, but if you let >>> me know, I can verify it too. >>> >>> What do you think? >> >> Personally I don't know how it was verified, we'll have to wait for >> Willy on that. > > Oh it's very simple, just build a small code that doesn't contain any > such explicit nor implicit call and check that it doesn't contain the > function. > > E.g > > $ printf "int main(void) { }\n" | gcc -nostdlib -static -Isysroot/x86/include -include nolibc.h -Os -Wl,--gc-sections -xc - > $ nm --size a.out Oh, cool. I can confirm that gcc does indeed add the strlen call (note I had to remove the "--size" param to nm, as the symbol is undefined and not shown otherwise) I wonder if there is an easy way to check for which functions gcc/clang do this... >>> As a side note, it seems strlcat()/strlcpy() fail to set the terminating null byte on some cases, > > Indeed I've just checked and you're right, that defeats their purpose! Cool. >>> Let me know if you think it is worth adding some _simple_ patches (I don't think it is worth fixing >>> all the cases, the code is to fix all of the cases is probably not nice and not worth it). >> >> Souns reasonable to me to fix the return values. >> And get some tests for it. > > Seconded! Thanks, I'll see how to improve that too :) Best, Rodrigo