clang and Crypto++

After Doug fixed bug #7851 yesterday (thanks, Doug!), I decided to see if crypto++ <http://www.cryptopp.com/&gt; would build with clang TOT.

Answer: No, it does not.

There are three problems:

1) the crypto++ sources make unqualified calls to member functions in base classes; clang flags this as an error.

clang++ -DNDEBUG -g -O2 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c panama.cpp
panama.cpp:425:2: error: use of undeclared identifier 'PadLastBlock'
       PadLastBlock(this->BLOCKSIZE, 0x01);
       ^
       this->
panama.cpp:500:22: note: in instantiation of member function
     'CryptoPP::Weak::PanamaHash<CryptoPP::EnumToType<CryptoPP::ByteOrder, 1>

::TruncatedFinal' requested here

template class Weak::PanamaHash<BigEndian>;
                    ^
In file included from panama.cpp:9:
In file included from ./panama.h:5:
./iterhash.h:38:7: note: must qualify identifier to find this declaration in dependent
     base class
       void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80);
            ^
panama.cpp:425:2: error: no member named 'PadLastBlock' in
     'CryptoPP::Weak::PanamaHash<LittleEndian>'
       PadLastBlock(this->BLOCKSIZE, 0x01);
       ^~~~~~~~~~~~
panama.cpp:501:22: note: in instantiation of member function
     'CryptoPP::Weak::PanamaHash<CryptoPP::EnumToType<CryptoPP::ByteOrder, 0>

::TruncatedFinal' requested here

template class Weak::PanamaHash<LittleEndian>;
                    ^
In file included from panama.cpp:9:
In file included from ./panama.h:4:
In file included from ./strciphr.h:31:
In file included from ./seckey.h:9:

This is easy to fix in crypto++; just follow the fixit hint (and I have submitted these changes to the crypto++ project)

2) clang asserts when compiling vmac.cpp <http://llvm.org/bugs/show_bug.cgi?id=8913&gt;

3) clang is much, much slower than gcc 4.2.1 when building crypto++.
On my 2007 MacPro:
  gcc takes 8m40s to build.
  clang (TOT this morning) takes much longer; there is one file - sha.cpp which takes over 30 minutes, if it ever does finish, but all the other files combined take more than 45 minutes.

I'm quite happy to provide the modified crypto++ distro in case anyone else is interested in pursuing this.

-- Marshall

After Doug fixed bug #7851 yesterday (thanks, Doug!), I decided to see if crypto++ <http://www.cryptopp.com/&gt; would build with clang TOT.

Answer: No, it does not.

There are three problems:

1) the crypto++ sources make unqualified calls to member functions in base classes; clang flags this as an error.

clang++ -DNDEBUG -g -O2 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c panama.cpp
panama.cpp:425:2: error: use of undeclared identifier 'PadLastBlock'
      PadLastBlock(this->BLOCKSIZE, 0x01);
      ^
      this->
panama.cpp:500:22: note: in instantiation of member function
    'CryptoPP::Weak::PanamaHash<CryptoPP::EnumToType<CryptoPP::ByteOrder, 1>

::TruncatedFinal' requested here

template class Weak::PanamaHash<BigEndian>;
                   ^
In file included from panama.cpp:9:
In file included from ./panama.h:5:
./iterhash.h:38:7: note: must qualify identifier to find this declaration in dependent
    base class
      void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80);
           ^
panama.cpp:425:2: error: no member named 'PadLastBlock' in
    'CryptoPP::Weak::PanamaHash<LittleEndian>'
      PadLastBlock(this->BLOCKSIZE, 0x01);
      ^~~~~~~~~~~~
panama.cpp:501:22: note: in instantiation of member function
    'CryptoPP::Weak::PanamaHash<CryptoPP::EnumToType<CryptoPP::ByteOrder, 0>

::TruncatedFinal' requested here

template class Weak::PanamaHash<LittleEndian>;
                   ^
In file included from panama.cpp:9:
In file included from ./panama.h:4:
In file included from ./strciphr.h:31:
In file included from ./seckey.h:9:

This is easy to fix in crypto++; just follow the fixit hint (and I have submitted these changes to the crypto++ project)

2) clang asserts when compiling vmac.cpp <http://llvm.org/bugs/show_bug.cgi?id=8913&gt;

This looks like an easy fix for someone familiar with LLVM's debug info generator.

3) clang is much, much slower than gcc 4.2.1 when building crypto++.
On my 2007 MacPro:
  gcc takes 8m40s to build.
  clang (TOT this morning) takes much longer; there is one file - sha.cpp which takes over 30 minutes, if it ever does finish, but all the other files combined take more than 45 minutes.

Naturally, we'd like to know where in clang this time is going. Is it the front end (-fsyntax-only)? The optimizer (> -O0), and if so, which one(s)?

  - Doug

After Doug fixed bug #7851 yesterday (thanks, Doug!), I decided to see if crypto++ <http://www.cryptopp.com/&gt; would build with clang TOT.

Answer: No, it does not.

There are three problems:

[ #1 and #2 snipped out ]

3) clang is much, much slower than gcc 4.2.1 when building crypto++.
On my 2007 MacPro:
  gcc takes 8m40s to build.
  clang (TOT this morning) takes much longer; there is one file - sha.cpp which takes over 30 minutes, if it ever does finish, but all the other files combined take more than 45 minutes.

Naturally, we'd like to know where in clang this time is going. Is it the front end (-fsyntax-only)? The optimizer (> -O0), and if so, which one(s)?

Looks like the optimizer.

$ time clang++ -Wno-tautological-compare -DNDEBUG -g -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -fsyntax-only sha.cpp
real 6.234s
$ time clang++ -Wno-tautological-compare -DNDEBUG -g -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
real 7.863s
$ time clang++ -Wno-tautological-compare -DNDEBUG -g -O1 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
real 17.882s
$ time clang++ -Wno-tautological-compare -DNDEBUG -g -O2 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
.... long, long time; I killed it after 30 minutes.

How do I tell which one?

-- Marshall

FWIW, it's not all about the optimizer:
$ time g++ -DNDEBUG -g -O2 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
real 1.662s

-- Marshall

I'm guessing one of the loop ones, but if you file a bug with a preprocessed file we'll figure it out.

Thanks!

-eric

Probably 2 bugs then :slight_smile:

-eric

Try passing -ftime-report to clang. Another silly question: did you build clang itself in debug mode? The first few lines of:

$ clang -cc1 -version

Should show either:

Low Level Virtual Machine (http://llvm.org/):
  llvm version 2.9svn
  DEBUG build with assertions.

or:

Low Level Virtual Machine (http://llvm.org/):
  llvm version 2.9svn
  Optimized build.

-Chris

Done.
  <http://llvm.org/bugs/show_bug.cgi?id=8916&gt; for the optimizer
  <http://llvm.org/bugs/show_bug.cgi?id=8917&gt; for the front end.

-- Marshall

D'oh! It's a debug build.
I will build a non-debug one and re-run the timings.

-- Marshall

clang -cc1 -version:
Low Level Virtual Machine (http://llvm.org/):
llvm version 2.9
Optimized build with assertions.

svn 122890

time clang++ -Wno-tautological-compare -DNDEBUG -g -O3
-DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp:

real 0m1.989s
user 0m1.964s
sys 0m0.024s

Everything's ok over here. :slight_smile:

g

Naturally, we'd like to know where in clang this time is going. Is it the front end (-fsyntax-only)? The optimizer (> -O0), and if so, which one(s)?

Looks like the optimizer.

$ time clang++ -Wno-tautological-compare -DNDEBUG -g -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -fsyntax-only sha.cpp
real 6.234s
$ time clang++ -Wno-tautological-compare -DNDEBUG -g -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
real 7.863s
$ time clang++ -Wno-tautological-compare -DNDEBUG -g -O1 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
real 17.882s
$ time clang++ -Wno-tautological-compare -DNDEBUG -g -O2 -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c sha.cpp
.... long, long time; I killed it after 30 minutes.

How do I tell which one?

Try passing -ftime-report to clang. Another silly question: did you build clang itself in debug mode? The first few lines of:

$ clang -cc1 -version

Should show either:

Low Level Virtual Machine (http://llvm.org/):
llvm version 2.9svn
DEBUG build with assertions.

or:

Low Level Virtual Machine (http://llvm.org/):
llvm version 2.9svn
Optimized build.

D'oh! It's a debug build.
I will build a non-debug one and re-run the timings.

I've closed bug #8917 (slower than gcc) with a "pilot error" notation.