Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using /etc/ld.so.preload in a multi arch setup

Is there some way to use ld.so.preload and cover both 32bit and 64bit binaries?

If I list both the 32bit and 64bit versions of the fault handler in ld.so.preload then the loader always complains that one of them fails to preload for whatever command I run. Not exactly earth shaking since the error is more a warning but I could certainly do without the printout.

Instead of specifying an absolute path I tried specifying simply "segv_handler.so" in the hopes that the loader would choose the lib in the arch appropriate path (a 32bit version is in /lib and a 64bit version is in /lib64).

Not likely apparently.

Is there a way to setup ld.so.preload to be architecturally aware? Or if not is there some way to turn off the error message?

like image 675
Bill Rees Avatar asked May 13 '11 05:05

Bill Rees


2 Answers

This works:

  1. put library under /path/lib for 32bit one, and put the 64bit one under /path/lib64 and they should have the same name
  2. put the following line in /etc/ld.so.preload: /path/$LIB/libname.so

$LIB will get the value "lib" (for 32bit) or "lib64" (for 64bit) automatically.

like image 185
pc201212 Avatar answered Nov 15 '22 23:11

pc201212


There's no reason to try to use ld.so.preload like this. By default ld is smart enough to know that if you're running a 64bit app to only lookup 64bit libs, and same with 32bit.

Case in point, if you have

/lib64/libawesome.so /lib/libawesome.so

And you try

gcc -lawesome -o funtime funtime.c

It'll choose whatever the default that gcc wants to build, ld will skip libraries of incorrect bit size for that build.

gcc -m64 -lawesome -o funtime funtime.c will pick the 64bit one

gcc -m32 -lawesome -o funtime funetime.c will pick the 32bit one.

This presumes that /etc/ld.so.conf lists /lib and /lib64 by default..

like image 32
synthesizerpatel Avatar answered Nov 15 '22 23:11

synthesizerpatel