Skip to contentSkip to conversation

vmlinux.lds.h clean-ups

RFC PATCH In review Rob Herring 2 participants 7 messages Mar 27, 2014 – Apr 24, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover vmlinux.lds.h clean-ups

From: Rob Herring <[email protected]>

Several DeviceTree related sections have been added recently to enable early DT initialization calls. I have the need to add yet another one in order to do a DT based earlycon. Since each section follows the same pattern, this seemed like a good opportunity for some clean-up. So this series creates a common macro to define these sections. with this adding any new OF table section is a 2 line change.

Each section ends with a zeroed struct of_device_id (except cpu_method). Right now there is an end section and a dummy variable to create the end marker. Really, we just need padding here, but I haven't come up with a way for the linker script to get the struct size.

The last patch extends the same concept to another common pattern for section definitons. There's still others which could be easily converted also, but I'm looking for feedback on this approach before proceeding any further.

Rob

Rob Herring (4):
irqchip: align irqchip OF match table section naming
ARM: align cpu_method_of_table naming vmlinuz.lds: define OF table sections with macros vmlinux.lds: define conditional sections with macros

 arch/arm/kernel/devtree.c         |  11 +--
 drivers/irqchip/irqchip.c         |   6 +-
 include/asm-generic/vmlinux.lds.h | 142 +++++++++++---------------------------
 3 files changed, 52 insertions(+), 107 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

RFC PATCH 1/4 irqchip: align irqchip OF match table section naming

From: Rob Herring <[email protected]>

Make the irqchip OF match table section naming aligned with other OF match table sections in preparation to have a common definition.

---
 drivers/irqchip/irqchip.c         | 6 +++---
 include/asm-generic/vmlinux.lds.h | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/irqchip/irqchip.c +3 -3
index cad3e24..0fe2f71 100644
@@ -19,11 +19,11 @@
  * special section.
  */
 static const struct of_device_id
-irqchip_of_match_end __used __section(__irqchip_of_end);
+irqchip_of_match_end __used __section(__irqchip_of_table_end);
 
-extern struct of_device_id __irqchip_begin[];
+extern struct of_device_id __irqchip_of_table[];
 
 void __init irqchip_init(void)
 {
-	of_irq_init(__irqchip_begin);
+	of_irq_init(__irqchip_of_table);
 }
include/asm-generic/vmlinux.lds.h +2 -2
index f7bf870..f8d1783 100644
@@ -151,9 +151,9 @@
 #ifdef CONFIG_IRQCHIP
 #define IRQCHIP_OF_MATCH_TABLE()					\
 	. = ALIGN(8);							\
-	VMLINUX_SYMBOL(__irqchip_begin) = .;				\
+	VMLINUX_SYMBOL(__irqchip_of_table) = .;				\
 	*(__irqchip_of_table)		  				\
-	*(__irqchip_of_end)
+	*(__irqchip_of_table_end)
 #else
 #define IRQCHIP_OF_MATCH_TABLE()
 #endif
Signature · 1 line
1.8.3.2
#2 lore raw

RFC PATCH 2/4 ARM: align cpu_method_of_table naming

In reply to Rob Herring

From: Rob Herring <[email protected]>

The cpu_method_of_table is the oddball of the various OF linker sections. In preparation to have common linker section definitions, align the cpu_method_of_table with the other definitions for the naming and ending with a blank struct.

Cc Russell King <[email protected]>
Cc Arnd Bergmann <[email protected]>
---
 arch/arm/kernel/devtree.c         | 11 +++++++----
 include/asm-generic/vmlinux.lds.h |  4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
arch/arm/kernel/devtree.c +7 -4
index c7419a5..bdac7a9 100644
@@ -65,18 +65,21 @@ void __init arm_dt_memblock_reserve(void)
 }
 
 #ifdef CONFIG_SMP
