diff mbox series

[v2,01/12] build: Only define OS_OBJECT_USE_OBJC with gcc

Message ID 20230830161425.91946-2-graf@amazon.com
State New
Headers show
Series Introduce new vmapple machine type | expand

Commit Message

Alexander Graf Aug. 30, 2023, 4:14 p.m. UTC
Recent versions of macOS use clang instead of gcc. The OS_OBJECT_USE_OBJC
define is only necessary when building with gcc. Let's not define it when
building with clang.

With this patch, I can successfully include GCD headers in QEMU when
building with clang.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Aug. 31, 2023, 8:12 a.m. UTC | #1
On 30/8/23 18:14, Alexander Graf wrote:
> Recent versions of macOS use clang instead of gcc. The OS_OBJECT_USE_OBJC
> define is only necessary when building with gcc. Let's not define it when
> building with clang.
> 
> With this patch, I can successfully include GCD headers in QEMU when
> building with clang.
> 
> Signed-off-by: Alexander Graf <graf@amazon.com>
> ---
>   meson.build | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/meson.build b/meson.build
> index 98e68ef0b1..0d6a0015a1 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -224,7 +224,9 @@ qemu_ldflags = []
>   if targetos == 'darwin'
>     # Disable attempts to use ObjectiveC features in os/object.h since they
>     # won't work when we're compiling with gcc as a C compiler.
> -  qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
> +  if compiler.get_id() == 'gcc'
> +    qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
> +  endif
>   elif targetos == 'solaris'
>     # needed for CMSG_ macros in sys/socket.h
>     qemu_common_flags += '-D_XOPEN_SOURCE=600'

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Akihiko Odaki Aug. 31, 2023, 8:53 a.m. UTC | #2
On 2023/08/31 17:12, Philippe Mathieu-Daudé wrote:
> On 30/8/23 18:14, Alexander Graf wrote:
>> Recent versions of macOS use clang instead of gcc. The OS_OBJECT_USE_OBJC
>> define is only necessary when building with gcc. Let's not define it when
>> building with clang.
>>
>> With this patch, I can successfully include GCD headers in QEMU when
>> building with clang.
>>
>> Signed-off-by: Alexander Graf <graf@amazon.com>
>> ---
>>   meson.build | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/meson.build b/meson.build
>> index 98e68ef0b1..0d6a0015a1 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -224,7 +224,9 @@ qemu_ldflags = []
>>   if targetos == 'darwin'
>>     # Disable attempts to use ObjectiveC features in os/object.h since 
>> they
>>     # won't work when we're compiling with gcc as a C compiler.
>> -  qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
>> +  if compiler.get_id() == 'gcc'
>> +    qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
>> +  endif
>>   elif targetos == 'solaris'
>>     # needed for CMSG_ macros in sys/socket.h
>>     qemu_common_flags += '-D_XOPEN_SOURCE=600'
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 

Defining OS_OBJECT_USE_OBJC does not look like a proper solution. 
Looking at os/object.h, it seems OS_OBJECT_USE_OBJC is defined as 0 when:
!defined(OS_OBJECT_HAVE_OBJC_SUPPORT) && (!defined(__OBJC__) || 
defined(__OBJC_GC__))

This means OS_OBJECT_USE_OBJC is always 0 if Objective-C is disabled. I 
also confirmed os/object.h will not use Objective-C features when 
compiled as C code on clang with the following command:

clang -E -x -c - <<EOF
#include <os/object.h>
EOF

If compilation fails with GCC when not defining OS_OBJECT_USE_OBJC, it 
probably means GCC incorrectly treats C code as Objective-C and that is 
the problem we should solve. I cannot confirm this theory however since 
I have only an Apple Silicon Mac that is incompatible with GCC.

