__builtin_thread_pointer

2025-02-11 Thread Ken Brown via Cygwin
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


Re: __builtin_thread_pointer

2025-02-11 Thread Brian Inglis via Cygwin


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

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


Re: __builtin_thread_pointer

2025-02-11 Thread Dimitry Andric via Cygwin
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)

$ cat test-builtin-thread-pointer.c
void f(void)
{
  void *p = __builtin_thread_pointer();
}

$ gcc -c test-builtin-thread-pointer.c
test-builtin-thread-pointer.c: In function ‘f’:
test-builtin-thread-pointer.c:3:13: warning: implicit declaration of function 
‘__builtin_thread_pointer’; did you mean ‘__builtin_extend_pointer’? 
[-Wimplicit-function-declaration]
3 |   void *p = __builtin_thread_pointer();
  | ^~~~
  | __builtin_extend_pointer
test-builtin-thread-pointer.c:3:13: warning: initialization of ‘void *’ from 
‘int’ makes pointer from integer without a cast [-Wint-conversion]

On Ubuntu 24.04 this program compiles without warnings.

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.

-Dimitry

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


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


Re: __builtin_thread_pointer

2025-02-11 Thread Corinna Vinschen via Cygwin
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  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 inf

Re: __builtin_thread_pointer

2025-02-11 Thread Brian Inglis via Cygwin

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?

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


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.


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


App Closes Unexpectedly When Resizing

2025-02-11 Thread Thomas Lake via Cygwin
When I open an app that uses Cygwin, I can't resize the window. When I try, the 
app closes with no warning or error message. I'm using Win 11 24H2

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


Re: __builtin_thread_pointer

2025-02-11 Thread Brian Inglis via Cygwin

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)
>
> $ cat test-builtin-thread-pointer.c
> void f(void)
> {
>void *p = __builtin_thread_pointer();
> }

If you read the docs at `info gcc tls` it uses the __thread storage class to 
allow you to declare auto, extern, or static thread variables like any other.


Whether that would run as expected is more than I can deduce.

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


Re: __builtin_thread_pointer

2025-02-11 Thread Dimitry Andric via Cygwin
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

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


Window Closes When Resizing

2025-02-11 Thread Thomas Lake via Cygwin
When I run an Cygwin app and try to resize the window, it closes unexpectedly 
with no warning or error message. I'm running Win 11 24H2 and 64-bit Cygwin.

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


Re: Window Closes When Resizing

2025-02-11 Thread Marco Atzeri via Cygwin

On 11/02/2025 19:19, Thomas Lake via Cygwin wrote:

When I run an Cygwin app and try to resize the window, it closes unexpectedly 
with no warning or error message. I'm running Win 11 24H2 and 64-bit Cygwin.



Hi Thomas,
Are you use the Cygwin terminal ?
Which App ?
How are you running it ?

please also follow
https://cygwin.com/problems.html
and provide the cygcheck.out as ATTACHMENT

Regards
Marco



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


Re: App Closes Unexpectedly When Resizing

2025-02-11 Thread Brian Inglis via Cygwin

On 2025-02-11 11:13, Thomas Lake via Cygwin wrote:

When I open an app that uses Cygwin, I can't resize the window. When I try, the 
app closes with no warning or error message. I'm using Win 11 24H2



Talk to whoever provided the app that uses Cygwin.
We have no idea what the app is, does, or even if it actauuly uses Cygwin.
Often the solution is to upgrade the included Cygwin and/or packages to the 
current version(s), so that they run properly under Win 11.


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


Re: __builtin_thread_pointer

2025-02-11 Thread Ken Brown via Cygwin

On 2/11/2025 4:03 PM, Corinna Vinschen via Cygwin wrote:

Ken, check the source or configury of your package.  It looks weird that
this function should be called architecture-independently.
Thanks for the suggestion.  It's actually not called 
architecture-independently, but the code was convoluted and I didn't see 
at first what was going on.  It turns out that I just had to add

"#if !defined(__CYGWIN__)" at the right place and the build succeeded.

Ken

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


Re: Potential Argument Injection Issue in Cygwin's Command Line Handling

2025-02-11 Thread Brian Inglis via Cygwin

On 2025-02-10 19:09, Kaz Kylheku wrote:

On 2025-02-10 12:32, Brian Inglis via Cygwin wrote:

One can avoid any issues by running Cygwin programs only from other Cygwin 
programs, and Windows programs only from other Windows programs.


Microsoft has provided a documented algorithm, which is implemented in the 
ShellAPI function CommandLineToArgvW, and in the CRT module that prepares 
arguments for the main or wmain functions of Microsoft Visual C/C++ programs.

I believe that the algorithm is sound in that it can round-trip any argv[] 
vector to string, and then back to recover an identical argv[].

(Am I correct?)


It appears not from the previous comments, the MS algorithm/hackaround messes up 
various argument strings and makes the original contents irretrievable, if they 
do not obey their limitations, rather than just pass along the verbatim command 
line as a string, as assumed by POSIX programs, normally preceding the 
environment in the heap, like an anonymous environment variable.


I prefer that Cygwin programs work like all other POSIX programs, as I maintain 
a few dozen packages, and build a bunch of others I use that, for the most part, 
port and run with no or only very minor patching, to work around Windows issues.


If every package had to work around the Windows issues that Cygwin handles for 
us, we would not have many packages available, and be unable to support the 
POSIX and Unix subsystems we do, that transparently interoperate with other Unix 
compatible systems Cygwin users can access around the globe.


If you want to handle Windows command lines the MS way, feel free to use Windows 
compilers and APIs, including AOCC, ICC, VC89, mingw64-x86_64-binutils/gcc, etc.


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


Re: __builtin_thread_pointer

2025-02-11 Thread Dimitry Andric via 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