Update. Attached is the patch to cpu.h that gets crypto++-5.6.2 compile and
run correctly under Xcode-6.0.1. Attaching my GNUmakefile diff just in case
- it adds quite a bit of customization and support for dynamic linking
under Mac OS X.
Wei, it would be really nice if you could incorporate these changes,
especially the GNUmakefile. It is tiresome to re-enable Mac OS X specifics
with every release. :-)
On Tue, Oct 14, 2014 at 3:35 PM, Mouse <[email protected]> wrote:
> Got a nasty problem: camellia.cpp crashes llvm compiler.
>
> I've submitted a bug report to llvm.com/bugs
> http://llvm.org/bugs/show_bug.cgi?id=21194, and they answered that llvm
> performs exactly as expected, and the problem is with the camellia code:
>
> The user code is incorrect, clang already has the diagnosis. You must pass
> integer constants to assembly with the "i" constraint. You cannot thread
> one through an always_inline function. This is a well-known compatibility
> issue. You have to use a macro. Sorry. :(
>
> ...................
>
> Justin and I discussed this.
>
> Like Reid said, the assertion in LLVM is a fallout from the new diagnostic
> handler, but the errors reported are legit.
>
> If it worked previously, this is likely by accident... Sorry.
>
> To fix the compiler assertion, we would likely need to teach the pass
> manager the notion of a failure in a pass, so that it can stop the
> compilation process, since the MIR is not in the expected shape.
> Previously, the error reporting was aborting directly so we were not seeing
> that, but we would have get just the first error.
>
>
> Here's what the compiler says:
>
> clang++ -DNDEBUG -g -O2 -std=c++11 -ansi -maes -mpclmul -fPIC
> -ffunction-sections -fdata-sections -m64 -arch x86_64
> -DCRYPTOPP_DISABLE_ASM -Wno-tautological-compare -c camellia.cpp
>
> In file included from camellia.cpp:16:
>
> ./cpu.h:34:64: warning: unknown attribute '__artificial__' ignored
>
> [-Wattributes]
>
> __inline int __attribute__((__gnu_inline__, __always_inline__,
> __artificial__))
>
> ^
>
> ./cpu.h:41:68: warning: unknown attribute '__artificial__' ignored
>
> [-Wattributes]
>
> __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __art...
>
> ^
>
> ./cpu.h:38:7: error: invalid operand for inline asm constraint 'i'
>
> asm ("pextrd %2, %1, %0" : "=rm"(r) : "x"(a), "i"(i));
>
> ^
>
> ./cpu.h:44:7: error: invalid operand for inline asm constraint 'i'
>
> asm ("pinsrd %2, %1, %0" : "+x"(a) : "rm"(b), "i"(i));
>
> ^
>
> Assertion failed: (MRI->getVRegDef(reg) && "Register use before def!"),
> function HandleVirtRegUse, file LiveVariables.cpp, line 133.
>
> 0 libLLVM-3.4.dylib 0x000000010b4938e9
> llvm::sys::PrintStackTrace(__sFILE*) + 40
>
> 1 libLLVM-3.4.dylib 0x000000010b493cd9 SignalHandler(int) + 248
>
> 2 libsystem_platform.dylib 0x00007fff89cb25aa _sigtramp + 26
>
> 3 libsystem_platform.dylib 000000000000000000 _sigtramp + 1983175280
>
> 4 libLLVM-3.4.dylib 0x000000010b493b40 abort + 22
>
> 5 libLLVM-3.4.dylib 0x000000010b493b2a abort + 0
>
> 6 libLLVM-3.4.dylib 0x000000010ade57f9
> llvm::LiveVariables::HandleVirtRegUse(unsigned int,
> llvm::MachineBasicBlock*, llvm::MachineInstr*) + 363
>
> 7 libLLVM-3.4.dylib 0x000000010ade708b
> llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&) + 1339
>
> 8 libLLVM-3.4.dylib 0x000000010ae06b60
> llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 48
>
> 9 libLLVM-3.4.dylib 0x000000010af68239
> llvm::FPPassManager::runOnFunction(llvm::Function&) + 297
>
> 10 libLLVM-3.4.dylib 0x000000010af683d1
> llvm::FPPassManager::runOnModule(llvm::Module&) + 41
>
> 11 libLLVM-3.4.dylib 0x000000010af68728
> llvm::legacy::PassManagerImpl::run(llvm::Module&) + 648
>
> 12 clang 0x000000010980b7f4
> clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions
> const&, clang::TargetOptions const&, clang::LangOptions const&,
> llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 5034
>
> 13 clang 0x00000001098e17b0
> clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 422
>
> 14 clang 0x00000001099248c7
> clang::ParseAST(clang::Sema&, bool, bool) + 348
>
> 15 clang 0x00000001098e0ec0
> clang::CodeGenAction::ExecuteAction() + 484
>
> 16 clang 0x000000010970c79b
> clang::FrontendAction::Execute() + 103
>
> 17 clang 0x00000001096efdcf
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 571
>
> 18 clang 0x00000001096c6629
> clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3861
>
> 19 clang 0x00000001096c017a cc1_main(char const**, char
> const**, char const*, void*) + 794
>
> 20 clang 0x00000001096c4c2d main + 6504
>
> 21 libdyld.dylib 0x00007fff937155fd start + 1
>
> 22 libdyld.dylib 0x000000000000003e start + 1821289026
>
> Stack dump:
>
> 0. Program arguments: /opt/local/libexec/llvm-3.4/bin/clang -cc1 -triple
> x86_64-apple-macosx10.9.0 -emit-obj -disable-free -main-file-name
> camellia.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim
> -masm-verbose -munwind-tables -target-cpu core2 -target-feature +aes
> -target-feature +pclmul -target-linker-version 236.3 -gdwarf-2
> -ffunction-sections -fdata-sections -coverage-file
> /Users/ur20980/src/cryptopp-5.6.2-clang/camellia.o -resource-dir
> /opt/local/libexec/llvm-3.4/bin/../lib/clang/3.4.2 -D NDEBUG -D
> CRYPTOPP_DISABLE_ASM -stdlib=libc++ -O2 -Wno-tautological-compare
> -std=c++98 -fdeprecated-macro -fdebug-compilation-dir
> /Users/ur20980/src/cryptopp-5.6.2-clang -ferror-limit 19 -fmessage-length
> 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0
> -fencode-extended-block-signature -fcxx-exceptions -fexceptions
> -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops
> -vectorize-slp -o camellia.o -x c++ camellia.cpp
>
> 1. <eof> parser at end of file
>
> 2. Code generation
>
> 3. Running pass 'Function Pass Manager' on module 'camellia.cpp'.
>
> 4. Running pass 'Live Variable Analysis' on function
> '@_Z16_mm_insert_epi32Dv2_xii'
>
> clang: error: unable to execute command: Illegal instruction: 4
>
> clang: error: clang frontend command failed due to signal (use -v to see
> invocation)
>
> clang version 3.4.2 (tags/RELEASE_34/dot2-final)
>
> Target: x86_64-apple-darwin13.4.0
>
> Thread model: posix
>
> clang: note: diagnostic msg: PLEASE submit a bug report to
> http://llvm.org/bugs/ and include the crash backtrace, preprocessed
> source, and associated run script.
>
> clang: note: diagnostic msg:
>
> ********************
>
>
> PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
>
> Preprocessed source(s) and associated run script(s) are located at:
>
> clang: note: diagnostic msg:
> /var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/camellia-20466f.cpp
>
> clang: note: diagnostic msg:
> /var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/camellia-20466f.sh
>
> clang: note: diagnostic msg:
>
>
> ********************
>
> make: *** [camellia.o] Error 254
>
>
> A solution to this problem/bug would be nice! According to LLVM people,
> those inline functions should be changed to macros...?
> --
> Regards,
> Mouse
>
>
--
Regards,
Mouse
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
--- GNUmakefile.~1~ 2013-03-08 11:29:52.000000000 -0500
+++ GNUmakefile 2014-10-14 16:00:20.000000000 -0400
@@ -1,8 +1,23 @@
-CC = gcc
-C++ = g++
-CXXFLAGS = -DNDEBUG -g -O2
SO = dylib
-DYNAMICLIBFLAGS = -dynamiclib
+LIBLDFLAGS =
+#CC=gcc
+CC=clang
+#CXX=g++
+CXX=clang++
+CXXFLAGS = -DNDEBUG -O3 -Ofast -Wno-unused-value -std=c++11
+CXXFLAGS += -maes -mpclmul
+
+ifeq ($(CXX),g++)
+ CXXFLAGS += -Wa,-q
+ CXXFLAGS += -ansi
+endif
+ifeq ($(CXX),clang++)
+ CXXFLAGS += -mtune=core-avx
+ CXXFLAGS += -msse4.2
+else
+ #CXXFLAGS += -mtune=native
+endif
+
# -O3 fails to link on Cygwin GCC version 4.5.3
# -fPIC is supported. Please report any breakage of -fPIC as a bug.
CXXFLAGS += -fPIC
@@ -11,8 +26,8 @@
# LDFLAGS += -Wl,--gc-sections
ARFLAGS = -cr # ar needs the dash on OpenBSD
RANLIB = ranlib
-CP = cp
-MKDIR = mkdir
+CP = cp -f
+MKDIR = mkdir -p
EGREP = egrep
UNAME = $(shell uname)
ISX86 = $(shell uname -m | $(EGREP) -c "i.86|x86|i86|amd64")
@@ -21,6 +36,9 @@
IS_MINGW = $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -c "mingw")
CLANG_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang
version")
+LDLIBS =
+#LDLIBS += -lstdc++
+
# Default prefix for make install
ifeq ($(PREFIX),)
PREFIX = /usr
@@ -30,6 +48,10 @@
CXX = g++
endif
+#ifeq ($(CXX),g++) # for some reason CXX is gcc on cygwin 1.1.4
+#CXXFLAGS += -maes -mpclmul -mssse3 -msse4.2 -mtune=core-avx2
+#endif
+
ifeq ($(ISX86),1)
GCC42_OR_LATER = $(shell $(CXX) -v 2>&1 | $(EGREP) -c "^gcc version
(4.[2-9]|[5-9])")
@@ -41,10 +63,18 @@
ifneq ($(GCC42_OR_LATER),0)
ifeq ($(UNAME),Darwin)
-CXXFLAGS += -arch x86_64 -arch i386
+ CXXFLAGS += -arch x86_64 # -arch i386
+ LIBLDFLAGS += -dynamiclib
+ SO = dylib
else
CXXFLAGS += -march=native
endif
+else
+ifeq ($(UNAME),Darwin)
+ CXXFLAGS += -arch x86_64 # -arch i386
+ LIBLDFLAGS += -dynamiclib
+ SO = dylib
+endif
endif
ifneq ($(INTEL_COMPILER),0)
@@ -76,7 +106,7 @@
ifeq ($(UNAME),) # for DJGPP, where uname doesn't exist
CXXFLAGS += -mbnu210
else
-CXXFLAGS += -pipe
+#CXXFLAGS += -pipe
endif
ifeq ($(IS_MINGW),1)
@@ -93,10 +123,11 @@
ifeq ($(UNAME),Darwin)
AR = libtool
ARFLAGS = -static -o
-CXX = c++
+#CXX = c++
IS_GCC2 = $(shell $(CXX) -v 2>&1 | $(EGREP) -c gcc-932)
ifeq ($(IS_GCC2),1)
CXXFLAGS += -fno-coalesce-templates -fno-coalesce-static-vtables
+#LDLIBS += -L/usr/lib -lstdc++
LDLIBS += -lstdc++
LDFLAGS += -flat_namespace -undefined suppress -m
endif
@@ -144,6 +175,7 @@
all: cryptest.exe
static: libcryptopp.a
dynamic: libcryptopp.$(SO)
+shared: dynamic
test: cryptest.exe
./cryptest.exe v
@@ -151,12 +183,13 @@
clean:
-$(RM) cryptest.exe libcryptopp.a libcryptopp.$(SO) $(LIBOBJS)
$(TESTOBJS) cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
cryptest.import.exe dlltest.exe $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTI MPORTOBJS)
$(DLLTESTOBJS)
-install:
+install: libcryptopp.a
$(MKDIR) -p $(PREFIX)/include/cryptopp $(PREFIX)/lib $(PREFIX)/bin
-$(CP) *.h $(PREFIX)/include/cryptopp
-$(CP) *.a $(PREFIX)/lib
- -$(CP) *.$(SO) $(PREFIX)/lib
+ -$(RANLIB) $(PREFIX)/lib/libcryptopp.a
-$(CP) *.exe $(PREFIX)/bin
+ -$(CP) *.$(SO) $(PREFIX)/lib
remove:
-$(RM) -rf $(PREFIX)/include/cryptopp
@@ -169,7 +202,7 @@
$(RANLIB) $@
libcryptopp.$(SO): $(LIBOBJS)
- $(CXX) -shared $(DYNAMICLIBFLAGS) -o $@ $(LIBOBJS)
+ $(CXX) -shared $(LIBLDFLAGS) -o $@ $(LIBOBJS)
cryptest.exe: libcryptopp.a $(TESTOBJS)
$(CXX) -o $@ $(CXXFLAGS) $(TESTOBJS) ./libcryptopp.a $(LDFLAGS)
$(LDLIBS)
--- cpu.h.~1~ 2010-08-06 17:46:18.000000000 -0400
+++ cpu.h 2014-10-14 15:58:21.000000000 -0400
@@ -8,7 +8,7 @@
#define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1
#define NAMESPACE_END
-#else
+#else // not CRYPTOPP_GENERATE_X64_MASM
#include "config.h"
@@ -17,7 +17,8 @@
#endif
#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
-#if !defined(__GNUC__) || defined(__SSSE3__) || defined(__INTEL_COMPILER)
+
+#if !defined(__GNUC__) || defined(__SSSE3__) || defined(__INTEL_COMPILER) ||
defined(__clang__)
#include <tmmintrin.h>
#else
__inline __m128i __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
@@ -27,7 +28,7 @@
return a;
}
#endif
-#if !defined(__GNUC__) || defined(__SSE4_1__) || defined(__INTEL_COMPILER)
+#if !defined(__GNUC__) || defined(__SSE4_1__) || defined(__INTEL_COMPILER) ||
defined(__clang__)
#include <smmintrin.h>
#else
__inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
@@ -44,7 +45,7 @@
return a;
}
#endif
-#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) ||
defined(__INTEL_COMPILER)
+#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__) &&
defined(__clang__)) || defined(__INTEL_COMPILER)
#include <wmmintrin.h>
#else
__inline __m128i __attribute__((__gnu_inline__, __always_inline__,
__artificial__))