https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91005
Bug ID: 91005 Summary: Cannot put a nested function into a different section Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pipcet at gmail dot com Target Milestone: --- Created attachment 46523 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46523&action=edit 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.