Operating System - Linux
1752460 Members
6056 Online
108788 Solutions
New Discussion юеВ

Re: LD_PRELOAD unresolved symbols

 
Joseph H. Buehler
New Member

LD_PRELOAD unresolved symbols

I am trying to patch the Boehm garbage collector to override malloc etc. using LD_PRELOAD on an HPUX 11.0 PARISC machine and running into some trouble.

Here is what happens:

# LD_PRELOAD=/home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2 date
/usr/lib/dld.sl: Unresolved symbol: __data_start (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved symbol: end (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved module for symbol: GC_dirty_maintained (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved module for symbol: GC_n_kinds (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved module for symbol: GC_root_size (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved module for symbol: GC_time_limit (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved module for symbol: GC_is_initialized (data) from /home/project-releases/tmp/gc6.4.redirect/.libs/libgc.sl.1.2
/usr/lib/dld.sl: Unresolved module for symbol: malloc (code) from /usr/lib/libpthread.1
Abort(coredump)
#

The first two symbols are special and I assume may need some porting work on my part. However, the others are in the library:

# odump -slexport $PR/tmp/gc6.4.redirect/.libs/libgc.sl.1.2 | grepword 'GC_dirty_maintained|GC_n_kinds|GC_root_size|GC_time_limit|GC_is_initialized|malloc'
000000074 -00000001 00001 0x40004270 Data 000000,155 00 GC_time_limit
000000077 -00000001 00015 0x400045f4 Data 000000,155 00 GC_is_initialized
000000080 -00000001 00014 0x40004404 Data 000000,155 00 GC_root_size
000000085 000000009 00018 0x40004644 Data 000000,155 00 GC_dirty_maintained
000000132 -00000001 00013 0x400043d4 Data 000000,155 00 GC_n_kinds
000000417 -00000001 00011 0x0001d9f4 Code 000000,155 00 malloc

Can anyone shed some light on this?

Joe Buehler
4 REPLIES 4
Joseph H. Buehler
New Member

Re: LD_PRELOAD unresolved symbols

First problem, the "date" binary does not have SHLIB_PATH enabled.

Second problem, there is some bizarreness in the way that SHLIB_PATH and/or LD_PRELOAD need to be set.

The following works:

env SHLIB_PATH=/the/dir/with/libgc.sl LD_PRELOAD=libgc.sl test_binary.exe

I found that exporting the two environment variables in a subshell does NOT work for whatever reason:

(export SHLIB_PATH=whatever; export LD_PRELOAD=whatever; test_binary.exe)

that just results in a memory fault...

Joe Buehler
Michael Steele_2
Honored Contributor

Re: LD_PRELOAD unresolved symbols

List dynamic dependencies with ldd -v and chatr.

Verify patch dependencies or linking to dynamic libraries in /usr/lib options in $SHLIB_PATH.

echo $SHLIB_PATH
Support Fatherhood - Stop Family Law
Dennis Handly
Acclaimed Contributor

Re: LD_PRELOAD unresolved symbols

>I am trying to patch the Boehm garbage collector to override malloc etc. using LD_PRELOAD

LD_PRELOAD is very dangerous. It would be better if you just link your application with that new GC.

>The first two symbols are special and I assume may need some porting work on my part.

These are the problem. You look at "Unresolved symbol" for the missing ones and the "Unresolved module" are the reason. So to fix the issue you need to relink your application with -Wl,+ee,__data_start -Wl,+ee,end.

But if you could do that, you might as well link with libgc.sl.1.2.

>Joseph: I found that exporting the two environment variables in a subshell does NOT work

Right, you never want to export that variable, only use it sparingly as possible. And you may want to consider LD_PRELOAD_ONCE if you have the appropriate patches.

Also SHLIB_PATH is not needed if you give the absolute path for LD_PRELOAD, unless there are dependent libs.
Joseph H. Buehler
New Member

Re: LD_PRELOAD unresolved symbols

Thanks Dennis -- I got it working but I need to experiment a little with various combinations of SHLIB_PATH, LD_PRELOAD and "chatr +s enable".

It's easier to link against libgc.sl of course, but much nicer to be able to use LD_PRELOAD on an arbitrary application to temporarily fix customer-discovered memory leaks.