delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/02/11/16:06:24

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 51BL6Nxd492261
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 51BL6Nxd492261
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=jAY8vkHp
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03E313858C35
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1739307983;
bh=nk5ph+g9ZdWHUKSfRQPEc2z+Zk07FZItptLKU67ljBo=;
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=jAY8vkHpaFiyn66k3j7SsjDK5fDP4qnOVNnDJfTh+YuBjDgxls5+56ihXJA6Z+XiG
6p4Odz3ISQbhe+n8OpjkOchXzCcN/NaHfOgneBITa/XVYYwjjp51Ku/X3BbjaCeGzh
d4UdRkDeuTUGpclktj10rSW4j+kQbCWBRVP6gRbU=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2745C3858D33
Date: Tue, 11 Feb 2025 22:03:48 +0100
To: cygwin AT cygwin DOT com
Subject: Re: __builtin_thread_pointer
Message-ID: <Z6u7NInSWeS2UtHP@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <9c6a1ccc-d2fb-4aaf-b8c2-29574fa640b4 AT cornell DOT edu>
<D47E777E-C732-47BD-81C8-5A488E38E1F3 AT unified-streaming DOT com>
MIME-Version: 1.0
In-Reply-To: <D47E777E-C732-47BD-81C8-5A488E38E1F3@unified-streaming.com>
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

On Feb 11 20:41, Dimitry Andric via Cygwin wrote:
> It's a gcc builtin function, not something implemented in an external library. Therefore, there is no linker option that can fix this.
> 
> Also, as far as I can see from gcc's documentation, __builtin_thread_pointer() is only supported for the RISCV and SH architectures. Then again, gcc's implementation seems to hinge this on whether the platform supports TLS or not.
> 
> In any case, it is probably better to not use this function if your gcc does not support it.
> 
> -Dimitry

Nice answer!

It's also not entirely clear what __builtin_thread_pointer is supposed
to return.  On some architectures, there's a register dedicated to point
to thread local storage (Risc-V, SH), on some architectures it's a
specific assembler call (Alpha).

There's no such predefined set of registers or assembler instructions on
x86_64.  The Windows ABI defines the GS register as the register
pointing to the TEB (Thread Environment Block), but that's not exactly
the same thing as TLS.  The TLS is another datastructure inside the TEB.
And Cygwin has it's own internal TLS area called cygtls, which resides
on the stack.

All in all, the fact that __builtin_thread_pointer is only defined on
*some* architectures supports what Dimitry already pointed out:

  It is probably better to not use this function.

Ken, check the source or configury of your package.  It looks weird that
this function should be called architecture-independently.


Corinna


> 
> > On 11 Feb 2025, at 20:26, Ken Brown via Cygwin <cygwin AT cygwin DOT com> wrote:
> > 
> > Does Cygwin support __builtin_thread_pointer?  I'm guessing not, because I'm getting a link error (undefined reference to `__builtin_thread_pointer') when I try to build some software that uses it.  Or is there something that would have to be added to the link command line?  The full command line and error message are quoted below, in case anyone spots something obvious.
> > 
> > Ken
> > 
> > [242/242] Linking C executable luametatex.exe
> > FAILED: luametatex.exe
> > : && /usr/bin/gcc.exe -ggdb -O2 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=3 -fstack-protector-strong --param=ssp-buffer-size=4 -ffile-prefix-map=/home/kbrown/src/cygluametatex/luametatex-2.11.05-1.x86_64/build=/usr/src/debug/luametatex-2.11.05-1 -ffile-prefix-map=/home/kbrown/src/cygluametatex/luametatex-2.11.05-1.x86_64/src/luametatex=/usr/src/debug/luametatex-2.11.05-1 -O2 -g -DNDEBUG -s CMakeFiles/luametatex.dir/source/luametatex.c.o -o luametatex.exe -Wl,--out-implib,libluametatex.dll.a -Wl,--major-image-version,0,--minor-image-version,0  libtex.a  liblua.a libmp.a  libluarest.a  libluasocket.a  libluaoptional.a  libpplib.a libminiz.a  libsoftposit.a  libpotrace.a  -ldl  libmimalloc.a  -lpthread  -lm && /bin/sh CMakeFiles/luametatex.dir/post-build.sh 7847d1a259c666c4
> > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: libmimalloc.a(alloc.c.o): in function `_mi_prim_thread_id':
> > /usr/src/debug/luametatex-2.11.05-1/source/libraries/mimalloc/include/mimalloc/prim.h:251:(.text+0x187): undefined reference to `__builtin_thread_pointer'
> > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: /usr/src/debug/luametatex-2.11.05-1/source/libraries/mimalloc/include/mimalloc/prim.h:251:(.text+0x437): undefined reference to `__builtin_thread_pointer'
> > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: /usr/src/debug/luametatex-2.11.05-1/source/libraries/mimalloc/include/mimalloc/prim.h:251:(.text+0x4e7): undefined reference to `__builtin_thread_pointer'
> > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: libmimalloc.a(alloc.c.o):/usr/src/debug/luametatex-2.11.05-1/source/libraries/mimalloc/src/free.c:340:(.text+0x597): undefined reference to `__builtin_thread_pointer'
> > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: libmimalloc.a(init.c.o): in function `_mi_prim_thread_id':
> > /usr/src/debug/luametatex-2.11.05-1/source/libraries/mimalloc/include/mimalloc/prim.h:251:(.text+0xd1): undefined reference to `__builtin_thread_pointer'
> > /usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: libmimalloc.a(init.c.o):/usr/src/debug/luametatex-2.11.05-1/source/libraries/mimalloc/include/mimalloc/prim.h:251: more undefined references to `__builtin_thread_pointer' follow
> > collect2: error: ld returned 1 exit status
> > 
> > -- 
> > Problem reports:      https://cygwin.com/problems.html
> > FAQ:                  https://cygwin.com/faq/
> > Documentation:        https://cygwin.com/docs.html
> > Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
> 
> 
> -- 
> Problem reports:      https://cygwin.com/problems.html
> FAQ:                  https://cygwin.com/faq/
> Documentation:        https://cygwin.com/docs.html
> Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019