Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppc64 pseries_defconfig ld.lld errors #602

Closed
nathanchance opened this issue Jul 17, 2019 · 17 comments
Closed

ppc64 pseries_defconfig ld.lld errors #602

nathanchance opened this issue Jul 17, 2019 · 17 comments
Labels
[ARCH] powerpc This bug impacts ARCH=powerpc [FIXED][LINUX] 6.5 This bug was fixed in Linux 6.5 [TOOL] lld The issue is relevant to LLD linker

Comments

@nathanchance
Copy link
Member

ld.lld: error: undefined symbol: .early_setup
>>> referenced by arch/powerpc/kernel/head_64.o:(.ref.text+0x72)

ld.lld: error: undefined symbol: .sys_restart_syscall
>>> referenced by kernel/systbl.o:(.rodata+0x0) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xD98) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_exit
>>> referenced by kernel/systbl.o:(.rodata+0x8) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDA0) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_read
>>> referenced by kernel/systbl.o:(.rodata+0x18) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDB0) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_write
>>> referenced by kernel/systbl.o:(.rodata+0x20) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDB8) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_open
>>> referenced by kernel/systbl.o:(.rodata+0x28) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_close
>>> referenced by kernel/systbl.o:(.rodata+0x30) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDC8) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_waitpid
>>> referenced by kernel/systbl.o:(.rodata+0x38) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDD0) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_creat
>>> referenced by kernel/systbl.o:(.rodata+0x40) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDD8) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_link
>>> referenced by kernel/systbl.o:(.rodata+0x48) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDE0) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_unlink
>>> referenced by kernel/systbl.o:(.rodata+0x50) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDE8) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_execve
>>> referenced by kernel/systbl.o:(.rodata+0x58) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_chdir
>>> referenced by kernel/systbl.o:(.rodata+0x60) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xDF8) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_time
>>> referenced by kernel/systbl.o:(.rodata+0x68) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_mknod
>>> referenced by kernel/systbl.o:(.rodata+0x70) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xE08) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_chmod
>>> referenced by kernel/systbl.o:(.rodata+0x78) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xE10) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_lchown
>>> referenced by kernel/systbl.o:(.rodata+0x80) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xE18) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_ni_syscall
>>> referenced by kernel/systbl.o:(.rodata+0x88) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0x90) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xB0) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xE0) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xF8) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0x100) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0x118) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0x160) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0x1A8) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0x1C0) in archive arch/powerpc/built-in.a
>>> referenced 123 more times

ld.lld: error: undefined symbol: .sys_lseek
>>> referenced by kernel/systbl.o:(.rodata+0x98) in archive arch/powerpc/built-in.a

ld.lld: error: undefined symbol: .sys_getpid
>>> referenced by kernel/systbl.o:(.rodata+0xA0) in archive arch/powerpc/built-in.a
>>> referenced by kernel/systbl.o:(.rodata+0xE38) in archive arch/powerpc/built-in.a

To reproduce (on current mainline or -next):

curl -LSs https://raw.githubusercontent.com/nathanchance/patches/ce2a9dd5db891946ecf94906e451554103d40b9e/linux/error-fixes/0003-powerpc-vdso32-Drop-mabi-elfv1-for-32-bit-objects.patch | git am

curl -LSs https://raw.githubusercontent.com/nathanchance/patches/ce2a9dd5db891946ecf94906e451554103d40b9e/linux/error-fixes/0004-powerpc-Kconfig-Don-t-enable-HAVE_FUNCTION_TRACER-on.patch | git am

make -j$(nproc) ARCH=powerpc CC=clang CROSS_COMPILE=powerpc-linux-gnu- LD=ld.lld O=out distclean pseries_defconfig vmlinux
@nathanchance nathanchance added [TOOL] lld The issue is relevant to LLD linker [ARCH] powerpc This bug impacts ARCH=powerpc labels Jul 17, 2019
@nickdesaulniers
Copy link
Member

What's special about these symbols that leads to LLD discarding them? Is there a linker script involved that LLD is not handling the same way as BFD?

@MaskRay
Copy link
Member

MaskRay commented Jul 31, 2019

This big-endian configuration doesn't work, even if ld.bfd is used:

