QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] tcg/ppc: Fix building with Clang
@ 2021-04-21  1:14 Brad Smith
  2021-04-21  9:03 ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Brad Smith @ 2021-04-21  1:14 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

Fix building with Clang.

At the moment Clang does not define _CALL_SYSV as GCC does. From
clang/lib/Basic/Targets/PPC.cpp in getTargetDefines()..

  // FIXME: The following are not yet generated here by Clang, but are
  //        generated by GCC:
  //
  //   _SOFT_FLOAT_
  //   __RECIP_PRECISION__
  //   __APPLE_ALTIVEC__
  //   __RECIP__
  //   __RECIPF__
  //   __RSQRTE__
  //   __RSQRTEF__
  //   _SOFT_DOUBLE_
  //   __NO_LWSYNC__
  //   __CMODEL_MEDIUM__
  //   __CMODEL_LARGE__
  //   _CALL_SYSV
  //   _CALL_DARWIN

This is from the OpenBSD ports tree where we use it to build
on OpenBSD/powerpc.

Signed-off-by: Brad Smith <brad@comstyle.com>

diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
index 838ccfa42d..d2611832e5 100644
--- a/tcg/ppc/tcg-target.c.inc
+++ b/tcg/ppc/tcg-target.c.inc
@@ -25,6 +25,11 @@
 #include "elf.h"
 #include "../tcg-pool.c.inc"
 
+/* Clang does not define _CALL_* */
+#if defined(__clang__) && defined(__ELF__) && !defined(_CALL_SYSV)
+#define _CALL_SYSV 1
+#endif
+
 #if defined _CALL_DARWIN || defined __APPLE__
 #define TCG_TARGET_CALL_DARWIN
 #endif


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tcg/ppc: Fix building with Clang
  2021-04-21  1:14 [PATCH] tcg/ppc: Fix building with Clang Brad Smith
@ 2021-04-21  9:03 ` Peter Maydell
  2021-04-22  5:18   ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2021-04-21  9:03 UTC (permalink / raw)
  To: Brad Smith; +Cc: Richard Henderson, QEMU Developers

On Wed, 21 Apr 2021 at 02:15, Brad Smith <brad@comstyle.com> wrote:
>
> Fix building with Clang.
>
> At the moment Clang does not define _CALL_SYSV as GCC does. From
> clang/lib/Basic/Targets/PPC.cpp in getTargetDefines()..
>
>   // FIXME: The following are not yet generated here by Clang, but are
>   //        generated by GCC:
>   //
>   //   _SOFT_FLOAT_
>   //   __RECIP_PRECISION__
>   //   __APPLE_ALTIVEC__
>   //   __RECIP__
>   //   __RECIPF__
>   //   __RSQRTE__
>   //   __RSQRTEF__
>   //   _SOFT_DOUBLE_
>   //   __NO_LWSYNC__
>   //   __CMODEL_MEDIUM__
>   //   __CMODEL_LARGE__
>   //   _CALL_SYSV
>   //   _CALL_DARWIN
>
> This is from the OpenBSD ports tree where we use it to build
> on OpenBSD/powerpc.
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
>
> diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
> index 838ccfa42d..d2611832e5 100644
> --- a/tcg/ppc/tcg-target.c.inc
> +++ b/tcg/ppc/tcg-target.c.inc
> @@ -25,6 +25,11 @@
>  #include "elf.h"
>  #include "../tcg-pool.c.inc"
>
> +/* Clang does not define _CALL_* */
> +#if defined(__clang__) && defined(__ELF__) && !defined(_CALL_SYSV)
> +#define _CALL_SYSV 1
> +#endif

This is trying to identify the calling convention used by the OS.
That's not purely compiler specific (ie it is not the case that
all ELF output from clang is definitely using the calling convention
that _CALL_SYSV implies), so settign it purely based on "this is clang
producing ELF files" doesn't seem right.

I guess if clang doesn't reliably tell us the calling convention
maybe we should scrap the use of _CALL_SYSV and _CALL_ELF and
use the host OS defines to guess the calling convention ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tcg/ppc: Fix building with Clang
  2021-04-21  9:03 ` Peter Maydell
@ 2021-04-22  5:18   ` Richard Henderson
  2021-04-22  9:20     ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2021-04-22  5:18 UTC (permalink / raw)
  To: Peter Maydell, Brad Smith; +Cc: QEMU Developers

On 4/21/21 2:03 AM, Peter Maydell wrote:
>> +/* Clang does not define _CALL_* */
>> +#if defined(__clang__) && defined(__ELF__) && !defined(_CALL_SYSV)
>> +#define _CALL_SYSV 1
>> +#endif
> 
> This is trying to identify the calling convention used by the OS.
> That's not purely compiler specific (ie it is not the case that
> all ELF output from clang is definitely using the calling convention
> that _CALL_SYSV implies), so settign it purely based on "this is clang
> producing ELF files" doesn't seem right.

We can get pretty close though.  There are three ppc32 calling conventions: 
AIX, DARWIN, SYSV.  The _CALL_ELF symbol is a 64-bit thing, and AIX itself 
doesn't use ELF.

> I guess if clang doesn't reliably tell us the calling convention
> maybe we should scrap the use of _CALL_SYSV and _CALL_ELF and
> use the host OS defines to guess the calling convention ?

No, I'd rely on _CALL_* first, and only fall back to something else if they're 
not present.

I'm thinking something like

#if !defined(_CALL_SYSV) && \
     !defined(_CALL_DARWIN) && \
     !defined(_CALL_AIX) && \
     !defined(_CALL_ELF)
# if defined(__APPLE__)
#  define _CALL_DARWIN
# elif defined(__ELF__) && TCG_TARGET_REG_BITS == 32
#  define _CALL_SYSV
# else
#  error "Unknown ABI"
# endif
#endif


r~


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tcg/ppc: Fix building with Clang
  2021-04-22  5:18   ` Richard Henderson
