Skip to contentSkip to conversation

Use cross-ldd for dracut instead of prelink-cross

PATCH Applied Thomas Petazzoni via buildroot 2 participants 6 messages Jan 8, 2025 – Jan 14, 2025

lore
Share & tools
lore
#0 lore raw

cover Use cross-ldd for dracut instead of prelink-cross

Hello,

dracut is the last user of host-prelink-cross, and host-prelink-cross is problematic because:

1. It is no longer maintained

2. It requires host-libiberty, which itself causes build failures due to conflict with host-binutils

3. It is very complicated for what dracut actually needs.

So, we replace host-prelink-cross by host-cross-ldd which packages the much simpler "xldd" script from Crosstool-NG, which is in fact even recommended/pointed by the Dracut documentation as the solution to use for cross-compilation scenarios.

Thomas

Thomas Petazzoni (4):
package/cross-ldd: new package
package/dracut: use host-cross-ldd instead of host-prelink-cross package/prelink-cross: remove package package/libiberty: remove package

 .checkpackageignore                           |  1 -
 DEVELOPERS                                    |  1 +
 package/cross-ldd/cross-ldd.hash              |  4 ++
 package/cross-ldd/cross-ldd.mk                | 37 ++++++++++++++++
 package/dracut/dracut.mk                      |  8 ++--
 .../{dracut_wrapper => dracut_wrapper.in}     |  2 +-
 package/gdb/gdb.mk                            |  4 +-
 package/libiberty/libiberty.hash              |  1 -
 package/libiberty/libiberty.mk                | 32 --------------
 ...c-Fix-TLS-offsets-computation-for-s3.patch | 43 ------------------
 ...rc-execstack.c-fix-prelink_path-type.patch | 44 -------------------
 package/prelink-cross/prelink-cross.hash      |  3 --
 package/prelink-cross/prelink-cross.mk        | 16 -------
 13 files changed, 49 insertions(+), 147 deletions(-)
 create mode 100644 package/cross-ldd/cross-ldd.hash
 create mode 100644 package/cross-ldd/cross-ldd.mk
 rename package/dracut/{dracut_wrapper => dracut_wrapper.in} (94%)
 delete mode 120000 package/libiberty/libiberty.hash
 delete mode 100644 package/libiberty/libiberty.mk
 delete mode 100644 package/prelink-cross/0001-src-rtld-dl-tls.c-Fix-TLS-offsets-computation-for-s3.patch
 delete mode 100644 package/prelink-cross/0002-src-execstack.c-fix-prelink_path-type.patch
 delete mode 100644 package/prelink-cross/prelink-cross.hash
 delete mode 100644 package/prelink-cross/prelink-cross.mk
Signature · 6 lines
2.47.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/4 package/cross-ldd: new package

This commit introduces a new cross-ldd package which installs the cross ldd implementation that comes from Crosstool-NG, and which can be used like ldd, but when cross-compiling. We intend to use it as a replacement of host-prelink-cross for our dracut package.

The cross-ldd from Crosstool-NG is in fact even recommended by the Dracut documentation, in its docs/README.cross document:

To support cross-compiled binaries, a different ldd variant is needed that works on those binaries. One such ldd script is found at
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f

This Github Gist in fact contains the xldd.in code from Crosstool-NG.

Our package downloads the full tarball of Crosstool-NG. We tried to download only the script and the license file, but we couldn't figure out a way of downloading them *and* have the version in the filename to make sure that when doing an upgrade to a newer version, we wouldn't have a clash between old/new files having the same name (and causing conflicts with the hash verification). So in the end, we opted for download the whole tarball.

---
 DEVELOPERS                       |  1 +
 package/cross-ldd/cross-ldd.hash |  4 ++++
 package/cross-ldd/cross-ldd.mk   | 37 ++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 package/cross-ldd/cross-ldd.hash
 create mode 100644 package/cross-ldd/cross-ldd.mk
DEVELOPERS +1 -0
index 16b72eee08..1174100014 100644
@@ -3145,6 +3145,7 @@ F:	package/cifs-utils/
 F:	package/cloop/
 F:	package/cmake/
 F:	package/cramfs/
+F:	package/cross-ldd/
 F:	package/dmidecode/
 F:	package/double-conversion/
 F:	package/flashrom/
