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

core: introduce crossfile arrays (xfa), refactored #9105

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ab05acb
core: Mark openocd info variables read-only
May 7, 2018
e52500a
cortexm_common: Binutils 2.30 ldscript unmodified
Aug 11, 2018
5d67e56
cortexm_common: Update ldscript to be more similar to binutils default
May 7, 2018
1a4b906
fixup! cortexm_common: Update ldscript to be more similar to binutils…
May 9, 2018
39d5d19
kinetis: Adjust ldscript memory segment attributes
May 9, 2018
a7f1125
fixup! fixup! cortexm_common: Update ldscript to be more similar to b…
May 9, 2018
f73aead
fixup! fixup! fixup! cortexm_common: Update ldscript to be more simil…
May 14, 2018
fddad1f
fixup! fixup! fixup! fixup! cortexm_common: Update ldscript to be mor…
May 14, 2018
0688e88
squash fix puf_sram init on cortex-m
Aug 25, 2018
ed277c6
core: Introduce cross file arrays (XFA)
kaspar030 May 4, 2018
eb933cd
squash XFA_CONST
May 4, 2018
21b36b3
fixup! squash XFA_CONST
May 8, 2018
ecc4d74
cpu: native: add xfa ld script
kaspar030 Sep 22, 2016
a029359
squash native XFA const
May 6, 2018
306f959
squash XFA use global ldscript for XFA
May 8, 2018
ede64a1
tests: Add xfa test
May 6, 2018
ec15abe
squash xfa add const test
May 8, 2018
b53ed61
lpc2387: specify load segment instead of load address for .data
May 9, 2018
2339ed3
atmega_common: add arch specific XFA ldscript to properly place .roxfa
May 9, 2018
fc08ca9
fixup! squash XFA use global ldscript for XFA
May 9, 2018
60c365b
fixup! squash xfa add const test
May 9, 2018
81137b6
unittests: Add XFA tests
May 14, 2018
0bfa9e6
tests/xfa: Add static check of XFA linking
May 14, 2018
e209a31
squash xfa.h Fix XFA_USE macros
May 14, 2018
6d09bbd
msp430: Add -Wno-pragmas for XFA in ancient GCC
May 14, 2018
dbd06a9
pic32_common: Add CPU specific xfa.ld variant
May 14, 2018
794b8aa
xfa: add a test script
cladmi Jun 4, 2018
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
9 changes: 9 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ export PREFIX ?= $(if $(TARGET_ARCH),$(TARGET_ARCH)-)
# Add standard include directories
INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include

# Augmentation ldscript for cross file arrays (XFA)
# this argument must come before any other -T options on the command line,
# otherwise we get an error message ".text not found for insert"
LINKFLAGS += -Txfa.ld

# process provided features
-include $(RIOTBOARD)/$(BOARD)/Makefile.features

Expand All @@ -252,6 +257,10 @@ TOOLCHAINS_SUPPORTED ?= gnu
# Import all toolchain settings
include $(RIOTMAKE)/toolchain/$(TOOLCHAIN).inc.mk

# Append ldscript path after importing CPU and board makefiles to allow
# overriding the core ldscripts
LINKFLAGS += -L$(RIOTBASE)/core/ldscripts

