Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use build id to lookup debug symbols for libc >= 2.31 #285

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ strfmt = "0.1.6"
maplit = "1.0.2"
flate2 = "1.0.22"
zstd = "0.10.0"
version-compare = "0.1.0"
hex = "0.4.3"

[dependencies.reqwest]
version = "0.11.9"
Expand Down
22 changes: 22 additions & 0 deletions src/elf/build_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::elf;

use std::path::Path;

use ex::fs;
use snafu::ResultExt;

/// Get the build id of the given elf file
pub fn get_build_id(path: &Path) -> elf::parse::Result<String> {
let bytes = fs::read(path).context(elf::parse::ReadSnafu)?;
let elf = elf::parse(path, &bytes)?;

let mut iter = elf
.iter_note_sections(&bytes, Some(".note.gnu.build-id"))
.unwrap();
let section = iter
.next()
.unwrap()
.context(elf::parse::GoblinSnafu { path })?;

Ok(hex::encode(section.desc))
}
2 changes: 2 additions & 0 deletions src/elf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod build_id;
pub mod detect;
mod has_debug_syms;
pub mod parse;

pub use build_id::get_build_id;
pub use has_debug_syms::has_debug_syms;
pub use parse::parse;
17 changes: 15 additions & 2 deletions src/fetch_ld.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::cpu_arch::CpuArch;
use crate::libc_deb;
use crate::libc_version::LibcVersion;

use colored::Colorize;
use snafu::ResultExt;
use snafu::Snafu;
use version_compare::Cmp;

#[derive(Debug, Snafu)]
pub enum Error {
Expand All @@ -22,7 +24,18 @@ pub fn fetch_ld(ver: &LibcVersion) -> Result {
println!("{}", "fetching linker".green().bold());

let deb_file_name = format!("libc6_{}.deb", ver);
let ld_name = format!("ld-{}.so", ver.string_short);
libc_deb::write_ubuntu_pkg_file(&deb_file_name, &ld_name, &ld_name).context(DebSnafu)?;

let ld_name = if version_compare::compare_to(&ver.string_short, "2.34", Cmp::Lt).unwrap() {
format!("ld-{}.so", ver.string_short)
} else {
match ver.arch {
CpuArch::I386 => "ld-linux.so.2",
CpuArch::Amd64 => "ld-linux-x86-64.so.2",
}
.to_string()
};
let out_name = format!("ld-{}.so", ver.string_short);

libc_deb::write_ubuntu_pkg_file(&deb_file_name, &ld_name, &out_name).context(DebSnafu)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/solvepy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn make_bindings(opts: &Opts) -> String {
&opts.template_bin_name,
patch_bin::bin_patched_path(opts)
.as_ref()
.or_else(|| opts.bin.as_ref()),
.or(opts.bin.as_ref()),
),
bind_line(&opts.template_libc_name, opts.libc.as_ref()),
bind_line(&opts.template_ld_name, opts.ld.as_ref()),
Expand Down
8 changes: 7 additions & 1 deletion src/unstrip_libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ex::io;
use snafu::ResultExt;
use snafu::Snafu;
use tempfile::TempDir;
use version_compare::Cmp;

#[derive(Debug, Snafu)]
#[allow(clippy::enum_variant_names)]
Expand Down Expand Up @@ -57,7 +58,12 @@ fn do_unstrip_libc(libc: &Path, ver: &LibcVersion) -> Result {

let sym_path = tmp_dir.path().join("libc-syms");

let name = format!("libc-{}.so", ver.string_short);
let name = if version_compare::compare_to(&ver.string_short, "2.23", Cmp::Lt).unwrap() {
format!("libc-{}.so", ver.string_short)
} else {
let build_id = elf::get_build_id(libc).context(ElfParseSnafu)?;
build_id.chars().skip(2).collect::<String>() + ".debug"
};

libc_deb::write_ubuntu_pkg_file(&deb_file_name, &name, &sym_path).context(DebSnafu)?;

Expand Down