www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/06/06:31:23

From: Roland Exler <r DOT exler AT jk DOT uni-linz DOT ac DOT at>
Newsgroups: comp.os.msdos.djgpp
Subject: WARNING: linker-error?
Date: Thu, 06 Nov 1997 07:40:56 -0800
Organization: emt.uni-linz.ac.at
Lines: 54
Message-ID: <3461E508.2CE4@jk.uni-linz.ac.at>
Reply-To: r DOT exler AT jk DOT uni-linz DOT ac DOT at
NNTP-Posting-Host: sensor194.emt.uni-linz.ac.at
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019