Skip to contentSkip to conversation

ARM: Sort exception table at compile time

PATCH Superseded Stephen Boyd 3 participants 8 messages Jul 30, 2012 – Aug 22, 2012 Arm (32-bit)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: Sort exception table at compile time

Add the ARM machine identifier to sortextable and select the config option so that we can sort the exception table at compile time. sortextable relies on a section named __ex_table existing in the vmlinux, but ARM's linker script places the exception table in the data section. Give the exception table its own section so that sortextable can find it.

This allows us to skip the runtime sorting step during boot.

---

I can't find any information on why the exception table lives in the data section. If there's a good reason for that, I'll look into changing sortextable to look for the __start___ex_table symbol.

 arch/arm/Kconfig              |  1 +
 arch/arm/kernel/vmlinux.lds.S | 19 +++++++++----------
 scripts/sortextable.c         |  1 +
 3 files changed, 11 insertions(+), 10 deletions(-)
arch/arm/Kconfig +1 -0
index b25c9d3..2af95e6 100644
@@ -1,6 +1,7 @@
 config ARM
 	bool
 	default y
+	select BUILDTIME_EXTABLE_SORT if MMU
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_AOUT
 	select HAVE_DMA_API_DEBUG
arch/arm/kernel/vmlinux.lds.S +9 -10
index 36ff15b..0e3e8b4 100644
@@ -220,16 +220,6 @@ SECTIONS
 		READ_MOSTLY_DATA(L1_CACHE_BYTES)
 
 		/*
-		 * The exception fixup table (might need resorting at runtime)
-		 */
-		. = ALIGN(4);
-		__start___ex_table = .;
-#ifdef CONFIG_MMU
-		*(__ex_table)
-#endif
-		__stop___ex_table = .;
-
-		/*
 		 * and the usual data section
 		 */
 		DATA_DATA
@@ -239,6 +229,15 @@ SECTIONS
 	}
 	_edata_loc = __data_loc + SIZEOF(.data);
 
+	. = ALIGN(4);
+	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
+		__start___ex_table = .;
+#ifdef CONFIG_MMU
+		*(__ex_table)
+#endif
+		__stop___ex_table = .;
+	}
+
 #ifdef CONFIG_HAVE_TCM
         /*
 	 * We align everything to a page boundary so we can
scripts/sortextable.c +1 -0
index 1ca9ceb..591acb3 100644
@@ -248,6 +248,7 @@ do_file(char const *const fname)
 		custom_sort = sort_x86_table;
 		break;
 	case EM_MIPS:
+	case EM_ARM:
 		break;
 	}  /* end switch */
 
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw
Quoted 58 lines · Stephen Boyd

Add the ARM machine identifier to sortextable and select the config option so that we can sort the exception table at compile time. sortextable relies on a section named __ex_table existing in the vmlinux, but ARM's linker script places the exception table in the data section. Give the exception table its own section so that sortextable can find it.

This allows us to skip the runtime sorting step during boot.

---

I can't find any information on why the exception table lives in the data section. If there's a good reason for that, I'll look into changing sortextable to look for the __start___ex_table symbol.

 arch/arm/Kconfig              |  1 +
 arch/arm/kernel/vmlinux.lds.S | 19 +++++++++----------
 scripts/sortextable.c         |  1 +
 3 files changed, 11 insertions(+), 10 deletions(-)
arch/arm/Kconfig +1 -0
index b25c9d3..2af95e6 100644
@@ -1,6 +1,7 @@
 config ARM
 	bool
 	default y
+	select BUILDTIME_EXTABLE_SORT if MMU
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_AOUT
 	select HAVE_DMA_API_DEBUG
arch/arm/kernel/vmlinux.lds.S +0 -10
index 36ff15b..0e3e8b4 100644
@@ -220,16 +220,6 @@ SECTIONS
 		READ_MOSTLY_DATA(L1_CACHE_BYTES)
 
 		/*
-		 * The exception fixup table (might need resorting at runtime)
-		 */
-		. = ALIGN(4);
-		__start___ex_table = .;
-#ifdef CONFIG_MMU
-		*(__ex_table)
-#endif
-		__stop___ex_table = .;
-
-		/*
 		 * and the usual data section
 		 */
 		DATA_DATA
@@ -239,6 +229,15 @@ SECTIONS
 	}
 	_edata_loc = __data_loc + SIZEOF(.data);

arch/arm/kernel/vmlinux.lds.S SECTIONS · line 240

Quoted 10 lines
arch/arm/kernel/vmlinux.lds.S +9 -0
 
+	. = ALIGN(4);
+	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
+		__start___ex_table = .;
+#ifdef CONFIG_MMU
+		*(__ex_table)
+#endif
+		__stop___ex_table = .;
+	}
+

Here you should be able to use the macro EXCEPTION_TABLE from vmlinux.lds.h.
I cannot see why the ifdef for not NON-MMU case is needed, but if it is needed the macro is not good...

Sam

#2 lore raw
Quoted 4 lines · Sam Ravnborg

Here you should be able to use the macro EXCEPTION_TABLE from vmlinux.lds.h.
I cannot see why the ifdef for not NON-MMU case is needed, but if it is needed the macro is not good...

Because you can not mention the same input section in two different places and end up with predictable output from the linker.

We discard the __ex_table for noMMU, but I think the start/stop symbols are still referenced somewhere. Dunno, I don't have much to do with noMMU ARM, and the only platform I'd be interested in never got merged.

#3 lore raw
Quoted 5 lines · Russell King - ARM Linux
Quoted 4 lines · Sam Ravnborg

