Re: [rfc patch script] treewide conversion of __section(foo) to section("foo");

From: Nick Desaulniers
Date: Mon Sep 16 2019 - 15:46:10 EST


On Thu, Sep 12, 2019 at 4:50 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> On Thu, 2019-09-12 at 15:45 -0700, Nick Desaulniers wrote:
> > If you want to email me just the patch file (so I don't have to
> > copy+pasta from an email),
>
> Lazy... ;)

Says the Perl programmer...http://threevirtues.com/ ;)

>
> > I'd be happy to apply it and compile+boot test a few more arch's
> > than x86.

Looks like arm defconfig has an error:

arch/arm/mach-omap2/omap-wakeupgen.c:634:1: error: expected ';' after
top level declarator
./include/linux/irqchip.h:27:43: note: expanded from macro 'IRQCHIP_DECLARE'
#define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name,
compat, fn)
^
./include/linux/of.h:1304:3: note: expanded from macro 'OF_DECLARE_2'
_OF_DECLARE(table, name, compat, fn, of_init_fn_2)
^
./include/linux/of.h:1284:10: note: expanded from macro '_OF_DECLARE'
__used __section("__" ## table ## "_of_table") \
^
./include/linux/compiler_attributes.h:232:77: note: expanded from
macro '__section'
#define __section(section) __attribute__((__section__(section)))
^


and

drivers/clocksource/timer-atmel-pit.c:263:1: error: pasting formed
'"__"timer', an invalid preprocessing token
TIMER_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
^
./include/linux/clocksource.h:263:2: note: expanded from macro
'TIMER_OF_DECLARE'
OF_DECLARE_1_RET(timer, name, compat, fn)
^
./include/linux/of.h:1302:3: note: expanded from macro 'OF_DECLARE_1_RET'
_OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
^
./include/linux/of.h:1284:25: note: expanded from macro '_OF_DECLARE'
__used __section("__" ## table ## "_of_table") \
^



and modpost is broken:
drivers/cpufreq/cpufreq_conservative.mod.c:12:11: error: expected expression
__section(.gnu.linkonce.this_module) = {
^
1 error generated.




arm64 then had this issue:
drivers/clocksource/arm_arch_timer.c:1624:1: error: expected ';' after
top level declarator
./include/linux/clocksource.h:272:2: note: expanded from macro
'TIMER_ACPI_DECLARE'
ACPI_DECLARE_PROBE_ENTRY(timer, name, table_id, 0, NULL, 0, fn)
^
./include/linux/acpi.h:1097:10: note: expanded from macro
'ACPI_DECLARE_PROBE_ENTRY'
__used __section("__" ## table ## "_acpi_probe_table") \
^
./include/linux/compiler_attributes.h:232:77: note: expanded from
macro '__section'
#define __section(section) __attribute__((__section__(section)))
^


Same problem (token pasting then concatenation of strings).


diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 1b7cda17c34e..71844dbc963b 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -21,7 +21,7 @@ extern struct thermal_governor
*__governor_thermal_table_end[];

#define THERMAL_TABLE_ENTRY(table, name) \
static typeof(name) *__thermal_table_entry_##name \
- __used __section("__" ## table ## "_thermal_table") = &name
+ __used __section("__" #table "_thermal_table") = &name

#define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor, name)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 24c1293d8717..5013725cdb92 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1094,7 +1094,7 @@ struct acpi_probe_entry {

#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable,
valid, data, fn) \
static const struct acpi_probe_entry __acpi_probe_##name \
- __used __section("__" ## table ## "_acpi_probe_table") \
+ __used __section("__" #table "_acpi_probe_table") \
= { \
.id = table_id, \
.type = subtable, \
diff --git a/include/linux/of.h b/include/linux/of.h
index 71e74771ce35..b2459fc411cf 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1281,7 +1281,7 @@ static inline int
of_get_available_child_count(const struct device_node *np)
#if defined(CONFIG_OF) && !defined(MODULE)
#define _OF_DECLARE(table, name, compat, fn, fn_type) \
static const struct of_device_id __of_table_##name \
- __used __section("__" ## table ## "_of_table") \
+ __used __section("__" #table "_of_table") \
= { .compatible = compat, \
.data = (fn == (fn_type)NULL) ? fn : fn }
#else
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 820eed87fb43..f2c70d1d5a2a 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2176,7 +2176,7 @@ static void add_header(struct buffer *b, struct
module *mod)
buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
buf_printf(b, "\n");
buf_printf(b, "__visible struct module __this_module\n");
- buf_printf(b, "__section(.gnu.linkonce.this_module) = {\n");
+ buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
if (mod->has_init)
buf_printf(b, "\t.init = init_module,\n");

--
Thanks,
~Nick Desaulniers
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 1b7cda17c34e..71844dbc963b 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -21,7 +21,7 @@ extern struct thermal_governor *__governor_thermal_table_end[];

#define THERMAL_TABLE_ENTRY(table, name) \
static typeof(name) *__thermal_table_entry_##name \
- __used __section("__" ## table ## "_thermal_table") = &name
+ __used __section("__" #table "_thermal_table") = &name

#define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor, name)

diff --git a/include/linux/of.h b/include/linux/of.h
index 71e74771ce35..b2459fc411cf 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1281,7 +1281,7 @@ static inline int of_get_available_child_count(const struct device_node *np)
#if defined(CONFIG_OF) && !defined(MODULE)
#define _OF_DECLARE(table, name, compat, fn, fn_type) \
static const struct of_device_id __of_table_##name \
- __used __section("__" ## table ## "_of_table") \
+ __used __section("__" #table "_of_table") \
= { .compatible = compat, \
.data = (fn == (fn_type)NULL) ? fn : fn }
#else
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 820eed87fb43..f2c70d1d5a2a 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2176,7 +2176,7 @@ static void add_header(struct buffer *b, struct module *mod)
buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
buf_printf(b, "\n");
buf_printf(b, "__visible struct module __this_module\n");
- buf_printf(b, "__section(.gnu.linkonce.this_module) = {\n");
+ buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
if (mod->has_init)
buf_printf(b, "\t.init = init_module,\n");