Skip to content

[Driver] Reject -mcmodel=tiny on X86 #125643

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

Merged
merged 25 commits into from
May 7, 2025
Merged

Conversation

ShashwathiNavada
Copy link
Contributor

@ShashwathiNavada ShashwathiNavada commented Feb 4, 2025

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:

#include <stdio.h>
int main( void )
{
printf( "Hello, World!\n" ); 
return 0; 
}
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -mcmodel=tiny <source>
1.	<eof> parser at end of file
 #0 0x0000000003b10218 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b10218)
 #1 0x0000000003b0e35c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b0e35c)
 #2 0x0000000003a5dbc3 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a5dbc3)
 #3 0x0000000003b05cfe llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b05cfe)
 #4 0x0000000000d4e3eb LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x0000000003a67c93 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a67c93)
 #6 0x0000000003a67df8 (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a67df8)
 #7 0x0000000002549148 llvm::X86TargetMachine::X86TargetMachine(llvm::Target const&, llvm::Triple const&, llvm::StringRef, llvm::StringRef, llvm::TargetOptions const&, std::optional<llvm::Reloc::Model>, std::optional<llvm::CodeModel::Model>, llvm::CodeGenOptLevel, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2549148)
 #8 0x00000000025491fc llvm::RegisterTargetMachine<llvm::X86TargetMachine>::Allocator(llvm::Target const&, llvm::Triple const&, llvm::StringRef, llvm::StringRef, llvm::TargetOptions const&, std::optional<llvm::Reloc::Model>, std::optional<llvm::CodeModel::Model>, llvm::CodeGenOptLevel, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x25491fc)
 #9 0x0000000003db74cc clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3db74cc)
#10 0x0000000004460d95 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4460d95)
#11 0x00000000060005ec clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x60005ec)
#12 0x00000000044614b5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44614b5)
#13 0x0000000004737121 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4737121)
#14 0x00000000046b777b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x46b777b)
#15 0x00000000048229e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48229e3)
#16 0x0000000000d50621 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd50621)
#17 0x0000000000d48e2d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#18 0x00000000044acc99 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#19 0x0000000003a5dac3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a5dac3)
#20 0x00000000044aceb9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#21 0x00000000044710dd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44710dd)
#22 0x0000000004472071 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4472071)
#23 0x000000000447c3fc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x447c3fc)
#24 0x0000000000d4d2b1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd4d2b1)
#25 0x0000000000c12464 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc12464)
#26 0x00007ae43b029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007ae43b029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x0000000000d488c5 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd488c5)

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Feb 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2025

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: None (ShashwathiNavada)

Changes

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 fix adds diagnostics to ensure the compiler throws a frontend error instead of crashing with an internal error.
Reduced test case:

#include &lt;stdio.h&gt;
int main( void )
{
printf( "Hello, World!\n" ); 
return 0; 
}
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -mcmodel=tiny &lt;source&gt;
1.	&lt;eof&gt; parser at end of file
 #<!-- -->0 0x0000000003b10218 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b10218)
 #<!-- -->1 0x0000000003b0e35c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b0e35c)
 #<!-- -->2 0x0000000003a5dbc3 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a5dbc3)
 #<!-- -->3 0x0000000003b05cfe llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b05cfe)
 #<!-- -->4 0x0000000000d4e3eb LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #<!-- -->5 0x0000000003a67c93 llvm::report_fatal_error(llvm::Twine const&amp;, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a67c93)
 #<!-- -->6 0x0000000003a67df8 (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a67df8)
 #<!-- -->7 0x0000000002549148 llvm::X86TargetMachine::X86TargetMachine(llvm::Target const&amp;, llvm::Triple const&amp;, llvm::StringRef, llvm::StringRef, llvm::TargetOptions const&amp;, std::optional&lt;llvm::Reloc::Model&gt;, std::optional&lt;llvm::CodeModel::Model&gt;, llvm::CodeGenOptLevel, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2549148)
 #<!-- -->8 0x00000000025491fc llvm::RegisterTargetMachine&lt;llvm::X86TargetMachine&gt;::Allocator(llvm::Target const&amp;, llvm::Triple const&amp;, llvm::StringRef, llvm::StringRef, llvm::TargetOptions const&amp;, std::optional&lt;llvm::Reloc::Model&gt;, std::optional&lt;llvm::CodeModel::Model&gt;, llvm::CodeGenOptLevel, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x25491fc)
 #<!-- -->9 0x0000000003db74cc clang::emitBackendOutput(clang::CompilerInstance&amp;, clang::CodeGenOptions&amp;, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::FileSystem&gt;, std::unique_ptr&lt;llvm::raw_pwrite_stream, std::default_delete&lt;llvm::raw_pwrite_stream&gt;&gt;, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3db74cc)
