ELF program header offset
I write an executable ELF header+program header manually like this:

    elf_head:
    e_ident db      7Fh, 'ELF', 1, 1, 1
            times   9 db 0
    e_type  dw      2                       ; ET_EXEC
    e_mach  dw      3                       ; EM_386
    e_ver   dd      1                       ; EV_CURRENT
    e_entry dd      0x08048000+elf_head_len ; entry point
    e_phoff dd      34h                     ; program header table offset
    e_shoff dd      00h                     ; section header table offset
    e_flags dd      0                       ; flags
    e_elfhs dw      34h                     ; ELF header size
    e_phes  dw      20h                     ; program header entry size
    e_phec  dw      01h                     ; program header entries count
    e_shes  dw      00h                     
    e_shec  dw      00h                    
    e_shsn  dw      00h                     
    elf_head_len  equ  $ - elf_head
    elf_ph:
    p_type  dd      01h                     ; PT_LOAD
    p_off   dd      elf_head_len+e_phes         
    p_vaddr dd      0x08048000+elf_head_len 
    p_paddr dd      0x08048000+elf_head_len 
    p_filsz dd      elf_head_len+file_len           
    p_memsz dd      elf_head_len+file_len      
    p_flags dd      7                       ; segment flags (RWX)
    p_align dd      0x1000                  ; page_size==4096bytes

I set up the e_entry field point right after the p_align field where i put my code in the file being created. But it doesn't work! I am a little confused with the p_offset field. I put there an offset from the start of the file (0x00) until the first byte of segment's code. Since the segment's code start right after p_align field, do i enter correctly the value elf_head_len+e_phes ? When i try to run the new created executable, bash responds: killed!


ELF program header offset
===

I write an executable ELF header+program header manually like this:

    elf_head:
    e_ident db      7Fh, 'ELF', 1, 1, 1
            times   9 db 0
    e_type  dw      2                       ; ET_EXEC
    e_mach  dw      3                       ; EM_386
    e_ver   dd      1                       ; EV_CURRENT
    e_entry dd      0x08048000+elf_head_len ; entry point
    e_phoff dd      34h                     ; program header table offset
    e_shoff dd      00h                     ; section header table offset
    e_flags dd      0                       ; flags
    e_elfhs dw      34h                     ; ELF header size
    e_phes  dw      20h                     ; program header entry size
    e_phec  dw      01h                     ; program header entries count
    e_shes  dw      00h                     
    e_shec  dw      00h                    
    e_shsn  dw      00h                     
    elf_head_len  equ  $ - elf_head
    elf_ph:
    p_type  dd      01h                     ; PT_LOAD
    p_off   dd      elf_head_len+e_phes         
    p_vaddr dd      0x08048000+elf_head_len 
    p_paddr dd      0x08048000+elf_head_len 
    p_filsz dd      elf_head_len+file_len           
    p_memsz dd      elf_head_len+file_len      
    p_flags dd      7                       ; segment flags (RWX)
    p_align dd      0x1000                  ; page_size==4096bytes

I set up the e_entry field point right after the p_align field where i put my code in the file being created. But it doesn't work! I am a little confused with the p_offset field. I put there an offset from the start of the file (0x00) until the first byte of segment's code. Since the segment's code start right after p_align field, do i enter correctly the value elf_head_len+e_phes ? When i try to run the new created executable, bash responds: killed!

