Support "Sun Style" syntax for section switching ("#alloc,#write" etc).
https://bugs.llvm.org/show_bug.cgi?id=43759
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
- Build Status
Buildable 40139 Build 40230: arc lint + arc unit
Event Timeline
I can see that this would allow "Sun Style" syntax for section switching that seems to be permitted for the Arm target. The question is why, and why just Arm? Looking at the GNU as code it looks like:
- This syntax was supported for Solaris, it only has tests for Solaris
- The syntax isn't gated by target, but it doesn't work on any target that uses # as the comment character (x86), it fails with a cryptic error message, this suggests it works on Arm and AArch64 by accident rather than by intention.
- The comment in MCAsmInfo.h states "instead of the normal ELF syntax", looking at the implementation it seems like both can be used at once as there isn't a parsing difference, however this might not be by design.
/// This is true if this target uses "Sun Style" syntax for section switching /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in /// .section directives. Defaults to false. bool SunStyleELFSectionSwitchSyntax = false;
So at the moment, I'm not convinced that doing this just for Arm and leaving the existing comment in MCAsmInfo.h in place is the right thing to do. If this is being done to be compatible with GNU, and for a good reason, then it should work on all targets that it works in GNU as and not just Arm.
I agree, and it seems GNU assembler supports both on arm so I have updated the comments on MCAsmInfo.h.
/// This is true if this target uses "Sun Style" syntax for section switching /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in /// .section directives. Defaults to false. bool SunStyleELFSectionSwitchSyntax = false;So at the moment, I'm not convinced that doing this just for Arm and leaving the existing comment in MCAsmInfo.h in place is the right thing to do. If this is being done to be compatible with GNU, and for a good reason, then it should work on all targets that it works in GNU as and not just Arm.
This is part of the effort to build Linux kernel with integrated assembler for 32-bit Arm (https://github.com/ClangBuiltLinux/linux/issues/744). Some assembly files are written with this syntax in the kernel, e.g. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/mm/proc-v7.S?h=v5.4-rc4. I only ran into this issue on Arm so far and by grepping for #alloc I only found such syntax used for arm, sparc (SunStyleELFSectionSwitchSyntax already set to true), m68k and nds32 use such syntax. I am not sure if anyone is actually building m68k or nds32 with integrated assembler so that is why I only tried to turn it on for Arm.
Thanks for the context. I managed to find: https://lists.gt.net/linux/kernel/352032?do=post_view_threaded which asked about the difference in section syntax used in the kernel. The view at the time 2003 was that the forms where equivalent but there wasn't a firm preference. I've found a few other instances in other projects, although I've not got a large corpus of code to search through, the one's I've found are: Xen and CMSIS for low level driver code.
I think that this qualifies the use of the Solaris form as rare, but not insubstantial. On that basis I'm inclined to approve, does anyone else have any strong counter arguments?
llvm/include/llvm/MC/MCAsmInfo.h | ||
---|---|---|
218 ↗ | (On Diff #226096) | nit: I'd use "alongside" rather than "along" here. |
llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp | ||
78 ↗ | (On Diff #226096) | nit: one blank line would match the style of the rest of the file. |
80 ↗ | (On Diff #226096) | Although SunStyleELFSectionSwitchSyntax comes under the section Data Emission Directives, I think that is a mistake in MCAsmInfo, as a Data Emission Directive is something like .word. I suggest a comment like: |
Thanks for the update. Looks good to me. Please can you apply the formatting change to the comment (80 columns) prior to commit.
llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp | ||
---|---|---|
79 ↗ | (On Diff #226287) | Can you break this comment into two lines so that it doesn't go over 80 columns? (https://llvm.org/docs/CodingStandards.html#source-code-width) |
llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp | ||
---|---|---|
79 ↗ | (On Diff #226287) | Or in vim: shift+v to highlight visual lines of comments, then gqgq to rewrap lines. May require set cc=80. |
llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp | ||
---|---|---|
79 ↗ | (On Diff #226287) | Thanks all for the comments. |
This breaks tests everywhere, see eg http://45.33.8.238/linux/2607/step_6.txt
Please take a look and revert if it takes a while to fix.
And please always watch http://lab.llvm.org:8011/console for a bit after landing.
Sorry about the breakage. I have reverted the commit. Will reland once I fix it.
Thanks much for the revert!
Going forward, when reverting things, please say in the revert commit message _why_ you're reverting (e.g. "breaks bots, see original review", or "breaks CodeGen/cfstring3.c on most bots", or similar) :)
Right now once we toggle SunStyleELFSectionSwitchSyntax on an architecture, all the section switching assembly is emitted on sun-style syntax, which is the reason why some test cases fail as they assume the regular syntax. To deal with this issue, I introduced a new variable that would allow the architecture to parse sun-style assembly while not emitting it.
@nickdesaulniers Maybe we should fix kernel instead? The fix will be cleaner that way.
The original patch looks fine because the SunStyleELFSectionSwitchSyntax functionality is already there. Now we start to add IsCompatibleWithSunStyleELFSectionSwitchSyntax... Have we communicated the Solaris assembler's .section syntax problem to the Linux community?
Linux has been patched by to use normal section switching syntax https://lkml.org/lkml/2019/10/30/807. Abandon this LLVM patch as we should be fine without it.
From my viewpoint of reducing maintenance burden, thanks! I am not clear about the Linux kernel development model but I think we cannot say "Linux has been patched" yet because the patch sent by nickdesaulniers has not been merged into the mainline kernel :) (Though I think it is promising.)