DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 51BMs3LB528100 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 51BMs3LB528100 Authentication-Results: delorie.com; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=shhaLyX7 X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57EB6385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1739314441; bh=nqMhgd3zM64YwjR+yPy1nEHpX3khiaxeCL8CGpCL2Q0=; h=Subject:Date:References:To:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=shhaLyX7Qq/aDQUKjHfd2ExOxpgug4eIblyyWOKlVIyyC4cxGtYAXoconKWEJRNtC lP6V3IKRp0EI+d/xoN2aYlwf5ITmUzp43L0YWHAga/0j5MdceqCPmAsPg44HqnTm0T h3Ghs7gbxsjt/eoasFslhqCgYR1Gn7uTtAn3uRyU= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EC343858D33 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7EC343858D33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739314381; cv=none; b=qv+BcCGd88vJqFoCs3eI/226bqcWuNNds52G18jKTlA8K1XJ+ZaiYC7gkNMYg1ZEOgdoIdvEkHLIk05jExwsec+a+4TnsKr45GORK1Sx94P9KEYBP8nJI5Rp6pkc8ARLBvjhoeEolqyQDkIsdYwBvasUS6UiN8a20UwBB8xE6HI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739314381; c=relaxed/simple; bh=QcG0N4mMSeVOHVyVlmcDy0pI3+l++CsRpyCXfRkIULk=; h=DKIM-Signature:From:Mime-Version:Subject:Date:To:Message-Id; b=woUVUFw33piSWI8Weta2i+Ym1CCwHlTWOGc/tw0ALJRNl5Gr/jyg0hgPS4V+kW0PyyMCsYOC6XFb8Jik4/8WLwPm+sLhsJa0sMnQvAQofwHU9im4y6XeC7wKy3qglJIC7Bf7YtVcaZO616LUB5GHqGUWAfts9bd2C0FrTR6Xu8Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EC343858D33 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739314379; x=1739919179; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zs0gjZ2HxE8jsmCzxjU06gQ9xeImgQWGWiCumJVxSf8=; b=tHMP82y5yehCXavqmFoSvrLzSEzUuzS8Ig/h95a67d9VEplxU4b0QH76ZVOCSSAjRP vsXdfl6NwVJPAOHmS2tyg5vFz6Dd4f0I4q4Rmo4nuUmBiDz4daEWpgdCcKbJS+FHb17/ Wd7uPMyG4WZ6g2c88SNGmYxvfsQ8EGsEYoTwwx78EfZOCsul0a99S2DqhWrQgNG40Yya j6etB6xZq4YNdZvjy68R4JdEZF1RDTxd27c13NHYc+z1qaHDrYQaAXePpc4jgFT+7LRQ o9bdUHC4A8dcZtL+fiuf2qawOOZS7Lkb1W4CS8uQDhiGJsQwnsgk+dqoAphRs3elk+o1 j4wg== X-Gm-Message-State: AOJu0Yys6kAIeYs12z1cM64Ek8dLX8hPJGT1YN9Vhk63I6qgfiXGTSAh VmIFcGSTj94ZiX85/3Lslun+vIYBoF2xQmxDB31hB+5k4/xdONtEzIUq/vmz6FkiADjpKt8OTTs Ds69/VTgOsol1dT100WJg9uP4/vQ1k9I+KTBTMurCNmlcV4LdyR+noZrdmsE3wnIUkoabOiAvmL zZ3S77sKh6CMPsEy8Gv6j7XQF+3bcUsuRjnG+Xh8PFJ5U= X-Gm-Gg: ASbGncvOqvxWYuHUeLIK4XGX8NS+w7aNQpkBCm3YckSHuHzRT0XxrUBCwxHc5iImKRD AzLqOAg9cGoy+4XVPrHnX33iQnv1heT08jUF9k/j3Sb1P2NZ5U/IYC6bBQmsfV2DKzWbUzCxN1R JQy8jFA/de0nQ51wHirIWfRjkZWj5xgQPLmjG+i5ae6ifx2Fdnsidh5ciUuWduu941e0QC5rPaC Jwo4AQbRLmz+wrqcxnKel4pEnNvtzBiLYCiDIFB8ity7nPz/w43zQ+nQi/Cz6LW08PTydsrV/wk wvCo4arF7QFQOO69JAqmg+zLGX5lllXtLeUHXNuvCIat2VPEntygcZXiiYk= X-Google-Smtp-Source: AGHT+IHu2IRui84IouUBQKCxyCLJoQufkBpag+cJATFhw5y+wVhJxI/ly02PMcO+eUGpa5DP1x/oSA== X-Received: by 2002:a05:6402:2106:b0:5d9:a85:1a59 with SMTP id 4fb4d7f45d1cf-5deade09ecemr826306a12.27.1739314378628; Tue, 11 Feb 2025 14:52:58 -0800 (PST) Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6.1.9\)) Subject: Re: __builtin_thread_pointer Date: Tue, 11 Feb 2025 23:52:57 +0100 References: <9c6a1ccc-d2fb-4aaf-b8c2-29574fa640b4 AT cornell DOT edu> <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> To: cygwin AT cygwin DOT com In-Reply-To: <87935cbb-4a43-4ebd-b8cb-125ecfcbcdc3@SystematicSW.ab.ca> Message-Id: X-Mailer: Apple Mail (2.3731.700.6.1.9) X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Dimitry Andric via Cygwin Reply-To: Dimitry Andric Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On 11 Feb 2025, at 23:25, Brian Inglis 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. -Dimitry -- 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