new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_RANGES_H
+#define _ASM_ALPHA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ALPHA_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_RANGES_H
+#define _ASM_ARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARC_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_RANGES_H
+#define _ASM_ARM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_RANGES_H
+#define _ASM_ARM64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM64_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_RANGES_H
+#define _ASM_AVR32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_AVR32_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_RANGES_H
+#define _ASM_BLACKFIN_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_BLACKFIN_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_RANGES_H
+#define _ASM_C6X_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_C6X_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_RANGES_H
+#define _ASM_CRIS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_CRIS_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_RANGES_H
+#define _ASM_FRV_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_FRV_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_RANGES_H
+#define _ASM_H8300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_H8300_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_RANGES_H
+#define _ASM_HEXAGON_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_HEXAGON_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_RANGES_H
+#define _ASM_IA64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_IA64_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_RANGES_H
+#define _ASM_M32R_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M32R_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_RANGES_H
+#define _ASM_M68K_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M68K_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_RANGES_H
+#define _ASM_METAG_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_METAG_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_RANGES_H
+#define _ASM_MICROBLAZE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MICROBLAZE_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_RANGES_H
+#define _ASM_MIPS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MIPS_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_RANGES_H
+#define _ASM_MN10300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MN10300_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_RANGES_H
+#define _ASM_NIOS2_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_NIOS2_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_RANGES_H
+#define _ASM_OPENRISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_OPENRISC_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_RANGES_H
+#define _ASM_PARISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_PARISC_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_RANGES_H
+#define _ASM_POWERPC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_POWERPC_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_RANGES_H
+#define _ASM_S390_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_S390_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_RANGES_H
+#define _ASM_SCORE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SCORE_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_RANGES_H
+#define _ASM_SH_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SH_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_RANGES_H
+#define _ASM_SPARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SPARC_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_RANGES_H
+#define _ASM_TILE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_TILE_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_RANGES_H
+#define _ASM_UM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UM_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_RANGES_H
+#define _ASM_UNICORE32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UNICORE32_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_RANGES_H
+#define _ASM_X86_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_X86_RANGES_H */
new file mode 100644
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_RANGES_H
+#define _ASM_XTENSA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_XTENSA_RANGES_H */
new file mode 100644
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_RANGES_H_
+#define _ASM_GENERIC_RANGES_H_
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of copyleft-next (version 0.3.1 or later) as published
+ * at http://copyleft-next.org/.
+ */
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_RANGES rng
+
+#define SECTION_RNG(section, name) \
+ SECTION_TYPE(section, SECTION_TYPE_RANGES, name, \
+ SECTION_ORDER_ANY)
+
+#define SECTION_RNG_LEVEL(section, name, level) \
+ SECTION_TYPE(section, SECTION_TYPE_RANGES, name, level)
+
+#define SECTION_RANGE_ALL(section) \
+ SECTION_TYPE_ALL(section,SECTION_TYPE_RANGES)
+
+#ifndef section_rng
+# define section_rng(section, name, flags) \
+ section_type(section, SECTION_TYPE_RANGES, name, \
+ SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_rng_asmtype
+# define section_rng_asmtype(section, name, flags, asmtype) \
+ section_type_asmtype(section, SECTION_TYPE_RANGES, name, \
+ SECTION_ORDER_ANY, flags, asmtype)
+#endif
+
+#ifndef section_rng_level
+# define section_rng_level(section, name, level, flags) \
+ section_type(section, SECTION_TYPE_RANGES, name, level, flags)
+#endif
+
+#ifndef push_section_rng
+# define push_section_rng(section, name, flags) \
+ push_section_type(section, SECTION_TYPE_RANGES, name, \
+ SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef push_section_rng_level
+# define push_section_rng_level(section, name, level, flags) \
+ push_section_type(section, SECTION_TYPE_RANGES, name, \
+ level, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_RANGE
+# define DECLARE_SECTION_RANGE(section, name) \
+ push_section_rng_level(section, name,,) ; \
+ .globl name ; \
+name: ; \
+ .popsection \
+ \
+ push_section_rng_level(section, name, ~,) ; \
+ .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_RANGES_H_ */
new file mode 100644
@@ -0,0 +1,54 @@
+#ifndef _LINUX_RANGES_H
+#define _LINUX_RANGES_H
+/*
+ * Linux section ranges
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of copyleft-next (version 0.3.1 or later) as published
+ * at http://copyleft-next.org/.
+ */
+#ifdef __KERNEL__
+#include <linux/sections.h>
+# include <asm/ranges.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+#define SECTION_ADDR_IN_RANGE(name, addr) \
+ (addr >= (unsigned long) LINUX_SECTION_START(name) && \
+ addr < (unsigned long) LINUX_SECTION_END(name))
+
+#define DECLARE_SECTION_RANGE(name) \
+ DECLARE_LINUX_SECTION_RO(char, name)
+
+#define SECTION_RANGE_BEGIN(name, __section) \
+ const __typeof__(name[0]) \
+ __attribute__((used, \
+ weak, \
+ __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+ section(SECTION_RNG_LEVEL(__section, name, ))))
+
+#define SECTION_RANGE_END(name, __section) \
+ const __typeof__(name[0]) \
+ __attribute__((used, \
+ __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+ section(SECTION_RNG_LEVEL(__section, name, ~))))
+
+#define DEFINE_SECTION_RANGE(name, section) \
+ DECLARE_LINUX_SECTION_RO(char, name); \
+ SECTION_RANGE_BEGIN(name, section) VMLINUX_SYMBOL(name)[0] = {};\
+ SECTION_RANGE_END(name, section) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+#define __LINUX_RANGE(section, name) \
+ __attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)), \
+ __section__(SECTION_RNG(section, name))))
+
+#define __LINUX_RANGE_ORDER(section, name, level) \
+ __attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)), \
+ __section__(SECTION_RNG_LEVEL(section, name, level))))
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_RANGES_H */
Section ranges are on one of the types of custom sections types used in Linux. This provides a series of helpers for defining them and using them. Most importantly this also enables us to avoid modifying the linker script when we add new section range. It turns out a lot of custom sections are actually section ranges, and these are typically spelled out in their architecture specific asm/sections.h file -- we anable architectures to override what asm is used for section ranges but start by defult trusting the asm-generic version all around. v3: new in this series, uses copyleft-next Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> --- arch/alpha/include/asm/ranges.h | 6 ++++ arch/arc/include/asm/ranges.h | 6 ++++ arch/arm/include/asm/ranges.h | 6 ++++ arch/arm64/include/asm/ranges.h | 6 ++++ arch/avr32/include/asm/ranges.h | 6 ++++ arch/blackfin/include/asm/ranges.h | 6 ++++ arch/c6x/include/asm/ranges.h | 6 ++++ arch/cris/include/asm/ranges.h | 6 ++++ arch/frv/include/asm/ranges.h | 6 ++++ arch/h8300/include/asm/ranges.h | 6 ++++ arch/hexagon/include/asm/ranges.h | 6 ++++ arch/ia64/include/asm/ranges.h | 6 ++++ arch/m32r/include/asm/ranges.h | 6 ++++ arch/m68k/include/asm/ranges.h | 6 ++++ arch/metag/include/asm/ranges.h | 6 ++++ arch/microblaze/include/asm/ranges.h | 6 ++++ arch/mips/include/asm/ranges.h | 6 ++++ arch/mn10300/include/asm/ranges.h | 6 ++++ arch/nios2/include/asm/ranges.h | 6 ++++ arch/openrisc/include/asm/ranges.h | 6 ++++ arch/parisc/include/asm/ranges.h | 6 ++++ arch/powerpc/include/asm/ranges.h | 6 ++++ arch/s390/include/asm/ranges.h | 6 ++++ arch/score/include/asm/ranges.h | 6 ++++ arch/sh/include/asm/ranges.h | 6 ++++ arch/sparc/include/asm/ranges.h | 6 ++++ arch/tile/include/asm/ranges.h | 6 ++++ arch/um/include/asm/ranges.h | 6 ++++ arch/unicore32/include/asm/ranges.h | 6 ++++ arch/x86/include/asm/ranges.h | 6 ++++ arch/xtensa/include/asm/ranges.h | 6 ++++ include/asm-generic/ranges.h | 70 ++++++++++++++++++++++++++++++++++++ include/linux/ranges.h | 54 ++++++++++++++++++++++++++++ 33 files changed, 310 insertions(+) create mode 100644 arch/alpha/include/asm/ranges.h create mode 100644 arch/arc/include/asm/ranges.h create mode 100644 arch/arm/include/asm/ranges.h create mode 100644 arch/arm64/include/asm/ranges.h create mode 100644 arch/avr32/include/asm/ranges.h create mode 100644 arch/blackfin/include/asm/ranges.h create mode 100644 arch/c6x/include/asm/ranges.h create mode 100644 arch/cris/include/asm/ranges.h create mode 100644 arch/frv/include/asm/ranges.h create mode 100644 arch/h8300/include/asm/ranges.h create mode 100644 arch/hexagon/include/asm/ranges.h create mode 100644 arch/ia64/include/asm/ranges.h create mode 100644 arch/m32r/include/asm/ranges.h create mode 100644 arch/m68k/include/asm/ranges.h create mode 100644 arch/metag/include/asm/ranges.h create mode 100644 arch/microblaze/include/asm/ranges.h create mode 100644 arch/mips/include/asm/ranges.h create mode 100644 arch/mn10300/include/asm/ranges.h create mode 100644 arch/nios2/include/asm/ranges.h create mode 100644 arch/openrisc/include/asm/ranges.h create mode 100644 arch/parisc/include/asm/ranges.h create mode 100644 arch/powerpc/include/asm/ranges.h create mode 100644 arch/s390/include/asm/ranges.h create mode 100644 arch/score/include/asm/ranges.h create mode 100644 arch/sh/include/asm/ranges.h create mode 100644 arch/sparc/include/asm/ranges.h create mode 100644 arch/tile/include/asm/ranges.h create mode 100644 arch/um/include/asm/ranges.h create mode 100644 arch/unicore32/include/asm/ranges.h create mode 100644 arch/x86/include/asm/ranges.h create mode 100644 arch/xtensa/include/asm/ranges.h create mode 100644 include/asm-generic/ranges.h create mode 100644 include/linux/ranges.h