🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #6582

Bug#1155668: gcc-16: hppa: OpenMP child of inlined hot COMDAT function gets wrong section/group

#6582
From: Barak A. Pearlmutter
Date: Sat, 28 Nov 2026 17:20
91 lines
5965 bytes
Package: gcc-16
Version: 16.2.0-5
Tags: upstream
User: debian-hppa@lists.debian.org
Usertags: hppa
X-Debbugs-Cc: debian-hppa@lists.debian.org

On hppa, when a function marked __attribute__((hot)) that is COMDAT
(e.g., an inline template) contains an OpenMP parallel region, and
every call to it is inlined so that the function itself is never
emitted, the outlined OpenMP child function is placed in the shared
".text.hot" section tagged with the *parent's* COMDAT group. GCC keys
named sections by name, so whichever decl first creates ".text.hot"
determines the group, and:

 (a) any other hot function (non-COMDAT, or with a different COMDAT
     group) that later needs ".text.hot" triggers a hard error,
     "section type conflict"; and

 (b) even without an error, OpenMP children of other instantiations
     are silently emitted into the first instantiation's COMDAT group,
     so the linker can discard them together with an unrelated group
     (wrong code).

amd64 compiles the same code correctly (children go in a plain
".text.hot" with no group). g++-15 15.3.0-6 on hppa behaves the same
way, so this is not a GCC 16 regression.

This is valid code, and it occurs in practice: Armadillo's
element-wise kernels (arma::eop_core<>::apply) are marked hot and
contain "#pragma omp parallel for" when compiled with -fopenmp. It
currently makes ensmallen FTBFS on hppa:
https://buildd.debian.org/status/logs.php?pkg=ensmallen&arch=hppa and
presumably affects other Armadillo users built with OpenMP.

Reproducer (tested on panama.debian.net, sid, g++ 16.2.0-5):

---- pr.cpp ----
template<typename T> __attribute__((hot)) inline void scale(T* o, int n)
{
#pragma omp parallel for
  for (int i = 0; i < n; ++i) o[i] *= 3;
}
void f(float* o, int n)  { scale(o, n); }   // scale<float> inlined, not emitted
void d(double* o, int n) { scale(o, n); }   // scale<double> inlined,
not emitted

__attribute__((hot)) void g(double* o, int n)  // ordinary hot function
{
#pragma omp parallel for
  for (int i = 0; i < n; ++i) o[i] *= 2;
}
----------------

$ g++ -O2 -fopenmp -c pr.cpp
pr.cpp: In function '_Z1gPdi._omp_fn.0':
pr.cpp:11:27: error: 'void g(double*, int)' causes a section type
conflict with 'void scale(T*, int) [with T = float]' in section
'.text.hot'
pr.cpp:3:55: note: 'void scale(T*, int) [with T = float]' was declared here

With g() deleted it compiles, but the assembly shows the double
instantiation's child in the float instantiation's group:

.section .text.hot,"axG",@progbits,_Z5scaleIfEvPT_i,comdat
_Z5scaleIfEvPT_i._omp_fn.0:
.section .text.hot,"axG",@progbits,_Z5scaleIfEvPT_i,comdat
_Z5scaleIdEvPT_i._omp_fn.0:

If scale() is made noinline, so the parent is emitted, everything is
correct (each function, child included, gets its own
.text.hot.<name> section in the right group).  -fno-reorder-functions
avoids the problem.

Likely cause: pa_function_section() in gcc/config/pa/pa.cc forces
"nested" functions into the section of their DECL_CONTEXT:

  if (decl
      && DECL_SECTION_NAME (decl) == NULL
      && DECL_CONTEXT (decl) != NULL_TREE
      && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
      && DECL_SECTION_NAME (DECL_CONTEXT (decl)) == NULL)
    return function_section (DECL_CONTEXT (decl));

An OpenMP outlined child has the parent as DECL_CONTEXT. When the
parent is never emitted it has no unique section, so
function_section(parent) falls through to default_function_section,
which returns get_named_text_section(parent, ".text.hot", NULL): the
shared ".text.hot" section carrying the parent's COMDAT group. Perhaps
this hook should skip DECL_COMDAT parents (or ones without an assigned
section), or the child should get its own section as on other targets.
Technical Details
Message-ID: <O4ufD-eI5I-5@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: "Barak A. Pearlmutter" <barak@cs.nuim.ie>
Newsgroups: linux.debian.bugs.dist,linux.debian.ports.hppa
Subject: Bug#1155668: gcc-16: hppa: OpenMP child of inlined hot COMDAT function gets wrong section/group
Date: Sat, 28 Nov 2026 18:20:01 +0100
Message-ID: <O4ufD-eI5I-5@gated-at.bofh.it>
X-Original-To: Debian Bug Tracking System <submit@bugs.debian.org>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Sat Nov 28 17:19:08 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: -1.451
Reply-To: "Barak A. Pearlmutter" <barak@cs.nuim.ie>, 1155668@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: debian-hppa@lists.debian.org, debian-gcc@lists.debian.org
X-Debian-Pr-Message: report 1155668
X-Debian-Pr-Package: gcc-16
X-Debian-Pr-Keywords: upstream
X-Debian-Pr-Source: gcc-16
X-Gm-Message-State: APuU4Z/2qwQfqGUhpRxO9MRDq3NdWflEhyK7lSIMAAgIJYnrczA8iXcD
	pIvUJ7+qA9+K+I71Tz52HyE2zBkl8WQ+hw60I5m2KE2HQI7ZeFUzSXPM7AQWYJEmYAqIoj3YI+d
	Hvs/XE5ZezKJbcoXmsxHxgTQHGvw8j+g=
X-Received: by 2002:a05:620a:8389:b0:942:a42a:78a2 with SMTP id
 af79cd13be357-949ba9ffe27mr5178068385a.31.1795886291664; Sat, 28 Nov 2026
 09:18:11 -0800 (PST)
MIME-Version: 1.0
X-Gmail-Original-Message-ID: <CANa01BLizNCvM-dvNx40gsVGkBoBxYKArsS4RVon6YBVOqGDcA@mail.gmail.com>
X-Gm-Features: Aa3M54o_ZS_HWAgWTiFNeA9UxaPwGI1K4KJI_bu5XWResTrJPvVb0SaGcs_Ny8g
Content-Type: text/plain; charset="UTF-8"
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2005652
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 91
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Sat, 28 Nov 2026 17:17:59 +0000
X-Original-Message-ID: <CANa01BLizNCvM-dvNx40gsVGkBoBxYKArsS4RVon6YBVOqGDcA@mail.gmail.com>