This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

i386-cygwin32: arbitrary section bug and workaround


Since I haven't heard anything about problem with multiple template
instances that PE linker can't seem to resolve properly (see my bug
reports in egcs-bugs over the past week), I've gone back to non-arbitrary
sections. Everything finally works again, with the downside that you
have to be careful about template instances. Patch at end of message.

Here's the scenario:

Let's say you start with the following file:
   
   #include <complex>

   complex c1;

   int main () { return 0; }

When you compile this, egcs will generate say the '/' operator for complex
class in a named section marked with '.linkonce discard', and make the 
symbol in the section global. After assembly, PE linker is supposed take
all the such named sections and pick one, and discard the rest.
Unfortunately somewhere between gas and ld (I'm using gas-971023), it's
going wrong and I end up with multiple definitions.

So I tried the following: 
  - codegen change (I had posted the fix to varasm.c in egcs-bugs): Make 
    the symbols in the named sections NOT global, ala ELF Weak symbols. 
    ld now does things fine, but relocations are all screwed up. 
  
  - gas change: Make linkonce discard directive override global (ala ELF
    Weak symbols again). Same problem with ld.

(Should the template instances be marked "global"? Suggestions on how I
can debug this problem?)

After both failed, and the fact that I can't figure out PE linker, here's
the workaround that works for some large'ish bodies of C++ code with lots
of templates. I'll use this until someone with better know-how comes up
with a real fix.

Wed Oct 29 12:30:22 1997  Mumit Khan <khan@brahma.xraylith.wisc.edu>

	Workaround for binutils bug for i386-cygwin32 target.

	* i386/cygwin32.h (ASM_OUTPUT_SECTION_NAME): Revert to non-arbirtrary
	section.
	(MULTIPLE_SYMBOL_SPACES): undef for now.
	(UNIQUE_SECTION_P): Likewise.
	(UNIQUE_SECTION): Likewise.
	(SUPPORTS_ONE_ONLY): Likewise.

--- config/i386/cygwin32.h.~1	Tue Oct 28 22:06:15 1997
+++ config/i386/cygwin32.h	Wed Oct 29 12:30:09 1997
@@ -167,4 +167,18 @@ while (0)
     if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG))
 
+/* Gas and PE linker seems to have trouble (tested upto gas-971023
+   snapshot when named sections are used, especially for implict template
+   instances. I'm not sure where the bug is, but PE linker is definitely
+   not discarding all but one of the named sections, giving multiple
+   definition errors. To avoid this, I've gone back to the old way of
+   creating sections until the problems are fixed. Downside is that now
+   you have to be careful with template code, unlike on ELF.  */
+
+#if 1
+
+#define ASM_OUTPUT_SECTION_NAME(STREAM, DECL, NAME, RELOC)	\
+  fprintf (STREAM, "\t.section %s\n", (NAME))
+   
+#else
 /* Define this macro if in some cases global symbols from one translation
    unit may not be bound to undefined symbols in another translation unit
@@ -200,2 +214,3 @@ do {								\
 	     ? "discard" : "same_size");			\
 } while (0)
+#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]