Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(cli): bundle Go project sources with --include-source (#72458)

Catalin Irimie4aa2af930005
diff --git a/cli/Cargo.lock b/cli/Cargo.lock
index 608a6e44c240..f15680164c45 100644
--- a/cli/Cargo.lock
+++ b/cli/Cargo.lock
@@ -2095,6 +2095,7 @@ dependencies = [
"dirs",
"globset",
"inquire",
+ "libc",
"magic_string",
"miette",
"open",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 351898c9ff16..39e2ca8521c6 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -64,6 +64,9 @@ zstd = "0.13"
symbolic = { version = "12.12", features = ["debuginfo"] }
plist = "1"
+[target.'cfg(unix)'.dependencies]
+libc = "0.2"
+
[dev-dependencies]
test-log = "0.2.17"
diff --git a/cli/src/debug_symbols/mod.rs b/cli/src/debug_symbols/mod.rs
index c46e8063d6ee..d482252a963b 100644
--- a/cli/src/debug_symbols/mod.rs
+++ b/cli/src/debug_symbols/mod.rs
@@ -105,7 +105,8 @@ impl DebugSymbolFile {
/// Filter DWARF source paths for native (Rust/C/C++) builds: on top of the
/// shared system-path filters, drop registry/toolchain sources that aren't
-/// part of the user's project tree.
+/// part of the user's project tree. Go toolchain sources are already trimmed
+/// inside the shared extraction (see `filter_go_toolchain_sources`).
fn filter_native_source_paths(paths: &[String]) -> Vec<&str> {
source_bundle::filter_source_paths(paths)
.into_iter()
diff --git a/cli/src/dsym/source_bundle.rs b/cli/src/dsym/source_bundle.rs
index a936466b90c6..a97cc3649cd7 100644
--- a/cli/src/dsym/source_bundle.rs
+++ b/cli/src/dsym/source_bundle.rs
@@ -67,15 +67,25 @@ pub fn extract_source_paths_from_dwarf_bytes(dwarf_data: &[u8]) -> Result<Vec<St
let mut paths: HashSet<String> = HashSet::new();
+ let mut any_go = false;
for obj in archive.objects() {
let obj = obj?;
- // Pass 1: CU-only walk to derive the project root prefix.
- let cu_paths = collect_cu_main_files_gimli(&obj);
- let project_prefix = longest_common_prefix(&cu_paths);
+ // Pass 1: CU-only walk to derive the project root prefix. Go CUs are
+ // packages, not files: DW_AT_name is the package import path
+ // ("internal/godebug") and DW_AT_comp_dir is "." — they contribute
+ // nothing to the prefix (which cgo C/C++ CUs, when present, still
+ // provide). For Go the line table is the source of truth instead:
+ // on-disk (absolute) `.go`/`.s` paths are kept, and Go toolchain
+ // sources are trimmed after the walk. `-trimpath` builds record no
+ // absolute paths at all, so they yield nothing here by design.
+ let cu_info = collect_cu_main_files_gimli(&obj);
+ any_go |= cu_info.has_go;
+ let project_prefix = longest_common_prefix(&cu_info.main_files);
tracing::debug!(
- "CU main files: {:?} → project prefix: {:?}",
- cu_paths,
+ "CU main files: {:?} (go: {}) → project prefix: {:?}",
+ cu_info.main_files,
+ cu_info.has_go,
project_prefix
);
@@ -87,11 +97,17 @@ pub fn extract_source_paths_from_dwarf_bytes(dwarf_data: &[u8]) -> Result<Vec<St
if abs_path.is_empty() {
continue;
}
- // Only keep paths inside the project tree.
+ // Only keep paths inside the project tree, plus — for Go — files
+ // that pass the Go source gate (pure Go binaries derive no prefix;
+ // cgo binaries need the union to keep both languages' sources).
// If we couldn't derive a prefix fall back to keeping everything
// (the normal EXCLUDED_PREFIXES / EXCLUDED_SUBSTRINGS filters still apply).
let in_project = match &project_prefix {
- Some(prefix) => abs_path.starts_with(prefix.as_str()),
+ Some(prefix) => {
+ abs_path.starts_with(prefix.as_str())
+ || (cu_info.has_go && is_bundleable_go_source(&abs_path))
+ }
+ None if cu_info.has_go => is_bundleable_go_source(&abs_path),
None => true,
};
if in_project {
@@ -104,6 +120,9 @@ pub fn extract_source_paths_from_dwarf_bytes(dwarf_data: &[u8]) -> Result<Vec<St
let mut paths: Vec<String> = paths.into_iter().collect();
paths.sort();
+ if any_go {
+ paths = filter_go_toolchain_sources(paths);
+ }
for p in &paths {
tracing::debug!("DWARF source path: {}", p);
@@ -112,21 +131,105 @@ pub fn extract_source_paths_from_dwarf_bytes(dwarf_data: &[u8]) -> Result<Vec<St
Ok(paths)
}
+/// Whether a Go line-table path may be read from disk and bundled. Requires
+/// an absolute path (Unix, or drive-qualified for ELFs built on Windows) and
+/// a Go source extension: line-table entries are attacker-influenced —
+/// `//line` directives in any dependency name arbitrary files — so this keeps
+/// the reachable set to source files rather than, say, `/etc/passwd`.
+fn is_bundleable_go_source(path: &str) -> bool {
+ let absolute = path.starts_with('/')
+ || (path.len() > 2
+ && path.as_bytes()[0].is_ascii_alphabetic()
+ && path.as_bytes()[1] == b':'
+ && matches!(path.as_bytes()[2], b'/' | b'\\'));
+ // Compiler-normalized paths never contain dot components; a spoofed one
+ // could otherwise smuggle `..` into derived ZIP entry names (zip slip).
+ let normalized = !path
+ .split(['/', '\\'])
+ .any(|component| component == "." || component == "..");
+ absolute && normalized && (path.ends_with(".go") || path.ends_with(".s"))
+}
+
+/// Drop Go toolchain sources, keeping project code. Runs for any binary with
+/// Go CUs, on whichever upload path (ELF or dSYM) extracted the paths.
+///
+/// GOROOT gives no fixed marker to filter on — it lands wherever the
+/// toolchain was installed (/usr/local/go, homebrew Cellar, nix store). Every
+/// Go binary unconditionally compiles in the runtime package though, so a
+/// directory whose `src/runtime/` holds several of its always-present files
+/// is a GOROOT src root; everything under it is stdlib. Requiring multiple
+/// witness files keeps a project that merely contains a `src/runtime/`
+/// directory (or a single spoofed `//line` entry) from marking its own tree
+/// as stdlib — misdetection would only suppress source context, never leak
+/// anything. Matching happens on /-normalized copies so ELFs built on
+/// Windows (backslash-separated DWARF paths) hit the same filters.
+fn filter_go_toolchain_sources(paths: Vec<String>) -> Vec<String> {
+ const GOROOT_WITNESSES: &[&str] = &[
+ "runtime/proc.go",
+ "runtime/malloc.go",
+ "runtime/mgc.go",
+ "runtime/runtime2.go",
+ ];
+ let normalize = |p: &str| p.replace('\\', "/");
+ let normalized_set: HashSet<String> = paths.iter().map(|p| normalize(p)).collect();
+ let goroot_src_roots: Vec<String> = normalized_set
+ .iter()
+ .filter_map(|p| {
+ p.find("/src/runtime/proc.go")
+ .map(|i| p[..i + "/src/".len()].to_string())
+ })
+ .filter(|root| {
+ GOROOT_WITNESSES
+ .iter()
+ .all(|w| normalized_set.contains(&format!("{root}{w}")))
+ })
+ .collect();
+
+ paths
+ .into_iter()
+ .filter(|path| {
+ let normalized = normalize(path);
+ // The module cache holds dependency sources, not project code.
+ if normalized.contains("/pkg/mod/") {
+ tracing::debug!("Filtered out (Go module cache): {}", path);
+ return false;
+ }
+ if goroot_src_roots
+ .iter()
+ .any(|root| normalized.starts_with(root.as_str()))
+ {
+ tracing::debug!("Filtered out (Go stdlib): {}", path);
+ return false;
+ }
+ true
+ })
+ .collect()
+}
+
+/// CU-level facts gathered without reading any line program.
+#[derive(Default)]
+struct CuInfo {
+ /// Resolved absolute paths of each CU's main file (non-Go CUs only).
+ main_files: Vec<String>,
+ /// Whether any CU is Go (`DW_AT_language == DW_LANG_Go`).
+ has_go: bool,
+}
+
/// Walk only `DW_TAG_compile_unit` root DIEs via gimli (no line table) and
/// return the resolved absolute path of the main file for each CU.
///
/// This deliberately does **not** read the line-number program, so cross-module
/// file references that appear there (e.g. type-declaration sites in imported
/// frameworks) are never included.
-fn collect_cu_main_files_gimli(obj: &Object<'_>) -> Vec<String> {
+fn collect_cu_main_files_gimli(obj: &Object<'_>) -> CuInfo {
match obj {
Object::MachO(m) => cu_main_files_from_dwarf(m),
Object::Elf(e) => cu_main_files_from_dwarf(e),
- _ => Vec::new(),
+ _ => CuInfo::default(),
}
}
-fn cu_main_files_from_dwarf<'d>(obj: &impl DwarfObject<'d>) -> Vec<String> {
+fn cu_main_files_from_dwarf<'d>(obj: &impl DwarfObject<'d>) -> CuInfo {
let empty: &[u8] = &[];
let info_data = obj
@@ -195,7 +298,7 @@ fn cu_main_files_from_dwarf<'d>(obj: &impl DwarfObject<'d>) -> Vec<String> {
}
};
- let mut out = Vec::new();
+ let mut out = CuInfo::default();
let mut iter = dwarf.units();
loop {
let header = match iter.next() {
@@ -221,6 +324,16 @@ fn cu_main_files_from_dwarf<'d>(obj: &impl DwarfObject<'d>) -> Vec<String> {
continue;
}
+ // Go CU names are package import paths, not source files — record the
+ // language and skip them so they never poison the project prefix.
+ if matches!(
+ root.attr_value(gimli::DW_AT_language),
+ Ok(Some(gimli::AttributeValue::Language(gimli::DW_LANG_Go)))
+ ) {
+ out.has_go = true;
+ continue;
+ }
+
let comp_dir: Option<String> = root
.attr_value(gimli::DW_AT_comp_dir)
.ok()
@@ -249,12 +362,12 @@ fn cu_main_files_from_dwarf<'d>(obj: &impl DwarfObject<'d>) -> Vec<String> {
};
if !path.is_empty() {
- out.push(path);
+ out.main_files.push(path);
}
}
// Drop synthetic linker-generated names and system/DerivedData paths before
// returning so they never poison the project-root prefix computation.
- out.retain(|p| {
+ out.main_files.retain(|p| {
if EXCLUDED_SYNTHETIC_NAMES.iter().any(|s| p.starts_with(s)) {
return false;
}
@@ -269,6 +382,61 @@ fn cu_main_files_from_dwarf<'d>(obj: &impl DwarfObject<'d>) -> Vec<String> {
out
}
+/// Read one DWARF-named source file. Such paths are only expected to be
+/// source files, but a hostile or corrupt entry can point anywhere, so:
+/// symlinks are refused (a compiler records the file it read, not a link —
+/// and a link named `legit.go` could target a credential file), the checks
+/// run against the opened handle's metadata so the file can't be swapped
+/// between check and read, non-regular files (devices, FIFOs) are refused,
+/// and reads are capped generously enough that even large generated sources
+/// (protobuf output, amalgamated C) are never clipped.
+fn read_source_file(path: &Path) -> std::io::Result<Vec<u8>> {
+ use std::io::{Error, ErrorKind, Read};
+
+ const MAX_SOURCE_FILE_BYTES: u64 = 64 * 1024 * 1024;
+
+ let err = |msg: &str| Err(Error::new(ErrorKind::InvalidInput, msg));
+ if fs::symlink_metadata(path)?.file_type().is_symlink() {
+ return err("path is a symlink");
+ }
+ let file = open_no_follow(path)?;
+ let meta = file.metadata()?;
+ if !meta.is_file() {
+ return err("not a regular file");
+ }
+ if meta.len() > MAX_SOURCE_FILE_BYTES {
+ return err("exceeds the source file size limit");
+ }
+
+ // Read one byte past the cap so a file that grew after the metadata
+ // check errors out rather than being silently truncated in the bundle.
+ let mut data = Vec::with_capacity(meta.len() as usize);
+ file.take(MAX_SOURCE_FILE_BYTES + 1)
+ .read_to_end(&mut data)?;
+ if data.len() as u64 > MAX_SOURCE_FILE_BYTES {
+ return err("exceeds the source file size limit");
+ }
+ Ok(data)
+}
+
+/// Open without following a symlink at the final component, so the symlink
+/// check above can't be raced by swapping the path between check and open.
+#[cfg(unix)]
+fn open_no_follow(path: &Path) -> std::io::Result<fs::File> {
+ use std::os::unix::fs::OpenOptionsExt;
+ fs::OpenOptions::new()
+ .read(true)
+ .custom_flags(libc::O_NOFOLLOW)
+ .open(path)
+}
+
+/// Windows has no O_NOFOLLOW equivalent in std; creating symlinks there
+/// requires elevated privileges, so the metadata pre-check has to do.
+#[cfg(not(unix))]
+fn open_no_follow(path: &Path) -> std::io::Result<fs::File> {
+ fs::File::open(path)
+}
+
/// Return the longest common directory prefix shared by all `paths`.
///
/// Only directory components are considered (the filename is stripped before
@@ -364,10 +532,16 @@ pub fn filter_source_paths(paths: &[String]) -> Vec<&str> {
paths
.iter()
.filter(|path| {
- // Exclude system prefixes
- if EXCLUDED_PREFIXES
- .iter()
- .any(|prefix| path.starts_with(prefix))
+ // Exclude system prefixes. Go sources are exempt: containerized
+ // Go builds commonly live under /usr/src (the official golang
+ // image's WORKDIR), and Go's own system trees — GOROOT wherever
+ // installed and the module cache — are already handled by
+ // filter_go_toolchain_sources.
+ let is_go_source = path.ends_with(".go") || path.ends_with(".s");
+ if !is_go_source
+ && EXCLUDED_PREFIXES
+ .iter()
+ .any(|prefix| path.starts_with(prefix))
{
tracing::debug!("Filtered out (prefix): {}", path);
return false;
@@ -402,8 +576,7 @@ pub fn collect_source_files(dwarf_paths: &[&str]) -> Result<SourceFiles> {
let zip_paths = build_zip_relative_paths(dwarf_paths);
for (dwarf_path, zip_rel_path) in dwarf_paths.iter().zip(zip_paths.iter()) {
- let path = Path::new(dwarf_path);
- match fs::read(path) {
+ match read_source_file(Path::new(dwarf_path)) {
Ok(data) => {
let zip_path = format!("__source/{}", zip_rel_path);
manifest_files.insert(dwarf_path.to_string(), zip_path.clone());
@@ -492,9 +665,15 @@ fn build_zip_relative_paths(paths: &[&str]) -> Vec<String> {
if indices.len() > 1 {
has_duplicates = true;
for &idx in indices {
- // Add one more parent component
- let components: Vec<&str> =
- paths[idx].split('/').filter(|s| !s.is_empty()).collect();
+ // Add one more parent component. Dot components are
+ // dropped: they never disambiguate, and a literal `..`
+ // would end up verbatim in a ZIP entry name, letting a
+ // crafted DWARF path escape the __source/ prefix on
+ // extraction (zip slip).
+ let components: Vec<&str> = paths[idx]
+ .split('/')
+ .filter(|s| !s.is_empty() && *s != "." && *s != "..")
+ .collect();
let current_depth = result[idx].matches('/').count() + 1;
let new_depth = (current_depth + 1).min(components.len());
let start = components.len().saturating_sub(new_depth);
@@ -540,3 +719,154 @@ pub fn load_sources_from_zip(
sources
}
+
+#[cfg(test)]
+mod tests {
+ use super::{
+ build_zip_relative_paths, filter_go_toolchain_sources, is_bundleable_go_source,
+ read_source_file,
+ };
+
+ #[test]
+ fn go_line_table_paths_are_gated_to_absolute_source_files() {
+ // On-disk source files, unix and drive-qualified.
+ assert!(is_bundleable_go_source("/home/u/app/main.go"));
+ assert!(is_bundleable_go_source("/home/u/app/asm_amd64.s"));
+ assert!(is_bundleable_go_source("C:/workspace/app/main.go"));
+ assert!(is_bundleable_go_source(r"C:\workspace\app\main.go"));
+
+ // Relative and synthetic entries can't be read from disk.
+ assert!(!is_bundleable_go_source("sync/once.go"));
+ assert!(!is_bundleable_go_source("<autogenerated>"));
+ assert!(!is_bundleable_go_source("?"));
+
+ // `//line` directives name arbitrary files; only source is bundleable.
+ assert!(!is_bundleable_go_source("/etc/passwd"));
+ assert!(!is_bundleable_go_source("/home/u/.ssh/id_rsa"));
+
+ // Dot components never appear in compiler-normalized paths and could
+ // smuggle `..` into ZIP entry names.
+ assert!(!is_bundleable_go_source("/a/../conflict.go"));
+ assert!(!is_bundleable_go_source("/a/./conflict.go"));
+ assert!(!is_bundleable_go_source(r"C:\a\..\conflict.go"));
+ }
+
+ #[test]
+ fn zip_entry_names_never_contain_dot_components() {
+ // Two same-basename paths force the collision loop to pull parent
+ // components into the entry name; a literal `..` there would escape
+ // the __source/ prefix on extraction.
+ let paths = ["/a/../conflict.go", "/a/b/conflict.go"];
+ for name in build_zip_relative_paths(&paths) {
+ assert!(
+ name.split('/')
+ .all(|c| c != ".." && c != "." && !c.is_empty()),
+ "zip entry name {name:?} contains a traversal component"
+ );
+ }
+ }
+
+ #[test]
+ fn symlinked_source_files_are_refused() {
+ let dir = tempfile::tempdir().unwrap();
+ let target = dir.path().join("secret");
+ std::fs::write(&target, "sensitive").unwrap();
+ let link = dir.path().join("legit.go");
+ #[cfg(unix)]
+ std::os::unix::fs::symlink(&target, &link).unwrap();
+ #[cfg(windows)]
+ std::os::windows::fs::symlink_file(&target, &link).unwrap();
+
+ assert!(read_source_file(&link).is_err());
+ assert_eq!(read_source_file(&target).unwrap(), b"sensitive");
+ }
+
+ fn goroot_witnesses(root: &str, sep: char) -> Vec<String> {
+ ["proc.go", "malloc.go", "mgc.go", "runtime2.go"]
+ .iter()
+ .map(|f| format!("{root}{sep}src{sep}runtime{sep}{f}"))
+ .collect()
+ }
+
+ #[test]
+ fn go_toolchain_sources_are_filtered_out() {
+ // GOROOT is recognized by its always-compiled runtime files,
+ // wherever installed.
+ let mut paths = goroot_witnesses("/nix/store/abc-go-1.25.5/share/go", '/');
+ paths.extend(goroot_witnesses(
+ "/opt/homebrew/Cellar/go/1.25.5/libexec",
+ '/',
+ ));
+ paths.extend(
+ [
+ "/home/u/app/main.go",
+ "/nix/store/abc-go-1.25.5/share/go/src/fmt/print.go",
+ "/opt/homebrew/Cellar/go/1.25.5/libexec/src/net/http/server.go",
+ // Module cache holds dependency sources, not project code.
+ "/home/u/go/pkg/mod/github.com/posthog/[email protected]/error_tracking.go",
+ ]
+ .into_iter()
+ .map(String::from),
+ );
+
+ assert_eq!(
+ filter_go_toolchain_sources(paths),
+ vec!["/home/u/app/main.go"]
+ );
+ }
+
+ #[test]
+ fn windows_built_binaries_hit_the_same_go_filters() {
+ let mut paths = goroot_witnesses(r"C:\go", '\\');
+ paths.extend(
+ [
+ r"C:\workspace\app\main.go",
+ r"C:\go\src\fmt\print.go",
+ r"C:\Users\u\go\pkg\mod\github.com\[email protected]\dep.go",
+ ]
+ .into_iter()
+ .map(String::from),
+ );
+
+ assert_eq!(
+ filter_go_toolchain_sources(paths),
+ vec![r"C:\workspace\app\main.go"]
+ );
+ }
+
+ #[test]
+ fn go_sources_under_usr_survive_the_system_prefix_filter() {
+ // The official golang Docker image builds under /usr/src/app; the
+ // /usr/ system-prefix rule must not empty those projects' bundles.
+ let paths: Vec<String> = [
+ "/usr/src/app/main.go",
+ "/usr/src/app/asm_amd64.s",
+ "/usr/include/stdio.h",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
+
+ assert_eq!(
+ super::filter_source_paths(&paths),
+ vec!["/usr/src/app/main.go", "/usr/src/app/asm_amd64.s"]
+ );
+ }
+
+ #[test]
+ fn projects_under_a_src_runtime_path_keep_their_sources() {
+ // A lone src/runtime/proc.go (project layout collision, or a spoofed
+ // //line entry) is not enough evidence of a GOROOT — all runtime
+ // witness files must be present.
+ let paths: Vec<String> = [
+ "/work/src/runtime/proc.go",
+ "/work/src/runtime/app/main.go",
+ "/work/src/api/server.go",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
+
+ assert_eq!(filter_go_toolchain_sources(paths.clone()), paths);
+ }
+}
diff --git a/cli/tests/debug_symbols.rs b/cli/tests/debug_symbols.rs
index 7879fc55ac7b..edf1e4661914 100644
--- a/cli/tests/debug_symbols.rs
+++ b/cli/tests/debug_symbols.rs
@@ -5,6 +5,7 @@ use posthog_cli::api::symbol_sets::SymbolSetUpload;
use posthog_cli::debug_symbols::{
dedup_uploads_by_chunk_id, discover, elf_debug_id, package_dsym_bundles, report_problems,
};
+use posthog_cli::dsym::source_bundle::extract_source_paths_from_dwarf_bytes;
use posthog_symbol_data::{read_symbol_data, AppleDsym, ElfDebugInfo};
/// The native ELF fixtures shared with cymbal's symbolication tests; built by
@@ -282,3 +283,53 @@ fn packages_elf_and_dsym_from_one_directory() {
"dSYM dwarf entry must be a Mach-O binary, not ELF"
);
}
+
+/// Go DWARF names CUs after package import paths ("main", "internal/godebug")
+/// with comp_dir "." — a project prefix derived from those rejects every real
+/// file. The extraction must instead surface the line table's absolute
+/// on-disk paths, which --include-source reads from the build machine.
+#[test]
+fn go_dwarf_source_extraction_uses_line_table_paths() {
+ let data = zstd::decode_all(
+ std::fs::read(fixtures_dir().join("test_go_binary_paths.zst"))
+ .unwrap()
+ .as_slice(),
+ )
+ .unwrap();
+
+ let paths = extract_source_paths_from_dwarf_bytes(&data).unwrap();
+ assert!(
+ paths.contains(&"/cymbal_tests/native/test_go.go".to_string()),
+ "project source missing from extraction: {paths:?}"
+ );
+ assert!(
+ paths.iter().all(|p| p.starts_with('/')),
+ "only on-disk (absolute) paths can be bundled"
+ );
+ assert!(
+ paths.iter().all(|p| !p.contains("/src/runtime/")),
+ "GOROOT stdlib sources must be filtered out: {paths:?}"
+ );
+ assert!(
+ paths
+ .iter()
+ .all(|p| p.ends_with(".go") || p.ends_with(".s")),
+ "only Go source files can be bundled: {paths:?}"
+ );
+}
+
+/// -trimpath strips every absolute path from Go DWARF, so there is nothing
+/// --include-source could read from disk; extraction must come back empty
+/// rather than bundling junk relative paths.
+#[test]
+fn go_trimpath_binaries_yield_no_bundleable_sources() {
+ let data = zstd::decode_all(
+ std::fs::read(fixtures_dir().join("test_go_binary.zst"))
+ .unwrap()
+ .as_slice(),
+ )
+ .unwrap();
+
+ let paths = extract_source_paths_from_dwarf_bytes(&data).unwrap();
+ assert_eq!(paths, Vec::<String>::new());
+}
diff --git a/rust/cymbal/tests/static/native/build.sh b/rust/cymbal/tests/static/native/build.sh
index 44d5b012f197..d1b53fd99461 100755
--- a/rust/cymbal/tests/static/native/build.sh
+++ b/rust/cymbal/tests/static/native/build.sh
@@ -68,6 +68,17 @@ GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-B gobuildid" -o test_go_bi
zstd -19 -f -q test_go_binary
rm test_go_binary
+# Go fixture with on-disk source paths: -trimpath strips the absolute paths
+# the CLI's --include-source bundling reads from disk, so this variant keeps
+# them, remapping only the project directory to the stable test prefix (the
+# baked-in GOROOT paths are machine-specific; tests must not assert on them).
+GOOS=linux GOARCH=amd64 go build -ldflags "-B gobuildid" \
+ -gcflags "all=-trimpath=$PWD=>/cymbal_tests/native" \
+ -asmflags "all=-trimpath=$PWD=>/cymbal_tests/native" \
+ -o test_go_binary_paths test_go.go
+zstd -19 -f -q test_go_binary_paths
+rm test_go_binary_paths
+
echo "Built fixtures:"
file test_binary_nopie test_binary_pie test_binary_inline test_binary_nodebug test_binary_nobuildid
-ls -la test_rust_binary.zst test_go_binary.zst
+ls -la test_rust_binary.zst test_go_binary.zst test_go_binary_paths.zst
diff --git a/rust/cymbal/tests/static/native/test_go_binary_paths.zst b/rust/cymbal/tests/static/native/test_go_binary_paths.zst
new file mode 100755
index 000000000000..2b97d3bb9801
Binary files /dev/null and b/rust/cymbal/tests/static/native/test_go_binary_paths.zst differ