[SCM] Samba Shared Repository - branch master updated

Andrew Tridgell tridge at samba.org
Tue Apr 12 20:38:04 MDT 2011


The branch, master has been updated
       via  380bd49 build: use readelf as a replacement for ldd
       via  cec7c53 libds: Make flag_mapping a library
       via  fe458f2 lib/util make UTIL_TDB a library
       via  5694ba5 libcli/ldap pull LIBCLI_LDAP_MESSAGE and LIBCLI_LDAP_NDR into a library
       via  601835e build: speed up SYMBOLCHECK code
      from  4edc98e s3: For net ads join, create a krb5.conf

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 380bd493bb02744dfd4e88a875d3beabb3c784f8
Author: Andrew Tridgell <tridge at samba.org>
Date:   Tue Apr 12 21:20:41 2011 +1000

    build: use readelf as a replacement for ldd
    
    using readelf allows us to do a non-recursive library listing, which
    is important to remove false positive symbol duplication
    
    Autobuild-User: Andrew Tridgell <tridge at samba.org>
    Autobuild-Date: Wed Apr 13 04:37:33 CEST 2011 on sn-devel-104

commit cec7c53da955ade9a218fdf0aaa44568d2417eb7
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Apr 8 13:18:14 2011 +1000

    libds: Make flag_mapping a library
    
    This is a tiny library, but otherwise the functions end up in multiple
    other libraries.
    
    Andrew Bartlett

commit fe458f23addff53378c5984fa80b813af821c98e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Apr 8 12:55:49 2011 +1000

    lib/util make UTIL_TDB a library

commit 5694ba507cf3774f6f1d30bb2b584a5f28b88a4b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Apr 8 11:16:45 2011 +1000

    libcli/ldap pull LIBCLI_LDAP_MESSAGE and LIBCLI_LDAP_NDR into a library
    
    This reduces symbol duplication
    
    Andrew Bartlett

commit 601835ee6db8952911216f8f7f02f5101dc3b269
Author: Andrew Tridgell <tridge at samba.org>
Date:   Tue Apr 12 11:11:55 2011 +1000

    build: speed up SYMBOLCHECK code
    
    this uses a nm and ldd cache to speed up the duplicate symbol checking
    code
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 buildtools/wafsamba/symbols.py    |  141 +++++++++++++++++++++++++++++--------
 lib/util/wscript_build            |    5 +-
 libcli/ldap/wscript_build         |   20 ++----
 libds/common/wscript_build        |    8 ++-
 source3/passdb/wscript_build      |    2 +-
 source3/wscript_build             |    8 +-
 source4/dsdb/wscript_build        |    4 +-
 source4/libcli/ldap/wscript_build |    2 +-
 8 files changed, 132 insertions(+), 58 deletions(-)


Changeset truncated at 500 lines:

diff --git a/buildtools/wafsamba/symbols.py b/buildtools/wafsamba/symbols.py
index 5059c60..ed19517 100644
--- a/buildtools/wafsamba/symbols.py
+++ b/buildtools/wafsamba/symbols.py
@@ -1,7 +1,7 @@
 # a waf tool to extract symbols from object files or libraries
 # using nm, producing a set of exposed defined/undefined symbols
 
-import Utils, Build, subprocess, Logs
+import Utils, Build, subprocess, Logs, re
 from samba_wildcard import fake_build_environment
 from samba_utils import *
 
@@ -21,12 +21,30 @@ from samba_utils import *
 #
 # LOCAL_CACHE(bld, 'TARGET_TYPE') : dictionary mapping subsystem name to target type
 
-def symbols_extract(objfiles, dynamic=False):
+
+def symbols_extract(bld, objfiles, dynamic=False):
     '''extract symbols from objfile, returning a dictionary containing
        the set of undefined and public symbols for each file'''
 
     ret = {}
 
