如何为STL/C ++调试GCC/LD链接过程 [英] How to debug GCC/LD linking process for STL/C++

查看:155
本文介绍了如何为STL/C ++调试GCC/LD链接过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究C ++中的裸机Cortex-M3,以获取乐趣和收益.我使用STL库,因为我需要一些容器.我以为只要提供分配器,就不会在最终的二进制文件中添加太多代码,因为您只会得到使用的东西.

I'm working on a bare-metal cortex-M3 in C++ for fun and profit. I use the STL library as I needed some containers. I thought that by simply providing my allocator it wouldn't add much code to the final binary, since you get only what you use.

实际上,我什至不希望使用STL进行任何链接过程 (给我分配器),因为我认为这都是模板代码.

I actually didn't even expect any linking process at all with the STL (giving my allocator), as I thought it was all template code.

我正在用-fno-exception进行编译.

不幸的是,大约有600KB或更多的空间被添加到了我的二进制文件中.我查找了nm最终二进制文件中包含的符号,这对我来说似乎是个玩笑.该列表很长,我不会尝试删除它.尽管有一些较弱的符号.

Unfortunately, about 600KB or more are added to my binary. I looked up what symbols are included in the final binary with nm and it seemed a joke to me. The list is so long I won't try and past it. Although there are some weak symbols.

我还查看了链接程序生成的.map文件,甚至找到了scanf符号

I also looked in the .map file generated by the linker and I even found the scanf symbols

.text
0x000158bc       0x30   /CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../arm-none-linux-gnueabi/libc/usr/lib/libc.a(sscanf.o)
0x000158bc                __sscanf
0x000158bc                sscanf
0x000158bc                _IO_sscanf

并且:

$ arm-none-linux-gnueabi-nm binary | grep scanf
000158bc T _IO_sscanf
0003e5f4 T _IO_vfscanf
0003e5f4 T _IO_vfscanf_internal
000164a8 T _IO_vsscanf
00046814 T ___vfscanf
000158bc T __sscanf
00046814 T __vfscanf
000164a8 W __vsscanf
000158bc T sscanf
00046814 W vfscanf
000164a8 W vsscanf

我该如何调试?首先,我想了解GCC用于链接的确切含义(我正在通过GCC进行链接).我知道,如果在文本段中找到符号, 整个段都用完了,但那仍然太多了.

How can I debug this? For first I wanted to understand what exactly GCC is using for linking (I'm linking through GCC). I know that if symbol is found in a text segment, the whole segment is used, but still that's too much.

任何有关如何解决此问题的建议将不胜感激.

Any suggestion on how to tackle this would really be appreciated.

谢谢

推荐答案

使用GCC的-v-Wl,-v选项将向您显示所使用的链接器命令(和链接器的版本信息).

Using GCC's -v and -Wl,-v options will show you the linker commands (and version info of the linker) being used.

您使用的是哪个版本的GCC?我对GCC 4.6进行了一些更改(请参见 PR 44647 PR 43863 )以减少代码大小,以帮助嵌入式系统.仍然有一个悬而未决的增强请求( PR 43852 )以允许禁用包含您所看到的IO符号-其中一些来自详细的终止处理程序,该进程在活动异常终止时会打印一条消息.如果您不使用执行程序,那么其中的某些代码对您就没有用了.

Which version of GCC are you using? I made some changes for GCC 4.6 (see PR 44647 and PR 43863) to reduce code size to help embedded systems. There's still an outstanding enhancement request (PR 43852) to allow disabling the inclusion of the IO symbols you're seeing - some of them come from the verbose terminate handler, which prints a message when the process is terminated with an active exception. If you're not using execptions then some of that code is useless to you.

这篇关于如何为STL/C ++调试GCC/LD链接过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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