RFR: build pragma error with gcc 4.4.7

Kim Barrett kim.barrett at oracle.com
Mon Mar 19 23:23:58 UTC 2018


> On Mar 16, 2018, at 6:48 AM, Michal Vala <mvala at redhat.com> wrote:
> 
> Hi,
> 
> I've been trying to build latest jdk with gcc 4.4.7 and I hit compile error due to pragma used in function:
> 
> /mnt/ramdisk/openjdk/src/hotspot/os/linux/os_linux.inline.hpp:103: error: #pragma GCC diagnostic not allowed inside functions
> 
> 
> I'm sending little patch that fixes the issue by wrapping whole function. I've also created a macro for ignoring deprecated declaration inside compilerWarnings.hpp to line up with others.
> 
> Can someone please review? If it's ok, I would also need a sponsor.
> 
> 
> diff -r 422615764e12 src/hotspot/os/linux/os_linux.inline.hpp
> --- a/src/hotspot/os/linux/os_linux.inline.hpp	Thu Mar 15 14:54:10 2018 -0700
> +++ b/src/hotspot/os/linux/os_linux.inline.hpp	Fri Mar 16 10:50:24 2018 +0100
> @@ -96,13 +96,12 @@
>   return ::ftruncate64(fd, length);
> }
> 
> -inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
> -{
> // readdir_r has been deprecated since glibc 2.24.
> // See https://sourceware.org/bugzilla/show_bug.cgi?id=19056 for more details.
> -#pragma GCC diagnostic push
> -#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> -
> +PRAGMA_DIAG_PUSH
> +PRAGMA_DEPRECATED_IGNORED
> +inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
> +{
>   dirent* p;
>   int status;
>   assert(dirp != NULL, "just checking");
> @@ -114,11 +113,11 @@
>   if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
>     errno = status;
>     return NULL;
> -  } else
> +  } else {
>     return p;
> -
> -#pragma GCC diagnostic pop
> +  }
> }
> +PRAGMA_DIAG_POP
> 
> inline int os::closedir(DIR *dirp) {
>   assert(dirp != NULL, "argument is NULL");
> diff -r 422615764e12 src/hotspot/share/utilities/compilerWarnings.hpp
> --- a/src/hotspot/share/utilities/compilerWarnings.hpp	Thu Mar 15 14:54:10 2018 -0700
> +++ b/src/hotspot/share/utilities/compilerWarnings.hpp	Fri Mar 16 10:50:24 2018 +0100
> @@ -48,6 +48,7 @@
> #define PRAGMA_FORMAT_NONLITERAL_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \
>                                          _Pragma("GCC diagnostic ignored \"-Wformat-security\"")
> #define PRAGMA_FORMAT_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat\"")
> +#define PRAGMA_DEPRECATED_IGNORED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
> 
> #if defined(__clang_major__) && \
>       (__clang_major__ >= 4 || \
> 
> 
> Thanks!
> 
> -- 
> Michal Vala
> OpenJDK QE
> Red Hat Czech

Given that there seem to be no callers of os::readdir that share the
DIR* among multiple threads, it would seem easier to just replace the
use of ::readdir_r with ::readdir.  That seems to be the intent in the
deprecation decision; use ::readdir, and either don't share a DIR*
among threads, or use external locking when doing so.

There are also problems with the patch as provided.

(1) Since PRAGMA_DIAG_PUSH/POP do nothing in the version of gcc this
change is being made in support of, the warning would be disabled for
all following code in any translation unit that includes this file.
That doesn't seem good.

(2) The default empty definition for PRAGMA_DEPRECATED_IGNORED is
missing.  That means the macro can't be used in shared code, in which
case having defined in (shared) compilerWarnings.hpp is questionable.




More information about the build-dev mailing list