oven-sh/bun · error · ElfError

NoWritableLoadSegment

NoWritableLoadSegment

Error message

NoWritableLoadSegment

What it means

ElfError variant: no PT_LOAD program-header entry with write permission exists in the executable. Appending the Bun section requires mapping it into a writable load segment; a read-only-only program header table (typical of fully stripped or unusual layouts) leaves nowhere to place it.

Solutions

  1. Link the target executable with a writable data segment (standard executables have one)
  2. Extend the ELF writer to add a new writable PT_LOAD segment when none exists
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/exe_format/elf.rs:31 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/8a256adfea6fcbad. Report an issue: GitHub.

Appendix: source

Thrown at src/exe_format/elf.rs:31

#[cfg(any(target_os = "linux", target_os = "android"))]
use bun_core::env_var;
use bun_core::{slice_to_nul, strings};

use crate::{align_up, read_struct, write_struct};

bun_core::declare_scope!(elf, visible);

#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
pub enum ElfError {
    #[error("InvalidElfFile")]
    InvalidElfFile,
    #[error("Not64Bit")]
    Not64Bit,
    #[error("NotLittleEndian")]
    NotLittleEndian,
    #[error("BunSectionNotFound")]
    BunSectionNotFound,
    #[error("NoWritableLoadSegment")]
    NoWritableLoadSegment,
    #[error("NewVaddrCollides")]
    NewVaddrCollides,
}

pub struct ElfFile {
    pub data: Vec<u8>,
}

impl ElfFile {
    pub fn init(data: Vec<u8>) -> Result<Box<ElfFile>, ElfError> {
        validate_elf64_le(&data)?;
        Ok(Box::new(ElfFile { data }))
    }

    /// If PT_INTERP points into a Nix/Guix store path, rewrite it to the
    /// standard FHS path so `bun build --compile` output stays portable when
    /// the bun binary itself was patchelf'd (NixOS autoPatchelfHook). See #24742.

View on GitHub (pinned to 8c5296ac45)