我有来自http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe的 clang 3.9
clang version 3.9.0 (branches/release_39)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
Run Code Online (Sandbox Code Playgroud)
和gcc 6.2.0(Mingw-w64)
gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
我的PC上没有安装MSVC,也没有安装Windows SDK.我需要clang的一些特殊功能,我想用gcc替换它,更具体地说用g ++替换它因为我使用C++.
当我尝试编译简单文件时,我得到:
致命错误:找不到'string'文件
这是否意味着我目前的clang安装不支持windows上的mingw?基本上我只想使用mingw-w64安装中的头文件和库.我一直在寻找解决方案而没有找到任何东西.我不知道该怎么办.
这是否也意味着我的clang安装取决于我没有的MSVC?
编辑: 从本页面的评论:http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/
这不再适用于LLVM的最新二进制文件(3.7.1,3.8,3.9),因为它们是使用Visual Studio和Visual Studio编译的.
您可以安装完整的Visual Studio 2015(大约8GB)或安装"Microsoft Visual C++ Build Tools 2015 Update …
如果要转换uint64_t为uint8_t[8](小尾数)。在小端架构上,您可以执行ug reinterpret_cast<>或memcpy(),例如:
void from_memcpy(const std::uint64_t &x, uint8_t* bytes) {
std::memcpy(bytes, &x, sizeof(x));
}
Run Code Online (Sandbox Code Playgroud)
这将产生有效的组装:
mov rax, qword ptr [rdi]
mov qword ptr [rsi], rax
ret
Run Code Online (Sandbox Code Playgroud)
但是,它不是便携式的。在一点字节序的机器上它将具有不同的行为。
要转换uint8_t[8]成uint64_t一个很好的解决方案-只需执行以下操作:
mov rax, qword ptr [rdi]
mov qword ptr [rsi], rax
ret
Run Code Online (Sandbox Code Playgroud)
这看起来效率低下,但实际上使用Clang时,-O2它会生成与以前完全相同的程序集,如果在大型字节序计算机上进行编译,它将足够聪明以使用本机字节交换指令。例如此代码:
void to(const std::uint8_t* bytes, std::uint64_t &x) {
x = (std::uint64_t(bytes[0]) << 8*0) |
(std::uint64_t(bytes[1]) << 8*1) |
(std::uint64_t(bytes[2]) << 8*2) |
(std::uint64_t(bytes[3]) << 8*3) |
(std::uint64_t(bytes[4]) << 8*4) …Run Code Online (Sandbox Code Playgroud) 我试图使用LLVM的C接口反汇编一些字节.但是LLVMCreateDisasm()返回NULL.
#include <stdio.h> // printf()
#include <stdlib.h> // EXIT_FAILURE, EXIT_SUCCESS
#define __STDC_CONSTANT_MACROS // llvm complains otherwise
#define __STDC_LIMIT_MACROS
#include <llvm-c/Disassembler.h>
int main()
{
LLVMDisasmContextRef dc = LLVMCreateDisasm (
"testname",
NULL,
0,
NULL,
NULL
);
if (dc == NULL) {
printf("Could not create disassembler");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
我在x64 Linux上.查看文档似乎我正在做的一切正确.
LLVMDisasmContextRef LLVMCreateDisasm (
const char * TripleName,
void * DisInfo,
int TagType,
LLVMOpInfoCallback GetOpInfo,
LLVMSymbolLookupCallback SymbolLookUp
)
Run Code Online (Sandbox Code Playgroud)
为TripleName创建反汇编程序.通过在DisInfo参数中传递信息块并指定TagType和回调函数来支持符号反汇编,如上所述.这些都可以作为NULL传递.如果成功,则返回反汇编程序上下文.如果不是,则返回NULL.
printf在lib/MC/MCDisassembler/Disassembler.cpp:LLVMCreateDisasmCPU()中插入,并在首次 …
clang当使用和选项进行交叉编译时-target,针对与本机系统相同的体系结构和硬件,我注意到对于三元组中的 是 的clang情况,似乎会产生比本机构建的对应部分更糟糕的优化。<sys>none
考虑这个简单的代码示例:
int square(int num) {
return num * num;
}
Run Code Online (Sandbox Code Playgroud)
当-O3使用进行优化时-target x86_64-linux-elf,本机x86_64目标代码生成结果为:
square(int):
mov eax, edi
imul eax, edi
ret
Run Code Online (Sandbox Code Playgroud)
生成的代码的-target x86_64-none-elf产量:
square(int):
push rbp
mov rbp, rsp
mov eax, edi
imul eax, edi
pop rbp
ret
Run Code Online (Sandbox Code Playgroud)
尽管具有相同的硬件和优化标志,但显然有些东西缺少优化。尽管没有使用特定于系统的功能,但如果在目标三元组中none替换为,问题就会消失。linux
乍一看,它可能看起来根本没有优化,但不同的代码段表明它正在执行一些优化,但不是全部。例如,循环展开仍在发生。
尽管上面的示例只是使用 x86_64,但实际上,这个问题正在为armv7基于 的受限嵌入式系统生成代码膨胀,并且我注意到在某些情况下存在一些错过的优化,例如:
add指令中(在类似-Os …我正在尝试使用getrust 向 url 发出请求,每次运行此项目时都会收到此错误,而我的其他 rust 项目工作正常。这是我的cargo.toml文件。
[package]
name = "api_req"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"]}
Run Code Online (Sandbox Code Playgroud)
这是我尝试构建/运行代码时得到的输出。
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
|
= note: "x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "C:\\Users\\sahil\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\self-contained\\crt2.o" "C:\\Users\\sahil\\.rustup\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "C:\\Users\\sahil\\CLionProjects\\coc-rs\\target\\debug\\deps\\coc_rs-6b97e9afad26cc80.1ax3t6bk8kjti15h.rcgu.o" …Run Code Online (Sandbox Code Playgroud) 为了使用 Xcode 将编译器选项迁移到 ARM,我正在寻找有关 clang c++ 编译器/链接器选项的综合文档。我能得到的最接近的是这个页面,但是:
-arch,-arch_errors_fatal,-sub_umbrella等等。-Wno-four-char-constants,-Wshorten-64-to-32等等。有什么地方可以找到对每个选项都有详尽解释的完整文档吗?请注意,我不需要在这里作为示例给出的选项的含义,仅用于综合参考。
I\xe2\x80\x99m 尝试使用基于 LLVM 的zig cc为 R4300i / VR4300 MIPS CPU(N64 中的处理器)编译 C 代码(最终还有其他基于 LLVM 的语言,如 Rust/Zig)。但我没有看到任何以 VR4300 作为目标进行编译的证据或示例:
zig targets。LLVM不支持VR4300作为编译目标吗?我怎样才能自己发现这一点?
\nclang ×5
c++ ×3
llvm ×3
c ×2
rust ×2
disassembly ×1
endianness ×1
file-io ×1
gcc ×1
migration ×1
mingw ×1
mips ×1
optimization ×1
rust-cargo ×1
rust-tokio ×1
windows ×1
xcode ×1
zig ×1