05.06.2014 Views

QNX Neutrino Programmer's Guide [6.5.0 SP1] - QNX Software ...

QNX Neutrino Programmer's Guide [6.5.0 SP1] - QNX Software ...

QNX Neutrino Programmer's Guide [6.5.0 SP1] - QNX Software ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

© 2012, <strong>QNX</strong> <strong>Software</strong> Systems Limited Optimizing the runtime linker<br />

• In the lazy-bound case, it doesn’t fail right away (since it didn’t check to see if it<br />

could resolve all the symbols) but will still fail on the first call to an unresolved<br />

symbol. This doesn’t change even if the application later calls dlopen() to load an<br />

object that defines that symbol, because the application can’t change the resolution<br />

scope. The only exceptions to this rule are objects loaded using dlopen() with the<br />

RTLD_LAZY flag (see below).<br />

Lazy binding is controlled by the -z option to the linker, ld. This option takes<br />

keywords as an argument; the keywords include (among others):<br />

lazy<br />

now<br />

When generating an executable or shared library, mark it to tell the dynamic<br />

linker to defer function-call resolution to the point when the function is<br />

called (lazy binding), rather than at load time.<br />

When generating an executable or shared library, mark it to tell the dynamic<br />

linker to resolve all symbols when the program is started, or when the<br />

shared library is linked to using dlopen(), instead of deferring function-call<br />

resolution to the point when the function is first called.<br />

Lazy binding is the default. If you’re using qcc (as we recommend), use the -W option<br />

to pass the -z option to ld. For example, specify -Wl,-zlazy or -Wl,-znow.<br />

There are cases where the default lazy binding isn’t desired. For example:<br />

• While the system is under development, you might want to fully resolve all<br />

symbols right away, to catch library mismatches; your application would fail to<br />

load if a referenced function couldn’t be resolved.<br />

• You might want to fully resolve the symbols for a particular object at load time.<br />

• You might want only a given program to be always bound right away.<br />

There’s a way to do each of these:<br />

• To change the default lazy binding to the “bind now” behavior for all processes<br />

started from a given shell, set the LD_BIND_NOW environment variable to a<br />

non-null value. For example:<br />

LD_BIND_NOW=1 ./foobar<br />

By default, pdebug sets LD_BIND_NOW to 1. If you start gdb from the command<br />

line on a self-hosted <strong>QNX</strong> <strong>Neutrino</strong> system, gdb also sets LD_BIND_NOW to 1.<br />

Without LD_BIND_NOW, you’d see a different backtrace for the first function call<br />

into the shared object as the runtime linker resolves the symbol. On subsequent calls<br />

to the same function, the backtrace would be as expected. You can prevent pdebug<br />

from setting LD_BIND_NOW by specifying the -l (“el”) option.<br />

• To override the binding strategy for a given shared object, link it with the -znow<br />

linker option:<br />

June 14, 2012 Chapter 1 • Compiling and Debugging 17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!