Gcc 使用objcopy删除未使用的节
假设我有以下源文件:Gcc 使用objcopy删除未使用的节,gcc,ld,objcopy,Gcc,Ld,Objcopy,假设我有以下源文件: // file.c: void f() {} void g() {} 我使用gcc-fffunction部分将其编译成对象文件: $ gcc -c -ffunction-sections file.c -o file.o # It now has at least two sections: `.text.f' (with `f'), `.text.g' (with `g'). 然后我尝试从对象文件中删除节.text.g(带有g): $ objcopy --remove
// file.c:
void f() {}
void g() {}
我使用gcc-fffunction部分将其编译成对象文件
:
$ gcc -c -ffunction-sections file.c -o file.o
# It now has at least two sections: `.text.f' (with `f'), `.text.g' (with `g').
然后我尝试从对象文件中删除节.text.g
(带有g
):
$ objcopy --remove-section .text.g file.o
objcopy: stQOLAU8: symbol `.text.g' required but not present
objcopy:stQOLAU8: No symbols
所以,有没有办法从对象文件中删除特定于函数的节(使用-fffunction节编译)
额外信息:
文件.o
中的符号完整列表为:
$ objdump -t file.o
file.o: file format elf64-x86-64
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 file.c
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l d .data 0000000000000000 .data
0000000000000000 l d .bss 0000000000000000 .bss
0000000000000000 l d .text.f 0000000000000000 .text.f
0000000000000000 l d .text.g 0000000000000000 .text.g
0000000000000000 l d .note.GNU-stack 0000000000000000 .note.GNU-stack
0000000000000000 l d .eh_frame 0000000000000000 .eh_frame
0000000000000000 l d .comment 0000000000000000 .comment
0000000000000000 g F .text.f 0000000000000007 f
0000000000000000 g F .text.g 0000000000000007 g
ld--gc sections
一样从对象文件中删除一些节或者说,这类任务完全超出了
objcopy
的范围,只能用ld-r
执行,这有什么理论上的原因吗?你有没有试着向yugr报告过这个问题?@yugr,没有,IIRC,我没有。你认为这真的是一个bug,应该报告吗?@yugr,我提交:。试着问Andreas是否有解决办法。这不是一个解决办法,而是一个用于-f功能部分的主标志。但是,objcopy
提供了对进入最终可执行文件的内容的完全控制,因此它的不可用性令人沮丧。