blob: 24713b61f84723e61250e496200c9caa34e68866 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SECTION = "devel"
2# Need binutils for libiberty.a
3# Would need transfig-native for documentation if it wasn't disabled
4DEPENDS = "elfutils binutils"
5SUMMARY = "An ELF prelinking utility"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006HOMEPAGE = "http://git.yoctoproject.org/cgit.cgi/prelink-cross/about/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007DESCRIPTION = "The prelink package contains a utility which modifies ELF shared libraries \
8and executables, so that far fewer relocations need to be resolved at \
9runtime and thus programs come up faster."
10LICENSE = "GPLv2"
11LIC_FILES_CHKSUM = "file://COPYING;md5=c93c0550bd3173f4504b2cbd8991e50b"
Andrew Geissler82c905d2020-04-13 13:39:40 -050012SRCREV = "f9975537dbfd9ade0fc813bd5cf5fcbe41753a37"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013PV = "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#
Patrick Williams213cb262021-08-07 19:21:33 -050022SUMMARY:${PN}-cron = "Cron scripts to control automatic prelinking"
23DESCRIPTION:${PN}-cron = "Cron scripts to control automatic prelinking. \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024See: ${sysconfdir}/cron.daily/prelink for configuration information."
25
Patrick Williams213cb262021-08-07 19:21:33 -050026FILES:${PN}-cron = "${sysconfdir}/cron.daily ${sysconfdir}/default"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027
28PACKAGES =+ "${PN}-cron"
29
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030SRC_URI = "git://git.yoctoproject.org/prelink-cross.git;branch=cross_prelink_staging \
Andrew Geissler82c905d2020-04-13 13:39:40 -050031 file://0001-Add-MIPS-gnu-hash-support.patch \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032 file://prelink.conf \
33 file://prelink.cron.daily \
34 file://prelink.default \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080035 file://macros.prelink \
Andrew Geissler82c905d2020-04-13 13:39:40 -050036 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040037UPSTREAM_CHECK_COMMITS = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038
Brad Bishop79641f22019-09-10 07:20:22 -040039# error: error.h: No such file or directory
Patrick Williams213cb262021-08-07 19:21:33 -050040COMPATIBLE_HOST:libc-musl = 'null'
Brad Bishop79641f22019-09-10 07:20:22 -040041
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042TARGET_OS_ORIG := "${TARGET_OS}"
Patrick Williams213cb262021-08-07 19:21:33 -050043OVERRIDES:append = ":${TARGET_OS_ORIG}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044
Patrick Williamsf1e5d692016-03-30 15:21:19 -050045S = "${WORKDIR}/git"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47inherit autotools
48
49BBCLASSEXTEND = "native"
50
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050051EXTRA_OECONF = "--with-pkgversion=${PV}-${PR} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 --with-bugurl=http://bugzilla.yoctoproject.org/"
53
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050054PACKAGECONFIG ??= ""
55PACKAGECONFIG[selinux] = "--enable-selinux,--disable-selinux,libselinux"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060056
57#
58# For target prelink we need to ensure paths match the lib path layout
59# including for any configured multilibs
60#
61python do_linkerpaths () {
62 values = all_multilib_tune_list(["TUNE_ARCH", "baselib", "ABIEXTENSION"], d)
63
64 arches = values["TUNE_ARCH"]
65 baselibs = values["baselib"]
66 abis = values["ABIEXTENSION"]
67
68 def replace_lines(f, search, replacement, d, firstonly = False, secondonly = False):
69 f = d.expand(f)
70 if search == replacement:
71 return
72 bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f))
73 with open(f, "r") as data:
74 lines = data.readlines()
75 with open(f, "w") as data:
76 for line in lines:
77 if not secondonly and not firstonly:
78 line = line.replace(search, replacement)
79 elif secondonly and search in line:
80 secondonly = False
81 elif firstonly and search and search in line:
82 line = line.replace(search, replacement)
83 search = None
84 data.write(line)
85
86 def replace_lines_rtld(f, search, replacement, section, d):
87 f = d.expand(f)
88 bb.debug(2, "Replacing %s with %s in %s" % (search, replacement, f))
89 with open(f, "r") as data:
90 lines = data.readlines()
91 found = False
92 found2 = False
93 with open(f, "w") as data:
94 for line in lines:
95 if section in line:
96 if section == "else" and "if" in line:
97 found = False
98 else:
99 found = True
100 if found and "dst_LIB =" in line:
101 found2 = True
102 elif "}" in line:
103 found = False
104 found2 = False
105 if found2:
106 line = line.replace(search, replacement)
107 data.write(line)
108
109 for i, arch in enumerate(arches):
110 tune_baselib = baselibs[i]
111 abi = abis[i]
112
113 bits = 32
114 if arch == "powerpc":
115 replace_lines("${S}/src/arch-ppc.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
116 elif arch == "powerpc64":
117 replace_lines("${S}/src/arch-ppc64.c", "/lib64/ld64.so.1", "/" + tune_baselib + "/ld64.so.1", d)
118 bits = 64
119 elif arch == "x86_64":
120 if abi == "x32":
121 replace_lines("${S}/src/arch-x86_64.c", "/libx32/ld-linux-x32.so.2", "/" + tune_baselib + "/ld-linux-x32.so.2", d)
122 else:
123 replace_lines("${S}/src/arch-x86_64.c", "/lib64/ld-linux-x86-64.so.2", "/" + tune_baselib + "/ld-linux-x86-64.so.2", d)
124 bits = 64
125 elif arch == "arm":
126 replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux.so.3", "/" + tune_baselib + "/ld-linux.so.3", d)
127 replace_lines("${S}/src/arch-arm.c", "/lib/ld-linux-armhf.so.3", "/" + tune_baselib + "/ld-linux-armhf.so.3", d)
128 elif arch == "mips" or arch == "mipsel":
129 replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, firstonly=True)
130 replace_lines("${S}/src/arch-mips.c", "/lib32/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
131 elif arch == "mips64" or arch == "mips64el":
132 replace_lines("${S}/src/arch-mips.c", "/lib/ld.so.1", "/" + tune_baselib + "/ld.so.1", d, secondonly=True)
133 replace_lines("${S}/src/arch-mips.c", "/lib64/ld.so.1", "/" + tune_baselib + "/ld.so.1", d)
134 bits = 64
135 elif arch.endswith("86"):
136 replace_lines("${S}/src/arch-i386.c", "/lib/ld-linux.so.2", "/" + tune_baselib + "/ld-linux.so.2", d)
137 if bits == 32 and tune_baselib != "lib":
138 replace_lines_rtld("${S}/src/rtld/rtld.c", "lib", tune_baselib, "else", d)
139 if bits == 64 and tune_baselib != "lib64":
140 replace_lines_rtld("${S}/src/rtld/rtld.c", "lib64", tune_baselib, "use_64bit", d)
141}
142
143python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 overrides = d.getVar("OVERRIDES").split(":")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600145 if "class-target" in overrides:
146 bb.build.addtask('do_linkerpaths', 'do_configure', 'do_patch', d)
147}
148
Patrick Williams213cb262021-08-07 19:21:33 -0500149do_configure:prepend () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 # Disable documentation!
151 echo "all:" > ${S}/doc/Makefile.am
152}
153
Patrick Williams213cb262021-08-07 19:21:33 -0500154do_install:append () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 install -d ${D}${sysconfdir}/cron.daily ${D}${sysconfdir}/default ${D}${sysconfdir}/rpm
156 install -m 0644 ${WORKDIR}/prelink.conf ${D}${sysconfdir}/prelink.conf
157 install -m 0644 ${WORKDIR}/prelink.cron.daily ${D}${sysconfdir}/cron.daily/prelink
158 install -m 0644 ${WORKDIR}/prelink.default ${D}${sysconfdir}/default/prelink
159 install -m 0644 ${WORKDIR}/macros.prelink ${D}${sysconfdir}/rpm/macros.prelink
160}
161
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500162# If we ae doing a cross install, we want to avoid prelinking.
163# Prelinking during a cross install should be handled by the image-prelink
164# bbclass. If the user desires this to run on the target at first boot
165# they will need to create a custom boot script.
Patrick Williams213cb262021-08-07 19:21:33 -0500166pkg_postinst:prelink() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167#!/bin/sh
168
169if [ "x$D" != "x" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500170 exit 0
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171fi
172
173prelink -a
174}
175
Patrick Williams213cb262021-08-07 19:21:33 -0500176pkg_prerm:prelink() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177#!/bin/sh
178
179if [ "x$D" != "x" ]; then
180 exit 1
181fi
182
183prelink -au
184}
185