Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | do_rootfs[depends] += "prelink-native:do_populate_sysroot" |
| 2 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 3 | IMAGE_PREPROCESS_COMMAND_append_libc-glibc = " prelink_setup; prelink_image; " |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4 | |
| 5 | python prelink_setup () { |
| 6 | oe.utils.write_ld_so_conf(d) |
| 7 | } |
| 8 | |
| 9 | inherit linuxloader |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
| 11 | prelink_image () { |
| 12 | # export PSEUDO_DEBUG=4 |
| 13 | # /bin/env | /bin/grep PSEUDO |
| 14 | # echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" |
| 15 | # echo "LD_PRELOAD=$LD_PRELOAD" |
| 16 | |
| 17 | pre_prelink_size=`du -ks ${IMAGE_ROOTFS} | awk '{size = $1 ; print size }'` |
| 18 | echo "Size before prelinking $pre_prelink_size." |
| 19 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 20 | # The filesystem may not contain sysconfdir so establish what is present |
| 21 | # to enable cleanup after temporary creation of sysconfdir if needed |
| 22 | presentdir="${IMAGE_ROOTFS}${sysconfdir}" |
| 23 | while [ "${IMAGE_ROOTFS}" != "${presentdir}" ] ; do |
| 24 | [ ! -d "${presentdir}" ] || break |
| 25 | presentdir=`dirname "${presentdir}"` |
| 26 | done |
| 27 | |
| 28 | mkdir -p "${IMAGE_ROOTFS}${sysconfdir}" |
| 29 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | # We need a prelink conf on the filesystem, add one if it's missing |
| 31 | if [ ! -e ${IMAGE_ROOTFS}${sysconfdir}/prelink.conf ]; then |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 32 | cp ${STAGING_ETCDIR_NATIVE}/prelink.conf \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | ${IMAGE_ROOTFS}${sysconfdir}/prelink.conf |
| 34 | dummy_prelink_conf=true; |
| 35 | else |
| 36 | dummy_prelink_conf=false; |
| 37 | fi |
| 38 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 39 | # We need a ld.so.conf with pathnames in,prelink conf on the filesystem, add one if it's missing |
| 40 | ldsoconf=${IMAGE_ROOTFS}${sysconfdir}/ld.so.conf |
| 41 | if [ -e $ldsoconf ]; then |
| 42 | cp $ldsoconf $ldsoconf.prelink |
| 43 | fi |
| 44 | cat ${STAGING_DIR_TARGET}${sysconfdir}/ld.so.conf >> $ldsoconf |
| 45 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 46 | dynamic_loader=${@get_linuxloader(d)} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 47 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | # prelink! |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 49 | if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 50 | bbnote " prelink: BUILD_REPRODUCIBLE_BINARIES..." |
| 51 | if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then |
| 52 | export PRELINK_TIMESTAMP=`git log -1 --pretty=%ct ` |
| 53 | else |
| 54 | export PRELINK_TIMESTAMP=$REPRODUCIBLE_TIMESTAMP_ROOTFS |
| 55 | fi |
| 56 | ${STAGING_SBINDIR_NATIVE}/prelink --root ${IMAGE_ROOTFS} -am -N -c ${sysconfdir}/prelink.conf --dynamic-linker $dynamic_loader |
| 57 | else |
| 58 | ${STAGING_SBINDIR_NATIVE}/prelink --root ${IMAGE_ROOTFS} -amR -N -c ${sysconfdir}/prelink.conf --dynamic-linker $dynamic_loader |
| 59 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | |
| 61 | # Remove the prelink.conf if we had to add it. |
| 62 | if [ "$dummy_prelink_conf" = "true" ]; then |
| 63 | rm -f ${IMAGE_ROOTFS}${sysconfdir}/prelink.conf |
| 64 | fi |
| 65 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 66 | if [ -e $ldsoconf.prelink ]; then |
| 67 | mv $ldsoconf.prelink $ldsoconf |
| 68 | else |
| 69 | rm $ldsoconf |
| 70 | fi |
| 71 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 72 | # Remove any directories temporarily created for sysconfdir |
| 73 | cleanupdir="${IMAGE_ROOTFS}${sysconfdir}" |
| 74 | while [ "${presentdir}" != "${cleanupdir}" ] ; do |
| 75 | rmdir "${cleanupdir}" |
| 76 | cleanupdir=`dirname ${cleanupdir}` |
| 77 | done |
| 78 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | pre_prelink_size=`du -ks ${IMAGE_ROOTFS} | awk '{size = $1 ; print size }'` |
| 80 | echo "Size after prelinking $pre_prelink_size." |
| 81 | } |