aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@gentoo.org>2023-10-01 10:32:33 +0100
committerJames Le Cuirot <chewi@gentoo.org>2023-10-02 22:38:18 +0100
commit8008e209d900dc988217ce3721292ba895cd0494 (patch)
tree2d2e4fe6fe32c5d0425e95a1b3c4a9d7809df811
parentenv_update: Write prefixed paths to files and terminal where appropriate (diff)
downloadportage-8008e209d900dc988217ce3721292ba895cd0494.tar.gz
portage-8008e209d900dc988217ce3721292ba895cd0494.tar.bz2
portage-8008e209d900dc988217ce3721292ba895cd0494.zip
env-update: Write /usr/etc/ld.so.conf to fix bfd in some obscure cases
This is only needed on prefixed systems. bfd currently reads ${EPREFIX}/etc/ld.so.conf and adds the prefix to these paths, but these paths are already prefixed. We need them to stay prefixed for ldconfig and the runtime linker. bfd will use ${EPREFIX}/usr/etc/ld.so.conf instead if that is present, so we can write the unprefixed paths there. Other linkers do not use these files at all. We tried to patch bfd to not use them either, as it shouldn't really be necessary, but that broke some cases, so we are trying this safer approach instead. env-update does not write the files under /etc/ld.so.conf.d, but we shouldn't need to handle these in any case, as all known instances are not affected by this issue. Bug: https://bugs.gentoo.org/892549 Closes: https://github.com/gentoo/portage/pull/1105 Signed-off-by: James Le Cuirot <chewi@gentoo.org>
-rw-r--r--NEWS3
-rw-r--r--lib/portage/util/env_update.py19
2 files changed, 22 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 75680fce1..c6d024769 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,9 @@ Bug fixes:
* emerge: fix application count when listing search results for ambiguous
packages (bug #915054).
+* env-update: Write ${EPREFIX}/usr/etc/ld.so.conf with unprefixed paths on
+ prefixed systems to fix the bfd linker in some obscure cases (bug #892549).
+
Cleanups:
* vartree: Remove unused variables and parameters
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index 04fde5a52..b19a85325 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -221,6 +221,25 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, writemsg_lev
myfd.write(x + "\n")
myfd.close()
+ if eprefix:
+ # ldconfig needs ld.so.conf paths to be prefixed, but the bfd linker
+ # needs them unprefixed, so write an alternative ld.so.conf file for
+ # the latter. Other linkers do not use these files. See ldelf.c in
+ # binutils for precise bfd behavior, as well as bug #892549.
+ ldsoconf_path = os.path.join(eroot, "usr", "etc", "ld.so.conf")
+ ensure_dirs(os.path.dirname(ldsoconf_path), mode=0o755)
+ myfd = atomic_ofstream(ldsoconf_path)
+ myfd.write(
+ "# ld.so.conf autogenerated by env-update; make all changes to\n"
+ f"# contents of {eprefix}/etc/env.d directory.\n"
+ "# This file is only used by the bfd linker. The paths are not\n"
+ "# prefixed as this is automatically added by the linker.\n"
+ )
+ for x in specials["LDPATH"]:
+ if x.startswith(eprefix + os.path.sep):
+ myfd.write(x[len(eprefix) :] + "\n")
+ myfd.close()
+
potential_lib_dirs = set()
for lib_dir_glob in ("usr/lib*", "lib*"):
x = os.path.join(eroot, lib_dir_glob)