www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/02/12/11:44:41

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 51CGifYT835204
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 51CGifYT835204
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=MPFm61S2
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4F1F385840E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1739378680;
bh=YfJRqhZ3W5mbTB2/HIyPQMNmzjtI8tTe1oszcmZedwA=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=MPFm61S2nZBPVUjb+GMGkSG0Y4ub++3VzAVPCKxz7b9Xumk/zZQ3RWqjPtkASzN+l
pRYqXR2AIFXt1ehYvsZgtk46g0AsRWXWuzgbIfz+BBd7B0S4FhjyPOMDpfDrYKnwop
3YUBKvQHEyTHCnTc1Zk7AMMReiyrx2JqrTIGr2AE=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CCDB3858403
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0CCDB3858403
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739378652; cv=none;
b=u/IeIe6D3w9EU+Vdf+xa+rKyB428O0XxMVE0zS60L19XWn2HjN2WOU2Q9vIFVh4u/V17iZZlGUwUxXaO3K7Wg3jc14gfzObf/6U5Dsdxg08xvu8Q/zaCtoD0cPlXBwagx+M/2Vjk5Ppe/sd5hwqlUY2oswzJytkrE38gYzzpSTs=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1739378652; c=relaxed/simple;
bh=9HRF7bgKALIi2jecOeWAk8l7N86WQfxUOtFWqeBxvhc=;
h=Message-ID:Date:MIME-Version:From:Subject:To:DKIM-Signature;
b=phndwwWVIB0ZwNFqZvnKRx2jtRnVt4G+8vVdscywmQtHhL9QgruTnasy7EjHI7sc/a6vx6OrssdGpXUguL+NpTHxogTVFUr4+wc5Li5GAoeNgdQyM1eJ2evaz7WFR5Q66JZygPtB0TxwE4aFZpjYK6EuTIlpP1dNJwomj1JMDA4=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0CCDB3858403
Message-ID: <a8a2d1b7-b006-4396-87bd-239680207901@SystematicSW.ab.ca>
Date: Wed, 12 Feb 2025 09:44:03 -0700
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: __builtin_thread_pointer
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>
<6faedefc-eb17-4b02-89b9-44b73e82d43f AT SystematicSW DOT ab DOT ca>
<0252F948-10C3-4B9E-943D-ACA35E190726 AT unified-streaming DOT com>
<87935cbb-4a43-4ebd-b8cb-125ecfcbcdc3 AT SystematicSW DOT ab DOT ca>
<BE17AA1A-EA85-40C9-AE04-46E689B27FF8 AT unified-streaming DOT com>
Autocrypt: addr=Brian DOT Inglis AT SystematicSW DOT ab DOT ca; keydata=
xjMEXopx8xYJKwYBBAHaRw8BAQdAnCK0qv/xwUCCZQoA9BHRYpstERrspfT0NkUWQVuoePbN
LkJyaWFuIEluZ2xpcyA8QnJpYW4uSW5nbGlzQFN5c3RlbWF0aWNTdy5hYi5jYT7ClgQTFggA
PhYhBMM5/lbU970GBS2bZB62lxu92I8YBQJeinHzAhsDBQkJZgGABQsJCAcCBhUKCQgLAgQW
AgMBAh4BAheAAAoJEB62lxu92I8Y0ioBAI8xrggNxziAVmr+Xm6nnyjoujMqWcq3oEhlYGAO
WacZAQDFtdDx2koSVSoOmfaOyRTbIWSf9/Cjai29060fsmdsDM44BF6KcfMSCisGAQQBl1UB
BQEBB0Awv8kHI2PaEgViDqzbnoe8B9KMHoBZLS92HdC7ZPh8HQMBCAfCfgQYFggAJhYhBMM5
/lbU970GBS2bZB62lxu92I8YBQJeinHzAhsMBQkJZgGAAAoJEB62lxu92I8YZwUBAJw/74rF
IyaSsGI7ewCdCy88Lce/kdwX7zGwid+f8NZ3AQC/ezTFFi5obXnyMxZJN464nPXiggtT9gN5
RSyTY8X+AQ==
Organization: Systematic Software
In-Reply-To: <BE17AA1A-EA85-40C9-AE04-46E689B27FF8@unified-streaming.com>
X-Stat-Signature: xobnngae3uj7775mx4oenriby9o3f31h
X-Rspamd-Server: rspamout01
X-Rspamd-Queue-Id: 989063E
X-Session-Marker: 427269616E2E496E676C69734053797374656D6174696353572E61622E6361
X-Session-ID: U2FsdGVkX18sB4zdoAKx0TvP78wUeiW1wqeElxTtQJo=
X-HE-Tag: 1739378644-149797
X-HE-Meta: U2FsdGVkX1+1tZzkL/yzZrEorttDis8nqW3nmMYwlX/yzPWY/dgoD9p3GZCKxzPecQ+OksERsylF34Ev6z82hliJ+WZw7JLS1YW9JCbn2gHceWNag0f8xV3QHyT1d+NJUpX8co9NB2vnhqhwNdA2hS6xdzhq6+rK9x+YkqHUVCy+6jwQSYZGU1f76VwppJP1YT38VIU3eFDQ3+VbbICQe58XcFgmnktk1aZkkL3L+r6O2kinhoGwvR3HaMTl57JKX5noCA+OIuQCPtXHwbrb4514k04QvEunM/KJjfRd9t+JqPAydYUi9fV4jXGeEb7MCNFFvXqLoGrYZEHgtB3OM3hlQTaS0bPbw7MlZr7B0RgXgIYsYtw2vPQCHd9PxxeCLV2AZ5sLyS5ahbuGWHrLIkKM5nfkrXtlN3sB5I+sw1f4euNQZIjde/mUXFCyS2DkTQhkD+iySEvLmU4hfMTM3w==
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: Brian Inglis via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Brian Inglis <Brian DOT Inglis AT SystematicSW DOT ab DOT ca>
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>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 51CGifYT835204

