2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
4 # RUN: ld.lld -o %t.out %t --oformat=binary
5 # RUN: od -t x1 -v %t.out | FileCheck %s
6 # CHECK: 0000000 90 11 22
9 ## OUTPUT_FORMAT(binary) selects the binary format as well.
10 # RUN: echo "OUTPUT_FORMAT(binary)" > %t.script
11 # RUN: ld.lld -o %t2.out -T %t.script %t
12 # RUN: od -t x1 -v %t2.out | FileCheck %s
13 ## More OUTPUT_FORMAT commands are ignored.
14 # RUN: echo "OUTPUT_FORMAT("binary")OUTPUT_FORMAT(elf64-x86-64)" > %t.script
15 # RUN: ld.lld -o %t2.out -T %t.script %t
16 # RUN: od -t x1 -v %t2.out | FileCheck %s
18 ## --oformat=binary overrides an ELF OUTPUT_FORMAT.
19 # RUN: echo "OUTPUT_FORMAT(elf64-x86-64) SECTIONS { . = 0x1000; }" > %t.script
20 # RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary
21 # RUN: od -t x1 -v %t2.out | FileCheck %s
23 # RUN: echo "SECTIONS { }" > %t.script
24 # RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary
25 # RUN: od -t x1 -v %t2.out | FileCheck %s
27 ## LMA(.text)=0x100, LMA(.mysec)=0x108. The minimum LMA of all non-empty sections is 0x100.
28 ## We place an output section at its LMA minus 0x100.
29 # RUN: echo 'SECTIONS { .text 0x100 : {*(.text)} .mysec ALIGN(8) : {*(.mysec*)} }' > %talign.lds
30 # RUN: ld.lld -T %talign.lds %t --oformat binary -o %talign
31 # RUN: od -Ax -t x1 %talign | FileCheck %s --check-prefix=ALIGN --ignore-case
33 # ALIGN: 000000 90 00 00 00 00 00 00 00 11 22
36 ## The empty section .data is ignored when computing the file size.
37 # RUN: echo 'SECTIONS { .text : {*(.text .mysec*)} .data 0x100 : {keep = .;}}' > %tempty.lds
38 # RUN: ld.lld -T %tempty.lds %t --oformat binary -o %tempty
39 # RUN: od -t x1 %tempty | FileCheck %s
41 ## NOBITS sections are ignored as well.
42 ## Also test that SIZEOF_HEADERS evaluates to 0.
43 # RUN: echo 'SECTIONS { .text : {. += SIZEOF_HEADERS; *(.text .mysec*)} .data 0x100 (NOLOAD) : {BYTE(0)}}' > %tnobits.lds
44 # RUN: ld.lld -T %tnobits.lds %t --oformat binary -o %tnobits
45 # RUN: od -t x1 %tnobits | FileCheck %s
47 ## FIXME .mysec should be placed at file offset 1.
48 ## This does not work because for a section without PT_LOAD, we consider LMA = VMA.
49 # RUN: echo 'SECTIONS { .text : {*(.text)} .mysec 0x8 : AT(1) {*(.mysec*)} }' > %tlma.lds
50 # RUN: ld.lld -T %tlma.lds %t --oformat binary -o %tlma
51 # RUN: od -Ax -t x1 %tlma | FileCheck %s --check-prefix=ALIGN --ignore-case
53 # RUN: not ld.lld -o /dev/null %t --oformat foo 2>&1 \
54 # RUN: | FileCheck %s --check-prefix ERR
55 # ERR: unknown --oformat value: foo
57 # RUN: echo "OUTPUT_FORMAT(binary-freebsd)" > %t.script
58 # RUN: not ld.lld -T %t.script %t -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
59 # ERR2: error: {{.*}}.script:1: unknown output format name: binary-freebsd
61 # RUN: ld.lld -o /dev/null %t --oformat elf
62 # RUN: ld.lld -o /dev/null %t --oformat=elf-foo
70 .section .mysec.1,"ax"
73 .section .mysec.2,"ax"