Re the message forwarded below. First I don't see a copy of this message at <https://lists.gnu.org/r/gnutls-devel/2015-02/index.html> so I'm taking the liberty of copying the entire thing to gnutls-de...@gnu.org.

Second, your patch (attached) doesn't look right. config.h should not #define __has_attribute because too much code (perhaps unwisely) defaults __has_attribute to something other than just 0, and relies on doing this, and if config.h defaults it to 0 then the code won't work. (The advice about defaulting __has_attribute to 0 in https://clang.llvm.org/docs/LanguageExtensions.html is wrong for GCC.)

Third, the proposed patch uses __has_attribute(__noreturn__) to decide whether _Noreturn is supported, which doesn't sound right. I expect that Clang historically has had modes in which __attribute__((__noreturn__)) worked and _Noreturn didn't, or vice versa.

If you could let us know exactly when Clang supports _Noreturn and when it doesn't (C++ vs C, which version of Clang, which other C preprocessor macros matter?) we could come up with a better patch.


---------- Forwarded message ---------
From: Jeffrey Walton <noloa...@gmail.com>
Date: Mon, Feb 3, 2020 at 3:12 AM
Subject: GnuTLS 3.6.12 patch for OS X 10.9
To: <gnutls-de...@lists.gnutls.org>

Hi Everyone,

I'm working from the GnuTLS 3.6.12 release tarball on OS X 10.9.

The build is failing due to the handling of _Noreturn in config.h and
gl/_Noreturn.h. An example of the error is shown below.

The attached patch fixes the build. In the case of OS X 10.9 with
Clang, the compiler already knows what to do with
__attribute__((__noreturn__)). The machinery should not modify
anything.

gcc -DHAVE_CONFIG_H -I. -I..  -I./gl -I./gl -I./../lib/includes
-I./../lib/includes -I./../libdane/includes -I./../extra/includes
-I../src/libopts -I./libopts  -I/usr/local/include -DNDEBUG
-fno-common -Wall   -g2 -O2 -march=native -fPIC -pthread -MT tests.o
-MD -MP -MF $depbase.Tpo -c -o tests.o tests.c &&\
mv -f $depbase.Tpo $depbase.Po
In file included from psk.c:50:
In file included from ./gl/unistd.h:40:
/usr/include/unistd.h:424:18: error: use of undeclared identifier '__noreturn__'
void     _exit(int) __dead2;
                     ^
/usr/include/sys/cdefs.h:135:33: note: expanded from macro '__dead2'
#define __dead2         __attribute__((noreturn))
                                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include/stdnoreturn.h:27:18:
note:
       expanded from macro 'noreturn'
#define noreturn _Noreturn
                  ^
../config.h:1828:37: note: expanded from macro '_Noreturn'
#  define _Noreturn __attribute__ ((__noreturn__))
                                     ^
In file included from psk.c:50:
In file included from ./gl/unistd.h:40:
/usr/include/unistd.h:640:18: error: use of undeclared identifier '__noreturn__'
void     _Exit(int) __dead2;
                     ^
/usr/include/sys/cdefs.h:135:33: note: expanded from macro '__dead2'
#define __dead2         __attribute__((noreturn))
                                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include/stdnoreturn.h:27:18:
note:
       expanded from macro 'noreturn'
#define noreturn _Noreturn
                  ^
../config.h:1828:37: note: expanded from macro '_Noreturn'
#  define _Noreturn __attribute__ ((__noreturn__))
                                     ^
2 errors generated.
gmake[4]: *** [Makefile:2121: psk.o] Error 1
gmake[4]: *** Waiting for unfinished jobs....

If you don't like the use of __has_attribute, then the following
defines may be helpful to untangle things (or make the fur ball
bigger):

$ gcc -dM -E - < /dev/null | grep -i -E 'clang|llvm|apple|gnu'
#define __APPLE_CC__ 6000
#define __APPLE__ 1
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 4
#define __VERSION__ "4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)"
#define __apple_build_version__ 6000057
#define __clang__ 1
#define __clang_major__ 6
#define __clang_minor__ 0
#define __clang_patchlevel__ 0
#define __clang_version__ "6.0 (clang-600.0.57)"
#define __llvm__ 1

Jeff


--- config.h.in
+++ config.h.in
@@ -1806,9 +1806,16 @@
 /* Define to 1 to make NetBSD features available. MINIX 3 needs this. */
 #undef _NETBSD_SOURCE
 
+/* https://clang.llvm.org/docs/LanguageExtensions.html */
+#ifndef __has_attribute         // Optional of course.
+# define __has_attribute(x) 0   // Compatibility non-clang compilers.
+#endif
+
 /* The _Noreturn keyword of C11.  */
 #ifndef _Noreturn
-# if (defined __cplusplus \
+# if defined(__APPLE__) && defined(__clang__) && (__has_attribute(__noreturn__) == 1)
+   /* Don't do anything. Stay out of code paths below. */
+# elif (defined __cplusplus \
       && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
           || (defined _MSC_VER && 1900 <= _MSC_VER)))
 #  define _Noreturn [[noreturn]]
--- src/gl/_Noreturn.h
+++ src/gl/_Noreturn.h
@@ -14,8 +14,15 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
+/* https://clang.llvm.org/docs/LanguageExtensions.html */
+#ifndef __has_attribute         // Optional of course.
+# define __has_attribute(x) 0   // Compatibility non-clang compilers.
+#endif
+
 #ifndef _Noreturn
-# if (defined __cplusplus \
+# if defined(__APPLE__) && defined(__clang__) && (__has_attribute(__noreturn__) == 1)
+   /* Don't do anything. Stay out of code paths below. */
+# elif (defined __cplusplus \
       && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
           || (defined _MSC_VER && 1900 <= _MSC_VER)))
 #  define _Noreturn [[noreturn]]

Reply via email to