llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

#pragma init_seg(section-specifier, func-name) not supported

Open AdamGlass opened this issue 1 year ago • 10 comments

This MSVC pragma is only partially implemented. As detailed here, there is functionality to specify a function to call in place of atexit.

https://learn.microsoft.com/en-us/cpp/preprocessor/init-seg?view=msvc-170

"func-name Specifies a function to be called in place of atexit when the program exits. This helper function also calls atexit with a pointer to the destructor for the global object. If you specify a function identifier in the pragma of the form,

C++

Copy int __cdecl myexit (void (__cdecl *pf)(void)) then your function will be called instead of the C run-time library's atexit. It allows you to build a list of the destructors to call when you're ready to destroy the objects."

Relevant code in ParsePragma.cpp:Parser::HandlePragmaMSInitSeg: // FIXME: Add support for the '[, func-name]' part of the pragma.

Maybe a good early OSS contribution given the limited use and lack of potential for regression

AdamGlass avatar Jul 15 '25 19:07 AdamGlass

@llvm/issue-subscribers-clang-frontend

Author: Adam Glass (AdamGlass)

This MSVC pragma is only partially implemented. As detailed here, there is functionality to specify a function to call in place of atexit.

https://learn.microsoft.com/en-us/cpp/preprocessor/init-seg?view=msvc-170

"func-name Specifies a function to be called in place of atexit when the program exits. This helper function also calls atexit with a pointer to the destructor for the global object. If you specify a function identifier in the pragma of the form,

C++

Copy int __cdecl myexit (void (__cdecl *pf)(void)) then your function will be called instead of the C run-time library's atexit. It allows you to build a list of the destructors to call when you're ready to destroy the objects."

Relevant code in ParsePragma.cpp:Parser::HandlePragmaMSInitSeg: // FIXME: Add support for the '[, func-name]' part of the pragma.

Maybe a good early OSS contribution given the limited use and lack of potential for regression

llvmbot avatar Jul 15 '25 19:07 llvmbot

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot avatar Jul 15 '25 19:07 llvmbot

@llvm/issue-subscribers-good-first-issue

Author: Adam Glass (AdamGlass)

This MSVC pragma is only partially implemented. As detailed here, there is functionality to specify a function to call in place of atexit.

https://learn.microsoft.com/en-us/cpp/preprocessor/init-seg?view=msvc-170

"func-name Specifies a function to be called in place of atexit when the program exits. This helper function also calls atexit with a pointer to the destructor for the global object. If you specify a function identifier in the pragma of the form,

C++

Copy int __cdecl myexit (void (__cdecl *pf)(void)) then your function will be called instead of the C run-time library's atexit. It allows you to build a list of the destructors to call when you're ready to destroy the objects."

Relevant code in ParsePragma.cpp:Parser::HandlePragmaMSInitSeg: // FIXME: Add support for the '[, func-name]' part of the pragma.

Maybe a good early OSS contribution given the limited use and lack of potential for regression

llvmbot avatar Jul 15 '25 19:07 llvmbot

Hi, I would like to contribute to this thanks @AdamGlass

rhyadav avatar Jul 15 '25 20:07 rhyadav

Our team would like to work on this

Shriiraz avatar Nov 06 '25 15:11 Shriiraz

Our team would like to work on this

In general, we assign after a PR is created.

shafik avatar Nov 13 '25 03:11 shafik

Since this was inactive for some time, I decided to open PR to fix the issue. See #203769

timofey256 avatar Jun 14 '26 14:06 timofey256

@shafik sir can I work on this

@competitive-programmer04 this feature is already implemented.

@rnk @shafik Could you please trigger CI in the linked PR above? Thank you

timofey256 avatar Nov 06 '26 20:11 timofey256

@competitive-programmer04 this feature is already implemented.

@rnk @shafik Could you please trigger CI in the linked PR above? Thank you

It looks like the branch needs to be updated.

shafik avatar Nov 06 '26 21:11 shafik