gpt4 book ai didi

c++ - 带有 C++14 的 Intel Pin

转载 作者:太空狗 更新时间:2023-10-29 21:14:49 26 4
gpt4 key购买 nike

问题

关于在 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 header 内的巨大错误日志中。 Pin 似乎带有它自己的 STL 子集,这与 C++11 和 C++14 冲突。我上传了 paste 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 不是办法。

最佳答案

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

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

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

关于c++ - 带有 C++14 的 Intel Pin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39691080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com