Setting ASM_LINK_EXECUTABLE removes ALL command options passed to linker
Hi, I hope this isn't a duplicate of anything.
The root issue is no longer present, however setting ASM_LINK_EXECUTABLE still behaves as outlined further down.
(For anyone else stumbling on this, setting the LINKER_LANGUAGE to C instead of ASM and then passing it -ffreestanding -O2 -nostdlib -lgcc fixed in removing all the extra sections from the binary)
For the past couple of days I've been trying to get a separate assembly build chain to work and I'm finally "close".
However, I need to specify the Linker as a custom linker and when doing so none of the linker options are passed to it.
Basically, my CMakeLists.txt:
add_executable(BOOT ${BOOT_SRC} ${BOOT_ARCH_SRC} ./boot/include ./boot/arch/${ARCH}/include)
target_include_directories(BOOT PUBLIC ./boot/include)
set_source_files_properties(${BOOT_SRC} PROPERTIES LANGUAGE ASM_NASM)
set_source_files_properties(${BOOT_ARCH_SRC} PROPERTIES LANGUAGE ASM_NASM)
set_target_properties(BOOT PROPERTIES LINKER_LANGUAGE ASM)
target_compile_options(BOOT PUBLIC -f elf64)
target_link_libraries(BOOT PRIVATE -nostartfiles -T "${PROJECT_SOURCE_DIR}/boot/arch/${ARCH}/boot.ld" -o "${PROJECT_SOURCE_DIR}/boot/bin/XXX-${ARCH}.bin")
ARCH is defined as x86_64 while BOOT_SRC and BOOT_ARCH_SRC are just file lists like file(GLOB BOOT_SRC "./boot/*.asm")
.
Now, executing this target gives me a binary, however it contains a bunch of sections I don't really need, or want
Sections:
Idx Name Size VMA LMA File off Algn
0 .boot 0000001c 0000000000100000 0000000000100000 00100000 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .interp 0000001c 000000000010001c 000000000010001c 0010001c 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.build-id 00000024 0000000000100038 0000000000100038 00100038 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .dynsym 00000018 0000000000100060 0000000000100060 00100060 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .dynstr 00000001 0000000000100078 0000000000100078 00100078 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .gnu.hash 0000001c 0000000000100080 0000000000100080 00100080 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .text 0000000b 00000000001000a0 00000000001000a0 001000a0 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
7 .dynamic 000000e0 00000000001000b0 00000000001000b0 001000b0 2**3
CONTENTS, ALLOC, LOAD, DATA
All I want are the sections .boot and .text.
So investigating a bit it turns out that the link command invokes cc
and not ld
:
/usr/bin/cc -g CMakeFiles/BOOT.dir/boot/arch/x86_64/boot.asm.o CMakeFiles/BOOT.dir/boot/arch/x86_64/multiboot_header.asm.o -o BOOT -nostartfiles -T ../boot/arch/x86_64/boot.ld -o ../boot/bin/XXX-x86_64.bin
After setting set(CMAKE_ASM_LINK_EXECUTABLE /opt/cross/XXX/local/bin/${ARCH}-pc-elf-ld)
(built as part of GCC) the link command is now only /opt/cross/XXX/local/bin/x86_64-pc-elf-ld
without any of the options.
When running the target ld then obviously complains no input files
.
CMake version is cmake version 3.10.2
, which is the highest I can get to my knowledge (I'm on Ubuntu Bionic).
Thanks!