Skip to contentSkip to conversation

Makefile: use root-relative -f path for /sbin/ldconfig

PATCH New Bjørn Forsman 3 participants 7 messages Oct 22, 2015 – Dec 29, 2015 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Makefile: use root-relative -f path for /sbin/ldconfig

Without this, the -f path argument is ignored:

 $ strace -f -s128 /sbin/ldconfig -r /home/vagrant/buildroot/output/target -f /home/vagrant/buildroot/output/target/etc/ld.so.conf |& grep "ld\.so\.conf"
 execve("/sbin/ldconfig", ["/sbin/ldconfig", "-r", "/home/vagrant/buildroot/output/target", "-f", "/home/vagrant/buildroot/output/target/etc/ld.so.conf"], [/* 61 vars */]) = 0
 execve("/sbin/ldconfig.real", ["/sbin/ldconfig.real", "-r", "/home/vagrant/buildroot/output/target", "-f", "/home/vagrant/buildroot/output/target/etc/ld.so.conf"], [/* 61 vars */]) = 0
 write(2, "Warning: ignoring configuration file that cannot be opened: /home/vagrant/buildroot/output/target/etc/ld.so.conf", 112Warning: ignoring configuration file that cannot be opened: /home/vagrant/buildroot/output/target/etc/ld.so.conf) = 112

