From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E879E770E1; Mon, 29 Jul 2024 09:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245663; cv=none; b=mHJuU3BPchROOrWu+G1NAtXANO7E5YIYdjki8MEa6ctWZ9CZHD9b6Z1tP1b7xAlJrvEI9HdEN0NHdmovS6+2I8Dny+tu1aq/SzA+Xi57J2l/4wuNcke1Ki6398A5mge3uoXCW2I/I5wfN6UemcOV1cd1y9Jo7vAF7VUvBMztW+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722245663; c=relaxed/simple; bh=3jPwdF87VODfvLYMSLQ6a8U5V6bwkM9aoC2LVJskl4k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JEreezV5t9lnUxTuIBdJa3YFmVyFHMeZ+n7QNbh7ZIwpX6QeAt3bF8Mtnpx/g13V16i+NrbC+c1ZkeSVMLz9Gkv7Ns8w4ma5q0ROW6JV5kpIANkUoQsRpCphC4G/oRry1ZSxfKiW/GRlyVMvkXx7MlEH6iI/iwK/uwabXbv0in8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=vRnJ603h; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vRnJ603h" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=8JC9Mk7PKGPRsFj1tUJdTnT65oycReDEnXbNeaPrch8=; b=vRnJ603hG2qrYgjH37cZsIaTty kbnnWa7CjLIqvatukxS67LykRqrQgJkaCNBwfmtKqR4SlBruRVepVz5alu67HS0JQAWmWFRDO/N7A od/rHvVXsl6oM7N955Rb5sa+a8xJ97rYORUGm4fgJ0xmlyJRcR61xnGllcfSu8IugcJKiLpqzkKKL HNYmPh4hrfJvQaXquK4Ni9lzRMMLs3Q9e6TGSXZ66gAPNwb34qKpVNmOJaPXE5x4r/pDx9bKMuD0C 1mbVBy9VfyT+tWOqSqsD/HTRS0rn5NIr7IuXjdIvHSXxuBOWoKqZIdmq+4NYePiNAVqodzmMhz/UQ 9oYkfk/Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYMla-0000000DQiR-1KUO; Mon, 29 Jul 2024 09:34:06 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id EAFEC300439; Mon, 29 Jul 2024 11:34:05 +0200 (CEST) Date: Mon, 29 Jul 2024 11:34:05 +0200 From: Peter Zijlstra To: Rong Xu Cc: Han Shen , Sriraman Tallam , David Li , Jonathan Corbet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , Arnd Bergmann , Josh Poimboeuf , Nick Desaulniers , Bill Wendling , Justin Stitt , Vegard Nossum , John Moon , Andrew Morton , Heiko Carstens , Luis Chamberlain , Samuel Holland , Mike Rapoport , "Paul E . McKenney" , Rafael Aquini , Petr Pavlu , Eric DeVolder , Bjorn Helgaas , Randy Dunlap , Benjamin Segall , Breno Leitao , Wei Yang , Brian Gerst , Juergen Gross , Palmer Dabbelt , Alexandre Ghiti , Kees Cook , Sami Tolvanen , Xiao Wang , Jan Kiszka , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-efi@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Krzysztof Pszeniczny Subject: Re: [PATCH 3/6] Change the symbols order when --ffuntion-sections is enabled Message-ID: <20240729093405.GC37996@noisy.programming.kicks-ass.net> References: <20240728203001.2551083-1-xur@google.com> <20240728203001.2551083-4-xur@google.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240728203001.2551083-4-xur@google.com> On Sun, Jul 28, 2024 at 01:29:56PM -0700, 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.: > “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.” > > It is unclear whether there is a straightforward method for converting > a suffix to "..". 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 grouped > and matched together. > > Note that the limitation arises because the linker script employs glob > patterns instead of regular expressions for string matching. While there > 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 | 19 ++++++++++++++++--- > 1 file changed, 16 insertions(+), 3 deletions(-) > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h > index 5703526d6ebf..f3de66bda293 100644 > --- a/include/asm-generic/vmlinux.lds.h > +++ b/include/asm-generic/vmlinux.lds.h > @@ -582,9 +582,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 symbols > + * first when in these builds. > */ > +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) > +#define TEXT_TEXT \ > + *(.text.asan.* .text.tsan.*) \ > + *(.text.unknown .text.unknown.*) \ > + *(.text.unlikely .text.unlikely.*) \ > + ALIGN_FUNCTION(); \ Why leave the above text sections unaligned? > + *(.text.hot .text.hot.*) \ > + *(TEXT_MAIN .text.fixup) \ > + NOINSTR_TEXT \ > + *(.ref.text) \ > + MEM_KEEP(init.text*) > +#else > #define TEXT_TEXT \ > ALIGN_FUNCTION(); \ > *(.text.hot .text.hot.*) \ > @@ -594,7 +606,8 @@ > NOINSTR_TEXT \ > *(.ref.text) \ > *(.text.asan.* .text.tsan.*) \ > - MEM_KEEP(init.text*) \ > + MEM_KEEP(init.text*) > +#endif > > > /* sched.text is aling to function alignment to secure we have same > -- > 2.46.0.rc1.232.g9752f9e123-goog >