[lld] [lld] Add target support for SystemZ (s390x) (PR #75643)
Nathan Chancellor via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 08:22:09 PST 2024
nathanchance wrote:
> I see, that appears to be an endian bug in the kernel makefiles:
>
> ```
> + # Change e_type to ET_REL so that it can be used to link final vmlinux.
> + # Unlike GNU ld, lld does not allow an ET_EXEC input.
> + printf '\1' | dd of=${2} conv=notrunc bs=1 seek=16 status=none
> ```
>
> introduced here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
>
> On a big-endian platform, instead of changing `e_type` from 0x03 to 0x01, this command changes it to 0x0103.
Well that's subtle... I guess we have not done any testing of `CONFIG_DEBUG_INFO_BTF` with big endian platforms and `ld.lld`. I think this diff should work though?
```diff
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index a432b171be82..8a9f48b3cb32 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -135,8 +135,15 @@ gen_btf()
${OBJCOPY} --only-section=.BTF --set-section-flags .BTF=alloc,readonly \
--strip-all ${1} ${2} 2>/dev/null
# Change e_type to ET_REL so that it can be used to link final vmlinux.
- # Unlike GNU ld, lld does not allow an ET_EXEC input.
- printf '\1' | dd of=${2} conv=notrunc bs=1 seek=16 status=none
+ # Unlike GNU ld, lld does not allow an ET_EXEC input. Make sure the correct
+ # byte gets changed with big endian platforms, otherwise e_type may be an
+ # invalid value.
+ if is_enabled CONFIG_CPU_BIG_ENDIAN; then
+ seek=17
+ else
+ seek=16
+ fi
+ printf '\1' | dd of=${2} conv=notrunc bs=1 seek=${seek} status=none
}
# Create ${2} .S file with all symbols from the ${1} object file
```
which results in the correct byte getting changed now.
```diff
diff --git a/tmp/.psub.TP3W7Zgscj b/tmp/.psub.lTsWusS61t
index 3ae242145876..3004259d1368 100644
--- a/tmp/.psub.TP3W7Zgscj
+++ b/tmp/.psub.lTsWusS61t
@@ -1,3 +1,3 @@
00000000 7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00 |.ELF............|
-00000010 00 03 00 16 00 00 00 01 00 00 00 00 00 10 00 00 |................|
+00000010 00 01 00 16 00 00 00 01 00 00 00 00 00 10 00 00 |................|
00000020
```
I will send it along later today.
https://github.com/llvm/llvm-project/pull/75643
More information about the llvm-commits
mailing list