0

For the demonstration I made 2 folders with 2 versions of libgcc_s.so.1 And I looked for library choice according to ldd:

> file {A,B}/libgcc_s.so.1
A/libgcc_s.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), stripped
B/libgcc_s.so.1: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), stripped

> LD_LIBRARY_PATH=A:B ldd MyProgram | grep libgcc_s.so.1
libgcc_s.so.1 => B/libgcc_s.so.1

Why MyProgram does not use A/libgcc_s.so.1 ? I understand that is a matter of architecture but how A/libgcc_s.so.1 is considered invalid and how can I test it manually ?

Alcolo47
  • 91
  • 1
  • 4

1 Answers1

0

The ELF header's third field is "machine" which has the value 62 for amd64 (x86_64) and 3 for i386 (80386). The loader of course will inspect this field to determine whether it can use a given library, and if not it will continue to the next path in its search list.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Ok,but how can I determine if a library is compliant with the current architecture ? I can get the 18-19th bytes of the ELF, but I don't know how determine if this code is compliant with my actual architecture. Doing [[ $(readelf -h | grep $(Machine:)) == \*$(uname -i)\* ]] it is safe ? – Alcolo47 Sep 22 '14 at 13:32
  • What's the actual goal you're trying to accomplish at a higher level? – John Zwinck Sep 22 '14 at 13:44
  • I have shared folders across different platforms containing different libraries for different architectures. My actual LD_LIBRARY_PATH include all of them. I want to reduce it with only useful folder according to the architecture without using any naming convention. – Alcolo47 Sep 22 '14 at 13:56
  • 1
    Then I think you should make folders named the same as the output of `uname -m` (e.g. x86_64). – John Zwinck Sep 22 '14 at 14:31
  • **without using any naming convention** – Alcolo47 Sep 22 '14 at 14:32
  • 1
    Well then sure, scan the output of readelf or `file(1)` or whatever and do string matching. Seems like a worse idea than having a naming convention but that's just my opinion. – John Zwinck Sep 22 '14 at 14:34
  • I agree with John: Then what is the right way to determine if a dynamic library is compliant with the current platform ? – Alcolo47 Sep 23 '14 at 13:58
  • The way everyone else does it is using a naming convention. But you already ruled that out for some reason. – John Zwinck Sep 24 '14 at 01:29