summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorKarl Lenz <xorangekiller@gmail.com>2019-07-04 20:27:46 -0400
committerAndrew Bartlett <abartlet@samba.org>2019-07-05 03:33:19 +0000
commitf31333d40e6fa38daa32a3ebb32d5a317c06fc62 (patch)
treedb6ffafe96db9f457d64b0ed44a14b8f1609ad35 /source4
parent17d267e9578299b9ccfd0227e522b79152b00a27 (diff)
downloadsamba-f31333d40e6fa38daa32a3ebb32d5a317c06fc62.tar.gz
s4 heimdal_build: Fix static heimdal builds with replacement closefrom()
If Samba was configured with "--nonshared-binary=winexe" to build winexe as a static binary, and the replacement closefrom() function was used (which is default on most GNU/Linux systems without the libbsd development package installed), then winexe would fail to link with the error message shown below. [2631/3059] Linking bin/default/examples/winexe/winexe source4/heimdal/lib/roken/closefrom.c.1.o: In function `rep_closefrom': closefrom.c:(.text+0x0): multiple definition of `rep_closefrom' lib/replace/closefrom.c.2.o:closefrom.c:(.text+0x292): first defined here collect2: error: ld returned 1 exit status The real problem here was not with the winexe build itself - that was merely the application that I was attempting to build statically when I encountered it. As Andrew Bartlett very helpfully pointed out to me, this regression was introduced when "lib/replace/closefrom.c" was added in commit 55529d0f and, more to the point, when the heimdal build started using it in commit 3a7ebd0e. From that point on, any time that Samba's embedded copy of heimdal was statically linked into an application, it would fail to link because heimdal's own rep_closefrom() function in its "roken" library would conflict with the rep_closefrom() function in the "replace" library used elsewhere in Samba - a library which the "roken" library itself depends on. To further compound the problem, heimdal's own "roken" library is also compiled for the host (a necessary distinction for cross-compiled builds) and linked into a small number of utility applications used during the heimdal build. However, they can't link directly against the "replace" library, unlike the main "roken" library build which carries that dependency, because the "replace" library is _not_ built for the host. I solved this problem by eliminating heimdal's version of rep_closefrom() and making it use the one from "lib/replace" everywhere. That wasn't a problem for the main heimdal library that is built for the target because it was already linking in "lib/replace" (that's what caused this problem in the first place!), but to solve the aforementioned issue with "lib/replace" not being built for the host, I added "lib/replace/closefrom.c" to the list of "source4/heimdal/lib/roken" sources to be built for the host to satisfy heimdal's host utilities. Everyone wins, I think. Signed-off-by: Karl Lenz <xorangekiller@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Diffstat (limited to 'source4')
-rw-r--r--source4/heimdal/lib/roken/closefrom.c57
-rw-r--r--source4/heimdal_build/wscript_build10
2 files changed, 6 insertions, 61 deletions
diff --git a/source4/heimdal/lib/roken/closefrom.c b/source4/heimdal/lib/roken/closefrom.c
deleted file mode 100644
index 770eb2c67ac..00000000000
--- a/source4/heimdal/lib/roken/closefrom.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2005 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <config.h>
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "roken.h"
-
-ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
-closefrom(int fd)
-{
- int num = getdtablesize();
-
- if (num < 0)
- num = 1024; /* XXX */
-
- for (; fd <= num; fd++)
- close(fd);
-
- return 0;
-}
diff --git a/source4/heimdal_build/wscript_build b/source4/heimdal_build/wscript_build
index bedc130e07a..163b622fca9 100644
--- a/source4/heimdal_build/wscript_build
+++ b/source4/heimdal_build/wscript_build
@@ -376,7 +376,7 @@ if not bld.CONFIG_SET('USING_SYSTEM_ROKEN'):
target = '../heimdal/lib/roken/err.h',
)
- ROKEN_HOSTCC_SOURCE = '''
+ ROKEN_COMMON_SOURCE = '''
lib/roken/base64.c
lib/roken/ct.c
lib/roken/hex.c
@@ -411,11 +411,13 @@ if not bld.CONFIG_SET('USING_SYSTEM_ROKEN'):
'''
if not bld.CONFIG_SET('HAVE_CLOSEFROM'):
- ROKEN_HOSTCC_SOURCE += '''
- lib/roken/closefrom.c
+ ROKEN_HOSTCC_SOURCE = ROKEN_COMMON_SOURCE + '''
+ ../../lib/replace/closefrom.c
'''
+ else:
+ ROKEN_HOSTCC_SOURCE = ROKEN_COMMON_SOURCE
- ROKEN_SOURCE = ROKEN_HOSTCC_SOURCE + '''
+ ROKEN_SOURCE = ROKEN_COMMON_SOURCE + '''
lib/roken/resolve.c
lib/roken/socket.c
lib/roken/roken_gethostby.c