From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 AD4C91FF044 for ; Mon, 21 Oct 2024 23:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729554208; cv=none; b=E1vDkZCawu5YjFeUoB70MlH8Re4qaWYlzT829RglmhCXQPhwX5dw7WSMILqDCZmE0SvGOLmnHJtocuJVmmbEVnGvBrDgjcJO/4WKf/S2Ek7qg27kezhbQ6dQRspinCpHvpdVIPZY2z+Qa++9ZcY434GEAsZFhhqMPRdZIzB0M6U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729554208; c=relaxed/simple; bh=670Rx8VhAsuQw1rqEOWFlDm06/IQZHXSWxj6k8/pKYg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=e5PiHyg0y6gI3F9SwlKz8fFfv6iXwH7VQ1MHIxvAlZ+kjGGFLVHlhOQXSUsUf1nsC5LUEgPj4WbHMt1h0z8v045UDn4j4vxLHOxTUNXFTC7OdfJCLrJWP+xHO4NazrnSj9VfaJDblI49nqaUds6OvOHMigCvQ2iXbTOfI7dHBJo= 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=ZBMsnG0C; arc=none smtp.client-ip=209.85.160.179 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZBMsnG0C" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-460a8d1a9b7so82941cf.1 for ; Mon, 21 Oct 2024 16:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729554204; x=1730159004; 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=VH1I9Ut0mQYyKMoQvkGxIgww2ZJ9ePwLy+OSXFMT9R4=; b=ZBMsnG0ChHKUl0wQKdVYuYQPqVHsNl+qZhUBU7c+0ggXFcD+1CvWi3OzBlwqutlfER SFvWLUc0UP1bPkA827mmxjUJjiP9/yVZ9sHFDbD28KU4ctH+YV/F0mOvwSZbI2xh9dl4 j6Km0ND0dE528TRBxFPAntNqMh2VAWshGSEKFUznzIpHov13Ij0X+dryYY6CY7N4lpZw lJYkVpalqAGenQrv/sKZFNLddgIDtFw7RO/1lLphSxLBw5N6xN51LIrcX7Gg23MtuQdY t2Oa5gRbxDDg4TnCQHgEJUMBjFjRldvA/vOdzd9Z9ftNPrE72hMTd+jyUFce+9uyGO6e vDYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729554204; x=1730159004; 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=VH1I9Ut0mQYyKMoQvkGxIgww2ZJ9ePwLy+OSXFMT9R4=; b=QIpVEAOis3V55RSqdkju/hNOtWN/n2++dFVaqce17uydLe2KY060FXTaAp3yGn3Srj 9C0vVfU4DTCrIlyRFpxJA735RXXvexmMJDsHn8Rqt2aqVC6BsT6CUZZUvGTS1P8jTaUG nFsn5cIAzmVjTzlOMA/R/Mx+52uEKsj2SbKbh124r1B/bpD/5Woo7mkuls+qJ4XheUg5 TtNIQP61N3ldbyzr6YL2nj8yqbS1B6TjQPEgLfasUwA1VbOlTo4OjHfhZjekdNhOMWsx lUIBR5cMRM8Kopsv8D+F96Bcc8n+jSC8g7jMmd0JoxRgaAi0ljWx0wEtv0CzaryrOdXf G4Ag== X-Forwarded-Encrypted: i=1; AJvYcCWRvoZ2Ft2CPhvqrL1VRmhoP4mCPdq2CtlJG9hZuZIulG6NzCbV4nKXtGh4W6UfDPsB/69sHZ7OteU=@vger.kernel.org X-Gm-Message-State: AOJu0YwL5QJozBVjzxqperFWteDA2U+Lr8xAWjp9SxKfc1se3DJD+4ji jpnclx+B1VEOWTFjnD0RY5FgW78GZSqHUrEFfleZeWxgCSnAL/w8g3O5Svf15oLU5DpGcRCDX9Z sYgF/BmeT/WdzG/KdVxncmhxW6dCGLu93WHOD X-Google-Smtp-Source: AGHT+IGBJEGpd9nQo0o209R0pXE8dMLJ0OAC0OgWVKOeU4WwTY9FO3DmQPqrzs2Q2l7L/01n09HMzEfWkSHfOjpUeOI= X-Received: by 2002:a05:622a:1827:b0:458:1d2b:35f6 with SMTP id d75a77b69052e-46100b9b324mr1762321cf.24.1729554204431; Mon, 21 Oct 2024 16:43:24 -0700 (PDT) Precedence: bulk X-Mailing-List: workflows@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241014213342.1480681-1-xur@google.com> <20241014213342.1480681-4-xur@google.com> In-Reply-To: From: Rong Xu Date: Mon, 21 Oct 2024 16:43:12 -0700 Message-ID: Subject: Re: [PATCH v4 3/6] Change the symbols order when --ffuntion-sections is enabled To: Masahiro Yamada Cc: Alice Ryhl , Andrew Morton , Arnd Bergmann , Bill Wendling , Borislav Petkov , Breno Leitao , Brian Gerst , Dave Hansen , David Li , Han Shen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jonathan Corbet , Josh Poimboeuf , Juergen Gross , Justin Stitt , Kees Cook , "Mike Rapoport (IBM)" , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , "Paul E. McKenney" , Peter Zijlstra , Sami Tolvanen , Thomas Gleixner , Wei Yang , workflows@vger.kernel.org, Miguel Ojeda , Maksim Panchenko , x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sriraman Tallam , Krzysztof Pszeniczny Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Oct 20, 2024 at 7:15=E2=80=AFPM Masahiro Yamada wrote: > > On Tue, Oct 15, 2024 at 6:33=E2=80=AFAM Rong Xu wrote: > > > > When the -ffunction-sections compiler option is enabled, each function > > is placed in a separate section named .text.function_name rather than > > putting all functions in a single .text section. > > > > However, using -function-sections can cause problems with the > > linker script. The comments included in include/asm-generic/vmlinux.lds= .h > > note these issues.: > > =E2=80=9CTEXT_MAIN here will match .text.fixup and .text.unlikely if = dead > > code elimination is enabled, so these sections should be converted > > to use ".." first.=E2=80=9D > > > > It is unclear whether there is a straightforward method for converting > > a suffix to "..". > > > > Why not for ".text.fixup"? > > $ git grep --name-only '\.text\.fixup' | xargs sed -i > 's/\.text\.fixup/.text..fixup/g' > I did not move .text.fixup because it currently groups together with TEXT_M= AIN. Yes. For all the kernel annotated sections, we can replace them with a ".." string. For compiler generate strings, like .unlikely, .hot, and .split, we need a compiler change for that (maybe under an option). The process will be long. Or we can use an extra script, like objcopy to change them? > > > I do not know how to rename other sections that are generated by compiler= s. > > > > > > This patch modifies the order of subsections within the > > text output section when the -ffunction-sections flag is enabled. > > Specifically, it repositions sections with certain fixed patterns (for > > example .text.unlikely) before TEXT_MAIN, ensuring that they are groupe= d > > and matched together. > > > > Note that the limitation arises because the linker script employs glob > > patterns instead of regular expressions for string matching. While ther= e > > is a method to maintain the current order using complex patterns, this > > significantly complicates the pattern and increases the likelihood of > > errors. > > > > Co-developed-by: Han Shen > > Signed-off-by: Han Shen > > Signed-off-by: Rong Xu > > Suggested-by: Sriraman Tallam > > Suggested-by: Krzysztof Pszeniczny > > --- > > include/asm-generic/vmlinux.lds.h | 17 +++++++++++++++-- > > 1 file changed, 15 insertions(+), 2 deletions(-) > > > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vm= linux.lds.h > > index eeadbaeccf88..5df589c60401 100644 > > --- a/include/asm-generic/vmlinux.lds.h > > +++ b/include/asm-generic/vmlinux.lds.h > > @@ -554,9 +554,21 @@ > > * during second ld run in second ld pass when generating System.map > > * > > * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead > > - * code elimination is enabled, so these sections should be converted > > - * to use ".." first. > > + * code elimination or function-section is enabled. Match these symbol= s > > + * first when in these builds. > > */ > > +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LT= O_CLANG) > > +#define TEXT_TEXT = \ > > > Why did you do this conditionally? > > You are making this even more unmaintainable. Again, we don't want to change the default build. If you think the change can apply to the default build, we would be happy to remove the condition. > > > > > > > + ALIGN_FUNCTION(); = \ > > + *(.text.asan.* .text.tsan.*) = \ > > + *(.text.unknown .text.unknown.*) = \ > > + *(.text.unlikely .text.unlikely.*) = \ > > + . =3D ALIGN(PAGE_SIZE); = \ > > + *(.text.hot .text.hot.*) = \ > > + *(TEXT_MAIN .text.fixup) = \ > > + NOINSTR_TEXT = \ > > + *(.ref.text) > > +#else > > #define TEXT_TEXT = \ > > ALIGN_FUNCTION(); = \ > > *(.text.hot .text.hot.*) = \ > > @@ -566,6 +578,7 @@ > > NOINSTR_TEXT = \ > > *(.ref.text) = \ > > *(.text.asan.* .text.tsan.*) > > +#endif > > > > > > /* sched.text is aling to function alignment to secure we have same > > -- > > 2.47.0.rc1.288.g06298d1525-goog > > > > > > > -- > Best Regards > Masahiro Yamada