|
9 | 9 | //! that the binary was linked with the correct option: |
10 | 10 | //! |
11 | 11 | //! - `otel_thread_ctx_v1` is exported as TLS GLOBAL in the dynamic symbol table. |
12 | | -//! - `otel_thread_ctx_v1` follows the TLSDESC model: there's either no relocation in `.rela.dyn` |
13 | | -//! (Local Exec), or a TLSDESC one. All other TLS relocation types (DTPMOD, DTPOFF, TPOFF, |
14 | | -//! GOTTPOFF, etc.) are rejected. |
| 12 | +//! - `otel_thread_ctx_v1` has no non-TLSDESC TLS relocations in `.rela.dyn`. The linker may pick |
| 13 | +//! TLSDESC or Local Exec depending on optimization; both are acceptable. All other TLS relocation |
| 14 | +//! types (DTPMOD, DTPOFF, TPOFF, GOTTPOFF, etc.) are rejected. |
15 | 15 | //! |
16 | 16 | //! This module is only available on Linux (the only platform that supports the TLSDESC dialect used |
17 | 17 | //! by this crate) and only when the `sanity-check` feature is enabled. |
@@ -51,15 +51,26 @@ fn own_elf_path() -> anyhow::Result<PathBuf> { |
51 | 51 | std::fs::read_to_string("/proc/self/maps").context("failed to read /proc/self/maps")?; |
52 | 52 | for line in maps.lines() { |
53 | 53 | // Format: address perms offset dev inode [pathname] |
54 | | - let fields: Vec<&str> = line.split_whitespace().collect(); |
55 | | - if fields.len() < 6 { |
56 | | - continue; |
| 54 | + // Skip the first 5 whitespace-delimited tokens then take the rest verbatim |
| 55 | + // as the path, so that pathnames containing spaces are preserved intact. |
| 56 | + let mut rest = line; |
| 57 | + |
| 58 | + for _ in 0..5 { |
| 59 | + rest = rest.trim_start_matches(|c: char| c.is_ascii_whitespace()); |
| 60 | + rest = rest.trim_start_matches(|c: char| !c.is_ascii_whitespace()); |
57 | 61 | } |
58 | | - let path = fields[5]; |
| 62 | + |
| 63 | + let path = rest.trim_start_matches(|c: char| c.is_ascii_whitespace()); |
| 64 | + |
59 | 65 | if !path.starts_with('/') { |
60 | 66 | continue; |
61 | 67 | } |
62 | | - if let Some((start_str, end_str)) = fields[0].split_once('-') { |
| 68 | + |
| 69 | + if let Some((start_str, end_str)) = line |
| 70 | + .split_whitespace() |
| 71 | + .next() |
| 72 | + .and_then(|f| f.split_once('-')) |
| 73 | + { |
63 | 74 | let start = usize::from_str_radix(start_str, 16).unwrap_or(0); |
64 | 75 | let end = usize::from_str_radix(end_str, 16).unwrap_or(0); |
65 | 76 | if addr >= start && addr < end { |
|
0 commit comments