Sha256: 8a25aab7164a5c8aa7a21279f8bae1f4d5f68a8d09c29a4ecd0d0c14564851cc

Contents?: true

Size: 1.68 KB

Versions: 36

Compression:

Stored size: 1.68 KB

Contents

use object::read::{Object, ObjectSection};
use object::{read, write};
use object::{
    Architecture, BinaryFormat, Endianness, RelocationEncoding, RelocationKind, SymbolFlags,
    SymbolKind, SymbolScope,
};

#[test]
fn reloc_overflow() {
    let mut object =
        write::Object::new(BinaryFormat::Coff, Architecture::X86_64, Endianness::Little);
    let text = object.section_id(write::StandardSection::Text);
    object.append_section_data(text, &[0; 4], 4);
    let symbol = object.add_symbol(write::Symbol {
        name: b"f".to_vec(),
        value: 0,
        size: 4,
        kind: SymbolKind::Text,
        scope: SymbolScope::Linkage,
        weak: false,
        section: write::SymbolSection::Section(text),
        flags: SymbolFlags::None,
    });
    for i in 0..0x10000 {
        object
            .add_relocation(
                text,
                write::Relocation {
                    offset: i,
                    size: 64,
                    kind: RelocationKind::Absolute,
                    encoding: RelocationEncoding::Generic,
                    symbol,
                    addend: 0,
                },
            )
            .unwrap();
    }
    let bytes = object.write().unwrap();

    //std::fs::write(&"reloc_overflow.o", &bytes).unwrap();

    let object = read::File::parse(&*bytes).unwrap();
    assert_eq!(object.format(), BinaryFormat::Coff);
    assert_eq!(object.architecture(), Architecture::X86_64);

    let section = object.sections().next().unwrap();
    assert_eq!(section.name(), Ok(".text"));

    let mut i = 0;
    for (offset, _relocation) in section.relocations() {
        assert_eq!(offset, i);
        i += 1;
    }
    assert_eq!(i, 0x10000);
}

Version data entries

36 entries across 30 versions & 1 rubygems

Version Path
wasmtime-23.0.2 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-22.0.0 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-21.0.1 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-20.0.2 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-20.0.0 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-18.0.3 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-17.0.1 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-17.0.0 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-16.0.0 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-15.0.1 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-15.0.0 ./ext/cargo-vendor/object-0.32.2/tests/round_trip/coff.rs
wasmtime-14.0.4 ./ext/cargo-vendor/object-0.32.1/tests/round_trip/coff.rs
wasmtime-14.0.3 ./ext/cargo-vendor/object-0.32.1/tests/round_trip/coff.rs
wasmtime-14.0.1 ./ext/cargo-vendor/object-0.32.1/tests/round_trip/coff.rs
wasmtime-14.0.0 ./ext/cargo-vendor/object-0.32.1/tests/round_trip/coff.rs
wasmtime-13.0.0 ./ext/cargo-vendor/object-0.32.0/tests/round_trip/coff.rs
wasmtime-12.0.1 ./ext/cargo-vendor/object-0.31.1/tests/round_trip/coff.rs
wasmtime-12.0.1 ./ext/cargo-vendor/object-0.32.0/tests/round_trip/coff.rs
wasmtime-12.0.0 ./ext/cargo-vendor/object-0.32.0/tests/round_trip/coff.rs
wasmtime-12.0.0 ./ext/cargo-vendor/object-0.31.1/tests/round_trip/coff.rs