Bug 39565 - Static variable leaves undefined symbol in object file
Summary: Static variable leaves undefined symbol in object file
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-26 17:51 UTC by Edmar Wienskoski
Modified: 2009-04-29 17:29 UTC (History)
3 users (show)

See Also:
Host: powerpc-unknown-linux-gnu
Target: powerpc-unknown-linux-gnu
Build: powerpc-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Edmar Wienskoski 2009-03-26 17:51:23 UTC
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
Comment 1 Richard Biener 2009-03-27 09:19:48 UTC
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
Comment 2 Edmar Wienskoski 2009-03-27 15:01:23 UTC
I noticed that too. On x86_64 there is no undefined symbol either.
Comment 3 Anmol P. Paralkar 2009-04-28 23:43:51 UTC
 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
 
Comment 4 Richard Biener 2009-04-29 08:34:47 UTC
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

Comment 5 Ben Elliston 2009-04-29 12:06:01 UTC
I think this PR can now be closed.
Comment 6 hjl@gcc.gnu.org 2009-04-29 14:55:13 UTC
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

Comment 7 Anmol P. Paralkar 2009-04-29 17:29:20 UTC
 Respun testcase per advice from Joseph S. Myers:

 http://gcc.gnu.org/ml/gcc-patches/2009-04/msg02363.html