gcc/mingw 中“启动文件”的来源

Posted

技术标签:

【中文标题】gcc/mingw 中“启动文件”的来源【英文标题】:Source for 'startup files' in gcc/mingw 【发布时间】:2014-12-13 15:24:57 【问题描述】:

我正在使用 mingw32

在 gcc 中有一个选项

" -nostartfiles  Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used. "

如果我自己不使用它,我在我的 exe 中得到的几乎是空的 c 源代码 1000 行反汇编包含此类函数的长存根代码

00401000 <___mingw_CRTStartup>:
00401110 <__gnu_exception_handler@4>:
00401280 <_mainCRTStartup>:
004012a0 <_WinMainCRTStartup>:
004012c0 <_atexit>:
004012d0 <__onexit>:
004012e0 <___gcc_register_frame>:
0040132c <___gcc_deregister_frame>:
00401334 <_WinMain@16>:
00401340 <___dyn_tls_dtor@12>:
00401390 <___dyn_tls_init@12>:
00401420 <___tlregdtor>:
00401430 <___cpu_features_init>:
00401510 <__fpreset>:
00401520 <___report_error>:
00401580 <___write_memory.part.0>:
00401690 <__pei386_runtime_relocator>:
00401870 <___do_global_dtors>:
004018a0 <___do_global_ctors>:
004018f0 <___main>:
00401910 <___mingwthr_run_key_dtors.part.0>:
00401970 <____w64_mingwthr_add_key_dtor>:
00401a00 <____w64_mingwthr_remove_key_dtor>:
00401a90 <___mingw_TLScallback>:
00401b30 <___getmainargs>:
00401b38 <__setmode>:
00401b40 <___p__fmode>:
00401b48 <___p__environ>:
00401b50 <__cexit>:
00401b58 <_signal>:
00401b60 <_fwrite>:
00401b68 <_vfprintf>:
00401b70 <_abort>:
00401b78 <_memcpy>:
00401b80 <_calloc>:
00401b88 <_free>:
00401b90 <_SetUnhandledExceptionFilter@4>:
00401b98 <_ExitProcess@4>:
00401ba0 <_GetModuleHandleA@4>:
00401ba8 <_GetProcAddress@8>:
00401bb0 <_VirtualQuery@12>:
00401bb8 <_VirtualProtect@16>:
00401bc0 <_GetCommandLineA@0>:
00401bc8 <_GetStartupInfoA@4>:
00401bd0 <_EnterCriticalSection@4>:
00401bd8 <_TlsGetValue@4>:
00401be0 <_GetLastError@0>:
00401be8 <_LeaveCriticalSection@4>:
00401bf0 <_DeleteCriticalSection@4>:
00401bf8 <_InitializeCriticalSection@4>:
00401c00 <_main>:
00401ce0 <_register_frame_ctor>:
00401cfc <__CTOR_LIST__>:
00401d00 <.ctors.65535>:
00401d08 <__DTOR_LIST__>:

也许有人可以说我在哪里可以找到来源? (或至少一些详细的解释是什么 - 但来源会更好)

【问题讨论】:

【参考方案1】:

我猜你可以下载GCC sources或MinGW sources。

由于 sourceforge.net 上的 mingw-w64 项目正在转移到 mingw-w64.org,我建议还检查 mingw-w64.org,然后运行 ​​grep 或类似的文本搜索实用程序并找到这些功能所在的特定文件(s) 已定义。

另请注意,exit()atexit()memcpy() 等一些函数来自 C 运行时库,它们不会在 GCC 源代码中定义。

【讨论】:

太棒了,不过如果你有可用的技能,你可能会提供更长的帮助,并尝试找到它并说出它在哪里(或者如果你找到了?) @user2214913 好的,我已经从git-scm.com/download/win 安装了 git。从 sourceforge 克隆官方 mingw-w64 存储库,执行 git clone git://git.code.sf.net/p/mingw-w64/mingw-w64 mingw-w64-mingw-w64。进入mingw-w64-mingw-w64目录,在资源管理器中搜索do_global_ctors,它指向了mingw-w64-mingw-w64\mingw-w64-crt\crt\gccmain.c,这里也可以找到do_global_dtors 磁盘aer上的源大约130Mb,git打包在传输中,所以你下载大约30Mb左右,git clone ...在终端窗口执行

以上是关于gcc/mingw 中“启动文件”的来源的主要内容,如果未能解决你的问题,请参考以下文章

使用 GCC/MinGW 创建代理 DLL

jar文件打开使用Java错误:启动文件中缺少下列必需字段:<jnlp>

u-boot start.S启动文件分析

MinGW - GCC 6.1.0

gcc MinGW 上的 InterlockedOr8

如何在cmd中编译命名运行c程序