【发布时间】:2017-02-03 02:28:36
【问题描述】:
问题
关于将 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++ 输出的paste。它填充了 2331 行,但我注意到它访问的文件夹中有这个奇怪的东西。 STL 库包含在 2 个不同的目录中:
/usr/include/c++/5//home/gabriel/Downloads/pin-3.0-76991-gcc-linux/extras/stlport/include/
逐个解决错误是不可行的,删除pin stl端口可能是一个更糟糕的主意。如果可以在较新的 C++ 中使用 Pin,我会说简单的 std=c++1y 不是办法。
【问题讨论】:
-
错误消息暗示了您的最后一个问题:传递
-std=c++11以获得C++ 2011 支持。对于 C++ 2014 支持,请使用-std=c++14。 -
问题是英特尔 Pin 需要大量的编译器选项。因此,他们制定了规则,通过 make 使其变得简单。我不知道如何在规则中包含此选项。还在找。
-
我的知识有点过时了,但我会小心地将任何同步原语添加到 Pintool 中,这些原语没有随 Pin 套件一起提供。调用它们可能无法按预期工作。相反,请使用 Pin 套件提供的同步原语、PinCRT API 或同步共享对象的链接。
-
我知道有一些努力使 Pin 与更高级的 C++ 一起工作 - 查找 Pin++。
-
@nitzanms 实际上,具有如此敏感指令集的同步指令绝对是一件危险的事情。我没有使用它,但我仍然对更新的 C++ 和 Pin 感到好奇,所以我决定继续讨论
标签: c++ c++11 gcc c++14 intel-pin