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

Nathan Chancellor via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 19:17:20 PST 2024


nathanchance wrote:

I have sent the patch to remove `-fPIC` from the s390 vDSO build:

https://lore.kernel.org/20240130-s390-vdso-drop-fpic-from-ldflags-v1-1-094ad104fc55@kernel.org/

I have worked around the other reported issue above with `__bug_table` by just disabling `CONFIG_BUG`, to see if I could get a working image otherwise.

Unfortunately, I immediately hit an issue that appears to be related to `-mrecord-mcount`, as it occurs in the `__mcount_loc` section. There are several errors, I've included a few.

```
$ echo CONFIG_BUG=n >arch/s390/configs/lld.config

$ make -skj"$(nproc)" ARCH=s390 LLVM=1 OBJCOPY=s390x-linux-gnu-objcopy OBJDUMP=s390x-linux-gnu-objdump mrproper defconfig lld.config bzImage
...
ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in vmlinux.a(arch/s390/kernel/cpufeature.o)
>>> referenced by cpufeature.c
>>>               arch/s390/kernel/cpufeature.o:(__mcount_loc+0x0) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in vmlinux.a(init/version.o)
>>> referenced by version.c
>>>               init/version.o:(__mcount_loc+0x0) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in vmlinux.a(arch/s390/kernel/dis.o)
>>> referenced by dis.c
>>>               arch/s390/kernel/dis.o:(__mcount_loc+0x0) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in vmlinux.a(arch/s390/kernel/dis.o)
>>> referenced by dis.c
>>>               arch/s390/kernel/dis.o:(__mcount_loc+0x8) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in vmlinux.a(arch/s390/kernel/dis.o)
>>> referenced by dis.c
>>>               arch/s390/kernel/dis.o:(__mcount_loc+0x10) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against local symbol; recompile with -fPIC
>>> defined in vmlinux.a(arch/s390/kernel/dis.o)
>>> referenced by dis.c
>>>               arch/s390/kernel/dis.o:(__mcount_loc+0x18) in archive vmlinux.a
...
```

Working around that by turning off the configurations that add `-mrecord-mcount` leads us to a similar issue but this time with the kernel's automatically generated syscall tables.

```
$ echo 'CONFIG_FUNCTION_TRACER=n
CONFIG_STACK_TRACER' >>arch/s390/configs/lld.config

$ make -skj"$(nproc)" ARCH=s390 LLVM=1 OBJCOPY=s390x-linux-gnu-objcopy OBJDUMP=s390x-linux-gnu-objdump mrproper defconfig lld.config bzImage
...
ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_ni_syscall'; recompile with -fPIC
>>> defined in vmlinux.a(arch/s390/kernel/syscall.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_exit'; recompile with -fPIC
>>> defined in vmlinux.a(kernel/exit.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_fork'; recompile with -fPIC
>>> defined in vmlinux.a(kernel/fork.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_read'; recompile with -fPIC
>>> defined in vmlinux.a(fs/read_write.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_write'; recompile with -fPIC
>>> defined in vmlinux.a(fs/read_write.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_open'; recompile with -fPIC
>>> defined in vmlinux.a(fs/open.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a

ld.lld: error: relocation R_390_64 cannot be used against symbol '__s390x_sys_close'; recompile with -fPIC
>>> defined in vmlinux.a(fs/open.o)
>>> referenced by arch/s390/kernel/entry.o:(sys_call_table) in archive vmlinux.a
...
```

Perhaps it is possible that the kernel should be compiled with `-fPIC`, it is built with `-fPIE` right now. Otherwise, maybe there is some missing compatibility with `ld.bfd`? 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.

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


More information about the llvm-commits mailing list