Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Jan 2025 18:35:52 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 235751] Failure to init TLS variables with func ptr inside shared lib
Message-ID:  <bug-235751-227-caB1hyqtvf@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-235751-227@https.bugs.freebsd.org/bugzilla/>
References:  <bug-235751-227@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D235751

Dennis Clarke <dclarke@blastwave.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|powerpc                     |amd64
            Version|12.0-RELEASE                |14.2-RELEASE

--- Comment #6 from Dennis Clarke <dclarke@blastwave.org> ---
(In reply to Mark Linimon from comment #5)

Seems yes on AMD64 and also on IBM POWER9 ppc64le.

******************* tests **************************
[1] test on AMD64 with FreeBSD 14.2-RELEASE

hydra$ uname -apKU=20
FreeBSD hydra 14.2-RELEASE FreeBSD 14.2-RELEASE
releng/14.2-n269506-c8918d6c7412 GENERIC amd64 amd64 1402000 1402000
hydra$ freebsd-version -kru=20
14.2-RELEASE
14.2-RELEASE
14.2-RELEASE

hydra$ which cc
/usr/bin/cc
hydra$ CC=3D/usr/bin/cc
hydra$ export CC

hydra$ $CC --version
FreeBSD clang version 18.1.6 (https://github.com/llvm/llvm-project.git
llvmorg-18.1.6-0-g1118c2e05e67)
Target: x86_64-unknown-freebsd14.2
Thread model: posix
InstalledDir: /usr/bin

hydra$ $CC -std=3Diso9899:1999 -pedantic -pedantic-errors -m64 -g -O0
-fno-builtin -shared -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600 -D_REENTRANT -o t1.so -fPIC t1.c
hydra$ echo $?
0

hydra$ $CC -std=3Diso9899:1999 -pedantic -pedantic-errors -m64 -g -O0
-fno-builtin -shared -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600 -D_REENTRANT -o foo t2.c t1.so

hydra$ file foo
foo: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), dynamically
linked, for FreeBSD 14.2, with debug_info, not stripped

hydra$ readelf -delV foo | grep -E 'NEED|NAME|PATH'
 0x0000000000000001 NEEDED               Shared library: [t1.so]
 0x0000000000000001 NEEDED               Shared library: [libc.so.7]
 0x000000006ffffffe VERNEED              0x340
 0x000000006fffffff VERNEEDNUM           1
hydra$=20
hydra$ ./foo
Segmentation fault (core dumped)
hydra$=20
hydra$ LD_LIBRARY_PATH=3D`pwd` ./foo
Segmentation fault (core dumped)
hydra$=20


hydra$ TERM=3Ddumb LD_LIBRARY_PATH=3D`pwd` gdb ./foo
GNU gdb (GDB) 15.1 [GDB v15.1 for FreeBSD]
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.htm=
l>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd14.1".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./foo...
(gdb) run
Starting program: /home/dclarke/tls/foo=20

Program received signal SIGSEGV, Segmentation fault.
Invalid permissions for mapped object.
0x0000000001021000 in ?? ()
(gdb) where
#0  0x0000000001021000 in ?? ()
#1  0x0000000000000000 in ?? ()
(gdb) quit
A debugging session is active.

        Inferior 1 [process 14818] will be killed.

Quit anyway? (y or n) y

With or without the debugger we still get a SIGSEGV :

hydra$ TERM=3Ddumb LD_LIBRARY_PATH=3D`pwd` ./foo
Segmentation fault (core dumped)
hydra$=20


**************************************
[2] 15.0-CURRENT on AMD64 :=20

titan$ uname -apKU
FreeBSD titan 15.0-CURRENT FreeBSD 15.0-CURRENT #5 main-n274856-488660360a7=
1:
Sat Jan 18 17:03:26 GMT 2025=20=20=20=20
root@titan:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG amd64 amd64 150=
0030
1500030
titan$=20
titan$ CC=3D/usr/bin/cc
titan$ export CC
titan$=20
titan$ $CC --version
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git
llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd15.0
Thread model: posix
InstalledDir: /usr/bin
Build config: +assertions
titan$=20
titan$ $CC -std=3Diso9899:1999 -pedantic -pedantic-errors -m64 -g -O0
-fno-builtin -shared -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600 -D_REENTRANT -o t1.so -fPIC t1.c
titan$ $CC -std=3Diso9899:1999 -pedantic -pedantic-errors -m64 -g -O0
-fno-builtin -shared -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600 -D_REENTRANT -o foo t2.c t1.so
titan$=20
titan$ file foo
foo: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), dynamically
linked, for FreeBSD 15.0 (1500030), with debug_info, not stripped
titan$=20
titan$=20
titan$ readelf -delV foo | grep -E 'NEED|NAME|PATH'
 0x0000000000000001 NEEDED               Shared library: [t1.so]
 0x0000000000000001 NEEDED               Shared library: [libc.so.7]
 0x000000006ffffffe VERNEED              0x340
 0x000000006fffffff VERNEEDNUM           1
