59 lines
2.1 KiB
Diff
59 lines
2.1 KiB
Diff
|
|
From ae03bc6effdffe145c871d70ce346f93faefc71b Mon Sep 17 00:00:00 2001
|
||
|
|
From: Johannes Berg <johannes.berg@intel.com>
|
||
|
|
Date: Thu, 28 Feb 2019 21:34:03 +0100
|
||
|
|
Subject: [PATCH 49/50] iw: fix cmd_size determination with LTO
|
||
|
|
|
||
|
|
Use a separate section to determine the cmd_size as in LTO
|
||
|
|
the entries in __cmd get freely rearranged, leading to a
|
||
|
|
(usually) very large cmd_size, and thus to the whole thing
|
||
|
|
not working.
|
||
|
|
|
||
|
|
Change-Id: I3437ad34de1d927961a3e98f109794d7a884327f
|
||
|
|
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
|
||
|
|
---
|
||
|
|
iw.c | 21 ++++++++++++++++++++-
|
||
|
|
1 file changed, 20 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/iw.c b/iw.c
|
||
|
|
index 76f152d..afc8118 100644
|
||
|
|
--- a/iw.c
|
||
|
|
+++ b/iw.c
|
||
|
|
@@ -542,6 +542,25 @@ int handle_cmd(struct nl80211_state *state, enum id_input idby,
|
||
|
|
return __handle_cmd(state, idby, argc, argv, NULL);
|
||
|
|
}
|
||
|
|
|
||
|
|
+/*
|
||
|
|
+ * Unfortunately, I don't know how densely the linker packs the struct cmd.
|
||
|
|
+ * For example, if you have a 72-byte struct cmd, the linker will pad each
|
||
|
|
+ * out to 96 bytes before putting them together in the section. There must
|
||
|
|
+ * be some algorithm, but I haven't found it yet.
|
||
|
|
+ *
|
||
|
|
+ * We used to calculate this by taking the (abs value of) the difference
|
||
|
|
+ * between __section_get and __section_set, but if LTO is enabled then this
|
||
|
|
+ * stops working because the entries of the "__cmd" section get rearranged
|
||
|
|
+ * freely by the compiler/linker.
|
||
|
|
+ *
|
||
|
|
+ * Fix this by using yet another "__sizer" section that only contains these
|
||
|
|
+ * two entries - then the (abs value of) the difference between them will
|
||
|
|
+ * be how they get packed and that can be used to iterate the __cmd section
|
||
|
|
+ * as well.
|
||
|
|
+ */
|
||
|
|
+static struct cmd sizer1 __attribute__((used,section("__sizer"))) = {};
|
||
|
|
+static struct cmd sizer2 __attribute__((used,section("__sizer"))) = {};
|
||
|
|
+
|
||
|
|
int main(int argc, char **argv)
|
||
|
|
{
|
||
|
|
struct nl80211_state nlstate;
|
||
|
|
@@ -549,7 +568,7 @@ int main(int argc, char **argv)
|
||
|
|
const struct cmd *cmd = NULL;
|
||
|
|
|
||
|
|
/* calculate command size including padding */
|
||
|
|
- cmd_size = labs((long)&__section_set - (long)&__section_get);
|
||
|
|
+ cmd_size = labs((uintptr_t)&sizer2 - (uintptr_t)&sizer1);
|
||
|
|
/* strip off self */
|
||
|
|
argc--;
|
||
|
|
argv0 = *argv++;
|
||
|
|
--
|
||
|
|
1.8.3.1
|
||
|
|
|