使用 Rust 构建的 DLL 在运行时是否需要 libgcc.dll? [英] Do DLLs built with Rust require libgcc.dll on run time?

查看:82
本文介绍了使用 Rust 构建的 DLL 在运行时是否需要 libgcc.dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 Rust 语言 构建 DLL,是否需要存在 libgcc*.dll在运行时?

一方面:

  • 我在互联网上的某个地方看到过一个帖子,声称是的;
  • rustc.exe 在其目录中有 libgcc_s_dw2-1.dll,下载时没有 dll,cargo.exe 将无法运行来自 http://crates.io 网站;

另一方面:

  • 我看过有关在 Rust 中构建玩具操作系统内核的文章,因此它们肯定不需要存在 libgcc 动态库.

所以,我很困惑.确切的答案是什么?

解决方案

Rust 为 Windows 提供了两个主要工具链:x86_64-pc-windows-gnux86_64-pc-windows-msvc.

-gnu 工具链包括一个 msys 环境并使用 GCC 的 ld.exe 来链接目标文件.此工具链要求 libgcc*.dll 在运行时存在.这个工具链的主要优点是它允许您链接到其他 msys 提供的库,这可以更容易地链接某些在普通 Windows 环境下难以链接的 C\C++ 库.>

-msvc 工具链使用标准的原生 Windows 开发工具(Windows SDK 安装或 Visual Studio 安装).此工具链在编译或运行时都不使用 libgcc*.dll.由于此工具链使用普通的 Windows 链接器,您可以自由地链接任何普通的 Windows 本机库.

如果您需要面向 32 位 Windows,可以使用这两个工具链的 i686- 变体.

<小时>

注意:以下答案总结了截至 2014 年 9 月的情况;我不知道它是否仍然是最新的,或者从那时起事情是否变得更好或更糟.但我强烈怀疑事情已经发生了变化,因为从那时起已经过去了 2 年.如果有人再次询问 steveklabnik,然后更新以下信息,或者写一个新的、更新鲜的答案,那就太好了!

<小时>

快速&与 steveklabnik 的 Rust IRC 聊天的原始记录,他给了我一种答案:

<块引用><块引用>

嗨;我有一个问题:如果我用 Rust 构建一个 DLL,它是否需要在运行时存在 libgcc*.dll?(在 Windows 上)

相信如果你使用标准库,那么它确实需要它;IIRC 我们依赖于它的 one 符号;但我不确定.

<块引用>

我怎样才能避免使用标准库,或者它的那些部分?(和/或您确切知道哪个符号?)

它涉及到 #[no_std] 在你的 crate 根;我认为不安全指南有更多内容.

运行 nm -D |grep gcc 向我展示了 __gc_personality_v0,然后是这个:__gxx_personality_v0 有什么用?一>,所以看起来我们的堆栈展开实现依赖于此.

<块引用>

我似乎记得我也看过一些关于拆分标准库效果的 RFC;有没有我可以在不引入 libgcc 的情况下使用的部分?

是的,libcore 不需要任何这些.你放弃了libstd.

另外,引用不安全指南的部分内容:

<块引用>

核心库 (libcore) 的依赖项非常少,而且比标准库 (libstd) 本身更具可移植性.此外,核心库具有编写惯用且有效的 Rust 代码所需的大部分功能.(……)其他库(例如 liballoc)为 libcore 添加了功能,这些功能做出了其他特定于平台的假设,但仍然比标准库本身更具可移植性.

当前用于展开模块的文档的片段::><块引用>

目前 Rust 使用 libgcc 提供的 unwind 运行时.

(为了便于阅读,对成绩单进行了轻微编辑.不过,如果有人提供格式更好、更全面的内容,我很乐意删除此答案!)

If I build a DLL with Rust language, does it require libgcc*.dll to be present on run time?

On one hand:

  • I've seen a post somewhere on the Internet, claiming that yes it does;
  • rustc.exe has libgcc_s_dw2-1.dll in its directory, and cargo.exe won't run without the dll when downloaded from the http://crates.io website;

On the other hand:

  • I've seen articles about building toy OS kernels in Rust, so they most certainly don't require libgcc dynamic library to be present.

So, I'm confused. What's the definite answer?

解决方案

Rust provides two main toolchains for Windows: x86_64-pc-windows-gnu and x86_64-pc-windows-msvc.

The -gnu toolchain includes an msys environment and uses GCC's ld.exe to link object files. This toolchain requires libgcc*.dll to be present at runtime. The main advantage of this toolchain is that it allows you to link against other msys provided libraries which can make it easier to link with certain C\C++ libraries that are difficult to under the normal Windows environment.

The -msvc toolchain uses the standard, native Windows development tools (either a Windows SDK install or a Visual Studio install). This toolchain does not use libgcc*.dll at either compile or runtime. Since this toolchain uses the normal windows linker, you are free to link against any normal Windows native libraries.

If you need to target 32-bit Windows, i686- variants of both of these toolchains are available.


NOTE: below answer summarizes situation as of Sep'2014; I'm not aware if it's still current, or if things have changed to better or worse since then. But I strongly suspect things have changed, given that 2 years have already passed since then. It would be cool if somebody tried to ask steveklabnik about it again, then update below info, or write a new, fresher answer!


Quick & raw transcript of a Rust IRC chat with steveklabnik, who gave me a kind of answer:

Hi; I have a question: if I build a DLL with Rust, does it require libgcc*.dll to be present on run time? (on Windows)

I believe that if you use the standard library, then it does require it; IIRC we depend on one symbol from it; but I am unsure.

How can I avoid using the standard library, or those parts of it that do? (and/or do you know which symbol exactly?)

It involves #[no_std] at your crate root; I think the unsafe guide has more.

Running nm -D | grep gcc shows me __gc_personality_v0, and then there is this: What is __gxx_personality_v0 for?, so it looks like our stack unwinding implementation depends on that.

I seem to recall I've seen some RFCs to the effect of splitting standard library, too; are there parts I can use without pulling libgcc in?

Yes, libcore doesn't require any of that. You give up libstd.

Also, quoting parts of the unsafe guide:

The core library (libcore) has very few dependencies and is much more portable than the standard library (libstd) itself. Additionally, the core library has most of the necessary functionality for writing idiomatic and effective Rust code. (...) Further libraries, such as liballoc, add functionality to libcore which make other platform-specific assumptions, but continue to be more portable than the standard library itself.

And fragment of the current docs for unwind module:

Currently Rust uses unwind runtime provided by libgcc.

(The transcript was edited slightly for readability. Still, I'll happily delete this answer if anyone provides something better formatted and more thorough!)

这篇关于使用 Rust 构建的 DLL 在运行时是否需要 libgcc.dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