Skip to contentSkip to conversation

Link the PowerPC vDSO with ld.lld

PATCH Applied Nathan Chancellor 2 participants 4 messages May 11, 2022 – May 24, 2022 PowerPC

lore
Share & tools
lore
#0 lore raw

v2 cover Link the PowerPC vDSO with ld.lld

Hi all,

This series is an alternative to the one proposed by Nick before the PowerPC vDSO unification in commit fd1feade75fb ("powerpc/vdso: Merge vdso64 and vdso32 into a single directory"):

https://lore.kernel.org/[email protected]/

Normally, we try to make compiling and linking two separate stages so that they can be done by $(CC) and $(LD) respectively, which is more in line with what the user expects, versus using the compiler as a linker driver and relying on the implicit default linker value. However, as shown in the above thread, getting this right for the PowerPC vDSO is a little tricky due to the linker emulation values.

The unification might make this easier but that needs further investigation. To avoid regressing ld.bfd while enabling support for linking the vDSO with ld.lld, we can tell the compiler to use ld.lld via either '--ld-path=' (clang 12.0.0) or '-fuse-ld=lld'.

The first patch avoids a warning from ld.lld when linking both vDSO objects and the second patch adds the flags.

This should help avoid the issue noticed during Alexey's LTO bring up:

https://lore.kernel.org/CAKwvOdmUMhqhQhDCpWjMNiQQPvwOJB9MbUkF3RR0BL+H+DagmA@mail.gmail.com/

Changelog:

v1 -> v2: https://lore.kernel.org/[email protected]/

* Flush out the second commit message much more with information from this cover letter and the other threads (Alexey's LTO enablement and Nick's initial stab at converting to $(CC) + $(LD)) [Nick].

* Add Nick and Alexey's tags.

Nathan Chancellor (2):
powerpc/vdso: Remove unused ENTRY in linker scripts powerpc/vdso: Link with ld.lld when requested

 arch/powerpc/kernel/vdso/Makefile     | 1 +
 arch/powerpc/kernel/vdso/vdso32.lds.S | 1 -
 arch/powerpc/kernel/vdso/vdso64.lds.S | 1 -
 3 files changed, 1 insertion(+), 2 deletions(-)

base-commit: b6b1c3ce06ca438eb24e0f45bf0e63ecad0369f5

Signature · 1 line
2.36.1
#1 lore raw

PATCH v2 1/2 powerpc/vdso: Remove unused ENTRY in linker scripts

When linking vdso{32,64}.so.dbg with ld.lld, there is a warning about not finding _start for the starting address:

ld.lld: warning: cannot find entry symbol _start; not setting start address ld.lld: warning: cannot find entry symbol _start; not setting start address

Looking at GCC + GNU ld, the entry point address is 0x0:

  $ llvm-readelf -h vdso{32,64}.so.dbg &| rg "(File|Entry point address):"
  File: vdso32.so.dbg
    Entry point address:               0x0
  File: vdso64.so.dbg
    Entry point address:               0x0

This matches what ld.lld emits:

  $ powerpc64le-linux-gnu-readelf -p .comment vdso{32,64}.so.dbg

File: vdso32.so.dbg

String dump of section '.comment':

    [     0]  Linker: LLD 14.0.0
    [    14]  clang version 14.0.0 (Fedora 14.0.0-1.fc37)

File: vdso64.so.dbg

String dump of section '.comment':

    [     0]  Linker: LLD 14.0.0
    [    14]  clang version 14.0.0 (Fedora 14.0.0-1.fc37)
  $ llvm-readelf -h vdso{32,64}.so.dbg &| rg "(File|Entry point address):"
  File: vdso32.so.dbg
    Entry point address:               0x0
  File: vdso64.so.dbg
    Entry point address:               0x0

Remove ENTRY to remove the warning, as it is unnecessary for the vDSO to function correctly.

---
 arch/powerpc/kernel/vdso/vdso32.lds.S | 1 -
 arch/powerpc/kernel/vdso/vdso64.lds.S | 1 -
 2 files changed, 2 deletions(-)
arch/powerpc/kernel/vdso/vdso32.lds.S +0 -1
index 58e0099f70f4..e0d19d74455f 100644
@@ -13,7 +13,6 @@ OUTPUT_FORMAT("elf32-powerpcle", "elf32-powerpcle", "elf32-powerpcle")
 OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc")
 #endif
 OUTPUT_ARCH(powerpc:common)
