c - 有什么方法可以重命名 gcc 编译的 .o 或 .a 文件中的节名称?

标签 c gcc object-files

我有一个使用基于 gcc 的编译器编译的预编译库,我想将函数从默认的 .text 部分移动到其他部分名称(假设为 foo)。有没有办法在不重新编译的情况下使用 binutils 来做到这一点?

最佳答案

.库或静态库只是目标文件的集合。

因此,在链接之前,您可以使用 objcpy rename 命令更改您的部分的名称。 同样,您也可以使用“-redefine-sym”更改符号名称

--rename-section oldname=newname[,flags] Rename a section from oldname to newname, optionally changing the section's flags to flags in the process. This has the advantage over using a linker script to perform the rename in that the output stays as an object file and does not become a linked executable.

用法:

objcopy -I binary -O <output_format> -B <architecture>
    --rename-section .data=.rodata,alloc,load,readonly,data,contents
    <input_binary_file> <output_object_file>

引用:http://man7.org/linux/man-pages/man1/objcopy.1.html

关于c - 有什么方法可以重命名 gcc 编译的 .o 或 .a 文件中的节名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42818801/

相关文章:

c - 套接字接受在没有释放的情况下消耗了我在 Windows 上的内存

c 如何从另一个结构变量初始化结构数组成员

c - 从 C 语言转换为汇编语言时,以 null 结尾的字符串在哪里?

c - GCC 链接.o 文件

c - 在 C 编程中使用 for 循环打印特定模式

c++ - 用于 igraph_vector_t 和 igraph_matrix_t 的 GDB pretty-print

c - 需要解释在什么情况下我们应该在C中将&与printf一起使用

c - 我想添加一组新属性,但我不知道如何添加

qt - 如何将目标文件添加到 Qt 中的项目

gcc - 将两个 GCC 编译的 .o 目标文件合并到第三个 .o 文件中