This is an archive of the discontinued LLVM Phabricator instance.

[AsmParser] handle .align 0 per MCAsmInfo
AbandonedPublic

Authored by nickdesaulniers on Sep 28 2021, 2:36 PM.

Details

Summary

While .align 0 may be converted to .balign 1 for x86_64 elf, on THUMB2
it's converted to .balign 4.

pr/51929.
Link: https://github.com/ClangBuiltLinux/linux/issues/1447

Diff Detail

Event Timeline

nickdesaulniers requested review of this revision.Sep 28 2021, 2:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2021, 2:36 PM
nickdesaulniers planned changes to this revision.Sep 28 2021, 2:39 PM

Hey @peter.smith , I'm not sure if you have cycles to look at this, but I could use some help. I've been trying to understand why the fragments created seem to have an offset of zero (I suspect the offset should be 2B into the function?) but I don't quite understand the fragment layout process very well. The added test case is failing on the Size: check; GAS passes this test.

craig.topper added inline comments.
llvm/include/llvm/MC/MCAsmInfo.h
861

Why not make Alignment a reference?

llvm/include/llvm/MC/MCAsmInfo.h
861

It's been beaten into my head the Google C++ coding style where in/out params are passed by pointer, so that it's obvious at the call site that they're being modified since their address must be taken. If this is explicitly not the LLVM style guide, I'm happy to change it to a non-const reference.

(The Google C++ coding style recommends const-reference params or pointer params; for in vs in-out params).

ARMAsmParser::parseDirectiveAlign falls back to AsmParser::parseDirectiveAlign, which doesn't handle .align 0 correctly for THUMB.

(oh, this is actually good enough to fix pr/51929). Maybe I can add a fixme to the test on the Size noting that GAS adds explicit nops. We don't necessarily need the nops; we need to not treat .align 0 as .align 1 on THUMB2 (and probably ARM; unverified).

(oh, this is actually good enough to fix pr/51929). Maybe I can add a fixme to the test on the Size noting that GAS adds explicit nops. We don't necessarily need the nops; we need to not treat .align 0 as .align 1 on THUMB2 (and probably ARM; unverified).

Is this an issue for RISCV too?

(oh, this is actually good enough to fix pr/51929). Maybe I can add a fixme to the test on the Size noting that GAS adds explicit nops. We don't necessarily need the nops; we need to not treat .align 0 as .align 1 on THUMB2 (and probably ARM; unverified).

Is this an issue for RISCV too?

Nevermind, after poking around I see this is a specific to ARM in gas.

llvm/test/MC/ARM/thumb-text-align0.s
9
mov r0, r1
.align 0
mov pc, lr

would be a more demonstrative test.

nickdesaulniers retitled this revision from [WIP][AsmParser] handle .align 0 per MCAsmInfo to [AsmParser] handle .align 0 per MCAsmInfo.
nickdesaulniers edited the summary of this revision. (Show Details)
  • rewrite tests
nickdesaulniers edited the summary of this revision. (Show Details)Sep 28 2021, 6:10 PM
nickdesaulniers added a reviewer: pengfei.

While .align 0 may be converted to .balign 1 for x86_64 elf, on THUMB2 it's converted to .balign 4.

Does gas do so? This is a surprising behavior. I hope we don't follow. The user should be fixed instead.

https://sourceware.org/binutils/docs/as/Align.html#Align says a default value is used. If thumb typically uses 2-byte alignment, .align 0 meaning .balign 4 seems unexpected.

I really don't want to see that MC adopts such a behavior.

I will disappear for a few days and be back next ~Wednesday.

I don't disagree. It looks like the 32b ARM linux kernel is using .align 0 by default for all symbol descriptions; I think changing it to .align 2 (to match aarch64) would be NFC for GAS and fix the underlying THUMB2 related boot failure for clang. Let me submit such a patch on the kernel side for comment+review. Thanks for the feedback.

nickdesaulniers abandoned this revision.Sep 29 2021, 11:04 AM