sgx-lkl icon indicating copy to clipboard operation
sgx-lkl copied to clipboard

Docker Hub's statically linked hello-world fails with "Exec format error"

Open letmaik opened this issue 5 years ago • 1 comments

I'm not sure if this will ever work, but at least we know. The hello-world image contains a hello program that's fully statically linked (uses musl).

docker pull hello-world
docker run --rm hello-world
sgx-lkl-disk create --size=10M --docker=hello-world hello-world.img
sgx-lkl-cfg create --disk hello-world.img --host-cfg host-cfg.json --app-cfg app-cfg.json
sgx-lkl-run-oe --host-config=host-cfg.json --app-config=app-cfg.json --hw-debug

Output:

[[  SGX-LKL ]] ERROR: Failed to map /hello: Exec format error

Diagnostics:

$ readelf -a tmp/hello
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x401054
  Start of program headers:          64 (bytes into file)
  Start of section headers:          12440 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         14
  Section header string table index: 13

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .note.gnu.propert NOTE             00000000004001c8  000001c8
       0000000000000020  0000000000000000   A       0     0     8
  [ 2] .init             PROGBITS         0000000000401000  00001000
       0000000000000003  0000000000000000  AX       0     0     1
  [ 3] .text             PROGBITS         0000000000401010  00001010
       0000000000000708  0000000000000000  AX       0     0     16
  [ 4] .fini             PROGBITS         0000000000401718  00001718
       0000000000000003  0000000000000000  AX       0     0     1
  [ 5] .rodata           PROGBITS         0000000000402000  00002000
       0000000000000332  0000000000000000   A       0     0     32
  [ 6] .eh_frame         PROGBITS         0000000000402338  00002338
       0000000000000034  0000000000000000   A       0     0     8
  [ 7] .init_array       INIT_ARRAY       0000000000403fe8  00002fe8
       0000000000000008  0000000000000008  WA       0     0     8
  [ 8] .fini_array       FINI_ARRAY       0000000000403ff0  00002ff0
       0000000000000008  0000000000000008  WA       0     0     8
  [ 9] .got              PROGBITS         0000000000403ff8  00002ff8
       0000000000000008  0000000000000000  WA       0     0     8
  [10] .got.plt          PROGBITS         0000000000404000  00003000
       0000000000000018  0000000000000008  WA       0     0     8
  [11] .data             PROGBITS         0000000000404018  00003018
       000000000000000c  0000000000000000  WA       0     0     8
  [12] .bss              NOBITS           0000000000404040  00003024
       0000000000000278  0000000000000000  WA       0     0     32
  [13] .shstrtab         STRTAB           0000000000000000  00003024
       0000000000000073  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x00000000000001e8 0x00000000000001e8  R      0x1000
  LOAD           0x0000000000001000 0x0000000000401000 0x0000000000401000
                 0x000000000000071b 0x000000000000071b  R E    0x1000
  LOAD           0x0000000000002000 0x0000000000402000 0x0000000000402000
                 0x000000000000036c 0x000000000000036c  R      0x1000
  LOAD           0x0000000000002fe8 0x0000000000403fe8 0x0000000000403fe8
                 0x000000000000003c 0x00000000000002d0  RW     0x1000
  NOTE           0x00000000000001c8 0x00000000004001c8 0x00000000004001c8
                 0x0000000000000020 0x0000000000000020  R      0x8
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10
  GNU_RELRO      0x0000000000002fe8 0x0000000000403fe8 0x0000000000403fe8
                 0x0000000000000018 0x0000000000000018  R      0x1

 Section to Segment mapping:
  Segment Sections...
   00     .note.gnu.property 
   01     .init .text .fini 
   02     .rodata .eh_frame 
   03     .init_array .fini_array .got .got.plt .data .bss 
   04     .note.gnu.property 
   05     
   06     .init_array .fini_array .got 

There is no dynamic section in this file.

There are no relocations in this file.

The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.

No version information found in this file.

Displaying notes found in: .note.gnu.property
  Owner                 Data size       Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0
      Properties: x86 ISA needed: i486

letmaik avatar Jun 12 '20 09:06 letmaik

The hello binary is statically linked (https://github.com/docker-library/hello-world/blob/9ef4804c28679a416a445397f9b2e2b105005151/Makefile#L20), and we don't know how to load this.

prp avatar Jun 13 '20 19:06 prp