Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Relinking objects with libstdc++ and local symbols
I wrote some code in C++ which I compiled into an object file foo.o
This object has some dependencies to libstdc++ which I want to avoid.

From another earlier request in this group I got the following advice:

>    ld -r foo.o /usr/lib/libstdc++.a -o foo1.o
>    objcopy -G foo1 -G foo2 ... -G fooN foo1.o -o foo.o

This step relinks my object with libstdc++ so any C++ dependencies gets
merged into my object. Filesize grows but the dependency for libstdc++
should be removed and the only undefined symbols are to libc.

Now the problem is that the libstdc++ symbols gets redefined from undefined
to defined. nm utility will still show the symbols though.

The objcopy step will mark my own functions as global, which is good, and
make all the libstdc++ functions into locals.

One example from nm:
00000000 t _ZNSt8ios_base4Init14_S_ios_destroyEv

00000000 d _ZNSt8ios_base4Init16_S_ios_base_initE

00000000 d  _ZNSt8ios_base4Init20_S_synced_with_stdi
oE

00000000 t _ZNSt8ios_base4InitC1Ev

But what exactly does it mean when the symbols are local?

What I wanted is to enable the user of my object to use gcc instead of g++
as frontend linker. This works now. However I tried to strip the symbolnames
and when doing so the linked program will crash.

I assume that since the symbols are local now instead of global (before the
objcopy step) I will not have any incompatibilities if users use another
version libstdc++ and/or gcc (except ABI problems which I don't think of
here). In other words if I used libstdc++ 3.4.1 and user uses 3.4.2 it will
still work since the c++ code is wrapped inside my object now.

Any comments are welcome here. I think it's a hard subject and theres very
little material on the net about it. Maybe I assumed something wrong. Please
tell me if you know better.

Thanks in advance.

-- John




Report this thread to moderator Post Follow-up to this message
Old Post
John Smith
04-12-05 01:57 PM


Re: Relinking objects with libstdc++ and local symbols
"John Smith" <john.smith@x-formation.com> writes:

> But what exactly does it mean when the symbols are local?

It means they are not considered by the linker at all when your
object is linked with anything else. Their only remaining reason
for existance is to assist you in debugging.

> However I tried to strip the symbolnames
> and when doing so the linked program will crash.

Well, either 'strip' is broken, or there is another reason for
these symbols. You aren't throw()ing exceptions in your code,
are you?

> Any comments are welcome here.

Posting the crash stack trace, or (even better) making a simple
test case demonstrating the problem with stripped object, may add
substance to this discussion.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

Report this thread to moderator Post Follow-up to this message
Old Post
Paul Pluzhnikov
04-12-05 08:58 PM


Re: Relinking objects with libstdc++ and local symbols
> > However I tried to strip the symbolnames 
>
> Well, either 'strip' is broken, or there is another reason for
> these symbols. You aren't throw()ing exceptions in your code,
> are you?
>

No, no exceptions are thrown. I don't think strip is broken though.

Unfortunatly I don't have any sample code right here (because I got my
problem fixed) but I experienced something similar on both linux and mac os
in different scenarios. For some reason it seems the loader needs the names,
or atleast some of them, (global or local) to be able to work right.

Instead of using strip I used objcopy with -G switch to make global symbols
into local on linux and on mac os I used nmedit. This works perfectly.

-- John



Report this thread to moderator Post Follow-up to this message
Old Post
John Smith
04-19-05 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:09 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.