Mail Archives: djgpp/1997/11/06/06:31:23
Hi all,
programming a bigger project I found the following problem which may be
a linker-error, but at least a very dangerous thing. It costs me more
than one day to find the bug.
The program below crashes with an segmentation fault, if file test.o is
linked to main, even if (as you see) main calls nothing from test, but
calls a function with the same name as a variable in test.o. The linker
seems to resolve the reference to the function 'int enable();' to the
variable 'int enable;' !!!
The problem may arise with all variable-names. With enable the problem
is even more complicated to find, as all file-io as (f)printf calls
enable() if interrupts are disabled and crashes the program this way. If
interrupts are not disabled, printf works without problems even if the
variable enable is declared! In my case, enable was a variable in one
module, but the program always crashed in other modules.
Roland
#################################################################
makefile
#################################################################
CXXFLAGS=-Wall -O2 -g
TARGET_ARCH=-m486
# system-crash with segmentation-fault, if test.o was linked
# program runs ok, if test.o was not linked
main: main.o test.o
test.o: test.cc
main.o: main.cc
#################################################################
main.cc
#################################################################
#include <dos.h>
int main()
{
disable();
enable();
return 0;
}
##########################################################################
test.cc
##########################################################################
int enable;
- Raw text -