This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Feature request: Globalize symbol
- From: Fredrik Hugosson <fredrik dot hugosson at axis dot com>
- To: gcc at gcc dot gnu dot org, hans-peter dot nilsson at axis dot com
- Date: Thu, 24 Feb 2005 10:42:13 +0100
- Subject: Feature request: Globalize symbol
Hi!
When working with unit tests I frequently have the need to override a
function or variable in a shared library. This works just as I want for
global symbols, but if the symbol is local (declared static) I have to
modify the source (remove the static using a STATIC preprocessor define)
to make it work.
The setup is as follows:
app/Makefile
app/src.c
app/checktests/Makefile
app/checktests/tests.c
In the application Makefile I have a target to compile the application
as a shared library. This target is invoked from the checktests Makefile
and the lib is then linked with the tests. So I compile the application
source under test from scratch and can control the flags. (To mess even
less with the application under test I may change the setup in the
future to include the application Makefile in a wrapper Makefile instead
of adding a shared library target to it.)
All this makes it possible to override any global symbols in src.c by
defining the symbol in the tests.c file. What I miss is the possibility
to override local symbols in a similar manner, without touching the
source. This problem could be fixed by adding some options to gcc to
globalize symbols.
My proposal is the following new options:
-fglobalize-symbol=SYMBOLNAME
-fglobalize-symbols=FILENAME
-fglobalize-all-symbols
The first option makes the symbol SYMBOLNAME global.
The second option makes all symbols in FILENAME global.
The third option makes all symbols global.
The globalization should apply to all symbols that are visible on the
file scope level but not globally visible. E.g. both functions declared
'static' and variables declared 'static' (outside functions). The
attribute '__attribute__ ((hidden))' may be overridden too, but for my
purposes I don't have the need for this.
Waiting hopefully
/HUGO.