From 8a4f4dbcd1168be57169f0ed0eb7a5d45d132426 Mon Sep 17 00:00:00 2001 From: Edmund Kump Date: Tue, 3 Mar 2026 15:08:51 -0500 Subject: [PATCH 1/2] set the LC_ID_DYLIB for mac binaries to set correct name for linking --- builder/src/arch/apple.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builder/src/arch/apple.rs b/builder/src/arch/apple.rs index 63bd18a7dc..12629b23cb 100644 --- a/builder/src/arch/apple.rs +++ b/builder/src/arch/apple.rs @@ -15,7 +15,12 @@ pub const PROF_DYNAMIC_LIB_FFI: &str = "libdatadog_profiling_ffi.dylib"; pub const PROF_STATIC_LIB_FFI: &str = "libdatadog_profiling_ffi.a"; pub const REMOVE_RPATH: bool = true; pub const BUILD_CRASHTRACKER: bool = true; -pub const RUSTFLAGS: [&str; 2] = ["-C", "relocation-model=pic"]; +pub const RUSTFLAGS: [&str; 4] = [ + "-C", + "relocation-model=pic", + "-C", + "link-arg=-Wl,-install_name,@rpath/libdatadog_profiling.dylib", +]; pub fn fix_rpath(lib_path: &str) { if REMOVE_RPATH { From cfd13f8de6ad4411e97c7eee8b921ceed7403f81 Mon Sep 17 00:00:00 2001 From: Edmund Kump Date: Tue, 3 Mar 2026 15:18:37 -0500 Subject: [PATCH 2/2] remove dead code around post-build binary renaming --- builder/src/arch/apple.rs | 27 --------------------------- builder/src/arch/linux.rs | 13 ------------- builder/src/arch/musl.rs | 11 ----------- builder/src/arch/windows.rs | 2 -- builder/src/bin/release.rs | 1 - builder/src/builder.rs | 13 ------------- 6 files changed, 67 deletions(-) diff --git a/builder/src/arch/apple.rs b/builder/src/arch/apple.rs index 12629b23cb..c40d17c67b 100644 --- a/builder/src/arch/apple.rs +++ b/builder/src/arch/apple.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 use std::ffi::OsStr; -use std::os::unix::process::ExitStatusExt; use std::process::Command; use crate::utils::wait_for_success; @@ -13,7 +12,6 @@ pub const PROF_DYNAMIC_LIB: &str = "libdatadog_profiling.dylib"; pub const PROF_STATIC_LIB: &str = "libdatadog_profiling.a"; pub const PROF_DYNAMIC_LIB_FFI: &str = "libdatadog_profiling_ffi.dylib"; pub const PROF_STATIC_LIB_FFI: &str = "libdatadog_profiling_ffi.a"; -pub const REMOVE_RPATH: bool = true; pub const BUILD_CRASHTRACKER: bool = true; pub const RUSTFLAGS: [&str; 4] = [ "-C", @@ -22,31 +20,6 @@ pub const RUSTFLAGS: [&str; 4] = [ "link-arg=-Wl,-install_name,@rpath/libdatadog_profiling.dylib", ]; -pub fn fix_rpath(lib_path: &str) { - if REMOVE_RPATH { - let lib_name = lib_path.split('/').next_back().unwrap(); - - let exit_status = Command::new("install_name_tool") - .arg("-id") - .arg("@rpath/".to_string() + lib_name) - .arg(lib_path) - .status() - .expect("Failed to fix rpath using install_name_tool"); - match exit_status.code() { - Some(0) => {} - Some(rc) => panic!("Failed to fix rpath using install_name_tool: return code {rc}"), - None => match exit_status.signal() { - Some(sig) => { - panic!("Failed to fix rpath using install_name_tool: killed by signal {sig}") - } - None => panic!( - "Failed to fix rpath using install_name_tool: exit status {exit_status:?}" - ), - }, - } - } -} - pub fn strip_libraries(lib_path: &str) { // objcopy is not available in macos image. Investigate llvm-objcopy let strip = Command::new("strip") diff --git a/builder/src/arch/linux.rs b/builder/src/arch/linux.rs index f6e0eb7db7..65fa738355 100644 --- a/builder/src/arch/linux.rs +++ b/builder/src/arch/linux.rs @@ -11,7 +11,6 @@ pub const PROF_DYNAMIC_LIB: &str = "libdatadog_profiling.so"; pub const PROF_STATIC_LIB: &str = "libdatadog_profiling.a"; pub const PROF_DYNAMIC_LIB_FFI: &str = "libdatadog_profiling_ffi.so"; pub const PROF_STATIC_LIB_FFI: &str = "libdatadog_profiling_ffi.a"; -pub const REMOVE_RPATH: bool = false; pub const BUILD_CRASHTRACKER: bool = true; pub const RUSTFLAGS: [&str; 4] = [ "-C", @@ -20,18 +19,6 @@ pub const RUSTFLAGS: [&str; 4] = [ "link-arg=-Wl,-soname,libdatadog_profiling.so", ]; -pub fn fix_rpath(lib_path: &str) { - if REMOVE_RPATH { - let patchelf = Command::new("patchelf") - .arg("--remove-rpath") - .arg(lib_path) - .spawn() - .expect("failed to spawn patchelf"); - - wait_for_success(patchelf, "patchelf"); - } -} - pub fn strip_libraries(lib_path: &str) { let rm_section = Command::new("objcopy") .arg("--remove-section") diff --git a/builder/src/arch/musl.rs b/builder/src/arch/musl.rs index 794d13b47f..684b0c1f3b 100644 --- a/builder/src/arch/musl.rs +++ b/builder/src/arch/musl.rs @@ -11,7 +11,6 @@ pub const PROF_DYNAMIC_LIB: &str = "libdatadog_profiling.so"; pub const PROF_STATIC_LIB: &str = "libdatadog_profiling.a"; pub const PROF_DYNAMIC_LIB_FFI: &str = "libdatadog_profiling_ffi.so"; pub const PROF_STATIC_LIB_FFI: &str = "libdatadog_profiling_ffi.a"; -pub const REMOVE_RPATH: bool = false; pub const BUILD_CRASHTRACKER: bool = true; pub const RUSTFLAGS: [&str; 4] = [ "-C", @@ -20,16 +19,6 @@ pub const RUSTFLAGS: [&str; 4] = [ "link-arg=-Wl,-soname,libdatadog_profiling.so", ]; -pub fn fix_rpath(lib_path: &str) { - if REMOVE_RPATH { - Command::new("patchelf") - .arg("--remove-rpath") - .arg(lib_path) - .spawn() - .expect("failed to remove rpath"); - } -} - pub fn strip_libraries(lib_path: &str) { let rm_section = Command::new("objcopy") .arg("--remove-section") diff --git a/builder/src/arch/windows.rs b/builder/src/arch/windows.rs index de50397d79..1d9313817f 100644 --- a/builder/src/arch/windows.rs +++ b/builder/src/arch/windows.rs @@ -12,7 +12,6 @@ pub const PROF_PDB: &str = "datadog_profiling.pdb"; pub const PROF_DYNAMIC_LIB_FFI: &str = "datadog_profiling_ffi.dll"; pub const PROF_STATIC_LIB_FFI: &str = "datadog_profiling_ffi.lib"; pub const PROF_PDB_FFI: &str = "datadog_profiling_ffi.pdb"; -pub const REMOVE_RPATH: bool = false; pub const BUILD_CRASHTRACKER: bool = false; pub const RUSTFLAGS: [&str; 4] = [ "-C", @@ -21,7 +20,6 @@ pub const RUSTFLAGS: [&str; 4] = [ "target-feature=+crt-static", ]; -pub fn fix_rpath(_lib_path: &str) {} pub fn strip_libraries(_lib_path: &str) {} pub fn add_additional_files(lib_path: &str, target_path: &OsStr) { diff --git a/builder/src/bin/release.rs b/builder/src/bin/release.rs index e4244287a5..dc0d972cf6 100644 --- a/builder/src/bin/release.rs +++ b/builder/src/bin/release.rs @@ -124,7 +124,6 @@ pub fn main() { let res = builder.build(); match res { Ok(_) => { - builder.sanitize_libraries(); // Note: tar creation is handled by CI, not by this binary } Err(err) => panic!("{}", format!("Building failed: {err}")), diff --git a/builder/src/builder.rs b/builder/src/builder.rs index 3363d18437..5e691e2280 100644 --- a/builder/src/builder.rs +++ b/builder/src/builder.rs @@ -123,19 +123,6 @@ impl Builder { .expect("Failed to create include directory"); } - // TODO: maybe do this in module's build.rs - pub fn sanitize_libraries(&self) { - let datadog_lib_dir = Path::new(self.source_lib.as_ref()); - - let libs = fs::read_dir(datadog_lib_dir).unwrap(); - for lib in libs.flatten() { - let name = lib.file_name().into_string().unwrap(); - if name.ends_with(".so") { - arch::fix_rpath(lib.path().to_str().unwrap()); - } - } - } - pub fn add_cmake(&self) { let libs = arch::NATIVE_LIBS.to_owned(); let cmake_dir: PathBuf = [&self.target_dir, "cmake"].iter().collect();