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" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 12 | SRCREV = "f9975537dbfd9ade0fc813bd5cf5fcbe41753a37" |
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 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | SRC_URI = "git://git.yoctoproject.org/prelink-cross.git;branch=cross_prelink_staging \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 31 | file://0001-Add-MIPS-gnu-hash-support.patch \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | file://prelink.conf \ |
| 33 | file://prelink.cron.daily \ |
| 34 | file://prelink.default \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 35 | file://macros.prelink \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 36 | " |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 37 | UPSTREAM_CHECK_COMMITS = "1" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 39 | # error: error.h: No such file or directory |
| 40 | COMPATIBLE_HOST_libc-musl = 'null' |
| 41 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | TARGET_OS_ORIG := "${TARGET_OS}" |
| 43 | OVERRIDES_append = ":${TARGET_OS_ORIG}" |
| 44 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 45 | S = "${WORKDIR}/git" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
| 47 | inherit autotools |
| 48 | |
| 49 | BBCLASSEXTEND = "native" |
| 50 | |
| 51 | EXTRA_OECONF = "--disable-selinux --with-pkgversion=${PV}-${PR} \ |
| 52 | --with-bugurl=http://bugzilla.yoctoproject.org/" |
| 53 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | |
| 55 | # |
| 56 | # For target prelink we need to ensure paths match the lib path layout |
| 57 | # including for any configured multilibs |
| 58 | # |
| 59 | python do_linkerpaths () { |
| 60 | values = all_multilib_tune_list(["TUNE_ARCH", "baselib", "ABIEXTENSION"], d) |
| 61 | |
| 62 | arches = values["TUNE_ARCH"] |
| 63 | baselibs = values["baselib"] |
| 64 | abis = values["ABIEXTENSION"] |
| 65 | |
| 66 | def replace_lines(f, search, replacement, d, firstonly = False, secondonly = False): |
| 67 | f = d.expand(f) |
| 68 | if search == replacement: |
| 69 | return |
| 70 | bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f)) |
| 71 | with open(f, "r") as data: |
| 72 | lines = data.readlines() |
| 73 | with open(f, "w") as data: |
| 74 | for line in lines: |
| 75 | if not secondonly and not firstonly: |
| 76 | line = line.replace(search, replacement) |
| 77 | elif secondonly and search in line: |
| 78 | secondonly = False |
| 79 | elif firstonly and search and search in line: |
| 80 | line = line.replace(search, replacement) |
| 81 | search = None |
| 82 | data.write(line) |
| 83 | |
| 84 | def replace_lines_rtld(f, search, replacement, section, d): |
| 85 | f = d.expand(f) |
| 86 | bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f)) |
| 87 | with open(f, "r") as data: |
| 88 | lines = data.readlines() |
| 89 | found = False |
| 90 | found2 = False |
| 91 | with open(f, "w") as data: |
| 92 | for line in lines: |
| 93 | if section in line: |
| 94 | if section == "else" and "if" in line: |
| 95 | found = False |
| 96 | else: |
| 97 | found = True |
| 98 | if found and "dst_LIB =" in line: |
| 99 | found2 = True |
| 100 | elif "}" in line: |
| 101 | found = False |
| 102 | found2 = False |
| 103 | if found2: |
| 104 | line = line.replace(search, replacement) |
| 105 | data.write(line) |
| 106 | |
| 107 | for i, arch in enumerate(arches): |
| 108 | tune_baselib = baselibs[i] |
| 109 | abi = abis[i] |
| 110 | |
| 111 | bits = 32 |
| 112 | if arch == "powerpc": |
| 113 | replace_lines("${S}/src/arch-ppc.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 114 | elif arch == "powerpc64": |
| 115 | replace_lines("${S}/src/arch-ppc64.c", "/lib64/ld64.so.1", "/" + tune_baselib + "/ld64.so.1", d) |
| 116 | bits = 64 |
| 117 | elif arch == "x86_64": |
| 118 | if abi == "x32": |
| 119 | replace_lines("${S}/src/arch-x86_64.c", "/libx32/ld-linux-x32.so.2", "/" + tune_baselib + "/ld-linux-x32.so.2", d) |
| 120 | else: |
| 121 | replace_lines("${S}/src/arch-x86_64.c", "/lib64/ld-linux-x86-64.so.2", "/" + tune_baselib + "/ld-linux-x86-64.so.2", d) |
| 122 | bits = 64 |
| 123 | elif arch == "arm": |
| 124 | replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux.so.3", "/" + tune_baselib + "/ld-linux.so.3", d) |
| 125 | replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux-armhf.so.3", "/" + tune_baselib + "/ld-linux-armhf.so.3", d) |
| 126 | elif arch == "mips" or arch == "mipsel": |
| 127 | replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, firstonly=True) |
| 128 | replace_lines("${S}/src/arch-mips.c", "/lib32/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 129 | elif arch == "mips64" or arch == "mips64el": |
| 130 | replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, secondonly=True) |
| 131 | replace_lines("${S}/src/arch-mips.c", "/lib64/ld.so.1", "/" + tune_baselib + "/ld.so.1", d) |
| 132 | bits = 64 |
| 133 | elif arch.endswith("86"): |
| 134 | replace_lines("${S}/src/arch-i386.c", "/lib/ld-linux.so.2", "/" + tune_baselib + "/ld-linux.so.2", d) |
| 135 | if bits == 32 and tune_baselib != "lib": |
| 136 | replace_lines_rtld("${S}/src/rtld/rtld.c", "lib", tune_baselib, "else", d) |
| 137 | if bits == 64 and tune_baselib != "lib64": |
| 138 | replace_lines_rtld("${S}/src/rtld/rtld.c", "lib64", tune_baselib, "use_64bit", d) |
| 139 | } |
| 140 | |
| 141 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | overrides = d.getVar("OVERRIDES").split(":") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 143 | if "class-target" in overrides: |
| 144 | bb.build.addtask('do_linkerpaths', 'do_configure', 'do_patch', d) |
| 145 | } |
| 146 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | do_configure_prepend () { |
| 148 | # Disable documentation! |
| 149 | echo "all:" > ${S}/doc/Makefile.am |
| 150 | } |
| 151 | |
| 152 | do_install_append () { |
| 153 | install -d ${D}${sysconfdir}/cron.daily ${D}${sysconfdir}/default ${D}${sysconfdir}/rpm |
| 154 | install -m 0644 ${WORKDIR}/prelink.conf ${D}${sysconfdir}/prelink.conf |
| 155 | install -m 0644 ${WORKDIR}/prelink.cron.daily ${D}${sysconfdir}/cron.daily/prelink |
| 156 | install -m 0644 ${WORKDIR}/prelink.default ${D}${sysconfdir}/default/prelink |
| 157 | install -m 0644 ${WORKDIR}/macros.prelink ${D}${sysconfdir}/rpm/macros.prelink |
| 158 | } |
| 159 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 160 | # If we ae doing a cross install, we want to avoid prelinking. |
| 161 | # Prelinking during a cross install should be handled by the image-prelink |
| 162 | # bbclass. If the user desires this to run on the target at first boot |
| 163 | # they will need to create a custom boot script. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | pkg_postinst_prelink() { |
| 165 | #!/bin/sh |
| 166 | |
| 167 | if [ "x$D" != "x" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 168 | exit 0 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | fi |
| 170 | |
| 171 | prelink -a |
| 172 | } |
| 173 | |
| 174 | pkg_prerm_prelink() { |
| 175 | #!/bin/sh |
| 176 | |
| 177 | if [ "x$D" != "x" ]; then |
| 178 | exit 1 |
| 179 | fi |
| 180 | |
| 181 | prelink -au |
| 182 | } |
| 183 | |