# Tell ccache to pass the original file to the compiler, instead of passing the
# preprocessed code. Without this setting, the compilation will fail with
# -Wimplicit-fallthrough warnings even when the fall through case is properly
Expand Down
153 changes: 153 additions & 0 deletions core/include/xfa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2016 Kaspar Schleiser <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup core_util
* @brief Cross File Arrays
* @{
*
* This macro, in combination with an entry in the linker scripts, allows the
* definition of constant arrays to be spread over multiple C compilation
* units. These arrays are called "cross-file arrays" or short xfa.
*
*
*
* @file
* @author Kaspar Schleiser <[email protected]>
*/

#ifndef XFA_H
#define XFA_H

/**
* @brief helper macro for other XFA_* macros
*
* @internal
*/
#define _XFA(name, prio) __attribute__((used, section(".xfa." #name "." #prio)))

/**
* @brief helper macro for other XFA_* macros
*
* @internal
*/
#define _XFA_CONST(name, prio) __attribute__((used, section(".roxfa." #name "." #prio))) const

/**
* @brief Define a read-only cross-file array
*
* This macro defines the symbols necessary to use XFA_START() and XFA_END().
* It needs to be part of one single compilation unit.
*
* @param[in] type name of the cross-file array
* @param[in] name name of the cross-file array
*/
#define XFA_INIT_CONST(type, name) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
_XFA_CONST(name, 0_) const type name [0] = {}; \
_XFA_CONST(name, 9_) const type name ## _end [0] = {}; \
_Pragma("GCC diagnostic pop") \
extern const unsigned __xfa_dummy

/**
* @brief Define a writable cross-file array
*
* This macro defines the symbols necessary to use XFA_START() and XFA_END().
* It needs to be part of one single compilation unit.
*
* @param[in] type name of the cross-file array
* @param[in] name name of the cross-file array
*/
#define XFA_INIT(type, name) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
_XFA(name, 0_) type name [0] = {}; \
_XFA(name, 9_) type name ## _end [0] = {}; \
_Pragma("GCC diagnostic pop") \
extern const unsigned __xfa_dummy

/**
* @brief Declare an external read-only cross-file array
*
* This macro defines the symbols necessary to use XFA_START() and XFA_END().
* Think of this as XFA_INIT() but with "extern" keyword.
* It is supposed to be used in compilation units where the cross file array is
* being accessed, but not defined using XFA_INIT.
*
* @param[in] type name of the cross-file array
* @param[in] name name of the cross-file array
*/
#define XFA_USE_CONST(type, name) \
extern const type name []; \
extern const type name ## _end []

/**
* @brief Declare an external writable cross-file array
*
* This macro defines the symbols necessary to use XFA_START() and XFA_END().
* Think of this as XFA_INIT() but with "extern" keyword.
* It is supposed to be used in compilation units where the cross file array is
* being accessed, but not defined using XFA_INIT.
*
* @param[in] type name of the cross-file array
* @param[in] name name of the cross-file array
*/
#define XFA_USE(type, name) \
extern type name []; \
extern type name ## _end []

/**
* @brief Define variable in writable cross-file array
*
* Variables will end up sorted by prio.
*
* Add this to the type in a variable definition, e.g.:
*
* XFA(driver_params, 0) driver_params_t _onboard = { .pin=42 };
*
* @param[in] name name of the xfa
* @param[in] prio priority within the xfa
*/
#define XFA(xfa_name, prio) _XFA(xfa_name, 5_ ##prio)

/**
* @brief Define variable in read-only cross-file array
*
* Variables will end up sorted by prio.
*
* Add this to the type in a variable definition, e.g.:
*
* XFA(driver_params, 0) driver_params_t _onboard = { .pin=42 };
*
* @param[in] name name of the xfa
* @param[in] prio priority within the xfa
*/
#define XFA_CONST(xfa_name, prio) _XFA_CONST(xfa_name, 5_ ##prio)

/**
* @brief Add a pointer to cross-file array
*
* Pointers will end up sorted by prio.
*
* @param[in] xfa_name name of the xfa
* @param[in] prio priority within the xfa
* @param[in] name symbol name
* @param[in] entry pointer variable to add to xfa
*/
#define XFA_ADD_PTR(xfa_name, prio, name, entry) \
_XFA_CONST(xfa_name, 5_ ##prio) \
const typeof(entry) xfa_name ## _ ## prio ## _ ## name = entry

/**
* @brief Calculate number of entries in cross-file array
*/
#define XFA_LEN(type, name) (((const char*)name ## _end - (const char*)name) / sizeof(type))

/** @} */
#endif /* XFA_H */
23 changes: 23 additions & 0 deletions core/ldscripts/xfa.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SECTIONS
{
.data :
{
KEEP (*(SORT(.xfa.*)))
}
__data_start = ADDR(.data);
__data_load_start = LOADADDR(.data);
__data_end = (__data_start + SIZEOF(.data));
__data_load_end = (__data_load_start + SIZEOF(.data));
}

INSERT AFTER .text;

SECTIONS
{
.rodata :
{
KEEP (*(SORT(.roxfa.*)))
}
}

INSERT AFTER .text;
4 changes: 2 additions & 2 deletions core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ static uint32_t runqueue_bitcache = 0;
#endif

FORCE_USED_SECTION
uint8_t max_threads = sizeof(sched_threads) / sizeof(thread_t*);
const uint8_t max_threads = sizeof(sched_threads) / sizeof(thread_t*);

#ifdef DEVELHELP
/* OpenOCD can't determine struct offsets and additionally this member is only
* available if compiled with DEVELHELP */
FORCE_USED_SECTION
uint8_t _tcb_name_offset = offsetof(thread_t, name);
const uint8_t _tcb_name_offset = offsetof(thread_t, name);
#endif

#ifdef MODULE_SCHEDSTATISTICS
Expand Down
1 change: 1 addition & 0 deletions cpu/atmega_common/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export CFLAGS_OPT ?= -Os

export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT)
export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
LINKFLAGS += -L$(RIOTCPU)/atmega_common/ldscripts
export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -e reset_handler -Wl,--gc-sections

# export the peripheral drivers to be linked into the final binary
Expand Down
16 changes: 16 additions & 0 deletions cpu/atmega_common/ldscripts/xfa.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SECTIONS
{
.data :
{
/* Special case for AVR (Harvard architecture) where .rodata is merged
* into .data by the toolchain default ldscripts. */
KEEP (*(SORT(.roxfa.*)))
KEEP (*(SORT(.xfa.*)))
}
__data_start = ADDR(.data);
__data_load_start = LOADADDR(.data);
__data_end = (__data_start + SIZEOF(.data));
__data_load_end = (__data_load_start + SIZEOF(.data));
}

INSERT AFTER .text;
Loading