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

Flag ELF32 as unsupported #912

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
24 changes: 9 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ jobs:
env:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install required tools
run: sudo apt-get install -y llvm-14 libelf-dev zlib1g-dev
- name: Install development dependencies
run: sudo apt-get install -y llvm-14 gcc-multilib libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: Check incremental rebuilds
Expand All @@ -170,8 +170,8 @@ jobs:
env:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install required tools
run: sudo apt-get install -y llvm-14 libelf-dev zlib1g-dev
- name: Install development dependencies
run: sudo apt-get install -y llvm-14 gcc-multilib libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -255,10 +255,8 @@ jobs:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install development dependencies
run: sudo apt-get install -y libelf-dev zlib1g-dev
run: sudo apt-get install -y llvm-14 libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- name: Install required tools
run: sudo apt-get install -y llvm-14
- uses: dtolnay/rust-toolchain@stable
- run: cargo check --package=blazesym-dev --features=generate-unit-test-files
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -295,7 +293,7 @@ jobs:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install development dependencies
run: sudo apt-get install -y libelf-dev zlib1g-dev
run: sudo apt-get install -y gcc-multilib libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -323,10 +321,8 @@ jobs:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install development dependencies
run: sudo apt-get install -y libelf-dev zlib1g-dev
run: sudo apt-get install -y llvm-14 gcc-multilib libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- name: Install required tools
run: sudo apt-get install -y llvm-14
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --workspace --release
Expand Down Expand Up @@ -363,7 +359,7 @@ jobs:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install development dependencies
run: sudo apt-get install -y libelf-dev zlib1g-dev
run: sudo apt-get install -y gcc-multilib libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo run --example backtrace
Expand Down Expand Up @@ -391,11 +387,9 @@ jobs:
LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-14
steps:
- name: Install development dependencies
run: sudo apt-get install -y libelf-dev zlib1g-dev
run: sudo apt-get install -y llvm-14 gcc-multilib libelf-dev zlib1g-dev
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: Install required tools
run: sudo apt-get install -y llvm-14
- name: Run benchmarks
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions dev/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ fn prepare_test_files() {
);

cc_test_so("libtest-so.so", &["-Wl,--build-id=sha1"]);
cc_test_so("libtest-so-32.so", &["-m32"]);
cc_test_so(
"libtest-so-no-separate-code.so",
&["-Wl,--build-id=md5,-z,noseparate-code"],
Expand Down
14 changes: 14 additions & 0 deletions src/elf/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use super::types::Elf64_Ehdr;
use super::types::Elf64_Phdr;
use super::types::Elf64_Shdr;
use super::types::Elf64_Sym;
use super::types::ELFCLASS32;
use super::types::ELFCLASS64;
use super::types::ELFCOMPRESS_ZLIB;
use super::types::ELFCOMPRESS_ZSTD;
use super::types::PN_XNUM;
Expand Down Expand Up @@ -305,6 +307,18 @@ impl<'mmap> Cache<'mmap> {
)))
}

// At this point we only support ELF64.
let class = ehdr.e_ident[4];
if class != ELFCLASS64 {
let class_str = match class {
ELFCLASS32 => Cow::Borrowed("ELF32"),
_ => Cow::Owned(class.to_string()),
};
return Err(Error::with_unsupported(format!(
"ELF class ({class_str}) is not currently supported"
)))
}

// "If the number of entries in the section header table is larger than
// or equal to SHN_LORESERVE, e_shnum holds the value zero and the real
// number of entries in the section header table is held in the sh_size
Expand Down
5 changes: 5 additions & 0 deletions src/elf/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type Elf64_Xword = u64;
pub(crate) const ET_EXEC: u16 = 2;
pub(crate) const ET_DYN: u16 = 3;

pub(crate) const ELFCLASSNONE: u8 = 0;
pub(crate) const ELFCLASS32: u8 = 1;
pub(crate) const ELFCLASS64: u8 = 2;


#[derive(Debug)]
#[repr(C)]
pub(crate) struct Elf64_Ehdr {
Expand Down
24 changes: 24 additions & 0 deletions tests/suite/symbolize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ fn error_on_non_existent_source() {
}
}

/// Test that we error out as expected when attempting to symbolize
/// addresses in an ELF32 binary.
#[tag(other_os)]
#[test]
fn error_elf32() {
let path = Path::new(&env!("CARGO_MANIFEST_DIR"))
.join("data")
.join("libtest-so-32.so");

let elf = Elf::new(path);
let src = Source::Elf(elf);
let symbolizer = Symbolizer::default();

let err = symbolizer
.symbolize_single(&src, Input::VirtOffset(0x2000100))
.unwrap_err();
assert!(
err.to_string()
.starts_with("ELF class (ELF32) is not currently supported"),
"{err}"
);
assert_eq!(err.kind(), ErrorKind::Unsupported);
}

/// Check that we can symbolize an address using ELF, DWARF, and GSYM.
#[tag(other_os)]
#[test]
Expand Down