Skip to content
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

8296812: sprintf is deprecated in Xcode 14 #11115

Closed
wants to merge 24 commits into from

Conversation

XueleiFan
Copy link
Member

@XueleiFan XueleiFan commented Nov 11, 2022

Hi,

May I have this update reviewed?

The sprintf is deprecated in Xcode 14 because of security concerns, and the use of it causing building failure. The build could pass if warnings are disabled for codes that use sprintf method. For the long run, the sprintf could be replaced with snprintf. This patch is trying to check if snprintf could be used.

Thanks,
Xuelei


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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11115

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 11, 2022

👋 Welcome back xuelei! 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 Nov 11, 2022

@XueleiFan The following labels will be automatically applied to this pull request:

  • client
  • hotspot

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

@openjdk openjdk bot added hotspot hotspot-dev@openjdk.org client client-libs-dev@openjdk.org labels Nov 11, 2022
@XueleiFan XueleiFan marked this pull request as ready for review November 13, 2022 06:32
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 13, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 13, 2022

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Hi @XueleiFan,

could you use jio_snprintf instead (see include/jvm_io.h)? That is what we usually do for snprintf. jio_snprintf hides platform particularities wrt snprintf.

Cheers, Thomas

@XueleiFan
Copy link
Member Author

could you use jio_snprintf instead (see include/jvm_io.h)? That is what we usually do for snprintf. jio_snprintf hides platform particularities wrt snprintf.

Good to know that. Thank you!

While I was doing the replacement from snprintf to jio_snprintf, I noticed a lot of existing use of snprintf in the files touched in this PR. What do you think if we have a snprintf clean up in a followed PR?

hotspot $ find . -type f |xargs grep snprintf |grep -v jio_snprintf |wc                  
     262    1895   26574

@tstuefe
Copy link
Member

tstuefe commented Nov 13, 2022

could you use jio_snprintf instead (see include/jvm_io.h)? That is what we usually do for snprintf. jio_snprintf hides platform particularities wrt snprintf.

Good to know that. Thank you!

While I was doing the replacement from snprintf to jio_snprintf, I noticed a lot of existing use of snprintf in the files touched in this PR. What do you think if we have a snprintf clean up in a followed PR?

hotspot $ find . -type f |xargs grep snprintf |grep -v jio_snprintf |wc                  
     262    1895   26574

Hmm, possibly. We may look again at the exact reason why we use jio_snprintf. Maybe it is less important nowadays, with reduced platform number (no solaris) and Windows being more standard conform than it had been in the past.

Lets hear what others think.

@kimbarrett
Copy link

Please don't add uses of jio_snprintf or ::snprintf to hotspot. Use os::snprintf.

Regarding jio_snprintf, see https://bugs.openjdk.org/browse/JDK-8198918.
Regarding os::snprintf and os::vsnprintf, see https://bugs.openjdk.org/browse/JDK-8285506.

I think the only reason we haven't marked ::sprintf and ::snprintf forbidden
(FORBID_C_FUNCTION) is there are a lot of uses, and nobody has gotten around
to dealing with it. ::snprintf in the list of candidates for
https://bugs.openjdk.org/browse/JDK-8214976, some of which have already been
marked. But I don't see new bugs for the as-yet unmarked ones.

As a general note, as a reviewer my preference is against non-trivial and
persnickety code changes that are scattered all over the code base. For
something like this I'd prefer multiple more bite-sized changes that were
dealing with specific uses. I doubt everyone agrees with me though.

@XueleiFan
Copy link
Member Author

Please don't add uses of jio_snprintf or ::snprintf to hotspot. Use os::snprintf.

Updated to use os::snprintf, except the files under adlc where the os::snptintf definition is not included. The use of snprintf could be cleaned up with existing code in the future.

Regarding jio_snprintf, see https://bugs.openjdk.org/browse/JDK-8198918. Regarding os::snprintf and os::vsnprintf, see https://bugs.openjdk.org/browse/JDK-8285506.

I think the only reason we haven't marked ::sprintf and ::snprintf forbidden (FORBID_C_FUNCTION) is there are a lot of uses, and nobody has gotten around to dealing with it. ::snprintf in the list of candidates for https://bugs.openjdk.org/browse/JDK-8214976, some of which have already been marked. But I don't see new bugs for the as-yet unmarked ones.

As a general note, as a reviewer my preference is against non-trivial and persnickety code changes that are scattered all over the code base. For something like this I'd prefer multiple more bite-sized changes that were dealing with specific uses. I doubt everyone agrees with me though.

It makes sense to me. I'd better focus on the building issue in this PR.

Thank you for the review!

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.

The hotspot changes seem okay using os::snprint. The adlc changes to use raw snprintf also seem okay for now - I'm not sure whether the platform differences for snprintf affect adlc.

The desktop change is wrong - you can't use os::snprintf there.

Thanks.

@XueleiFan XueleiFan closed this Nov 14, 2022
@XueleiFan XueleiFan reopened this Nov 14, 2022
@XueleiFan XueleiFan marked this pull request as draft November 14, 2022 05:02
@openjdk openjdk bot removed the rfr Pull request is ready for review label Nov 14, 2022
@tstuefe
Copy link
Member

tstuefe commented Nov 14, 2022

Please don't add uses of jio_snprintf or ::snprintf to hotspot. Use os::snprintf.

I did not know this was our policy now. Sorry for giving the wrong advice. Maybe we should add this to the hotspot style guide since I'm probably not the only one not knowing this.

Regarding jio_snprintf, see https://bugs.openjdk.org/browse/JDK-8198918. Regarding os::snprintf and os::vsnprintf, see https://bugs.openjdk.org/browse/JDK-8285506.

I think the only reason we haven't marked ::sprintf and ::snprintf forbidden (FORBID_C_FUNCTION) is there are a lot of uses, and nobody has gotten around to dealing with it. ::snprintf in the list of candidates for https://bugs.openjdk.org/browse/JDK-8214976, some of which have already been marked. But I don't see new bugs for the as-yet unmarked ones.

As a general note, as a reviewer my preference is against non-trivial and persnickety code changes that are scattered all over the code base. For something like this I'd prefer multiple more bite-sized changes that were dealing with specific uses. I doubt everyone agrees with me though.

I agree with you. Makes backporting a bit easier too.

@XueleiFan XueleiFan marked this pull request as ready for review November 14, 2022 08:05
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 14, 2022
@theRealAph
Copy link
Contributor

Kim said:

As a general note, as a reviewer my preference is against non-trivial and persnickety code changes that are scattered all over the code base. For something like this I'd prefer multiple more bite-sized changes that were dealing with specific uses. I doubt everyone agrees with me though.

There's a lot of wisdom in what you say. It's far too easy to mess things up when doing cleanups for compiler warnings. Also, long patches never get enough reviewing.

@XueleiFan
Copy link
Member Author

Please review the last update, and hopefully we are close to an agreement. Thanks!

@oraluben
Copy link

oraluben commented Dec 7, 2022

Any update on this? xcode 14 build has been broken for a while.

@XueleiFan
Copy link
Member Author

Could I have the last update reviewed?

@bourgesl
Copy link
Contributor

bourgesl commented Dec 7, 2022

I will have a look, I am affected too

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

I looked through all the code and found only some minor issues. I would appreciate more eyes on this, though.

I still think this would have been less work (for author and reviewers) had we converted the code to stringStream right away in the hotspot. stringStream takes care of a lot of this boilerplate stuff.

src/hotspot/os/bsd/attachListener_bsd.cpp Outdated Show resolved Hide resolved
src/hotspot/share/adlc/output_c.cpp Show resolved Hide resolved
src/hotspot/share/runtime/os.cpp Show resolved Hide resolved
src/hotspot/share/runtime/os.cpp Show resolved Hide resolved
src/hotspot/share/jvmci/jvmciCompilerToVMInit.cpp Outdated Show resolved Hide resolved
src/hotspot/share/utilities/utf8.cpp Show resolved Hide resolved
@mlbridge
Copy link

mlbridge bot commented Dec 8, 2022

Mailing list message from Michael Hall on client-libs-dev:

On Dec 7, 2022, at 3:41 AM, Thomas Stuefe <stuefe at openjdk.org> wrote:

am surprised this even builds.

It builds for me?

* Toolchain: clang (clang/LLVM from Xcode 14.1)

With the exception of these errors in cmstypes.c

/Users/mjh/Documents/GitHub/jdk/src/java.desktop/share/native/liblcms/cmstypes.c:3441:132: error: parameter 'SizeOfTag' set but not used [-Werror,-Wunused-but-set-parameter]
void *Type_ProfileSequenceId_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
^
/Users/mjh/Documents/GitHub/jdk/src/java.desktop/share/native/liblcms/cmstypes.c:5137:125: error: parameter 'SizeOfTag' set but not used [-Werror,-Wunused-but-set-parameter]
void *Type_Dictionary_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
^
2 errors generated.

I had seen this sometime back. The same workaround of adding?

cmsUNUSED_PARAMETER(SizeOfTag); // mjh

To the two methods, which I had noticed included elsewhere in the code, still appears to work.

I first noticed the sprintf issue in later releases of Xcode 13. It isn?t just Xcode 14.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20221207/87ad1668/attachment-0001.htm>

@XueleiFan
Copy link
Member Author

With the exception of these errors in cmstypes.c

/Users/mjh/Documents/GitHub/jdk/src/java.desktop/share/native/liblcms/cmstypes.c:3441:132: error: parameter 'SizeOfTag' set but not used [-Werror,-Wunused-but-set-parameter] void Type_ProfileSequenceId_Read(struct _cms_typehandler_struct self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) ^ /Users/mjh/Documents/GitHub/jdk/src/java.desktop/share/native/liblcms/cmstypes.c:5137:125: error: parameter 'SizeOfTag' set but not used [-Werror,-Wunused-but-set-parameter] void Type_Dictionary_Read(struct _cms_typehandler_struct self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) ^ 2 errors generated.

I had seen this sometime back. The same workaround of adding?

cmsUNUSED_PARAMETER(SizeOfTag); // mjh

To the two methods, which I had noticed included elsewhere in the code, still appears to work.

The SizeOfTag issue was tracked with https://bugs.openjdk.org/browse/JDK-8283221.

I first noticed the sprintf issue in later releases of Xcode 13. It isn?t just Xcode 14.

In the Apple Developer Documentation, there is a note for sprintf, "macOS 10.12–10.13.1 Deprecated". It looks like that deprecation was backported.

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Good from my side. But someone else should look as well. It's fiddly stuff.

@bourgesl
Copy link
Contributor

bourgesl commented Dec 8, 2022

I will try building openjdk20 with this patch tonight on mbp 2015, macos 13, xcode 14...

@mlbridge
Copy link

mlbridge bot commented Dec 8, 2022

Mailing list message from Michael Hall on client-libs-dev:

On Dec 7, 2022, at 9:23 PM, Xue-Lei Andrew Fan <xuelei at openjdk.org> wrote:

On Wed, 7 Dec 2022 21:25:11 GMT, Xue-Lei Andrew Fan <xuelei at openjdk.org <mailto:xuelei at openjdk.org>> wrote:

Hi,

May I have this update reviewed?

The sprintf is deprecated in Xcode 14 because of security concerns, and the use of it causing building failure. The build could pass if warnings are disabled for codes that use sprintf method. For the long run, the sprintf could be replaced with snprintf. This patch is trying to check if snprintf could be used.

Thanks,
Xuelei

Xue-Lei Andrew Fan has updated the pull request incrementally with one additional commit since the last revision:

update on review feedback

With the exception of these errors in cmstypes.c

/Users/mjh/Documents/GitHub/jdk/src/java.desktop/share/native/liblcms/cmstypes.c:3441:132: error: parameter 'SizeOfTag' set but not used [-Werror,-Wunused-but-set-parameter] void *Type_ProfileSequenceId_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) ^ /Users/mjh/Documents/GitHub/jdk/src/java.desktop/share/native/liblcms/cmstypes.c:5137:125: error: parameter 'SizeOfTag' set but not used [-Werror,-Wunused-but-set-parameter] void *Type_Dictionary_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) ^ 2 errors generated.

I had seen this sometime back. The same workaround of adding?

cmsUNUSED_PARAMETER(SizeOfTag); // mjh

To the two methods, which I had noticed included elsewhere in the code, still appears to work.

The SizeOfTag issue was tracked with https://bugs.openjdk.org/browse/JDK-8283221 <https://bugs.openjdk.org/browse/JDK-8283221>.

Sorry, I should of mentioned that I had come across this bug report the first time I had this issue. I don?t think it was closed at the time. The --disable-warnings-as-errors seemed the only suggested workaround at the time. I thought mine was better. I?m not very familiar with these things but I assume that the fix for that bug hasn?t been merged into your pull request yet, but will be at some point.

I first noticed the sprintf issue in later releases of Xcode 13. It isn?t just Xcode 14.

