niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » AIX
Localize symbols on AIX
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
Author Message
Henrik Goldman
*nix forums Guru Wannabe


Joined: 26 Mar 2006
Posts: 102

PostPosted: Mon Jul 03, 2006 9:37 am    Post subject: Re: Localize symbols on AIX Reply with quote

Quote:
You are probably using GNU nm, for which '-C' is the opposite:
-C
--demangle[=style]
Decode (demangle) low-level symbol names into user-level names.

You're right. When I installed binutils I also got a copy of gnu-nm which
overrided the native nm util. I didn't notice this until you mentioned it.
With the native nm util i get the correct result though.
However I choose also to rename "T" symbols and not just D and B.
I think they are just as important as the others.

Quote:

Here is how we do it:
ld -r -bnoentry -bnoautoexp -bstatic -bex2:rename-script foo.o -o bar.o

where rename-script is:
rename foo __hidden_foo
rename .foo __hidden_dot_foo
... 100s more ...

Thanks a million! This is just what I was missing. Now I am doing the same
thing and get everything renamed.

Quote:
[We are renaming '.foo' symbols as well because this was required
on aix4.x IIRC]

Yes I would like to do that as well. However I found that if I rename some
dot symbols then the linked application crashes. I was unable to find out
which ones so for now I do not rename the dot symbols which is probably bad.
I don't know about differences between AIX 4.X and 5L but it seems for
instance that the linker won't work unless you have for instance both main
and .main. I'm sure I got some symbols renamed which eventually was
important to the runtime linker. However it's only guesswork so far.

One idea would eventually be to install a completely other version of gcc
(currently using 3.3.6) to see how compatibility are between them. However I
am not keen on risking my current setup. Perhaps it would be possible to
install them side by side with --prefix to see if it actually works or not.

Perhaps Gary knows some more on this dot symbol magic?

Thanks in advance.
-- Henrik
Back to top
Paul Pluzhnikov
*nix forums Guru


Joined: 25 Mar 2005
Posts: 512

PostPosted: Sun Jul 02, 2006 4:57 pm    Post subject: Re: Localize symbols on AIX Reply with quote

[This is a re-post of message <m3d5cpqx8m.fsf@somewhere.in.california.localhost>
from Sat, 01 Jul 2006 06:18:49 -0700 which my news server "ate"]

"Henrik Goldman" <henrik_goldman@mail.tele.dk> writes:

Quote:
nm -pBC | egrep ' [BD] ' | awk....
will work just fine.

Unfortunatly not. It seems that it will demangle the symbols:

000000000002d010 D operator new(unsigned long, std::nothrow_t const&)

From "man nm":
-C Suppresses the demangling of C++ names.


You are probably using GNU nm, for which '-C' is the opposite:
-C
--demangle[=style]
Decode (demangle) low-level symbol names into user-level names.

Quote:
If I was given a file (with one symbols on each line) with symbols that had
both normal and dotted version, which command would I use to exclude those
with dots? I'm sorry but I'm lacking some unix scripting knowledge.

$ cat symlist
foo
..foo
bar
..bar
$ sed '/^\./d' symlist
foo
bar


Quote:
Another BIG problem is that aix linker doesn't seem to like scripts as a
parts of it's action.

It does. As far as UNIX linkers go, AIX one is second (after GNU ld)
in "scriptability". Look for "binder options" ex{1,2,3,4,5} in "man ld".

Quote:
So far I have spent ALOT of time on trying to implement this renaming.
However currently it takes more then 30 min to rename a 1 mb object file and
....
This is because I had to make a ld -r step for each symbol. If I would do
them all at once it would complain and say that the commandline is too long.

Here is how we do it:
ld -r -bnoentry -bnoautoexp -bstatic -bex2:rename-script foo.o -o bar.o

where rename-script is:
rename foo __hidden_foo
rename .foo __hidden_dot_foo
... 100s more ...

[We are renaming '.foo' symbols as well because this was required
on aix4.x IIRC]

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Back to top
Henrik Goldman
*nix forums Guru Wannabe


Joined: 26 Mar 2006
Posts: 102

PostPosted: Fri Jun 30, 2006 6:58 pm    Post subject: Re: Localize symbols on AIX Reply with quote

Quote:
Why not take all the code that uses the old version and put it
into a shared module? Black-box it and hide the implementation.
This would be much easier than trying to implement linker tricks.

I wish I could do that too. However it's a user requirement to it this way
so there are no alternatives.
If it would be up to me I would never have spent any minute on AIX 5.1. Now
that I read it's EOL'd I don't think it's worthwhile spending so much time
on it. Unfortunatly it's not up to me though...

Quote:
nm -pBC | egrep ' [BD] ' | awk....
will work just fine.

Unfortunatly not. It seems that it will demangle the symbols:

000000000002d010 D operator new(unsigned long, std::nothrow_t const&)
0000000000026b84 D _GLOBAL__F__ZnwmRKSt9nothrow_t
000000000002a670 D operator new[](unsigned long)
0000000000026bfc D _GLOBAL__F__Znam
000000000002d01c D operator new[](unsigned long, std::nothrow_t const&)

