2017-01-30 3 views
1

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 파일 컴파일 및 링크를 만들 수 ?

답변

0

이것은 불가능한 것처럼 보입니다. GNU ld는 --gc-sectionsOUTPUT_FORMAT(binary)으로 무시합니다.

가능한 해결 방법은 OUTPUT_FORMAT(elf32-i386)을 사용하고 출력 ELF 파일을 후 처리하는 것입니다. objcopy -O binary a.out a.out.bin.