Skip to content

[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format #87149

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 1 commit into from
Apr 3, 2024

Conversation

phoebewang
Copy link
Contributor

We have many problems to use CodeView for a win32-elf target, e.g., #87140 and error: .seh_* directives are not supported on this target.

Fixes: #87140

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Mar 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 30, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Phoebe Wang (phoebewang)

Changes

We have many problems to use CodeView for a win32-elf target, e.g., #87140 and error: .seh_* directives are not supported on this target.

Fixes: #87140


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

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/MSVC.h (+3-3)
  • (added) clang/test/Misc/win32-elf.c (+5)
diff --git a/clang/lib/Driver/ToolChains/MSVC.h b/clang/lib/Driver/ToolChains/MSVC.h
index 48369e030aade2..3a5975272c570f 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -61,9 +61,9 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
   /// override the default.
   llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
-    return getTriple().isOSBinFormatMachO()
-               ? llvm::codegenoptions::DIF_DWARF
-               : llvm::codegenoptions::DIF_CodeView;
+    return getTriple().isOSBinFormatCOFF()
+               ? llvm::codegenoptions::DIF_CodeView
+               : llvm::codegenoptions::DIF_DWARF;
   }
 
   /// Set the debugger tuning to "default", since we're definitely not tuning
diff --git a/clang/test/Misc/win32-elf.c b/clang/test/Misc/win32-elf.c
new file mode 100644
index 00000000000000..f75281dc418727
--- /dev/null
+++ b/clang/test/Misc/win32-elf.c
@@ -0,0 +1,5 @@
+// Check that basic use of win32-elf targets works.
+// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf %s
+
+// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf -g %s -### 2>&1 | FileCheck %s -check-prefix=DEBUG-INFO
+// DEBUG-INFO: -dwarf-version={{.*}}

Copy link

github-actions bot commented Mar 30, 2024

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

We have many problems to use CodeView for a win32-elf target, e.g., llvm#87140
and `error: .seh_* directives are not supported on this target`.

Fixes: llvm#87140
Copy link
Collaborator

@rnk rnk left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@phoebewang phoebewang merged commit 4b25053 into llvm:main Apr 3, 2024
@phoebewang phoebewang deleted the win32-elf branch April 3, 2024 07:21
phoebewang added a commit that referenced this pull request Apr 3, 2024
…rmat (#87149)"

This reverts commit 4b25053.

There're failures in some target.
phoebewang added a commit to phoebewang/llvm-project that referenced this pull request Apr 8, 2024
phoebewang added a commit that referenced this pull request Apr 10, 2024
…rmat" (#87987)

This relands #87149.

The previous commit exposed failures on some targets. The reason is only
a few targets support COFF ObjectFormatType on Windows:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/TargetParser/Triple.cpp#L835-L842

With #87149, the targets don't support COFF will report "warning:
argument unused during compilation: '-gcodeview-command-line'
[-Wunused-command-line-argument]" in the test gcodeview-command-line.c

This patch limits gcodeview-command-line.c only run on targets support
COFF.
@MaskRay
Copy link
Member

MaskRay commented Apr 26, 2024

I am curious what a win32-elf triple is. Does MSVC support generating ELF object files?

@phoebewang
Copy link
Contributor Author

I am curious what a win32-elf triple is. Does MSVC support generating ELF object files?

No idea, but #87140 doesn't look like from fuzzing.
Consider Windows has WSL now, I'd not surprise it's supported or will be supported someday, see https://learn.microsoft.com/en-us/cpp/build/walkthrough-build-debug-wsl2?view=msvc-170

phoebewang added a commit that referenced this pull request Jun 5, 2024
…rmat", second try (#88245)

This is a second try to reland
#87149.

The previous commit exposed failures on some targets. The reason is only
a few targets support COFF ObjectFormatType on Windows:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/TargetParser/Triple.cpp#L835-L842

With #87149, the targets don't
support COFF will report "warning: argument unused during compilation:
'-gcodeview-command-line' [-Wunused-command-line-argument]" in the test
gcodeview-command-line.c

I was thinking `REQUIRES: *-registered-target` could solve the problem,
but it didn't. We need to check the actual triple instead of just
`*-registered-target`.
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 targeting i386-elf-win32 with debugging information
4 participants