Libraries, function names and link

J

joseluismarchetti

Hello everybody,

Although I am sure this is an important question for this group, I
am not sure this question belongs to this group and I will be
happy to move it to the correct one after you point it to me.

Direct question:
How can I know if a function is defined in more than one static
library that I am using to link ?

More information:
We have a huge project with about 40 libraries, some of them are
third part libraries.
One day, when I got a new third part library release, I luckly
started getting a link error because a function called FileExists
was being defined in two libraries.
I said luckly because if I invert the order that the libraries are
being linked, I could not see the error and in that case who knows
what funcion was being used.
( of course I know, but it might be the wrong one and the problem
might showup two months from now and it must not show up )

The problem I am trying to avoid is: having two functions in two
different libraries with the same name, in this case, the function
that will be linked depend on the position of the libraries in the
link command.

I know that this is the beaulty of libraries, that we can override
functions, but I would like to be aware that this situation is
happening.

Also I know that is common sense that the libraries should have a
prefix in their name function, like the foo.lib should have
function names as foo_function1 or something like that, but this
is a convention and that can fail when using third part libraries.

Also can be argued that I should know the function names in the
libraries, but in this project we are talking about of thousands
of functions, lots of them are bought without source code, so it
is not pratical to do so, but even if this was pratical I would
like to have a computer checking to me.

I looked into my link for any option that would do that and I
could not find ( for references I use the ADS arm toolkit )

The ideal solution would be having a utility that will check the
libraries for me, or something else with the same idea.

I work in this area for many years and never thought about this
problem, until it bit me and know I think this is a problem that
could bite anyone, but I am not finding answers until now.

Please let me know if you need more information and any comments
are welcome.

Thanks in advance

Jose Luis Marchetti
 
W

Walter Roberson

Although I am sure this is an important question for this group, I
am not sure this question belongs to this group

It doesn't really. It would be better put in a newsgroup specific
to your programming environment.
Direct question:
How can I know if a function is defined in more than one static
library that I am using to link ?

You mention the ADS arm toolkit but you do not happen to mention
which platform you are running on.

As a generalization, unix-like platforms often provide tools such as
'nm' which can be used to ask a library for a list of symbols that it
defines.

The following gets unix-specific.


I happen to prefer the "Berkeley" style output of 'nm', the -B option.
With it, you look for items marked with D (a data definition with
initialization) or with T (a "text" = code definition). Some systems also
use B (a data definition of an object to be zero'd at startup),
G (small initialized data definition) and S (small zeroed data
definition).

For example,

$ nm -B /usr/freeware/lib32/libpcap.so |egrep ' [BDT] ' | head
00000000 T __dso_displacement
08a80000 T __elf_header
08a8d9cc T __pcap_atodn
08a8d93c T __pcap_atoin
08a8dbf8 T __pcap_nametodnaddr
08a80034 T __program_header_table
08ab21f8 D blocks
08a84aa0 T bpf_dump
08a85d00 T bpf_error
08a84bd8 T bpf_filter


That translates to an 'extern' definition for 'blocks', and definitions
of the functions bpf_dump, bpf_error, bpf_filter .


With a program such as this available, it is relatively easy to write
a tool that will locate the definitions of each library, dump them
into a file, and then for each new library, cross-check in case it
defines something that is already present.
 
J

joseluismarchetti

Walter said:
You mention the ADS arm toolkit but you do not happen to mention
which platform you are running on.

It is an embedded system based on the Arm PXA255.
As a generalization, unix-like platforms often provide tools such as
'nm' which can be used to ask a library for a list of symbols that it
defines.

ADS tools have a similar feature where I can have a list of the library

symbol table and other information.
With a program such as this available, it is relatively easy to write
a tool that will locate the definitions of each library, dump them
into a file, and then for each new library, cross-check in case it
defines something that is already present.
--

Well... I thought about that and I agree with you, would not be hard to
create an application to do that, but would you agree with me that all
systems that use libraries are subject to this issue ? And if this is
the
case I think ( but I might be wrong )this check should already be
available somewhere.

Thanks for your answer.
 
J

joseluismarchetti

Hello everybody,

Although I am sure this is an important question for this group, I
am not sure this question belongs to this group and I will be
happy to move it to the correct one after you point it to me.

Direct question:
How can I know if a function is defined in more than one static
library that I am using to link ?

More information:
We have a huge project with about 40 libraries, some of them are
third part libraries.
One day, when I got a new third part library release, I luckly
started getting a link error because a function called FileExists
was being defined in two libraries.
I said luckly because if I invert the order that the libraries are
being linked, I could not see the error and in that case who knows
what funcion was being used.
( of course I know, but it might be the wrong one and the problem
might showup two months from now and it must not show up )

The problem I am trying to avoid is: having two functions in two
different libraries with the same name, in this case, the function
that will be linked depend on the position of the libraries in the
link command.

I know that this is the beaulty of libraries, that we can override
functions, but I would like to be aware that this situation is
happening.

Also I know that is common sense that the libraries should have a
prefix in their name function, like the foo.lib should have
function names as foo_function1 or something like that, but this
is a convention and that can fail when using third part libraries.

Also can be argued that I should know the function names in the
libraries, but in this project we are talking about of thousands
of functions, lots of them are bought without source code, so it
is not pratical to do so, but even if this was pratical I would
like to have a computer checking to me.

I looked into my link for any option that would do that and I
could not find ( for references I use the ADS arm toolkit )

The ideal solution would be having a utility that will check the
libraries for me, or something else with the same idea.

I work in this area for many years and never thought about this
problem, until it bit me and know I think this is a problem that
could bite anyone, but I am not finding answers until now.

Please let me know if you need more information and any comments
are welcome.

Thanks in advance

Jose Luis Marchetti

I got a good answer ( worked ) from comp.sys.arm and I am bringing
it here:

Try linking all the objects from each library in a single link.
e.g.

armlink lib1.a(*.o) lib2.a(*.o) ...


If two functions with the same name exist, you should get multiple
definition errors.


Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top