gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:24:46 26 4
gpt4 key购买 nike

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

最佳答案

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

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

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

用法:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com