tcg/ppc: Fix building with Clang
PATCH 1/1 tcg/ppc: Fix building with Clang
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.
tcg/ppc/tcg-target.c.inc +5 -0
@@ -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
Quoted 33 lines · Brad Smith
Fix building with Clang.
At the moment Clang does not define
_CALL_SYSVas GCC does. From clang/lib/Basic/Targets/PPC.cpp ingetTargetDefines()..// 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_DARWINThis is from the OpenBSD ports tree where we use it to build on OpenBSD/powerpc.
Signed-off-by Brad Smith <[email protected]>tcg/ppc/tcg-target.c.inc +0
-0
tcg/ppc/tcg-target.c.inc line 31
Quoted 7 lines
tcg/ppc/tcg-target.c.inc +4
-0@@ -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
Quoted 10 lines · Peter Maydell
tcg/ppc/tcg-target.c.inc line 31
Quoted 4 lines
tcg/ppc/tcg-target.c.inc +4
-0+/* Clang does not define _CALL_* */ +#if defined(__clang__) && defined(__ELF__) && !defined(_CALL_SYSV) +#define _CALL_SYSV 1 +#endifThis 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_SYSVimplies), 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.
Quoted 3 lines
I guess if clang doesn't reliably tell us the calling convention maybe we should scrap the use of
_CALL_SYSVand_CALL_ELFand 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
#endifr~
Quoted 26 lines · Richard Henderson
Quoted 10 lines · Peter Maydell
tcg/ppc/tcg-target.c.inc line 31
Quoted 4 lines
tcg/ppc/tcg-target.c.inc +4
-0+/* Clang does not define _CALL_* */ +#if defined(__clang__) && defined(__ELF__) && !defined(_CALL_SYSV) +#define _CALL_SYSV 1 +#endifThis 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_SYSVimplies), 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_ELFsymbol is a 64-bit thing, and AIX itself doesn't use ELF.Quoted 3 lines
I guess if clang doesn't reliably tell us the calling convention maybe we should scrap the use of
_CALL_SYSVand_CALL_ELFand 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
Quoted 12 lines
#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
#endifDoesn't this also need some case that handles "64bit ppc clang which doesn't define _CALL_anything" ?
thanks
-- PMM
Quoted 16 lines · Peter Maydell
On Thu, 22 Apr 2021 at 06:18, Richard Henderson
Quoted 14 lines
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
Quoted 2 lines
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~
Quoted 20 lines · Richard Henderson
Quoted 16 lines · Peter Maydell
On Thu, 22 Apr 2021 at 06:18, Richard Henderson
Quoted 6 lines
I'm thinking something like
#if !defined(_CALL_SYSV) && \
!defined(_CALL_DARWIN) && \
!defined(_CALL_AIX) && \
!defined(_CALL_ELF)Quoted 8 lines
# if defined(__APPLE__) # define _CALL_DARWIN # elif defined(__ELF__) && TCG_TARGET_REG_BITS == 32 # define _CALL_SYSV # else # error "Unknown ABI" # endif #endifQuoted 2 lines
Doesn't this also need some case that handles "64bit ppc clang which doesn't define
_CALL_anything" ?
Quoted 8 lines
Clang does define
_CALL_ELFfor 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?
Quoted 23 lines · Brad Smith
Quoted 22 lines · Richard Henderson
Quoted 16 lines · Peter Maydell
On Thu, 22 Apr 2021 at 06:18, Richard Henderson
Quoted 6 lines
I'm thinking something like
#if !defined(_CALL_SYSV) && \
!defined(_CALL_DARWIN) && \
!defined(_CALL_AIX) && \
!defined(_CALL_ELF)Quoted 8 lines
# if defined(__APPLE__) # define _CALL_DARWIN # elif defined(__ELF__) && TCG_TARGET_REG_BITS == 32 # define _CALL_SYSV # else # error "Unknown ABI" # endif #endifQuoted 2 lines
Doesn't this also need some case that handles "64bit ppc clang which doesn't define
_CALL_anything" ?Clang does define
_CALL_ELFfor ppc64:
Quoted 8 lines
Quoted 6 lines
// 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?
ping?