This is probably not a good idea.

Quote:

Work with the non-"." version.


If I was given a file (with one symbols on each line) with symbols that had
both normal and dotted version, which command would I use to exclude those
with dots? I'm sorry but I'm lacking some unix scripting knowledge.

Another BIG problem is that aix linker doesn't seem to like scripts as a
parts of it's action.

So far I have spent ALOT of time on trying to implement this renaming.
However currently it takes more then 30 min to rename a 1 mb object file and
then it eventually fails and I can start debug it and try again. It's
surprisingly how fast 8 hours on a day can go and you still feel like you've
got nothing done.

This is because I had to make a ld -r step for each symbol. If I would do
them all at once it would complain and say that the commandline is too long.

This is what I have so far (part of my makefile):

nm $filename | grep -E \" T | B | D \" | awk '{print \$3}' > $TMP/orig.txt;

comm -3 $TMP/orig.txt aix_keep_symbols.txt > $TMP/new.txt;

echo #!/bin/sh > $TMP/relink.sh;

awk '{printf \"ld -r -brename:%s,new_%s\ $filename\\n\", \$0, \$0}'
$TMP/new.txt >> $TMP/relink.sh;

chmod +x $TMP/relink.sh;

Then I would execute relink.sh and it would do a rename for each symbols.

I'm really open to good suggestions. It's just a hassle right now and it
still fails on some symbols. I have not found out why since I didn't have
the patience to wait another 30 min to get the error code.

Thanks in advance.

-- Henrik
Back to top
Gary R. Hook
*nix forums Guru Wannabe


Joined: 22 Feb 2005
Posts: 172

PostPosted: Thu Jun 29, 2006 2:13 pm    Post subject: Re: Localize symbols on AIX Reply with quote

Henrik Goldman wrote:
Quote:
True. This was just for demonstration purposes. In the real code I have an
object where libstdc++.a object code is being merged and I want to avoid
references to libstdc++.a since it could cause problems between different
gcc versions.

Why not take all the code that uses the old version and put it
into a shared module? Black-box it and hide the implementation.
This would be much easier than trying to implement linker tricks.

Quote:
Basicly I want to do the same thing as I initially described: Hide all
symbols names except for those which I want to have.
In order to do this my plan is to filter on 'nm' output in order to figure
out all the symbols I want to rename.

So far I have the first step ready:

nm temp/my.o | grep -E " T | B | D " | awk '{print tolower($3)}'
nm -pBC | egrep ' [BD] ' | awk....

will work just fine.

Quote:
This will give me a quite complete list. But in order to make it work I
would need to figure out how to remove those symbols I *don't* want renamed.
Also AIX seems to have two versions of most objects where one is prefixed by
".". For instance:

_zst24__throw_invalid_argumentpkc
._zst24__throw_invalid_argumentpkc

Work with the non-"." version.

Quote:

I don't know if this will cause problems as well but I could imagine that
perhaps the dotted version needs to be removed as well.

Could any of you help me fill the details in order to finalize the list of
symbols to be renamed and make it into a list of names usable by 'ld -r'?

FYI static symbols get collected as "_$STATIC" or some such, but
you might not want to use the same name. YMMV.

Perhaps you can explain this in detail?

Global symbols declared static within a compilation unit are all
collected and named by the label "_$STATIC". This obfuscates the
original names, yet provides an anchor point for debug information, etc.
Not sure what else there is to say. Suffice that there are symbols that
you shouldn't use, and that's one of them.
Back to top
Henrik Goldman
*nix forums Guru Wannabe


Joined: 26 Mar 2006
Posts: 102

PostPosted: Fri Jun 23, 2006 8:49 am    Post subject: Re: Localize symbols on AIX Reply with quote

Quote:
I'll presume that the example code is overly simplified, and that
there would nominally be references to bar within this compilation
unit. The references would be necessary to ensure that the symbol
doesn't get get garbage collected during a link.

True. This was just for demonstration purposes. In the real code I have an
object where libstdc++.a object code is being merged and I want to avoid
references to libstdc++.a since it could cause problems between different
gcc versions.

Quote:
I'd suggest using the -brename option of the linker to change
the name of _Z3barv to something not referenced/recognizes by
any of the other code. The renaming causes everything within that
.o to still have access to the symbol, but would obfuscate the
symbol for any other object code involved in a subsequent link.
You could run this .o through ld -r to perform the operation.

This sounds like an idea.

Basicly I want to do the same thing as I initially described: Hide all
symbols names except for those which I want to have.
In order to do this my plan is to filter on 'nm' output in order to figure
out all the symbols I want to rename.

So far I have the first step ready:

nm temp/my.o | grep -E " T | B | D " | awk '{print tolower($3)}'

This will give me a quite complete list. But in order to make it work I
would need to figure out how to remove those symbols I *don't* want renamed.
Also AIX seems to have two versions of most objects where one is prefixed by
".". For instance:

