-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Driver] Reject -mcmodel=tiny on X86 #125643
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: None (ShashwathiNavada) ChangesThe mcmodel=tiny memory model is only valid on ARM targets. While trying this on X86 compiler throws an internal error along with stack dump. #125641
Full diff: https://github.com/llvm/llvm-project/pull/125643.diff 1 Files Affected:
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 11fd6ab7f52a795..ac8d8be572012bb 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1897,6 +1897,15 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
Opts.setInlining(CodeGenOptions::NormalInlining);
}
+// -mcmodel option.
+if (const llvm::opt::Arg *A = Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ))
+{
+ llvm::StringRef modelName = A->getValue();
+ if(modelName=="tiny" && !T.isARM())
+ Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
+ << A->getSpelling() <<modelName<< T.getTriple();
+}
+
// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
// -fdirect-access-external-data.
Opts.DirectAccessExternalData =
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Can you add tests and a release note entry? Thanks! |
Thank you for the response! |
@cor3ntin I have addressed your comment. Could you please look into it. Thank you!! |
ping @cor3ntin |
ping @hstk30-hw |
ping @cor3ntin @hstk30-hw |
Hi, these is a pending review suggestion. Just put the test cast to exist test file, maybe like clang/test/Driver/mcmodel.c |
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.
LGTM,thx. And you? @cor3ntin
llvm::StringRef modelName = A->getValue(); | ||
if (modelName == "tiny" && !(T.isARM() || T.isAArch64())) { | ||
Diags.Report(diag::err_drv_unsupported_option_argument_for_target) | ||
<< A->getSpelling() << modelName << T.getTriple(); |
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.
llvm::StringRef modelName = A->getValue(); | |
if (modelName == "tiny" && !(T.isARM() || T.isAArch64())) { | |
Diags.Report(diag::err_drv_unsupported_option_argument_for_target) | |
<< A->getSpelling() << modelName << T.getTriple(); | |
StringRef ModelName = A->getValue(); | |
if (ModelName == "tiny" && !(T.isARM() || T.isAArch64())) { | |
Diags.Report(diag::err_drv_unsupported_option_argument_for_target) | |
<< A->getSpelling() << ModelName << T.getTriple(); |
Fixing for our coding style.
llvm/docs/ReleaseNotes.md
Outdated
@@ -240,6 +240,9 @@ Changes to Sanitizers | |||
Other Changes | |||
------------- | |||
|
|||
* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic. |
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.
Oops, this belongs in clang/docs/ReleaseNotes.rst
rather than in LLVM (because this is changing diagnostic behavior of the Clang driver).
llvm/docs/ReleaseNotes.md
Outdated
@@ -240,6 +240,9 @@ Changes to Sanitizers | |||
Other Changes | |||
------------- | |||
|
|||
* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic. |
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.
* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic. | |
* The ``-mcmodel=tiny`` option will now be diagnosed on all targets other than ARM or AArch64. |
clang/test/Driver/mcmodel.c
Outdated
@@ -4,6 +4,7 @@ | |||
// RUN: %clang --target=x86_64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=KERNEL %s | |||
// RUN: %clang --target=x86_64 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s | |||
// RUN: %clang --target=x86_64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s | |||
// RUN: not %clang --target=x86_64 -c -mcmodel=tiny %s 2>&1 | FileCheck %s |
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.
What about Line 2 of this file? That seems like it would now start failing, right?
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.
Thanks for the response, I have modified the command.
Thanks for the response, I have made the changes in clang/lib/Driver |
clang/test/Driver/mcmodel.c
Outdated
@@ -44,3 +44,5 @@ | |||
// ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux' | |||
|
|||
// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt' | |||
|
|||
// CHECK: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}' |
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.
We have nothing with a check prefix of just CHECK
so this will never actually be tested. Also, this is the same message as ERR-TINY
so we wouldn't need this line anyway.
clang/lib/Driver/Driver.cpp
Outdated
@@ -1755,6 +1755,18 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { | |||
<< TC.getTriple().str(); | |||
} | |||
|
|||
// Throw diagnosis if mcmodel=tiny option is passed for targets other than ARM | |||
// or AArch64. | |||
if (Arg *A = UArgs->getLastArg(options::OPT_mcmodel_EQ)) { |
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.
Move to clang/lib/Driver/ToolChains/CommonArgs.cpp addMCModel
. You might delete add an early return to that function and run check-clang-driver
to find relevant tests. Then follow that style and add one for Arm.
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.
tiny
is expected to work with AArch64.
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.
@MaskRay Thank you for your response!
I noticed that in the function you mentioned, there’s a check like this:
else if (Triple.getArch() == llvm::Triple::x86_64) {
Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"}, CM);
}
I found that removing the tiny option here gives the desired result.
Would you mind confirming if this approach looks good?
ping @MaskRay |
clang/docs/ReleaseNotes.rst
Outdated
@@ -391,6 +391,7 @@ Improvements to Clang's diagnostics | |||
|
|||
|
|||
- An error is now emitted when a ``musttail`` call is made to a function marked with the ``not_tail_called`` attribute. (#GH133509). | |||
- The ``-mcmodel=tiny`` option will now be diagnosed on all targets other than ARM or AArch64. |
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.
The commit message/description and the note should be changed. Only X86 is affected. This change is pretty niche and does not deserve a release note.
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.
@MaskRay, Thank you for the response. I have removed the release note entry and updated the commit message as well.
This patch causes a test fail on I tested with build: |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/31001 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/27305 Here is the relevant piece of the build log for the reference
|
Hi there, we would appreciate it if you could revert this PR while investigating. It breaks our buildbot and will block our downstream merge. |
I put up #138959 which removes the offending |
The mcmodel=tiny memory model is only valid on ARM targets. While trying this on X86 compiler throws an internal error along with stack dump. #125641
This patch resolves the issue.
Reduced test case: