Norbert Juffa
2004-02-15 22:21:23 UTC
My apologies if someone has already seen this post over
in gnu.gcc. I belatedly noticed that gnu.gcc is a very
low-volume group and probably not suitable for questions
such as this, which could explain the lack of replies.
I am trying to find a way of hiding all non-API symbols
contained in a static libary (i.e., lib*.a). I am using
the gcc 3.2 tool chain, and the static library consists
of a fairly large number of object files generated from C
sources. The modularity of the library is of no concern,
as any real-world application will pull in 90+% of the
library code anyhow.
What I am trying to accomplish is easily implemented for
a DSO by use of --version-script combined with aggressive
stripping. However in this case I need to deliver a static
library, not a DSO.
Here is what I am doing right now. First, I converted as
many functions as possible to static functions. I figured
further that by combining the object files comprising the
library into one giant new object file, all inter-object
references will be resolved and thus no longer needed. I
could then strip off the names of everything but API the
API symbols and undefined symbols (i.e. references to
functions in other libraries):
$(LD) -o super.o -O5 -Ur --retain-symbols-file api.txt *.o
$(AR) rcvs $(STAT_LIB_NAME) super.o
$(STRIP) --strip-debug --discard-all -R .note -R .comment
Here, api.txt refers to a list of API functions using the
format required by --retain-symbols-file (flat file with
one symbol name per line).
Unfortunately, the above approach does not do what I want
to accomplish. Using nm on the resulting static library
shows me that all symbols with external linkage from the
original object files are preserved. I experimented with
various switch combinations of strip, objcopy, and ld, but
can't find a way to make this work.
The description of --retain-symbols-file says it "does not
discard undefined symbols, or symbols needed for relocations".
So apparently the linker considers the symbols I would like
to remove as "needed for relocation", although I have created
a single object file?
Is there a way to solve this issue without obfuscating the
names of non-API symbols?
-- Norbert
in gnu.gcc. I belatedly noticed that gnu.gcc is a very
low-volume group and probably not suitable for questions
such as this, which could explain the lack of replies.
I am trying to find a way of hiding all non-API symbols
contained in a static libary (i.e., lib*.a). I am using
the gcc 3.2 tool chain, and the static library consists
of a fairly large number of object files generated from C
sources. The modularity of the library is of no concern,
as any real-world application will pull in 90+% of the
library code anyhow.
What I am trying to accomplish is easily implemented for
a DSO by use of --version-script combined with aggressive
stripping. However in this case I need to deliver a static
library, not a DSO.
Here is what I am doing right now. First, I converted as
many functions as possible to static functions. I figured
further that by combining the object files comprising the
library into one giant new object file, all inter-object
references will be resolved and thus no longer needed. I
could then strip off the names of everything but API the
API symbols and undefined symbols (i.e. references to
functions in other libraries):
$(LD) -o super.o -O5 -Ur --retain-symbols-file api.txt *.o
$(AR) rcvs $(STAT_LIB_NAME) super.o
$(STRIP) --strip-debug --discard-all -R .note -R .comment
Here, api.txt refers to a list of API functions using the
format required by --retain-symbols-file (flat file with
one symbol name per line).
Unfortunately, the above approach does not do what I want
to accomplish. Using nm on the resulting static library
shows me that all symbols with external linkage from the
original object files are preserved. I experimented with
various switch combinations of strip, objcopy, and ld, but
can't find a way to make this work.
The description of --retain-symbols-file says it "does not
discard undefined symbols, or symbols needed for relocations".
So apparently the linker considers the symbols I would like
to remove as "needed for relocation", although I have created
a single object file?
Is there a way to solve this issue without obfuscating the
names of non-API symbols?
-- Norbert