Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | SECTION = "devel" |
| 2 | # Need binutils for libiberty.a |
| 3 | # Would need transfig-native for documentation if it wasn't disabled |
| 4 | DEPENDS = "elfutils binutils" |
| 5 | SUMMARY = "An ELF prelinking utility" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6 | HOMEPAGE = "http://git.yoctoproject.org/cgit.cgi/prelink-cross/about/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | DESCRIPTION = "The prelink package contains a utility which modifies ELF shared libraries \ |
| 8 | and executables, so that far fewer relocations need to be resolved at \ |
| 9 | runtime and thus programs come up faster." |
| 10 | LICENSE = "GPLv2" |
| 11 | LIC_FILES_CHKSUM = "file://COPYING;md5=c93c0550bd3173f4504b2cbd8991e50b" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 12 | SRCREV = "05aeafd053e56356ec8c62f4bb8f7b95bae192f3" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | PV = "1.0+git${SRCPV}" |
| 14 | |
| 15 | # |
| 16 | # The cron script attempts to re-prelink the system daily -- on |
| 17 | # systems where users are adding applications, this might be reasonable |
| 18 | # but for embedded, we should be re-running prelink -a after an update. |
| 19 | # |
| 20 | # Default is prelinking is enabled. |
| 21 | # |
| 22 | SUMMARY_${PN}-cron = "Cron scripts to control automatic prelinking" |
| 23 | DESCRIPTION_${PN}-cron = "Cron scripts to control automatic prelinking. \ |
| 24 | See: ${sysconfdir}/cron.daily/prelink for configuration information." |
| 25 | |
| 26 | FILES_${PN}-cron = "${sysconfdir}/cron.daily ${sysconfdir}/default" |
| 27 | |
| 28 | PACKAGES =+ "${PN}-cron" |
| 29 | |
| 30 | SRC_URI = "git://git.yoctoproject.org/prelink-cross.git;branch=cross_prelink \ |
| 31 | file://prelink.conf \ |
| 32 | file://prelink.cron.daily \ |
| 33 | file://prelink.default \ |
| 34 | file://macros.prelink" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 35 | UPSTREAM_CHECK_COMMITS = "1" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | |
| 37 | TARGET_OS_ORIG := "${TARGET_OS}" |
| 38 | OVERRIDES_append = ":${TARGET_OS_ORIG}" |
| 39 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 40 | S = "${WORKDIR}/git" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | |
| 42 | inherit autotools |
| 43 | |
| 44 | BBCLASSEXTEND = "native" |
| 45 | |
| 46 | EXTRA_OECONF = "--disable-selinux --with-pkgversion=${PV}-${PR} \ |
| 47 | --with-bugurl=http://bugzilla.yoctoproject.org/" |
| 48 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 49 | |
| 50 | # |
| 51 | # For target prelink we need to ensure paths match the lib path layout |
| 52 | # including for any configured multilibs |
| 53 | # |
| 54 | python do_linkerpaths () { |
| 55 | values = all_multilib_tune_list(["TUNE_ARCH", "baselib", "ABIEXTENSION"], d) |
| 56 | |
| 57 | arches = values["TUNE_ARCH"] |
| 58 | baselibs = values["baselib"] |
| 59 | abis = values["ABIEXTENSION"] |
| 60 | |
| 61 | def replace_lines(f, search, replacement, d, firstonly = False, secondonly = False): |
| 62 | f = d.expand(f) |
| 63 | if search == replacement: |
| 64 | return |
| 65 | bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f)) |
| 66 | with open(f, "r") as data: |
| 67 | lines = data.readlines() |
| 68 | with open(f, "w") as data: |
| 69 | for line in lines: |
| 70 | if not secondonly and not firstonly: |
| 71 | line = line.replace(search, replacement) |
| 72 | elif secondonly and search in line: |
| 73 | secondonly = False |
| 74 | elif firstonly and search and search in line: |
| 75 | line = line.replace(search, replacement) |
| 76 | search = None |
| 77 | data.write(line) |
| 78 | |
| 79 | def replace_lines_rtld(f, search, replacement, section, d): |
| 80 | f = d.expand(f) |
| 81 | bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f)) |
| 82 | with open(f, "r") as data: |
| 83 | lines = data.readlines() |
| 84 | found = False |
| 85 | found2 = False |
| 86 | with open(f, "w") as data: |
| 87 | for line in lines: |
| 88 | if section in line: |
| 89 | if section == "else" and "if" in line: |
| 90 | found = False |
| 91 | else: |
| 92 | found = True |
| 93 | if found and "dst_LIB =" in line: |
| 94 | found2 = True |
| 95 | elif "}" in line: |
| 96 | found = False |
| 97 | found2 = False |
| 98 | if found2: |
| 99 | line = line.replace(search, replacement) |
| 100 | data.write(line) |
| 101 | |
| 102 | for i, arch in enumerate(arches): |
| 103 | tune_baselib = baselibs[i] |
| 104 | abi = abis[i] |
| 105 | |
| 106 | bits = 32 |
| 107 | if arch == "powerpc": |
| 108 | replace_lines("${S}/src/arch-ppc.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 109 | elif arch == "powerpc64": |
| 110 | replace_lines("${S}/src/arch-ppc64.c", "/lib64/ld64.so.1", "/" + tune_baselib + "/ld64.so.1", d) |
| 111 | bits = 64 |
| 112 | elif arch == "x86_64": |
| 113 | if abi == "x32": |
| 114 | replace_lines("${S}/src/arch-x86_64.c", "/libx32/ld-linux-x32.so.2", "/" + tune_baselib + "/ld-linux-x32.so.2", d) |
| 115 | else: |
| 116 | replace_lines("${S}/src/arch-x86_64.c", "/lib64/ld-linux-x86-64.so.2", "/" + tune_baselib + "/ld-linux-x86-64.so.2", d) |
| 117 | bits = 64 |
| 118 | elif arch == "arm": |
| 119 | replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux.so.3", "/" + tune_baselib + "/ld-linux.so.3", d) |
| 120 | replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux-armhf.so.3", "/" + tune_baselib + "/ld-linux-armhf.so.3", d) |
| 121 | elif arch == "mips" or arch == "mipsel": |
| 122 | replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, firstonly=True) |
| 123 | replace_lines("${S}/src/arch-mips.c", "/lib32/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 124 | elif arch == "mips64" or arch == "mips64el": |
| 125 | replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, secondonly=True) |
| 126 | replace_lines("${S}/src/arch-mips.c", "/lib64/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 127 | bits = 64 |
| 128 | elif arch.endswith("86"): |
| 129 | replace_lines("${S}/src/arch-i386.c", "/lib/ld-linux.so.2", "/" + tune_baselib + "/ld-linux.so.2", d) |
| 130 | if bits == 32 and tune_baselib != "lib": |
| 131 | replace_lines_rtld("${S}/src/rtld/rtld.c", "lib", tune_baselib, "else", d) |
| 132 | if bits == 64 and tune_baselib != "lib64": |
| 133 | replace_lines_rtld("${S}/src/rtld/rtld.c", "lib64", tune_baselib, "use_64bit", d) |
| 134 | } |
| 135 | |
| 136 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | overrides = d.getVar("OVERRIDES").split(":") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | if "class-target" in overrides: |
| 139 | bb.build.addtask('do_linkerpaths', 'do_configure', 'do_patch', d) |
| 140 | } |
| 141 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 142 | do_configure_prepend () { |
| 143 | # Disable documentation! |
| 144 | echo "all:" > ${S}/doc/Makefile.am |
| 145 | } |
| 146 | |
| 147 | do_install_append () { |
| 148 | install -d ${D}${sysconfdir}/cron.daily ${D}${sysconfdir}/default ${D}${sysconfdir}/rpm |
| 149 | install -m 0644 ${WORKDIR}/prelink.conf ${D}${sysconfdir}/prelink.conf |
| 150 | install -m 0644 ${WORKDIR}/prelink.cron.daily ${D}${sysconfdir}/cron.daily/prelink |
| 151 | install -m 0644 ${WORKDIR}/prelink.default ${D}${sysconfdir}/default/prelink |
| 152 | install -m 0644 ${WORKDIR}/macros.prelink ${D}${sysconfdir}/rpm/macros.prelink |
| 153 | } |
| 154 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 155 | # If we ae doing a cross install, we want to avoid prelinking. |
| 156 | # Prelinking during a cross install should be handled by the image-prelink |
| 157 | # bbclass. If the user desires this to run on the target at first boot |
| 158 | # they will need to create a custom boot script. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | pkg_postinst_prelink() { |
| 160 | #!/bin/sh |
| 161 | |
| 162 | if [ "x$D" != "x" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 163 | exit 0 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | fi |
| 165 | |
| 166 | prelink -a |
| 167 | } |
| 168 | |
| 169 | pkg_prerm_prelink() { |
| 170 | #!/bin/sh |
| 171 | |
| 172 | if [ "x$D" != "x" ]; then |
| 173 | exit 1 |
| 174 | fi |
| 175 | |
| 176 | prelink -au |
| 177 | } |
| 178 | |