Proof that using root-relative path -f path (/etc/ld.so.conf, without $(TARGET_DIR) in front) picks up the correct file:

 $ strace -f -s128 /sbin/ldconfig -r /home/vagrant/buildroot/output/target -f /etc/ld.so.conf |& grep "ld\.so\.conf"
 execve("/sbin/ldconfig", ["/sbin/ldconfig", "-r", "/home/vagrant/buildroot/output/target", "-f", "/etc/ld.so.conf"], [/* 61 vars */]) = 0
 execve("/sbin/ldconfig.real", ["/sbin/ldconfig.real", "-r", "/home/vagrant/buildroot/output/target", "-f", "/etc/ld.so.conf"], [/* 61 vars */]) = 0
 lstat("/home/vagrant/buildroot/output/target/etc/ld.so.conf", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
 open("/home/vagrant/buildroot/output/target/etc/ld.so.conf", O_RDONLY) = 3

Tested on Ubuntu 14.04.

 $ /sbin/ldconfig --version
 ldconfig (Ubuntu EGLIBC 2.19-0ubuntu6.6) 2.19
 ...

$(TARGET_CROSS)ldconfig behaves differently (at least the ldconfig I tested, which was built by Buildroot) and should not have root-relative -f path. If it does, it will pick up host /etc/ld.so.conf file.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index dd8959f..61ce1f9 100644
@@ -607,7 +607,7 @@ endif
 					-f $(TARGET_DIR)/etc/ld.so.conf; \
 	else \
 		/sbin/ldconfig -r $(TARGET_DIR) \
-			       -f $(TARGET_DIR)/etc/ld.so.conf; \
+			       -f /etc/ld.so.conf; \
 	fi
 	( \
 		echo "NAME=Buildroot"; \
Signature · 1 line
2.5.2
#1 lore raw

PATCH 2/2 Makefile: add -C flag for /sbin/ldconfig

Needed when building in a FHS chroot on NixOS[1]. Without it, ldconfig tries to open a directory in the nix store. Being explicit fixes it.

Tested that it doesn't regress on Ubuntu 14.04.

[1] I know, it's an uncommon setup :-)

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 61ce1f9..ff812f3 100644
@@ -607,6 +607,7 @@ endif
 					-f $(TARGET_DIR)/etc/ld.so.conf; \
 	else \
 		/sbin/ldconfig -r $(TARGET_DIR) \
+			       -C /etc/ld.so.cache \
 			       -f /etc/ld.so.conf; \
 	fi
 	( \
Signature · 1 line
2.5.2
#2 lore raw

PATCH 1/2 Makefile: use root-relative -f path for /sbin/ldconfig

In reply to Bjørn Forsman
Quoted 18 lines · Bj?rn Forsman

Without this, the -f path argument is ignored:

 $ strace -f -s128 /sbin/ldconfig -r /home/vagrant/buildroot/output/target -f /home/vagrant/buildroot/output/target/etc/ld.so.conf |& grep "ld\.so\.conf"
 execve("/sbin/ldconfig", ["/sbin/ldconfig", "-r", "/home/vagrant/buildroot/output/target", "-f", "/home/vagrant/buildroot/output/target/etc/ld.so.conf"], [/* 61 vars */]) = 0
 execve("/sbin/ldconfig.real", ["/sbin/ldconfig.real", "-r", "/home/vagrant/buildroot/output/target", "-f", "/home/vagrant/buildroot/output/target/etc/ld.so.conf"], [/* 61 vars */]) = 0
 write(2, "Warning: ignoring configuration file that cannot be opened: /home/vagrant/buildroot/output/target/etc/ld.so.conf", 112Warning: ignoring configuration file that cannot be opened: /home/vagrant/buildroot/output/target/etc/ld.so.conf) = 112

Proof that using root-relative path -f path (/etc/ld.so.conf, without $(TARGET_DIR) in front) picks up the correct file:

 $ strace -f -s128 /sbin/ldconfig -r /home/vagrant/buildroot/output/target -f /etc/ld.so.conf |& grep "ld\.so\.conf"
 execve("/sbin/ldconfig", ["/sbin/ldconfig", "-r", "/home/vagrant/buildroot/output/target", "-f", "/etc/ld.so.conf"], [/* 61 vars */]) = 0
 execve("/sbin/ldconfig.real", ["/sbin/ldconfig.real", "-r", "/home/vagrant/buildroot/output/target", "-f", "/etc/ld.so.conf"], [/* 61 vars */]) = 0
 lstat("/home/vagrant/buildroot/output/target/etc/ld.so.conf", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
 open("/home/vagrant/buildroot/output/target/etc/ld.so.conf", O_RDONLY) = 3

Tested on Ubuntu 14.04.

Quoted 7 lines
 $ /sbin/ldconfig --version
 ldconfig (Ubuntu EGLIBC 2.19-0ubuntu6.6) 2.19
 ...

$(TARGET_CROSS)ldconfig behaves differently (at least the ldconfig I tested, which was built by Buildroot) and should not have root-relative -f path. If it does, it will pick up host /etc/ld.so.conf file.

This makes me worried that it will do the wrong thing on some other build
hosts. In fact, using /sbin/ldconfig is fundamentally broken since we can't be sure that it's compatible with the target dynamic linker.

Regards,
Arnout

Quoted 20 lines
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index dd8959f..61ce1f9 100644
@@ -607,7 +607,7 @@ endif
 					-f $(TARGET_DIR)/etc/ld.so.conf; \
 	else \
 		/sbin/ldconfig -r $(TARGET_DIR) \
-			       -f $(TARGET_DIR)/etc/ld.so.conf; \
+			       -f /etc/ld.so.conf; \
 	fi
 	( \
 		echo "NAME=Buildroot"; \
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#3 lore raw

PATCH 1/2 Makefile: use root-relative -f path for /sbin/ldconfig

Quoted 3 lines · Arnout Vandecappelle

This makes me worried that it will do the wrong thing on some other build hosts. In fact, using /sbin/ldconfig is fundamentally broken since we can't be sure that it's compatible with the target dynamic linker.

If you don't want to apply this patch, that is totally fine. It just fixes a warning I saw while debugging an issue that ended up being fixed by the next patch:

[PATCH 2/2] Makefile: add -C flag for /sbin/ldconfig

The 2nd patch is the one I really care about, it currently blocks me from running Buildroot in my preferred environment.

If you want to completely remove use of (host) /sbin/ldconfig, that's fine too.

Just tell me what to do :-)

- Bj?rn

#4 lore raw

PATCH 1/2 Makefile: use root-relative -f path for /sbin/ldconfig

Dear Bj?rn Forsman,

Quoted 3 lines · Bj?rn Forsman

If you want to completely remove use of (host) /sbin/ldconfig, that's fine too.

Just tell me what to do :-)

We need to completely remove the ldconfig stuff, since it simply cannot work. However, there is at least one package (mysql) that installs libraries in a non-standard location (/usr/lib/mysql) and relies on ld.so.conf for the dynamic linker to find them. I believe we need to fix MySQL so that it installs its libraries in /usr/lib, and then get rid of all the ldconfig/ld.so.conf stuff.

Or, alternatively, see how to get it working with an init script which runs ldconfig at boot time. But then you have to look at how uClibc and musl handle this, and implement a solution that works for all three C libraries.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#5 lore raw

PATCH 1/2 Makefile: use root-relative -f path for /sbin/ldconfig

Hi Thomas,

Quoted 15 lines · Thomas Petazzoni

Dear Bj?rn Forsman,

Quoted 3 lines · Bj?rn Forsman

If you want to completely remove use of (host) /sbin/ldconfig, that's fine too.

Just tell me what to do :-)

We need to completely remove the ldconfig stuff, since it simply cannot work. However, there is at least one package (mysql) that installs libraries in a non-standard location (/usr/lib/mysql) and relies on ld.so.conf for the dynamic linker to find them. I believe we need to fix MySQL so that it installs its libraries in /usr/lib, and then get rid of all the ldconfig/ld.so.conf stuff.

Quoted 4 lines

Or, alternatively, see how to get it working with an init script which runs ldconfig at boot time. But then you have to look at how uClibc and musl handle this, and implement a solution that works for all three C libraries.

Sounds like a bigger task than I planned... :-/ (I'm afraid to break things.)

Would it be possible to merge "[PATCH 2/2] Makefile: add -C flag for /sbin/ldconfig" as a stop-gap fix for my build problem then?

- Bj?rn

#6 lore raw

PATCH 1/2 Makefile: use root-relative -f path for /sbin/ldconfig

In reply to Bjørn Forsman

Bj?rn,

Quoted 8 lines · Bj?rn Forsman

$(TARGET_CROSS)ldconfig behaves differently (at least the ldconfig I tested, which was built by Buildroot) and should not have root-relative -f path. If it does, it will pick up host /etc/ld.so.conf file.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

As we discussed previously, our ldconfig handling is broken. So we are simply planning to remove entirely. I have just posted a patch to this effect:

	https://patchwork.ozlabs.org/patch/561618/

The idea is that from now on, packages are expected to install libraries in path that are in the default search path of the dynamic linker.

Consequently, I've marked your patches as Superseded. If you find any package that doesn't work properly following our ldconfig removal, do not hesitate to let us know.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com