-extern struct of_cpu_method __cpu_method_of_table_begin[];
-extern struct of_cpu_method __cpu_method_of_table_end[];
+extern struct of_cpu_method __cpu_method_of_table[];
+
+static const struct of_cpu_method __cpu_method_of_table_sentinel
+	__used __section(__cpu_method_of_table_end);
+
 
 static int __init set_smp_ops_by_method(struct device_node *node)
 {
 	const char *method;
-	struct of_cpu_method *m = __cpu_method_of_table_begin;
+	struct of_cpu_method *m = __cpu_method_of_table;
 
 	if (of_property_read_string(node, "enable-method", &method))
 		return 0;
 
-	for (; m < __cpu_method_of_table_end; m++)
+	for (; m->method; m++)
 		if (!strcmp(m->method, method)) {
 			smp_set_ops(m->ops);
 			return 1;
include/asm-generic/vmlinux.lds.h +2 -2
index f8d1783..d09e670 100644
@@ -169,9 +169,9 @@
 
 #ifdef CONFIG_SMP
 #define CPU_METHOD_OF_TABLES() . = ALIGN(8);				    \
-			   VMLINUX_SYMBOL(__cpu_method_of_table_begin) = .; \
+			   VMLINUX_SYMBOL(__cpu_method_of_table) = .; \
 			   *(__cpu_method_of_table)			    \
-			   VMLINUX_SYMBOL(__cpu_method_of_table_end) = .;
+			   *(__cpu_method_of_table_end)
 #else
 #define CPU_METHOD_OF_TABLES()
 #endif
Signature · 1 line
1.8.3.2
#3 lore raw

RFC PATCH 3/4 vmlinuz.lds: define OF table sections with macros

In reply to Rob Herring

From: Rob Herring <[email protected]>

OF table sections all have the same pattern, so create a macro to define them and insure consistency.

---
 include/asm-generic/vmlinux.lds.h | 58 ++++++++++-----------------------------
 1 file changed, 14 insertions(+), 44 deletions(-)
include/asm-generic/vmlinux.lds.h +14 -44
index d09e670..000a0f30 100644
@@ -139,52 +139,22 @@
 #define TRACE_SYSCALLS()
 #endif
 
-#ifdef CONFIG_CLKSRC_OF
-#define CLKSRC_OF_TABLES() . = ALIGN(8);				\
-			   VMLINUX_SYMBOL(__clksrc_of_table) = .;	\
-			   *(__clksrc_of_table)				\
-			   *(__clksrc_of_table_end)
-#else
-#define CLKSRC_OF_TABLES()
-#endif
 
-#ifdef CONFIG_IRQCHIP
-#define IRQCHIP_OF_MATCH_TABLE()					\
+#define ___OF_TABLE(cfg, name)	_OF_TABLE_##cfg(name)
+#define __OF_TABLE(cfg, name)	___OF_TABLE(cfg, name)
+#define OF_TABLE(cfg, name)	__OF_TABLE(config_enabled(cfg), name)
+#define _OF_TABLE_0(name)
+#define _OF_TABLE_1(name)						\
 	. = ALIGN(8);							\
-	VMLINUX_SYMBOL(__irqchip_of_table) = .;				\
-	*(__irqchip_of_table)		  				\
-	*(__irqchip_of_table_end)
-#else
-#define IRQCHIP_OF_MATCH_TABLE()
-#endif
-
-#ifdef CONFIG_COMMON_CLK
-#define CLK_OF_TABLES() . = ALIGN(8);				\
-			VMLINUX_SYMBOL(__clk_of_table) = .;	\
-			*(__clk_of_table)			\
-			*(__clk_of_table_end)
-#else
-#define CLK_OF_TABLES()
-#endif
-
-#ifdef CONFIG_SMP
-#define CPU_METHOD_OF_TABLES() . = ALIGN(8);				    \
-			   VMLINUX_SYMBOL(__cpu_method_of_table) = .; \
-			   *(__cpu_method_of_table)			    \
-			   *(__cpu_method_of_table_end)
-#else
-#define CPU_METHOD_OF_TABLES()
-#endif
-
-#ifdef CONFIG_OF_RESERVED_MEM
-#define RESERVEDMEM_OF_TABLES()				\
-	. = ALIGN(8);					\
-	VMLINUX_SYMBOL(__reservedmem_of_table) = .;	\
-	*(__reservedmem_of_table)			\
-	*(__reservedmem_of_table_end)
-#else
-#define RESERVEDMEM_OF_TABLES()
-#endif
+	VMLINUX_SYMBOL(__##name##_of_table) = .;			\
+	*(__##name##_of_table)						\
+	*(__##name##_of_table_end)
+
+#define CLKSRC_OF_TABLES()	OF_TABLE(CONFIG_CLKSRC_OF, clksrc)
+#define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
+#define CLK_OF_TABLES()		OF_TABLE(CONFIG_COMMON_CLK, clk)
+#define CPU_METHOD_OF_TABLES()	OF_TABLE(CONFIG_SMP, cpu_method)
+#define RESERVEDMEM_OF_TABLES()	OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
 
 #define KERNEL_DTB()							\
 	STRUCT_ALIGN();							\
Signature · 1 line
1.8.3.2
#4 lore raw

RFC PATCH 4/4 vmlinux.lds: define conditional sections with macros

In reply to Rob Herring

From: Rob Herring <[email protected]>

Various section definitions all use the same pattern. Create a common macro to define these.

There are a few other instances with a different symbol naming convention which could also be converted over to use this.

---
 include/asm-generic/vmlinux.lds.h | 82 +++++++++++++--------------------------
 1 file changed, 27 insertions(+), 55 deletions(-)
include/asm-generic/vmlinux.lds.h +27 -55
index 000a0f30..9a08039 100644
@@ -84,61 +84,33 @@
 #define MEM_DISCARD(sec) *(.mem##sec)
 #endif
 
-#ifdef CONFIG_FTRACE_MCOUNT_RECORD
-#define MCOUNT_REC()	. = ALIGN(8);				\
-			VMLINUX_SYMBOL(__start_mcount_loc) = .; \
-			*(__mcount_loc)				\
-			VMLINUX_SYMBOL(__stop_mcount_loc) = .;
-#else
-#define MCOUNT_REC()
-#endif
-
-#ifdef CONFIG_TRACE_BRANCH_PROFILING
-#define LIKELY_PROFILE()	VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
-				*(_ftrace_annotated_branch)			      \
-				VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
-#else
-#define LIKELY_PROFILE()
-#endif
-
-#ifdef CONFIG_PROFILE_ALL_BRANCHES
-#define BRANCH_PROFILE()	VMLINUX_SYMBOL(__start_branch_profile) = .;   \
-				*(_ftrace_branch)			      \
-				VMLINUX_SYMBOL(__stop_branch_profile) = .;
-#else
-#define BRANCH_PROFILE()
-#endif
-
-#ifdef CONFIG_EVENT_TRACING
-#define FTRACE_EVENTS()	. = ALIGN(8);					\
-			VMLINUX_SYMBOL(__start_ftrace_events) = .;	\
-			*(_ftrace_events)				\
-			VMLINUX_SYMBOL(__stop_ftrace_events) = .;
-#else
-#define FTRACE_EVENTS()
-#endif
-
-#ifdef CONFIG_TRACING
-#define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .;      \
-			 *(__trace_printk_fmt) /* Trace_printk fmt' pointer */ \
-			 VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .;
-#define TRACEPOINT_STR() VMLINUX_SYMBOL(__start___tracepoint_str) = .;	\
-			 *(__tracepoint_str) /* Trace_printk fmt' pointer */ \
-			 VMLINUX_SYMBOL(__stop___tracepoint_str) = .;
-#else
-#define TRACE_PRINTKS()
-#define TRACEPOINT_STR()
-#endif
-
-#ifdef CONFIG_FTRACE_SYSCALLS
-#define TRACE_SYSCALLS() . = ALIGN(8);					\
-			 VMLINUX_SYMBOL(__start_syscalls_metadata) = .;	\
-			 *(__syscalls_metadata)				\
-			 VMLINUX_SYMBOL(__stop_syscalls_metadata) = .;
-#else
-#define TRACE_SYSCALLS()
-#endif
-
+#define __DEF_SECT(cfg, align, sec, sym)	_DEF_SECT_##cfg(align, sec, sym)
+#define _DEF_SECT(cfg, align, sec, sym)		__DEF_SECT(cfg, align, sec, sym)
+#define DEF_SECTION_SYM(cfg, align, sec, sym)				\
+	_DEF_SECT(config_enabled(cfg), align, sec, sym)
+#define DEF_SECTION(cfg, align, sec)				\
+	_DEF_SECT(config_enabled(cfg), align, sec, sec)
+#define _DEF_SECT_0(align, sec, sym)
+#define _DEF_SECT_1(align, sec, sym)					\
+	. = ALIGN(align);						\
+	VMLINUX_SYMBOL(__start_##sym) = .;				\
+	*(##sec)							\
+	VMLINUX_SYMBOL(__stop_##sym) = .;
+
+#define MCOUNT_REC()		\
+	DEF_SECTION(CONFIG_FTRACE_MCOUNT_RECORD, 8, mcount_loc)
+#define LIKELY_PROFILE()	\
+	DEF_SECTION_SYM(CONFIG_TRACE_BRANCH_PROFILING, 1, _ftrace_annotated_branch, annotated_branch_profile)
+#define FTRACE_EVENTS()		\
+	DEF_SECTION(CONFIG_EVENT_TRACING, 8, ftrace_events)
+#define BRANCH_PROFILE()	\
+	DEF_SECTION_SYM(CONFIG_PROFILE_ALL_BRANCHES, 1, _ftrace_branch, branch_profile)
+#define TRACE_PRINTKS()		\
+	DEF_SECTION_SYM(CONFIG_TRACING, 1, __trace_printk_fmt, __trace_bprintk_fmt)
+#define TRACEPOINT_STR()	\
+	DEF_SECTION(CONFIG_TRACING, 1, __tracepoint_str)
+#define TRACE_SYSCALLS()	\
+	DEF_SECTION_SYM(CONFIG_FTRACE_SYSCALLS, 8, __syscalls_metadata, syscalls_metadata)
 
 #define ___OF_TABLE(cfg, name)	_OF_TABLE_##cfg(name)
 #define __OF_TABLE(cfg, name)	___OF_TABLE(cfg, name)
Signature · 1 line
1.8.3.2
#5 lore raw
In reply to Rob Herring
Quoted 27 lines · Rob Herring

From: Rob Herring <[email protected]>

Several DeviceTree related sections have been added recently to enable early DT initialization calls. I have the need to add yet another one in order to do a DT based earlycon. Since each section follows the same pattern, this seemed like a good opportunity for some clean-up. So this series creates a common macro to define these sections. with this adding any new OF table section is a 2 line change.

Each section ends with a zeroed struct of_device_id (except cpu_method). Right now there is an end section and a dummy variable to create the end marker. Really, we just need padding here, but I haven't come up with a way for the linker script to get the struct size.

The last patch extends the same concept to another common pattern for section definitons. There's still others which could be easily converted also, but I'm looking for feedback on this approach before proceeding any further.

Rob

Rob Herring (4):
irqchip: align irqchip OF match table section naming
ARM: align cpu_method_of_table naming vmlinuz.lds: define OF table sections with macros vmlinux.lds: define conditional sections with macros

Quoted 3 lines
 arch/arm/kernel/devtree.c         |  11 +--
 drivers/irqchip/irqchip.c         |   6 +-
 include/asm-generic/vmlinux.lds.h | 142 +++++++++++---------------------------

Arnd, Any comments on this series?

Rob

maintainer
#6 lore raw
Quoted 7 lines · Rob Herring
Quoted 4 lines
 arch/arm/kernel/devtree.c         |  11 +--
 drivers/irqchip/irqchip.c         |   6 +-
 include/asm-generic/vmlinux.lds.h | 142 +++++++++++---------------------------

Arnd, Any comments on this series?

No qualified comments. The linker script is always magic to me. For all I can tell, it's all good and you can add an Acked-by from me if that helps you, but I'm not able to judge whether it's correct. Do you want to merge it through the DT git?

Arnd