@ 2021-04-22  9:20     ` Peter Maydell
  2021-04-22 15:39       ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2021-04-22  9:20 UTC (permalink / raw)
  To: Richard Henderson; +Cc: QEMU Developers, Brad Smith

On Thu, 22 Apr 2021 at 06:18, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 4/21/21 2:03 AM, Peter Maydell wrote:
> >> +/* Clang does not define _CALL_* */
> >> +#if defined(__clang__) && defined(__ELF__) && !defined(_CALL_SYSV)
> >> +#define _CALL_SYSV 1
> >> +#endif
> >
> > This is trying to identify the calling convention used by the OS.
> > That's not purely compiler specific (ie it is not the case that
> > all ELF output from clang is definitely using the calling convention
> > that _CALL_SYSV implies), so settign it purely based on "this is clang
> > producing ELF files" doesn't seem right.
>
> We can get pretty close though.  There are three ppc32 calling conventions:
> AIX, DARWIN, SYSV.  The _CALL_ELF symbol is a 64-bit thing, and AIX itself
> doesn't use ELF.
>
> > I guess if clang doesn't reliably tell us the calling convention
> > maybe we should scrap the use of _CALL_SYSV and _CALL_ELF and
> > use the host OS defines to guess the calling convention ?
>
> No, I'd rely on _CALL_* first, and only fall back to something else if they're
> not present.
>
> I'm thinking something like
>
> #if !defined(_CALL_SYSV) && \
>      !defined(_CALL_DARWIN) && \
>      !defined(_CALL_AIX) && \
>      !defined(_CALL_ELF)
> # if defined(__APPLE__)
> #  define _CALL_DARWIN
> # elif defined(__ELF__) && TCG_TARGET_REG_BITS == 32
> #  define _CALL_SYSV
> # else
> #  error "Unknown ABI"
> # endif
> #endif

Doesn't this also need some case that handles "64bit ppc clang which doesn't
define _CALL_anything" ?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tcg/ppc: Fix building with Clang
  2021-04-22  9:20     ` Peter Maydell
@ 2021-04-22 15:39       ` Richard Henderson
  2021-05-02  4:02         ` Brad Smith
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2021-04-22 15:39 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Brad Smith

On 4/22/21 2:20 AM, Peter Maydell wrote:
> On Thu, 22 Apr 2021 at 06:18, Richard Henderson
>> I'm thinking something like
>>
>> #if !defined(_CALL_SYSV) && \
>>       !defined(_CALL_DARWIN) && \
>>       !defined(_CALL_AIX) && \
>>       !defined(_CALL_ELF)
>> # if defined(__APPLE__)
>> #  define _CALL_DARWIN
>> # elif defined(__ELF__) && TCG_TARGET_REG_BITS == 32
>> #  define _CALL_SYSV
>> # else
>> #  error "Unknown ABI"
>> # endif
>> #endif
> 
> Doesn't this also need some case that handles "64bit ppc clang which doesn't
> define _CALL_anything" ?

Clang does define _CALL_ELF for ppc64:

   // ABI options.
   if (ABI == "elfv1")
     Builder.defineMacro("_CALL_ELF", "1");
   if (ABI == "elfv2")
     Builder.defineMacro("_CALL_ELF", "2");


r~


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tcg/ppc: Fix building with Clang
  2021-04-22 15:39       ` Richard Henderson
@ 2021-05-02  4:02         ` Brad Smith
  0 siblings, 0 replies; 6+ messages in thread
From: Brad Smith @ 2021-05-02  4:02 UTC (permalink / raw)
  To: Richard Henderson, Peter Maydell; +Cc: QEMU Developers

On 4/22/2021 11:39 AM, Richard Henderson wrote:
> On 4/22/21 2:20 AM, Peter Maydell wrote:
>> On Thu, 22 Apr 2021 at 06:18, Richard Henderson
>>> I'm thinking something like
>>>
>>> #if !defined(_CALL_SYSV) && \
>>>       !defined(_CALL_DARWIN) && \
>>>       !defined(_CALL_AIX) && \
>>>       !defined(_CALL_ELF)
>>> # if defined(__APPLE__)
>>> #  define _CALL_DARWIN
>>> # elif defined(__ELF__) && TCG_TARGET_REG_BITS == 32
>>> #  define _CALL_SYSV
>>> # else
>>> #  error "Unknown ABI"
>>> # endif
>>> #endif
>>
>> Doesn't this also need some case that handles "64bit ppc clang which 
>> doesn't
>> define _CALL_anything" ?
>
> Clang does define _CALL_ELF for ppc64:
>
>  // ABI options.
>  if (ABI == "elfv1")
>    Builder.defineMacro("_CALL_ELF", "1");
>  if (ABI == "elfv2")
>    Builder.defineMacro("_CALL_ELF", "2");
>

Able to spin up a patch that you think is appropriate?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21  1:14 [PATCH] tcg/ppc: Fix building with Clang Brad Smith
2021-04-21  9:03 ` Peter Maydell
2021-04-22  5:18   ` Richard Henderson
2021-04-22  9:20     ` Peter Maydell
2021-04-22 15:39       ` Richard Henderson
2021-05-02  4:02         ` Brad Smith

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git
	git clone --mirror https://lore.kernel.org/qemu-devel/2 qemu-devel/git/2.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git