titan$=20
titan$ ./foo
Segmentation fault (core dumped)
titan$=20
titan$ LD_LIBRARY_PATH=3D`pwd` ./foo
Segmentation fault (core dumped)
titan$=20
titan$ TERM=3Ddumb LD_LIBRARY_PATH=3D`pwd` gdb ./foo
GNU gdb (GDB) 15.1 [GDB v15.1 for FreeBSD]
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.htm=
l>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd15.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./foo...
(gdb) run
Starting program: /home/dclarke/pgm/bw/in_progress/tls/foo=20

Program received signal SIGSEGV, Segmentation fault.
Invalid permissions for mapped object.
0x0000000001021000 in ?? ()
(gdb) where
#0  0x0000000001021000 in ?? ()
#1  0x0000000000000001 in ?? ()
#2  0x00007fffffffec70 in ?? ()
#3  0x0000000000000000 in ?? ()
(gdb) quit
A debugging session is active.

        Inferior 1 [process 5060] will be killed.

Quit anyway? (y or n) y
titan$=20

***********************************************************
[3] 14.2-RELEASE FreeBSD on powerpc64le

scotty$=20
scotty$ uname -apKU
FreeBSD scotty 14.2-RELEASE FreeBSD 14.2-RELEASE
releng/14.2-n269506-c8918d6c7412 GENERIC powerpc powerpc64le 1402000 1402000
scotty$=20
scotty$ sysctl hw.model
hw.model: IBM POWER9
scotty$=20
scotty$ CC=3D/usr/bin/cc
scotty$ export CC
scotty$=20
scotty$ $CC --version
FreeBSD clang version 18.1.6 (https://github.com/llvm/llvm-project.git
llvmorg-18.1.6-0-g1118c2e05e67)
Target: powerpc64le-unknown-freebsd14.2
Thread model: posix
InstalledDir: /usr/bin
scotty$=20
scotty$ $CC -std=3Diso9899:1999 -pedantic -pedantic-errors -m64 -g -O0
-fno-builtin -shared -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600 -D_REENTRANT -o t1.so -fPIC t1.c
scotty$ $CC -std=3Diso9899:1999 -pedantic -pedantic-errors -m64 -g -O0
-fno-builtin -shared -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600 -D_REENTRANT -o foo t2.c t1.so
scotty$ file foo
foo: ELF 64-bit LSB shared object, 64-bit PowerPC or cisco 7500, OpenPOWER =
ELF
V2 ABI, version 1 (FreeBSD), dynamically linked, for FreeBSD 14.2, with
debug_info, not stripped
scotty$=20
scotty$ readelf -delV foo | grep -E 'NEED|NAME|PATH'
 0x0000000000000001 NEEDED               Shared library: [t1.so]
 0x0000000000000001 NEEDED               Shared library: [libc.so.7]
 0x000000006ffffffe VERNEED              0x340
 0x000000006fffffff VERNEEDNUM           1
scotty$=20
scotty$ ./foo
Segmentation fault (core dumped)
scotty$=20


***********************************************
      other systems and compiler tools
***********************************************


For the sake of a comparison I will change the return value to 42 and
do the same test on a Solaris 10 SPARCv9 Fujitsu server using an entirely
different set of tools :=20


hubble $ uname -a=20
SunOS hubble 5.10 Generic_150400-67 sun4u sparc SUNW,SPARC-Enterprise
hubble $=20
hubble $ echo $CC
/opt/developerstudio12.6/bin/cc
hubble $=20
hubble $ $CC -V
cc: Studio 12.6 Sun C 5.15 SunOS_sparc 2017/05/30
hubble $=20
hubble $ cat t2.c


/* as seen at
 * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D235751
 */

struct s_t {
    int (*func)(int);
};

