I was trying to debug a WIP port, so I compiled it with '-g -O0' on my
amd64 laptop. When trying to execute the binary, I got

$ ./lean
ksh: ./lean: Cannot allocate memory

mpi was able to pinpoint this to the following check in exec_elf.c:

 699                 case PT_OPENBSD_RANDOMIZE:
 700                         if (ph[i].p_memsz > randomizequota) {
 701                                 error = ENOMEM;
 702                                 goto bad;
 703                         }

so we got ENOMEM because some of the the program headers are too large.

$ readelf -l ./lean
Elf file type is DYN (Shared object file)
Entry point 0x4f4000
There are 11 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
                 0x0000000000000268 0x0000000000000268  R      8
  INTERP         0x00000000000002a8 0x00000000000002a8 0x00000000000002a8
                 0x0000000000000013 0x0000000000000013  R      1
      [Requesting program interpreter: /usr/libexec/ld.so]
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000004f3e24 0x00000000004f3e24  R      100000
  LOAD           0x00000000004f4000 0x00000000004f4000 0x00000000004f4000
                 0x0000000000c8da80 0x0000000000c8da80  R E    100000
  LOAD           0x0000000001182000 0x0000000001182000 0x0000000001182000
                 0x000000000014fae0 0x0000000000152030  RW     100000
  DYNAMIC        0x00000000012cd008 0x00000000012cd008 0x00000000012cd008
                 0x0000000000000160 0x0000000000000160  RW     8
  GNU_RELRO      0x0000000001185000 0x0000000001185000 0x0000000001185000
                 0x000000000014cae0 0x000000000014cae0  R      10
  GNU_EH_FRAME   0x000000000014c9c0 0x000000000014c9c0 0x000000000014c9c0
                 0x00000000000aba8c 0x00000000000aba8c  R      4
  OPENBSD_RANDOM 0x0000000001185000 0x0000000001185000 0x0000000001185000
                 0x000000000012c1a0 0x000000000012c1a0  RW     8
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     8
  NOTE           0x00000000000002bc 0x00000000000002bc 0x00000000000002bc
                 0x0000000000000018 0x0000000000000018  R      4

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .interp 
   02     .interp .note.openbsd.ident .dynsym .gnu.hash .hash .dynstr .rela.dyn 
.rela.plt .gcc_except_table .rodata .eh_frame_hdr .eh_frame 
   03     .text .init .fini .plt 
   04     .data .openbsd.randomdata .jcr .ctors .dtors .data.rel.ro .dynamic 
.got .got.plt .bss 
   05     .dynamic 
   06     .openbsd.randomdata .jcr .ctors .dtors .data.rel.ro .dynamic .got 
.got.plt 
   07     .eh_frame_hdr 
   08     .openbsd.randomdata 
   09     
   10     .note.openbsd.ident 

I'm not sure if this a bug or a feature, but if it happens to be a bug, the
binary (compiled with -current) and the ports makefile available under

        cvs:~tb:lean/{lean,lean.tgz}

Reply via email to