+    # see if we can get some results from the nm cache
+    if not bld.env.nm_cache:
+        bld.env.nm_cache = {}
+
+    objfiles = set(objfiles).copy()
+
+    remaining = set()
+    for obj in objfiles:
+        if obj in bld.env.nm_cache:
+            ret[obj] = bld.env.nm_cache[obj].copy()
+        else:
+            remaining.add(obj)
+    objfiles = remaining
+
+    if len(objfiles) == 0:
+        return ret
+
     cmd = ["nm"]
     if dynamic:
         # needed for some .so files
@@ -60,6 +78,13 @@ def symbols_extract(objfiles, dynamic=False):
         elif symbol_type in "U":
             ret[filename]["UNDEFINED"].add(symbol)
 
+    # add to the cache
+    for obj in objfiles:
+        if obj in ret:
+            bld.env.nm_cache[obj] = ret[obj].copy()
+        else:
+            bld.env.nm_cache[obj] = { "PUBLIC": set(), "UNDEFINED" : set() }
+
     return ret
 
 
@@ -69,35 +94,102 @@ def real_name(name):
     return name
 
 
-def get_ldd_libs(bld, binname):
-    '''find the list of linked libraries for any binary or library
-    binname is the path to the binary/library on disk
-    '''
-    ret = set()
-    lddpipe = subprocess.Popen(['ldd', binname], stdout=subprocess.PIPE).stdout
+def find_ldd_path(bld, libname, binary):
+    '''find the path to the syslib we will link against'''
+    ret = None
+    if not bld.env.syslib_paths:
+        bld.env.syslib_paths = {}
+    if libname in bld.env.syslib_paths:
+        return bld.env.syslib_paths[libname]
+
+    lddpipe = subprocess.Popen(['ldd', binary], stdout=subprocess.PIPE).stdout
     for line in lddpipe:
         line = line.strip()
         cols = line.split(" ")
-        if len(cols) < 3 or cols[1] != "=>" or cols[2] == '':
+        if len(cols) < 3 or cols[1] != "=>":
             continue
-        ret.add(os.path.realpath(cols[2]))
+        if cols[0].startswith("libc."):
+            # save this one too
+            bld.env.libc_path = cols[2]
+        if cols[0].startswith(libname):
+            ret = cols[2]
+    bld.env.syslib_paths[libname] = ret
+    return ret
+
+
+# some regular expressions for parsing readelf output
+re_sharedlib = re.compile('Shared library: \[(.*)\]')
+re_rpath     = re.compile('Library rpath: \[(.*)\]')
+
+def get_libs(bld, binname):
+    '''find the list of linked libraries for any binary or library
+    binname is the path to the binary/library on disk
+
+    We do this using readelf instead of ldd as we need to avoid recursing
+    into system libraries
+    '''
+
+    # see if we can get the result from the ldd cache
+    if not bld.env.lib_cache:
+        bld.env.lib_cache = {}
+    if binname in bld.env.lib_cache:
+        return bld.env.lib_cache[binname].copy()
+
+    rpath = []
+    libs = set()
+
+    elfpipe = subprocess.Popen(['readelf', '--dynamic', binname], stdout=subprocess.PIPE).stdout
+    for line in elfpipe:
+        m = re_sharedlib.search(line)
+        if m:
+            libs.add(m.group(1))
+        m = re_rpath.search(line)
+        if m:
+            rpath.extend(m.group(1).split(":"))
+
+    ret = set()
+    for lib in libs:
+        found = False
+        for r in rpath:
+            path = os.path.join(r, lib)
+            if os.path.exists(path):
+                ret.add(os.path.realpath(path))
+                found = True
+                break
+        if not found:
+            # we didn't find this lib using rpath. It is probably a system
+            # library, so to find the path to it we either need to use ldd
+            # or we need to start parsing /etc/ld.so.conf* ourselves. We'll
+            # use ldd for now, even though it is slow
+            path = find_ldd_path(bld, lib, binname)
+            if path:
+                ret.add(os.path.realpath(path))
+
+    bld.env.lib_cache[binname] = ret.copy()
+
     return ret
 
 
