linker wisdom

10
The Linker Common Issues

Upload: dmichelsen

Post on 20-May-2015

563 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Linker Wisdom

The LinkerCommon Issues

Page 2: Linker Wisdom

General wisdomRead ld.so.1(1)Verify your assumptions

Page 3: Linker Wisdom

What does the linker do?

Combine an executable and shared libraries to a runnable entity

Page 4: Linker Wisdom

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.2

Search 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

Page 5: Linker Wisdom

Getting the runpath in the binary

Read ld(1)Always done during compile-time linkingOption „-R <path>“LD_OPTIONS is processed before -R

This can break testsuites

Page 6: Linker Wisdom

-R or LD_OPTIONS ?-R in LDFLAGS

Plays nice with applicationsIf they honour LDFLAGS

Multiple shell invocations may destroy $ISALIST

LD_OPTIONSWorks alwaysMay confuse build of test apps as they link against installed libs instead of the newly build

Page 7: Linker Wisdom

$ISALISTDynamically expanded by ld.so.1, e.g.sparcv9+vis2sparcv9+vissparcv9sparcv8plus+vis2sparcv8plus+vissparcv8plussparcv8sparcv8-fsmuldsparcv7sparc

See also isalist(1)

Page 8: Linker Wisdom

DebuggingStatic info from the binary

dump -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>

Page 9: Linker Wisdom

DebuggingInfo from the running process

pldddam@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

Page 10: Linker Wisdom

AUXV linkage

Link 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