public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.1&6.6 0/3] kbuild: Avoid weak external linkage where possible
@ 2024-12-06  8:58 Huacai Chen
  2024-12-06  8:58 ` [PATCH 6.1&6.6 1/3] kallsyms: Avoid weak references for kallsyms symbols Huacai Chen
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Huacai Chen @ 2024-12-06  8:58 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Sasha Levin, Huacai Chen
  Cc: Xuerui Wang, Masahiro Yamada, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, stable, linux-kbuild, linux-kernel, loongarch,
	Huacai Chen, Ard Biesheuvel

Backport this series to 6.1&6.6 because LoongArch gets build errors with
latest binutils which has commit 599df6e2db17d1c4 ("ld, LoongArch: print
error about linking without -fPIC or -fPIE flag in more detail").

  CC      .vmlinux.export.o
  UPD     include/generated/utsversion.h
  CC      init/version-timestamp.o
  LD      .tmp_vmlinux.kallsyms1
loongarch64-unknown-linux-gnu-ld: kernel/kallsyms.o:(.text+0): relocation R_LARCH_PCALA_HI20 against `kallsyms_markers` can not be used when making a PIE object; recompile with -fPIE
loongarch64-unknown-linux-gnu-ld: kernel/crash_core.o:(.init.text+0x984): relocation R_LARCH_PCALA_HI20 against `kallsyms_names` can not be used when making a PIE object; recompile with -fPIE
loongarch64-unknown-linux-gnu-ld: kernel/bpf/btf.o:(.text+0xcc7c): relocation R_LARCH_PCALA_HI20 against `__start_BTF` can not be used when making a PIE object; recompile with -fPIE
loongarch64-unknown-linux-gnu-ld: BFD (GNU Binutils) 2.43.50.20241126 assertion fail ../../bfd/elfnn-loongarch.c:2673

In theory 5.10&5.15 also need this, but since LoongArch get upstream at
5.19, so I just ignore them because there is no error report about other
archs now.

Weak external linkage is intended for cases where a symbol reference
can remain unsatisfied in the final link. Taking the address of such a
symbol should yield NULL if the reference was not satisfied.

Given that ordinary RIP or PC relative references cannot produce NULL,
some kind of indirection is always needed in such cases, and in position
independent code, this results in a GOT entry. In ordinary code, it is
arch specific but amounts to the same thing.

While unavoidable in some cases, weak references are currently also used
to declare symbols that are always defined in the final link, but not in
the first linker pass. This means we end up with worse codegen for no
good reason. So let's clean this up, by providing preliminary
definitions that are only used as a fallback.

Ard Biesheuvel (3):
  kallsyms: Avoid weak references for kallsyms symbols
  vmlinux: Avoid weak reference to notes section
  btf: Avoid weak external references

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 include/asm-generic/vmlinux.lds.h | 28 ++++++++++++++++++
 kernel/bpf/btf.c                  |  7 +++--
 kernel/bpf/sysfs_btf.c            |  6 ++--
 kernel/kallsyms.c                 |  6 ----
 kernel/kallsyms_internal.h        | 30 ++++++++------------
 kernel/ksysfs.c                   |  4 +--
 lib/buildid.c                     |  4 +--
 7 files changed, 52 insertions(+), 33 deletions(-)
---
2.27.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-09-05  8:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-06  8:58 [PATCH 6.1&6.6 0/3] kbuild: Avoid weak external linkage where possible Huacai Chen
2024-12-06  8:58 ` [PATCH 6.1&6.6 1/3] kallsyms: Avoid weak references for kallsyms symbols Huacai Chen
2024-12-06  8:58 ` [PATCH 6.1&6.6 2/3] vmlinux: Avoid weak reference to notes section Huacai Chen
2024-12-06  8:58 ` [PATCH 6.1&6.6 3/3] btf: Avoid weak external references Huacai Chen
2024-12-06 13:04 ` [PATCH 6.1&6.6 0/3] kbuild: Avoid weak external linkage where possible Greg Kroah-Hartman
2024-12-07  9:21   ` Huacai Chen
2024-12-07  9:32     ` Greg Kroah-Hartman
2024-12-07 10:46       ` Xi Ruoyao
2024-12-09  8:31         ` Ard Biesheuvel
2024-12-09 10:01           ` Xi Ruoyao
2025-02-06  8:37   ` WangYuli
2025-02-06  9:31     ` Ard Biesheuvel
2025-02-06 10:03     ` Greg KH
2025-09-05  6:49       ` Ming Wang
2025-09-05  7:09         ` Greg KH
2025-09-05  8:29           ` Ming Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox