public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Issue with locale (sysroot installation)
@ 2021-03-20 21:32 Oleg Smolsky
  2021-03-21  8:19 ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Oleg Smolsky @ 2021-03-20 21:32 UTC (permalink / raw)
  To: libc-help

Hello there! I'm testing a GCC-10/glibc-2.33 combo where libc is 
installed into a sysroot. Here is a small test demonstrating a problem:

#include <iostream>
#include <locale>
int main() {
     std::cout << "User-preferred locale: " << std::locale("").name() << 
std::endl;
}

Things work when I build this test using a normal compiler and the 
program prints "en_US.UTF-8" on my system. Yet I get an exception when 
running a program built with the GCC-10/glibc combo:

     what():  locale::facet::_S_create_c_locale name not valid

Here is what the run-time setup is for the test program:

$ ldd test
         linux-vdso.so.1 =>  (0x00007ffd6d7d8000)
         libpthread.so.0 => /opt/sysroot/lib64/libpthread.so.0 
(0x00007f3aafb0d000)
         librt.so.1 => /opt/sysroot/lib64/librt.so.1 (0x00007f3aaf905000)
         libdl.so.2 => /opt/sysroot/lib64/libdl.so.2 (0x00007f3aaf701000)
         libstdc++.so.6 => /opt/gcc-10sr/lib64/libstdc++.so.6 
(0x00007f3aaf334000)
         libm.so.6 => /opt/sysroot/lib64/libm.so.6 (0x00007f3aaeff5000)
         libgcc_s.so.1 => /opt/gcc-10sr/lib64/libgcc_s.so.1 
(0x00007f3aaedde000)
         libc.so.6 => /opt/sysroot/lib64/libc.so.6 (0x00007f3aaea1b000)
         /opt/sysroot/lib64/ld-linux-x86-64.so.2 => 
/lib64/ld-linux-x86-64.so.2 (0x00007f3aafd2b000)

Some notes:

1. The program works when I force the locale via environment with LC_ALL=C

2. In the broken case it looks like glibc code is searching in the 
system dirs. Here is "strace -e file" output:

openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=2981280, ...}, 
AT_EMPTY_PATH) = 0
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=2995, ...}, 
AT_EMPTY_PATH) = 0
openat(AT_FDCWD, "/usr/lib/locale/en_US.UTF-8/LC_TIME", 
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/en_US.utf8/LC_TIME", 
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/en_US/LC_TIME", O_RDONLY|O_CLOEXEC) = 
-1 ENOENT (No such file or directory)
...

3. I tried installing locales with "localedata/install-locale-files" and 
"localedata/install-locales". Yet the program does not look in the 
sysroot...

4. Glibc was configured with:

CC=$boostrap_gcc/bin/gcc CXX=$boostrap_gcc/bin/g++ PATH=/opt/3p/bin:$PATH \
     ../configure \
         --prefix=/usr --libdir=/usr/lib \
         --host=x86_64-pc-linux \
         --enable-kernel=4.4.0 \
         --with-headers=$sysroot/usr/include

Could someone shed some light on how this setup is supposed to work 
please? It seems like I am missing some glue/config that should get 
baked into glibc during compilation or installation...

Thanks in advance!
Oleg.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Issue with locale (sysroot installation)
  2021-03-20 21:32 Issue with locale (sysroot installation) Oleg Smolsky
@ 2021-03-21  8:19 ` Florian Weimer
  2021-03-21 15:17   ` Oleg Smolsky
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2021-03-21  8:19 UTC (permalink / raw)
  To: Oleg Smolsky via Libc-help

* Oleg Smolsky via Libc-help:

> 2. In the broken case it looks like glibc code is searching in the 
> system dirs. Here is "strace -e file" output:
>
> openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 4
> newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=2981280, ...}, 
> AT_EMPTY_PATH) = 0
> openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
> newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=2995, ...}, 
> AT_EMPTY_PATH) = 0
> openat(AT_FDCWD, "/usr/lib/locale/en_US.UTF-8/LC_TIME", 
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/usr/lib/locale/en_US.utf8/LC_TIME", 
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> openat(AT_FDCWD, "/usr/lib/locale/en_US/LC_TIME", O_RDONLY|O_CLOEXEC) = 
> -1 ENOENT (No such file or directory)
> ...

> 4. Glibc was configured with:
>
> CC=$boostrap_gcc/bin/gcc CXX=$boostrap_gcc/bin/g++ PATH=/opt/3p/bin:$PATH \
>      ../configure \
>          --prefix=/usr --libdir=/usr/lib \
>          --host=x86_64-pc-linux \
>          --enable-kernel=4.4.0 \
>          --with-headers=$sysroot/usr/include

Due to --prefix=/usr, the built glibc will locate ancillary in the
standard paths.  Therefore, you have to set LOCPATH and GCONV_PATH to
tell the glibc in the sysroot to use files at non-standard locations.
(The system files are not necessarily compatible.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Issue with locale (sysroot installation)
  2021-03-21  8:19 ` Florian Weimer
@ 2021-03-21 15:17   ` Oleg Smolsky
  2021-03-21 18:27     ` Oleg Smolsky
  0 siblings, 1 reply; 4+ messages in thread
From: Oleg Smolsky @ 2021-03-21 15:17 UTC (permalink / raw)
  To: Florian Weimer, Oleg Smolsky via Libc-help

On 2021-03-21 01:19, Florian Weimer wrote:
>
>> 4. Glibc was configured with:
>>
>> CC=$boostrap_gcc/bin/gcc CXX=$boostrap_gcc/bin/g++ PATH=/opt/3p/bin:$PATH \
>>       ../configure \
>>           --prefix=/usr --libdir=/usr/lib \
>>           --host=x86_64-pc-linux \
>>           --enable-kernel=4.4.0 \
>>           --with-headers=$sysroot/usr/include
> Due to --prefix=/usr, the built glibc will locate ancillary in the
> standard paths.  Therefore, you have to set LOCPATH and GCONV_PATH to
> tell the glibc in the sysroot to use files at non-standard locations.
> (The system files are not necessarily compatible.)

Ah, I see. Thank you for the hint, Florian! The run-time solution works, 
but I would like to bake the locale location into glibc.

My current build recipe configures GLibc with "--prefix=/usr 
--libdir=/usr/lib" and then I do "make install_root=$sysroot install". 
This generates the right directory structure for GCC to discover 
everything and for the generated executables to run (given the minimal 
rpath tweaks).

Is there a different way to configure/install so that the locale path 
gets baked in and discovered at run-time?

Thanks!
Oleg.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Issue with locale (sysroot installation)
  2021-03-21 15:17   ` Oleg Smolsky
@ 2021-03-21 18:27     ` Oleg Smolsky
  0 siblings, 0 replies; 4+ messages in thread
From: Oleg Smolsky @ 2021-03-21 18:27 UTC (permalink / raw)
  To: Florian Weimer, Oleg Smolsky via Libc-help

On 2021-03-21 08:17, Oleg Smolsky wrote:
> On 2021-03-21 01:19, Florian Weimer wrote:
>>
>>> 4. Glibc was configured with:
>>>
>>> CC=$boostrap_gcc/bin/gcc CXX=$boostrap_gcc/bin/g++ 
>>> PATH=/opt/3p/bin:$PATH \
>>>       ../configure \
>>>           --prefix=/usr --libdir=/usr/lib \
>>>           --host=x86_64-pc-linux \
>>>           --enable-kernel=4.4.0 \
>>>           --with-headers=$sysroot/usr/include
>> Due to --prefix=/usr, the built glibc will locate ancillary in the
>> standard paths.  Therefore, you have to set LOCPATH and GCONV_PATH to
>> tell the glibc in the sysroot to use files at non-standard locations.
>> (The system files are not necessarily compatible.)
>
> Ah, I see. Thank you for the hint, Florian! The run-time solution 
> works, but I would like to bake the locale location into glibc.
>
> My current build recipe configures GLibc with "--prefix=/usr 
> --libdir=/usr/lib" and then I do "make install_root=$sysroot install". 
> This generates the right directory structure for GCC to discover 
> everything and for the generated executables to run (given the minimal 
> rpath tweaks).
>
> Is there a different way to configure/install so that the locale path 
> gets baked in and discovered at run-time?

After a few experiments, I got the following to work: glibc is built 
with --prefix=$sysroot/usr. The only kink is that during GCC build I 
have to create $sysroot hierarchy inside $sysroot - so I cheated with a 
symlink.

The test program finds the locale at the right place now.

Thanks!
Oleg.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-21 18:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-20 21:32 Issue with locale (sysroot installation) Oleg Smolsky
2021-03-21  8:19 ` Florian Weimer
2021-03-21 15:17   ` Oleg Smolsky
2021-03-21 18:27     ` Oleg Smolsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).