From: Joel Stanley <joel@jms.id.au> Date: 2018-09-10 08:57:24
Two fixes to get us closer to building with clang. With a one patch[1]
on top of clang master I can build and boot a powernv kernel:
$ make ARCH=powerpc powernv_defconfig
$ ./scripts/config -e PPC_DISABLE_WERROR -d FTRACE -d BTRFS_FS -d MD_RAID456
$ make CC=/scratch/joel/llvm-build/bin/clang-8 CLANG_TRIPLE=powerpc64le-linux-gnu -j128
$ qemu-system-ppc64 -M powernv -m 3G -nographic -kernel zImage.epapr \
-L ~/skiboot/ -initrd ~/rootfs.cpio.xz
Linux version 4.19.0-rc3-00003-g728b25f26bce (joel@ozrom3) (clang version 8.0.0 (trunk 341773)) #12 SMP Mon Sep 10 17:32:05 ACST 2018
The DISABLE_WERROR is due to clang's -Wduplicate-decl-specifier. Some
macros we have in arch/powerpc/include/asm/uaccess.h warn on 'const
typeof(var)', where as the GCC version doesn't. Anton did fix this a
while ago, but the fix was 'reverted' to resolve some sparse warnings.
I think we should re-apply Anton's patch[2].
[1] https://reviews.llvm.org/D50965
[2] http://git.kernel.org/torvalds/c/b91c1e3e7a6f22a6b898e345b745b6a43273c973
Joel Stanley (2):
powerpc/boot: Fix crt0.S syntax for clang
powerpc/boot: Ensure _zimage_start is a weak symbol
arch/powerpc/boot/crt0.S | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--
2.17.1
From: Joel Stanley <joel@jms.id.au> Date: 2018-09-10 08:57:30
Clang's assembler does not like the syntax of the cmpdi:
arch/powerpc/boot/crt0.S:168:22: error: unexpected modifier on variable reference
cmpdi 12,RELACOUNT@l
^
arch/powerpc/boot/crt0.S:168:11: error: unknown operand
cmpdi 12,RELACOUNT@l
^
Enclosing RELACOUNT in () makes it is happy. Tested with GCC 8 and Clang
8 (trunk).
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
arch/powerpc/boot/crt0.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Joel Stanley <joel@jms.id.au> Date: 2018-09-10 08:57:36
When building with clang crt0's _zimage_start is not marked weak, which
breaks the build when linking the kernel image:
$ objdump -t arch/powerpc/boot/crt0.o |grep _zimage_start$
0000000000000058 g .text 0000000000000000 _zimage_start
ld: arch/powerpc/boot/wrapper.a(crt0.o): in function '_zimage_start':
(.text+0x58): multiple definition of '_zimage_start';
arch/powerpc/boot/pseries-head.o:(.text+0x0): first defined here
Clang requires the .weak directive to appear after the symbol is
declared. The binutils manual says:
This directive sets the weak attribute on the comma separated list of
symbol names. If the symbols do not already exist, they will be
created.
So it appears this is different with clang. The only reference I could
see for this was an OpenBSD mailing list post[1].
Changing it to be after the declaration fixes building with Clang, and
still works with GCC.
$ objdump -t arch/powerpc/boot/crt0.o |grep _zimage_start$
0000000000000058 w .text 0000000000000000 _zimage_start
[1] https://groups.google.com/forum/#!topic/fa.openbsd.tech/PAgKKen2YCY
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
arch/powerpc/boot/crt0.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
On Mon, Sep 10, 2018 at 06:57:13PM +1000, Joel Stanley wrote:
Clang's assembler does not like the syntax of the cmpdi:
arch/powerpc/boot/crt0.S:168:22: error: unexpected modifier on variable reference
cmpdi 12,RELACOUNT@l
^
arch/powerpc/boot/crt0.S:168:11: error: unknown operand
cmpdi 12,RELACOUNT@l
^
Enclosing RELACOUNT in () makes it is happy. Tested with GCC 8 and Clang
8 (trunk).
Is clang going to fix this? You also might want to add a comment that
this is a workaround for that broken assembler.
Segher
From: Joel Stanley <joel@jms.id.au> Date: 2018-09-14 02:55:15
On Tue, 11 Sep 2018 at 21:02, Segher Boessenkool
[off-list ref] wrote:
On Mon, Sep 10, 2018 at 06:57:13PM +1000, Joel Stanley wrote:
quoted
Clang's assembler does not like the syntax of the cmpdi:
arch/powerpc/boot/crt0.S:168:22: error: unexpected modifier on variable reference
cmpdi 12,RELACOUNT@l
^
arch/powerpc/boot/crt0.S:168:11: error: unknown operand
cmpdi 12,RELACOUNT@l
^
Enclosing RELACOUNT in () makes it is happy. Tested with GCC 8 and Clang
8 (trunk).
Is clang going to fix this? You also might want to add a comment that
this is a workaround for that broken assembler.
I am not sure that we need a comment, it doesn't look too out of place
compared to the other uses of wrapping symbols in ().
I did open a bug against clang though in the hope that they can fix
the behaviour:
https://bugs.llvm.org/show_bug.cgi?id=38945
Cheers,
Joel