package/cross-ldd/cross-ldd.hash new file +4 -0
new file mode 100644
index 0000000000..b179aec5e0
@@ -0,0 +1,4 @@
+# From http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.26.0.tar.xz.sha512
+sha512  7834184ae5792fd347455f9f48fee826248dcb82d271954ed4304b1a18f63995ff8a2c3b817564dcf147ac7e16e02d779195b26d97eb57db27f1118a1837002a  crosstool-ng-1.26.0.tar.xz
+# Locally calculated
+sha256  07bc0ccd386469c748c4cf6c8faca5667fbf8c4400386714287fa233acfd68ba  COPYING
package/cross-ldd/cross-ldd.mk new file +37 -0
new file mode 100644
index 0000000000..357133cdd2
@@ -0,0 +1,37 @@
+################################################################################
+#
+# cross-ldd
+#
+################################################################################
+
+CROSS_LDD_VERSION = 1.26.0
+CROSS_LDD_SITE = http://crosstool-ng.org/download/crosstool-ng
+CROSS_LDD_SOURCE = crosstool-ng-$(CROSS_LDD_VERSION).tar.xz
+CROSS_LDD_LICENSE = GPL-2.0
+CROSS_LDD_LICENSE_FILES = COPYING
+
+ifeq ($(BR2_ARCH_IS_64),y)
+CROSS_LDD_BITNESS = 64
+else
+CROSS_LDD_BITNESS = 32
+endif
+
+CROSS_LDD_TOOLS_PREFIX = $(patsubst %-,%,$(TARGET_CROSS))
+
+define HOST_CROSS_LDD_CONFIGURE_CMDS
+	sed \
+		-e "s%@@CT_bash@@%/usr/bin/env bash%" \
+		-e "s%@@CT_VERSION@@%$(CROSS_LDD_VERSION)%" \
+		-e "s%@@CT_BITS@@%$(CROSS_LDD_BITNESS)%" \
+		-e "s%@@CT_sed@@%sed%" \
+		-e "s%@@CT_grep@@%grep%" \
+		-e "s%^prefix=.*%prefix=$(CROSS_LDD_TOOLS_PREFIX)%" \
+		$(@D)/scripts/xldd.in > \
+		$(@D)/scripts/xldd
+endef
+
+define HOST_CROSS_LDD_INSTALL_CMDS
+	$(INSTALL) -m 0755 -D $(@D)/scripts/xldd $(TARGET_CROSS)xldd
+endef
+
+$(eval $(host-generic-package))
Signature · 6 lines
2.47.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 1/4] package/cross-ldd: new package

Hello Thomas, All,

Le 08/01/2025 à 23:43, Thomas Petazzoni via buildroot a écrit :

Quoted 22 lines

This commit introduces a new cross-ldd package which installs the cross ldd implementation that comes from Crosstool-NG, and which can be used like ldd, but when cross-compiling. We intend to use it as a replacement of host-prelink-cross for our dracut package.

The cross-ldd from Crosstool-NG is in fact even recommended by the Dracut documentation, in its docs/README.cross document:

To support cross-compiled binaries, a different ldd variant is needed that works on those binaries. One such ldd script is found at
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f

This Github Gist in fact contains the xldd.in code from Crosstool-NG.

Our package downloads the full tarball of Crosstool-NG. We tried to download only the script and the license file, but we couldn't figure out a way of downloading them *and* have the version in the filename to make sure that when doing an upgrade to a newer version, we wouldn't have a clash between old/new files having the same name (and causing conflicts with the hash verification). So in the end, we opted for download the whole tarball.

Quoted 1 line

I've run some runtime tests without any issue.

Applied to master, thanks.

Best regards,
Romain

Quoted 63 lines
---
 DEVELOPERS                       |  1 +
 package/cross-ldd/cross-ldd.hash |  4 ++++
 package/cross-ldd/cross-ldd.mk   | 37 ++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 package/cross-ldd/cross-ldd.hash
 create mode 100644 package/cross-ldd/cross-ldd.mk
DEVELOPERS +1 -0
index 16b72eee08..1174100014 100644
@@ -3145,6 +3145,7 @@ F:	package/cifs-utils/
 F:	package/cloop/
 F:	package/cmake/
 F:	package/cramfs/