In the [Apple Developer Documentation](https://developer.apple.com/documentation/kernel/1441083-sprintf <https://developer.apple.com/documentation/kernel/1441083-sprintf>), there is a note for sprintf, "macOS 10.12?10.13.1 Deprecated". It looks like that deprecation was backported.

I installed an old Xcode (13.1) version. Which wasn?t a very easy process and probably only was possible since I have an Apple developer account to get the download. The next time I had gone into Xcode it forced an update to 14. I have continued to use the 13.1 to allow jdk builds until trying yours with 14.1. It worked as indicated.

Thanks for the reply.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20221207/f5f9a99a/attachment.htm>

Copy link

@kimbarrett kimbarrett 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. A couple of minor nits that you can address or not.

src/hotspot/share/adlc/formssel.cpp Outdated Show resolved Hide resolved
src/hotspot/share/adlc/formssel.cpp Show resolved Hide resolved
src/hotspot/share/adlc/output_c.cpp Outdated Show resolved Hide resolved
@bourgesl
Copy link
Contributor

bourgesl commented Dec 9, 2022

LGTM, build on macos 13 + xcode 14.1 (x64): OK

I run successfully few applications with built jdk image...

Configuration summary:
* Name:           macosx-x86_64-server-release
* Debug level:    release
* HS debug level: product
* JVM variants:   server
* JVM features:   server: 'cds compiler1 compiler2 dtrace epsilongc g1gc jfr jni-check jvmci jvmti management parallelgc serialgc services shenandoahgc vm-structs zgc' 
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 20-internal-adhoc.jmmc.jdk-gh (20-internal)
* Source date:    1670605929 (2022-12-09T17:12:09Z)

Tools summary:
* Boot JDK:       openjdk version "20-ea" 2023-03-21 OpenJDK Runtime Environment (build 20-ea+26-2022) OpenJDK 64-Bit Server VM (build 20-ea+26-2022, mixed mode, sharing) (at /Users/jmmc/apps/jdk-20.jdk/Contents/Home)
* Toolchain:      clang (clang/LLVM from Xcode 14.1)
* Sysroot:        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk
* C Compiler:     Version 14.0.0 (at /usr/bin/clang)
* C++ Compiler:   Version 14.0.0 (at /usr/bin/clang++)

@XueleiFan
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 9, 2022

Going to push as commit 478ef38.
Since your change was applied there have been 227 commits pushed to the master branch:

  • 715bf70: Merge
  • a894649: 8298225: [AIX] Disable PPC64LE continuations on AIX
  • 52fffdd: 8298463: tools/javac/modules/EdgeCases.java fails on Windows after JDK-8297988
  • b7b996c: 8298353: C2 fails with assert(opaq->outcnt() == 1 && opaq->in(1) == limit) failed
  • 05d67f6: 8298340: java/net/httpclient/CancelRequestTest.java fails with AssertionError: Found some subscribers for testPostInterrupt
  • 5a92bee: 8298455: JFR: Add logging to TestClose.java
  • 133ad8e: 8297988: NPE in JavacTypes.getOverriddenMethods from doclint
  • 553ba65: 8298402: ProblemList javax/swing/JFileChooser/4847375/bug4847375.java on windows-x64
  • 9749a43: 8298457: Instructions in a11y manual tests need to be updated
  • 7dbdd83: 8298190: Update --release 20 symbol information for JDK 20 build 27
  • ... and 217 more: https://git.openjdk.org/jdk/compare/b778cd52b3fae013ecb21d90bcf940a4d947bd68...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 9, 2022

@XueleiFan Pushed as commit 478ef38.

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

@XueleiFan XueleiFan deleted the JDK-8296812 branch December 9, 2022 22:40
@mlbridge
Copy link

mlbridge bot commented Dec 10, 2022

Mailing list message from Michael Hall on client-libs-dev:

Fwiw, Where I seem to differ?

macOS 12.6

* Version string: 20-internal-adhoc.mjh.jdk (20-internal)
* Source date: 1668643046 (2022-11-16T23:57:26Z)

* Boot JDK: openjdk version "19" 2022-09-20 OpenJDK Runtime Environment (build 19+36-2238) OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home)

But it did build without the cmstypes errors.
Attempting tier 1 tests showed an sprintf deprecation error as follows?

=== Output from failing command(s) repeated here ===
* For target support_test_hotspot_jtreg_native_support_libAsyncExceptionOnMonitorEnter_libAsyncExceptionOnMonitorEnter.o:
/Users/mjh/Documents/GitHub/jdk/test/hotspot/jtreg/runtime/Thread/libAsyncExceptionOnMonitorEnter.cpp:37:3: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
sprintf(name, "MyRawMonitor");
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
#define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
^
1 error generated.

@Siedlerchr
Copy link
Contributor

I just stumbled across this issue as well, make images did succeed, only the test is now failing with the same error
mac os 13.1 with XCode 14.2 on macbook M1 pro
commit:
11fd651


ERROR: Build failed for target 'run-test-tier1' in configuration 'macosx-aarch64-server-release' (exit code 2) 

=== Output from failing command(s) repeated here ===
* For target support_test_hotspot_jtreg_native_support_libAsyncExceptionOnMonitorEnter_libAsyncExceptionOnMonitorEnter.o:
/Users/christophs/workspace/jdk/test/hotspot/jtreg/runtime/Thread/libAsyncExceptionOnMonitorEnter.cpp:37:3: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
  sprintf(name, "MyRawMonitor");
  ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
))
        

@XueleiFan
Copy link
Member Author

ERROR: Build failed for target 'run-test-tier1' in configuration 'macosx-aarch64-server-release' (exit code 2)

JDK-8299378 was filled to track the issue. Thanks!

@mlbridge
Copy link

mlbridge bot commented Dec 28, 2022

Mailing list message from Michael Hall on client-libs-dev:

Thank you for providing the tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

10 participants