|
| 1 | +RUN: yaml2obj %p/Inputs/sectionlayout.yaml -o %t.obj |
| 2 | + |
| 3 | +## Error on non-exist input layout file |
| 4 | +RUN: not lld-link /entry:main /sectionlayout:doesnotexist.txt %t.obj |
| 5 | + |
| 6 | +## Order in 1 -> 3 -> 2 |
| 7 | +RUN: echo ".text1" > %t.layout.txt |
| 8 | +RUN: echo ".text3" >> %t.layout.txt |
| 9 | +RUN: echo ".text2" >> %t.layout.txt |
| 10 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 11 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK1 %s |
| 12 | + |
| 13 | +## While /sectionlayout:abc is valid, /sectionlayout:@abc is also accepted (to align with MS link.exe) |
| 14 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:@%t.layout.txt %t.obj |
| 15 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK1 %s |
| 16 | + |
| 17 | +## Ensure tokens after section name is ignored (for now, to align with MS link.exe) |
| 18 | +RUN: echo ".text1 ALIGN=1" > %t.layout.txt |
| 19 | +RUN: echo ".text3" >> %t.layout.txt |
| 20 | +RUN: echo ".text2" >> %t.layout.txt |
| 21 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:@%t.layout.txt %t.obj |
| 22 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK1 %s |
| 23 | + |
| 24 | +CHECK1: Sections [ |
| 25 | +CHECK1: Section { |
| 26 | +CHECK1: Number: 1 |
| 27 | +CHECK1: Name: .text1 |
| 28 | +CHECK1: } |
| 29 | +CHECK1: Section { |
| 30 | +CHECK1: Number: 2 |
| 31 | +CHECK1: Name: .text3 |
| 32 | +CHECK1: } |
| 33 | +CHECK1: Section { |
| 34 | +CHECK1: Number: 3 |
| 35 | +CHECK1: Name: .text2 |
| 36 | +CHECK1: } |
| 37 | +CHECK1: ] |
| 38 | + |
| 39 | +## Order in 3 -> 2 -> 1 |
| 40 | +RUN: echo ".text3" > %t.layout.txt |
| 41 | +RUN: echo ".text2" >> %t.layout.txt |
| 42 | +RUN: echo ".text1" >> %t.layout.txt |
| 43 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 44 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK2 %s |
| 45 | + |
| 46 | +CHECK2: Sections [ |
| 47 | +CHECK2: Section { |
| 48 | +CHECK2: Number: 1 |
| 49 | +CHECK2: Name: .text3 |
| 50 | +CHECK2: } |
| 51 | +CHECK2: Section { |
| 52 | +CHECK2: Number: 2 |
| 53 | +CHECK2: Name: .text2 |
| 54 | +CHECK2: } |
| 55 | +CHECK2: Section { |
| 56 | +CHECK2: Number: 3 |
| 57 | +CHECK2: Name: .text1 |
| 58 | +CHECK2: } |
| 59 | +CHECK2: ] |
| 60 | + |
| 61 | +## Put non-exisist section in layout file has no effect; original order is respected |
| 62 | +RUN: echo "notexist" > %t.layout.txt |
| 63 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 64 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK3 %s |
| 65 | + |
| 66 | +## Empty layout file has no effect |
| 67 | +RUN: echo "" > %t.layout.txt |
| 68 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 69 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK3 %s |
| 70 | + |
| 71 | +## Empty layout file has no effect |
| 72 | +RUN: echo " " > %t.layout.txt |
| 73 | +RUN: echo " " >> %t.layout.txt |
| 74 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 75 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK3 %s |
| 76 | + |
| 77 | +CHECK3: Sections [ |
| 78 | +CHECK3: Section { |
| 79 | +CHECK3: Number: 1 |
| 80 | +CHECK3: Name: .text1 |
| 81 | +CHECK3: } |
| 82 | +CHECK3: Section { |
| 83 | +CHECK3: Number: 2 |
| 84 | +CHECK3: Name: .text2 |
| 85 | +CHECK3: } |
| 86 | +CHECK3: Section { |
| 87 | +CHECK3: Number: 3 |
| 88 | +CHECK3: Name: .text3 |
| 89 | +CHECK3: } |
| 90 | +CHECK3: ] |
| 91 | + |
| 92 | +## Order in 3 -> 1, but 2 remains unspecified |
| 93 | +RUN: echo ".text3" > %t.layout.txt |
| 94 | +RUN: echo ".text1" >> %t.layout.txt |
| 95 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 96 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK4 %s |
| 97 | + |
| 98 | +CHECK4: Sections [ |
| 99 | +CHECK4: Section { |
| 100 | +CHECK4: Number: 1 |
| 101 | +CHECK4: Name: .text3 |
| 102 | +CHECK4: } |
| 103 | +CHECK4: Section { |
| 104 | +CHECK4: Number: 2 |
| 105 | +CHECK4: Name: .text1 |
| 106 | +CHECK4: } |
| 107 | +CHECK4: Section { |
| 108 | +CHECK4: Number: 3 |
| 109 | +CHECK4: Name: .text2 |
| 110 | +CHECK4: } |
| 111 | +CHECK4: ] |
| 112 | + |
| 113 | +## Order in 3 -> 2, but 1 remains unspecified. |
| 114 | +## 1 should be the first, as the original order (1 -> 2 -> 3) is respected |
| 115 | +RUN: echo ".text3" > %t.layout.txt |
| 116 | +RUN: echo ".text2" >> %t.layout.txt |
| 117 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 118 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK2 %s |
| 119 | + |
| 120 | +## Order in 3 -> 2 -> 1, multiple specification has no effect (the first one is used) |
| 121 | +RUN: echo ".text3" > %t.layout.txt |
| 122 | +RUN: echo ".text3" >> %t.layout.txt |
| 123 | +RUN: echo ".text3" >> %t.layout.txt |
| 124 | +RUN: echo ".text2" >> %t.layout.txt |
| 125 | +RUN: echo ".text2" >> %t.layout.txt |
| 126 | +RUN: echo ".text1" >> %t.layout.txt |
| 127 | +RUN: echo ".text3" >> %t.layout.txt |
| 128 | +RUN: lld-link /out:%t.exe /entry:main /sectionlayout:%t.layout.txt %t.obj |
| 129 | +RUN: llvm-readobj --sections %t.exe | FileCheck -check-prefix=CHECK2 %s |
0 commit comments