-def get_ldd_libs_recursive(bld, binname, seen=set()):
+def get_libs_recursive(bld, binname, seen):
     '''find the recursive list of linked libraries for any binary or library
     binname is the path to the binary/library on disk. seen is a set used
     to prevent loops
     '''
     if binname in seen:
         return set()
-    ret = get_ldd_libs(bld, binname)
+    ret = get_libs(bld, binname)
     seen.add(binname)
     for lib in ret:
-        ret = ret.union(get_ldd_libs_recursive(bld, lib, seen))
+        # we don't want to recurse into system libraries. If a system
+        # library that we use (eg. libcups) happens to use another library
+        # (such as libkrb5) which contains common symbols with our own
+        # libraries, then that is not an error
+        if lib in bld.env.library_dict:
+            ret = ret.union(get_libs_recursive(bld, lib, seen))
     return ret
 
 
+
 def find_syslib_path(bld, libname, deps):
     '''find the path to the syslib we will link against'''
     # the strategy is to use the targets that depend on the library, and run ldd
@@ -108,20 +200,7 @@ def find_syslib_path(bld, libname, deps):
     if libname == "python":
         libname += bld.env.PYTHON_VERSION
 
-    ret = None
-
-    lddpipe = subprocess.Popen(['ldd', linkpath], stdout=subprocess.PIPE).stdout
-    for line in lddpipe:
-        line = line.strip()
-        cols = line.split(" ")
-        if len(cols) < 3 or cols[1] != "=>":
-            continue
-        if cols[0].startswith("lib%s." % libname.lower()):
-            ret = cols[2]
-        if cols[0].startswith("libc."):
-            # save this one too
-            bld.env.libc_path = cols[2]
-    return ret
+    return find_ldd_path(bld, "lib%s" % libname.lower(), linkpath)
 
 
 def build_symbol_sets(bld, tgt_list):
@@ -143,7 +222,7 @@ def build_symbol_sets(bld, tgt_list):
                 objlist.append(objpath)
                 objmap[objpath] = t
 
-    symbols = symbols_extract(objlist)
+    symbols = symbols_extract(bld, objlist)
     for obj in objlist:
         t = objmap[obj]
         t.public_symbols = t.public_symbols.union(symbols[obj]["PUBLIC"])
@@ -236,7 +315,7 @@ def build_syslib_sets(bld, tgt_list):
     syslib_paths.append(bld.env.libc_path)
     objmap[bld.env.libc_path] = 'c'
 
-    symbols = symbols_extract(syslib_paths, dynamic=True)
+    symbols = symbols_extract(bld, syslib_paths, dynamic=True)
 
     # keep a map of syslib names to public symbols
     bld.env.syslib_symbols = {}
@@ -503,9 +582,9 @@ def report_duplicate(bld, binname, sym, libs):
 
 def symbols_dupcheck_binary(bld, binname):
     '''check for duplicated symbols in one binary'''
-    libs = get_ldd_libs_recursive(bld, binname)
 
-    symlist = symbols_extract(libs, dynamic=True)
+    libs = get_libs_recursive(bld, binname, set())
+    symlist = symbols_extract(bld, libs, dynamic=True)
 
     symmap = {}
     for libpath in symlist:
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 11bb40a..901f200 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -57,10 +57,11 @@ bld.SAMBA_LIBRARY('wrap_xattr',
 	)
 
 
