Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 B2D9C4C6E for ; Fri, 13 May 2022 18:28:47 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id s14so8735064plk.8 for ; Fri, 13 May 2022 11:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:to:cc:references :from:in-reply-to:content-transfer-encoding; bh=WGeEFtW+qWgYEib1uWcOLgCq1srN8mGZzrkA8bVtVI0=; b=euMyw1414NTr9pLTQrkN6Zjje/sgQu2q+FLX5y3yqSiJBSB8mqg09y8M/riUklzywO Tn3VPSCO75DJ1sioNxyr1or8x7VCj5nL+8OFV19Yk6QMcZts162WLujL9QPIP0KTexoh 3Ld6d1fRiJ7vYY8kQwxkwRK87HhzLv84KbVJubni3UN/ZIBYFeohvEdGda1dTeuwr+Jl ynI4TOnNbnOimkqDVoA2Ikp+uxuxorFkDrknm62k36/0rF6FEGjGRXPXqFWJM5x1ZJC3 4WaDP9F+iFCZNT5AoT9IMZ5kpItRV6+Dq1Xc9StWc0vB3xzpqpJwn2uvfqNhZTGyl01y DOvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :to:cc:references:from:in-reply-to:content-transfer-encoding; bh=WGeEFtW+qWgYEib1uWcOLgCq1srN8mGZzrkA8bVtVI0=; b=Gzelgu8zfrdAj1LTPUsVLwvDPF/sKVXOmdG+0QyxruBZK3mHRIhTIt5m4q+U4Fotkr o7AynokusLRc4QC00GuDflMmAuxRFWB7yL5BBhG9KYH8IsrUzJH4Fy3xR8bZ4WTaSOyM 0YldCZH9QQN1BKTtoGZh2odF1f/TB2NduptYx+VkLiH4gbOoLGaSD0wWF4uMcPUBcfZm pRwWIwD5mU6mCN9kT22nfltwAN3w7AndnkALC4ErIwmPL2mnSNjGKwDPtR9DPFlfTm5h 0ug+wEywlrkG6q5BsbRpkNnxQ3W47oWvR4ODwKlK3cZTWUwryorsI91LWGInDH5B537x Pb6A== X-Gm-Message-State: AOAM532S3mnsSWSG7V7k3KwZoPCH7vMxL1Gm314mMSgR8w2TBPHKL7+3 VEJz1aX3XK410RUikKI09u4= X-Google-Smtp-Source: ABdhPJy/G2FpW1sRNV1Sq94oQXe/w2hGlTDKasT3hfq8Vc4fKaqMyaLjil8Y765FzXGsOI/mV8+qoQ== X-Received: by 2002:a17:903:124a:b0:154:c7a4:9375 with SMTP id u10-20020a170903124a00b00154c7a49375mr6066093plh.0.1652466527058; Fri, 13 May 2022 11:28:47 -0700 (PDT) Received: from [0.0.0.0] ([2604:a880:1:20::1f:7001]) by smtp.gmail.com with ESMTPSA id y124-20020a62ce82000000b0050dc76281f9sm2080709pfg.211.2022.05.13.11.28.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 May 2022 11:28:46 -0700 (PDT) Message-ID: <30f9c99e-9bc4-9369-a533-7b454a213403@gmail.com> Date: Sat, 14 May 2022 02:28:40 +0800 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v2] RISC-V: build: Allow LTO to be selected To: Nick Desaulniers Cc: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, nathan@kernel.org, llvm@lists.linux.dev, Fangrui Song References: <20220512205545.992288-1-twd2.me@gmail.com> From: twd2 In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 2022/5/13 5:34, Nick Desaulniers 写道: > On Thu, May 12, 2022 at 1:56 PM Wende Tan wrote: >> Allow LTO to be selected for RISC-V, only when LLD >= 14, since there is an >> issue [1] in prior LLD versions that prevents LLD to generate proper >> machine code for RISC-V when writing `nop`s. >> >> I have tested enabling LTO for `defconfig`. The LLD took ~2m21s and ~3GiB >> on our Intel Xeon Gold 6140 server and produced an 18MiB Image. The image >> can boot to shell using an archriscv rootfs on QEMU. >> >> I have also tested it for `allyesconfig` without COMPILE_TEST, FTRACE, >> KASAN, and GCOV. The LLD took ~7h03m and ~335GiB on the server, > Haha! That's ok, allyesconfig is not expected to boot for any > architectures AFAIK. For CI, we simply verify we can build them; we > boot test everything but allyesconfig and allmodconfig (and > architectures which don't yet have qemu ports). It helps detect when > assembler sources don't use enough encoding space when referenced > external symbols are too far away for larger images, IME. > > That's a long time; first time I've seen a number from someone trying > to LTO allyesconfig! > >> successfully producing a 1.7GiB Image. Unfortunately, we cannot boot this >> image because the `create_kernel_page_table()` -> `alloc_pmd_early()` -> >> `BUG_ON()` logic limits the image to be < 1GiB. Maybe we can fix it in a >> separate patch further. >> >> [1] https://github.com/llvm/llvm-project/issues/50505, resolved by LLVM >> commit e63455d5e0e5 ("[MC] Use local MCSubtargetInfo in writeNops") > So looking at that change, it doesn't look like it touches LLD at all. > To me it touches both the assembler and the object streamer, which is > used by the compiler (and assembler) to stream instructions directly > into an object file (without the need for an external assembler). > > That makes me think that > CLANG_VERSION >= 140000 > would be more appropriate than > LLD_VERSION >= 140000 > > WDYT? It seems that when LTO is enabled, the compiler (clang) only generates bitcode, and LLD collects all the bitcode, does LTO, and generates machine code (assembly) and ELF object files? Actually, the error message in #50505 was originally reported by LLD. So I'd like to check LLD_VERSION here. > > Also, I'm curious if the LLVM patch you had me commit for you recently > is at all related or necessary for this? If so, then the version check > should probably be against clang-15, not clang-14. > https://github.com/llvm/llvm-project/commit/6baaad740a5abb4bfcff022a8114abb4eea66a2d Aha, that patch is for enabling LTO for allyesconfig (especially, with xfs and overlayfs). I think that patch is not mandatory for enabling LTO for RISC-V. > Anyways, I just did a build+boot (in qemu) test of defconfig+thinlto > and defconfig+lto. LGTM > > Tested-by: Nick Desaulniers Thanks, Wende >> Tested-by: Wende Tan >> Signed-off-by: Wende Tan >> --- >> v2: >> - Some textual changes suggested by Nick. >> - Drop the changes to `arch/riscv/Makefile`, since the LLVM issue is filed >> and resolved. >> - Drop the unnecessary changes to `arch/riscv/kernel/vdso/Makefile`. >> >> v1: https://lore.kernel.org/linux-riscv/20210719205208.1023221-1-twd2.me@gmail.com/ >> --- >> arch/riscv/Kconfig | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig >> index 00fd9c548f26..c55f6b95e5af 100644 >> --- a/arch/riscv/Kconfig >> +++ b/arch/riscv/Kconfig >> @@ -38,6 +38,10 @@ config RISCV >> select ARCH_SUPPORTS_ATOMIC_RMW >> select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU >> select ARCH_SUPPORTS_HUGETLBFS if MMU >> + # LLD >= 14: >> + # - https://github.com/llvm/llvm-project/issues/50505 >> + select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000 >> + select ARCH_SUPPORTS_LTO_CLANG_THIN if LLD_VERSION >= 140000 >> select ARCH_USE_MEMTEST >> select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU >> select ARCH_WANT_FRAME_POINTERS >> -- >> 2.25.1 >>