Bug 91005 - Cannot put a nested function into a different section
Summary: Cannot put a nested function into a different section
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure, wrong-code
Depends on:
Blocks:
 
Reported: 2019-06-26 16:34 UTC by pipcet
Modified: 2024-03-14 23:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 8.3.0
Last reconfirmed: 2024-03-14 00:00:00


Attachments
test case (105 bytes, text/plain)
2019-06-26 16:34 UTC, pipcet
Details
illustrative patch (984 bytes, patch)
2019-06-26 16:35 UTC, pipcet
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pipcet 2019-06-26 16:34:16 UTC
Created attachment 46523 [details]
test case

Compiling the attached file fails:

/usr/bin/ld: /tmp/ccuSWyMB.o: in function `main':
inner-section.c:(.text+0x5): undefined reference to `inner.1911'
collect2: error: ld returned 1 exit status

I've looked into the problem a little, and it seems that the C frontend sets DECL_CONTEXT only after the section attribute is handled, so this code

  if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
    {
      node->origin = cgraph_node::get_create (DECL_CONTEXT (decl));
      node->next_nested = node->origin->nested;
      node->origin->nested = node;
    }

in cgraph.c is run early, when DECL_CONTEXT isn't yet set, so the function is never added to the nested list.

I might be wrong, though.

The attached patch seems to fix this specific example on this specific machine, but I'm almost certain it'll turn out to be wrong somehow.
Comment 1 pipcet 2019-06-26 16:35:06 UTC
Created attachment 46524 [details]
illustrative patch
Comment 2 Richard Biener 2019-06-27 07:50:53 UTC
Confirmed.