-ENTRY(_start)
 
 SECTIONS
 {
arch/powerpc/kernel/vdso/vdso64.lds.S +0 -1
index 0288cad428b0..1a4a7bc4c815 100644
@@ -13,7 +13,6 @@ OUTPUT_FORMAT("elf64-powerpcle", "elf64-powerpcle", "elf64-powerpcle")
 OUTPUT_FORMAT("elf64-powerpc", "elf64-powerpc", "elf64-powerpc")
 #endif
 OUTPUT_ARCH(powerpc:common64)
-ENTRY(_start)
 
 SECTIONS
 {
Signature · 1 line
2.36.1
#2 lore raw

PATCH v2 2/2 powerpc/vdso: Link with ld.lld when requested

In reply to Nathan Chancellor

The PowerPC vDSO uses $(CC) to link, which differs from the rest of the kernel, which uses $(LD) directly. As a result, the default linker of the compiler is used, which may differ from the linker requested by the builder. For example:

  $ make ARCH=powerpc LLVM=1 mrproper defconfig arch/powerpc/kernel/vdso/
  ...
  $ llvm-readelf -p .comment arch/powerpc/kernel/vdso/vdso{32,64}.so.dbg

File: arch/powerpc/kernel/vdso/vdso32.so.dbg
String dump of section '.comment':
[ 0] clang version 14.0.0 (Fedora 14.0.0-1.fc37)

File: arch/powerpc/kernel/vdso/vdso64.so.dbg
String dump of section '.comment':
[ 0] clang version 14.0.0 (Fedora 14.0.0-1.fc37)

LLVM=1 sets LD=ld.lld but ld.lld is not used to link the vDSO; GNU ld is because "ld" is the default linker for clang on most Linux platforms.

This is a problem for Clang's Link Time Optimization as implemented in the kernel because use of GNU ld with LTO requires the LLVMgold plugin, which is not technically supported for ld.bfd per
https://llvm.org/docs/GoldPlugin.html. Furthermore, if LLVMgold.so is missing from a user's system, the build will fail, even though LTO as it is implemented in the kernel requires ld.lld to avoid this dependency in the first place.

Ultimately, the PowerPC vDSO should be converted to compiling and linking with $(CC) and $(LD) respectively but there were issues last time this was tried, potentially due to older but supported tool versions. To avoid regressing GCC + binutils, use the compiler option '-fuse-ld', which tells the compiler which linker to use when it is invoked as both the compiler and linker. Use '-fuse-ld=lld' when LD=ld.lld has been specified (CONFIG_LD_IS_LLD) so that the vDSO is linked with the same linker as the rest of the kernel.

  $ llvm-readelf -p .comment arch/powerpc/kernel/vdso/vdso{32,64}.so.dbg

File: arch/powerpc/kernel/vdso/vdso32.so.dbg
String dump of section '.comment':
[ 0] Linker: LLD 14.0.0
[ 14] clang version 14.0.0 (Fedora 14.0.0-1.fc37)

File: arch/powerpc/kernel/vdso/vdso64.so.dbg
String dump of section '.comment':
[ 0] Linker: LLD 14.0.0
[ 14] clang version 14.0.0 (Fedora 14.0.0-1.fc37)

LD can be a full path to ld.lld, which will not be handled properly by '-fuse-ld=lld' if the full path to ld.lld is outside of the compiler's search path. '-fuse-ld' can take a path to the linker but it is deprecated in clang 12.0.0; '--ld-path' is preferred for this scenario.

Use '--ld-path' if it is supported, as it will handle a full path or just 'ld.lld' properly. See the LLVM commit below for the full details of '--ld-path'.

---
 arch/powerpc/kernel/vdso/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kernel/vdso/Makefile +1 -0
index 954974287ee7..096b0bf1335f 100644
@@ -48,6 +48,7 @@ UBSAN_SANITIZE := n
 KASAN_SANITIZE := n
 
 ccflags-y := -shared -fno-common -fno-builtin -nostdlib -Wl,--hash-style=both
+ccflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld)
 
 CC32FLAGS := -Wl,-soname=linux-vdso32.so.1 -m32
 AS32FLAGS := -D__VDSO32__ -s
Signature · 1 line
2.36.1
#3 lore raw
In reply to Nathan Chancellor
Quoted 6 lines · Nathan Chancellor

This series is an alternative to the one proposed by Nick before the PowerPC vDSO unification in commit fd1feade75fb ("powerpc/vdso: Merge vdso64 and vdso32 into a single directory"):

https://lore.kernel.org/[email protected]/

Quoted 8 lines

Normally, we try to make compiling and linking two separate stages so that they can be done by $(CC) and $(LD) respectively, which is more in line with what the user expects, versus using the compiler as a linker driver and relying on the implicit default linker value. However, as shown in the above thread, getting this right for the PowerPC vDSO is a little tricky due to the linker emulation values.

[...]

Applied to powerpc/next.

[1/2] powerpc/vdso: Remove unused ENTRY in linker scripts

      https://git.kernel.org/powerpc/c/e247172854a57d1a7213bb835ecb4a40ce9bb2b9
[2/2] powerpc/vdso: Link with ld.lld when requested
      https://git.kernel.org/powerpc/c/4406b12214f6592909b63dabdea86d69f1b5ba2e

cheers