Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 1 | # REQUIRES: x86 |
| 2 | # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t |
| 3 | # RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \ |
| 4 | # RUN: SECTIONS { \ |
| 5 | # RUN: . = 0x10000200; \ |
George Rimar | 215dd47 | 2016-08-10 14:02:35 +0000 | [diff] [blame] | 6 | # RUN: .text : {*(.text*)} :all \ |
Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 7 | # RUN: .foo : {*(.foo.*)} :all \ |
| 8 | # RUN: .data : {*(.data.*)} :all}" > %t.script |
Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 9 | # RUN: ld.lld -o %t1 --script %t.script %t |
| 10 | # RUN: llvm-readobj -program-headers %t1 | FileCheck %s |
Eugene Leviant | 56b21c8 | 2016-09-09 09:46:16 +0000 | [diff] [blame] | 11 | |
Eugene Leviant | db35fdf | 2016-10-20 09:39:09 +0000 | [diff] [blame] | 12 | ## Check that program headers are not written, unless we explicitly tell |
| 13 | ## lld to do this. |
| 14 | # RUN: echo "PHDRS {all PT_LOAD;} \ |
| 15 | # RUN: SECTIONS { \ |
| 16 | # RUN: . = 0x10000200; \ |
| 17 | # RUN: /DISCARD/ : {*(.text*)} \ |
| 18 | # RUN: .foo : {*(.foo.*)} :all \ |
| 19 | # RUN: }" > %t.script |
| 20 | # RUN: ld.lld -o %t1 --script %t.script %t |
| 21 | # RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=NOPHDR %s |
| 22 | |
Eugene Leviant | 56b21c8 | 2016-09-09 09:46:16 +0000 | [diff] [blame] | 23 | ## Check the AT(expr) |
| 24 | # RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS AT(0x500 + 0x500) ;} \ |
| 25 | # RUN: SECTIONS { \ |
| 26 | # RUN: . = 0x10000200; \ |
| 27 | # RUN: .text : {*(.text*)} :all \ |
| 28 | # RUN: .foo : {*(.foo.*)} :all \ |
| 29 | # RUN: .data : {*(.data.*)} :all}" > %t.script |
| 30 | # RUN: ld.lld -o %t1 --script %t.script %t |
| 31 | # RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=AT %s |
| 32 | |
Eugene Leviant | ce30b1c | 2016-10-19 15:04:49 +0000 | [diff] [blame] | 33 | # RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \ |
| 34 | # RUN: SECTIONS { \ |
| 35 | # RUN: . = 0x10000200; \ |
| 36 | # RUN: .text : {*(.text*)} :all \ |
| 37 | # RUN: .foo : {*(.foo.*)} \ |
| 38 | # RUN: .data : {*(.data.*)} }" > %t.script |
| 39 | # RUN: ld.lld -o %t1 --script %t.script %t |
| 40 | # RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=DEFHDR %s |
| 41 | |
Eugene Leviant | 2a942c4 | 2016-12-05 16:38:32 +0000 | [diff] [blame] | 42 | ## Check that error is reported when trying to use phdr which is not listed |
| 43 | ## inside PHDRS {} block |
| 44 | ## TODO: If script doesn't contain PHDRS {} block then default phdr is always |
| 45 | ## created and error is not reported. |
| 46 | # RUN: echo "PHDRS { all PT_LOAD; } \ |
| 47 | # RUN: SECTIONS { .baz : {*(.foo.*)} :bar }" > %t.script |
| 48 | # RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s |
| 49 | |
Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 50 | # CHECK: ProgramHeaders [ |
| 51 | # CHECK-NEXT: ProgramHeader { |
| 52 | # CHECK-NEXT: Type: PT_LOAD (0x1) |
| 53 | # CHECK-NEXT: Offset: 0x0 |
| 54 | # CHECK-NEXT: VirtualAddress: 0x10000000 |
| 55 | # CHECK-NEXT: PhysicalAddress: 0x10000000 |
| 56 | # CHECK-NEXT: FileSize: 521 |
| 57 | # CHECK-NEXT: MemSize: 521 |
George Rimar | a14b13d | 2016-09-07 10:46:07 +0000 | [diff] [blame] | 58 | # CHECK-NEXT: Flags [ (0x7) |
Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 59 | # CHECK-NEXT: PF_R (0x4) |
George Rimar | a14b13d | 2016-09-07 10:46:07 +0000 | [diff] [blame] | 60 | # CHECK-NEXT: PF_W (0x2) |
Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 61 | # CHECK-NEXT: PF_X (0x1) |
| 62 | # CHECK-NEXT: ] |
| 63 | |
Eugene Leviant | db35fdf | 2016-10-20 09:39:09 +0000 | [diff] [blame] | 64 | # NOPHDR: ProgramHeaders [ |
| 65 | # NOPHDR-NEXT: ProgramHeader { |
| 66 | # NOPHDR-NEXT: Type: PT_LOAD (0x1) |
| 67 | # NOPHDR-NEXT: Offset: 0x200 |
| 68 | # NOPHDR-NEXT: VirtualAddress: 0x10000200 |
| 69 | # NOPHDR-NEXT: PhysicalAddress: 0x10000200 |
| 70 | # NOPHDR-NEXT: FileSize: 8 |
| 71 | # NOPHDR-NEXT: MemSize: 8 |
| 72 | # NOPHDR-NEXT: Flags [ (0x6) |
| 73 | # NOPHDR-NEXT: PF_R (0x4) |
| 74 | # NOPHDR-NEXT: PF_W (0x2) |
| 75 | # NOPHDR-NEXT: ] |
| 76 | # NOPHDR-NEXT: Alignment: 4096 |
| 77 | # NOPHDR-NEXT: } |
| 78 | # NOPHDR-NEXT: ] |
| 79 | |
Eugene Leviant | 56b21c8 | 2016-09-09 09:46:16 +0000 | [diff] [blame] | 80 | # AT: ProgramHeaders [ |
| 81 | # AT-NEXT: ProgramHeader { |
| 82 | # AT-NEXT: Type: PT_LOAD (0x1) |
| 83 | # AT-NEXT: Offset: 0x0 |
| 84 | # AT-NEXT: VirtualAddress: 0x10000000 |
| 85 | # AT-NEXT: PhysicalAddress: 0xA00 |
| 86 | # AT-NEXT: FileSize: 521 |
| 87 | # AT-NEXT: MemSize: 521 |
| 88 | # AT-NEXT: Flags [ (0x7) |
| 89 | # AT-NEXT: PF_R (0x4) |
| 90 | # AT-NEXT: PF_W (0x2) |
| 91 | # AT-NEXT: PF_X (0x1) |
| 92 | # AT-NEXT: ] |
| 93 | |
George Rimar | 95dd718 | 2016-10-18 10:49:50 +0000 | [diff] [blame] | 94 | ## Check the numetic values for PHDRS. |
| 95 | # RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x11223344; } \ |
Rafael Espindola | 3371398 | 2017-01-05 14:20:35 +0000 | [diff] [blame] | 96 | # RUN: SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.foo* .text*) } : text : foo}" > %t1.script |
George Rimar | 95dd718 | 2016-10-18 10:49:50 +0000 | [diff] [blame] | 97 | # RUN: ld.lld -o %t2 --script %t1.script %t |
| 98 | # RUN: llvm-readobj -program-headers %t2 | FileCheck --check-prefix=INT-PHDRS %s |
| 99 | |
| 100 | # INT-PHDRS: ProgramHeaders [ |
| 101 | # INT-PHDRS: ProgramHeader { |
| 102 | # INT-PHDRS: Type: (0x11223344) |
| 103 | # INT-PHDRS-NEXT: Offset: 0xB0 |
| 104 | # INT-PHDRS-NEXT: VirtualAddress: 0xB0 |
| 105 | # INT-PHDRS-NEXT: PhysicalAddress: 0xB0 |
George Rimar | 3fb5a6d | 2016-11-29 16:05:27 +0000 | [diff] [blame] | 106 | # INT-PHDRS-NEXT: FileSize: |
| 107 | # INT-PHDRS-NEXT: MemSize: |
George Rimar | 95dd718 | 2016-10-18 10:49:50 +0000 | [diff] [blame] | 108 | # INT-PHDRS-NEXT: Flags [ |
| 109 | # INT-PHDRS-NEXT: PF_R |
| 110 | # INT-PHDRS-NEXT: PF_W |
| 111 | # INT-PHDRS-NEXT: PF_X |
| 112 | # INT-PHDRS-NEXT: ] |
George Rimar | 11992c86 | 2016-11-25 08:05:41 +0000 | [diff] [blame] | 113 | # INT-PHDRS-NEXT: Alignment: |
George Rimar | 95dd718 | 2016-10-18 10:49:50 +0000 | [diff] [blame] | 114 | # INT-PHDRS-NEXT: } |
| 115 | # INT-PHDRS-NEXT: ] |
| 116 | |
Eugene Leviant | ce30b1c | 2016-10-19 15:04:49 +0000 | [diff] [blame] | 117 | # DEFHDR: ProgramHeaders [ |
| 118 | # DEFHDR-NEXT: ProgramHeader { |
| 119 | # DEFHDR-NEXT: Type: PT_LOAD (0x1) |
| 120 | # DEFHDR-NEXT: Offset: 0x0 |
| 121 | # DEFHDR-NEXT: VirtualAddress: 0x10000000 |
| 122 | # DEFHDR-NEXT: PhysicalAddress: 0x10000000 |
| 123 | # DEFHDR-NEXT: FileSize: 521 |
| 124 | # DEFHDR-NEXT: MemSize: 521 |
| 125 | # DEFHDR-NEXT: Flags [ (0x7) |
| 126 | # DEFHDR-NEXT: PF_R (0x4) |
| 127 | # DEFHDR-NEXT: PF_W (0x2) |
| 128 | # DEFHDR-NEXT: PF_X (0x1) |
| 129 | # DEFHDR-NEXT: ] |
| 130 | |
Eugene Leviant | 2a942c4 | 2016-12-05 16:38:32 +0000 | [diff] [blame] | 131 | # BADHDR: {{.*}}.script:1: section header 'bar' is not listed in PHDRS |
| 132 | |
Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 133 | .global _start |
| 134 | _start: |
| 135 | nop |
| 136 | |
| 137 | .section .foo.1,"a" |
| 138 | foo1: |
| 139 | .long 0 |
| 140 | |
| 141 | .section .foo.2,"aw" |
| 142 | foo2: |
| 143 | .long 0 |