[lld] [lld] Add target support for SystemZ (s390x) (PR #75643)

Tulio Magno Quites Machado Filho via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 11:27:55 PST 2024


tuliom wrote:

> Perhaps it is possible that the kernel should be compiled with `-fPIC`, it is built with `-fPIE` right now.

@nathanchance I don't think so. I'm afraid that lld is actually pointing at a real error here, but I'd love if somebody with more experience would review this.

> If there is any information I can provide if this seems like something that should be resolved in `ld.lld`, I am more than happy to do so. If not, I'll see if I can get some help from the kernel folks.

With the information that @nathanchance provided, I decided to test the build with gcc-14 + lld-17.
I had to fix some compatibility issues first:
```
diff --git a/arch/s390/Makefile b/arch/s390/Makefile
index 73873e451686..2ef8fa238e02 100644
--- a/arch/s390/Makefile
+++ b/arch/s390/Makefile
@@ -9,7 +9,6 @@
 #
 
 LD_BFD		:= elf64-s390
-KBUILD_LDFLAGS	:= -m elf64_s390
 KBUILD_AFLAGS_MODULE += -fPIC
 KBUILD_CFLAGS_MODULE += -fPIC
 KBUILD_AFLAGS	+= -m64
diff --git a/arch/s390/kernel/vdso32/vdso32.lds.S b/arch/s390/kernel/vdso32/vdso32.lds.S
index edf5ff1debe1..2a5536f02678 100644
--- a/arch/s390/kernel/vdso32/vdso32.lds.S
+++ b/arch/s390/kernel/vdso32/vdso32.lds.S
@@ -7,7 +7,6 @@
 #include <asm/page.h>
 #include <asm/vdso.h>
 
-OUTPUT_FORMAT("elf32-s390", "elf32-s390", "elf32-s390")
 OUTPUT_ARCH(s390:31-bit)
 ENTRY(_start)
 
```
Then, after applying the same suggestions from @nathanchance , I hit the following errors:
```
$ echo 'CONFIG_BUG=n
CONFIG_DEBUG_INFO_BTF=n' >arch/s390/configs/lld.config
$ make -kj"$(nproc)" V=1 LD=/usr/bin/ld.lld lld.config bzImage
...
+ /usr/bin/ld.lld -z noexecstack -pie --build-id=sha1 -X --script=./arch/s390/kernel/vmlinux.lds --strip-debug
 -o .tmp_vmlinux.kallsyms1 --whole-archive vmlinux.a .vmlinux.export.o init/version-timestamp.o --no-whole-arc
hive --start-group --end-group
ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in .vmlinux.export.o
>>> referenced by .vmlinux.export.c
>>>               .vmlinux.export.o:(___ksymtab+system_state+0x8)

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in .vmlinux.export.o
>>> referenced by .vmlinux.export.c
>>>               .vmlinux.export.o:(___ksymtab+system_state+0x10)

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in .vmlinux.export.o
>>> referenced by .vmlinux.export.c
>>>               .vmlinux.export.o:(___ksymtab_gpl+static_key_initialized+0x8)
...
```

It looks like that `__KSYM_REF()` is indeed asking for an absolute address that is incompatible with a `-pie` executable.

I decided to try to confirm if vmlinux would link after removing the following line from `arch/s390/Makefile`:

```
LDFLAGS_vmlinux := -pie
```

The build progressed, but it hits another issue:
```
# LD      arch/s390/boot/vmlinux.syms
  /usr/bin/ld.lld -z noexecstack  --oformat elf64-s390 -e startup -T arch/s390/boot/vmlinux.lds arch/s390/boot/head.o arch/s390/boot/als.o arch/s390/boot/startup.o arch/s390/boot/physmem_info.o arch/s390/boot/ipl_parm.o arch/s390/boot/ipl_report.o arch/s390/boot/vmem.o arch/s390/boot/string.o arch/s390/boot/ebcdic.o arch/s390/boot/sclp_early_core.o arch/s390/boot/mem.o arch/s390/boot/ipl_vmparm.o arch/s390/boot/cmdline.o arch/s390/boot/version.o arch/s390/boot/pgm_check_info.o arch/s390/boot/ctype.o arch/s390/boot/ipl_data.o arch/s390/boot/machine_kexec_reloc.o arch/s390/boot/uv.o arch/s390/boot/kaslr.o arch/s390/boot/decompressor.o arch/s390/boot/info.o -o arch/s390/boot/vmlinux.syms
ld.lld: error: section .ipldata virtual address range overlaps with .head.text
>>> .ipldata range is [0x38, 0x237]
>>> .head.text range is [0x200, 0x102CF]

ld.lld: error: section .head.text virtual address range overlaps with .discard.addressable
>>> .head.text range is [0x200, 0x102CF]
>>> .discard.addressable range is [0x238, 0x307]
...
```

https://github.com/llvm/llvm-project/pull/75643


More information about the llvm-commits mailing list