relaytool link error when making a shared library (-fPIC missing)

3 views
Skip to first unread message

Jan Niklas Hasse

unread,
Nov 5, 2009, 11:53:50 AM11/5/09
to autop...@googlegroups.com
Hi,

Before creating the new mailing list I asked if someone could help me
with relaytool. Now here's my problem, hope someone can point me out
what I'm doing wrong:

I'm trying to create a shared library with a weak link against
libjpeg. But I'm getting an error because relaytool doesn't seem to
use the -fPIC option:

$ export CFLAGS="-fPIC"
$ g++ $CFLAGS -shared main.cpp `relaytool --relay jpeg -ljpeg` -ldl -o test.so
/usr/bin/ld: ./libjpeg.so.62.stub.o: relocation R_X86_64_32S against
`.bss' can not be used when making a shared object; recompile with
-fPIC
./libjpeg.so.62.stub.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
$

How to tell relaytool to use -fPIC? Is it even possible to create a
shared library using relaytool?

Mike Hearn

unread,
Nov 5, 2009, 12:50:26 PM11/5/09
to autop...@googlegroups.com
Does it work in 32 bit mode? I don't think relaytool supports
generating PIC, that'd be a lot more complicated.

BTW the new website has broken some links, eg, if you search for
[relaytool] on google ....

Jan Niklas Hasse

unread,
Nov 6, 2009, 10:55:55 AM11/6/09
to autop...@googlegroups.com
On Thu, Nov 5, 2009 at 6:50 PM, Mike Hearn <mi...@plan99.net> wrote:
> Does it work in 32 bit mode?

Yes, but it segfaults when I'm trying to use the library:

Program received signal SIGSEGV, Segmentation fault.
0x00687642 in _relaytool_init_libjpeg () from /usr/lib/test.so

I've attached three files which can be used to reproduce the error.

> BTW the new website has broken some links, eg, if you search for
> [relaytool] on google ....

Thanks, fixed.
main.cpp
lib.cpp
build.sh

Jan

unread,
Nov 18, 2009, 6:15:11 AM11/18/09
to autopackage
No idea?

Mike Hearn

unread,
Nov 18, 2009, 12:07:20 PM11/18/09
to autop...@googlegroups.com
I haven't had time to look at it, sorry. You can debug it yourself
with gdb. Look at where it's crashing. It's probably getting a NULL
from one of the dl* functions.

On Wed, Nov 18, 2009 at 12:15 PM, Jan <jha...@gmail.com> wrote:
> No idea?
>

Jan Niklas Hasse

unread,
Nov 18, 2009, 1:51:42 PM11/18/09
to autop...@googlegroups.com
On Wed, Nov 18, 2009 at 6:07 PM, Mike Hearn <mi...@plan99.net> wrote:
> I haven't had time to look at it, sorry.
No problem, just wanted to post again in case you've missed my last
mail somehow.

> You can debug it yourself
> with gdb. Look at where it's crashing. It's probably getting a NULL
> from one of the dl* functions.

Couldn't get it to work with gdb, but with many printfs i managed to
find the line where it's crashing:

FIXUP_GOT_RELOC( "jpeg_std_message_table", dlsym(handle,
"jpeg_std_message_table") );

I also checked if dlsym(handle, "jpeg_std_message_table") returns
NULL, but it doesn't.

Mike Hearn

unread,
Nov 18, 2009, 2:23:56 PM11/18/09
to autop...@googlegroups.com
Is that the first fixup? Why did it not work in gdb - knowing the
exact instruction or address it faults on would be the next step.

Jan Niklas Hasse

unread,
Nov 18, 2009, 3:44:57 PM11/18/09
to autop...@googlegroups.com
On Wed, Nov 18, 2009 at 8:23 PM, Mike Hearn <mi...@plan99.net> wrote:
> Is that the first fixup?
What do you mean? I can't find any more calls to FIXUP_GOT_RELOC.

> Why did it not work in gdb
Just tried again and this time it worked. I seem to have done
something wrong compiling the stub file before.

> - knowing the
> exact instruction or address it faults on would be the next step.

When using this:

1: void* addr = dlsym(handle, "jpeg_std_message_table");
2: printf("%d\n", (int)addr);
3: asm("\tmovl %0, %%eax\n"
4: "\tmovl %%eax, " "jpeg_std_message_table" "@GOT(%%ebx)\n" : :
"r" (addr));

It prints an address of 10800352 and it crashes in line 3. I don't
know if that helps you, as I said I don't know assembler (or what's
going on in those lines).
Reply all
Reply to author
Forward
0 new messages