From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (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 A7E698468 for ; Mon, 11 Nov 2024 20:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731357850; cv=none; b=m7aaei86koziCkavjR/5uc/N+Zj8Sd1lMyS6rPgvL5vw/VHwWbQUZUd5asKllpf/6LHGyoBEu84hp+qhnOc1OwBNmF3H9x16ai4bG38H+7BC1Z9WGJtQMnssFij9fJwo6VxbbsDCH4RLGhGE+Pu2shssZgmVBNLA3MneDf8abrU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731357850; c=relaxed/simple; bh=pu1bE2oQyz4PIzvOKsfMnSgcPR/vFs7LU5lLf0wlKVk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=S+ZbuA4LiwJWZJk3LBAn2ULW2enYQ+sEx/5sMeFUcQj7MzkIMKXOaMFJwA/hu+V9mAJCDuLft6dg3jK8eUZfUf58mm7exnABcx3pAgBSuObZXct7HuGwADDRcyMJc540JOrFPvOmYAryeAJOoG0A95luQnW2wcBDTuCZaiaLD0o= 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=th4JP1D9; arc=none smtp.client-ip=209.85.160.173 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="th4JP1D9" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-460969c49f2so60081cf.0 for ; Mon, 11 Nov 2024 12:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731357847; x=1731962647; 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=wJ6uFcLfCmrIfQWM4xw2qYGBJMJQRq1denWE0S9O56A=; b=th4JP1D92CK3cfrjBEFzfpzxnrBrwJZUBTJIbHXzUfJkZ5RmdqnaEnn+3K2ZvNLqgs qIIr9Yos1Y8AxPSEJCov1/XvepIiV2VZqbMykG2K3XF7pK3pK/7wYXHBqrYHX9/hkMZI Jb0krIPMLBExfk3O6+Jgj0vVk/61RghT0qh8e42Mz033A/k3DaWdTAvZDVs131T/ZLrD kvTMZhmeIDKunUCd1VqnGp6t0zvRAk9QHiUFaRPHYuDBL3kEJooHwZFEKrguq4PLkNBi B0vbK/mloWngKj8P4pPBx53Exj761aTLx4+FOLhKsQ+bet60Tcid9Uu2JTfvizeEI+jl uIrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731357847; x=1731962647; 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=wJ6uFcLfCmrIfQWM4xw2qYGBJMJQRq1denWE0S9O56A=; b=A6i5/Yg5rDlGQCvV1I1GFQ/D0T5IZgoO+UgpFjeQAPdgyaJxOWX3Cj0VWqdHZbwOMf rHmTbt8GYC6uTag7PjFhtdw07//Lh2rPzpalKLbC8DIphTCbUFIsChgbUA9YqLS+tdaP 2O3kie2+fUzllMz8DrWDSMnj74SKhnmsotcgGGsp+m23SpIZMRc/yuB9uCC6Ead72gHs u2ZF1Tr1YM2cbf+tzK+bY9aaw47KOJLFR6Vw2ZP5XD4gZVX3qxhVuZaJXEXbmK9CjbIV dt7FB3JI1SsWFqQB/uxQ6AuUuya/zrC7LcdK47Y14zPkhaLpxvRFn//yObccAFtKh3Tq MfdA== X-Forwarded-Encrypted: i=1; AJvYcCU8x7CEByQcaMMU/SgTk/CKKAMITZF0YTIP7stOR8AV7tXFtneoLCIMYMMMLxTLYx+k4a96YqeN7x8=@vger.kernel.org X-Gm-Message-State: AOJu0YwYx5nvKnLuqy/SBdy39B9jRrqyBJjQy60F4mLkRPSc4BMhGXvL 3lupyaBpSfRokVYhsloSdOTCSUnV7/pyCEF5v8B6WWgsw9Es9JyGAHSr/Ewus3meVqbqLogqjd0 49IbD8J3lXoewqQbr9ok9hLxZM7WjdJVUMMM0 X-Gm-Gg: ASbGnctuXcUNkAXJ3+pyAXg4kpcyH/Ufihnv7Xvp8o/VAppLtw0OHdVtCX4dzbRT+b7 xkSTx2bOIbGBMC1pgeuZg1U+r+E4/eAnkzUi7sO4WRUBLC/QDXuNpk4JoYiVlVw== X-Google-Smtp-Source: AGHT+IHN/VTkEzYYSUDWzDF6ttzYMfgpvSZeOr4oSBlM+xWBr13kyerRjwvS3iVYPd8P6qhTDE91E+q+P0S+4DZZ1Yw= X-Received: by 2002:ac8:57cb:0:b0:462:c961:ab88 with SMTP id d75a77b69052e-4633f2ba6b3mr499291cf.13.1731357846333; Mon, 11 Nov 2024 12:44:06 -0800 (PST) Precedence: bulk X-Mailing-List: workflows@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241026051410.2819338-1-xur@google.com> <20241026051410.2819338-4-xur@google.com> <44193ca7-9d31-4b58-99cc-3300a6ad5289@gmail.com> In-Reply-To: <44193ca7-9d31-4b58-99cc-3300a6ad5289@gmail.com> From: Rong Xu Date: Mon, 11 Nov 2024 12:43:54 -0800 Message-ID: Subject: Re: [PATCH v6 3/7] Adjust symbol ordering in text output section To: Klara Modin 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 , Masahiro Yamada , "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 , "David S. Miller" , Andreas Larsson , Yonghong Song , Yabin Cui , Krzysztof Pszeniczny , Sriraman Tallam , Stephane Eranian , x86@kernel.org, linux-arch@vger.kernel.org, sparclinux@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for reporting this issue! I'm assuming your kernel build enables dead code elimination and uses the --ffunction-sections compiler flag. Without this patch, all the functions -- I think there are only .text.unlikely.* and .text.* are grouped together in the final vmlinux. This patch modifies the linker script to place .text.unlikely.* functions before .text.* functions. I've examined arch/mips/kernel/vmlinux.lds.S, an= d haven't found any obvious issue. Can you send me the following? (1) the kernel build command (2) System.map without the patch (3) System.map with the patch Best regards, -Rong On Sat, Nov 9, 2024 at 7:39=E2=80=AFAM Klara Modin = wrote: > > Hi, > > On 2024-10-26 07:14, 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 "..". > > > > This patch modifies the order of subsections within the text output > > section. Specifically, it repositions sections with certain fixed patte= rns > > (for example .text.unlikely) before TEXT_MAIN, ensuring that they are > > grouped and matched together. It also places .text.hot section at the > > beginning of a page to help the TLB performance. > > > > 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. > > > > This patch also changes vmlinux.lds.S for the sparc64 architecture to > > accommodate specific symbol placement requirements. > > With this patch (622240ea8d71a75055399fd4b3cc2b190e44d2e2 in > next-20241108) my Edgerouter 6P hangs on boot (Cavium Octeon III, > mips64, running in big endian). It's using device tree passed from the > vendored u-boot (attached in case it's relevant). > > Disabling dead code elimination does not fix the issue. > > Please let me know if there's anything else you need. > > Regards, > Klara Modin > > > > > Co-developed-by: Han Shen > > Signed-off-by: Han Shen > > Signed-off-by: Rong Xu > > Suggested-by: Sriraman Tallam > > Suggested-by: Krzysztof Pszeniczny > > Tested-by: Yonghong Song > > Tested-by: Yabin Cui > > Change-Id: I5202d40bc7e24f93c2bfb2f0d987e9dc57dec1b1 > > --- > > arch/sparc/kernel/vmlinux.lds.S | 5 +++++ > > include/asm-generic/vmlinux.lds.h | 19 ++++++++++++------- > > 2 files changed, 17 insertions(+), 7 deletions(-) > > > > diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinu= x.lds.S > > index d317a843f7ea9..f1b86eb303404 100644 > > --- a/arch/sparc/kernel/vmlinux.lds.S > > +++ b/arch/sparc/kernel/vmlinux.lds.S > > @@ -48,6 +48,11 @@ SECTIONS > > { > > _text =3D .; > > HEAD_TEXT > > + ALIGN_FUNCTION(); > > +#ifdef CONFIG_SPARC64 > > + /* Match text section symbols in head_64.S first */ > > + *head_64.o(.text) > > +#endif > > TEXT_TEXT > > SCHED_TEXT > > LOCK_TEXT > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vm= linux.lds.h > > index eeadbaeccf88b..fd901951549c0 100644 > > --- a/include/asm-generic/vmlinux.lds.h > > +++ b/include/asm-generic/vmlinux.lds.h > > @@ -553,19 +553,24 @@ > > * .text section. Map to function alignment to avoid address changes > > * 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. > > + * TEXT_MAIN here will match symbols with a fixed pattern (for example= , > > + * .text.hot or .text.unlikely) if dead code elimination or > > + * function-section is enabled. Match these symbols first before > > + * TEXT_MAIN to ensure they are grouped together. > > + * > > + * Also placing .text.hot section at the beginning of a page, this > > + * would help the TLB performance. > > */ > > #define TEXT_TEXT \ > > 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) \ > > - *(.text.unlikely .text.unlikely.*) \ > > - *(.text.unknown .text.unknown.*) \ > > NOINSTR_TEXT \ > > - *(.ref.text) \ > > - *(.text.asan.* .text.tsan.*) > > + *(.ref.text) > > > > > > /* sched.text is aling to function alignment to secure we have same