Here you should be able to use the macro EXCEPTION_TABLE from vmlinux.lds.h.
I cannot see why the ifdef for not NON-MMU case is needed, but if it is needed the macro is not good...

Quoted 7 lines

Because you can not mention the same input section in two different places and end up with predictable output from the linker.

We discard the __ex_table for noMMU, but I think the start/stop symbols are still referenced somewhere. Dunno, I don't have much to do with noMMU ARM, and the only platform I'd be interested in never got merged.

I was thinking, perhaps we can ifdef out the exception fixup sections in the places where they're added? Then we can just use the EXCEPTION_TABLE macro from vmlinux.lds.h knowing that there are no __ex_table sections in the input object files?

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#4 lore raw
In reply to Stephen Boyd
Quoted 9 lines · Stephen Boyd

Add the ARM machine identifier to sortextable and select the config option so that we can sort the exception table at compile time. sortextable relies on a section named __ex_table existing in the vmlinux, but ARM's linker script places the exception table in the data section. Give the exception table its own section so that sortextable can find it.

This allows us to skip the runtime sorting step during boot.

Quoted 7 lines

---

I can't find any information on why the exception table lives in the data section. If there's a good reason for that, I'll look into changing sortextable to look for the __start___ex_table symbol.

Be careful about the placement of this, especially with XIP.

#5 lore raw
Quoted 10 lines · Russell King - ARM Linux
Quoted 9 lines · Stephen Boyd

Add the ARM machine identifier to sortextable and select the config option so that we can sort the exception table at compile time. sortextable relies on a section named __ex_table existing in the vmlinux, but ARM's linker script places the exception table in the data section. Give the exception table its own section so that sortextable can find it.

This allows us to skip the runtime sorting step during boot.

Quoted 9 lines
Quoted 7 lines

---

I can't find any information on why the exception table lives in the data section. If there's a good reason for that, I'll look into changing sortextable to look for the __start___ex_table symbol.

Be careful about the placement of this, especially with XIP.

Thanks for the hint. I'm unfamiliar with how XIP works so I'll take a closer look there.

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#6 lore raw
Quoted 15 lines · Stephen Boyd
Quoted 14 lines · Russell King - ARM Linux
Quoted 13 lines · Stephen Boyd

Add the ARM machine identifier to sortextable and select the config option so that we can sort the exception table at compile time. sortextable relies on a section named __ex_table existing in the vmlinux, but ARM's linker script places the exception table in the data section. Give the exception table its own section so that sortextable can find it.

This allows us to skip the runtime sorting step during boot.

---

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I can't find any information on why the exception table lives in the data section. If there's a good reason for that, I'll look into changing sortextable to look for the __start___ex_table symbol.

Be careful about the placement of this, especially with XIP.

Thanks for the hint. I'm unfamiliar with how XIP works so I'll take a closer look there.

Ok. It looks like the exception table is placed in the data section so that XIP kernels can boot up and sort the exception table (otherwise the exception table would be in read-only flash). Now that the exception table is sorted at compile time, we should be able to place the exception table in the rodata area, essentially placing the table in the non-volatile storage on XIP kernels.

I propose we move the exception table right after the rodata. Other arches (x86/mips) may actually want to put the exception table into the rodata, but that looks like a larger change.

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#7 lore raw

PATCH v2 1/1 ARM: Sort exception table at compile time

In reply to Stephen Boyd

Add the ARM machine identifier to sortextable and select the config option so that we can sort the exception table at compile time. sortextable relies on a section named __ex_table existing in the vmlinux, but ARM's linker script places the exception table in the data section. Give the exception table its own section so that sortextable can find it.

This allows us to skip the sorting step during boot.

---

Changes since v1:
* Moved exception table next to RO data for XIP builds

 arch/arm/Kconfig              |  1 +
 arch/arm/kernel/vmlinux.lds.S | 19 +++++++++----------
 scripts/sortextable.c         |  1 +
 3 files changed, 11 insertions(+), 10 deletions(-)
arch/arm/Kconfig +1 -0
index 6d6e18f..ccf830b 100644
@@ -1,6 +1,7 @@
 config ARM
 	bool
 	default y
+	select BUILDTIME_EXTABLE_SORT if MMU
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select HAVE_AOUT
 	select HAVE_DMA_API_DEBUG
arch/arm/kernel/vmlinux.lds.S +9 -10
index 36ff15b..b9f38e3 100644
@@ -114,6 +114,15 @@ SECTIONS
 
 	RO_DATA(PAGE_SIZE)
 
+	. = ALIGN(4);
+	__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
+		__start___ex_table = .;
+#ifdef CONFIG_MMU
+		*(__ex_table)
+#endif
+		__stop___ex_table = .;
+	}
+
 #ifdef CONFIG_ARM_UNWIND
 	/*
 	 * Stack unwinding tables
@@ -220,16 +229,6 @@ SECTIONS
 		READ_MOSTLY_DATA(L1_CACHE_BYTES)
 
 		/*
-		 * The exception fixup table (might need resorting at runtime)
-		 */
-		. = ALIGN(4);
-		__start___ex_table = .;
-#ifdef CONFIG_MMU
-		*(__ex_table)
-#endif
-		__stop___ex_table = .;
-
-		/*
 		 * and the usual data section
 		 */
 		DATA_DATA
scripts/sortextable.c +1 -0
index 6acf834..ba8f7c1 100644
@@ -247,6 +247,7 @@ do_file(char const *const fname)
 	case EM_X86_64:
 		custom_sort = sort_x86_table;
 		break;
+	case EM_ARM:
 	case EM_S390:
 	case EM_MIPS:
 		break;
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.