C++ - Clang 链接器问题和获取调试信息

发布于 2024-11-28 15:41:25 字数 3121 浏览 1 评论 0原文

我想做C++代码的调试信息分析。 据我了解,Clang 应该能够处理 C++。

我尝试了clang myFile.cpp。 但我得到

clang: error: unable to execute command: program not executable
clang error: linker command failed due to signal 1 (use -v to see invocation).

After set the path for llvm-ld, it部分有效。我的意思是,如果我执行

clang C:myFile.cpp -S -emit-llvm -o -

它会输出一些信息。但 clang myFile.cpp 仍然失败,并出现错误

clang version 2.9 (tags/RELEASE_29/final)
Target: i686-pc-win32
Thread model: posix
 "C:/FrontEnd/llvm/bin/Debug/clang.exe" -cc1 -triple i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name BinarySearch_Kernels.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -momit-leaf-frame-pointer -v -resource-dir C:/FrontEnd/l
lvm/bin/Debug\..\lib\clang\2.9 -ferror-limit 19 -fmessage-length 280 -fcxx-exceptions -fexceptions -fms-extensions -fmsc-version=1300 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o C:/Users/ilipov/AppData/Local/Temp/cc-563130.o -x c++ C:\clang\BinarySearch_Kernels
.cpp
clang -cc1 version 2.9 based upon llvm 2.9 hosted on i686-pc-win32
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/include"
  #include "..." search starts here:
  #include <...> search starts here:
 C:/FrontEnd/llvm/bin/Debug/../lib/clang/2.9/include
 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\\include
End of search list.
 "link.exe" -out:a.out -defaultlib:libcmt -nologo C:/Users/ilipov/AppData/Local/Temp/cc-563130.o
clang: error: unable to execute command: program not executable
clang: error: linker command failed due to signal 1 (use -v to see invocation)

任何情况下,我都想获得 尽可能完整的调试信息

例如,

class stamBase
{
public:
    int get1(){return 2;};
    int get0(){return 0;}
};
class stamDer : public stamBase
{
public:
    int get1(){return 1;}
};
void func()
{
    stamDer d;
    int x = d.get1();
}

得到

target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i686-pc-win32"
%class.stamDer = type { i8 }
define void @_Z4funcv() {
entry:
  %d = alloca %class.stamDer, align 1
  %x = alloca i32, align 4
  %call = call i32 @_ZN7stamDer4get1Ev(%class.stamDer* %d)
  store i32 %call, i32* %x, align 4
  ret void
}
define linkonce_odr i32 @_ZN7stamDer4get1Ev(%class.stamDer* %this) nounwind align 2 {
entry:
  %this.addr = alloca %class.stamDer*, align 4
  store %class.stamDer* %this, %class.stamDer** %this.addr, align 4
  %this1 = load %class.stamDer** %this.addr
  ret i32 1
}

我从对 Clang debug 的调查中 信息代码,我想我也应该得到 stamBase 的信息!

如何正确运行 Clang 以接受完整的调试信息并防止 Clang 错误?

I want to do the analysis of debug information of C++ code.
As I understand, Clang should be able to handle C++.

I tried clang myFile.cpp.
But I get

clang: error: unable to execute command: program not executable
clang error: linker command failed due to signal 1 (use -v to see invocation).

After setting the path for llvm-ld, it partially works. I mean, if I perform

clang C:myFile.cpp -S -emit-llvm -o -

it outputs some information. But it still fails for clang myFile.cpp with error

clang version 2.9 (tags/RELEASE_29/final)
Target: i686-pc-win32
Thread model: posix
 "C:/FrontEnd/llvm/bin/Debug/clang.exe" -cc1 -triple i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name BinarySearch_Kernels.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -momit-leaf-frame-pointer -v -resource-dir C:/FrontEnd/l
lvm/bin/Debug\..\lib\clang\2.9 -ferror-limit 19 -fmessage-length 280 -fcxx-exceptions -fexceptions -fms-extensions -fmsc-version=1300 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o C:/Users/ilipov/AppData/Local/Temp/cc-563130.o -x c++ C:\clang\BinarySearch_Kernels
.cpp
clang -cc1 version 2.9 based upon llvm 2.9 hosted on i686-pc-win32
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/include"
  #include "..." search starts here:
  #include <...> search starts here:
 C:/FrontEnd/llvm/bin/Debug/../lib/clang/2.9/include
 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\\include
End of search list.
 "link.exe" -out:a.out -defaultlib:libcmt -nologo C:/Users/ilipov/AppData/Local/Temp/cc-563130.o
clang: error: unable to execute command: program not executable
clang: error: linker command failed due to signal 1 (use -v to see invocation)

Any case, I want to get as full debug information as possible

For example, for

class stamBase
{
public:
    int get1(){return 2;};
    int get0(){return 0;}
};
class stamDer : public stamBase
{
public:
    int get1(){return 1;}
};
void func()
{
    stamDer d;
    int x = d.get1();
}

I get

target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i686-pc-win32"
%class.stamDer = type { i8 }
define void @_Z4funcv() {
entry:
  %d = alloca %class.stamDer, align 1
  %x = alloca i32, align 4
  %call = call i32 @_ZN7stamDer4get1Ev(%class.stamDer* %d)
  store i32 %call, i32* %x, align 4
  ret void
}
define linkonce_odr i32 @_ZN7stamDer4get1Ev(%class.stamDer* %this) nounwind align 2 {
entry:
  %this.addr = alloca %class.stamDer*, align 4
  store %class.stamDer* %this, %class.stamDer** %this.addr, align 4
  %this1 = load %class.stamDer** %this.addr
  ret i32 1
}

From my investigation of Clang debug information code, I thought that I should get the information for stamBase too!

How can I run Clang correctly for accepting full debug information and preventing Clang errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-12-05 15:41:25

我认为你需要安装一个链接器。 GNU ld 就可以了;您应该能够通过包管理器安装它。

还有一个 LLVM 链接器。它不太受欢迎,但一旦安装了 Clang,它就会开箱即用(只需将其添加到 PATH 并重新运行 clang)。

I think you need to install a linker. GNU ld will be fine; you should be able to install it via your package manager.

There also is an LLVM linker. It is less popular, but it would run out of the box with Clang once installed (just add it to the PATH a rerun clang).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文