Message ID | 20240208012057.2754421-2-yshuiv7@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-57361-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2616124dyb; Wed, 7 Feb 2024 17:23:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUrlMVzbQnMyhwS4UBNMFISH+iPfqSEKheF3dqJk9EqUyMoL6zH7P3JvwGVdP+nsJXQJeitVFGGESAIU64hDfv1BFrqaw== X-Google-Smtp-Source: AGHT+IERe19B21RzneEXBqr1nvI59A2NwngJW2aYcV86CjvPsfp7n2ODyYAcPvp7zHfexijsifT6 X-Received: by 2002:a05:6358:98a4:b0:176:9e92:8e4 with SMTP id q36-20020a05635898a400b001769e9208e4mr5438372rwa.10.1707355385438; Wed, 07 Feb 2024 17:23:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707355385; cv=pass; d=google.com; s=arc-20160816; b=LJGEIgCHq0zWQfQ74HL1YxocTZbZCPSwDIc0sx18KwPC2Y27IsBonuonEQWnre0Xw3 C9esZeG8FMBjaB/MmibREpAW02rKlglDTXLDuaeNLusdK+MvMPggMvdFhpNFAkyvvmqH hw+QaYnGm+n8/dSD7a4At4VppUfszRurfpxZI+VWS5VKO6z3lAd88JAqbu1URHf458uh 1aMPVyvaFaiEMfh6pApYLmOCsN2qrR/FMWXe3KcVwfhptszfpSCm05B4IPmYAtgCwOvc p7P40ym6gTTgK8hxUVwzwwlM0DNSPYhRf74V3F1uvUBYlVKDm1iSQVp0TkyrSUBGcwWE Ib4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=kY0vgVMAWXvg6WdX7kWSrpFxwM9nLTP4P22qdJFLKnI=; fh=wGQDvAWXmvi4bnAxcjhlA0mKg3hl+HjwG9bNPHu6Khg=; b=sW0+ODYCk8sznEepfTCCCb9UMAW3pBo+GuZJt+fglZ7kB+g0z80WvE+CkTNyJQmK19 0OfliPyrYeMr3wb+L/IHwFbjxa+m44htBHmcq/g3retEiObTh6wGbiKgbqs/o/QoMriF QEWWIOYl0nVlZTMhqCMxPMc2m5X6ErtEZyren+X3kCl6UpWWBA/Rob9I6UYOhZAURqCm MkY24Sg4QOJBsGTGRbn6QlTe8B5v29FPzfrR3w+UaK92vURhkGvn/9NVYS9YdLyx9mQh ekeMdRiStjsj0K7K/eQKIbXHAW/aKPe1WezkTj1GYEX2LvD2TGDgr3Y11o/K+LZ+bScL ERwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bQfiLZm+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-57361-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57361-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCVFI4ozTeQzj54U0kV+bKtoFXHiwa0nTHel9JEN/51GuzDzuS19itdglLDGNZ5TkpQYK7Z/e4P+u+gTWpvfgluWKYinyw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s12-20020a63770c000000b005dc0d38b231si2815840pgc.17.2024.02.07.17.23.05 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 17:23:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57361-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bQfiLZm+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-57361-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57361-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 325822836C4 for <ouuuleilei@gmail.com>; Thu, 8 Feb 2024 01:23:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5A571CD21; Thu, 8 Feb 2024 01:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bQfiLZm+" Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 24D8A1E885; Thu, 8 Feb 2024 01:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707355367; cv=none; b=Ql5okxs05ajiHhMbGH54CMN7FimPw3Bnkc1MmSxDs6IKi0A6GKse1xpS8zZEt/A6YKaAb4/kdjIUtrZllR37vTbV7hOwfD3e41hudW0r9TD0Kot+83RJie9keC57pdbqnfgkf4nPr9AsKcTk96lwE7Yqvy0Z2RBBL30yY2ccnOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707355367; c=relaxed/simple; bh=Mm/LoXa3RB6B+MBL36Ib2qcdqqwIv2prBEiaoLJuQyE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=p4ZEgQwcln9V/XbV764RRyn6UzVxH1K9ncOu8N3Ers0QGN8Zfc0Ui+snvWMCjQE6sC/btrnW+Ui40Sd3usCOPQVk+QKn1uSDRicubb+DmhZh5vn4OWw2xFbZ3rkJtsUEOtPRfwK/cfO4dSZ/HRu/dK6l8n/t4T8gPhZkmkhgbq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bQfiLZm+; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40fff96d5daso11033105e9.0; Wed, 07 Feb 2024 17:22:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707355364; x=1707960164; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kY0vgVMAWXvg6WdX7kWSrpFxwM9nLTP4P22qdJFLKnI=; b=bQfiLZm+TdFQLcpy42UK2WTzX89N5f51/pRxA7ks9cwgLooPAf+l54dBFIP3KaNqzI m0jB15nN+oLpEjDV+1okw9RrUNNQSNd6xfDSBrqZcuwqePsjoT+6DldUx1v0+VF9YacP MAtvixIYMjW5pSoJ9+W8HZ5ejrN8db4Opb/L3f2K15z6LWu9pUvrJqjMOp0UPeop5jlF 6rSN6/FhiuB/MWD6iHz/CWb6G/yp9rmtqaVFsg1jopdJBpVyrQO4+haD76nO6t5/AcsM zeGk+8cxYebh3m6dPtiYFew7ArizslIU6mTQf0yoKsZuGr1oHzmBmVrVVyl9gJGBgTMu 8LDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707355364; x=1707960164; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kY0vgVMAWXvg6WdX7kWSrpFxwM9nLTP4P22qdJFLKnI=; b=axScRmMLwOEqCMRwj11a3KruajbjdGeyd4sYJNq1yOeQZUMj37+lP2Z0B1nQP7BCAu lLd5qc2GhgiY7MtZag0nwg4CgdjPPmPOsSqDFYXlXMqb4IT+zRTubgEJ/Br41YQ0rnid 8/jkWdbhY+IBdnaV6PgFdN7t89jvouWj8oFeybddtmjdrNGx9q5yAzmj14oV+/4qxVbJ uM3+eeCiUTxekzJiUpg+z6sHs8olKcLE+cGvdTMeERTAq0xsXVASwwSUxlSTPwmEXTZ7 pS92pvrLqzxA5aJKcNxvecUWiqhIStFYa9Si9I28EZH1CsYsiO5Y3ke4t+okSVUA89Ii 9CsQ== X-Forwarded-Encrypted: i=1; AJvYcCWPA64jQcowbr1okFhUwEHC6GBUKFfWX6J0CU1GImGVrxLQPd7iZP/q1VxKqQIyTzRWEigVzaCm4rn3NN32GKLOLvdPMurKrO/o0LpmgGNHzEBsL9Oz2Vsgxki8OlWUzGohYbbWHJE5HxRl X-Gm-Message-State: AOJu0Yypz1/eeHUe/n4Wauhk7Tl17KHtwwpL4NYEhx/0/Mcwa6NGDgVS A+TOoboPCm79XTNNFHnzfToKRTsYQOlQkrugKFbDqU1ngCQ5ei2x X-Received: by 2002:a05:600c:3543:b0:40f:c1fc:e5b6 with SMTP id i3-20020a05600c354300b0040fc1fce5b6mr5694924wmq.38.1707355364099; Wed, 07 Feb 2024 17:22:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU1eHQPE5BUroa8741BQMtqOa6Q3Ltc5RSdH3ErtrGeYLe8Xm6pGHsUedrwe1B8tYW8NHtdJ5Tio6FyolPLSS6AH46OVd1PmvzbQrhn8/qcjAoGyY4NSXVZAMV33WFicA0tbE/4fqACx4qSvJLZMDWZu6aYBguC+HjQdfgZZ5Fho50GpVVDLSt2/p5eSal/z7XlF5BVuksvA+1DDGsT6He2M2DnZXAmdThDH7nGz67NPFOUEcN750jA8KKbl7/p3/dAxbHThD9eJqyJwU8eK418Kv/1+uXQil4qoZSmPn1zL39LxlLOaUgM4p+nL2mCyOAtc2pG0Vc200Mc9b7sJrEw9J9YnfOcG04Su6q6zcrYFDu3CQ== Received: from node-04.shui.grid ([31.94.24.68]) by smtp.gmail.com with ESMTPSA id j12-20020a05600c190c00b0040ebf603a89sm161866wmq.11.2024.02.07.17.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 17:22:43 -0800 (PST) From: Yuxuan Shui <yshuiv7@gmail.com> To: llvm@lists.linux.dev Cc: masahiroy@kernel.org, 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, Yuxuan Shui <yshuiv7@gmail.com> Subject: [PATCH] kbuild: Fix building with LLVM on NixOS Date: Thu, 8 Feb 2024 01:20:58 +0000 Message-ID: <20240208012057.2754421-2-yshuiv7@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790291880952062153 X-GMAIL-MSGID: 1790291880952062153 |
Series |
kbuild: Fix building with LLVM on NixOS
|
|
Commit Message
Yuxuan Shui
Feb. 8, 2024, 1:20 a.m. UTC
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 have
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.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
---
Makefile | 3 +++
arch/x86/boot/Makefile | 2 +-
arch/x86/realmode/rm/Makefile | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
Comments
+Cc: Fangrui Song <maskray@google.com> On Thu, Feb 8, 2024 at 10:22 AM Yuxuan Shui <yshuiv7@gmail.com> wrote: > > 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 have > 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. > Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com> > --- > 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 = > AFLAGS_KERNEL = > LDFLAGS_vmlinux = > > +LDFLAGS_MODULE += --no-dynamic-linker > +LDFLAGS_vmlinux += --no-dynamic-linker > + > # Use USERINCLUDE when you must reference the UAPI directories only. > USERINCLUDE := \ > -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 += -I$(objtree)/$(obj) > $(obj)/header.o: $(obj)/zoffset.h > > -LDFLAGS_setup.elf := -m elf_i386 -z noexecstack -T > +LDFLAGS_setup.elf := --no-dynamic-linker -m elf_i386 -z noexecstack -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/Makefile > 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 += realmode.lds > $(obj)/realmode.lds: $(obj)/pasyms.h > > -LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T > +LDFLAGS_realmode.elf := --no-dynamic-linker -m elf_i386 --emit-relocs -T > CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj) > > targets += realmode.elf > -- > 2.43.0 >
On Mon, Feb 12, 2024 at 1:30 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > +Cc: Fangrui Song <maskray@google.com> > > > > On Thu, Feb 8, 2024 at 10:22 AM Yuxuan Shui <yshuiv7@gmail.com> wrote: > > > > 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 have > > 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=. 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= is enough justification to change linkers. > > Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com> > > --- > > 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 = > > AFLAGS_KERNEL = > > LDFLAGS_vmlinux = > > > > +LDFLAGS_MODULE += --no-dynamic-linker > > +LDFLAGS_vmlinux += --no-dynamic-linker > > + > > # Use USERINCLUDE when you must reference the UAPI directories only. > > USERINCLUDE := \ > > -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 += -I$(objtree)/$(obj) > > $(obj)/header.o: $(obj)/zoffset.h > > > > -LDFLAGS_setup.elf := -m elf_i386 -z noexecstack -T > > +LDFLAGS_setup.elf := --no-dynamic-linker -m elf_i386 -z noexecstack -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/Makefile > > 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 += realmode.lds > > $(obj)/realmode.lds: $(obj)/pasyms.h > > > > -LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T > > +LDFLAGS_realmode.elf := --no-dynamic-linker -m elf_i386 --emit-relocs -T > > CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj) > > > > targets += realmode.elf > > -- > > 2.43.0 > > > > > -- > Best Regards > Masahiro Yamada >
Hi, On Mon, Feb 12, 2024 at 9:59 PM Fangrui Song <maskray@google.com> wrote: > > On Mon, Feb 12, 2024 at 1:30 PM Masahiro Yamada <masahiroy@kernelorg> wrote: > > > > +Cc: Fangrui Song <maskray@google.com> > > > > > > > > On Thu, Feb 8, 2024 at 10:22 AM Yuxuan Shui <yshuiv7@gmail.com> wrote: > > > > > > 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 have > > > 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. This is true. I am not familiar with non-x86, and I don't have a test environment for them. That being said, if you or someone can point to me what other linker flag variables I need to change, I will try to fix them as well. > It feels to me that NixOS should provide a linker wrapper that does > not force --dynamic-linker=. I actually tried that. The problem is, NixOS tries to enforce the same build environment for downstream packages that depend on the kernel (think kernel modules, perf, etc.) This is reasonable in most cases. But if I use a linker wrapper that does _not_ have --dynamic-linker for the kernel, then all downstream packages will inherit the same linker wrapper too. This breaks, for example, zfs. Because its configure script tries to build some executable and run them, which fails because it's using a linker wrapper without --dynamic-linker. > 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 think I quite get what you are trying to say here. > I don't feel that NixOS forcing --dynamic-linker= is enough > justification to change linkers. You already rejected the option of changing lld to match ld.bfd's behavior. If you reject this kernel patch also, then what's left can only be some horrible hacks on NixOS' side; or this means NixOS will never get a clang built kernel. Which would be quite unfortunate. > > > > Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com> > > > --- > > > 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 = > > > AFLAGS_KERNEL = > > > LDFLAGS_vmlinux = > > > > > > +LDFLAGS_MODULE += --no-dynamic-linker > > > +LDFLAGS_vmlinux += --no-dynamic-linker > > > + > > > # Use USERINCLUDE when you must reference the UAPI directories only. > > > USERINCLUDE := \ > > > -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 += -I$(objtree)/$(obj) > > > $(obj)/header.o: $(obj)/zoffset.h > > > > > > -LDFLAGS_setup.elf := -m elf_i386 -z noexecstack -T > > > +LDFLAGS_setup.elf := --no-dynamic-linker -m elf_i386 -z noexecstack -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/Makefile > > > 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 += realmode.lds > > > $(obj)/realmode.lds: $(obj)/pasyms.h > > > > > > -LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T > > > +LDFLAGS_realmode.elf := --no-dynamic-linker -m elf_i386 --emit-relocs -T > > > CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj) > > > > > > targets += realmode.elf > > > -- > > > 2.43.0 > > > > > > > > > -- > > Best Regards > > Masahiro Yamada > > > > > -- > 宋方睿
diff --git a/Makefile b/Makefile index a171eafce2a3b..10ed19caecb1b 100644 --- a/Makefile +++ b/Makefile @@ -531,6 +531,9 @@ RUSTFLAGS_KERNEL = AFLAGS_KERNEL = LDFLAGS_vmlinux = +LDFLAGS_MODULE += --no-dynamic-linker +LDFLAGS_vmlinux += --no-dynamic-linker + # Use USERINCLUDE when you must reference the UAPI directories only. USERINCLUDE := \ -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 += -I$(objtree)/$(obj) $(obj)/header.o: $(obj)/zoffset.h -LDFLAGS_setup.elf := -m elf_i386 -z noexecstack -T +LDFLAGS_setup.elf := --no-dynamic-linker -m elf_i386 -z noexecstack -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/Makefile 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 += realmode.lds $(obj)/realmode.lds: $(obj)/pasyms.h -LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T +LDFLAGS_realmode.elf := --no-dynamic-linker -m elf_i386 --emit-relocs -T CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj) targets += realmode.elf