Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2712093rdb; Mon, 12 Feb 2024 14:06:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWyAQxOzBkaGGuambDs1pizbDfT1fOINisrJFHdSIs0QWlDFB+NPpD43Wz28+ZGZU34ESMveRoOZqoLeTdYgRDLCiGTCPxaZdmz9uogJw== X-Google-Smtp-Source: AGHT+IGuttIZ5s4+fU3Wt2WsbjRK/O6YrCuZPMsmOXpr59dx/KQTH9doCgGdZ6RSxin2vQLJiwQH X-Received: by 2002:a92:cb0f:0:b0:363:f8c5:9d7b with SMTP id s15-20020a92cb0f000000b00363f8c59d7bmr9028512ilo.9.1707775613401; Mon, 12 Feb 2024 14:06:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707775613; cv=pass; d=google.com; s=arc-20160816; b=Ij1B6RzE83CfEkvt7CgFJv7KanypGCMtjKcXOvK9odCKWw8wT0imt6tgiPDCwfFDq8 o2BIm0l6yv502OjaXLRtuNbDa+juK4PYn5TaAwWsnzvVKbshEeih3yVbmLrGZ06LfZ+b uLVodN3gFF7m+9wpxoCrh8d7JlzcLlV5B2XhEgOzIMZUoOahyek4/2BA6PlUK70UpcSr oZsk+cdVbg/SZzcxjfNPjOnAM3W/IEiP3vsFf2QbVmAxhNH3xKRgKm+31apwxbwvAQCb Xg/P7v8rn/goc1JsqKhOgWDZxBaoDLJAAySoSKrrIRa9uIklkHCzSyntQufc9SWzWudt VSRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=FAP8ciFMVXJQebx3ikecm7gfdkfYQjqo8DHa2ep2azc=; fh=Pk8CLgHvN5gcdqnnV2wjSzC5Qyz8xPYfQA9u2cykYl0=; b=TwLDJ+Ja8zF885oEL7dJhXtlSwnguOvt0vIao6GSIxcClhzaJYkEzz6XE/MZJwghlU 8RRK20KNUy1im0WydtCV4Q0ZKLZkAqrMaG3b913kiVjwhF0UN0S+sQzBqzH6caKNCXvc /SO/yiB+B/ON9dk3rTwBcINaRxE5u4GYoSFUqTjZhlIpQtENZr2no9qcxc0Osj8zTw4V b0KsjHcfSjga4hlJFAYQM7NQ/haiZVqpg0zDT960LfDo5TeAvOHCoxImkh7cIbT9uo1/ 8O9KrBUvhJAAgdla/5ztnf7SHvy8b8AiO6m3pIJkaSX3uzo9Wa7VgAiXD/BaTLhSYEaC iDyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wD7rETtq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-62447-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62447-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCUfjoMygvOZ0KgYgftosnIS9XPuabl0k0t7eTWkobtRQyTk8wOLBTSV/UfvjfcRCARkO53XDTOBIJ8w3idRqiZK2wow0XAPHDYDe8O6sw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m185-20020a6326c2000000b005dc1330fadcsi836322pgm.6.2024.02.12.14.06.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 14:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62447-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wD7rETtq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-62447-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62447-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7A25AB22C1D for ; Mon, 12 Feb 2024 21:59:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 544224D599; Mon, 12 Feb 2024 21:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wD7rETtq" Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 A3E084CDE5 for ; Mon, 12 Feb 2024 21:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707775171; cv=none; b=N7fWWjq2lrmx1otwYllwXbEliUubZjncrpk60pGxdetztoARZXd0ipwCyciRwSGH2CcgOCiikIQeJ4tHKo9LmoByaAdpY+67I7PsZuH+PzGe597uNkmhF+/lG2rcIhCW5WgDle24EpyJpopAfqPIAApHnQzbLIvnonZRSri/bBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707775171; c=relaxed/simple; bh=b+F7pcUkc0r1mBK4PMiDYHZh9PrP/YYZbjdLAkDYuqQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=NWlS2gP4h0MMZVhupMbmqtojkjrA8GMpzUAcTmOXBRMkEwaLFQ2WKoU+Bwttvf0cWAFDe+Xup22XqGu3wqKBOaYF2I3yVV+g0gwN1qrSuSjbfksBgQMt6HlEM0kFISVtZerurkyMpOnUGzNlgFUiSOCRtCTkblIaB3vQ83arpAU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wD7rETtq; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-561f0f116ecso771a12.0 for ; Mon, 12 Feb 2024 13:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707775168; x=1708379968; darn=vger.kernel.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=FAP8ciFMVXJQebx3ikecm7gfdkfYQjqo8DHa2ep2azc=; b=wD7rETtqM4/AXpgyBmUXVB/RxvDASj96OA3fpDl+l5zIbLSdb2C0yABKfNBMEjYSqs rfQiDnPfueMDBAMjO1KbdmkGrdOZ09tar1O03kWVwt4ZiU97GErY0Omh/MGe2Q4LnfM4 jJNJjI0tlhXOthnkMk0Ahe/wofJhKaSVCGCbLhKQ9VVpdZ8etBcjVJ1EMkrkaiTZHTvf L78ZFoMBAFWoLO/wCpCUXtTUn4cfRpHsSFXYmAXnyDkMvteofbst609rR49o0IX2uC9i 4oveUekPtgh8KGmqyLwmG1DkP0eHTOZER0wkpekaD8m1Fha5z7i14z44ZpdbBknobU4C s1hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707775168; x=1708379968; 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=FAP8ciFMVXJQebx3ikecm7gfdkfYQjqo8DHa2ep2azc=; b=Wk35cXcOKXNrsx24MbXxdcse839nn8DDSBux2wYTuwSvZWynpzeHND4+YXQ7xwGpKk RBwKzijq5DkYj+PGcy++iGIxtXMhywYQ93P3WsP9K47KkTTbsk6QwUBsA97HFPzWwsOW FfLHhO6gWwLwN1RcmwR63yK3aIYU2Vxq5bfLBVJnoPDHlU+g90rA7vWm4TdodQ4I4QRS DFZT5CLysCEQQzs1GApdDSzNJzcF1UG2kYmGRqFcBWwcTSX0KMOcHCQVmCM1c7H6WotL iMbH7DgbFHIvURyQ2ePTtQIsFbKq0QEHkyc7Aw1Y/I1yrbZEegAq18N6fUM8HrntSrXu 9CzQ== X-Forwarded-Encrypted: i=1; AJvYcCVog21qXyfwVTiO2xKGTWERp7FNwCfPXYL+ytvFRAp0+Fkcso5HlVQXflTeZrqyOj6IUTsNW748ogDIgsLRLfNdE+S/kpeetH+1urfS X-Gm-Message-State: AOJu0YwxarIBhcAAShMx1wM5WxlwV4CVrEwghgt0UQBGOCLxbK0b1p5b 6pfoQgOBb2sw3aeeX7b/ombvRxV1Myoc36fpKCG+XckUWEkYyQsjaejgTzfmeX4EF/PKDgGF0no rUMm7UMIfGbQZ7RPwrFK0FPeprw6/H2DkohxZ X-Received: by 2002:a50:f615:0:b0:561:d84d:f6ce with SMTP id c21-20020a50f615000000b00561d84df6cemr22522edn.6.1707775167821; Mon, 12 Feb 2024 13:59:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240208012057.2754421-2-yshuiv7@gmail.com> In-Reply-To: From: Fangrui Song Date: Mon, 12 Feb 2024 13:59:13 -0800 Message-ID: Subject: Re: [PATCH] kbuild: Fix building with LLVM on NixOS To: Yuxuan Shui Cc: Masahiro Yamada , llvm@lists.linux.dev, nathan@kernel.org, nicolas@fjasle.eu, linux-kbuild@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 12, 2024 at 1:30=E2=80=AFPM Masahiro Yamada wrote: > > +Cc: Fangrui Song > > > > On Thu, Feb 8, 2024 at 10:22=E2=80=AFAM Yuxuan Shui w= rote: > > > > NixOS is designed to have immutable packages, and explicit dependencies= . > > It allows multiple different versions of the same shared library to > > co-exist in its file system. > > > > Each application built with Nix, the NixOS package manager, will have > > paths to its dependency shared libraries hardcoded into its executable, > > this includes the dynamic linker. To achieve this, Nix adds a > > --dynamic-linker linker flag when building any application. > > > > This isn't a problem if the kernel is built with ld.bfd, because ld.bfd > > ignores the --dynamic-linker flag when the resulting binary doesn't hav= e > > a DT_NEEDED entry. However, ld.lld respects --dynamic-linker > > unconditionally, which breaks linking in several cases. > > > > This commit adds an explicit --no-dynamic-linker flag which overrides > > the flag added by Nix. > > > > I expect some Acks from LLVM folks (especially, from Frangrui) > if this is the right thing to do. GNU ld seems to ignore --dynamic-linker for a position-dependent executable (ET_EXEC) when there is no DT_NEEDED entry. ld.lld respects --dynamic-linker in this case. Before this kernel report, I do not know any user inconvenienced by this difference. (mold respects --dynamic-linker as well.) This could be helpful to test an executable with PT_INTERP but no DT_NEEDED= . I think this patch does not fix non-x86 builds. It feels to me that NixOS should provide a linker wrapper that does not force --dynamic-linker=3D. While it's extremely uncommon (and generally not recommended), certain programs invoke the linker directly (instead of using a compiler driver). Such programs would run into a problem when they make a position-dependent executable with no dependency as well. I don't feel that NixOS forcing --dynamic-linker=3D is enough justification to change linkers. > > Signed-off-by: Yuxuan Shui > > --- > > Makefile | 3 +++ > > arch/x86/boot/Makefile | 2 +- > > arch/x86/realmode/rm/Makefile | 2 +- > > 3 files changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/Makefile b/Makefile > > index a171eafce2a3b..10ed19caecb1b 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -531,6 +531,9 @@ RUSTFLAGS_KERNEL =3D > > AFLAGS_KERNEL =3D > > LDFLAGS_vmlinux =3D > > > > +LDFLAGS_MODULE +=3D --no-dynamic-linker > > +LDFLAGS_vmlinux +=3D --no-dynamic-linker > > + > > # Use USERINCLUDE when you must reference the UAPI directories only. > > USERINCLUDE :=3D \ > > -I$(srctree)/arch/$(SRCARCH)/include/uapi \ > > diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile > > index 3cece19b74732..390a4604166eb 100644 > > --- a/arch/x86/boot/Makefile > > +++ b/arch/x86/boot/Makefile > > @@ -102,7 +102,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE > > AFLAGS_header.o +=3D -I$(objtree)/$(obj) > > $(obj)/header.o: $(obj)/zoffset.h > > > > -LDFLAGS_setup.elf :=3D -m elf_i386 -z noexecstack -T > > +LDFLAGS_setup.elf :=3D --no-dynamic-linker -m elf_i386 -z noexecs= tack -T > > $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE > > $(call if_changed,ld) > > > > diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makef= ile > > index f614009d3e4e2..4b42006d9ce02 100644 > > --- a/arch/x86/realmode/rm/Makefile > > +++ b/arch/x86/realmode/rm/Makefile > > @@ -50,7 +50,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE > > targets +=3D realmode.lds > > $(obj)/realmode.lds: $(obj)/pasyms.h > > > > -LDFLAGS_realmode.elf :=3D -m elf_i386 --emit-relocs -T > > +LDFLAGS_realmode.elf :=3D --no-dynamic-linker -m elf_i386 --emit-reloc= s -T > > CPPFLAGS_realmode.lds +=3D -P -C -I$(objtree)/$(obj) > > > > targets +=3D realmode.elf > > -- > > 2.43.0 > > > > > -- > Best Regards > Masahiro Yamada > --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF