Skip to content

Commit 52f5684

Browse files
gideondsouzatorvalds
authored andcommitted
kernel: use macros from compiler.h instead of __attribute__((...))
To increase compiler portability there is <linux/compiler.h> which provides convenience macros for various gcc constructs. Eg: __weak for __attribute__((weak)). I've replaced all instances of gcc attributes with the right macro in the kernel subsystem. Signed-off-by: Gideon Israel Dsouza <gidisrael@gmail.com> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ce816fa commit 52f5684

13 files changed

Lines changed: 34 additions & 21 deletions

File tree

kernel/fork.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include <linux/signalfd.h>
7474
#include <linux/uprobes.h>
7575
#include <linux/aio.h>
76+
#include <linux/compiler.h>
7677

7778
#include <asm/pgtable.h>
7879
#include <asm/pgalloc.h>
@@ -286,7 +287,7 @@ void __init fork_init(unsigned long mempages)
286287
init_task.signal->rlim[RLIMIT_NPROC];
287288
}
288289

289-
int __attribute__((weak)) arch_dup_task_struct(struct task_struct *dst,
290+
int __weak arch_dup_task_struct(struct task_struct *dst,
290291
struct task_struct *src)
291292
{
292293
*dst = *src;

kernel/kallsyms.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/mm.h>
2424
#include <linux/ctype.h>
2525
#include <linux/slab.h>
26+
#include <linux/compiler.h>
2627

2728
#include <asm/sections.h>
2829

@@ -36,8 +37,8 @@
3637
* These will be re-linked against their real values
3738
* during the second link stage.
3839
*/
39-
extern const unsigned long kallsyms_addresses[] __attribute__((weak));
40-
extern const u8 kallsyms_names[] __attribute__((weak));
40+
extern const unsigned long kallsyms_addresses[] __weak;
41+
extern const u8 kallsyms_names[] __weak;
4142

4243
/*
4344
* Tell the compiler that the count isn't in the small data section if the arch
@@ -46,10 +47,10 @@ extern const u8 kallsyms_names[] __attribute__((weak));
4647
extern const unsigned long kallsyms_num_syms
4748
__attribute__((weak, section(".rodata")));
4849

49-
extern const u8 kallsyms_token_table[] __attribute__((weak));
50-
extern const u16 kallsyms_token_index[] __attribute__((weak));
50+
extern const u8 kallsyms_token_table[] __weak;
51+
extern const u16 kallsyms_token_index[] __weak;
5152

52-
extern const unsigned long kallsyms_markers[] __attribute__((weak));
53+
extern const unsigned long kallsyms_markers[] __weak;
5354

5455
static inline int is_kernel_inittext(unsigned long addr)
5556
{

kernel/kexec.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/vmalloc.h>
3333
#include <linux/swap.h>
3434
#include <linux/syscore_ops.h>
35+
#include <linux/compiler.h>
3536

3637
#include <asm/page.h>
3738
#include <asm/uaccess.h>
@@ -1551,10 +1552,10 @@ void vmcoreinfo_append_str(const char *fmt, ...)
15511552
* provide an empty default implementation here -- architecture
15521553
* code may override this
15531554
*/
1554-
void __attribute__ ((weak)) arch_crash_save_vmcoreinfo(void)
1555+
void __weak arch_crash_save_vmcoreinfo(void)
15551556
{}
15561557

1557-
unsigned long __attribute__ ((weak)) paddr_vmcoreinfo_note(void)
1558+
unsigned long __weak paddr_vmcoreinfo_note(void)
15581559
{
15591560
return __pa((unsigned long)(char *)&vmcoreinfo_note);
15601561
}

kernel/ksysfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/stat.h>
1919
#include <linux/sched.h>
2020
#include <linux/capability.h>
21+
#include <linux/compiler.h>
2122

2223
#include <linux/rcupdate.h> /* rcu_expedited */
2324

@@ -162,8 +163,8 @@ KERNEL_ATTR_RW(rcu_expedited);
162163
/*
163164
* Make /sys/kernel/notes give the raw contents of our kernel .notes section.
164165
*/
165-
extern const void __start_notes __attribute__((weak));
166-
extern const void __stop_notes __attribute__((weak));
166+
extern const void __start_notes __weak;
167+
extern const void __stop_notes __weak;
167168
#define notes_size (&__stop_notes - &__start_notes)
168169

169170
static ssize_t notes_read(struct file *filp, struct kobject *kobj,

kernel/power/power.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/suspend_ioctls.h>
33
#include <linux/utsname.h>
44
#include <linux/freezer.h>
5+
#include <linux/compiler.h>
56

67
struct swsusp_info {
78
struct new_utsname uts;
@@ -11,7 +12,7 @@ struct swsusp_info {
1112
unsigned long image_pages;
1213
unsigned long pages;
1314
unsigned long size;
14-
} __attribute__((aligned(PAGE_SIZE)));
15+
} __aligned(PAGE_SIZE);
1516

1617
#ifdef CONFIG_HIBERNATION
1718
/* kernel/power/snapshot.c */

kernel/power/snapshot.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/highmem.h>
2828
#include <linux/list.h>
2929
#include <linux/slab.h>
30+
#include <linux/compiler.h>
3031

3132
#include <asm/uaccess.h>
3233
#include <asm/mmu_context.h>
@@ -155,7 +156,7 @@ static inline void free_image_page(void *addr, int clear_nosave_free)
155156
struct linked_page {
156157
struct linked_page *next;
157158
char data[LINKED_PAGE_DATA_SIZE];
158-
} __attribute__((packed));
159+
} __packed;
159160

160161
static inline void
161162
free_list_of_pages(struct linked_page *list, int clear_page_nosave)

kernel/power/suspend.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/syscore_ops.h>
2727
#include <linux/ftrace.h>
2828
#include <trace/events/power.h>
29+
#include <linux/compiler.h>
2930

3031
#include "power.h"
3132

@@ -156,13 +157,13 @@ static int suspend_prepare(suspend_state_t state)
156157
}
157158

158159
/* default implementation */
159-
void __attribute__ ((weak)) arch_suspend_disable_irqs(void)
160+
void __weak arch_suspend_disable_irqs(void)
160161
{
161162
local_irq_disable();
162163
}
163164

164165
/* default implementation */
165-
void __attribute__ ((weak)) arch_suspend_enable_irqs(void)
166+
void __weak arch_suspend_enable_irqs(void)
166167
{
167168
local_irq_enable();
168169
}

kernel/power/swap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct swsusp_header {
101101
unsigned int flags; /* Flags to pass to the "boot" kernel */
102102
char orig_sig[10];
103103
char sig[10];
104-
} __attribute__((packed));
104+
} __packed;
105105

106106
static struct swsusp_header *swsusp_header;
107107

kernel/sched/clock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@
6060
#include <linux/sched.h>
6161
#include <linux/static_key.h>
6262
#include <linux/workqueue.h>
63+
#include <linux/compiler.h>
6364

6465
/*
6566
* Scheduler clock - returns current time in nanosec units.
6667
* This is default implementation.
6768
* Architectures and sub-architectures can override this.
6869
*/
69-
unsigned long long __attribute__((weak)) sched_clock(void)
70+
unsigned long long __weak sched_clock(void)
7071
{
7172
return (unsigned long long)(jiffies - INITIAL_JIFFIES)
7273
* (NSEC_PER_SEC / HZ);

kernel/sched/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include <linux/init_task.h>
7474
#include <linux/binfmts.h>
7575
#include <linux/context_tracking.h>
76+
#include <linux/compiler.h>
7677

7778
#include <asm/switch_to.h>
7879
#include <asm/tlb.h>
@@ -6498,7 +6499,7 @@ static cpumask_var_t fallback_doms;
64986499
* cpu core maps. It is supposed to return 1 if the topology changed
64996500
* or 0 if it stayed the same.
65006501
*/
6501-
int __attribute__((weak)) arch_update_cpu_topology(void)
6502+
int __weak arch_update_cpu_topology(void)
65026503
{
65036504
return 0;
65046505
}

0 commit comments

Comments
 (0)