Skip to content

Commit 383f784

Browse files
Wrap the ld.lld binary with hab-ld-wrapper
For the `build-script-build` binaries to be able to run during the compilation process, we need to disable the `lld` as it misses creating required `DT_RPATH` entries. Thus we replace the *actual* `ld.lld` linker with `hab-ld-wrapper.sh` wrapped `ld.bfd` linker from `core/binutils`. Signed-off-by: Abhijit Gadgil <agadgil@progress.com>
1 parent 32ba5dc commit 383f784

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

linux/development/compilers/rust/glibc/x86_64-linux/.hab-plan-config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ host-elf-interpreter = {level = "off"}
1212
# 3. core/tzdata - Needed for the proper operation of the GNU C Library (glibc).
1313
# 4. core/iana-etc - Also required for the functioning of glibc.
1414
unused-dependency = {ignored_packages = [
15-
"core/{cacerts,binutils,tzdata,iana-etc}"
15+
"core/{cacerts,binutils,tzdata,iana-etc,hab-ld-wrapper}"
1616
]}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
HAB_DEBUG=${HAB_DEBUG:-${HAB_LD_DEBUG:-0}} \
3+
HAB_LD_RUN_PATH=${HAB_LD_RUN_PATH:-${LD_RUN_PATH:-""}} \
4+
@wrapper@ @program@ "$@"

linux/development/compilers/rust/glibc/x86_64-linux/plan.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pkg_deps=(
2121
core/iana-etc
2222
core/tzdata
2323
core/zlib
24+
core/hab-ld-wrapper
2425
)
2526
pkg_build_deps=(
2627
core/build-tools-patchelf
@@ -147,10 +148,50 @@ do_install() {
147148
# RUSTFLAGS to ensure the library's detection during the linking process.
148149
wrap_rustc_binary
149150

151+
# The whole `lld` default Saga -
152+
# TLDR; Since 1.90.0 `rust` enabled the `lld` by default that doesn't work with our
153+
# non-standard paths and custom runtime `linker`. We just continue to use the *old*
154+
# `ld.bfd` linker from `core/binutils`
155+
#
156+
# With the introduction of the `lld` linker, during the compilation of dependencies -
157+
# running the `build-script-build` binaries fail to run causing compilation failure.
158+
# This is because the binaries are dynamically linked even though we are trying to build
159+
# statically linked binaries for the *target* (`x86_64-unknown-linux-musl` in our case).
160+
#
161+
# We can disable the `lld` default linker using `RUSTFLAGS` - but they are not honoured when
162+
# `--target` is set as we do. In short we cannot disable the `lld` linker for the
163+
# `build-script-build` compilation. With `lld` linker the `rpath` entries are not added in
164+
# the generated binaries and hence they cannot be run.
165+
#
166+
# If we use our standard technique of wrapping with the wrapper calling original binary
167+
# named `ld.lld.real`, this fails because `rustc`s `ld-wrapper` script expects the *called*
168+
# binary name to be `ld.lld`. This leaves us with only choice of *wrapping* the *old*
169+
# `ld.bfd.real` binary from the `core/binutils` package.
170+
wrap_lld_linker "$pkg_prefix"/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/ld.lld \
171+
"$(pkg_path_for binutils)"/bin/ld.bfd.real
172+
150173
# Delete the uninstaller script as it is not required
151174
rm "${pkg_prefix}"/lib/rustlib/uninstall.sh
152175
}
153176

177+
wrap_lld_linker() {
178+
local wrapper_binary
179+
local actual_binary
180+
181+
actual_binary="$2"
182+
wrapper_binary="$1"
183+
184+
local hab_ld_wrapper
185+
hab_ld_wrapper="$(pkg_path_for hab-ld-wrapper)"
186+
187+
sed "$PLAN_CONTEXT/ld-wrapper.sh" \
188+
-e "s^@wrapper@^${hab_ld_wrapper}/bin/hab-ld-wrapper^g" \
189+
-e "s^@program@^${actual_binary}^g" \
190+
>"$wrapper_binary"
191+
192+
chmod 755 "$wrapper_binary"
193+
}
194+
154195
wrap_rustc_binary() {
155196
local binary
156197
local gcc_base

0 commit comments

Comments
 (0)