如何重命名调试信息?
编辑:我完全改写了我原来的问题,因为它还很不清楚(在底部可以看到不清晰!)。
我正在开发一个 RTOS,其中内核和应用程序都必须映射到内存中非常特定的位置。例如:
0x00000000:0x0000ffff: application #1
0x00010000:0x0000ffff: application #2
...
0xffff0000:0xffffffff: kernel
应用程序(和内核)是单独开发(和编译)的。要将所有内容合并到单个可执行文件中,请使用以下过程:(
- 分别)编译内核和应用程序(去除任何符号)。
- (通过脚本)生成链接器脚本以将内核和应用程序重新定位到所需位置。为了防止节名称之间发生任何冲突,生成的链接描述文件会“重命名”所有应用程序的所有节(例如 .app1.text、.app1.data、.app1.bss,...)。
- 使用先前生成的链接描述文件进行链接(即全部合并)。
问题 1) 是否可以用类似以下过程的内容替换步骤 #2 和 #3?
- 将内核和应用程序的目标文件重新定位到所需位置。
- 重命名应用程序目标文件上的所有符号(以防止名称冲突)。
- 全部合并。
我正在尝试用一些已经可用的工具替换链接器脚本的生成。
步骤#1应该可以通过创建位置无关的可执行文件来实现(我仍然需要调查这一点)。
步骤 #2 可以通过 GNU objcopy 实现。
对于步骤#3,我还没有可能的解决方案。如果使用GNU ld,它会使用一些默认的链接器脚本,并且之前的重定位会丢失。如果GNU gdb接受GNU ar生成的档案,问题就会得到解决(我猜!)。
问题2)如果上述过程可行,是否也可以应用于调试信息?
步骤#1 应保持不变。
对于步骤#2,我不确定调试信息是否被重命名。
步骤#3 的问题仍然存在。
原问题如下:
我有一个自定义内核和一个或多个应用程序,并且我想使用 GDB来调试整个系统。为了避免任何名称冲突 在链接期间,我使用 objcopy 重命名所有部分和符号 名称(应用程序的起始地址在内核中硬编码)。 然而,调试信息[我猜]是硬编码在那些内部的 .debug.* 部分并且不会被重命名。
有没有办法重命名调试信息?然后,在那之后, 将该信息与另一组已存在的调试合并 信息?
我搜索了 GCC 的手册,看看是否可以找到前缀选项 (就像全局命名空间)编译期间的所有符号,但我 还没找到。
我的猜测是有一种调试格式公开了它的 有关对象符号表的信息(可以重命名)。
EDIT: I am rephrasing entirely my original question as it was far from clear (it's non-clearness can be seen at the bottom!).
I am developing a RTOS where both the kernel and the applications must be mapped to very specific locations in memory. For example:
0x00000000:0x0000ffff: application #1
0x00010000:0x0000ffff: application #2
...
0xffff0000:0xffffffff: kernel
The applications (and the kernel) are developed (and compiled) separately. To merged everything into a single executable, the following process is used:
- (Separately) Compile the kernel and the applications (stripped of any symbols).
- (Through a script) Generate a linker script to relocate the kernel and the applications to the desired locations. To prevent any conflicts between sections' names, the generated linker script "renames" all sections of all applications (e.g. .app1.text, .app1.data, .app1.bss, ...).
- Link using the previously generated linker script (i.e. merge all).
Question 1) Is it possible to replace steps #2 and #3 with something like the following process?
- Relocate the object files of the kernel and the applications to the desired position.
- Rename all symbols on the applications' object files (to prevent name clashes).
- Merge all.
I'm trying to replace the generation of the linker script with some already available tools.
Step #1 should be possible through the creation of a position independent executable (I still have to investigate this).
Step #2 is possible through GNU objcopy.
For Step #3 I have no possible solution yet. If GNU ld is used, it uses some default linker script and the previous relocation is lost. If GNU gdb accepted archives generated from GNU ar the problem would be solved (I guess!).
Question 2) If the above process is possible, can it be applied to debugging information as well?
Step #1 should remain intact.
For step #2 I am not sure if debugging information gets renamed or not.
The problem with step #3 remains.
The original question follows:
I have a custom kernel and one or more applications and, I want to use
GDB to debug the entire system. In order to avoid any name clashes
during linkage I use objcopy to rename all the sections and symbols
names (applications' start addresses are hard-coded in the kernel).
However, debugging information is [I guess] hard-coded inside those
.debug.* sections and do not get renamed.Is there a way to rename the debugging information? And, after that,
merge that information with another set of already existent debugging
information?I have searched GCC's manual to see if I can find an option to prefix
(like a global namespace) all symbols during compilation, but I
haven't found any.My guess is that there is a debugging format which exposes its
information on the objects symbol table (which can be renamed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答问题1)
不,这是不可能的。当可执行文件的加载地址仅在加载时已知时,位置无关的可执行文件非常有用。就我而言,我想硬连线加载地址。
似乎没有解决方法。因此,链接描述文件是必需的。
回答问题2)
事实上,调试信息不会被重命名。您可以使用 objdump -s 并检查调试信息是否硬连线在这些 .debug.* 部分内。
解决方法)
即使没有调试信息,您也可以使用目标文件的符号表来设置断点。但是,您必须使用 b main 来代替 b * main,因为符号表中的符号被解释为地址。这虽然不多,但确实有帮助。
Answer to Question 1)
No, it is not possible. A position independent executable is useful when the load address of the executable is known only at load time. In my case, I want to hardwire the load address.
There seems to be no workaround. A linker script is thus mandatory.
Answer to Question 2)
In fact, debugging information does not get renamed. You can use objdump -s and check that debugging information is hardwired inside those .debug.* sections.
Workaround)
Even without debugging information you can use the object file's symbol table to set breakpoints. However, instead b main your must use b * main because the symbols in the symtable are interpreted as address. This is not much, but it certainly helps.