developingpld:advanceddeveloping:fixingasneeded
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| developingpld:advanceddeveloping:fixingasneeded [2006-08-07 01:19] – Created from my posts on pld-devel-en list, needs a lot of work SamChi | developingpld:advanceddeveloping:fixingasneeded [2007-05-27 20:51] (current) – arekm | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| - | ==== Quick Workaround | + | ===== Quick and ugly workaround (DON'T USE IT!) ===== |
| - | Put in spec file this line: | + | Put this line in '' |
| - | < | ||
| - | </ | ||
| - | But **don' | ||
| - | Why ? Because it's very stupid. If something fails to build normally | + | |
| + | < | ||
| + | </ | ||
| + | But **don't use it** unless you really need to quickly | ||
| ===== How --as-needed works ===== | ===== How --as-needed works ===== | ||
| - | With '' | + | With '' |
| - | == About positions | + | ==== Why it fails for some packages ==== |
| - | Linker options are positional, and position | + | In other words, if you list 10 libraries |
| - | Correct | + | This normally works because if project requires libraries //A// and //B// and //A// itself lists //B// as a dependency, both //A// and //B// get pulled in even if the project itself only lists //A//. |
| + | |||
| + | Now assume that //A// is a superfluous (unneeded) dependency which gets dropped (or //A// requiring //B// is superfluous and //B// gets dropped from //A//). The symbols are no longer available. | ||
| + | |||
| + | |||
| + | |||
| + | ==== About positions ==== | ||
| + | Linker options are positional, and position is very important. It looks for missing symbols only in libraries coming after object file. | ||
| + | |||
| + | Correct | ||
| < | < | ||
| Line 29: | Line 38: | ||
| and this generally works well. | and this generally works well. | ||
| - | If there is something like that: | + | |
| + | If there is something like that: | ||
| < | < | ||
| Line 35: | Line 45: | ||
| the library will __never__ be linked, because it's not required at the time it's checked. | the library will __never__ be linked, because it's not required at the time it's checked. | ||
| - | And with something like that: | + | |
| + | And with something like that: | ||
| < | < | ||
| </ | </ | ||
| - | library will allways | + | library will __allways__ |
| ==== Short examples ==== | ==== Short examples ==== | ||
| - | Most of problems are with readline/ | + | Most of problems are with readline/ |
| - | But some packages link with readline or ncurses while they use __only__ symbols from tinfo. | + | But some packages link with readline or ncurses while they use __only__ symbols from tinfo. //Without// '' |
| + | |||
| + | For a longer example take a look at real example nr. 1. | ||
| Line 57: | Line 70: | ||
| < | < | ||
| </ | </ | ||
| - | and normally objects | + | It's usual situation when object files require only library 2, and //-l1// is required by //-l2//. As I said linker only checks for symbols from objects, so //-l1// is not linked. Normally it is easy to fix it, simply make sure while linking |
| - | ===== Examples | + | ===== Real examples |
| ==== 1. unresolved symbols in executable ==== | ==== 1. unresolved symbols in executable ==== | ||
| - | xmoto | + | Very common situation, [[http:// |
| With '' | With '' | ||
| Line 71: | Line 84: | ||
| - | < | + | < |
| VApp.o: In function `vapp:: | VApp.o: In function `vapp:: | ||
| Line 96: | Line 109: | ||
| Binary file / | Binary file / | ||
| </ | </ | ||
| - | they are in '' | + | They are in '' |
| What we get after running make in build tree: | What we get after running make in build tree: | ||
| Line 102: | Line 115: | ||
| - | < | + | < |
| VApp.o: In function `vapp:: | VApp.o: In function `vapp:: | ||
| Line 124: | Line 137: | ||
| '' | '' | ||
| - | But take a look at spec file, -lGL thing was fixed there already: | + | But [[http:// |
| Line 135: | Line 148: | ||
| - | < | + | < |
| make[1]: Leaving directory `/ | make[1]: Leaving directory `/ | ||
| </ | </ | ||
| - | //It worked !// | + | **It worked !** |
| == Why was it working without --as-needed ? == | == Why was it working without --as-needed ? == | ||
| - | Answer is realy easy: libSDL is required by SDL_mixer: | + | Answer is really |
| Line 151: | Line 164: | ||
| libSDL-1.2.so.0 => / | libSDL-1.2.so.0 => / | ||
| </ | </ | ||
| - | but xmoto-edit contains no SDL_mixer symbols, that's why xmoto-edit | + | but xmoto-edit contains no SDL_mixer symbols, that's why it wasn't linked with SDL_mixer, and there was nothing |
| - | Can you see now why was it so stupid to disable '' | + | Can you see now why was it stupid to disable '' |
| Line 163: | Line 176: | ||
| LIBS=" | LIBS=" | ||
| </ | </ | ||
| - | or patching configure.in and the result is: | + | or patching configure.in, and the result is: |
| - | Wrote: / | + | '' |
| ==== 2. unresolved symbols in library while linking executable ==== | ==== 2. unresolved symbols in library while linking executable ==== | ||
| - | That's the most common and a little more difficult case, evolution-data-server: | + | That's the most common and a little more difficult case, [[http:// |
| Compilation stops at this place: | Compilation stops at this place: | ||
| Line 176: | Line 189: | ||
| - | < | + | < |
| + | -lgnome-keyring -lpthread | ||
| - | x86_64-pld-linux-gcc -ggdb -O2 -ftree-vectorize -ftree-vectorizer-verbose=1 -march=athlon64 -mmmx -msse -msse2 -m3dnow -mfpmath=sse -Wall -Wmissing-prototypes -Wno-sign-compare | + | gcc -Wl, |
| ./ | ./ | ||
| Line 207: | Line 221: | ||
| '' | '' | ||
| - | So add this one and glade to that library deps: | + | So add this one and '' |
| Line 230: | Line 244: | ||
| == Why was it working without --as-needed ? == | == Why was it working without --as-needed ? == | ||
| - | test-source-selector binary was linked with all libraries needed by libedataserverui-1.2.so, | + | '' |
| + | |||
| + | |||
| + | |||
| + | === What if broken library comes from other package ? === | ||
| + | You can check manually does library has all required symbols, simply running ' gcc //library// ', like this: | ||
| + | |||
| + | This is an example of correctly linked library: | ||
| + | |||
| + | < | ||
| + | / | ||
| + | (.text+0x20): | ||
| + | collect2: ld returned 1 exit status | ||
| + | </ | ||
| + | And incorrectly linked one: | ||
| + | |||
| + | < | ||
| + | / | ||
| + | (.text+0x20): | ||
| + | / | ||
| + | / | ||
| + | [...] | ||
| + | / | ||
| + | collect2: ld returned 1 exit status | ||
| + | </ | ||
| + | **Warning: | ||
| - | ==== 3. ==== | + | ==== 3. unresolved symbols caused by incorrect order ==== |
| - | Two of most difficult of common problems at one, evolution.spec: | + | Two of most difficult of common problems at once, [[http:// |
| The difficulties are: | The difficulties are: | ||
| Line 253: | Line 292: | ||
| - | < | + | < |
| / | / | ||
| Line 260: | Line 299: | ||
| collect2: ld returned 1 exit status | collect2: ld returned 1 exit status | ||
| </ | </ | ||
| - | function ''' | + | function ''' |
| - | just take a look at my fix: | + | Just take a look at my fix: |
| Line 274: | Line 313: | ||
| + | + | ||
| </ | </ | ||
| - | with this simple change everything works perfectly | + | With this simple change everything works perfectly. |
developingpld/advanceddeveloping/fixingasneeded.1154906347.txt.gz · Last modified: 2006-08-07 01:19 by SamChi