On 2025-02-11 15:52, Dimitry Andric via Cygwin wrote:
> On 11 Feb 2025, at 23:25, Brian Inglis <Brian DOT Inglis AT SystematicSW DOT ab DOT ca> wrote:
>>
>> On 2025-02-11 13:58, Dimitry Andric wrote:
>>>> On 11 Feb 2025, at 21:45, Brian Inglis via Cygwin wrote:
>>>> On 2025-02-11 12:41, Dimitry Andric via Cygwin wrote:
>>>>>> On 11 Feb 2025, at 20:26, Ken Brown via Cygwin 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.
>>>>
>>>>> 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.
>>>> Does `info gcc tls` help and do we know if that is supported by our gcc(s)?
>>
>>> It does not look like it's supported by Cygwin's gcc:
>>> $ gcc -v
>>> Using built-in specs.
>>> COLLECT_GCC=gcc
>>> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/12/lto-wrapper.exe
>>> Target: x86_64-pc-cygwin
>>> Configured with: /mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-12.4.0/configure --srcdir=/mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-12.4.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --with-gcc-major-version-only --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --enable-clocale=newlib --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++,jit --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --disable-multilib --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix
>    --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
>>> Thread model: posix
>>> Supported LTO compression algorithms: zlib zstd
>>> gcc version 12.4.0 (GCC)
>>
>>> On Ubuntu 24.04 this program compiles without warnings.
>>
>> On which platform - RISCV or SH?
> 
> Sorry, I forgot to mention that: just plain old x86_64. I think the Ubuntu package build will have detected TLS support during its configure phase.
> 
>>
>>> It looks like the gcc configure script checks for TLS here: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/configure.ac;h=8fab93c9365496062583c5bd8ace402c8a797817;hb=HEAD#l3846, by running some code through the assembler. I would guess that doesn't work on Cygwin.
>>
>> It should as gas supports storage class 'T' for thread, and GCC supports and uses posix threads.
> 
> I tried to find Cygwin gcc build logs on https://cygwin.com/cgi-bin2/jobs.cgi?srcpkg=gcc&status=&user=, but that comes up with only "not built" builds, or failed builds. If somebody knows a URL where the configure output can be found, it might shed some more light.
> 
> 
>> This compiles just fine under Cygwin:
>>
>> /* test-thread-storage.c */
>> int f(int *np, char *cp)
>> {
>>   static __thread int  n;
>>   static __thread char *p;
>>   int i;
>>
>>   n = *np;
>>   p = cp;
>>
>>   for (i = 0; i < n; ++i)
>>       *cp++ = *p++;
>>
>>   return i;
>> }
>>
>> Cygwin and GCC support POSIX threads, and they are used in many Cygwin packages, this may just work!
>>
>> Cygwin could define its own builtin_thread_pointer() to access its own cygtls areas from GCC, and if they are defined using storage class 'T', it should work.
>> It is not clear if this is just intended as an optimization for a few embedded targets that have a dedicated pointer register for tls.
> 
> Yes, that is the RISCV or SH specific method. On x86_64, you access it via the fs register, i.e. gcc (on Linux at least :) compiles:
> 
>    void *p = __builtin_thread_pointer();
> 
> to something like:
> 
>    	movq	%fs:0, %rax
> 	movq	%rax, -8(%rbp)
> 
> If somebody knows how to build the Cygwin gcc package from scratch, they could inspect the config.log file, to see what that says about TLS detection.

The config test you pointed to appears to generate a gas program using storage 
class 'T' accessing fields via GS: this may work unless it depends on files 
available only on certain platforms and not on Cygwin, but it shows awareness of 
newlib configs, so it seems it could work.

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

-- 
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