From nobody Wed Feb 19 09:57:57 2025 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YyWzs4fQ6z5p7BX for ; Wed, 19 Feb 2025 09:58:17 +0000 (UTC) (envelope-from vini.ipsmaker@gmail.com) Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YyWzr4M1cz3VsG for ; Wed, 19 Feb 2025 09:58:16 +0000 (UTC) (envelope-from vini.ipsmaker@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=J2lVvdVk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of vini.ipsmaker@gmail.com designates 2a00:1450:4864:20::134 as permitted sender) smtp.mailfrom=vini.ipsmaker@gmail.com Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-5452c2805bcso5277307e87.2 for ; Wed, 19 Feb 2025 01:58:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739959094; x=1740563894; darn=freebsd.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PtMMbpIsjrrS9+GIRu3h3KE1K/Vk4hYkwPM2CLBdlBo=; b=J2lVvdVkcgosNBNSeoRIo7dzOJ5qzBnaH+Di5mGtf8FyhnCjx29fevRAAHwrCgufLQ +Yv0OhS1Q9JneU2ZQXLIHfHIm1eqcIs7QWs38wuWpa6lhLuWFZxpfMpHv9mJMYteknPt q0CFIYa323CqzdrK/IzOyZkZxpbVK4t5S4CW+Dj62PTUz9YXGZyqMJf8wnnUqs9K6Tkw tdZHF0b3qUZO0venaVhS1cTOr0WzG+yrtlDFGCDw3hjok5gDfbZm6NEVFbCP71r1WbCU 0o2esLxfwXZalSSdFNbDo+E2sAT7WxVleUOlHNIB0Qm30RPsX6I9kd3DF26QkWU3R6zZ WsAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739959094; x=1740563894; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PtMMbpIsjrrS9+GIRu3h3KE1K/Vk4hYkwPM2CLBdlBo=; b=uhJVaD5aLLiy9on2PeB/jJlq8Vas/hCadOaRtk/LWUij/HaL/eKmF0lOK+0mLS2cVn IOdllUPYg0CRH3MoTO0XkQR56p0L7BHjJRw9Yw3R5t5tIumLz0ElB2FY3+c0MTlQL0BN pgW7jWW/pOGzsKxI0B4ihNEt3hZG4R8iN6KCa7CE4ELNbgHnZn0SRbimctigHVNBoN+P vi2K283QCUEZXRG1jMPavEMJkfqrcPiIUtJkP8L92WlzQRKaR6FBswsgMcIng3IXA5T9 bLtkJUO/pJyycc0Wvp3wtN1rNGF8B8L4cpSKd+gk+bWQZwSxic37dutJ8rHu8XmudsOW TqNw== X-Gm-Message-State: AOJu0Yz5K4sWvBK/BE+1ObvClryhfhHg211DvWznSO3XlxvkJgJwwJNa MNaqgXumTYxHjnuUg6+dTANVWXX0WXmpSed8enx+v3IR+jDUqwPt6BnZAtcSg3DJ+yhkqM1msP0 FDUgforkGrswSURy+IBBGMd3I874= X-Gm-Gg: ASbGncuhuyl9bNJen+t46PsiEYnYk8muwaqB4z3yEgg35RuLOkd2bslTMb6NQD9sQrQ F+jiY3aNy9GuoddUW5jswCn41MlOHeK0IyHgIKH6GyClmOTBS4l8fLt2cohq4+njwQTQ2V9M/ X-Google-Smtp-Source: AGHT+IENlRSVO+4RdZTDJndgfVcM57PoADqhTLiuX9AWH7IRp1TVJPL5glZdrlcanc1Bh+4IaRvdyU3cqtNVlQaGIfU= X-Received: by 2002:a05:6512:2823:b0:545:4cb:b25d with SMTP id 2adb3069b0e04-5452fe37326mr5719523e87.13.1739959094130; Wed, 19 Feb 2025 01:58:14 -0800 (PST) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?Q?Vin=C3=ADcius_dos_Santos_Oliveira?= Date: Wed, 19 Feb 2025 06:57:57 -0300 X-Gm-Features: AWEUYZmdnyvdjPVsSLKm7dX6xa_BBrB-ZSAiwy1sCpfTBmNpFn9b3Z3a6JV_LBs Message-ID: Subject: Re: Capsicum and weak libc symbols To: Konstantin Belousov Cc: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.33 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_SPAM_SHORT(0.67)[0.666]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_TO(0.00)[gmail.com]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ARC_NA(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; TAGGED_FROM(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCVD_COUNT_ONE(0.00)[1]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; MID_RHS_MATCH_FROMTLD(0.00)[]; MISSING_XM_UA(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::134:from] X-Rspamd-Queue-Id: 4YyWzr4M1cz3VsG X-Spamd-Bar: -- Em sex., 7 de fev. de 2025 =C3=A0s 00:08, Konstantin Belousov escreveu: > On Thu, Feb 06, 2025 at 10:40:52PM -0300, Vin=C3=ADcius dos Santos Olivei= ra wrote: > > [...] > > The purpose of the weak attribute is to allow the weak symbol to be undef= ined. > It is not about the order of resolution (by default our rtld indeed prefe= rs > non-weak over weak, but it is a bug, and there is knob to turn this behav= ior > off). > > If you need to interpose symbol, just link the interposing object before = the > object that supplies the symbol to be preempted by your definition. There are two use cases for interposing symbols: * with rtld * without rtld (fully static binaries) I don't want to change what rtld sees. I don't want to change /lib/libc.so.7. It works fines as is right now. I want to change what /usr/bin/ld.lld sees. I only want the symbols to be weak in /usr/lib/libc.a. For instance, the following code fails to compile when you try to build a static binary (it works fine on the default mode though): #include #include #include #include DIR *opendir(const char *name) { if (name[0] =3D=3D '\0') { errno =3D ENOENT; return NULL; } int fd =3D open(name, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC); if (fd =3D=3D -1) { return NULL; } DIR *ret =3D fdopendir(fd); if (!ret) { int saved_errno =3D errno; close(fd); errno =3D saved_errno; } return ret; } int main(int argc, char *argv[]) { (void)argc; (void)argv; } The build output for for clang -static will be: ld: error: duplicate symbol: opendir >>> defined at t2.c >>> /tmp/t2-3cf81c.o:(opendir) >>> defined at opendir.c:55 (/usr/src/lib/libc/gen/opendir.c:55) >>> opendir.o:(.text+0x0) in archive /usr/lib/libc.a clang: error: linker command failed with exit code 1 (use -v to see invocat= ion) Meanwhile symbols such as unlink are weak (in /usr/lib/libc.a) and I can interpose them easily in static builds as well. However with further investigation I've realised that weak symbols in /usr/lib/libc.a are also weak in /lib/libc.so.7. Does FreeBSD use the same weak attributes whether it's building libc.so.7 or libc.a? --=20 Vin=C3=ADcius dos Santos Oliveira https://vinipsmaker.github.io/