Package init

This commit is contained in:
overweight 2019-09-30 10:53:54 -04:00
commit 9b27a1f5b9
3 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,58 @@
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

BIN
iw-5.0.1.tar.gz Normal file

Binary file not shown.

43
iw.spec Normal file
View File

@ -0,0 +1,43 @@
Name: iw
Version: 5.0.1
Release: 1
Summary: A nl80211 based wireless configuration tool
License: ISC
URL: https://wireless.kernel.org/en/users/Documentation/%{name}
Source0: https://www.kernel.org/pub/software/network/%{name}/%{name}-%{version}.tar.gz
Patch6000: 0049-iw-fix-cmd_size-determination-with-LTO.patch
BuildRequires: gcc kernel-headers libnl3-devel pkgconfig
%description
iw is a new nl80211 based CLI configuration utility for wireless devices.
It supports all new drivers that have been added to the kernel recently.
The old tool iwconfig, which uses Wireless Extensions interface,
is deprecated and it's strongly recommended to switch to iw and nl80211.
%package_help
%prep
%autosetup -n %{name}-%{version} -p1
%build
export CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS"
%make_build
%install
%make_install MANDIR=%{_mandir}
%files
%defattr(-,root,root)
%license COPYING
%{_sbindir}/%{name}
%files help
%defattr(-,root,root)
%{_mandir}/man8/iw.*
%changelog
* Mon Sep 02 2019 openEuler Buildteam <buildteam@openeuler.org> - 5.0.1-1
- Package init