+F:	package/cross-ldd/
 F:	package/dmidecode/
 F:	package/double-conversion/
 F:	package/flashrom/
package/cross-ldd/cross-ldd.hash new file +4 -0
new file mode 100644
index 0000000000..b179aec5e0
@@ -0,0 +1,4 @@
+# From http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.26.0.tar.xz.sha512
+sha512  7834184ae5792fd347455f9f48fee826248dcb82d271954ed4304b1a18f63995ff8a2c3b817564dcf147ac7e16e02d779195b26d97eb57db27f1118a1837002a  crosstool-ng-1.26.0.tar.xz
+# Locally calculated
+sha256  07bc0ccd386469c748c4cf6c8faca5667fbf8c4400386714287fa233acfd68ba  COPYING
package/cross-ldd/cross-ldd.mk new file +27 -0
new file mode 100644
index 0000000000..357133cdd2
@@ -0,0 +1,37 @@
+################################################################################
+#
+# cross-ldd
+#
+################################################################################
+
+CROSS_LDD_VERSION = 1.26.0
+CROSS_LDD_SITE = http://crosstool-ng.org/download/crosstool-ng
+CROSS_LDD_SOURCE = crosstool-ng-$(CROSS_LDD_VERSION).tar.xz
+CROSS_LDD_LICENSE = GPL-2.0
+CROSS_LDD_LICENSE_FILES = COPYING
+
+ifeq ($(BR2_ARCH_IS_64),y)
+CROSS_LDD_BITNESS = 64
+else
+CROSS_LDD_BITNESS = 32
+endif
+
+CROSS_LDD_TOOLS_PREFIX = $(patsubst %-,%,$(TARGET_CROSS))
+
+define HOST_CROSS_LDD_CONFIGURE_CMDS
+	sed \
+		-e "s%@@CT_bash@@%/usr/bin/env bash%" \
+		-e "s%@@CT_VERSION@@%$(CROSS_LDD_VERSION)%" \
+		-e "s%@@CT_BITS@@%$(CROSS_LDD_BITNESS)%" \
+		-e "s%@@CT_sed@@%sed%" \
+		-e "s%@@CT_grep@@%grep%" \

package/cross-ldd/cross-ldd.mk line 37

Quoted 10 lines
package/cross-ldd/cross-ldd.mk new file +10 -0
+		-e "s%^prefix=.*%prefix=$(CROSS_LDD_TOOLS_PREFIX)%" \
+		$(@D)/scripts/xldd.in > \
+		$(@D)/scripts/xldd
+endef
+
+define HOST_CROSS_LDD_INSTALL_CMDS
+	$(INSTALL) -m 0755 -D $(@D)/scripts/xldd $(TARGET_CROSS)xldd
+endef
+
+$(eval $(host-generic-package))

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

PATCH 2/4 package/dracut: use host-cross-ldd instead of host-prelink-cross

In reply to Thomas Petazzoni via buildroot

This commit reworks the dracut package to use the cross-ldd installed by host-cross-ldd instead of prelink-rtld installed by host-prelink-cross.

Indeed, prelink-cross is not maintained upstream, and its dependency on host-libiberty causes problems in Buildroot with other packages.

The only change needed is that the dracut_wrapper script needs to be generated, as we now need to know the prefix of the cross-compilation tool (TARGET_CROSS).

Tested by running the dracut tests of the test suite.

---
 package/dracut/dracut.mk                             | 8 +++++---
 package/dracut/{dracut_wrapper => dracut_wrapper.in} | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)
 rename package/dracut/{dracut_wrapper => dracut_wrapper.in} (94%)
package/dracut/dracut.mk +5 -3
index 8573e64055..cb6044415e 100644
@@ -10,12 +10,14 @@ DRACUT_LICENSE = GPL-2.0
 DRACUT_LICENSE_FILES = COPYING
 DRACUT_CPE_ID_VALID = YES
 
-HOST_DRACUT_DEPENDENCIES = host-pkgconf host-kmod host-prelink-cross
+HOST_DRACUT_DEPENDENCIES = host-pkgconf host-kmod host-cross-ldd
 
 define HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
 	mv $(HOST_DIR)/bin/dracut $(HOST_DIR)/bin/dracut.real
