Suppose I have the following source file:
// file.c:
void f() {}
void g() {}
I compile it into object file using 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').
Then I try to remove section .text.g
(with g
) from object file:
$ objcopy --remove-section .text.g file.o
objcopy: stQOLAU8: symbol `.text.g' required but not present
objcopy:stQOLAU8: No symbols
So, is there way to remove function-specific section from object file (compiled with -ffunction-sections
)?
Extra info:
Full list of symbols in
file.o
is:$ 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
My goal is to eliminate some sections from object file similarly to what
ld --gc-sections
does.
Or is there some theoretical reason why such task is absolutely out of the scope of objcopy
and can only be performed with ld -r
?