mirror of
https://git.yoctoproject.org/poky
synced 2026-02-21 17:09:42 +01:00
We have a problem when for example, a glibc 2.27 based system builds some library like libpopt-native and puts it into sstate then it is reused on a pre glibc-2.27 system to build something which depends on popt like rpm-native. This results in an error like: recipe-sysroot-native/usr/lib/libpopt.so: undefined reference to `glob@GLIBC_2.27' In the past we've had this problem with new symbols like getrandom and getentropy, here its with a more complex symbol where there is an old version and a newer version. We've looked into various options, basically we cannot link against our uninative libc/ld.so since we don't have the right headers or compiler link libraries. The compiler doesn't allow you to switch in a new set either, even if we did want to ship them. Shipping a complete compiler, dev headers and libs also isn't an option. On the other hand if we follow the ld man page, it does say: """ The reasons for allowing undefined symbol references in shared libraries specified at link time are that: - A shared library specified at link time may not be the same as the one that is available at load time, so the symbol might actually be resolvable at load time. """ which is exactly this case. By the time the binary runs, it will use our uninative loader and libc and the symbol will be available. Therefore we basically have a choice, we get weird intermittent bugs, we drop uninative entirely, or we pass this option. If we pass the option, we can drop the other workarounds too. (From OE-Core rev: 75a62ede393bf6b4972390ef5290d50add19341a) (From OE-Core rev: d18bf7fa8e80d6cfaf3fdbe1ab06eec84b954432) (From OE-Core rev: 4545f5436a5a106154680825ecb1cb60437faa91) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> [Clean up for Rocko context] Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
165 lines
7.3 KiB
Plaintext
165 lines
7.3 KiB
Plaintext
UNINATIVE_LOADER ?= "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/lib/${@bb.utils.contains('BUILD_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', 'ld-linux.so.2', d)}"
|
|
UNINATIVE_STAGING_DIR ?= "${STAGING_DIR}"
|
|
|
|
UNINATIVE_URL ?= "unset"
|
|
UNINATIVE_TARBALL ?= "${BUILD_ARCH}-nativesdk-libc.tar.bz2"
|
|
# Example checksums
|
|
#UNINATIVE_CHECKSUM[i586] = "dead"
|
|
#UNINATIVE_CHECKSUM[x86_64] = "dead"
|
|
UNINATIVE_DLDIR ?= "${DL_DIR}/uninative/"
|
|
|
|
# Enabling uninative will change the following variables so they need to go the parsing white list to prevent multiple recipe parsing
|
|
BB_HASHCONFIG_WHITELIST += "NATIVELSBSTRING SSTATEPOSTUNPACKFUNCS BUILD_LDFLAGS"
|
|
|
|
addhandler uninative_event_fetchloader
|
|
uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted"
|
|
|
|
addhandler uninative_event_enable
|
|
uninative_event_enable[eventmask] = "bb.event.ConfigParsed"
|
|
|
|
python uninative_event_fetchloader() {
|
|
"""
|
|
This event fires on the parent and will try to fetch the tarball if the
|
|
loader isn't already present.
|
|
"""
|
|
|
|
chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH"))
|
|
if not chksum:
|
|
bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH"))
|
|
|
|
loader = d.getVar("UNINATIVE_LOADER")
|
|
loaderchksum = loader + ".chksum"
|
|
if os.path.exists(loader) and os.path.exists(loaderchksum):
|
|
with open(loaderchksum, "r") as f:
|
|
readchksum = f.read().strip()
|
|
if readchksum == chksum:
|
|
return
|
|
|
|
import subprocess
|
|
try:
|
|
# Save and restore cwd as Fetch.download() does a chdir()
|
|
olddir = os.getcwd()
|
|
|
|
tarball = d.getVar("UNINATIVE_TARBALL")
|
|
tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR"), chksum)
|
|
tarballpath = os.path.join(tarballdir, tarball)
|
|
|
|
if not os.path.exists(tarballpath):
|
|
bb.utils.mkdirhier(tarballdir)
|
|
if d.getVar("UNINATIVE_URL") == "unset":
|
|
bb.fatal("Uninative selected but not configured, please set UNINATIVE_URL")
|
|
|
|
localdata = bb.data.createCopy(d)
|
|
localdata.setVar('FILESPATH', "")
|
|
localdata.setVar('DL_DIR', tarballdir)
|
|
# Our games with path manipulation of DL_DIR mean standard PREMIRRORS don't work
|
|
# and we can't easily put 'chksum' into the url path from a url parameter with
|
|
# the current fetcher url handling
|
|
ownmirror = d.getVar('SOURCE_MIRROR_URL')
|
|
if ownmirror:
|
|
localdata.appendVar("PREMIRRORS", " ${UNINATIVE_URL}${UNINATIVE_TARBALL} ${SOURCE_MIRROR_URL}/uninative/%s/${UNINATIVE_TARBALL}" % chksum)
|
|
|
|
srcuri = d.expand("${UNINATIVE_URL}${UNINATIVE_TARBALL};sha256sum=%s" % chksum)
|
|
bb.note("Fetching uninative binary shim from %s" % srcuri)
|
|
|
|
fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False)
|
|
fetcher.download()
|
|
localpath = fetcher.localpath(srcuri)
|
|
if localpath != tarballpath and os.path.exists(localpath) and not os.path.exists(tarballpath):
|
|
# Follow the symlink behavior from the bitbake fetch2.
|
|
# This will cover the case where an existing symlink is broken
|
|
# as well as if there are two processes trying to create it
|
|
# at the same time.
|
|
if os.path.islink(tarballpath):
|
|
# Broken symbolic link
|
|
os.unlink(tarballpath)
|
|
|
|
# Deal with two processes trying to make symlink at once
|
|
try:
|
|
os.symlink(localpath, tarballpath)
|
|
except FileExistsError:
|
|
pass
|
|
|
|
# ldd output is "ldd (Ubuntu GLIBC 2.23-0ubuntu10) 2.23", extract last option from first line
|
|
glibcver = subprocess.check_output(["ldd", "--version"]).decode('utf-8').split('\n')[0].split()[-1]
|
|
if bb.utils.vercmp_string(d.getVar("UNINATIVE_MAXGLIBCVERSION"), glibcver) < 0:
|
|
raise RuntimeError("Your host glibc verson (%s) is newer than that in uninative (%s). Disabling uninative so that sstate is not corrupted." % (glibcver, d.getVar("UNINATIVE_MAXGLIBCVERSION")))
|
|
|
|
cmd = d.expand("\
|
|
mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; \
|
|
cd ${UNINATIVE_STAGING_DIR}-uninative; \
|
|
tar -xjf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; \
|
|
${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py \
|
|
${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux \
|
|
${UNINATIVE_LOADER} \
|
|
${UNINATIVE_LOADER} \
|
|
${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative \
|
|
${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so" % chksum)
|
|
subprocess.check_output(cmd, shell=True)
|
|
|
|
with open(loaderchksum, "w") as f:
|
|
f.write(chksum)
|
|
|
|
enable_uninative(d)
|
|
|
|
except RuntimeError as e:
|
|
bb.warn(str(e))
|
|
except bb.fetch2.BBFetchException as exc:
|
|
bb.warn("Disabling uninative as unable to fetch uninative tarball: %s" % str(exc))
|
|
bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.")
|
|
except subprocess.CalledProcessError as exc:
|
|
bb.warn("Disabling uninative as unable to install uninative tarball: %s" % str(exc))
|
|
bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.")
|
|
finally:
|
|
os.chdir(olddir)
|
|
}
|
|
|
|
python uninative_event_enable() {
|
|
"""
|
|
This event handler is called in the workers and is responsible for setting
|
|
up uninative if a loader is found.
|
|
"""
|
|
enable_uninative(d)
|
|
}
|
|
|
|
def enable_uninative(d):
|
|
loader = d.getVar("UNINATIVE_LOADER")
|
|
if os.path.exists(loader):
|
|
bb.debug(2, "Enabling uninative")
|
|
d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d))
|
|
d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp")
|
|
d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp")
|
|
d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined")
|
|
d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined")
|
|
d.prependVar("PATH", "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:")
|
|
|
|
python uninative_changeinterp () {
|
|
import subprocess
|
|
import stat
|
|
import oe.qa
|
|
|
|
if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)):
|
|
return
|
|
|
|
sstateinst = d.getVar('SSTATE_INSTDIR')
|
|
for walkroot, dirs, files in os.walk(sstateinst):
|
|
for file in files:
|
|
if file.endswith(".so") or ".so." in file:
|
|
continue
|
|
f = os.path.join(walkroot, file)
|
|
if os.path.islink(f):
|
|
continue
|
|
s = os.stat(f)
|
|
if not ((s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH)):
|
|
continue
|
|
elf = oe.qa.ELFFile(f)
|
|
try:
|
|
elf.open()
|
|
except oe.qa.NotELFFileError:
|
|
continue
|
|
if not elf.isDynamic():
|
|
continue
|
|
|
|
subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)
|
|
}
|