www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/09/22:51:05

Date: Sat, 06 Sep 1997 15:51:09 -0600
From: edkiser AT southeast DOT net
Subject: Problem: exception handling and optimizations don't mix
Newsgroups: comp.os.msdos.djgpp
Message-ID: <873577006.32607@dejanews.com>
Organization: Deja News Posting Service
Lines: 93
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Whenever I compile a C++ program with -fhandle-exceptions and -O3, -O2,
sometimes even -O1, everything compiles perfectly, then I get linker
errors to the effect that a bunch of symbols of the form L<nnnnn> don't
exist. Here's an example:

***** makefile *****

#EXCEPT =

EXCEPT = -fhandle-exceptions

STDOPTS = -Wall $(EXCEPT) -m486 -O6

LINK = -lstdcxx -s

parity.exe : parity.o
	gcc parity.o -o parity.exe $(LINK)

parity.o : parity.s
	gcc -c parity.s -o parity.o $(STDOPTS)

parity.s : parity.cpp
	gcc -S parity.cpp -o parity.s $(STDOPTS)

 .phony: clean
clean:
	rm -rf parity.o parity.s parity.exe *.bak

***** parity.cpp *****

#ifndef _IOSTREAM_H
#include <iostream.h>
#endif

inline int parity(unsigned int p)
{ register char q;
  asm ("testl %1,%1\n\t"
       "setpo %0\n"
       : "=r" (q)
       : "r" (p)
      );
  return (int)q;
};

int main(void)
{ bool done=false;
  while (!done)
  { cout << "Enter a number: " << flush;
    int i=0;
    cin >> i;
    if (cin.fail()) done=true;
    if (!done)
    { cout << "Parity: " << parity(i) << endl;
    }
  }
  return 0;
};

***** output *****

gcc -S parity.cpp -o parity.s -Wall -fhandle-exceptions -m486 -O6
gcc -c parity.s -o parity.o -Wall -fhandle-exceptions -m486 -O6
gcc parity.o -o parity.exe -lstdcxx -s
parity.o(.text+0x320):parity.cc: undefined reference to `L3167'
parity.o(.text+0x324):parity.cc: undefined reference to `L3168'
parity.o(.text+0x328):parity.cc: undefined reference to `L3169'
parity.o(.text+0x32c):parity.cc: undefined reference to `L3179'
parity.o(.text+0x330):parity.cc: undefined reference to `L3180'
parity.o(.text+0x334):parity.cc: undefined reference to `L3181'
make.exe: *** [parity.exe] Error 1

***** end *****

I've used -O6 here to aggravate the problem on purpose, because for this
particular program, -O1 doesn't cause any problem, nor does -O2. But I
have a larger program (3,500 lines) that won't even compile with -O1
without producing missing L<nnnnn> symbols.

This behavior is typical for ALL my C++ programs.

The reference to L3167, etc., is from the ___EXCEPTION_TABLE__ in the .s
file.

Why are symbols being put into the exception table when the code for
those symbols has been optimized out?

Is this a bug in the compiler? It must be! When will it be fixed?

------ reply to:
e d k i s e r @ s o u t h e a s t . n e t

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

- Raw text -


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