Sha256: 29f20305a2df5badceeef1cd214a756e9ad19f9dc46a1cf2c495d8799c76fd81

Contents?: true

Size: 1.78 KB

Versions: 13

Compression:

Stored size: 1.78 KB

Contents

use object::read::{Object, ObjectSection};
use object::{read, write};
use object::{
    Architecture, BinaryFormat, Endianness, RelocationEncoding, RelocationFlags, 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,
                    symbol,
                    addend: 0,
                    flags: RelocationFlags::Generic {
                        kind: RelocationKind::Absolute,
                        encoding: RelocationEncoding::Generic,
                        size: 64,
                    },
                },
            )
            .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

13 entries across 13 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/object-0.36.7/tests/round_trip/coff.rs
wasmtime-28.0.0 ./ext/cargo-vendor/object-0.36.7/tests/round_trip/coff.rs
wasmtime-27.0.0 ./ext/cargo-vendor/object-0.36.5/tests/round_trip/coff.rs
wasmtime-26.0.0 ./ext/cargo-vendor/object-0.36.5/tests/round_trip/coff.rs
wasmtime-25.0.2 ./ext/cargo-vendor/object-0.36.3/tests/round_trip/coff.rs
wasmtime-25.0.1 ./ext/cargo-vendor/object-0.36.3/tests/round_trip/coff.rs
wasmtime-25.0.0 ./ext/cargo-vendor/object-0.36.3/tests/round_trip/coff.rs
wasmtime-24.0.0 ./ext/cargo-vendor/object-0.36.3/tests/round_trip/coff.rs
wasmtime-23.0.2 ./ext/cargo-vendor/object-0.36.3/tests/round_trip/coff.rs
wasmtime-22.0.0 ./ext/cargo-vendor/object-0.36.3/tests/round_trip/coff.rs
wasmtime-21.0.1 ./ext/cargo-vendor/object-0.33.0/tests/round_trip/coff.rs
wasmtime-20.0.2 ./ext/cargo-vendor/object-0.33.0/tests/round_trip/coff.rs
wasmtime-20.0.0 ./ext/cargo-vendor/object-0.33.0/tests/round_trip/coff.rs