From fbb8d64fa77741bae3a6b85570b301e695872c2e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Fri, 15 Feb 2019 22:11:28 +0000 Subject: [PATCH] Add update-alternative for ld rhbz#1739973 --- lld.spec | 16 +++++++++++++++- tests/ld-alternative/runtest.sh | 32 ++++++++++++++++++++++++++++++++ tests/tests-ld-alternative.yml | 14 ++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 tests/ld-alternative/runtest.sh create mode 100644 tests/tests-ld-alternative.yml diff --git a/lld.spec b/lld.spec index aa7e766..3aabebc 100644 --- a/lld.spec +++ b/lld.spec @@ -3,7 +3,7 @@ Name: lld Version: 8.0.0 -Release: 1%{?rc_ver:.rc%{rc_ver}}%{?dist}.1 +Release: 2%{?rc_ver:.rc%{rc_ver}}%{?dist} Summary: The LLVM Linker License: NCSA @@ -27,6 +27,9 @@ BuildRequires: python3-rpm-macros BuildRequires: python3-lit BuildRequires: llvm-googletest = %{version} +Requires(post): %{_sbindir}/alternatives +Requires(preun): %{_sbindir}/alternatives + %description The LLVM project linker. @@ -76,6 +79,13 @@ cd %{_target_platform} chrpath --delete %{buildroot}%{_bindir}/* chrpath --delete %{buildroot}%{_libdir}/*.so* +%post +%{_sbindir}/update-alternatives --install %{_bindir}/ld ld %{_bindir}/ld.lld 1 + +%postun +if [ $1 -eq 0 ] ; then + %{_sbindir}/update-alternatives --remove ld %{_bindir}/ld.lld +fi %check @@ -87,6 +97,7 @@ make -C %{_target_platform} %{?_smp_mflags} check-lld %ldconfig_scriptlets libs %files +%ghost %{_bindir}/ld %{_bindir}/lld* %{_bindir}/ld.lld %{_bindir}/ld64.lld @@ -100,6 +111,9 @@ make -C %{_target_platform} %{?_smp_mflags} check-lld %{_libdir}/liblld*.so.* %changelog +* Tue Aug 13 2019 Tom Stellard - 8.0.0-2 +- Add update-alternative for ld + * Thu Jul 25 2019 Fedora Release Engineering - 8.0.0-1.1 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild diff --git a/tests/ld-alternative/runtest.sh b/tests/ld-alternative/runtest.sh new file mode 100755 index 0000000..0cc6a2f --- /dev/null +++ b/tests/ld-alternative/runtest.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# This test assumes lld is already installed. + +set -ex + +function verify_ld_bfd { + + # Verify that /usr/bin/ld points to ld.bfd. + ls -l /etc/alternatives/ld | grep ld.bfd + + # Run ld and verify it invokes ld.bfd + /usr/bin/ld --version | grep 'GNU ld' +} + + +# Verify ld.bfd is still the system linker when lld is installed +verify_ld_bfd + +# Set lld as the system linker +update-alternatives --set ld /usr/bin/ld.lld + +# Verify that /usr/bin/ld points to lld +ls -l /etc/alternatives/ld | grep ld.lld + +# Run ld and verify it invokes lld +/usr/bin/ld --version | grep 'LLD' + +# Uninstall lld and make sure the /usr/bin/ld is reset to ld.bfd +dnf -y remove lld + +verify_ld_bfd diff --git a/tests/tests-ld-alternative.yml b/tests/tests-ld-alternative.yml new file mode 100644 index 0000000..e1fe1a3 --- /dev/null +++ b/tests/tests-ld-alternative.yml @@ -0,0 +1,14 @@ +# The ld-alternative test uninstalls lld, so it needs to be run by +# itself in a separate .yml file so it doesn't modify the test +# environment for other tests. + +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + required_packages: + - binutils + - lld + tests: + - ld-alternative