Compiling the test case, produces undefined symbols codestrs_4 and codestrs_8, which will result in a link error. If the static is dropped or one of the cases in the switch statement is removed, the object file does not have undefined symbols. Test case: static const union codestrs_t_4 { struct { char str_2[sizeof ("Illegal opcode")]; }; char str[0]; } codestrs_4 = { {"Illegal opcode"} }; static const union codestrs_t_8 { struct { char str_12[sizeof ("Integer divide by zero")]; }; char str[0]; } codestrs_8 = { {"Integer divide by zero"} }; const char * psiginfo (int pinfo) { const char *base = ((void *)0); switch (pinfo) { case 4: base = codestrs_4.str; break; case 8: base = codestrs_8.str; break; } return base; } Compiled with: gcc -O2 -c objdump -t Result: cases.o: file format elf32-powerpc SYMBOL TABLE: 00000000 l df *ABS* 00000000 cases.c 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l O .data 00000014 CSWTCH.1 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 l d .comment 00000000 .comment 00000000 l d .gnu.attributes 00000000 .gnu.attributes 00000000 g F .text 00000024 psiginfo 00000000 *UND* 00000000 codestrs_4 00000000 *UND* 00000000 codestrs_8
I get t.o: file format elf32-i386 SYMBOL TABLE: 00000000 l df *ABS* 00000000 t.c 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l O .rodata 0000000f codestrs_4 0000000f l O .rodata 00000017 codestrs_8 00000000 l d .rodata 00000000 .rodata 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 l d .comment 00000000 .comment 00000000 g F .text 00000022 psiginfo
I noticed that too. On x86_64 there is no undefined symbol either.
I verified with native GCC on target: powerpc-unknown-linux-gnu on: gcc version 4.5.0 20090423 (experimental) [trunk revision 146648] (GCC) gcc version 4.4.1 20090424 (prerelease) [gcc-4_4-branch revision 146746] (GCC) that this is no longer a problem. I have submitted a testcase for the regression suite; please see: http://gcc.gnu.org/ml/gcc-patches/2009-04/msg02296.html
Subject: Bug 39565 Author: rguenth Date: Wed Apr 29 08:34:21 2009 New Revision: 146928 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146928 Log: 2009-04-29 Anmol P. Paralkar <anmol@freescale.com> PR target/39565 * gcc.dg/pr39565.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/pr39565.c Modified: trunk/gcc/testsuite/ChangeLog
I think this PR can now be closed.
Subject: Bug 39565 Author: hjl Date: Wed Apr 29 14:54:54 2009 New Revision: 146972 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146972 Log: 2009-04-29 H.J. Lu <hongjiu.lu@intel.com> Backport from mainline: 2009-04-29 Richard Guenther <rguenther@suse.de> PR tree-optimization/39941 * gcc.c-torture/compile/pr39941.c: New testcase. 2009-04-29 Anmol P. Paralkar <anmol@freescale.com> PR target/39565 * gcc.dg/pr39565.c: New testcase. 2009-04-28 Richard Guenther <rguenther@suse.de> PR middle-end/39937 * gfortran.fortran-torture/compile/pr39937.f: New testcase. Added: branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr39941.c - copied unchanged from r146971, trunk/gcc/testsuite/gcc.c-torture/compile/pr39941.c branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr39565.c - copied unchanged from r146971, trunk/gcc/testsuite/gcc.dg/pr39565.c branches/gcc-4_4-branch/gcc/testsuite/gfortran.fortran-torture/compile/pr39937.f - copied unchanged from r146971, trunk/gcc/testsuite/gfortran.fortran-torture/compile/pr39937.f Modified: branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Respun testcase per advice from Joseph S. Myers: http://gcc.gnu.org/ml/gcc-patches/2009-04/msg02363.html