Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch-axel-80] cmake: use 3.13 linker features #56

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: GPL-2.0-only
#

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.13)
include(CheckCCompilerFlag)

include(${CMAKE_CURRENT_LIST_DIR}/configs/seL4Config.cmake)
Expand Down Expand Up @@ -183,6 +183,7 @@ add_compile_options(
-Wundef
-Wpointer-arith
-Wno-nonnull
-Wformat
#-----------------------------------
# Configure compiler settings.
#-----------------------------------
Expand All @@ -207,32 +208,32 @@ add_compile_options(

# Linker parameters. There are two kinds actually:
# - flags processed by GCC when invoking it as linker wrapper
# - flags passed by GCC to the actual linker invocation ("-Wl,<flag>").
string(
APPEND CMAKE_EXE_LINKER_FLAGS
# - flags passed by GCC to the actual linker, CMake translates "LINKER:<flag>"
# to the toolchain specific syntax, e.g. "-Wl,<flag>" for GCC.
add_link_options(
# KernelCommonFlags adds "-nostdlib", it's the GCC linker step counterpart
# for "-ffreestanding" and makes GCC not use the standard system startup
# files or libraries. This also excludes GCC's helper library libgcc. Any
# libraries that are to be linked must be specified explicitly. Tests have
# shown that this parameter doesn't prevent GCC from adding paths from a
# "-L <path>" argument to the linker invocation for the standard libs, and
# there seems no option that prevents this apart from providing an entirely
# different specs file via -specs=<file>. Note that "-Wl,-nostdlib" is not
# used here, because it is not needed. It makes the linker use library
# different specs file via -specs=<file>. Note that "LINKER:-nostdlib" is
# not used here, because it is not needed. It makes the linker use library
# directories specified on the command line only and ignore any SEARCH_DIR
# set in a linker script. We provide our own linker scripts, and these
# don't set SEARCH_DIR.
" -static" # Implies "-no-pie" (and overrides "-pie"). The ld 2.37 docs say
# "-no-pie" is a linker option, but passing "-Wl,-no-pie" fails.
" -Wl,--build-id=none" # Ensure reproducible builds
" -Wl,-n" # Disable page alignment of sections
-static # Implies "-no-pie" (and overrides "-pie"). The ld 2.37 docs say
# "-no-pie" is a linker option, but passing "LINKER:-no-pie" fails.
LINKER:--build-id=none # Ensure reproducible builds
LINKER:-n # Disable page alignment of sections
)

# Setup kernel specific flags used for both the compilation and linking step
macro(KernelCommonFlags)
foreach(common_flag IN ITEMS ${ARGV})
add_compile_options(${common_flag})
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${common_flag} ")
add_link_options(${common_flag})
endforeach()
endmacro(KernelCommonFlags)

Expand Down Expand Up @@ -691,11 +692,12 @@ add_custom_target(kernel_theories DEPENDS ${theories_deps})

# Declare final kernel output
add_executable(kernel.elf EXCLUDE_FROM_ALL ${asm_sources} kernel_all.c)
target_include_directories(kernel.elf PRIVATE ${config_dir})
target_include_directories(kernel.elf PRIVATE include)
target_include_directories(kernel.elf PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_include_directories(
kernel.elf
PRIVATE "${config_dir}" "include" "${CMAKE_CURRENT_BINARY_DIR}/generated"
)
target_link_libraries(kernel.elf PRIVATE kernel_Config kernel_autoconf)
set_property(TARGET kernel.elf APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-T ${linker_lds_path} ")
target_link_options(kernel.elf PRIVATE "LINKER:-T,${linker_lds_path}")
set_target_properties(kernel.elf PROPERTIES LINK_DEPENDS "${linker_lds_path}")
add_dependencies(kernel.elf circular_includes)

Expand Down