Linker Wisdom

798 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
798
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Linker Wisdom

  1. 1. The Linker Common Issues
  2. 2. General wisdomRead ld.so.1(1)Verify yourassumptions
  3. 3. What does the linker do?Combine an executable and sharedlibraries to a runnable entity
  4. 4. How does it work? (a bit simplified...)This is runtime linking!Look for wanted libs in NEEDED in the object[1] NEEDED libcurses.so.1[2] NEEDED libintl.so.8[3] NEEDED libiconv.so.2Search them in system dirs Default Library Path (ELF): /lib:/usr/lib (system default) Trusted Directories (ELF): /lib/secure:/usr/lib/secure (system default)and RUNPATH[10] RUNPATH /opt/csw/lib/$ISALIST:/opt/csw/lib
  5. 5. Getting the runpath in the binary Read ld(1) Always done during compile-time linking Option „-R <path>“ LD_OPTIONS is processed before -R This can break testsuites
  6. 6. -R or LD_OPTIONS ?-R in LDFLAGS Plays nice with applications If they honour LDFLAGS Multiple shell invocations may destroy $ISALISTLD_OPTIONS Works always May confuse build of test apps as they link against installed libs instead of the newly build
  7. 7. $ISALISTDynamically expanded by ld.so.1, e.g.sparcv9+vis2sparcv9+vissparcv9sparcv8plus+vis2sparcv8plus+vissparcv8plussparcv8sparcv8-fsmuldsparcv7sparcSee also isalist(1)
  8. 8. Debugging Static info from the binarydump -Lv <binary>dam@login [login]:/home/dam > dump -Lv /opt/csw/bin/bash/opt/csw/bin/bash: **** DYNAMIC SECTION INFORMATION ****.dynamic:[INDEX] Tag Value[1] NEEDED libcurses.so.1[2] NEEDED libintl.so.8[3] NEEDED libiconv.so.2[4] NEEDED libsocket.so.1[5] NEEDED libnsl.so.1[6] NEEDED libdl.so.1[7] NEEDED libc.so.1[8] INIT 0xce204[9] FINI 0xce214[10] RUNPATH /opt/csw/lib/$ISALIST:/opt/csw/lib:/opt/csw/lib:/opt/csw/lib[11] RPATH /opt/csw/lib/$ISALIST:/opt/csw/lib:/opt/csw/lib:/opt/csw/lib[12] HASH 0x100e8[13] STRTAB 0x1c994...lari <binary>
  9. 9. Debugging Info from the running processpldddam@login [login]:/home/dam > pldd $$3838: /opt/csw/bin/zsh/opt/csw/lib/libgdbm.so.3.0.0/opt/csw/lib/libpcre.so.0.0.1/opt/csw/lib/libiconv.so.2.5.1/lib/libsocket.so.1/lib/libdl.so.1/opt/csw/lib/libncursesw.so.5.9/lib/libm.so.1/lib/libc.so.1/lib/libnsl.so.1/platform/sun4v/lib/libc_psr.so.1/opt/csw/lib/zsh/4.3.10/zsh/zle.so
  10. 10. AUXV linkageLink option -f <filtee>E.g. ld -h libcurl.so.4 -f libcurl-feature.so.4 ...How does it look in the binary?[10] SONAME libcurl.so.4[11] AUXILIARY libcurl-feature.so.4

×