From nobody Wed Nov 27 02:26:53 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 7BEF91D3643 for ; Mon, 14 Oct 2024 21:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728941633; cv=none; b=LQjcSKwfw4+EtptRyxqguOaRPsXcwWwDOVkKDyRGc6Cb2mVv0N1ngMb/No0zF3pM/ECAn0Lfvn/y8s8GRw2b0fS5yVhxRO/Qm1cv+cRWn/aDfa03niAFt1oSaF9oB4m/JDP+MU+6CAGAeCEtriGC1/oYZzhPJRDPUF695JGki54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728941633; c=relaxed/simple; bh=LqcsOVQmv5GpC5shRDpw1q19kzqKid+XE2EfW/9oI3s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ck0UF0ZGHNa8X+7vd+7r6VwC3Byt4GpIiYMMMaaXwC5T45+S4bZfxePivD1Bgf2BOZrke1QJXdo3ZeW8maIDKr/rymRTqUU0GB2uf36VvlZqBZSxdmDzBUrztwSrLDx3lskf8ed6xdHMlU6f7Q++DzLjYQuMr8lvYNoPIyKX0ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bseQDC1R; arc=none smtp.client-ip=209.85.219.202 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=flex--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bseQDC1R" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e28edea9af6so6422765276.3 for ; Mon, 14 Oct 2024 14:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728941630; x=1729546430; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=3BOqTSYvoekh3ysMWFRZqW1diZJBhOLc/W4rCwg+Ukg=; b=bseQDC1RXWv0A5TH7LbZUyoKhNXnGuI8+aprXQFAcgli9TkldlU4cfwVFgTYjg+8zX ujBcNJVA6nDlrOtTpjnNS15UMOLLVhCDBCkBTppWMS7KlaGPV13mq6Fcxg0v4EvsfpR7 nvKfrgnH/JrnirGKZgUiT8l/NMd6T4sBqW0JXvTVCWOnIz76GAoscbJU/ofIOkrTlb9/ JKQOXgBN23kKp36BaT6Bh0mS6RONVzFK8HhjsR5ResLCQTT9Tqsq4/SVHSMUcbUcG4Z7 yHOJVaqMn4phSIZ6BCKtvNp6VNBPSOtiKHyLyOcRs91kR2wWMibEa/P3WOOyvUDxWl8N 36KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728941630; x=1729546430; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=3BOqTSYvoekh3ysMWFRZqW1diZJBhOLc/W4rCwg+Ukg=; b=NHVtEb99hIP/LRpRTz1QumPoTcq2tp9HR+s3FUovOeyEZTeiH1dJ3h9b2rTi7GkFAJ ytuyl0iLDKqxN0PEqbi96RR5KNQjjYtGVUTrROJqPG+aq0tx9/fCsIMNUohxrhMxTLiY azs7b248ecVQBix5l1f4z8Ga6A1di80Mhia+f8DNZHflYstGN8SX0vrJgKeMAI8ToIOV UCuab60vVhrzO9GcqwXwipHX2w23QN8wZ5tMytZbdACDfgIZw4ZcV8WTFvLHIq7nqY+A UKPy8gqbTAQVQcG/K+XGaxzAkBWkC+Bmw/guFrEGiY6POlBVw6pg1I6k7aHN6SqrWsQE zYyg== X-Forwarded-Encrypted: i=1; AJvYcCW01H0LCfvDhBPruQX4LzTXuMjvrYDGVfucE+aodnulomgkjPDjJHwAcxe9RX8NJkRkWf9T9EykIfZXy5s=@vger.kernel.org X-Gm-Message-State: AOJu0YxTvDgqqXvotZ0ZidupRvpLApzVx/7psn/CcpOM5MgGqMs7D2fd nJipoR/uI2NMN0LzLFC1Yhmjbr8W+6e0o1TJPmnpr9zriMRccI/TVSNzIaledtaORg== X-Google-Smtp-Source: AGHT+IGJAf1dyn6T0B9hkA7jpV9sHV0gdw83rZtNGaxxQS6w9BKyM0bMWv36PdPXm3t7rejUADUFc3c= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a25:3607:0:b0:e28:e74f:4cb with SMTP id 3f1490d57ef6-e2918e5347amr56303276.0.1728941630550; Mon, 14 Oct 2024 14:33:50 -0700 (PDT) Date: Mon, 14 Oct 2024 14:33:37 -0700 In-Reply-To: <20241014213342.1480681-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241014213342.1480681-1-xur@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014213342.1480681-4-xur@google.com> Subject: [PATCH v4 3/6] Change the symbols order when --ffuntion-sections is enabled From: Rong Xu To: 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 , Rong Xu , Sami Tolvanen , Thomas Gleixner , Wei Yang , workflows@vger.kernel.org, Miguel Ojeda , Maksim Panchenko Cc: 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.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 symbols + * first when in these builds. */ +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CL= ANG) +#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) \ + 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 =20 =20 /* sched.text is aling to function alignment to secure we have same --=20 2.47.0.rc1.288.g06298d1525-goog