Skip to content

Conversation

@Berrysoft
Copy link
Contributor

@Berrysoft Berrysoft commented Jan 1, 2025

This PR is necessary for cygwin target of Rust.

References:

@github-actions
Copy link

github-actions bot commented Jan 1, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@Berrysoft Berrysoft force-pushed the fix-cygwin-dll-import branch from 5062f77 to 694e20e Compare January 1, 2025 17:11
@Berrysoft Berrysoft changed the title [X86][Cygwin] Fix global variable dll import [Cygwin] Fix global variable dll import Jan 1, 2025
Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Ideally, any functional change like this would warrant a change to a test case though. One way of identifying an existing test case relating to this, would be to e.g. break the existing code and run ninja check-llvm or similar, and see which tests now fail. That would show e.g. this list of tests:

  LLVM :: CodeGen/AArch64/mingw-refptr.ll
  LLVM :: CodeGen/ARM/Windows/mingw-refptr.ll
  LLVM :: CodeGen/ARM/Windows/pic.ll
  LLVM :: CodeGen/ARM/emutls_generic.ll
  LLVM :: CodeGen/ARM/win32-ssp.ll
  LLVM :: CodeGen/X86/PR40322.ll
  LLVM :: CodeGen/X86/br-fold.ll
  LLVM :: CodeGen/X86/mingw-refptr.ll
  LLVM :: CodeGen/X86/stack-protector.ll
  LLVM :: CodeGen/X86/win32-ssp.ll
  LLVM :: CodeGen/X86/win64-byval.ll

So it might be possible to copy some of these, or add RUN lines within the existing ones, for doing the same test for a cygwin target.

Copy link
Contributor

@mati865 mati865 left a comment

Choose a reason for hiding this comment

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

You beat me to it, I was planning to look into it this month 😉

@mstorsjo
Copy link
Member

mstorsjo commented Jan 1, 2025

You beat me to it, I was planning to look into it this month 😉

In case @Berrysoft isn't familiar with adding tests, do you think you could look into adding a test for this change?

@mati865
Copy link
Contributor

mati865 commented Jan 1, 2025

I can look into it, but probably not sooner than mid-January. My initial plan was to keep the changes as patches for MSYS2 and, after confirming they work, upstream them.

@Berrysoft
Copy link
Contributor Author

Thank you. I'm really not familiar with adding tests. If @mati865 has a larger plan including this patch, I think it's also OK. I just wanted to solve the problem.

@mstorsjo
Copy link
Member

mstorsjo commented Jan 2, 2025

Thank you. I'm really not familiar with adding tests. If @mati865 has a larger plan including this patch, I think it's also OK. I just wanted to solve the problem.

We generally require test additions to go along with the functional changes, unless there's a good reason not to, or there is a high urgency to unbreak things.

For this case, just add this change to your patch:

diff --git a/llvm/test/CodeGen/X86/mingw-refptr.ll b/llvm/test/CodeGen/X86/mingw-refptr.ll
index 73f1a9880913..82a90aba3865 100644
--- a/llvm/test/CodeGen/X86/mingw-refptr.ll
+++ b/llvm/test/CodeGen/X86/mingw-refptr.ll
@@ -1,4 +1,5 @@
 ; RUN: llc < %s -mtriple=x86_64-w64-mingw32 | FileCheck %s -check-prefix=CHECK-X64
+; RUN: llc < %s -mtriple=x86_64-pc-cygwin | FileCheck %s -check-prefix=CHECK-X64
 ; RUN: llc < %s -mtriple=i686-w64-mingw32 | FileCheck %s -check-prefix=CHECK-X86
 ; RUN: llc < %s -mtriple=i686-w64-mingw32-none-elf | FileCheck %s -check-prefix=CHECK-X86-ELF
 

I tested that this is enough. Without the change in this patch, this added test fails (you can run ninja llc && bin/llvm-lit -a path/to/llvm/test/CodeGen/X86/mingw-refptr.ll), and with this change it succeeds.

@Berrysoft
Copy link
Contributor Author

Thank you very much, @mstorsjo ! I have added the test.

@llvmbot
Copy link
Member

llvmbot commented Jan 2, 2025

@llvm/pr-subscribers-backend-x86

Author: 王宇逸 (Berrysoft)

Changes

This PR is necessary for cygwin target of Rust.

References:


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

2 Files Affected:

  • (modified) llvm/lib/Target/TargetMachine.cpp (+1-1)
  • (modified) llvm/test/CodeGen/X86/mingw-refptr.ll (+1)
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index c0985f3be91a53..d5365f3c047437 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -204,7 +204,7 @@ bool TargetMachine::shouldAssumeDSOLocal(const GlobalValue *GV) const {
     // don't assume the variables to be DSO local unless we actually know
     // that for sure. This only has to be done for variables; for functions
     // the linker can insert thunks for calling functions from another DLL.
-    if (TT.isWindowsGNUEnvironment() && GV->isDeclarationForLinker() &&
+    if (TT.isOSCygMing() && GV->isDeclarationForLinker() &&
         isa<GlobalVariable>(GV))
       return false;
 
diff --git a/llvm/test/CodeGen/X86/mingw-refptr.ll b/llvm/test/CodeGen/X86/mingw-refptr.ll
index 73f1a9880913c9..82a90aba386546 100644
--- a/llvm/test/CodeGen/X86/mingw-refptr.ll
+++ b/llvm/test/CodeGen/X86/mingw-refptr.ll
@@ -1,4 +1,5 @@
 ; RUN: llc < %s -mtriple=x86_64-w64-mingw32 | FileCheck %s -check-prefix=CHECK-X64
+; RUN: llc < %s -mtriple=x86_64-pc-cygwin | FileCheck %s -check-prefix=CHECK-X64
 ; RUN: llc < %s -mtriple=i686-w64-mingw32 | FileCheck %s -check-prefix=CHECK-X86
 ; RUN: llc < %s -mtriple=i686-w64-mingw32-none-elf | FileCheck %s -check-prefix=CHECK-X86-ELF
 

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mati865
Copy link
Contributor

mati865 commented Jan 2, 2025

Thank you. I'm really not familiar with adding tests. If @mati865 has a larger plan including this patch, I think it's also OK. I just wanted to solve the problem.

Please go ahead. My work is still in an early stage.

@mstorsjo mstorsjo merged commit f03b100 into llvm:main Jan 2, 2025
9 checks passed
@github-actions
Copy link

github-actions bot commented Jan 2, 2025

@Berrysoft Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@Berrysoft Berrysoft deleted the fix-cygwin-dll-import branch March 1, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants