elf_loader 0.17.0

A no_std-friendly ELF loader and runtime linker for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
use super::{
    KeyResolver, ResolveInput, ResolveRequest, ResolvedKey,
    request::{LoaderProvider, LoaderVisitor},
};
use crate::{
    Error, IoError, ParseEhdrError, Result,
    image::{ModuleSearch, PathTokens, SharedDir, normalize_dir},
    input::{ElfFile, Path, PathBuf},
    loader::read_ehdr,
    relocation::RelocationArch,
    sync::{Arc, arc_unsize},
    tls::TlsResolver,
};
use alloc::vec::Vec;
use core::fmt;

type PathProvider = dyn for<'req> Fn(CandidateRequest<'req>, &mut Vec<PathBuf>) -> Result<()>
    + Send
    + Sync
    + 'static;

#[derive(Clone)]
enum SearchPathEntry {
    Rpath,
    Runpath,
    Dir(SharedDir),
    DirProvider(Arc<PathProvider>),
    CandidateProvider(Arc<PathProvider>),
}

impl fmt::Debug for SearchPathEntry {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Rpath => f.write_str("Rpath"),
            Self::Runpath => f.write_str("Runpath"),
            Self::Dir(dir) => f.debug_tuple("Dir").field(dir).finish(),
            Self::DirProvider(_) => f.write_str("DirProvider(..)"),
            Self::CandidateProvider(_) => f.write_str("CandidateProvider(..)"),
        }
    }
}

/// Search request used to build filesystem candidates for a root or dependency.
#[derive(Clone, Copy)]
pub struct CandidateRequest<'a> {
    requested: &'a Path,
    owner: &'a ModuleSearch,
    tokens: &'a PathTokens,
    loaders: &'a LoaderProvider<'a>,
}

impl<'a> CandidateRequest<'a> {
    #[inline]
    const fn new(
        requested: &'a Path,
        owner: &'a ModuleSearch,
        tokens: &'a PathTokens,
        loaders: &'a LoaderProvider<'a>,
    ) -> Self {
        Self {
            requested,
            owner,
            tokens,
            loaders,
        }
    }

    /// Returns the requested root path or dependency name/path.
    #[inline]
    pub const fn requested(&self) -> &'a Path {
        self.requested
    }

    #[inline]
    const fn owner(&self) -> &'a ModuleSearch {
        self.owner
    }

    #[inline]
    const fn tokens(&self) -> &'a PathTokens {
        self.tokens
    }

    fn visit_loaders(
        &self,
        mut visitor: impl for<'search> FnMut(&'search ModuleSearch) -> Result<bool>,
    ) -> Result<()> {
        (self.loaders)(&mut visitor)
    }

    /// Returns the owner name for caller-aware roots and dependencies.
    #[inline]
    pub fn owner_name(&self) -> &'a str {
        self.owner().name()
    }

    /// Returns the owner path for caller-aware roots and dependencies.
    #[inline]
    pub fn owner_path(&self) -> &'a Path {
        self.owner().path()
    }

    /// Returns the owner directory used for `$ORIGIN` expansion.
    #[inline]
    pub fn origin(&self) -> &'a Path {
        self.owner_path().parent()
    }
}

impl fmt::Debug for CandidateRequest<'_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("CandidateRequest")
            .field("requested", &self.requested)
            .field("owner", &self.owner)
            .finish()
    }
}

/// Filesystem-backed dependency resolver for [`Linker`](crate::Linker).
///
/// `SearchPathResolver` is an opt-in convenience resolver for callers whose
/// linker keys can be viewed as loader paths and constructed from resolved
/// paths. Root requests and dependencies with directory separators are tried
/// directly. Plain-name searches walk the configured sources in insertion
/// order.
///
/// This resolver intentionally does not model the host dynamic linker's global
/// policy: it does not read `LD_LIBRARY_PATH`, system cache files, or default
/// system library directories unless callers add runtime directory providers
/// for them.
///
/// Module-owned `DT_RPATH` and `DT_RUNPATH` entries have their dynamic string
/// tokens expanded by the loader and are shared between modules. File existence
/// and final lookup results are not cached.
#[derive(Clone, Default)]
pub struct SearchPathResolver {
    entries: Vec<SearchPathEntry>,
}

impl fmt::Debug for SearchPathResolver {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SearchPathResolver")
            .field("entries", &self.entries)
            .finish()
    }
}

