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
Ubuntu 14.04でld 2.24とGCC 4.8.4。
はどうすればOUTPUT_FORMAT(binary)
とし、--gc-sections
によって排除callmagicのコードで、この.c
ファイルのコンパイルとリンクを行うことができますか?