# HEAD commit 4010b622f1d2a6112244101f38225eaee20c07f2 Tue Jul 30 17:32:46 2019 -0700
% curl -LSs https://raw.githubusercontent.com/nathanchance/patches/ce2a9dd5db891946ecf94906e451554103d40b9e/linux/error-fixes/0003-powerpc-vdso32-Drop-mabi-elfv1-for-32-bit-objects.patch | git am
% curl -LSs https://raw.githubusercontent.com/nathanchance/patches/ce2a9dd5db891946ecf94906e451554103d40b9e/linux/error-fixes/0004-powerpc-Kconfig-Don-t-enable-HAVE_FUNCTION_TRACER-on.patch | git am

# Install powerpc64-linux-gnu-gcc (big-endian)
% make -j"$(nproc)" ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu- HOSTCC=clang HOSTLD=ld.lld CC=clang LD=ld.lld O=out.ppc64 distclean pseries_defconfig vmlinux
... ld.lld: error: undefined symbol as noted above

% cd out.ppc64; /tmp/powerpc64/ld/ld-new -EB -m elf64ppc -Bstatic --orphan-handling=warn --build-id -o .tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive arch/powerpc/kernel/head_64.o arch/powerpc/kernel/entry_64.o arch/powerpc/kernel/fpu.o arch/powerpc/kernel/vector.o arch/powerpc/kernel/prom_init.o init/built-in.a usr/built-in.a arch/powerpc/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a block/built-in.a lib/built-in.a drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive --start-group lib/lib.a --end-group
/tmp/powerpc64/ld/ld-new: arch/powerpc/kernel/head_64.o .opd not allowed in ABI version 2
/tmp/powerpc64/ld/ld-new: arch/powerpc/kernel/head_64.o: error adding symbols: bad value

/tmp/powerpc64/ld/ld-new: arch/powerpc/kernel/head_64.o .opd not allowed in ABI version 2

.opd is some ELFv1 stuff.

@nathanchance
Copy link
Member Author

This is interesting... Building without LD=ld.lld works perfectly fine.

$ make -j"$(nproc)" ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- HOSTCC=clang HOSTLD=ld.lld CC=clang O=out.ppc64 V=1 distclean pseries_defconfig vmlinux

However, trying to link all of those files with ld.lld results in a similar set of errors:

$ ( cd out.ppc64; "${CBL_BIN}"/ld.lld -EB -m elf64ppc -Bstatic --orphan-handling=warn --build-id -o .tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive arch/powerpc/kernel/head_64.o arch/powerpc/kernel/entry_64.o arch/powerpc/kernel/fpu.o arch/powerpc/kernel/vector.o arch/powerpc/kernel/prom_init.o init/built-in.a usr/built-in.a arch/powerpc/built-in.a
 kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a block/built-in.a lib/built-in.a drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive --start-group lib/lib.a --end-group )
ld.lld: error: arch/powerpc/kernel/head_64.o: ABI version 1 is not supported
ld.lld: error: arch/powerpc/kernel/fpu.o: ABI version 1 is not supported
ld.lld: error: arch/powerpc/kernel/vector.o: ABI version 1 is not supported
ld.lld: error: init/built-in.a(main.o): ABI version 1 is not supported
ld.lld: error: init/built-in.a(do_mounts.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/cputable.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/irq.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/pmc.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/process.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/idle.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/sysfs.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/time.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/prom.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/traps.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/setup-common.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/misc.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/io.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/misc_64.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/setup_64.o): ABI version 1 is not supported
ld.lld: error: arch/powerpc/built-in.a(kernel/paca.o): ABI version 1 is not supported
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

Wonder what changes the ABI version.

@ihalip
Copy link

ihalip commented Aug 14, 2019

Wonder what changes the ABI version.

Took me a while to figure this out. TLDR: arch/powerpc/Makefile uses ELFv1 ABI for PPC64 & big endian. Since this is not supported by lld, would it be ok to just exit early in the build process with a message clarifying that?

@nathanchance
Copy link
Member Author

I don't know that we need a build error for this right out the gate since as far as I am aware, I am the only one who has tried this :)