extern struct s_t __thread x;

int main(int argc, const char *argv[]) {
    return (*x.func)(argc+41);
}

hubble $=20
hubble $ echo $CFLAGS
-m64 -xarch=3Dsparc -g -xO0 -mc -xs -errfmt=3Derror -erroff=3D%none -errsho=
rt=3Dfull
-errtags=3Dyes -errwarn=3D%none -ftrap=3D%none -xbuiltin=3D%none -xildoff -=
xlibmieee
-xstrconst -xcode=3Dpic32 -xmemalign=3D8s -xnolibmil -xunroll=3D1 -xdepend
-xregs=3Dno%appl -xdebugformat=3Ddwarf
hubble $=20
hubble $ echo $CPPFLAGS
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64 -D_XOPEN_SOURCE=3D600
-D_POSIX_PTHREAD_SEMANTICS -D_TS_ERRNO
hubble $=20
hubble $ $CC $CFLAGS -G $CPPFLAGS -D_REENTRANT -o t1.so -h t1.so t1.c
hubble $ file t1.so
t1.so: ELF 64-bit MSB dynamic lib SPARCV9 Version 1, dynamically linked, not
stripped
hubble $=20
hubble $ $CC $CFLAGS $CPPFLAGS -D_REENTRANT -o foo t2.c t1.so
hubble $=20
hubble $ elfdump -delv foo | grep -E 'NEED|NAME|PATH'
       [0]  NEEDED            0xe3                t1.so
       [1]  NEEDED            0xd0                libc.so.1
       [4]  RUNPATH           0xe9                /opt/bw/lib
       [5]  RPATH             0xe9                /opt/bw/lib
      [12]  VERNEED           0x1000007a8=20=20=20=20=20=20=20=20=20
      [13]  VERNEEDNUM        0x1=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20
hubble $=20
hubble $ ldd foo
        t1.so =3D>         (file not found)
        libc.so.1 =3D>     /lib/64/libc.so.1
        libm.so.2 =3D>     /lib/64/libm.so.2
        /lib/sparcv9/../libm/sparcv9/libm_hwcap1.so.2
        /platform/SUNW,SPARC-Enterprise/lib/sparcv9/libc_psr.so.1
hubble $=20
hubble $ LD_LIBRARY_PATH=3D`pwd` ./foo
hubble $ echo $?
42
hubble $=20

So that seems to work there.

Here is an IBM POWER9 server with the IBM XLC compiler :=20

dax$ uname -a=20
Linux dax 6.1.118-mrw1 #1 SMP Sun Nov 17 22:40:36 PST 2024 ppc64le GNU/Linux
dax$=20
dax$ CC=3D/opt/ibm/xlC/16.1.1/bin/xlc
dax$ export CC
dax$=20
dax$ CFLAGS=3D'-qlanglvl=3Dstdc99 -O0 -g'
dax$ export CFLAGS
dax$=20
dax$ CPPFLAGS=3D'-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=3D64
-D_XOPEN_SOURCE=3D600'
dax$ export CPPFLAGS
dax$=20
dax$ $CC $CFLAGS $CPPFLAGS -D_REENTRANT -shared -fPIC -o t1.so t1.c
dax$ file t1.so=20
t1.so: ELF 64-bit LSB shared object, 64-bit PowerPC or cisco 7500, OpenPOWER
ELF V2 ABI, version 1 (SYSV), dynamically linked, with debug_info, not stri=
pped
dax$=20
dax$ $CC $CFLAGS $CPPFLAGS -D_REENTRANT -o foo t2.c t1.so=20
dax$ ldd foo
        linux-vdso64.so.1 (0x00007fff83650000)
        t1.so =3D> not found
        libgcc_s.so.1 =3D> /lib/powerpc64le-linux-gnu/libgcc_s.so.1
(0x00007fff835e0000)
        libm.so.6 =3D> /lib/powerpc64le-linux-gnu/libm.so.6 (0x00007fff834b=
0000)
        libc.so.6 =3D> /lib/powerpc64le-linux-gnu/libc.so.6 (0x00007fff8320=
0000)
        /lib64/ld64.so.2 (0x00007fff83660000)
dax$=20
dax$ LD_LIBRARY_PATH=3D`pwd` ./foo
dax$ echo $?
42
dax$=20

I have not bothered to look on RISC-V yet.


--=20
--
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-235751-227-caB1hyqtvf>