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