stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iw: set retain atrribute on sections
@ 2021-04-22 18:25 Manoj Gupta
  2021-04-23  7:41 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Manoj Gupta @ 2021-04-22 18:25 UTC (permalink / raw)
  To: Johannes Berg; +Cc: stable, maskray, llozano, manojgupta, linux-wireless

LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
collection of C identifier name sections despite the __start_/__stop_
references.  Simply set the retain attribute so that GCC 11 (if
configure-time binutils is 2.36 or newer)/Clang 13 will set the
SHF_GNU_RETAIN section attribute to prevent garbage collection.

Without the patch, there are linker errors like the following with -z
start-stop-gc:
ld.lld: error: undefined symbol: __stop___cmd
>>> referenced by iw.c:418
>>>               iw.o:(__handle_cmd)

Suggested-by: Fangrui Song <maskray@google.com>

Signed-off-by: Manoj Gupta <manojgupta@google.com>
---
 iw.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/iw.h b/iw.h
index 7f7f4fc..67aa00c 100644
--- a/iw.h
+++ b/iw.h
@@ -118,8 +118,9 @@ struct chandef {
 		.parent = _section,					\
 		.selector = (_sel),					\
 	};								\
+	_Pragma("GCC diagnostic ignored \"-Wattributes\"") 		\
 	static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \
-	__attribute__((used,section("__cmd"))) =			\
+	__attribute__((used,retain,section("__cmd"))) =			\
 	&__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
 	__COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iw: set retain atrribute on sections
  2021-04-22 18:25 [PATCH] iw: set retain atrribute on sections Manoj Gupta
@ 2021-04-23  7:41 ` Greg KH
  2021-04-24  0:31 ` Manoj Gupta
  2021-04-26 16:30 ` [PATCH v2] " Manoj Gupta
  2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-04-23  7:41 UTC (permalink / raw)
  To: Manoj Gupta; +Cc: Johannes Berg, stable, maskray, llozano, linux-wireless

On Thu, Apr 22, 2021 at 11:25:45AM -0700, Manoj Gupta wrote:
> LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
> collection of C identifier name sections despite the __start_/__stop_
> references.  Simply set the retain attribute so that GCC 11 (if
> configure-time binutils is 2.36 or newer)/Clang 13 will set the
> SHF_GNU_RETAIN section attribute to prevent garbage collection.
> 
> Without the patch, there are linker errors like the following with -z
> start-stop-gc:
> ld.lld: error: undefined symbol: __stop___cmd
> >>> referenced by iw.c:418
> >>>               iw.o:(__handle_cmd)
> 
> Suggested-by: Fangrui Song <maskray@google.com>
> 
> Signed-off-by: Manoj Gupta <manojgupta@google.com>
> ---
>  iw.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)


<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] iw: set retain atrribute on sections
  2021-04-22 18:25 [PATCH] iw: set retain atrribute on sections Manoj Gupta
  2021-04-23  7:41 ` Greg KH
@ 2021-04-24  0:31 ` Manoj Gupta
  2021-04-26 16:30 ` [PATCH v2] " Manoj Gupta
  2 siblings, 0 replies; 4+ messages in thread
From: Manoj Gupta @ 2021-04-24  0:31 UTC (permalink / raw)
  To: Johannes Berg; +Cc: llozano, manojgupta, linux-wireless, Fangrui Song, stable

LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
collection of C identifier name sections despite the __start_/__stop_
references.  Simply set the retain attribute so that GCC 11 (if
configure-time binutils is 2.36 or newer)/Clang 13 will set the
SHF_GNU_RETAIN section attribute to prevent garbage collection.

Without the patch, there are linker errors like the following with -z
start-stop-gc:
ld.lld: error: undefined symbol: __stop___cmd
>>> referenced by iw.c:418
>>>               iw.o:(__handle_cmd)

Suggested-by: Fangrui Song <maskray@google.com>

Cc: stable@vger.kernel.org

Signed-off-by: Manoj Gupta <manojgupta@google.com>
---
 iw.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/iw.h b/iw.h
index 7f7f4fc..67aa00c 100644
--- a/iw.h
+++ b/iw.h
@@ -118,8 +118,9 @@ struct chandef {
 		.parent = _section,					\
 		.selector = (_sel),					\
 	};								\
+	_Pragma("GCC diagnostic ignored \"-Wattributes\"") 		\
 	static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \
-	__attribute__((used,section("__cmd"))) =			\
+	__attribute__((used,retain,section("__cmd"))) =			\
 	&__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
 	__COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] iw: set retain atrribute on sections
  2021-04-22 18:25 [PATCH] iw: set retain atrribute on sections Manoj Gupta
  2021-04-23  7:41 ` Greg KH
  2021-04-24  0:31 ` Manoj Gupta
@ 2021-04-26 16:30 ` Manoj Gupta
  2 siblings, 0 replies; 4+ messages in thread
From: Manoj Gupta @ 2021-04-26 16:30 UTC (permalink / raw)
  To: Johannes Berg, Johannes Berg
  Cc: llozano, manojgupta, linux-wireless, Fangrui Song, stable

LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
collection of C identifier name sections despite the __start_/__stop_
references.  Simply set the retain attribute so that GCC 11 (if
configure-time binutils is 2.36 or newer)/Clang 13 will set the
SHF_GNU_RETAIN section attribute to prevent garbage collection.

Without the patch, there are linker errors like the following with -z
start-stop-gc:
ld.lld: error: undefined symbol: __stop___cmd
>>> referenced by iw.c:418
>>>               iw.o:(__handle_cmd)

Suggested-by: Fangrui Song <maskray@google.com>

Cc: stable@vger.kernel.org

Signed-off-by: Manoj Gupta <manojgupta@google.com>
---
Changes v1 -> v2:
Apply the retain attribute to all places with attribute used.

 iw.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/iw.h b/iw.h
index 7f7f4fc..8ca8e44 100644
--- a/iw.h
+++ b/iw.h
@@ -118,8 +118,9 @@ struct chandef {
 		.parent = _section,					\
 		.selector = (_sel),					\
 	};								\
+	_Pragma("GCC diagnostic ignored \"-Wattributes\"") 		\
 	static struct cmd *__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden ## _p \
-	__attribute__((used,section("__cmd"))) =			\
+	__attribute__((used,retain,section("__cmd"))) =			\
 	&__cmd ## _ ## _symname ## _ ## _handler ## _ ## _nlcmd ## _ ## _idby ## _ ## _hidden
 #define __ACMD(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel, _alias)\
 	__COMMAND(_section, _symname, _name, _args, _nlcmd, _flags, _hidden, _idby, _handler, _help, _sel);\
@@ -141,16 +142,18 @@ struct chandef {
 		.handler = (_handler),					\
 		.help = (_help),					\
 	 };								\
+	_Pragma("GCC diagnostic ignored \"-Wattributes\"") 		\
 	static struct cmd *__section ## _ ## _name ## _p		\
-	__attribute__((used,section("__cmd"))) = &__section ## _ ## _name
+	__attribute__((used,retain,section("__cmd"))) = &__section ## _ ## _name
 
 #define SECTION(_name)							\
 	struct cmd __section ## _ ## _name = {				\
 		.name = (#_name),					\
 		.hidden = 1,						\
 	};								\
+	_Pragma("GCC diagnostic ignored \"-Wattributes\"") 		\
 	static struct cmd *__section ## _ ## _name ## _p		\
-	__attribute__((used,section("__cmd"))) = &__section ## _ ## _name
+	__attribute__((used,retain,section("__cmd"))) = &__section ## _ ## _name
 
 #define DECLARE_SECTION(_name)						\
 	extern struct cmd __section ## _ ## _name;
@@ -162,13 +165,14 @@ struct vendor_event {
 };
 
 #define VENDOR_EVENT(_id, _subcmd, _callback)				\
+	_Pragma("GCC diagnostic ignored \"-Wattributes\"") 		\
 	const struct vendor_event 					\
 	vendor_event_ ## _id ## _ ## _subcmd = {			\
 		.vendor_id = _id,					\
 		.subcmd = _subcmd,					\
 		.callback = _callback,					\
 	}, * const vendor_event_ ## _id ## _ ## _subcmd ## _p		\
-	__attribute__((used,section("vendor_event"))) =			\
+	__attribute__((used,retain,section("vendor_event"))) =			\
 		&vendor_event_ ## _id ## _ ## _subcmd
 
 extern const char iw_version[];
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-26 16:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 18:25 [PATCH] iw: set retain atrribute on sections Manoj Gupta
2021-04-23  7:41 ` Greg KH
2021-04-24  0:31 ` Manoj Gupta
2021-04-26 16:30 ` [PATCH v2] " Manoj Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).