假设我有以下源文件:
// file.c:
void f() {}
void g() {}
我使用gcc -ffunction-sections
将其编译为目标文件:
$ 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
那么,是否可以从目标文件中删除特定于功能的部分(使用-ffunction-sections
编译)?
额外信息:
file.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
执行?