llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.11k forks source link

[libc++] tzdb throws if `/etc/localtime` is not a symlink #105634

Open mgorny opened 3 months ago

mgorny commented 3 months ago

When /etc/localtime is a file rather than a symlink, tzdb throws. This can be seen e.g. in the following libc++ tests:

``` FAIL: llvm-libc++-shared.cfg.in :: std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp (8284 of 9740) ******************** TEST 'llvm-libc++-shared.cfg.in :: std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp' FAILED ******************** Exit Code: 250 Command Output (stdout): -- # COMPILED WITH /usr/lib/ccache/bin/i686-pc-linux-gnu-clang++ /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp -pthread --target=i686-pc-linux-gnu -nostdinc++ -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -lc++experimental -nostdlib++ -L /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -Wl,-rpath,/var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -lc++ -latomic -o /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.access/Output/current_zone.pass.cpp.dir/t.tmp.exe # executed command: /usr/lib/ccache/bin/i686-pc-linux-gnu-clang++ /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp -pthread --target=i686-pc-linux-gnu -nostdinc++ -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -lc++experimental -nostdlib++ -L /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -Wl,-rpath,/var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -lc++ -latomic -o /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.access/Output/current_zone.pass.cpp.dir/t.tmp.exe # EXECUTED AS /usr/bin/python3.12 /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/utils/run.py --execdir /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.access/Output/current_zone.pass.cpp.dir -- /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.access/Output/current_zone.pass.cpp.dir/t.tmp.exe # executed command: /usr/bin/python3.12 /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/utils/run.py --execdir /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.access/Output/current_zone.pass.cpp.dir -- /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.access/Output/current_zone.pass.cpp.dir/t.tmp.exe # .---command stderr------------ # | libc++abi: terminating due to uncaught exception of type std::runtime_error: tzdb: the path '/etc/localtime' is not a symlink # `----------------------------- # error: command failed with exit status: 250 -- ******************** FAIL: llvm-libc++-shared.cfg.in :: std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp (8298 of 9740) ******************** TEST 'llvm-libc++-shared.cfg.in :: std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp' FAILED ******************** Exit Code: 250 Command Output (stdout): -- # COMPILED WITH /usr/lib/ccache/bin/i686-pc-linux-gnu-clang++ /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp -pthread --target=i686-pc-linux-gnu -nostdinc++ -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -lc++experimental -nostdlib++ -L /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -Wl,-rpath,/var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -lc++ -latomic -o /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/Output/current_zone.pass.cpp.dir/t.tmp.exe # executed command: /usr/lib/ccache/bin/i686-pc-linux-gnu-clang++ /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp -pthread --target=i686-pc-linux-gnu -nostdinc++ -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/include/c++/v1 -I /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/test/support -std=c++26 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -lc++experimental -nostdlib++ -L /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -Wl,-rpath,/var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/lib -lc++ -latomic -o /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/Output/current_zone.pass.cpp.dir/t.tmp.exe # EXECUTED AS /usr/bin/python3.12 /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/utils/run.py --execdir /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/Output/current_zone.pass.cpp.dir -- /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/Output/current_zone.pass.cpp.dir/t.tmp.exe # executed command: /usr/bin/python3.12 /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/libcxx/utils/run.py --execdir /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/Output/current_zone.pass.cpp.dir -- /var/tmp/portage/sys-libs/libcxx-20.0.0_pre20240822/work/runtimes_build-abi_x86_32.x86/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/Output/current_zone.pass.cpp.dir/t.tmp.exe # .---command stderr------------ # | libc++abi: terminating due to uncaught exception of type std::runtime_error: tzdb: the path '/etc/localtime' is not a symlink # `----------------------------- # error: command failed with exit status: 250 -- ******************** ```

While systemd requires /etc/localtime to be a symlink, there's no such requirement for non-systemd systems, and at least fresh non-systemd Gentoo installs still default to that (I'm going to work on changing that but the point remains that non-symlink /etc/localtime is still a valid scenario supported by glibc).

mgorny commented 1 month ago

Oh, there's another uncovered scenario: /etc/localtime is also permitted not to exist at all.

emaste commented 1 month ago

FreeBSD also defaults to a non-symlink /etc/localtime in existing releases.

jrtc27 commented 1 month ago

GCC falls back on reading /etc/timezone (for Debian and derivatives) and /var/db/zoneinfo (for FreeBSD). Whether that's sensible I don't know, but it's better than doing nothing.