-bld.SAMBA_SUBSYSTEM('UTIL_TDB',
+bld.SAMBA_LIBRARY('UTIL_TDB',
 	source='util_tdb.c',
 	local_include=False,
-	public_deps='tdb talloc'
+	public_deps='tdb talloc',
+                  private_library=True
 	)
 
 bld.SAMBA_SUBSYSTEM('UTIL_TEVENT',
diff --git a/libcli/ldap/wscript_build b/libcli/ldap/wscript_build
index feab651..63a2de1 100644
--- a/libcli/ldap/wscript_build
+++ b/libcli/ldap/wscript_build
@@ -1,17 +1,9 @@
 #!/usr/bin/env python
 
-bld.SAMBA_SUBSYSTEM('LIBCLI_LDAP_MESSAGE',
-	source='ldap_message.c',
-	public_deps='errors talloc ldb',
-	public_headers='ldap_message.h ldap_errors.h',
-	deps='samba-util asn1util'
+bld.SAMBA_LIBRARY('cli-ldap-common',
+                  source='ldap_message.c ldap_ndr.c',
+                  public_deps='errors talloc ldb',
+                  public_headers='ldap_message.h ldap_errors.h',
+                  deps='samba-util asn1util NDR_SECURITY tevent',
+                  private_library=True
 	)
-
-
-bld.SAMBA_SUBSYSTEM('LIBCLI_LDAP_NDR',
-	source='ldap_ndr.c',
-	public_deps='errors talloc',
-	public_headers='ldap_ndr.h',
-	deps='samba-util ldb NDR_SECURITY tevent'
-	)
-
diff --git a/libds/common/wscript_build b/libds/common/wscript_build
index f6ed209..8ee2177 100644
--- a/libds/common/wscript_build
+++ b/libds/common/wscript_build
@@ -1,4 +1,6 @@
 
-bld.SAMBA_SUBSYSTEM('flag_mapping',
-                    public_deps='talloc replace',
-                    source='flag_mapping.c')
+bld.SAMBA_LIBRARY('flag_mapping',
+                  public_deps='talloc replace',
+                  source='flag_mapping.c',
+		  private_library=True,
+		  deps='samba-util-common')
diff --git a/source3/passdb/wscript_build b/source3/passdb/wscript_build
index 2c0416f..79b1435 100644
--- a/source3/passdb/wscript_build
+++ b/source3/passdb/wscript_build
@@ -28,7 +28,7 @@ bld.SAMBA3_MODULE('pdb_ldap',
 bld.SAMBA3_MODULE('pdb_ads',
                  subsystem='pdb',
                  source=PDB_ADS_SRC,
-                 deps='LIBCLI_LDAP_NDR TLDAP',
+                 deps='cli-ldap-common TLDAP',
                  init_function='',
                  internal_module=bld.SAMBA3_IS_STATIC_MODULE('pdb_ads'),
                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('pdb_ads'))
diff --git a/source3/wscript_build b/source3/wscript_build
index 12b7944..300f5b3 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -808,7 +808,7 @@ bld.SAMBA3_SUBSYSTEM('LIBDRSUAPI',
 
 bld.SAMBA3_SUBSYSTEM('CLDAP',
                     source='libads/cldap.c',
-                    deps='LIBCLI_LDAP_MESSAGE LIBCLI_LDAP_NDR LIBCLI_CLDAP LIBTSOCKET',
+                    deps='cli-ldap-common LIBCLI_CLDAP LIBTSOCKET',
                     vars=locals())
 
 bld.SAMBA3_SUBSYSTEM('SECRETS3',
@@ -824,7 +824,7 @@ bld.SAMBA3_SUBSYSTEM('SMBLDAP',
 
 bld.SAMBA3_LIBRARY('ads',
                    source=LIBADS_SRC,
-                   deps='LIBCLI_LDAP_NDR krb5 gssapi gssapi_krb5 ldap lber',
+                   deps='cli-ldap-common krb5 gssapi gssapi_krb5 ldap lber',
                    private_library=True,
                    vars=locals(),
                    enabled=bld.env.HAVE_ADS)
@@ -1136,7 +1136,7 @@ bld.SAMBA3_BINARY('pdbedit',
                  source=PDBEDIT_SRC,
                  deps='''talloc tdb tevent cap resolv wbclient param LIB_NONSMBD
                  LIBNTLMSSP LIBSMB_ERR POPT_SAMBA3 passdb SMBLDAP
-                 PASSWD_UTIL LIBCLI_LDAP_NDR''',
+                 PASSWD_UTIL cli-ldap-common''',
                  vars=locals())
 
 bld.SAMBA3_BINARY('smbget',
@@ -1262,7 +1262,7 @@ bld.SAMBA3_BINARY('ntlm_auth' + bld.env.suffix3,
                  deps='''tdb talloc cap resolv krb5 k5crypto com_err wbclient param LIB_NONSMBD
                  samba3core LIBNTLMSSP POPT_SAMBA3 asn1util LIBTSOCKET
                  passdb SMBLDAP winbind-client LIBINIPARSER LIBADS_SERVER
-                 NDR_SAMR NDR_LSA NDR_NETLOGON LIBCLI_LDAP_NDR LIBNMB SLCACHE SPNEGO_PARSE KRBCLIENT''',
+                 NDR_SAMR NDR_LSA NDR_NETLOGON cli-ldap-common LIBNMB SLCACHE SPNEGO_PARSE KRBCLIENT''',
                  vars=locals())
 
 bld.SAMBA3_BINARY('timelimit',
diff --git a/source4/dsdb/wscript_build b/source4/dsdb/wscript_build
index 364edf1..83d7433 100644
--- a/source4/dsdb/wscript_build
+++ b/source4/dsdb/wscript_build
@@ -8,7 +8,7 @@ bld.SAMBA_LIBRARY('samdb',
 	autoproto='samdb/samdb_proto.h',
 	public_deps='krb5',
 	vnum='0.0.1',
-	deps='ndr NDR_DRSUAPI NDR_DRSBLOBS auth_system_session LIBCLI_AUTH ndr SAMDB_SCHEMA ldbsamba samdb-common LIBCLI_DRSUAPI LIBCLI_LDAP_NDR samba-util com_err authkrb5 credentials ldbwrap',
+	deps='ndr NDR_DRSUAPI NDR_DRSBLOBS auth_system_session LIBCLI_AUTH ndr SAMDB_SCHEMA ldbsamba samdb-common LIBCLI_DRSUAPI cli-ldap-common samba-util com_err authkrb5 credentials ldbwrap',
 	)
 
 
@@ -16,7 +16,7 @@ bld.SAMBA_LIBRARY('samdb-common',
 	source='common/util.c common/util_groups.c common/util_samr.c common/dsdb_dn.c common/dsdb_access.c',
 	autoproto='common/proto.h',
 	private_library=True,
-	deps='ldb NDR_DRSBLOBS UTIL_LDB LIBCLI_AUTH samba-hostconfig samba_socket LIBCLI_LDAP_NDR flag_mapping'
+	deps='ldb NDR_DRSBLOBS UTIL_LDB LIBCLI_AUTH samba-hostconfig samba_socket cli-ldap-common flag_mapping'
 	)
 
 
diff --git a/source4/libcli/ldap/wscript_build b/source4/libcli/ldap/wscript_build
index a7b3717..99b6c4e 100644
--- a/source4/libcli/ldap/wscript_build
+++ b/source4/libcli/ldap/wscript_build
@@ -5,7 +5,7 @@ bld.SAMBA_LIBRARY('cli-ldap',
                   autoproto='ldap_proto.h',
                   public_deps='errors tevent LIBPACKET',
                   public_headers='libcli_ldap.h:ldap-util.h',
-                  deps='LIBCLI_COMPOSITE samba_socket NDR_SAMR LIBTLS LIBCLI_LDAP_NDR ndr LP_RESOLVE gensec LIBCLI_LDAP_MESSAGE',
+                  deps='LIBCLI_COMPOSITE samba_socket NDR_SAMR LIBTLS ndr LP_RESOLVE gensec cli-ldap-common',
                   private_library=True
                   )
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list