If there isn't support in ld.lld for elfv1, I think we can just close this as it is a moot point.

@nathanchance
Copy link
Member Author

I sent CONFIG_LD_IS_LLD to deal with #785.

With that patch, we could tackle this issue using something like this:

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index f310c32e88a4..97af461e8b8e 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -143,7 +143,13 @@ endif
 endif

 CFLAGS-$(CONFIG_PPC64) := $(call cc-option,-mtraceback=no)
-ifndef CONFIG_CC_IS_CLANG
+ifdef CONFIG_CC_IS_CLANG
+ifdef CONFIG_LD_IS_LLD
+ifdef CONFIG_CPU_BIG_ENDIAN
+$(error ld.lld does not support PowerPC big endian due to lack of elfv1 support)
+endif
+endif
+else
 ifdef CONFIG_CPU_LITTLE_ENDIAN
 CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2,$(call cc-option,-mcall-aixdesc))
 AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2)

@MaskRay
Copy link
Member

MaskRay commented Apr 19, 2020

+ifdef CONFIG_CC_IS_CLANG

I guess CONFIG_CC_IS_CLANG is not needed.

@nathanchance
Copy link
Member Author

Yes, fair point :)

If I end up sending that along, I'll add it.

nathanchance pushed a commit that referenced this issue Jun 26, 2020
In the datapath, the ip6gre_tunnel_lookup() is used and it internally uses
fallback tunnel device pointer, which is fb_tunnel_dev.
This pointer variable should be set to NULL when a fb interface is deleted.
But there is no routine to set fb_tunnel_dev pointer to NULL.
So, this pointer will be still used after interface is deleted and
it eventually results in the use-after-free problem.

Test commands:
    ip netns add A
    ip netns add B
    ip link add eth0 type veth peer name eth1
    ip link set eth0 netns A
    ip link set eth1 netns B

    ip netns exec A ip link set lo up
    ip netns exec A ip link set eth0 up
    ip netns exec A ip link add ip6gre1 type ip6gre local fc:0::1 \
	    remote fc:0::2
    ip netns exec A ip -6 a a fc:100::1/64 dev ip6gre1
    ip netns exec A ip link set ip6gre1 up
    ip netns exec A ip -6 a a fc:0::1/64 dev eth0
    ip netns exec A ip link set ip6gre0 up

    ip netns exec B ip link set lo up
    ip netns exec B ip link set eth1 up
    ip netns exec B ip link add ip6gre1 type ip6gre local fc:0::2 \
	    remote fc:0::1
    ip netns exec B ip -6 a a fc:100::2/64 dev ip6gre1
    ip netns exec B ip link set ip6gre1 up
    ip netns exec B ip -6 a a fc:0::2/64 dev eth1
    ip netns exec B ip link set ip6gre0 up
    ip netns exec A ping fc:100::2 -s 60000 &
    ip netns del B

Splat looks like:
[   73.087285][    C1] BUG: KASAN: use-after-free in ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.088361][    C1] Read of size 4 at addr ffff888040559218 by task ping/1429
[   73.089317][    C1]
[   73.089638][    C1] CPU: 1 PID: 1429 Comm: ping Not tainted 5.7.0+ #602
[   73.090531][    C1] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[   73.091725][    C1] Call Trace:
[   73.092160][    C1]  <IRQ>
[   73.092556][    C1]  dump_stack+0x96/0xdb
[   73.093122][    C1]  print_address_description.constprop.6+0x2cc/0x450
[   73.094016][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.094894][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.095767][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.096619][    C1]  kasan_report+0x154/0x190
[   73.097209][    C1]  ? ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.097989][    C1]  ip6gre_tunnel_lookup+0x1064/0x13f0 [ip6_gre]
[   73.098750][    C1]  ? gre_del_protocol+0x60/0x60 [gre]
[   73.099500][    C1]  gre_rcv+0x1c5/0x1450 [ip6_gre]
[   73.100199][    C1]  ? ip6gre_header+0xf00/0xf00 [ip6_gre]
[   73.100985][    C1]  ? rcu_read_lock_sched_held+0xc0/0xc0
[   73.101830][    C1]  ? ip6_input_finish+0x5/0xf0
[   73.102483][    C1]  ip6_protocol_deliver_rcu+0xcbb/0x1510
[   73.103296][    C1]  ip6_input_finish+0x5b/0xf0
[   73.103920][    C1]  ip6_input+0xcd/0x2c0
[   73.104473][    C1]  ? ip6_input_finish+0xf0/0xf0
[   73.105115][    C1]  ? rcu_read_lock_held+0x90/0xa0
[   73.105783][    C1]  ? rcu_read_lock_sched_held+0xc0/0xc0
[   73.106548][    C1]  ipv6_rcv+0x1f1/0x300
[ ... ]

Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Fixes: c12b395 ("gre: Support GRE over IPv6")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
@MaskRay
Copy link
Member

