#760211 on some archs, a library using Task_Attributes needs -lpthread

Package:
gnat-12
Source:
gcc-12
Description:
GNU Ada compiler
Submitter:
Nicolas Boulenguez
Date:
2022-04-04 05:33:32 UTC
Severity:
normal
#760211#5
Date:
2014-09-01 21:30:01 UTC
From:
To:
On armel armhf hurd-i386 kfreebsd-amd64 s390x, the following scenario
complains about the "pthread_getspecific" symbol being undefined.
Adding "-lpthread" to library_options (used at the end of the link
command) fixes the problem, but gnat should not expect the end user to
know that inlining adds a dependency.

mkdir lib
cat > pack.ads <<EOF
with Ada.Task_Attributes;
package Pack is new Ada.Task_Attributes (Integer, 0);
EOF
cat > pack.gpr <<EOF
library project Proj is
   for Library_Name    use "pack";
   for Library_Version use "libpack.so.1";
   for Source_Dirs     use (".");
   for Library_Dir     use "lib";
   for Library_Kind    use "dynamic";
   for Library_Options use ("-Wl,-z,defs"); -- Fail on undefined symbols.
   package Compiler is
      for Switches ("Ada") use ("-O1", "-gnatn");
   end Compiler;
end Proj;
EOF
gnatmake -v -Ppack.gpr

For the record, here are two sensible work-arounds:
* in linker options:
  -Wl,--as-needed -lpthread -Wl,--no-as-needed
* in a GNAT project:
  case External ("NEEDS_PTHREAD") is
      when "yes" =>
         for Library_Options use project'library_options & ("-lpthread");
      when "no" =>
         null;
  end case;

Checked on zelenka.debian.org (s390x).
Most probably related to #717014.

#760211#10
Date:
2015-10-04 10:42:46 UTC
From:
To:
Confirmed on kfreebsd-amd64.
#760211#49
Date:
2019-07-17 12:35:07 UTC
From:
To:
Checked on armel.
Gnatmake does not support projects anymore, a new reproducer follows.

BV=9
# Reproducer for 717014
echo 'with Ada.Numerics.Generic_Elementary_Functions;' > a.ads
echo 'package A is new Ada.Numerics.Generic_Elementary_Functions (Float);' >> a.ads
gcc-$BV -fPIC -c a.ads
gcc-$BV -shared -Wl,-soname,liba.so.1 -o liba.so.1 -Wl,-z,defs a.o -lgnarl-$BV -lgnat-$BV
# Reproducer for 760211
echo 'with Ada.Task_Attributes;' > b.ads
echo 'package B is new Ada.Task_Attributes (Integer, 0);' >> b.ads
gcc-$BV -fPIC -c b.ads -O1 -gnatn
gcc-$BV -shared -Wl,-soname,libb.so.1 -o libb.so.1 -Wl,-z,defs b.o -lgnarl-$BV -lgnat-$BV

#760211#60
Date:
2020-09-27 12:32:12 UTC
From:
To:
Reproduced on armel.