diff mbox series

[pushed] libsanitizer, Darwin : Handle missing __builtin_os_log_format.

Message ID C7468CF8-E6C3-4420-BEA0-B814FCEA62D9@sandoe.co.uk
State New
Headers show
Series [pushed] libsanitizer, Darwin : Handle missing __builtin_os_log_format. | expand

Commit Message

Iain Sandoe May 13, 2021, 8:26 p.m. UTC
Hi,

The update to libsanitizer broke bootstrap on Darwin, since the upstream
sources assume building with clang on Darwin and make use of a header
depending on a builtin that GCC does not currently implement.

This patch fixes the build.  Whether to implement the missing builtin is
something to consider another day,

bootstrapped on Darwin16 and smoke-tested the sanitizer,
pushed to master,
thanks
Iain

I pushed also r12-781-g1f6fc2826d19136bb5ab97a4bdac07e6736b6869 which
adds this patch to libsanitizer LOCAL_PATCHES.

=====


GCC does not, currently, define __builtin_os_log_format, which
is needed by os/log.h.  Do not include that header unless the
builtin is defined (since the header errors out on the same
condition).  Provide a work-around solution to the missing API
provided via the header.

libsanitizer/ChangeLog:

	* sanitizer_common/sanitizer_mac.cpp : Check for the
	availability of __builtin_os_log_format before trying to
	include a header depending on it.
	(OS_LOG_DEFAULT): New.
	(os_log_error): Define to a fall-back using an older API.
---
 libsanitizer/sanitizer_common/sanitizer_mac.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Martin Liška May 14, 2021, 7:12 a.m. UTC | #1
On 5/13/21 10:26 PM, Iain Sandoe wrote:
> Hi,
> 
> The update to libsanitizer broke bootstrap on Darwin, since the upstream
> sources assume building with clang on Darwin and make use of a header
> depending on a builtin that GCC does not currently implement.

Hello.

Thank you for the fix. Btw. is it something that can be suggested to upstream?

Martin

> 
> This patch fixes the build.  Whether to implement the missing builtin is
> something to consider another day,
> 
> bootstrapped on Darwin16 and smoke-tested the sanitizer,
> pushed to master,
> thanks
> Iain
> 
> I pushed also r12-781-g1f6fc2826d19136bb5ab97a4bdac07e6736b6869 which
> adds this patch to libsanitizer LOCAL_PATCHES.
> 
> =====
> 
> 
> GCC does not, currently, define __builtin_os_log_format, which
> is needed by os/log.h.  Do not include that header unless the
> builtin is defined (since the header errors out on the same
> condition).  Provide a work-around solution to the missing API
> provided via the header.
> 
> libsanitizer/ChangeLog:
> 
> 	* sanitizer_common/sanitizer_mac.cpp : Check for the
> 	availability of __builtin_os_log_format before trying to
> 	include a header depending on it.
> 	(OS_LOG_DEFAULT): New.
> 	(os_log_error): Define to a fall-back using an older API.
> ---
>   libsanitizer/sanitizer_common/sanitizer_mac.cpp | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
> index f455856c85d..30a94fcba14 100644
> --- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp
> +++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
> @@ -70,7 +70,15 @@ extern "C" {
>   #include <mach/mach_time.h>
>   #include <mach/vm_statistics.h>
>   #include <malloc/malloc.h>
> -#include <os/log.h>
> +#if defined(__has_builtin) && __has_builtin(__builtin_os_log_format)
> +# include <os/log.h>
> +#else
> +   /* Without support for __builtin_os_log_format, fall back to the older
> +      method.  */
> +# define OS_LOG_DEFAULT 0
> +# define os_log_error(A,B,C) \
> +  asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", (C));
> +#endif
>   #include <pthread.h>
>   #include <sched.h>
>   #include <signal.h>
>
Iain Sandoe May 14, 2021, 7:18 a.m. UTC | #2
Martin Liška <mliska@suse.cz> wrote:

> On 5/13/21 10:26 PM, Iain Sandoe wrote:
>> Hi,
>> The update to libsanitizer broke bootstrap on Darwin, since the upstream
>> sources assume building with clang on Darwin and make use of a header
>> depending on a builtin that GCC does not currently implement.

> Thank you for the fix. Btw. is it something that can be suggested to  
> upstream?

Perhaps(?) - the builtin has been in clang since 2016 so it’s not depending  
on
anything new - and the code already caters for earlier macOS versions that  
did
not have a new-enough XCode - if I have some time I will ask.

thanks,
Iain
diff mbox series

Patch

diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
index f455856c85d..30a94fcba14 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
@@ -70,7 +70,15 @@  extern "C" {
 #include <mach/mach_time.h>
 #include <mach/vm_statistics.h>
 #include <malloc/malloc.h>
-#include <os/log.h>
+#if defined(__has_builtin) && __has_builtin(__builtin_os_log_format)
+# include <os/log.h>
+#else
+   /* Without support for __builtin_os_log_format, fall back to the older
+      method.  */
+# define OS_LOG_DEFAULT 0
+# define os_log_error(A,B,C) \
+  asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", (C));
+#endif
 #include <pthread.h>
 #include <sched.h>
 #include <signal.h>