0

I have a MacPorts GCC compiler installed, and I have a MacPorts Clang installed for the integrated assembler:

$ port installed | egrep -i '(gcc|g\+\+|clang)'
  clang-3.8 @3.8-r262722_1+analyzer (active)
  clang_select @1.0_0 (active)
  gcc49 @4.9.3_0 (active)
  gcc_select @0.1_8 (active)
  libgcc @6.1.0_0 (active)

When I attempt to compile an empty program using the integrated assembler:

$ cat test.cc 
int main(int argc, char* argv[])
{
    return argc;
}

It results in an error:

$ /opt/local//bin/gcc-mp-4.9 -Wa,-q -march=native test.cc -o test.exe
/opt/local/bin/as: assembler (/opt/local/bin/clang) not installed

And:

$ ls /opt/local/bin/clang
ls: /opt/local/bin/clang: No such file or directory

It appears there more to using the integrated assembler than just -Wa,-q. If I omit -Wa,-q, then the real program experiences a failure similar to How to use AVX/pclmulqdq on Mac OS X.

How do I tell the GCC compiler to use the integrated assembler from the installed Clang? I.e., clang++ -Wa,-q -Wa,as=/opt/local/bin/clang-mp-3.8

Or, do these things need to be installed in pairs where the version numbers matter? I.e., something like GCC 4.9 (JAN 2016) needs Clang 3.7 (JAN 2016)?

Or, what compiler does MacPorts normally place at /opt/local/bin/clang? E.g., Clang 3.5 is normally placed at /opt/local/bin/clang


For completeness, this MacBook has MacPorts, but its not on path. I use the MBP for OS X testing, and a second role is [soon to be] MacPorts testing. However, I've refrained from putting MacPorts on path to avoid tainting OS X testing.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

3 Answers3

2

You can simply do sudo port select clang mp-clang-3.8. I did not like this, because it makes this the default when simply calling clang (only if MacPorts is on the PATH, of course).

What I ended up doing is to replace /opt/local/bin/as with the following simple script:

#!/bin/sh 
clang -c -x assembler $@ - 

And then I don't use the -Wa,-q arguments to gcc.

m7thon
  • 3,033
  • 1
  • 11
  • 17
  • Oh, good idea. My next thought is I don't want to avoid `-Wa,-q` because we want to test it. We have users in the "MacPorts/GCC with Clang/Assembler" configuration, and we recently [took a related bug report](http://github.com/weidai11/cryptopp/issues/190). So, can we use your clever hack *and* use `-Wa,-q`? – jww Jun 20 '16 at 02:09
  • Well, sure. You can do `sudo port select clang mp-clang-3.8` *and* replace `/opt/local/bin/as` by a script. If you pass `-Wa,-q`, then `gcc` will call the clang assembler directly, and without it will call `as`, which refers to `clang`. The script gives you more control over which `clang` is called, though, e.g., you can put `/usr/bin/clang` explicitly. – m7thon Jun 20 '16 at 11:53
  • Also, FYI, there is a more fancy script to replace `as` around [here](https://gist.github.com/xianyi/2957847). But the simple version above did it for me. – m7thon Jun 20 '16 at 12:03
2

One doesn't need to mess with the compiler options (-Wa,-q) in order to switch to the clang integrated assembler. The same behaviour can be triggered setting the AS_INTEGRATED_ASSEMBLER environment variable as I explained here.

1

I am pretty sure the versions don't need to match. But I'm afraid that Macports has to be on the path for these to work. More so, I'm afraid you'd have to "port select" gcc...

Here's my setup that works:

$ port select --list clang
Available versions for clang:
    apple-clang (active)
    mp-clang-3.7
    none
    uri-clang
$ ll /opt/local/bin/clang
lrwxr-xr-x  1 root  admin  14 Jan 21  2015 /opt/local/bin/clang@ ->    /usr/bin/clang
$ port select --list gcc
Available versions for gcc:
    apple-gcc
    mp-gcc6 (active)
    none
$ ll /opt/local/bin/gcc
lrwxr-xr-x  1 root  admin  23 May  6 17:13 /opt/local/bin/gcc@ -> /opt/local/bin/gcc-mp-6
$ file /opt/local/bin/as
/opt/local/bin/as: Mach-O 64-bit executable x86_64
$ port provides /opt/local/bin/as
/opt/local/bin/as is provided by: cctools
$ $ port dependents cctools
gcc6 depends on cctools
libgcc depends on cctools
$

Try just symlink'ing /usr/bin/clang to /opt/local/bin/clang (same for /usr/bin/clang++) and see if it helps. And make sure cctools port is installed (though I can't imagine it not being there, as either gcc or clang depends on it).

And AFAIK, "-Wa,-q" is the way to tell GCC to use the native assembler (at least it has been working for me since Xcode-6 and GCC-4.8).

Mouse
  • 542
  • 6
  • 9
  • But you could set PATH for one test, and change it for the next one? – Mouse Jun 18 '16 at 04:07
  • Alas, I don't. One might _conjecture_ that if `port` executable resides in `/opt/local/bin`, then probably `/opt/local` is your Macports installation directory. But this is probably not fool-proof. :-( – Mouse Jul 05 '16 at 01:31