MaskRay commented Jan 31, 2021

@q66 told me that @leahneukirchen has a patch to drop ELFv1 legacy from arch/powerpc/Makefile. It is simplification on its own (likely upstreamable) and can potentially help ld.lld https://github.com/void-linux/void-packages/blob/master/srcpkgs/linux5.10/patches/ppc64-be-elfv2.patch

@q66
Copy link

q66 commented Jan 31, 2021

that's my patch, @leahneukirchen just pulled it in from the previous patches for a previous kernel

@MaskRay
Copy link
Member

MaskRay commented Jan 31, 2021

Thanks for clarification!

https://www.kernel.org/doc/html/latest/process/changes.html requires GCC 4.9. GCC gained support for -mabi=elfv2 in 2013. Perhaps we can make -mabi=elfv2 unconditional and entirely drop -mcall-aixdesc (not supported by Clang as of 12.0.0).

@q66
Copy link

q66 commented Jan 31, 2021

the patch should still fall back to ELFv1 and -mcall-aixdesc as it is when the support is not available

there were efforts upstream to add the ELFv2 option previously, first one some years back (which got abandoned later) and IIRC there's a second one that was under review just recently (not sure what became of it)

@nickdesaulniers
Copy link
Member

@q66 was there a thread for the upstream discussions that you can link to? This is still reproducible with ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make CC=clang LD=ld.lld -j71 pseries_defconfig all; we may want to send a revised version of @nathanchance 's patch for now.

@nathanchance
Copy link
Member Author

nathanchance commented Oct 29, 2021

Big endian ELFv2 support was sent upstream but the commit message of the second patch in the series mentions that LLVM did not receive testing so it was restricted to GCC and binutils in Kconfig: https://lore.kernel.org/r/20210611093959.821525-1-npiggin@gmail.com/

It does not look like it was ever picked up.

@nickdesaulniers
Copy link
Member

@q66 told me that @leahneukirchen has a patch to drop ELFv1 legacy from arch/powerpc/Makefile. It is simplification on its own (likely upstreamable) and can potentially help ld.lld https://github.com/void-linux/void-packages/blob/master/srcpkgs/linux5.10/patches/ppc64-be-elfv2.patch

We should ask @mpe on the list whether big endian could be moved to ELFv2 (via that patch).

@nathanchance found https://lore.kernel.org/all/20210611093959.821525-1-npiggin@gmail.com/, but mentioned that there's some Kconfig changes we need to make+test. @nathanchance can you provide more info?

@mandlebug mentioned that FreeBSD switched their BE ppc64 build to ELFv2.

@nickdesaulniers
Copy link
Member

https://lore.kernel.org/all/20210611093959.821525-3-npiggin@gmail.com/ mentions:

although it is rumored to work with clang
that's not been tested yet.

Let's hop on that thread and help test.

@nathanchance
Copy link
Member Author

This should not be visible in mainline after https://git.kernel.org/linus/9d90161ca5c7234e80e14e563d198f322ca0c1d0. Closing this up for now.

@nathanchance nathanchance added [FIXED][LINUX] 6.5 This bug was fixed in Linux 6.5 and removed low priority This bug is not critical and not a priority labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ARCH] powerpc This bug impacts ARCH=powerpc [FIXED][LINUX] 6.5 This bug was fixed in Linux 6.5 [TOOL] lld The issue is relevant to LLD linker
Projects
None yet
Development

No branches or pull requests

5 participants