-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbuild.rs
More file actions
29 lines (26 loc) · 1.25 KB
/
build.rs
File metadata and controls
29 lines (26 loc) · 1.25 KB
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
// Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0
extern crate build_common;
use build_common::generate_and_configure_header;
use std::env;
fn main() {
generate_and_configure_header("otel-thread-ctx.h");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
// Export the TLSDESC thread-local variable to the dynamic symbol table so
// external readers (e.g. the eBPF profiler) can locate it. Rust's cdylib
// linker applies a version script with `local: *` that hides all symbols
// not explicitly whitelisted, and also causes lld to relax the TLSDESC
// access to local-exec (LE), eliminating the dynsym entry entirely.
// Passing our own version script with an explicit `global:` entry for the
// symbol beats the `local: *` wildcard and prevents that relaxation.
//
// Merging multiple version scripts is not supported by GNU ld, so we also
// force lld explicitly.
if target_os == "linux" {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-cdylib-link-arg=-fuse-ld=lld");
println!(
"cargo:rustc-cdylib-link-arg=-Wl,--version-script={manifest_dir}/tls-dynamic-list.txt"
);
}
}