_zst24__throw_invalid_argumentpkc
.._zst24__throw_invalid_argumentpkc

I don't know if this will cause problems as well but I could imagine that
perhaps the dotted version needs to be removed as well.

Could any of you help me fill the details in order to finalize the list of
symbols to be renamed and make it into a list of names usable by 'ld -r'?

Quote:
FYI static symbols get collected as "_$STATIC" or some such, but
you might not want to use the same name. YMMV.

Perhaps you can explain this in detail?

Thanks in advance.

-- Henrik
Back to top
Gary R. Hook
*nix forums Guru Wannabe


Joined: 22 Feb 2005
Posts: 172

PostPosted: Thu Jun 22, 2006 3:24 pm    Post subject: Re: Localize symbols on AIX Reply with quote

Paul Pluzhnikov wrote:
Quote:
"Henrik Goldman" <henrik_goldman@mail.tele.dk> writes:

I would like to localize symbols in an object file.

I am not aware of any "native" tools that do this, and Gary Hook
didn't supply an answer this time Sad

Gary was swapping out laptops yesterday and got nothing done.

There's no general purpose tool for manipulating the symbol table
of an xcoff file. That said....

I'll presume that the example code is overly simplified, and that
there would nominally be references to bar within this compilation
unit. The references would be necessary to ensure that the symbol
doesn't get get garbage collected during a link.

I'd suggest using the -brename option of the linker to change
the name of _Z3barv to something not referenced/recognizes by
any of the other code. The renaming causes everything within that
..o to still have access to the symbol, but would obfuscate the
symbol for any other object code involved in a subsequent link.
You could run this .o through ld -r to perform the operation.

FYI static symbols get collected as "_$STATIC" or some such, but
you might not want to use the same name. YMMV.
Back to top
Paul Pluzhnikov
*nix forums Guru


Joined: 25 Mar 2005
Posts: 512

PostPosted: Thu Jun 22, 2006 4:11 am    Post subject: Re: Localize symbols on AIX Reply with quote

"Henrik Goldman" <henrik_goldman@mail.tele.dk> writes:

Quote:
I would like to localize symbols in an object file.

I am not aware of any "native" tools that do this, and Gary Hook
didn't supply an answer this time :(

The "normal" way this is controlled on AIX is by shipping a shared
library (in which case it is trivial to control symbol visibility
with an export list), but I understand you are trying to do the
same for an archive library.

You could try to fix the bug in GNU binutils, but libbfd on which
objcopy is based is notoriously hard to understand :(

Your other alternative is to build an aix64-specific custom tool
to do the same. AIX XCOFF format is quite simple, and fairly well
documented in /usr/include/syms.h

I expect the whole thing could be done in <1000 lines of code.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Back to top
Henrik Goldman
*nix forums Guru Wannabe


Joined: 26 Mar 2006
Posts: 102

PostPosted: Tue Jun 20, 2006 3:35 pm    Post subject: Localize symbols on AIX Reply with quote

Hi,

As I described in a recent post I found some problems with objcopy (2.16.1)
on AIX 5.1.

I would like to localize symbols in an object file.

An example would be:

bash-3.00# cat test.cpp
int foo()
{
int x = 1;
}

int bar()
{
int y = 1;
}

bash-3.00# g++ -c test.cpp

bash-3.00# nm test.o
0000000000000098 d .data
U __divss
U __divus
U __mulh
U __mull
U __quoss
U __quous
0000000000000000 t .text
000000000000009c d TOC
000000000000008c d _Z3barv
000000000000008c D _Z3barv
0000000000000040 T ._Z3barv
0000000000000080 d _Z3foov
0000000000000080 D _Z3foov
0000000000000000 T ._Z3foov


We see that both _Z3barv and _Z3foov are global. I'd like to create a new
object where both are still present but only foo remains global.
I've been looking at strip and gnu-strip as alternative to objcopy but no
luck so far. AIX strip is even more limited then gnu strip.

Are there no native AIX utils which can localize global symbols?

Thanks in advance.
-- Henrik
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
The time now is Sat Jan 10, 2009 1:12 am | All times are GMT
navigation Forum index » *nix » AIX
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts math symbols not displaying Andrew Dabrowski python 1 Sat Jul 15, 2006 1:12 am
No new posts aCC option to load all the symbols during linking Bujji HP-UX 2 Fri Jul 14, 2006 6:18 pm
No new posts how to weak_alias of symbols in application code seyong_choi@hotmail.com C 0 Wed Jul 12, 2006 8:35 pm
No new posts unresolved symbols and other problems Norman Elliott Setup 21 Mon Jul 10, 2006 12:31 pm
No new posts unresolved symbols and other problems Norman Elliott networking 0 Mon Jul 10, 2006 10:42 am

Business Sales | Debt Consolidation | Credit Counseling | Credit Card Debt Consolidation | Car Finance
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 1.0508s ][ Queries: 20 (0.8760s) ][ GZIP on - Debug on ]