-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Warn on align directive with non-zero fill value in virtual sections #66792
Conversation
This patch warns when an align directive with a non-zero fill value is used in a virtual section. The fill value is also set to zero, preventing an assertion in MCAssembler::writeSectionData for the case of MCFragment::FT_Align from tripping.
@llvm/pr-subscribers-mc ChangesThis patch warns when an align directive with a non-zero fill value is Full diff: https://github.com/llvm/llvm-project/pull/66792.diff 2 Files Affected:
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index f70620c15a7ebb7..15ba96b84fa4701 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3392,6 +3392,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
bool HasFillExpr = false;
int64_t FillExpr = 0;
int64_t MaxBytesToFill = 0;
+ SMLoc FillExprLoc;
auto parseAlign = [&]() -> bool {
if (parseAbsoluteExpression(Alignment))
@@ -3402,7 +3403,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
// .align 3,,4
if (getTok().isNot(AsmToken::Comma)) {
HasFillExpr = true;
- if (parseAbsoluteExpression(FillExpr))
+ if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
return true;
}
if (parseOptionalToken(AsmToken::Comma))
@@ -3451,6 +3452,17 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
}
}
+ if (HasFillExpr) {
+ MCSection *Sec = getStreamer().getCurrentSectionOnly();
+ if (Sec && Sec->isVirtualSection()) {
+ ReturnVal |=
+ Warning(FillExprLoc, "ignoring non-zero fill value in " +
+ Sec->getVirtualSectionKind() + " section '" +
+ Sec->getName() + "'");
+ FillExpr = 0;
+ }
+ }
+
// Diagnose non-sensical max bytes to align.
if (MaxBytesLoc.isValid()) {
if (MaxBytesToFill < 1) {
diff --git a/llvm/test/MC/ELF/nobits-non-zero-value.s b/llvm/test/MC/ELF/nobits-non-zero-value.s
index 16d386dc62ad549..8f37a957b6b56c0 100644
--- a/llvm/test/MC/ELF/nobits-non-zero-value.s
+++ b/llvm/test/MC/ELF/nobits-non-zero-value.s
@@ -12,5 +12,8 @@
# CHECK: {{.*}}.s:[[#@LINE+1]]:3: error: SHT_NOBITS section '.bss' cannot have instructions
addb %al,(%rax)
+# CHECK: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss'
+.align 4, 42
+
# CHECK: <unknown>:0: error: SHT_NOBITS section '.bss' cannot have non-zero initializers
.long 1
|
@@ -12,5 +12,8 @@ | |||
# CHECK: {{.*}}.s:[[#@LINE+1]]:3: error: SHT_NOBITS section '.bss' cannot have instructions | |||
addb %al,(%rax) | |||
|
|||
# CHECK: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss' | |||
.align 4, 42 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add check lines for --no-warn
/ --fatal-warnings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add check lines for
--no-warn
/--fatal-warnings
?
Can you walk me through why we might want that, please? I'd have guessed that if we properly emit a warning and the diagnostic infrastructure is working as intended then we wouldn't need to test such interactions for all kinds of warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning()
returns true (indicating an error) only in presense of --fatal-warnings
. We might want to add the --fatal-warnings
check to test that we didn't forget ReturnVal |=
part. (However, it appears that omitting it does not change the behavior because top-level loop not only checks for the return value, but also for what hasPendingErrors()
returns.)
Regarding --no-warn
, I tend to agree with you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a RUN with --fatal-warnings
. Let me know if it addresses your concerns properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check line would match if Warning
was replaced with Error
. I expected something like:
# RUN: not llvm-mc ... | FileCheck %s
# RUN: not llvm-mc --fatal-warnings ... | FileCheck --check-prefix=FATAL %s
...
# CHECK: ... warning: ignoring ...
# FATAL: ... error: ignoring...
I grepped mc tests and found only 4 tests that excercise --fatal-warnings
, so I guess you can just drop the last commit and go ahead...
@@ -12,5 +12,8 @@ | |||
# CHECK: {{.*}}.s:[[#@LINE+1]]:3: error: SHT_NOBITS section '.bss' cannot have instructions | |||
addb %al,(%rax) | |||
|
|||
# CHECK: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss' | |||
.align 4, 42 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check line would match if Warning
was replaced with Error
. I expected something like:
# RUN: not llvm-mc ... | FileCheck %s
# RUN: not llvm-mc --fatal-warnings ... | FileCheck --check-prefix=FATAL %s
...
# CHECK: ... warning: ignoring ...
# FATAL: ... error: ignoring...
I grepped mc tests and found only 4 tests that excercise --fatal-warnings
, so I guess you can just drop the last commit and go ahead...
9d53a0e
to
fc0c8f5
Compare
Hey this seems to produce a lot of invalid warnings for me. Example on a linux x86-64 system:
Results in:
it seems this just checks for the presence of fill-expression but not if it is actually non-zero... |
my comment was based on LLVM f548d19 |
The original patch (PR llvm#66792) did not properly check the non-zero fill value condition. This patch adds a new test case to ensure the overly aggressive check does not return.
@MatzeB You're right, this patch was flawed. My original patch also checked the non-zero fill value but, for whatever reason, I seem to have removed that before I submitted the PR. Apologies. Here's a fix: #67237. @s-barannikov |
This patch warns when an align directive with a non-zero fill value is used in a virtual section. The fill value is also set to zero, preventing an assertion in
MCAssembler::writeSectionData
for the caseof
MCFragment::FT_Align
from tripping.