Skip to content

Commit 85c2ce9

Browse files
author
Peter Zijlstra
committed
sched, vmlinux.lds: 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: c3a340f ("sched: Have sched_class_highest define by vmlinux.lds.h") Reported-by: kernel test robot <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent faa2fd7 commit 85c2ce9

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@
108108
#define SBSS_MAIN .sbss
109109
#endif
110110

111+
/*
112+
* GCC 4.5 and later have a 32 bytes section alignment for structures.
113+
* Except GCC 4.9, that feels the need to align on 64 bytes.
114+
*/
115+
#if __GNUC__ == 4 && __GNUC_MINOR__ == 9
116+
#define STRUCT_ALIGNMENT 64
117+
#else
118+
#define STRUCT_ALIGNMENT 32
119+
#endif
120+
#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
121+
111122
/*
112123
* The order of the sched class addresses are important, as they are
113124
* used to determine the order of the priority of each sched class in
@@ -123,13 +134,6 @@
123134
*(__stop_sched_class) \
124135
__end_sched_classes = .;
125136

126-
/*
127-
* Align to a 32 byte boundary equal to the
128-
* alignment gcc 4.5 uses for a struct
129-
*/
130-
#define STRUCT_ALIGNMENT 32
131-
#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
132-
133137
/* The actual configuration determine if the init/exit sections
134138
* are handled as text/data or they can be discarded (which
135139
* often happens at runtime)

kernel/sched/sched.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <linux/tsacct_kern.h>
6868

6969
#include <asm/tlb.h>
70+
#include <asm-generic/vmlinux.lds.h>
7071

7172
#ifdef CONFIG_PARAVIRT
7273
# include <asm/paravirt.h>
@@ -1810,7 +1811,7 @@ struct sched_class {
18101811
#ifdef CONFIG_FAIR_GROUP_SCHED
18111812
void (*task_change_group)(struct task_struct *p, int type);
18121813
#endif
1813-
} __aligned(32); /* STRUCT_ALIGN(), vmlinux.lds.h */
1814+
} __aligned(STRUCT_ALIGNMENT); /* STRUCT_ALIGN(), vmlinux.lds.h */
18141815

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

0 commit comments

Comments
 (0)