summary refs log tree commit diff
path: root/pkgs/build-support/libredirect
Commit message (Collapse)AuthorAge
* libredirect: Fix segfault handling null pathsaszlig2023-08-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While using libredirect in conjunction with geckodriver, I stumbled on odd segfaults that happened when running the wrapped statx() call from libredirect: 0x00007ffff7ddd541 in __strncmp_avx2 () from .../lib/libc.so.6 0x00007ffff7f6fe57 in statx () from .../lib/libredirect.so 0x00005555558d35bd in std::sys::unix::fs::try_statx::h2045d39b0c66d4e8 () 0x00005555558d2230 in std::sys::unix::fs::stat::ha063998dfb361520 () 0x0000555555714019 in mozversion::firefox_version::hdc3b57eb04947426 () 0x00005555556a603c in geckodriver::capabilities::FirefoxCapabilities::version::h58e289917bd3c721 () 0x00005555556a77f5 in <geckodriver::capabilities::FirefoxCapabilities as webdriver::capabilities::BrowserCapabilities>::validate_custom::h62d23cf9fd63b719 () 0x000055555562a7c8 in webdriver::capabilities::SpecNewSessionParameters::validate::h60da250d33f0989f () 0x00005555556d7a13 in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold::h9427a360a3d0bf8f () 0x0000555555669d85 in <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::hd274d536ea29bb33 () 0x00005555555c05ef in core::iter::adapters::try_process::hdf96a01ec1f9b8bd () 0x000055555561768d in <webdriver::capabilities::SpecNewSessionParameters as webdriver::capabilities::CapabilitiesMatching>::match_browser::hfbd8c38f6db17e9f () 0x00005555555ca6ef in <geckodriver::marionette::MarionetteHandler as webdriver::server::WebDriverHandler<geckodriver::command::GeckoExtensionRoute>>::handle_command::h13b98b9cb87a69d6 () 0x00005555555e859e in webdriver::server::Dispatcher<T,U>::run::h746a8bf2f0bc24fd () 0x000055555569ff0f in std::sys_common::backtrace::__rust_begin_short_backtrace::h3b920773bd467d2a () 0x00005555555dbc99 in core::ops::function::FnOnce::call_once{{vtable.shim}}::h81ba7228877515f7 () 0x00005555558d31a3 in std::sys::unix::thread::Thread::new::thread_start::h4514580219a899c5 () 0x00007ffff7d0ce24 in start_thread () from .../lib/libc.so.6 0x00007ffff7d8e9b0 in clone3 () from .../lib/libc.so.6 The reason why I found this odd was because it happens in the following piece of code (shortened a bit): 1 static const char * rewrite(const char * path, char * buf) 2 { 3 if (path == NULL) return path; 4 for (int n = 0; n < nrRedirects; ++n) { 5 int len = strlen(from[n]); 6 if (strncmp(path, from[n], len) != 0) continue; 7 if (snprintf(buf, PATH_MAX, "%s%s", to[n], path + len) >= PATH_MAX) 8 abort(); 9 return buf; 10 } 11 return path; 12 } When inspecting the assembly, I found that the check for the null pointer in line 3 was completely missing and the code was directly entering the loop and then eventually segfault when running strncmp() with a null pointer as its first argument. I confirmed that indeed that check was missing by compiling libredirect with "-O0" and comparing the generated assembly with the optimized one. The one compiled with "-O0" had that check while the optimized one did not and indeed when running geckodriver with the unoptimized version it worked fine. Digging in the Git history, I found 5677ce200831a83a7b3d37f2cfc4ec00c10, which actually introduced the null pointer check. Going back to that commit however, the check actually was still in the generated assembly. So I bisected between that commit and the most recent one and ended up with commit ca8aa5dc877344082864cf75512e59c7a1d0ad8c, which moved everything to use GCC 7. I haven't found out why *exactly* GCC was optimizing the check away, but playing around on Godbolt with various other compilers seems that other compilers such as Clang are doing it as well. Additionally, given that passing NULL to stat() is UB, my guess is that compilers tend to assume that such an argument can't be NULL. My assumption is based on the fact that GCC warns with "argument 1 null where non-null expected" when passing NULL to eg. stat(). To address this for now, I marked the path argument of the rewrite() volatile and also added a test that should cause a segfault in case this would regress again as it already did. Signed-off-by: aszlig <aszlig@nix.build>
* libredirect: fix build with clang 16Randy Eckenrode2023-07-14
| | | | | | | * Preferentially use the stdenv clang if it is new enough to produce arm64e binaries; and * Fix incompatible function pointer conversions (results in an error with clang 16).
* libredirect: fix build on musl libcNoah Fontes2023-02-06
| | | | | musl doesn't yet provide a wrapper for the statx syscall, so don't bother wrapping it here unless it's actually available.
* libredirect: add tests for new wrappersNoah Fontes2023-01-26
|
* libredirect: add more wrappersNoah Fontes2023-01-25
| | | | | | This appears to satisfy the JVM and most coreutils programs like mkdir, etc., as used in self-contained installers like Revenera InstallAnywhere.
* treewide: remove -ldl linker flagsAlyssa Ross2023-01-23
| | | | | | | | | | | With all libcs I'm aware of, libdl is now either empty (Glibc, musl, uclibc, illumos), a symlink to libc or equivalent (Apple), or does not exist (FreeBSD, NetBSD). So explicitly linking libdl now does nothing for the former platforms, and breaks the build for the latter platforms. With this patch I've removed -ldl from all overridden linker flags for all free packages in Nixpkgs. Everything still seems to build.
* libredirect: Fix cross compilation `buildPackages`Hamish Mackenzie2022-07-20
| | | | | | | | | | | | | | | | Currently when cross compiling the `buildPackages.libredirect` has the wrong dynamic library extension. To reproduce the issue run something like: ``` file $(nix-build -A pkgsCross.mingwW64.buildPackages.libredirect)/lib/libredirect.dll /nix/store/80llmqa9lkabg3qnmglngzz22fwf739q-libredirect-0/lib/libredirect.dll: Mach-O 64-bit dynamically linked shared library x86_64 ``` or ``` nix-diff $(nix-instantiate -A libredirect) $(nix-instantiate -A pkgsCross.mingwW64.buildPackages.libredirect) ```
* Merge remote-tracking branch 'nixpkgs/staging-next' into stagingAlyssa Ross2022-01-24
|\ | | | | | | | | | | Conflicts: pkgs/development/python-modules/cupy/default.nix pkgs/development/python-modules/staticjinja/default.nix
| * libredirect: fix build for aarch64-darwin (PR #156460)Jonathan Ringer2022-01-24
| |
* | libredirect: add support for mktempRobert Scott2022-01-18
| |
* | libredirect: add support for mkdtempRobert Scott2022-01-18
| |
* | libredirect: add support for mkstemp family of functionsRobert Scott2022-01-18
| |
* | libredirect: add support for unlink, unlinkat, rmdirRobert Scott2022-01-18
|/ | | | add coverage of these and mkdir functions in tests
* libredirect: improve musl support (#154039)Jörg Thalheim2022-01-12
| | | | __nss_files_open is glibc only. Also mark some linux specific system calls as such for better portability with other unixes.
* Merge branch 'staging-next' into stagingJan Tojnar2022-01-10
|\ | | | | | | | | | | | | ; Conflicts: ; nixos/doc/manual/from_md/release-notes/rl-2205.section.xml ; nixos/doc/manual/release-notes/rl-2205.section.md ; pkgs/build-support/libredirect/default.nix
| * pkgsStatic.libredirect: print error message why it won't workDmitry Bogatov2022-01-08
| | | | | | | | The whole point of libredirect is manipulation with LD_PRELOAD, which is not supposed to work on static builds.
* | libredirect: build fat library for x86_64, arm64, arm64e on darwin (#153441)Moritz Angermann2022-01-07
| | | | | | | | | | | | macOS's dyld can be rather picky as to what dylib it accepts. This even changes across macOS versions. Therefore we now build a fat dylib with all three architectures (x86_64, arm64, arm64e). This should then be compatible with pretty much any macOS's dyld.
* | libredirect: fix musl buildRyan Burns2021-12-30
|/
* libredirect: workaround dyld env not inheritedStéphan Kochen2021-11-05
|
* libredirect: use __interpose on darwinStéphan Kochen2021-11-05
| | | | DYLD_FORCE_FLAT_NAMESPACE was removed in recent versions of macOS.
* libredirect: handle mkdir(2) + mkdirat(2)Bjørn Forsman2021-10-09
| | | | | | Fixes https://github.com/NixOS/nixpkgs/issues/140735. Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
* libredirect: add subprocess testPascal Bach2021-09-03
|
* libredirect: Fix redirects not working for subprocessesNiklas Hambüchen2021-09-03
|
* libredirect: Enable debug symbolsNiklas Hambüchen2021-09-03
|
* libredirect: Add missing phase hooksNiklas Hambüchen2021-09-03
|
* application/development: /s/name/pname&version/Felix Buehler2021-06-30
|
* brscan5: init at 1.2.6-0Matt Christ2021-05-21
|
* treewide: stdenv.lib -> libPavol Rusnak2021-01-24
|
* python3Packages.python-engineio: fix build w/glibc-2.32Maximilian Bosch2020-09-12
| | | | | | | Also had to wrap `__nss_files_fopen` in `libredirect` as this is the way now `nss` uses to retrieve file-databases[1]. [1] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=299210c1fa67e2dfb564475986fce11cd33db9ad;hp=469c03907b116c37c98d8ad7a9edac2bdbf3e934
* libredirect: fix build on darwinMario Rodas2020-01-23
| | | | Fix build failure on darwin due to absence of `O_TMPFILE`.
* libredirect: fix `access` return typeDemin Dmitriy2019-11-12
| | | | | `access` should return `int` not `int*`. Actually compiler produced identical assembly with any of those types, so by luck it "just worked".
* libredirect: fix argument forwarding in open* functionsDemin Dmitriy2019-11-12
| | | | | Flag `O_TMPFILE` was added in Linux 3.11. It affects whether or not `mode` argument should be passed.
* libredirect: add posix_spawnp supportMaximilian Bosch2019-06-18
| | | | | | | | | | | | After bumping sublime3 in #61636 we realized that saving files as root doesn’t work anymore and somehow the paths weren’t patched by `libredirect`. After some debugging it came out that Sublime switched from `posix_spawn(3)` to `posix_spawnp(3)` to start new processes internally. Since `libredirect` only handled the former, `/usr/bin/pkexec` stopped being redirected. Wrapping `posix_spawnp` fixes the problem.
* libredirect: remove dlopen supportJan Tojnar2019-05-04
| | | | | | | | | While it might be useful in some cases, there are too many caveats to be worth it. When libredirect intercepts dlopen call and calls the original function, the dynamic loader will use libredirect.so's DT_RUNPATH entry instead of the one from the ELF file the dlopen call originated from. That means that when program tries to dlopen a library that it expects to find on its RPATH, the call will fail. This broke Sublime Text for just that reason.
* libredirect: add support for openat and dlopenJan Tojnar2019-04-20
| | | | | | | gobject-introspection uses glib’s g_module_open function, which in turn relies on dlopen. I also implemented openat, since I initially thought this function was used but turns out dlopen uses the openat signal directly. We might as well keep it, even thought I do not need it at the moment.
* libredirect: set install_name on Darwinzimbatm2018-11-14
| | | | fixes https://github.com/NixOS/nixpkgs/pull/50246#issuecomment-437975038
* libredirect: introduce optional setup-hookzimbatm2018-11-14
| | | | | | | This allows to simplify the usage of libredirect inside of nix build sandboxes. Add "libredirect.hook" to the build inputs to get everything linked in automaticall. All that's left is to set NIX_REDIRECTS and call the target program.
* libredirect: specify libNamezimbatm2018-11-13
| | | | | | reduces a bit of duplication and can also be used from the outside: export LD_PRELOAD=${libredirect}/lib/${libredirect.libName}
* libredirect: Add preload wrapper for stat()aszlig2018-11-12
| | | | | | | | | | | | | | Pull request #50246 was merged a bit too quickly and it was supposed to fix libredirect on Darwin. However it still failed on Darwin and this was missed by the person merging the pull request. The reason this was failing was that there is no __xstat* on Darwin. So I'm adding a wrapper for stat() as well as it works on Darwin and it still doesn't hurt on GNU/Linux. Signed-off-by: aszlig <aszlig@nix.build> Cc: @edolstra, @zimbatm
* libredirect: Add a small testaszlig2018-11-12
| | | | | | | | | | | | | | | | This is just a sanity check on whether the library correctly wraps the syscalls and it's using the "true" executable for posix_spawn() and execv(). The installCheckPhase is not executed if we are cross-compiling, so this shouldn't break cross-compilation. One thing I'm not actually sure is whether ${coreutils}/bin/true is universally available on all the platforms, nor whether all the functions we use in the test are available, but we can still fix that after we've found out about that. Signed-off-by: aszlig <aszlig@nix.build>
* libredirect: Use extensions.sharedLibraryaszlig2018-11-12
| | | | | | | | | This is to make sure we get the correct shared library suffix of the target platform. While for example on Darwin it would even work with the hardcoded .so prefix it's IMHO a bit nicer to have the actual native extension. Signed-off-by: aszlig <aszlig@nix.build>
* assume that it works on all unix platformszimbatm2018-11-12
|
* use for cross-compilationzimbatm2018-11-12
|
* libredirect: Add support for Darwinaszlig2018-11-11
| | | | | | | | | | | | | | | The library can be used also on Darwin using it like this: NIX_REDIRECTS='foo=bar' \ DYLD_INSERT_LIBRARIES=${libredirect}/lib/libredirect.so \ DYLD_FORCE_FLAT_NAMESPACE=1 \ some_program So let's actually not hardcade gcc and add Darwin to meta.platforms. No other changes seem to be required. Signed-off-by: aszlig <aszlig@nix.build>
* libredirect: add descriptionOrivej Desh2017-12-14
| | | | Fixes #32675
* libredirect: allow null pathsmichael bishop2017-05-24
|
* treewide: Add lots of platforms to packages with no metaTuomas Tynkkynen2016-08-02
| | | | Build-tested on x86_64 Linux and on Darwin.
* xl2tpd: add nixos module for serviceobadz2016-06-20
| | | | (required adding execv to libredirect)
* citrix-receiver: init at 13.2.1, fixes #8458obadz2015-11-11
|
* libredirect: add __xlib64 and posix_spawnDemin Dmitriy2015-10-24
|