impl SearchPathResolver {
    /// Creates an empty search-path resolver.
    #[inline]
    pub const fn new() -> Self {
        Self {
            entries: Vec::new(),
        }
    }

    fn push_entry(&mut self, entry: SearchPathEntry) -> &mut Self {
        let entry = match entry {
            SearchPathEntry::Rpath => {
                if self
                    .entries
                    .iter()
                    .any(|entry| matches!(entry, SearchPathEntry::Rpath))
                {
                    return self;
                }
                SearchPathEntry::Rpath
            }
            SearchPathEntry::Runpath => {
                if self
                    .entries
                    .iter()
                    .any(|entry| matches!(entry, SearchPathEntry::Runpath))
                {
                    return self;
                }
                SearchPathEntry::Runpath
            }
            SearchPathEntry::Dir(dir) => {
                if self.entries.iter().any(|entry| {
                    matches!(entry, SearchPathEntry::Dir(existing) if existing.as_ref() == dir.as_ref())
                }) {
                    return self;
                }
                SearchPathEntry::Dir(dir)
            }
            entry => entry,
        };
        self.entries.push(entry);
        self
    }

    /// Appends inherited `DT_RPATH` directories.
    ///
    /// The direct loader is visited first, followed by its loader chain. The
    /// entire source is skipped when the direct loader has `DT_RUNPATH`.
    pub fn push_rpath(&mut self) -> &mut Self {
        self.push_entry(SearchPathEntry::Rpath)
    }

    /// Appends the direct loader's `DT_RUNPATH` directories.
    ///
    /// Unlike `DT_RPATH`, this source is not inherited by indirect
    /// dependencies.
    pub fn push_runpath(&mut self) -> &mut Self {
        self.push_entry(SearchPathEntry::Runpath)
    }

    /// Appends a fixed search directory.
    pub fn push_fixed_dir(&mut self, dir: impl Into<PathBuf>) -> &mut Self {
        self.push_entry(SearchPathEntry::Dir(Arc::from(
            normalize_dir(dir.into()).into_string(),
        )))
    }

    /// Appends a callback that can provide search directories per request.
    pub fn push_search_dir_provider<F>(&mut self, provider: F) -> &mut Self
    where
        F: for<'req> Fn(CandidateRequest<'req>, &mut Vec<PathBuf>) -> Result<()>
            + Send
            + Sync
            + 'static,
    {
        self.push_entry(SearchPathEntry::DirProvider(
            arc_unsize!(Arc::new(provider) => PathProvider),
        ))
    }

    /// Appends a callback that can provide complete file candidates per request.
    ///
    /// Candidates are opened in the order supplied and are not joined with the
    /// requested library name. This is suitable for sources such as
    /// `/etc/ld.so.cache` that have already selected an exact file path.
    pub fn push_candidate_provider<F>(&mut self, provider: F) -> &mut Self
    where
        F: for<'req> Fn(CandidateRequest<'req>, &mut Vec<PathBuf>) -> Result<()>
            + Send
            + Sync
            + 'static,
    {
        self.push_entry(SearchPathEntry::CandidateProvider(arc_unsize!(
            Arc::new(provider) => PathProvider
        )))
    }

    /// Opens and validates a target-compatible ELF candidate.
    fn open_elf<Arch: RelocationArch>(path: &Path) -> Result<Option<ElfFile>> {
        let file = match ElfFile::from_path(path) {
            Ok(file) => file,
            Err(Error::Io(IoError::OpenFailed { .. })) => return Ok(None),
            Err(err) => return Err(err),
        };

        read_ehdr::<Arch>(&file)?;
        Ok(Some(file))
    }

    #[inline]
    fn is_incompatible_elf(err: &Error) -> bool {
        matches!(
            err,
            Error::ParseEhdr(
                ParseEhdrError::FileClassMismatch { .. }
                    | ParseEhdrError::FileEndianMismatch { .. }
                    | ParseEhdrError::FileArchMismatch { .. }
                    | ParseEhdrError::InvalidFlags { .. }
            )
        )
    }
}

impl<Arch, Tls> KeyResolver<Arch, Tls> for SearchPathResolver
where
    Arch: RelocationArch,
    Tls: TlsResolver<Arch>,
{
    type Root = PathBuf;

    #[inline]
    fn root_key<'a>(&self, root: &'a Self::Root) -> &'a str {
        root.as_str()
    }

    fn resolve<'cfg>(
        &self,
        req: ResolveRequest<'_, Self::Root>,
    ) -> Result<ResolvedKey<'cfg, Arch, Tls>> {
        let requested = match req.input() {
            ResolveInput::Root { root } => root.as_path(),
            ResolveInput::Dependency { needed } => Path::new(needed),
        };
        let loaders = |visitor: &mut LoaderVisitor<'_>| req.visit_loaders(visitor);
        let request = CandidateRequest::new(requested, req.search(), req.tokens(), &loaders);

        let mut incompatible = None;
        let mut try_candidate = |candidate: &Path,
                                 continue_on_incompatible: bool|
         -> Result<Option<ResolvedKey<'cfg, Arch, Tls>>> {
            let file = match Self::open_elf::<Arch>(candidate) {
                Ok(Some(file)) => file,
                Ok(None) => return Ok(None),
                Err(err) if continue_on_incompatible && Self::is_incompatible_elf(&err) => {
                    incompatible.get_or_insert(err);
                    return Ok(None);
                }
                Err(err) => return Err(err),
            };
            Ok(Some(ResolvedKey::load(file)))
        };

        let requested_value = request.requested().as_str();
        let expanded = if requested_value.contains('$') {
            let Some(expanded) = request
                .tokens()
                .expand(requested_value, Some(request.origin()))
            else {
                return Err(req.unresolved());
            };
            Some(expanded)
        } else {
            None
        };
        let requested = expanded
            .as_ref()
            .map_or_else(|| request.requested(), PathBuf::as_path);
        if requested.has_dir_separator() {
            return try_candidate(requested, false)?.ok_or_else(|| req.unresolved());
        }

        let mut provided = Vec::new();
        let mut candidate = PathBuf::default();
        for entry in &self.entries {
            match entry {
                SearchPathEntry::Rpath => {
                    if request.owner().runpath().is_some() {
                        continue;
                    }
                    let mut found = None;
                    request.visit_loaders(|owner| {
                        let Some(dirs) = owner.rpath() else {
                            return Ok(true);
                        };
                        for dir in dirs {
                            candidate.set_joined(dir, requested.as_str());
                            if let Some(value) = try_candidate(candidate.as_path(), true)? {
                                found = Some(value);
                                return Ok(false);
                            }
                        }
                        Ok(true)
                    })?;
                    if let Some(found) = found {
                        return Ok(found);
                    }
                }
                SearchPathEntry::Runpath => {
                    let Some(dirs) = request.owner().runpath() else {
                        continue;
                    };
                    for dir in dirs {
                        candidate.set_joined(dir, requested.as_str());
                        if let Some(found) = try_candidate(candidate.as_path(), true)? {
                            return Ok(found);
                        }
                    }
                }
                SearchPathEntry::Dir(dir) => {
                    candidate.set_joined(Path::new(dir), requested.as_str());
                    if let Some(found) = try_candidate(candidate.as_path(), true)? {
                        return Ok(found);
                    }
                }
                SearchPathEntry::DirProvider(provider) => {
                    provided.clear();
                    provider(request, &mut provided)?;
                    for dir in &provided {
                        candidate.set_joined(dir, requested.as_str());
                        if let Some(found) = try_candidate(candidate.as_path(), true)? {
                            return Ok(found);
                        }
                    }
                }
                SearchPathEntry::CandidateProvider(provider) => {
                    provided.clear();
                    provider(request, &mut provided)?;
                    for candidate in &provided {
                        if let Some(found) = try_candidate(candidate.as_path(), true)? {
                            return Ok(found);
                        }
                    }
                }
            }
        }

        match incompatible {
            Some(err) => Err(err),
            None => Err(req.unresolved()),
        }
    }
}

#[cfg(test)]
mod tests {
    extern crate std;

    use super::*;
    use crate::{arch::NativeArch, linker::resolver::ResolvedKind};
    use std::{fs, path::Path as StdPath};

    fn module_search(
        path: &str,
        soname: Option<&str>,
        runpath: Option<&str>,
        rpath: Option<&str>,
    ) -> ModuleSearch {
        ModuleSearch::from_dynamic(PathBuf::from(path), soname, runpath, rpath)
    }

    fn visit_chain(chain: &[&ModuleSearch], visitor: &mut LoaderVisitor<'_>) -> Result<()> {
        for &search in chain {
            if !visitor(search)? {
                break;
            }
        }
        Ok(())
    }

    fn temp_dir(name: &str) -> std::path::PathBuf {
        let mut path = std::env::temp_dir();
        path.push(std::format!(
            "elf_loader_search_{name}_{}",
            std::process::id()
        ));
        let _ = fs::remove_dir_all(&path);
        fs::create_dir_all(&path).unwrap();
        path
    }

    fn install_elf(path: &StdPath) {
        fs::create_dir_all(path.parent().unwrap()).unwrap();
        let source = std::env::current_exe().unwrap();
        if fs::hard_link(&source, path).is_err() {
            fs::copy(source, path).unwrap();
        }
    }

    fn resolve_path(
        resolver: &SearchPathResolver,
        request: CandidateRequest<'_>,
    ) -> Option<PathBuf> {
        let req = ResolveRequest::dependency(
            request.requested().as_str(),
            request.owner(),
            request.tokens(),
            request.loaders,
        );
        match <SearchPathResolver as KeyResolver<NativeArch>>::resolve(resolver, req)
            .ok()?
            .into_parts()
            .0
        {
            ResolvedKind::Load(reader) => Some(PathBuf::from(reader.path().as_str())),
            ResolvedKind::Module { .. } => None,
        }
    }

    #[test]
    fn resolver_is_clone() {
        fn assert_clone<T: Clone>() {}

        assert_clone::<SearchPathResolver>();
    }

    #[test]
    fn fixed_dirs_are_shared_and_deduplicated() {
        let mut resolver = SearchPathResolver::new();
        resolver.push_fixed_dir("/usr/lib/");
        resolver.push_fixed_dir("/usr/lib");
        assert_eq!(resolver.entries.len(), 1);

        let cloned = resolver.clone();
        let SearchPathEntry::Dir(first) = &resolver.entries[0] else {
            panic!("expected fixed directory");
        };
        let SearchPathEntry::Dir(second) = &cloned.entries[0] else {
            panic!("expected fixed directory");
        };
        assert!(Arc::ptr_eq(first, second));
    }

    #[test]
    fn rpath_inherits_loader_chain() {
        let base = temp_dir("rpath_chain");
        let direct_path = base.join("middle");
        let root_path = base.join("root");
        let expected = base.join("lib/libleaf.so");
        install_elf(&expected);
        let direct = module_search(direct_path.to_str().unwrap(), None, None, None);
        let root = module_search(root_path.to_str().unwrap(), None, None, Some("$ORIGIN/lib"));
        let chain = [&direct, &root];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let tokens = PathTokens::default();
        let request = CandidateRequest::new(Path::new("libleaf.so"), &direct, &tokens, &loaders);
        let mut resolver = SearchPathResolver::new();
        resolver.push_rpath();

        assert_eq!(
            resolve_path(&resolver, request).unwrap().as_str(),
            expected.to_str().unwrap()
        );
    }

    #[test]
    fn expands_dependency_origin() {
        let base = temp_dir("dependency_origin");
        let owner_path = base.join("owner");
        let expected = base.join("libvalue.so");
        install_elf(&expected);
        let owner = module_search(owner_path.to_str().unwrap(), None, None, None);
        let chain = [&owner];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let tokens = PathTokens::default();
        let request =
            CandidateRequest::new(Path::new("$ORIGIN/libvalue.so"), &owner, &tokens, &loaders);
        let resolver = SearchPathResolver::new();

        assert_eq!(
            resolve_path(&resolver, request).unwrap().as_str(),
            expected.to_str().unwrap()
        );
    }

    #[test]
    fn expands_target_tokens() {
        let base = temp_dir("target_tokens");
        let owner_path = base.join("owner");
        let expected = base.join("lib64/target-v1/libleaf.so");
        install_elf(&expected);
        let mut paths = crate::image::SearchPathPool::new();
        paths.set_lib("lib64").set_platform("target-v1");
        let tokens = paths.tokens();
        let owner = paths.module_search(
            PathBuf::from(owner_path.to_str().unwrap()),
            None,
            Some("$ORIGIN/$LIB/${PLATFORM}"),
            None,
        );
        let chain = [&owner];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let request = CandidateRequest::new(Path::new("libleaf.so"), &owner, &tokens, &loaders);
        let mut resolver = SearchPathResolver::new();
        resolver.push_runpath();

        assert_eq!(
            resolve_path(&resolver, request).unwrap().as_str(),
            expected.to_str().unwrap()
        );
    }