Regards,
Akihiko Odaki
Alexander Graf Aug. 31, 2023, 8:59 a.m. UTC | #3
On 31.08.23 10:53, Akihiko Odaki wrote:
>
>
> On 2023/08/31 17:12, Philippe Mathieu-Daudé wrote:
>> On 30/8/23 18:14, Alexander Graf wrote:
>>> Recent versions of macOS use clang instead of gcc. The 
>>> OS_OBJECT_USE_OBJC
>>> define is only necessary when building with gcc. Let's not define it 
>>> when
>>> building with clang.
>>>
>>> With this patch, I can successfully include GCD headers in QEMU when
>>> building with clang.
>>>
>>> Signed-off-by: Alexander Graf <graf@amazon.com>
>>> ---
>>>   meson.build | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/meson.build b/meson.build
>>> index 98e68ef0b1..0d6a0015a1 100644
>>> --- a/meson.build
>>> +++ b/meson.build
>>> @@ -224,7 +224,9 @@ qemu_ldflags = []
>>>   if targetos == 'darwin'
>>>     # Disable attempts to use ObjectiveC features in os/object.h since
>>> they
>>>     # won't work when we're compiling with gcc as a C compiler.
>>> -  qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
>>> +  if compiler.get_id() == 'gcc'
>>> +    qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
>>> +  endif
>>>   elif targetos == 'solaris'
>>>     # needed for CMSG_ macros in sys/socket.h
>>>     qemu_common_flags += '-D_XOPEN_SOURCE=600'
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>
>
> Defining OS_OBJECT_USE_OBJC does not look like a proper solution.
> Looking at os/object.h, it seems OS_OBJECT_USE_OBJC is defined as 0 when:
> !defined(OS_OBJECT_HAVE_OBJC_SUPPORT) && (!defined(__OBJC__) ||
> defined(__OBJC_GC__))
>
> This means OS_OBJECT_USE_OBJC is always 0 if Objective-C is disabled. I
> also confirmed os/object.h will not use Objective-C features when
> compiled as C code on clang with the following command:
>
> clang -E -x -c - <<EOF
> #include <os/object.h>
> EOF
>
> If compilation fails with GCC when not defining OS_OBJECT_USE_OBJC, it
> probably means GCC incorrectly treats C code as Objective-C and that is
> the problem we should solve. I cannot confirm this theory however since
> I have only an Apple Silicon Mac that is incompatible with GCC.


My take on this was to make the gcc hack be a "legacy" thing that we put 
into its own corner, so that in a few years we can just drop it 
altogether. I don't really think it's worth wasting much time on this 
workaround and its potential compatibility with old macOS versions.


Alex





Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
Akihiko Odaki Aug. 31, 2023, 10:45 a.m. UTC | #4
On 2023/08/31 17:59, Alexander Graf wrote:
> 
> On 31.08.23 10:53, Akihiko Odaki wrote:
>>
>>
>> On 2023/08/31 17:12, Philippe Mathieu-Daudé wrote:
>>> On 30/8/23 18:14, Alexander Graf wrote:
>>>> Recent versions of macOS use clang instead of gcc. The 
>>>> OS_OBJECT_USE_OBJC
>>>> define is only necessary when building with gcc. Let's not define it 
>>>> when
>>>> building with clang.
>>>>
>>>> With this patch, I can successfully include GCD headers in QEMU when
>>>> building with clang.
>>>>
>>>> Signed-off-by: Alexander Graf <graf@amazon.com>
>>>> ---
>>>>   meson.build | 4 +++-
>>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/meson.build b/meson.build
>>>> index 98e68ef0b1..0d6a0015a1 100644
>>>> --- a/meson.build
>>>> +++ b/meson.build
>>>> @@ -224,7 +224,9 @@ qemu_ldflags = []
>>>>   if targetos == 'darwin'
>>>>     # Disable attempts to use ObjectiveC features in os/object.h since
>>>> they
>>>>     # won't work when we're compiling with gcc as a C compiler.
>>>> -  qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
>>>> +  if compiler.get_id() == 'gcc'
>>>> +    qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
>>>> +  endif
>>>>   elif targetos == 'solaris'
>>>>     # needed for CMSG_ macros in sys/socket.h
>>>>     qemu_common_flags += '-D_XOPEN_SOURCE=600'
>>>
>>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>
>>
>> Defining OS_OBJECT_USE_OBJC does not look like a proper solution.
>> Looking at os/object.h, it seems OS_OBJECT_USE_OBJC is defined as 0 when:
>> !defined(OS_OBJECT_HAVE_OBJC_SUPPORT) && (!defined(__OBJC__) ||
>> defined(__OBJC_GC__))
>>
>> This means OS_OBJECT_USE_OBJC is always 0 if Objective-C is disabled. I
>> also confirmed os/object.h will not use Objective-C features when
>> compiled as C code on clang with the following command:
>>
>> clang -E -x -c - <<EOF
>> #include <os/object.h>
>> EOF
>>
>> If compilation fails with GCC when not defining OS_OBJECT_USE_OBJC, it
>> probably means GCC incorrectly treats C code as Objective-C and that is
>> the problem we should solve. I cannot confirm this theory however since
>> I have only an Apple Silicon Mac that is incompatible with GCC.
> 
> 
> My take on this was to make the gcc hack be a "legacy" thing that we put 
> into its own corner, so that in a few years we can just drop it 
> altogether. I don't really think it's worth wasting much time on this 
> workaround and its potential compatibility with old macOS versions.

That makes sense.

Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index 98e68ef0b1..0d6a0015a1 100644
--- a/meson.build
+++ b/meson.build
@@ -224,7 +224,9 @@  qemu_ldflags = []
 if targetos == 'darwin'
   # Disable attempts to use ObjectiveC features in os/object.h since they
   # won't work when we're compiling with gcc as a C compiler.
-  qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
+  if compiler.get_id() == 'gcc'
+    qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0'
+  endif
 elif targetos == 'solaris'
   # needed for CMSG_ macros in sys/socket.h
   qemu_common_flags += '-D_XOPEN_SOURCE=600'