generic-poky/meta/classes/image-mklibs.bbclass
Tyler Hall b578a06564 image-mklibs: handle position independent binaries
Executables built with -fpie have the ELF type DYN rather than EXEC
which makes them difficult to distinguish from shared libraries.
Currently when building the list of executables we omit these binaries
so they might fail to run on the resultant rootfs due to missing
symbols. One of these is systemd which builds -fpie unconditionally, so
mklibs breaks images containing systemd.

Modify the search to catch all executable files that are ELF and have an
interpreter set. Omit libc and libpthread as special cases because they
have an interpreter and are directly executable but treating them as
such is antithetical to the pupose of mklibs.

(From OE-Core rev: 30da34ef032d5b4b2f694743715f2c8d64dd9849)

Signed-off-by: Tyler Hall <tylerwhall@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-03-10 23:13:54 +00:00

57 lines
1.5 KiB
Text

do_rootfs[depends] += "mklibs-native:do_populate_sysroot"
IMAGE_PREPROCESS_COMMAND += "mklibs_optimize_image; "
inherit linuxloader
mklibs_optimize_image_doit() {
rm -rf ${WORKDIR}/mklibs
mkdir -p ${WORKDIR}/mklibs/dest
cd ${IMAGE_ROOTFS}
du -bs > ${WORKDIR}/mklibs/du.before.mklibs.txt
# Build a list of dynamically linked executable ELF files.
# Omit libc/libpthread as a special case because it has an interpreter
# but is primarily what we intend to strip down.
for i in `find . -type f -executable ! -name 'libc-*' ! -name 'libpthread-*'`; do
file $i | grep -q ELF || continue
${HOST_PREFIX}readelf -l $i | grep -q INTERP || continue
echo $i
done > ${WORKDIR}/mklibs/executables.list
dynamic_loader=$(linuxloader)
mklibs -v \
--ldlib ${dynamic_loader} \
--libdir ${baselib} \
--sysroot ${PKG_CONFIG_SYSROOT_DIR} \
--gcc-options "--sysroot=${PKG_CONFIG_SYSROOT_DIR}" \
--root ${IMAGE_ROOTFS} \
--target `echo ${TARGET_PREFIX} | sed 's/-$//' ` \
-d ${WORKDIR}/mklibs/dest \
`cat ${WORKDIR}/mklibs/executables.list`
cd ${WORKDIR}/mklibs/dest
for i in *
do
cp $i `find ${IMAGE_ROOTFS} -name $i`
done
cd ${IMAGE_ROOTFS}
du -bs > ${WORKDIR}/mklibs/du.after.mklibs.txt
echo rootfs size before mklibs optimization: `cat ${WORKDIR}/mklibs/du.before.mklibs.txt`
echo rootfs size after mklibs optimization: `cat ${WORKDIR}/mklibs/du.after.mklibs.txt`
}
mklibs_optimize_image() {
for img in ${MKLIBS_OPTIMIZED_IMAGES}
do
if [ "${img}" = "${PN}" ] || [ "${img}" = "all" ]
then
mklibs_optimize_image_doit
break
fi
done
}