Skip to content

Conversation

kimbarrett
Copy link

@kimbarrett kimbarrett commented Sep 10, 2025

Please review this change to FORBID_C_FUNCTION to make the exception specs of
the forbidding declarations match up with the exception specs of the
associated library declarations. This needs to account for different platform
libraries either having or not having exception specs. It's needed because,
after switching to C++17, some compilers complain about some differences in
the exception specs.

Also removed the workaround for JDK-8367051, which should no longer be needed
after this change.

Hoping someone will test the aix-ppc port. @MBaesken or @TheRealMDoerr ?

Testing: mach5 tier1, GHA sanity checks (nearly finished)
Locally (linux-aarch64) built with clang, which failed without the JDK-8367051
workaround.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8367282: FORBID_C_FUNCTION needs exception spec consistent with library declaration (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27180/head:pull/27180
$ git checkout pull/27180

Update a local copy of the PR:
$ git checkout pull/27180
$ git pull https://git.openjdk.org/jdk.git pull/27180/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27180

View PR using the GUI difftool:
$ git pr show -t 27180

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27180.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 10, 2025

👋 Welcome back kbarrett! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 10, 2025

@kimbarrett This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8367282: FORBID_C_FUNCTION needs exception spec consistent with library declaration

Reviewed-by: dholmes, mbaesken

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 60 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Sep 10, 2025

@kimbarrett The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot [email protected] rfr Pull request is ready for review labels Sep 10, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 10, 2025

Webrevs

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Seems reasonable. Thanks for getting this sorted out.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 10, 2025

#define FORBID_NORETURN_C_FUNCTION(Signature, Alternative) \
FORBID_C_FUNCTION(FORBIDDEN_FUNCTION_NORETURN_ATTRIBUTE Signature, Alternative)
#define FORBID_NORETURN_C_FUNCTION(Signature, Noexcept, Alternative) \
Copy link
Member

Choose a reason for hiding this comment

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

Is the added whitespace after ')' intended ?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for noticing. Will fix.

@MBaesken
Copy link
Member

Bad news from AIX, with this patch included we get build errors like this

=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_objs_sharedRuntimeTrans.o:
In file included from /jdk/src/hotspot/share/runtime/sharedRuntimeTrans.cpp:26:
In file included from /jdk/src/hotspot/share/runtime/interfaceSupport.inline.hpp:31:
In file included from /jdk/src/hotspot/share/gc/shared/gc_globals.hpp:28:
In file included from /jdk/src/hotspot/share/runtime/globals_shared.hpp:28:
In file included from /jdk/src/hotspot/share/utilities/align.hpp:31:
In file included from /jdk/src/hotspot/share/utilities/globalDefinitions.hpp:31:
/jdk/src/hotspot/share/utilities/forbiddenFunctions.hpp:61:23: error: exception specification in declaration does not match previous declaration
   61 | FORBID_C_FUNCTION(int sprintf(char*, const char*, ...), noexcept, "use os::snprintf");
      |                       ^
/usr/include/stdio.h:325:12: note: previous declaration is here
  325 | extern int      sprintf(char *__restrict__, const char *__restrict__, ...); 
      |                 ^

@snake66
Copy link
Contributor

snake66 commented Sep 10, 2025

Tested and found to work on FreeBSD Aarch64 (with all my still out-of-tree patches applied.)

@MBaesken
Copy link
Member

MBaesken commented Sep 10, 2025

Seems the forbidden sprintf AND snprintf cause the trouble on AIX, if I uncomment those 2 from forbiddenFunctions.hpp on top of this patch

/*
FORBID_C_FUNCTION(int sprintf(char*, const char*, ...), noexcept, "use os::snprintf");
FORBID_C_FUNCTION(int snprintf(char*, size_t, const char*, ...), noexcept, "use os::snprintf");
*/

the rest of forbidden functions causes no trouble on AIX, the build is successful.

@kimbarrett
Copy link
Author

Tested and found to work on FreeBSD Aarch64 (with all my still out-of-tree patches applied.)

Thanks for checking that!

@kimbarrett
Copy link
Author

Seems the forbidden sprintf AND snprintf cause the trouble on AIX, [...] the rest of forbidden functions causes
no trouble on AIX, the build is successful.

I was afraid something like this might turn up. I can hack around the
sprintf/snprintf AIX issue. But I think the only reliable long-term solution
might be to generate the forbidding declarations as part of the build process.
That's more work than I want to do for this right now though.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 11, 2025
@@ -119,8 +119,10 @@
extern "C" { \
[[deprecated(Alternative)]] \
Signature \
/* Not PASTE_TOKENS, which expands FFCN => nothing. */ \
FORBIDDEN_FUNCTION_COND_NOEXCEPT_ ## Noexcept \
/* 2-step pasting to avoid expansion of FFCN => nothing. */ \
Copy link
Member

Choose a reason for hiding this comment

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

Was this an issue with AIX or is this just a "better" way?

Copy link
Author

Choose a reason for hiding this comment

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

This is needed in order to allow NOT_AIX(noexcept) for the Noexcept
argument. We need pasting of the expansion, not direct pasting. Just using
direct ## as before results in making something like
FORBIDDEN_FUNCTION_COND_NOEXCEPT_NOT_AIX(noexcept)
which isn't what we want here. And doing a single paste, e.g.
PASTE_TOKENS(FORBIDDEN_FUNCTION_COND_NOEXCEPT_, Noexcept)
expands the first argument to nothing, so we just get noexcept, which isn't
what we want and doesn't work on platforms that don't declare their library
functions noexcept. The joys of macros...

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 12, 2025
Copy link
Member

@MBaesken MBaesken left a comment

Choose a reason for hiding this comment

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

Works now on AIX as well, thanks !

@kimbarrett
Copy link
Author

Thanks for reviews @MBaesken and @dholmes-ora

@kimbarrett
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 12, 2025

Going to push as commit 4e59c63.
Since your change was applied there have been 62 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 12, 2025
@openjdk openjdk bot closed this Sep 12, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 12, 2025
@openjdk
Copy link

openjdk bot commented Sep 12, 2025

@kimbarrett Pushed as commit 4e59c63.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@kimbarrett kimbarrett deleted the clang-forbid-noexcept branch September 12, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants