带有 C++14 的 Intel Pin
Intel Pin with C++14
问题
我有几个关于使用 C++14 或其他 C++ 版本的 Intel Pin 的问题。
- 用较新版本编译旧 C++ 的代码很少有任何问题,但由于 Intel Pin 是操纵指令级别的,如果我用 C++11 或 C++ 编译它,是否会产生任何不良副作用14?
- 如果可以使用 C++11 或 C++14 进行编译,我该如何制定规则以仅为我的工具启用较新版本的 C++?
- 如何将 GCC/G++ 默认 C++ 版本设置为最新,如果 可能,这样做时我应该记住什么?
情况
我正在构建动态调用图 pin 工具。为了使其易于理解,我正在计算调用堆栈的深度。为了安全起见,我决定用 std::mutex
包装增加或减少深度的代码摘录。这让我遇到了 std::mutex
仅在 C++11 之后才可用的问题,这在我的机器中不是默认的 Intel Pin。
$ g++ -v
[...]
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)
编译命令:
$ make obj-intel64/callgraph.so
[...]
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support
[...]
编辑
我设法制定了一个将版本定义为 C++11 的构建规则,但它失败了。通过 make 发送到 g++ 的命令是
g++ -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1
-DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables
-fasynchronous-unwind-tables -fno-rtti -DTARGET_IA32E -DHOST_IA32E -fPIC
-DTARGET_LINUX -fabi-version=2 -I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/source/include/pin
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/source/include/pin/gen
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/stlport/include
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/libstdc++/include
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include/arch-x86_64
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include/kernel/uapi
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include/kernel/uapi/asm-x86
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/components/include
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/xed-intel64/include
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/source/tools/InstLib -O3
-fomit-frame-pointer -fno-strict-aliasing -std=c++11
-c -o obj-intel64/callgraph.o callgraph.cpp
这无法编译。相反,它会落入 STL headers 中的巨大错误日志中。 Pin 似乎带有它自己的 STL 子集,这与 C++11 和 C++14 冲突。我已经上传了 g++ 输出的 paste。它填充了 2331 行,但我注意到它访问的文件夹中有奇怪的东西。 STL 库来自 2 个不同的目录:
/usr/include/c++/5/
/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/stlport/include/
解决错误 one-by-one 是不可行的,删除 pin stl 端口可能是一个更糟糕的主意。如果可以将 Pin 与较新的 C++ 一起使用,我会说简单 std=c++1y
不是办法。
从编译pin工具的编译器选项来看,我推测你使用的是最新版本的pin,即3.0。根据 Intel,框架附带的 CRT 不支持 C++11 及更高版本的语言。特别是,您将无法使用 C++11 中支持的任何 API,包括 std::mutex
。如果使用 C++11 API 对您来说很重要,那么您应该使用以前版本的 Pin,即 2.14,它不附带 CRT,而是使用编译器的 CRT。
但是,如果您只需要一个互斥锁,您可以使用 Pin 3.0 附带的 OS-便携式互斥锁。有关详细信息,请参阅 documentation.
使用 Pin 3.0 时,不允许使用编译器的任何头文件或目标文件(来自 /usr/include/c++/5/
的)。只能使用PinCRT和少量系统头文件。
问题
我有几个关于使用 C++14 或其他 C++ 版本的 Intel Pin 的问题。
- 用较新版本编译旧 C++ 的代码很少有任何问题,但由于 Intel Pin 是操纵指令级别的,如果我用 C++11 或 C++ 编译它,是否会产生任何不良副作用14?
- 如果可以使用 C++11 或 C++14 进行编译,我该如何制定规则以仅为我的工具启用较新版本的 C++?
- 如何将 GCC/G++ 默认 C++ 版本设置为最新,如果 可能,这样做时我应该记住什么?
情况
我正在构建动态调用图 pin 工具。为了使其易于理解,我正在计算调用堆栈的深度。为了安全起见,我决定用 std::mutex
包装增加或减少深度的代码摘录。这让我遇到了 std::mutex
仅在 C++11 之后才可用的问题,这在我的机器中不是默认的 Intel Pin。
$ g++ -v
[...]
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)
编译命令:
$ make obj-intel64/callgraph.so
[...]
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support
[...]
编辑
我设法制定了一个将版本定义为 C++11 的构建规则,但它失败了。通过 make 发送到 g++ 的命令是
g++ -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1
-DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables
-fasynchronous-unwind-tables -fno-rtti -DTARGET_IA32E -DHOST_IA32E -fPIC
-DTARGET_LINUX -fabi-version=2 -I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/source/include/pin
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/source/include/pin/gen
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/stlport/include
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/libstdc++/include
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include/arch-x86_64
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include/kernel/uapi
-isystem /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/crt/include/kernel/uapi/asm-x86
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/components/include
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/xed-intel64/include
-I/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/source/tools/InstLib -O3
-fomit-frame-pointer -fno-strict-aliasing -std=c++11
-c -o obj-intel64/callgraph.o callgraph.cpp
这无法编译。相反,它会落入 STL headers 中的巨大错误日志中。 Pin 似乎带有它自己的 STL 子集,这与 C++11 和 C++14 冲突。我已经上传了 g++ 输出的 paste。它填充了 2331 行,但我注意到它访问的文件夹中有奇怪的东西。 STL 库来自 2 个不同的目录:
/usr/include/c++/5/
/home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/stlport/include/
解决错误 one-by-one 是不可行的,删除 pin stl 端口可能是一个更糟糕的主意。如果可以将 Pin 与较新的 C++ 一起使用,我会说简单 std=c++1y
不是办法。
从编译pin工具的编译器选项来看,我推测你使用的是最新版本的pin,即3.0。根据 Intel,框架附带的 CRT 不支持 C++11 及更高版本的语言。特别是,您将无法使用 C++11 中支持的任何 API,包括 std::mutex
。如果使用 C++11 API 对您来说很重要,那么您应该使用以前版本的 Pin,即 2.14,它不附带 CRT,而是使用编译器的 CRT。
但是,如果您只需要一个互斥锁,您可以使用 Pin 3.0 附带的 OS-便携式互斥锁。有关详细信息,请参阅 documentation.
使用 Pin 3.0 时,不允许使用编译器的任何头文件或目标文件(来自 /usr/include/c++/5/
的)。只能使用PinCRT和少量系统头文件。