ld --gc-sections
명령 줄 플래그는 무시 될 것 같다 나는 GNU를 사용하고는
$ cat gcs.c extern void magic(void); void callmagic(void) { magic(); } int uanswer = 42; int main(void) { return 0; } $ cat ofbin.scr OUTPUT_FORMAT(binary) OUTPUT_ARCH(i386) ENTRY(main) SECTIONS { . = 0x10000; .text : { *(.text*) } .data : { *(.data*) *(.rodata*) } .bss : { *(.bss*); } } $ cat ofelf.scr OUTPUT_FORMAT(elf32-i386) OUTPUT_ARCH(i386) ENTRY(main) SECTIONS { . = 0x10000; .text : { *(.text*) } .data : { *(.data*) *(.rodata*) } .bss : { *(.bss*); } } $ gcc -m32 -nostdlib -nostartfiles -nodefaultlibs gcs.c -ffunction-sections -fdata-sections -Wl,--gc-sections,--print-gc-sections -Wl,-T,ofelf.scr /usr/bin/ld: Removing unused section '.text.callmagic' in file '/tmp/ccSFoPYg.o' /usr/bin/ld: Removing unused section '.data.uanswer' in file '/tmp/ccSFoPYg.o' /usr/bin/ld: Removing unused section '.eh_frame' in file '/tmp/ccSFoPYg.o' $ gcc -m32 -nostdlib -nostartfiles -nodefaultlibs gcs.c -ffunction-sections -fdata-sections -Wl,--gc-sections,--print-gc-sections -Wl,-T,ofbin.scr /tmp/cceXCw2b.o: In function `callmagic': gcs.c:(.text.callmagic+0x7): undefined reference to `magic' collect2: error: ld returned 1 exit status
우분투 14.04에서 ld 2.24와 GCC 4.8.4.
는어떻게 OUTPUT_FORMAT(binary)
와 --gc-sections
에 의해 제거 callmagic의 코드이 .c
파일 컴파일 및 링크를 만들 수 ?