Initial commit
This commit is contained in:
34
tools/mklibs/Makefile
Normal file
34
tools/mklibs/Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Copyright (C) 2009-2013 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=mklibs
|
||||
PKG_VERSION:=0.1.35
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=http://ftp.de.debian.org/debian/pool/main/m/mklibs/
|
||||
PKG_HASH:=ccb1023dc1729c5a37ca6c3eca8e4bac3491116763c8820dfce8eea4845c8567
|
||||
|
||||
HOST_FIXUP:=autoreconf
|
||||
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
|
||||
HOST_CFLAGS += -I$(CURDIR)/include
|
||||
|
||||
define Host/Install
|
||||
$(INSTALL_BIN) \
|
||||
$(HOST_BUILD_DIR)/src/mklibs \
|
||||
$(HOST_BUILD_DIR)/src/mklibs-copy \
|
||||
$(HOST_BUILD_DIR)/src/mklibs-readelf/mklibs-readelf \
|
||||
$(STAGING_DIR_HOST)/bin/
|
||||
endef
|
||||
|
||||
define Host/Clean
|
||||
rm -f $(STAGING_DIR_HOST)/bin/mklibs*
|
||||
endef
|
||||
|
||||
$(eval $(call HostBuild))
|
||||
2559
tools/mklibs/include/elf.h
Normal file
2559
tools/mklibs/include/elf.h
Normal file
File diff suppressed because it is too large
Load Diff
8
tools/mklibs/patches/001-compile.patch
Normal file
8
tools/mklibs/patches/001-compile.patch
Normal file
@@ -0,0 +1,8 @@
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -1,4 +1,4 @@
|
||||
-AC_INIT([mklibs],m4_esyscmd(dpkg-parsechangelog | perl -ne 'print $1 if m/^Version: (.*)$/;'))
|
||||
+AC_INIT([mklibs],m4_esyscmd([head -n1 debian/changelog | awk -F'[\\\\(\\\\)]' '{ print $2 }' | xargs -I{} echo -n {}]))
|
||||
AM_INIT_AUTOMAKE([foreign no-define])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AM_MAINTAINER_MODE
|
||||
20
tools/mklibs/patches/002-disable_symbol_checks.patch
Normal file
20
tools/mklibs/patches/002-disable_symbol_checks.patch
Normal file
@@ -0,0 +1,20 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -524,7 +524,7 @@ while 1:
|
||||
# No progress in last pass. Verify all remaining symbols are weak.
|
||||
for name in unresolved:
|
||||
if not needed_symbols[name].weak:
|
||||
- raise Exception("Unresolvable symbol %s" % name)
|
||||
+ print "WARNING: Unresolvable symbol %s" % name
|
||||
break
|
||||
|
||||
previous_pass_unresolved = unresolved
|
||||
@@ -559,7 +559,7 @@ while 1:
|
||||
for name in needed_symbols:
|
||||
if not name in symbol_provider:
|
||||
if not needed_symbols[name].weak:
|
||||
- raise Exception("No library provides non-weak %s" % name)
|
||||
+ print "WARNING: Unresolvable symbol %s" % name
|
||||
else:
|
||||
lib = symbol_provider[name]
|
||||
library_symbols_used[lib].add(library_symbols[lib][name])
|
||||
50
tools/mklibs/patches/003-no_copy.patch
Normal file
50
tools/mklibs/patches/003-no_copy.patch
Normal file
@@ -0,0 +1,50 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -463,7 +463,7 @@ while 1:
|
||||
passnr = passnr + 1
|
||||
# Gather all already reduced libraries and treat them as objects as well
|
||||
small_libs = []
|
||||
- for lib in regexpfilter(os.listdir(dest_path), "(.*-so-stripped)$"):
|
||||
+ for lib in regexpfilter(os.listdir(dest_path), "(.*-so)$"):
|
||||
obj = dest_path + "/" + lib
|
||||
small_libs.append(obj)
|
||||
inode = os.stat(obj)[ST_INO]
|
||||
@@ -579,12 +579,7 @@ while 1:
|
||||
if not so_file:
|
||||
sys.exit("File not found:" + library)
|
||||
pic_file = find_pic(library)
|
||||
- if not pic_file:
|
||||
- # No pic file, so we have to use the .so file, no reduction
|
||||
- debug(DEBUG_VERBOSE, "No pic file found for", so_file, "; copying")
|
||||
- command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
|
||||
- so_file, dest_path + "/" + so_file_name + "-so-stripped")
|
||||
- else:
|
||||
+ if pic_file:
|
||||
# we have a pic file, recompile
|
||||
debug(DEBUG_SPAM, "extracting from:", pic_file, "so_file:", so_file)
|
||||
soname = extract_soname(so_file)
|
||||
@@ -627,22 +622,14 @@ while 1:
|
||||
cmd.append(library_depends_gcc_libnames(so_file))
|
||||
command(target + "gcc", *cmd)
|
||||
|
||||
- # strip result
|
||||
- command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
|
||||
- dest_path + "/" + so_file_name + "-so",
|
||||
- dest_path + "/" + so_file_name + "-so-stripped")
|
||||
## DEBUG
|
||||
debug(DEBUG_VERBOSE, so_file, "\t", `os.stat(so_file)[ST_SIZE]`)
|
||||
debug(DEBUG_VERBOSE, dest_path + "/" + so_file_name + "-so", "\t",
|
||||
`os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]`)
|
||||
- debug(DEBUG_VERBOSE, dest_path + "/" + so_file_name + "-so-stripped",
|
||||
- "\t", `os.stat(dest_path + "/" + so_file_name + "-so-stripped")[ST_SIZE]`)
|
||||
|
||||
# Finalising libs and cleaning up
|
||||
-for lib in regexpfilter(os.listdir(dest_path), "(.*)-so-stripped$"):
|
||||
- os.rename(dest_path + "/" + lib + "-so-stripped", dest_path + "/" + lib)
|
||||
-for lib in regexpfilter(os.listdir(dest_path), "(.*-so)$"):
|
||||
- os.remove(dest_path + "/" + lib)
|
||||
+for lib in regexpfilter(os.listdir(dest_path), "(.*)-so$"):
|
||||
+ os.rename(dest_path + "/" + lib + "-so", dest_path + "/" + lib)
|
||||
|
||||
# Canonicalize library names.
|
||||
for lib in regexpfilter(os.listdir(dest_path), "(.*so[.\d]*)$"):
|
||||
28
tools/mklibs/patches/004-libpthread_link.patch
Normal file
28
tools/mklibs/patches/004-libpthread_link.patch
Normal file
@@ -0,0 +1,28 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -106,14 +106,14 @@ def library_depends(obj):
|
||||
|
||||
# Return a list of libraries the passed objects depend on. The
|
||||
# libraries are in "-lfoo" format suitable for passing to gcc.
|
||||
-def library_depends_gcc_libnames(obj):
|
||||
+def library_depends_gcc_libnames(obj, soname):
|
||||
if not os.access(obj, os.F_OK):
|
||||
raise Exception("Cannot find lib: " + obj)
|
||||
libs = library_depends(obj)
|
||||
ret = []
|
||||
for i in libs:
|
||||
match = re.match("^(((?P<ld>ld\S*)|(lib(?P<lib>\S+))))\.so.*$", i)
|
||||
- if match:
|
||||
+ if match and not soname in ("libpthread.so.0"):
|
||||
if match.group('ld'):
|
||||
ret.append(find_lib(match.group(0)))
|
||||
elif match.group('lib'):
|
||||
@@ -619,7 +619,7 @@ while 1:
|
||||
cmd.extend(extra_flags)
|
||||
cmd.append("-lgcc")
|
||||
cmd.extend(["-L%s" % a for a in [dest_path] + [sysroot + b for b in lib_path if sysroot == "" or b not in ("/" + libdir + "/", "/usr/" + libdir + "/")]])
|
||||
- cmd.append(library_depends_gcc_libnames(so_file))
|
||||
+ cmd.append(library_depends_gcc_libnames(so_file, soname))
|
||||
command(target + "gcc", *cmd)
|
||||
|
||||
## DEBUG
|
||||
35
tools/mklibs/patches/005-duplicate_syms.patch
Normal file
35
tools/mklibs/patches/005-duplicate_syms.patch
Normal file
@@ -0,0 +1,35 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -531,7 +531,6 @@ while 1:
|
||||
|
||||
library_symbols = {}
|
||||
library_symbols_used = {}
|
||||
- symbol_provider = {}
|
||||
|
||||
# WORKAROUND: Always add libgcc on old-abi arm
|
||||
header = elf_header(find_lib(libraries.copy().pop()))
|
||||
@@ -549,20 +548,13 @@ while 1:
|
||||
library_symbols_used[library] = set()
|
||||
for symbol in symbols:
|
||||
for name in symbol.base_names():
|
||||
- if name in symbol_provider:
|
||||
- debug(DEBUG_SPAM, "duplicate symbol %s in %s and %s" % (symbol, symbol_provider[name], library))
|
||||
- else:
|
||||
- library_symbols[library][name] = symbol
|
||||
- symbol_provider[name] = library
|
||||
+ library_symbols[library][name] = symbol
|
||||
|
||||
# which symbols are actually used from each lib
|
||||
for name in needed_symbols:
|
||||
- if not name in symbol_provider:
|
||||
- if not needed_symbols[name].weak:
|
||||
- print "WARNING: Unresolvable symbol %s" % name
|
||||
- else:
|
||||
- lib = symbol_provider[name]
|
||||
- library_symbols_used[lib].add(library_symbols[lib][name])
|
||||
+ for lib in libraries:
|
||||
+ if name in library_symbols[lib]:
|
||||
+ library_symbols_used[lib].add(library_symbols[lib][name])
|
||||
|
||||
# reduce libraries
|
||||
for library in libraries:
|
||||
14
tools/mklibs/patches/006-uclibc_init.patch
Normal file
14
tools/mklibs/patches/006-uclibc_init.patch
Normal file
@@ -0,0 +1,14 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -595,6 +595,11 @@ while 1:
|
||||
extra_post_obj.append(sysroot + libc_extras_dir + "/sofini.o")
|
||||
symbols.add(ProvidedSymbol('__dso_handle', None, None, True))
|
||||
|
||||
+ if soname in ("libc.so.0"):
|
||||
+ symbols.add(ProvidedSymbol('__uClibc_init', None, None, True))
|
||||
+ symbols.add(ProvidedSymbol('__uClibc_fini', None, None, True))
|
||||
+ extra_flags.append("-Wl,-init,__uClibc_init")
|
||||
+
|
||||
map_file = find_pic_map(library)
|
||||
if map_file:
|
||||
extra_flags.append("-Wl,--version-script=" + map_file)
|
||||
11
tools/mklibs/patches/007-gc_sections.patch
Normal file
11
tools/mklibs/patches/007-gc_sections.patch
Normal file
@@ -0,0 +1,11 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -607,7 +607,7 @@ while 1:
|
||||
# compile in only used symbols
|
||||
cmd = []
|
||||
cmd.extend(gcc_options)
|
||||
- cmd.append("-nostdlib -nostartfiles -shared -Wl,-soname=" + soname)
|
||||
+ cmd.append("-nostdlib -nostartfiles -shared -Wl,--gc-sections -Wl,-soname=" + soname)
|
||||
cmd.extend(["-u%s" % a.linker_name() for a in symbols])
|
||||
cmd.extend(["-o", dest_path + "/" + so_file_name + "-so"])
|
||||
cmd.extend(extra_pre_obj)
|
||||
37
tools/mklibs/patches/008-uclibc_libgcc_link.patch
Normal file
37
tools/mklibs/patches/008-uclibc_libgcc_link.patch
Normal file
@@ -0,0 +1,37 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -113,11 +113,8 @@ def library_depends_gcc_libnames(obj, so
|
||||
ret = []
|
||||
for i in libs:
|
||||
match = re.match("^(((?P<ld>ld\S*)|(lib(?P<lib>\S+))))\.so.*$", i)
|
||||
- if match and not soname in ("libpthread.so.0"):
|
||||
- if match.group('ld'):
|
||||
- ret.append(find_lib(match.group(0)))
|
||||
- elif match.group('lib'):
|
||||
- ret.append('-l%s' % match.group('lib'))
|
||||
+ if match:
|
||||
+ ret.append(find_lib(match.group(0)))
|
||||
return ' '.join(ret)
|
||||
|
||||
class Symbol(object):
|
||||
@@ -584,6 +581,7 @@ while 1:
|
||||
extra_flags = []
|
||||
extra_pre_obj = []
|
||||
extra_post_obj = []
|
||||
+ libgcc_link = find_lib("libgcc_s.so.1")
|
||||
|
||||
symbols.update(library_symbols_used[library])
|
||||
|
||||
@@ -614,9 +612,10 @@ while 1:
|
||||
cmd.append(pic_file)
|
||||
cmd.extend(extra_post_obj)
|
||||
cmd.extend(extra_flags)
|
||||
- cmd.append("-lgcc")
|
||||
cmd.extend(["-L%s" % a for a in [dest_path] + [sysroot + b for b in lib_path if sysroot == "" or b not in ("/" + libdir + "/", "/usr/" + libdir + "/")]])
|
||||
- cmd.append(library_depends_gcc_libnames(so_file, soname))
|
||||
+ if soname != "libgcc_s.so.1":
|
||||
+ cmd.append(library_depends_gcc_libnames(so_file, soname))
|
||||
+ cmd.append(libgcc_link)
|
||||
command(target + "gcc", *cmd)
|
||||
|
||||
## DEBUG
|
||||
63
tools/mklibs/patches/009-uclibc_libpthread_symbols.patch
Normal file
63
tools/mklibs/patches/009-uclibc_libpthread_symbols.patch
Normal file
@@ -0,0 +1,63 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -162,9 +162,10 @@ def undefined_symbols(obj):
|
||||
return result
|
||||
|
||||
class ProvidedSymbol(Symbol):
|
||||
- def __init__(self, name, version, library, default_version):
|
||||
+ def __init__(self, name, version, library, default_version, weak):
|
||||
super(ProvidedSymbol, self).__init__(name, version, library)
|
||||
self.default_version = default_version
|
||||
+ self.weak = weak
|
||||
|
||||
def base_names(self):
|
||||
ret = []
|
||||
@@ -205,11 +206,15 @@ def provided_symbols(obj):
|
||||
if version_string.lower() not in ('base', 'none'):
|
||||
version = version_string
|
||||
|
||||
+ weak = False
|
||||
+ if weak_string.lower() == 'true':
|
||||
+ weak = True
|
||||
+
|
||||
default_version = False
|
||||
if default_version_string.lower() == 'true':
|
||||
default_version = True
|
||||
|
||||
- result.append(ProvidedSymbol(name, version, library, default_version))
|
||||
+ result.append(ProvidedSymbol(name, version, library, default_version, weak))
|
||||
|
||||
return result
|
||||
|
||||
@@ -500,6 +505,9 @@ while 1:
|
||||
debug(DEBUG_SPAM, "present_symbols adding %s" % symbol)
|
||||
names = symbol.base_names()
|
||||
for name in names:
|
||||
+ if name in present_symbols:
|
||||
+ if symbol.library != present_symbols[name].library:
|
||||
+ needed_symbols[name] = UndefinedSymbol(name, True, symbol.version, symbol.library)
|
||||
present_symbols[name] = symbol
|
||||
|
||||
# are we finished?
|
||||
@@ -591,12 +599,16 @@ while 1:
|
||||
# may segfault in ptmalloc_init due to undefined weak reference
|
||||
extra_pre_obj.append(sysroot + libc_extras_dir + "/soinit.o")
|
||||
extra_post_obj.append(sysroot + libc_extras_dir + "/sofini.o")
|
||||
- symbols.add(ProvidedSymbol('__dso_handle', None, None, True))
|
||||
+ symbols.add(ProvidedSymbol('__dso_handle', None, None, True, True))
|
||||
|
||||
- if soname in ("libc.so.0"):
|
||||
- symbols.add(ProvidedSymbol('__uClibc_init', None, None, True))
|
||||
- symbols.add(ProvidedSymbol('__uClibc_fini', None, None, True))
|
||||
- extra_flags.append("-Wl,-init,__uClibc_init")
|
||||
+ if soname == "libc.so.0":
|
||||
+ symbols.add(ProvidedSymbol('__uClibc_init', None, None, True, True))
|
||||
+ symbols.add(ProvidedSymbol('__uClibc_fini', None, None, True, True))
|
||||
+ extra_pre_obj.append("-Wl,-init,__uClibc_init")
|
||||
+
|
||||
+ if soname == "libpthread.so.0":
|
||||
+ symbols.add(ProvidedSymbol('__pthread_initialize_minimal_internal', None, None, True, True))
|
||||
+ extra_flags.append("-Wl,-z,nodelete,-z,initfirst,-init=__pthread_initialize_minimal_internal")
|
||||
|
||||
map_file = find_pic_map(library)
|
||||
if map_file:
|
||||
20
tools/mklibs/patches/010-remove_STT_GNU_IFUNC.patch
Normal file
20
tools/mklibs/patches/010-remove_STT_GNU_IFUNC.patch
Normal file
@@ -0,0 +1,20 @@
|
||||
--- a/src/mklibs-readelf/main.cpp
|
||||
+++ b/src/mklibs-readelf/main.cpp
|
||||
@@ -84,7 +84,7 @@ static void process_symbols_provided (co
|
||||
continue;
|
||||
if (shndx == SHN_UNDEF || shndx == SHN_ABS)
|
||||
continue;
|
||||
- if (type != STT_NOTYPE && type != STT_OBJECT && type != STT_FUNC && type != STT_GNU_IFUNC && type != STT_COMMON && type != STT_TLS)
|
||||
+ if (type != STT_NOTYPE && type != STT_OBJECT && type != STT_FUNC && type != STT_COMMON && type != STT_TLS)
|
||||
continue;
|
||||
if (!name.size())
|
||||
continue;
|
||||
@@ -115,7 +115,7 @@ static void process_symbols_undefined (c
|
||||
continue;
|
||||
if (shndx != SHN_UNDEF)
|
||||
continue;
|
||||
- if (type != STT_NOTYPE && type != STT_OBJECT && type != STT_FUNC && type != STT_GNU_IFUNC && type != STT_COMMON && type != STT_TLS)
|
||||
+ if (type != STT_NOTYPE && type != STT_OBJECT && type != STT_FUNC && type != STT_COMMON && type != STT_TLS)
|
||||
continue;
|
||||
if (!name.size())
|
||||
continue;
|
||||
10
tools/mklibs/patches/011-remove_multiarch.patch
Normal file
10
tools/mklibs/patches/011-remove_multiarch.patch
Normal file
@@ -0,0 +1,10 @@
|
||||
--- a/src/mklibs
|
||||
+++ b/src/mklibs
|
||||
@@ -263,6 +263,7 @@ def extract_soname(so_file):
|
||||
return ""
|
||||
|
||||
def multiarch(paths):
|
||||
+ return paths
|
||||
devnull = open('/dev/null', 'w')
|
||||
dpkg_architecture = subprocess.Popen(
|
||||
['dpkg-architecture', '-qDEB_HOST_MULTIARCH'],
|
||||
Reference in New Issue
Block a user