#<!-- -->10 0x0000000004460d95 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4460d95)
#<!-- -->11 0x00000000060005ec clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x60005ec)
#<!-- -->12 0x00000000044614b5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44614b5)
#<!-- -->13 0x0000000004737121 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4737121)
#<!-- -->14 0x00000000046b777b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x46b777b)
#<!-- -->15 0x00000000048229e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48229e3)
#<!-- -->16 0x0000000000d50621 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd50621)
#<!-- -->17 0x0000000000d48e2d ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->18 0x00000000044acc99 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->19 0x0000000003a5dac3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a5dac3)
#<!-- -->20 0x00000000044aceb9 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->21 0x00000000044710dd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44710dd)
#<!-- -->22 0x0000000004472071 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4472071)
#<!-- -->23 0x000000000447c3fc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x447c3fc)
#<!-- -->24 0x0000000000d4d2b1 clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd4d2b1)
#<!-- -->25 0x0000000000c12464 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc12464)
#<!-- -->26 0x00007ae43b029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->27 0x00007ae43b029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->28 0x0000000000d488c5 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd488c5)

Full diff: https://github.com/llvm/llvm-project/pull/125643.diff

1 Files Affected:

  • (modified) clang/lib/Frontend/CompilerInvocation.cpp (+9)
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 =

Copy link

github-actions bot commented Feb 4, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@ShashwathiNavada ShashwathiNavada changed the title Adding diagnostics for unsupported option #125641 Adding diagnostics for unsupported option Feb 4, 2025
@abhishek-kaushik22 abhishek-kaushik22 linked an issue Feb 4, 2025 that may be closed by this pull request
@cor3ntin
Copy link
Contributor

cor3ntin commented Feb 4, 2025

Can you add tests and a release note entry? Thanks!

@ShashwathiNavada
Copy link
Contributor Author

Can you add tests and a release note entry? Thanks!

Thank you for the response!
Sure, will do that!

@hstk30-hw hstk30-hw changed the title Adding diagnostics for unsupported option [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets Feb 5, 2025
@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Feb 11, 2025
@ShashwathiNavada
Copy link
Contributor Author

Can you add tests and a release note entry? Thanks!

@cor3ntin I have addressed your comment. Could you please look into it. Thank you!!

@ShashwathiNavada
Copy link
Contributor Author

ping @cor3ntin

@ShashwathiNavada
Copy link
Contributor Author

ping @hstk30-hw

@ShashwathiNavada
Copy link
Contributor Author

ping @cor3ntin @hstk30-hw

@hstk30-hw
Copy link
Contributor

Hi, these is a pending review suggestion. Just put the test cast to exist test file, maybe like clang/test/Driver/mcmodel.c
PLS

Copy link
Contributor

@hstk30-hw hstk30-hw left a 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

Comment on lines 1911 to 1914
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@@ -240,6 +240,9 @@ Changes to Sanitizers
Other Changes
-------------

* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic.
Copy link
Collaborator

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).

@@ -240,6 +240,9 @@ Changes to Sanitizers
Other Changes
-------------

* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

@@ -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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@ShashwathiNavada
Copy link
Contributor Author

We typically add such incompatibility check in clang/lib/Driver instead of clang/lib/Frontend.

(Apologies, I will have limited internet access between April 20th and May 4th, and my response time may be delayed.. Happy if a regular clang maintainer is happy.)

Thanks for the response, I have made the changes in clang/lib/Driver

@@ -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 '{{.*}}'
Copy link
Collaborator

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.