    #[test]
    fn expands_tokens_in_dependency_name() {
        let base = temp_dir("dependency_tokens");
        let expected = base.join("target-v1/libleaf.so");
        install_elf(&expected);
        let owner = module_search("/app/owner", None, None, None);
        let mut paths = crate::image::SearchPathPool::new();
        paths
            .set_lib(base.to_str().unwrap())
            .set_platform("target-v1");
        let tokens = paths.tokens();
        let chain = [&owner];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let request = CandidateRequest::new(
            Path::new("$LIB/${PLATFORM}/libleaf.so"),
            &owner,
            &tokens,
            &loaders,
        );
        let resolver = SearchPathResolver::new();

        assert_eq!(
            resolve_path(&resolver, request).unwrap().as_str(),
            expected.to_str().unwrap()
        );
    }

    #[test]
    fn missing_target_token_discards_path() {
        let owner = module_search("/app/owner", None, Some("$ORIGIN/$PLATFORM"), None);
        let chain = [&owner];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let tokens = PathTokens::default();
        let request = CandidateRequest::new(Path::new("libleaf.so"), &owner, &tokens, &loaders);
        let mut resolver = SearchPathResolver::new();
        resolver.push_runpath();
        assert!(resolve_path(&resolver, request).is_none());
    }

    #[test]
    fn runpath_suppresses_rpath_chain() {
        let direct = module_search("/app/middle", None, Some(""), Some("/direct"));
        let root = module_search("/app/root", None, None, Some("/root"));
        let chain = [&direct, &root];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let tokens = PathTokens::default();
        let request = CandidateRequest::new(Path::new("libleaf.so"), &direct, &tokens, &loaders);
        let mut resolver = SearchPathResolver::new();
        resolver.push_rpath();
        assert!(resolve_path(&resolver, request).is_none());
    }

    #[test]
    fn rpath_and_runpath_have_independent_order() {
        let base = temp_dir("search_order");
        let fixed = base.join("fixed");
        let run = base.join("run");
        let fixed_candidate = fixed.join("libleaf.so");
        let run_candidate = run.join("libleaf.so");
        install_elf(&fixed_candidate);
        install_elf(&run_candidate);
        let direct = module_search("/app/middle", None, Some(run.to_str().unwrap()), None);
        let root = module_search("/app/root", None, None, Some("/unused"));
        let chain = [&direct, &root];
        let loaders = |visitor: &mut LoaderVisitor<'_>| visit_chain(&chain, visitor);
        let tokens = PathTokens::default();
        let request = CandidateRequest::new(Path::new("libleaf.so"), &direct, &tokens, &loaders);
        let mut resolver = SearchPathResolver::new();
        resolver.push_rpath();
        resolver.push_fixed_dir(fixed.to_str().unwrap());
        resolver.push_runpath();
        assert_eq!(
            resolve_path(&resolver, request).unwrap().as_str(),
            fixed_candidate.to_str().unwrap()
        );

        fs::remove_file(fixed_candidate).unwrap();
        assert_eq!(
            resolve_path(&resolver, request).unwrap().as_str(),
            run_candidate.to_str().unwrap()
        );
    }

    #[test]
    fn path_lists_preserve_current_directory() {
        let owner = module_search("/app/owner", None, Some(":/fallback"), None);
        assert_eq!(
            owner
                .runpath()
                .unwrap()
                .map(PathBuf::from)
                .collect::<Vec<_>>(),
            [PathBuf::from("."), PathBuf::from("/fallback")]
        );
    }

    #[test]
    fn origin_requires_a_token_boundary() {
        let owner = module_search(
            "/app/owner",
            None,
            Some("$ORIGIN/lib:$ORIGIN_SUFFIX:${ORIGIN}/alt"),
            None,
        );
        let paths = owner
            .runpath()
            .unwrap()
            .map(PathBuf::from)
            .collect::<Vec<_>>();
        assert_eq!(
            paths,
            [
                PathBuf::from("/app/lib"),
                PathBuf::from("$ORIGIN_SUFFIX"),
                PathBuf::from("/app/alt"),
            ]
        );
    }
}