llvm / llvm/llvm-project

`sysv_abi` attribute for constructors and destructors on Windows, and/or in a pragma?

Open
#166,925 2 comments 0 reactions 0 assignees View on GitHub
ABI clang:codegen clang:frontend platform:windows
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Hey,

I have to work on a Windows project unfortunately (I'm a Linux guy myself).

I hate MS x64 calling convention and would like to use `sysv_abi` throughout the project (except external dlls of course) to be able to pass stuff like `std::span` directly etc.
Calling an MS ABI function from a SysV ABI function is fine, however, calling a SysV ABI function from an MS ABI function introduces function coloring / additional overhead due to XMM clobbering which negates benefits of using SysV ABI on Windows, unless the whole project is in SysV ABI.
Unfortunately, for now Clang doesn't support setting the `sysv_abi` attribute for constructors and destructors, as well as using pragmas. The latter can be worked around by marking every function separately (annoying but acceptable), while the former complicates things a lot.
It's also interesting that Clang on Linux supports marking constructors and destructors with `ms_abi`, but not vice versa.

Are there any plans to remove those limitations? That would really help; otherwise, I start doubting it's worth it at all.

Or maybe there are some other flags/WAs in Clang that would avoid passing 16-byte structs via implicit references instead of registers on Windows for the whole project?

Contributor guide

Open the contributing guide

Research direction

Start by locating Clang's handling of the sysv_abi attribute and its support for constructors and destructors on Windows. Then investigate whether pragma-based application follows the same path. Done means these declarations and a suitable project-wide mechanism accept sysv_abi without the reported ABI overhead or unsupported-attribute limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.