-	install -D -m 0755 $(HOST_DRACUT_PKGDIR)/dracut_wrapper \
-		$(HOST_DIR)/bin/dracut
+	sed -e "s%@@TARGET_CROSS@@%$(TARGET_CROSS)%" \
+		$(HOST_DRACUT_PKGDIR)/dracut_wrapper.in > \
+		$(@D)/dracut_wrapper
+	install -D -m 0755 $(@D)/dracut_wrapper $(HOST_DIR)/bin/dracut
 endef
 HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
 
package/dracut/dracut_wrapper.in renamed from package/dracut/dracut_wrapper +1 -1
similarity index 94%
rename from package/dracut/dracut_wrapper
rename to package/dracut/dracut_wrapper.in
index 968d65cbeb..33012853d5 100644
@@ -34,7 +34,7 @@ topdir="$(dirname "$(realpath "$(dirname "${0}")")")"
 DRACUT_LDD="$(mktemp /tmp/dracut-ldd.XXXXXX)"
 cat >"${DRACUT_LDD}" <<EOL
 #!/bin/bash
-${topdir}/sbin/prelink-rtld --root='${sysroot}' \${1}
+@@TARGET_CROSS@@xldd --root='${sysroot}' \${1}
 EOL
 chmod +x "${DRACUT_LDD}"
 export DRACUT_LDD
Signature · 6 lines
2.47.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

PATCH 3/4 package/prelink-cross: remove package

In reply to Thomas Petazzoni via buildroot

We are now using cross-ldd instead of prelink-cross, so we can drop this package.

---
 .checkpackageignore                           |  1 -
 ...c-Fix-TLS-offsets-computation-for-s3.patch | 43 ------------------
 ...rc-execstack.c-fix-prelink_path-type.patch | 44 -------------------
 package/prelink-cross/prelink-cross.hash      |  3 --
 package/prelink-cross/prelink-cross.mk        | 16 -------
 5 files changed, 107 deletions(-)
 delete mode 100644 package/prelink-cross/0001-src-rtld-dl-tls.c-Fix-TLS-offsets-computation-for-s3.patch
 delete mode 100644 package/prelink-cross/0002-src-execstack.c-fix-prelink_path-type.patch
 delete mode 100644 package/prelink-cross/prelink-cross.hash
 delete mode 100644 package/prelink-cross/prelink-cross.mk
.checkpackageignore +0 -1
index 84b1e7ae00..7768962b9f 100644
@@ -996,7 +996,6 @@ package/pptp-linux/0001-susv3-legacy.patch lib_patch.Upstream
 package/pptp-linux/0002-fix-parallel-build.patch lib_patch.Upstream
 package/prboom/0001-libpng-1.4.patch lib_patch.Upstream
 package/prboom/0002-configure-remove-predefined-O2-optimization-flag.patch lib_patch.Upstream
-package/prelink-cross/0001-src-rtld-dl-tls.c-Fix-TLS-offsets-computation-for-s3.patch lib_patch.Upstream
 package/procps-ng/S02sysctl lib_sysv.Variables
 package/proftpd/S50proftpd Shellcheck lib_sysv.Indent lib_sysv.Variables
 package/prosody/0001-enable-syslog.patch lib_patch.Upstream
package/prelink-cross/0001-src-rtld-dl-tls.c-Fix-TLS-offsets-computation-for-s3.patch deleted +0 -43

43 lines not on this page · raw message

package/prelink-cross/0002-src-execstack.c-fix-prelink_path-type.patch deleted +0 -44

44 lines not on this page · raw message

package/prelink-cross/prelink-cross.hash deleted +0 -3
deleted file mode 100644
index 6776d407b8..0000000000
@@ -1,3 +0,0 @@
-# Locally computed
-sha256  555fd65c1b907f9b78d6d41ec04cb6e242d2ecb0667867e39cdd517b3f182dd3  prelink-cross-a853a5d715d84eec93aa68e8f2df26b7d860f5b2-git4.tar.gz
-sha256  b8a2f73f743dc1a51aff23f1aacbca4b868564db52496fa3c0caba755bfd1eaf  COPYING
package/prelink-cross/prelink-cross.mk deleted +0 -16
deleted file mode 100644
index 2312ee53e6..0000000000
@@ -1,16 +0,0 @@
-################################################################################
-#
-# host-prelink-cross
-#
-################################################################################
-
-PRELINK_CROSS_VERSION = a853a5d715d84eec93aa68e8f2df26b7d860f5b2
-PRELINK_CROSS_SITE = https://git.yoctoproject.org/git/prelink-cross
-PRELINK_CROSS_SITE_METHOD = git
-PRELINK_CROSS_LICENSE = GPL-2.0+
-PRELINK_CROSS_LICENSE_FILES = COPYING
-# Sources from git, no configure script present
-PRELINK_CROSS_AUTORECONF = YES
-HOST_PRELINK_CROSS_DEPENDENCIES = host-elfutils host-libiberty
-
-$(eval $(host-autotools-package))
Signature · 6 lines
2.47.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

