From 58966617d09e41af2be5c187564cd4e2862a2180 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <abokovoy@redhat.com>
Date: Thu, 12 Jul 2018 12:03:35 +0300
Subject: [PATCH] Change scope to local for symbols automatically added by
 upcoming binutils 2.31

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1600035
---
 samba-4.8.3-vscript.local.patch | 96 +++++++++++++++++++++++++++++++++
 samba.spec                      |  9 +++-
 2 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 samba-4.8.3-vscript.local.patch

diff --git a/samba-4.8.3-vscript.local.patch b/samba-4.8.3-vscript.local.patch
new file mode 100644
index 0000000..2e4ddc2
--- /dev/null
+++ b/samba-4.8.3-vscript.local.patch
@@ -0,0 +1,96 @@
+From dd70ab4d600192336af547c32acd18dcbcb0c8b0 Mon Sep 17 00:00:00 2001
+From: Alexander Bokovoy <ab@samba.org>
+Date: Thu, 12 Jul 2018 10:19:41 +0300
+Subject: [PATCH] wafsamba/samba_abi: always hide ABI symbols which must be
+ local
+
+binutils 2.31 is going to change how shared libraries are linked, such
+that they always provide their own local definitions of the _end, _edata
+and _bss_start symbols.  This would all be fine, except for shared
+libraries that export all symbols be default.  (Rather than just
+exporting those symbols that form part of their API).
+
+According to binutils developers, we should only export the symbols we
+explicitly want to be used. We don't use this principle for all our
+libraries and deliberately don't want to have ABI versioning control for
+all of them, so the change I introduce here is to explicitly mark those
+symbols that will always be added by default linker configuration with
+binutils 2.31 as local. Right now these are '_end', '_edata', and
+'_bss_start' symbols.
+
+Signed-off-by: Alexander Bokovoy <ab@samba.org>
+---
+ buildtools/wafsamba/samba_abi.py      | 10 ++++++----
+ buildtools/wafsamba/tests/test_abi.py | 14 ++++++++++++++
+ 2 files changed, 20 insertions(+), 4 deletions(-)
+
+diff --git a/buildtools/wafsamba/samba_abi.py b/buildtools/wafsamba/samba_abi.py
+index 196b468f5b3..f3f66dd1d45 100644
+--- a/buildtools/wafsamba/samba_abi.py
++++ b/buildtools/wafsamba/samba_abi.py
+@@ -192,10 +192,12 @@ def abi_write_vscript(f, libname, current_version, versions, symmap, abi_match):
+             f.write("\t\t%s;\n" % x)
+     else:
+         f.write("\t\t*;\n")
+-    if abi_match != ["*"]:
+-        f.write("\tlocal:\n")
+-        for x in local_abi:
+-            f.write("\t\t%s;\n" % x[1:])
++    # Always hide symbols that must be local if exist
++    local_abi.extend(["!_end", "!_bss_start", "!_edata"])
++    f.write("\tlocal:\n")
++    for x in local_abi:
++        f.write("\t\t%s;\n" % x[1:])
++    if global_abi != ["*"]:
+         if len(global_abi) > 0:
+             f.write("\t\t*;\n")
+     f.write("};\n")
+diff --git a/buildtools/wafsamba/tests/test_abi.py b/buildtools/wafsamba/tests/test_abi.py
+index bba78c1ba07..30c152417c7 100644
+--- a/buildtools/wafsamba/tests/test_abi.py
++++ b/buildtools/wafsamba/tests/test_abi.py
+@@ -66,6 +66,10 @@ class WriteVscriptTests(TestCase):
+ 1.0 {
+ \tglobal:
+ \t\t*;
++\tlocal:
++\t\t_end;
++\t\t_bss_start;
++\t\t_edata;
+ };
+ """)
+ 
+@@ -84,6 +88,10 @@ MYLIB_0.1 {
+ 1.0 {
+ \tglobal:
+ \t\t*;
++\tlocal:
++\t\t_end;
++\t\t_bss_start;
++\t\t_edata;
+ };
+ """)
+ 
+@@ -99,6 +107,9 @@ MYLIB_0.1 {
+ \t\t*;
+ \tlocal:
+ \t\texc_*;
++\t\t_end;
++\t\t_bss_start;
++\t\t_edata;
+ };
+ """)
+ 
+@@ -115,6 +126,9 @@ MYLIB_0.1 {
+ \t\tpub_*;
+ \tlocal:
+ \t\texc_*;
++\t\t_end;
++\t\t_bss_start;
++\t\t_edata;
+ \t\t*;
+ };
+ """)
+-- 
+2.17.1
+
diff --git a/samba.spec b/samba.spec
index 693774d..0439d06 100644
--- a/samba.spec
+++ b/samba.spec
@@ -6,7 +6,7 @@
 # ctdb is enabled by default, you can disable it with: --without clustering
 %bcond_without clustering
 
-%define main_release 3
+%define main_release 4
 
 %define samba_version 4.8.3
 %define talloc_version 2.1.11
@@ -89,7 +89,7 @@
 
 Name:           samba
 Version:        %{samba_version}
-Release:        %{samba_release}.1
+Release:        %{samba_release}
 
 %if 0%{?rhel}
 Epoch:          0
@@ -123,6 +123,7 @@ Source200:      README.dc
 Source201:      README.downgrade
 
 Patch0:         samba-4.8.3-fix_krb5_plugins.patch
+Patch1:         samba-4.8.3-vscript.local.patch
 
 Requires(pre): /usr/sbin/groupadd
 Requires(post): systemd
@@ -3530,6 +3531,10 @@ fi
 %endif # with_clustering_support
 
 %changelog
+* Thu Jul 12 2018 Alexander Bokovoy <abokovoy@redhat.com> - 2:4.8.3-4
+- Change scope to local for symbols automatically added by upcoming binutils 2.31
+- Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1600035
+
 * Wed Jul 11 2018 Alexander Bokovoy <abokovoy@redhat.com> - 2:4.8.3-3
 - Rebuild Samba against binutils 2.30.90-2.fc29
 - Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1600035