[cfe-users] Determine Clang Assembler versus System Assembler at compile time?

Jeffrey Walton noloader at gmail.com
Tue Jul 21 13:07:42 PDT 2015


We are trying to work around LLVM Bug 18916 - don't err on
".att_syntax prefix" (https://llvm.org/bugs/show_bug.cgi?id=18916).
(More correctly, we are trying to account for a corner case).

Here's what the work around looks like:

// https://llvm.org/bugs/show_bug.cgi?id=18916
#if defined(__clang__)
# define GNU_ATT_SYNTAX ".att_syntax;"
# define GNU_INTEL_SYNTAX ".intel_syntax;"
#elif defined(__GNUC__)
# define GNU_ATT_SYNTAX ".att_syntax prefix;"
# define GNU_INTEL_SYNTAX ".intel_syntax noprefix;"
#else
# define GNU_ATT_SYNTAX ".att_syntax prefix;"
# define GNU_INTEL_SYNTAX ".intel_syntax noprefix;"
#endif

Here's the corner case: if Clang is used to compile but
-fno-integrated-as is included in C{XX}FLAGS, then:

clang++ -DNDEBUG -g2 -O3 -Wall -fPIC -fno-integrated-as -march=native
-pipe -Wno-tautological-compare -c gcm.cpp
/tmp/gcm-01b73e.s: Assembler messages:
/tmp/gcm-01b73e.s:1404: Error: too many memory references for `movdqa'
/tmp/gcm-01b73e.s:1405: Error: too many memory references for `movdqu'
/tmp/gcm-01b73e.s:1405: Error: too many memory references for `pxor'
/tmp/gcm-01b73e.s:1405: Error: too many memory references for `pxor'
/tmp/gcm-01b73e.s:1405: Error: too many memory references for `movd'
...

Its obvious we need something like: `#if defined(__clang__) &&
!<integrated assembler>`. However, Clang does not appear to give us
such a preprocessor macro:

$ clang++ -dM -E - < /dev/null | sort | grep -i as | egrep -v "(FAST|LEAST)"
#define __ATOMIC_RELEASE 3
#define __clang_version__ "3.5.0 (tags/RELEASE_350/final)"
#define __DBL_HAS_DENORM__ 1
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __FLT_HAS_DENORM__ 1
#define __FLT_HAS_INFINITY__ 1
#define __FLT_HAS_QUIET_NAN__ 1
#define __LDBL_HAS_DENORM__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __LDBL_HAS_QUIET_NAN__ 1
#define __VERSION__ "4.2.1 Compatible Clang 3.5.0 (tags/RELEASE_350/final)"

How can we determine when the integrated assembler is being used? How
do we guard the Clang block?



More information about the cfe-users mailing list