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