@@ -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)) {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@ShashwathiNavada ShashwathiNavada Apr 28, 2025

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?

@ShashwathiNavada
Copy link
Contributor Author

ping @MaskRay

@@ -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.
Copy link
Member

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.

Copy link
Contributor Author

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.

@ShashwathiNavada ShashwathiNavada changed the title [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets [ARM] Fix for crash when using -mcmodel=tiny on X86 May 6, 2025
@MaskRay MaskRay changed the title [ARM] Fix for crash when using -mcmodel=tiny on X86 [Driver] Reject -mcmodel=tiny on X86 May 7, 2025
@MaskRay MaskRay merged commit c53e583 into llvm:main May 7, 2025
11 checks passed
@jplehr
Copy link
Contributor

jplehr commented May 7, 2025

This patch causes a test fail on check-flang in our bot: https://lab.llvm.org/buildbot/#/builders/140/builds/22683
Local revert make the fail go away.
Not sure if this is a simple forward fix or something more substantial.

I tested with build: ninja -G Ninja -C offload/cmake/caches/AMDGPUBot.cmake -S llvm -B build

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 7, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building clang at step 7 "test-build-unified-tree-check-all".

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
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Flang :: Driver/mcmodel.f90' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
not /build/buildbot/premerge-monolithic-linux/build/bin/flang -### -c --target=i686 -mcmodel=medium /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90 2>&1 | /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck --check-prefix=ERR-MEDIUM /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90 # RUN: at line 1
+ not /build/buildbot/premerge-monolithic-linux/build/bin/flang -### -c --target=i686 -mcmodel=medium /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90
+ /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck --check-prefix=ERR-MEDIUM /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90
/build/buildbot/premerge-monolithic-linux/build/bin/flang --target=x86_64 -### -c -mcmodel=tiny /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90 2>&1 | /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck --check-prefix=TINY /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90 # RUN: at line 2
+ /build/buildbot/premerge-monolithic-linux/build/bin/flang --target=x86_64 -### -c -mcmodel=tiny /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90
+ /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck --check-prefix=TINY /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90
/build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90:27:9: error: TINY: expected string not found in input
! TINY: "-mcmodel=tiny"
        ^
<stdin>:1:1: note: scanning from here
flang version 21.0.0git (https://github.com/llvm/llvm-project.git c53e583007738f591d0c9993f06b65c4898a04f8)
^
<stdin>:6:56: note: possible intended match here
flang-21: error: unsupported argument 'tiny' to option '-mcmodel=' for target 'x86_64'
                                                       ^

Input file: <stdin>
Check file: /build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: flang version 21.0.0git (https://github.com/llvm/llvm-project.git c53e583007738f591d0c9993f06b65c4898a04f8) 
check:27'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
            2: Target: x86_64 
check:27'0     ~~~~~~~~~~~~~~~
            3: Thread model: posix 
check:27'0     ~~~~~~~~~~~~~~~~~~~~
            4: InstalledDir: /build/buildbot/premerge-monolithic-linux/build/bin 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5: Build config: +assertions 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~
            6: flang-21: error: unsupported argument 'tiny' to option '-mcmodel=' for target 'x86_64' 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:27'1                                                            ?                                possible intended match
            7:  "/build/buildbot/premerge-monolithic-linux/build/bin/flang" "-fc1" "-triple" "x86_64" "-emit-obj" "-mrelocation-model" "static" "-target-cpu" "x86-64" "-resource-dir" "/build/buildbot/premerge-monolithic-linux/build/lib/clang/21" "-mframe-pointer=all" "-o" "mcmodel.o" "-x" "f95" "/build/buildbot/premerge-monolithic-linux/llvm-project/flang/test/Driver/mcmodel.f90" 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented May 7, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building clang at step 6 "test-build-unified-tree-check-flang".

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
Step 6 (test-build-unified-tree-check-flang) failure: test (failure)
******************** TEST 'Flang :: Driver/mcmodel.f90' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
not /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang -### -c --target=i686 -mcmodel=medium /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90 2>&1 | /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck --check-prefix=ERR-MEDIUM /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90 # RUN: at line 1
+ not /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang -### -c --target=i686 -mcmodel=medium /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck --check-prefix=ERR-MEDIUM /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang --target=x86_64 -### -c -mcmodel=tiny /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90 2>&1 | /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck --check-prefix=TINY /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90 # RUN: at line 2
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang --target=x86_64 -### -c -mcmodel=tiny /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck --check-prefix=TINY /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90:27:9: error: TINY: expected string not found in input
! TINY: "-mcmodel=tiny"
        ^
<stdin>:1:1: note: scanning from here
flang version 21.0.0git (https://github.com/llvm/llvm-project.git c53e583007738f591d0c9993f06b65c4898a04f8)
^
<stdin>:6:56: note: possible intended match here
flang-21: error: unsupported argument 'tiny' to option '-mcmodel=' for target 'x86_64'
                                                       ^

Input file: <stdin>
Check file: /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: flang version 21.0.0git (https://github.com/llvm/llvm-project.git c53e583007738f591d0c9993f06b65c4898a04f8) 
check:27'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
            2: Target: x86_64 
check:27'0     ~~~~~~~~~~~~~~~
            3: Thread model: posix 
check:27'0     ~~~~~~~~~~~~~~~~~~~~
            4: InstalledDir: /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5: Build config: +assertions 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~
            6: flang-21: error: unsupported argument 'tiny' to option '-mcmodel=' for target 'x86_64' 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:27'1                                                            ?                                possible intended match
            7:  "/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang" "-fc1" "-triple" "x86_64" "-emit-obj" "-mrelocation-model" "static" "-target-cpu" "x86-64" "-resource-dir" "/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/lib/clang/21" "-mframe-pointer=all" "-o" "mcmodel.o" "-x" "f95" "/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Driver/mcmodel.f90" 
check:27'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>

--

********************


@Kewen12
Copy link

Kewen12 commented May 7, 2025

Hi there, we would appreciate it if you could revert this PR while investigating. It breaks our buildbot and will block our downstream merge.

jplehr added a commit that referenced this pull request May 7, 2025
@jplehr
Copy link
Contributor

jplehr commented May 7, 2025

I put up #138959 which removes the offending tiny mcmodel from the Flang driver test. I don't know if this is the right fix though.

jplehr added a commit that referenced this pull request May 7, 2025
petrhosek pushed a commit to petrhosek/llvm-project that referenced this pull request May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when using '-mcmodel=tiny' on X86
9 participants