PATCH 4/4 package/libiberty: remove package

In reply to Thomas Petazzoni via buildroot

host-libiberty was only used by host-prelink-cross, which has now been removed.

The dependency of host-gdb on host-libiberty was not because it was needed, but because if both host-libiberty and host-gdb were built, host-gdb should be built after host-liberty. See commit f0a583ddc4c2cab121330284e316f54229dee492 ("package/gdb: depend on libiberty")

Fixes:

http://autobuild.buildroot.net/results/82d2d7d30c8e00bf6e9918c3d989f65a7330d381/ (host-binutils)
http://autobuild.buildroot.net/results/a4674122a683e4842c1fd913da80a3e6e484d5a5/ (host-binutils-bare-metal)

---
 package/gdb/gdb.mk               |  4 +---
 package/libiberty/libiberty.hash |  1 -
 package/libiberty/libiberty.mk   | 32 --------------------------------
 3 files changed, 1 insertion(+), 36 deletions(-)
 delete mode 120000 package/libiberty/libiberty.hash
 delete mode 100644 package/libiberty/libiberty.mk
package/gdb/gdb.mk +1 -3
index c966cdc10b..69f7979149 100644
@@ -30,9 +30,7 @@ GDB_PRE_CONFIGURE_HOOKS += GDB_CONFIGURE_SYMLINK
 # For the host variant, we really want to build with XML support,
 # which is needed to read XML descriptions of target architectures. We
 # also need ncurses.
-# As for libiberty, gdb may use a system-installed one if present, so
-# we must ensure ours is installed first.
-HOST_GDB_DEPENDENCIES = host-expat host-libiberty host-ncurses host-zlib
+HOST_GDB_DEPENDENCIES = host-expat host-ncurses host-zlib
 
 # Disable building documentation
 GDB_MAKE_OPTS += MAKEINFO=true
package/libiberty/libiberty.hash deleted +0 -1
deleted file mode 120000
index e0655d3af3..0000000000
@@ -1 +0,0 @@
-../binutils/binutils.hash
\ No newline at end of file
package/libiberty/libiberty.mk deleted +0 -32
deleted file mode 100644
index ac6afc44ca..0000000000
@@ -1,32 +0,0 @@
-################################################################################
-#
-# libiberty
-#
-################################################################################
-
-LIBIBERTY_VERSION = 2.41
-LIBIBERTY_SOURCE = binutils-$(LIBIBERTY_VERSION).tar.xz
-LIBIBERTY_SITE = $(BR2_GNU_MIRROR)/binutils
-HOST_LIBIBERTY_DL_SUBDIR = binutils
-
-# We're only building libiberty here, not the full binutils suite
-LIBIBERTY_LICENSE = LGPL-2.1+
-LIBIBERTY_LICENSE_FILES = COPYING.LIB
-
-LIBIBERTY_SUBDIR = libiberty
-
-# We explicitly disable multilib, as we do in binutils.
-# By default, libiberty installs nothing, so we must force it.
-HOST_LIBIBERTY_CONF_OPTS = \
-	--disable-multilib \
-	--enable-install-libiberty
-
-# Some packages (e.g. host-gdb) will pick this library and build shared
-# objects with it. But libiberty does not honour the --enable-shared and
-# --disable-static flags; it only ever builds a static library no matter
-# what. So we must force -fPIC in build flags.
-HOST_LIBIBERTY_CONF_ENV = \
-	CFLAGS="$(HOST_CFLAGS) -fPIC" \
-	LDFLAGS="$(HOST_LDFLAGS) -fPIC"
-
-$(eval $(host-autotools-package))
Signature · 6 lines
2.47.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot