/usr/local/google/home/jiancai/storage/llvm-project/build/release/bin/clang -Wp,-MD,arch/arm/kernel/.sleep.o.d -nostdinc -isystem /media/storage/jiancai/llvm-project/build/release/lib/clang/11.0.0/include -I./arch/arm/include -I./arch/arm/include/generated -I./include -I./arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Qunused-arguments -D__ASSEMBLY__ -fno-PIE --target=arm-linux-gnueabihf --prefix=/usr/bin/ --gcc-toolchain=/usr -Werror=unknown-warning-option -mabi=aapcs-linux -mfpu=vfp -funwind-tables -meabi gnu -marm -Wa,-W -D__LINUX_ARM_ARCH__=7 -march=armv7-a -include asm/unified.h -msoft-float -c -o arch/arm/kernel/sleep.o arch/arm/kernel/sleep.S
arch/arm/kernel/sleep.S:149:20: error: invalid reassignment of non-absolute variable 'up_b_offset' in '.equ' directive
.equ up_b_offset, 1f - 9998b ; .pushsection ".alt.smp.init", "a" ; .long 9998b ; b . + up_b_offset ; .popsection
Was able to reduce it to the following code
$ cat repro.s
0:
.equ x, 1f - 0b ;
b . + x ;
1:
$ arm-linux-gnueabihf-gcc -nostdinc -I./arch/arm/include -I./arch/arm/include/generated -I./include -I./arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -D__ASSEMBLY__ -fno-PIE --prefix=/usr/bin/ -Werror=unknown-warning-option -mabi=aapcs-linux -mfpu=vfp -funwind-tables -marm -Wa,-W -D__LINUX_ARM_ARCH__=7 -march=armv7-a -include asm/unified.h -msoft-float -c repro.s
$ echo $?
0
$ llvm-mc -triple armv7a-linux-gnueabihf repro.s -filetype=obj -o /dev/null
repro.s:5:9: error: invalid reassignment of non-absolute variable 'x' in '.equ' directive
.equ x, 0xff ;
Reproduced on x86
$ cat repro.s
0:
.equ x, 1f - 0b ;
jmp . + x ;
1:
.equ x, 0xff ;
$ gcc -c repro.s
$ echo $?
0
$ c
llvm-mc -triple i386 repro.s -filetype=obj -o /dev/null
repro.s:5:9: error: invalid reassignment of non-absolute variable 'x' in '.equ' directive
.equ x, 0xff ;
Fixing this issue in LLVM seems to be more complicated than I thought. Currently .equ requires the old value of a variable to be constant. In the case of the reproducer, the value of x is an expression (1f - 0b) when the second .equ happens, which triggers the assertion. I tried to disable this assert and one more to let the assembling finish, but ended up with unexpected output.
gcc:
Disassembly of section .text:
0000000000000000 <.text>:
0: eb 00 jmp 2
2: 8b 04 25 ff 00 00 00 mov 0xff,%eax
clang with my local change:
Disassembly of section .text:
00000000 <.text>:
0: e9 fa 00 00 00 jmp ff
5: a1 ff 00 00 00 mov 0xff,%eax
It seems the integrated assembler (with my local changes) replaced all the uses of x with its last definition, including the use before it. Will file an upstream bug and see if someone with more expertise can provide more insight for a fix on LLVM. Meanwhile, up_b_offset only has one use, so it may be easier to fix the issue on Linux kernel as follows,
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 99929122dad7..a2138980d97b 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -269,10 +269,9 @@
.endif ;\
.popsection
#define ALT_UP_B(label) \
- .equ up_b_offset, label - 9998b ;\
.pushsection ".alt.smp.init", "a" ;\
.long 9998b ;\
- W(b) . + up_b_offset ;\
+ W(b) . + (label - 9998b) ;\
@nickdesaulniers WDYT?
upstream bug filed: https://bugs.llvm.org/show_bug.cgi?id=45248
So the arm tree (arch/arm/) has a different system for submitting patches. I'd wait a week for feedback once submitting a patch to the list. Then I'd collect the reviewed by or tested by tags and submit to: https://www.armlinux.org.uk/developer/patches/
@jcai19 you should go and make an account there. I can walk you through the rest.
@jcai19 you should go and make an account there. I can walk you through the rest.
Will do. Thanks for reviewing this patch.
Thank @nickdesaulniers and @agners for reviewing the patch. I tried to register on https://www.armlinux.org.uk/developer/patches/ to send the patch with reviewed-by tags. The registration seemed to go through as I could not register my email again, but I never received any emails. I tried several times to request password reseting over the last a few days but did not receive any emails either. Double checked my spam folder and nothing was there. Any idea on what I might have missed here? Thanks.
I shot a quick mail to Russell who I believe maintains that patch tracker. Hopefully he can help sort it out.
Thanks for the help!
So I've successfully created my account on https://www.armlinux.org.uk/developer/patches/. Is "Sending in a patch" section of https://www.armlinux.org.uk/developer/patches/ the right steps to follow to submit the patch? Thanks.
Yep, sign in there, click Add new patch.
For Summary put the initial line of the commit message
For Kernel Version, put the tag of the tree you generated the diff from. For example, if you used "mainline" kernel tree (Linus' tree), you'd put v5.7-rc3 (or whatever the latest git tag existed when you wrote the patch). If you used linux-next, you'd put next-20200428 (or whatever the latest `git tag existed when you wrote the patch). This info will help Russell resolve any conflicts.
For Patch notes: put the rest of the commit message excluding the first line
Then attach the patch file, and click Submit patch.
After some time, your patch should show up in "Incoming" https://www.armlinux.org.uk/developer/patches/section.php?section=0
Eventually, it will be moved to either accepted or rejected. If accepted, it will eventually show up in linux-next, and eventually become a pull request to Linus from Russell.
Note: all of this is only for arm32 specific patches that the arm32 maintainers should accept.
Thank you for the clarification! I will follow the instructions and submit the patch ASAP.
Patch submitted at https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=8971/1
Is that your first Linux kernel patch @jcai19 ?
Yes it is :)
reopening until this hits mainline.