Bug 30700 - [4.2 Regression] YA bogus undefined reference error to static func with -g and -O
Summary: [4.2 Regression] YA bogus undefined reference error to static func with -g an...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
Depends on: 31899
Blocks:
  Show dependency treegraph
 
Reported: 2007-02-04 17:50 UTC by Martin Michlmayr
Modified: 2007-05-12 14:50 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.1 4.1.2 4.3.0
Known to fail: 4.2.0
Last reconfirmed: 2007-02-04 18:02:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Michlmayr 2007-02-04 17:50:25 UTC
PR27657 addressed a similar problem but this one is slightly different and remains unsolved:

(sid)1556:tbm@em64t: ~/src/a] cat test.c
static void sand_window_create_shape (int test) {}
static void (* const b) (int test) = sand_window_create_shape;

(sid)1557:tbm@em64t: ~/src/a] cat main.c
int main() {
}
(sid)1558:tbm@em64t: ~/src/a] make
/usr/lib/gcc-snapshot/bin/gcc -c -o main.o main.c
/usr/lib/gcc-snapshot/bin/gcc -c -g -O -o test.o test.c
/usr/lib/gcc-snapshot/bin/gcc main.o test.o
test.o:(.debug_info+0x49): undefined reference to `sand_window_create_shape'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Comment 1 Richard Biener 2007-02-04 18:02:36 UTC
Index: dwarf2out.c
===================================================================
*** dwarf2out.c (revision 121576)
--- dwarf2out.c (working copy)
*************** reference_to_unused (tree * tp, int * wa
*** 10007,10012 ****
--- 10007,10018 ----
        if (!node->needed)
        return *tp;
      }
+   else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL)
+     {
+       struct cgraph_node *node = cgraph_node (*tp);
+       if (!node->needed)
+         return *tp;
+     }

    return NULL_TREE;
  }

honza - does this look sane and can we maybe do this whole function in
graph ways?
Comment 2 Richard Biener 2007-04-04 12:46:18 UTC
Fixed on the mainline by

Author: hubicka
Date: Fri Mar 30 09:03:55 2007
New Revision: 123358

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123358
Log:
	PR middle-end/PR30700
	* dwarf2out.c (reference_to_unused): Ask cgraph for functions 
	availablility; add more sanity checking; ask varpool only about
	VAR_DECL.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
Comment 3 Jack Howarth 2007-04-11 15:05:20 UTC
I'm puzzled why the fix for this PR was checked into mainline instead of gcc 4.2 branch since only gcc 4.2 is marked as known to fail.
Comment 4 Martin Michlmayr 2007-04-12 07:24:12 UTC
If you click on "View Bug Activity" you'll see that the bug used to be marked
as 4.2/4.3.  Richi changed it to 4.2 only when the patch got committed to
mainline.
Comment 5 Jack Howarth 2007-04-12 17:58:17 UTC
Does that mean that the patch for mainline wouldn't work on gcc 4.2 branch or that the patch just hasn't been applied to gcc 4.2 branch yet?
Comment 6 Richard Biener 2007-04-12 22:41:30 UTC
The latter.
Comment 7 Jan Hubicka 2007-04-17 19:02:25 UTC
Subject: Bug 30700

Author: hubicka
Date: Tue Apr 17 19:02:09 2007
New Revision: 123922

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123922
Log:
	PR middle-end/30700
	* dwarf2out.c (reference_to_unused): Ask cgraph for functions
	availablility; add more sanity checking; ask varpool only about
	VAR_DECL.

Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/dwarf2out.c

Comment 8 Jan Hubicka 2007-04-17 19:04:56 UTC
Fixed.