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

linker: Introduce linker-tool-lld.h #59792

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmake/linker/lld/target_base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
macro(toolchain_ld_base)

if(NOT PROPERTY_LINKER_SCRIPT_DEFINES)
set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__)
set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__LLD_LINKER_CMD__)
endif()

# TOOLCHAIN_LD_FLAGS comes from compiler/clang/target.cmake
Expand Down
61 changes: 61 additions & 0 deletions include/zephyr/linker/linker-tool-lld.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023, Google, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief LLVM LLD linker defs
*
* This header file defines the necessary macros used by the linker script for
* use with the LLD linker.
*/

#ifndef ZEPHYR_INCLUDE_LINKER_LINKER_TOOL_LLD_H_
#define ZEPHYR_INCLUDE_LINKER_LINKER_TOOL_LLD_H_

#include <zephyr/linker/linker-tool-gcc.h>

/**
* @def SECTION_PROLOGUE
*
* The SECTION_PROLOGUE() macro is used to define the beginning of a section.
*
* When --omagic (-N) option is provided to LLD then only the first output
* section of given region has aligned LMA (by default, without --omagic, LLD
* aligns LMA and VMA of every section to the same value) and the difference
* between VMA addresses (0 is this is the first section) is added.
* The difference between LMA and VMA is constant for every section, so this
* emulates ALIGN_WITH_INPUT option present in GNU LD (required by XIP systems).
*
* The --omagic flag is defined in cmake/linker/lld/target_baremetal.cmake
*
* @param name Name of the output section
* @param options Section options, such as (NOLOAD), or left blank
* @param align Alignment directives, such as SUBALIGN(). May be blank.
*/
#undef SECTION_PROLOGUE
#define SECTION_PROLOGUE(name, options, align) \
name options : align

/**
* @def SECTION_DATA_PROLOGUE
*
* Same as for SECTION_PROLOGUE(), except that this one must be used
* for data sections which on XIP platforms will have differing
* virtual and load addresses (i.e. they'll be copied into RAM at
* program startup). Such a section must also use
* GROUP_DATA_LINK_IN to specify the correct output load address.
*
* This is equivalent to SECTION_PROLOGUE() when linking using LLD.
*
* @param name Name of the output section
* @param options Section options, or left blank
* @param align Alignment directives, such as SUBALIGN(). May be blank.
*/
#undef SECTION_DATA_PROLOGUE
#define SECTION_DATA_PROLOGUE(name, options, align) \
SECTION_PROLOGUE(name, options, align)

#endif /* ZEPHYR_INCLUDE_LINKER_LINKER_TOOL_LLD_H_ */
2 changes: 2 additions & 0 deletions include/zephyr/linker/linker-tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <zephyr/linker/linker-tool-gcc.h>
#elif defined(__MWDT_LINKER_CMD__)
#include <zephyr/linker/linker-tool-mwdt.h>
#elif defined(__LLD_LINKER_CMD__)
#include <zephyr/linker/linker-tool-lld.h>
#else
#error "Unknown toolchain"
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/toolchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <zephyr/toolchain/mwdt.h>
#elif defined(__ARMCOMPILER_VERSION)
#include <zephyr/toolchain/armclang.h>
#elif defined(__llvm__)
#elif defined(__llvm__) || (defined(_LINKER) && defined(__LLD_LINKER_CMD__))
#include <zephyr/toolchain/llvm.h>
#elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__))
#include <zephyr/toolchain/gcc.h>
Expand Down
Loading