[lkml]   [2020]   [Oct]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectGCC section alignment, and GCC-4.9 being a weird one
On Tue, Oct 20, 2020 at 04:39:38PM -0700, Florian Fainelli wrote:
> This patch causes all files under kernel/sched/* that include sched.h to
> be rebuilt whenever the value of CONFIG_BLK_DEV_INITRD. There are at
> least two build systems (buildroot and OpenWrt) that toggle this
> configuration value in order to produce a kernel image without an
> initramfs, and one with.
> On ARM we get all of these to be needlessly rebuilt:

Is it really ARM specific? AFAICT this should happen on everything.

> Short of moving the STRUCT_ALIGNMENT to a separate header that would not
> be subject to any configuration key change, can you think of a good way
> to avoid these rebuilds, including for architectures like ARM that ship
> their own I would not say this is a bug, but it is
> definitively an inconvenience.

Well, no :/ I barely made it work in the first place. This linker cruft
is not my forte. GCC-4.9 being 'special' here is just weird in any case.

We can ask our friends on linux-toolchains; maybe they'll have a clue.

Guys, the problem is the below commit which, for dubious raisins makes
kernel/sched/sched.h depend on asm-generic/ and triggers
rebuilds whenever a CONFIG mentioned in asm-generic/

Is there an explanation for why GCC-4.9 is weird and is there a better
way to find the appropriate value?

commit 85c2ce9104eb93517db2037699471c517e81f9b4
Author: Peter Zijlstra <>
Date: Tue Jun 30 16:49:05 2020 +0200

sched, Increase STRUCT_ALIGNMENT to 64 bytes for GCC-4.9

For some mysterious reason GCC-4.9 has a 64 byte section alignment for
structures, all other GCC versions (and Clang) tested (including 4.8
and 5.0) are fine with the 32 bytes alignment.

Getting this right is important for the new SCHED_DATA macro that
creates an explicitly ordered array of 'struct sched_class' in the
linker script and expect pointer arithmetic to work.

Fixes: c3a340f7e7ea ("sched: Have sched_class_highest define by")
Reported-by: kernel test robot <>
Signed-off-by: Peter Zijlstra (Intel) <>

diff --git a/include/asm-generic/ b/include/asm-generic/
index 66fb84c3dc7e..3ceb4b7279ec 100644
--- a/include/asm-generic/
+++ b/include/asm-generic/
@@ -108,6 +108,17 @@
#define SBSS_MAIN .sbss

+ * GCC 4.5 and later have a 32 bytes section alignment for structures.
+ * Except GCC 4.9, that feels the need to align on 64 bytes.
+ */
+#if __GNUC__ == 4 && __GNUC_MINOR__ == 9
* The order of the sched class addresses are important, as they are
* used to determine the order of the priority of each sched class in
@@ -123,13 +134,6 @@
*(__stop_sched_class) \
__end_sched_classes = .;

- * Align to a 32 byte boundary equal to the
- * alignment gcc 4.5 uses for a struct
- */
/* The actual configuration determine if the init/exit sections
* are handled as text/data or they can be discarded (which
* often happens at runtime)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 5aa6661ecaf1..9bef2dd01247 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -67,6 +67,7 @@
#include <linux/tsacct_kern.h>

#include <asm/tlb.h>
+#include <asm-generic/>

# include <asm/paravirt.h>
@@ -1810,7 +1811,7 @@ struct sched_class {
void (*task_change_group)(struct task_struct *p, int type);
-} __aligned(32); /* STRUCT_ALIGN(), */
+} __aligned(STRUCT_ALIGNMENT); /* STRUCT_ALIGN(), */

static inline void put_prev_task(struct rq *rq, struct task_struct *prev)

 \ /
  Last update: 2020-10-21 10:01    [W:0.172 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site