5

问题

关于将 Intel Pin 与 C++14 或其他 C++ 版本一起使用,我有几个问题。

  • 用较新版本从较旧的 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 标头内的巨大错误日志中。似乎 Pin 带有它自己的 STL 子集,与 C++11 和 C++14 冲突。我已经上传了g++ 输出的粘贴。它填充了 2331 行,但我注意到它访问的文件夹中有这个奇怪的东西。STL 库包含在2 个不同的目录中:

  • /usr/include/c++/5/
  • /home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/stlport/include/

一个一个地解决错误是不可行的,删除pin stl端口可能是一个更糟糕的主意。如果可以将 Pin 与较新的 C++ 一起使用,我想说简单std=c++1y不是办法。

4

1 回答 1

6

从用于编译 pin 工具的编译器选项来看,我假设您使用的是最新版本的 Pin,即 3.0。据英特尔称,该框架附带的 CRT 不支持 C++11 及更高版本的语言。特别是,您将无法使用 C++11 中支持的任何 API,包括std::mutex. 如果使用 C++11 API 对您很重要,那么您应该使用以前版本的 Pin,即 2.14,它不附带 CRT,而是使用编译器的 CRT。

但是,如果您只需要一个互斥锁,您可以使用 Pin 3.0 附带的操作系统可移植互斥锁。有关详细信息,请参阅文档

使用 Pin 3.0 时,不允许使用编译器的任何头文件或目标文件(来自 的那些/usr/include/c++/5/)。您只能使用 PinCRT 和少数系统头文件。

于 2016-10-03T11:59:32.967 回答