Skip to content

Commit 6cf2443

Browse files
committed
[lld-macho][easy] Fix segment max protection
We should have maxprot == initprot for all non-i386 architectures, which is what ld64 does. Reviewed By: #lld-macho, compnerd Differential Revision: https://reviews.llvm.org/D89420
1 parent b869081 commit 6cf2443

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lld/MachO/OutputSegment.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ static uint32_t initProt(StringRef name) {
3131
}
3232

3333
static uint32_t maxProt(StringRef name) {
34-
if (name == segment_names::pageZero)
35-
return 0;
36-
return VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE;
34+
assert(config->arch != AK_i386 &&
35+
"TODO: i386 has different maxProt requirements");
36+
return initProt(name);
3737
}
3838

3939
size_t OutputSegment::numNonHiddenSections() const {

lld/test/MachO/segments.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
## dyld3 assumes that the __TEXT segment starts from the file header
2929
# CHECK-NEXT: fileoff: 0
3030
# CHECK-NEXT: filesize:
31-
# CHECK-NEXT: maxprot: rwx
31+
# CHECK-NEXT: maxprot: r-x
3232
# CHECK-NEXT: initprot: r-x
3333
# CHECK-NEXT: nsects: 1
3434
# CHECK-NEXT: flags: 0x0
@@ -46,7 +46,7 @@
4646
# CHECK-NEXT: vmsize:
4747
# CHECK-NEXT: fileoff: [[#%u, LINKEDIT_OFF:]]
4848
# CHECK-NEXT: filesize: [[#%u, LINKEDIT_SIZE:]]
49-
# CHECK-NEXT: maxprot: rwx
49+
# CHECK-NEXT: maxprot: r--
5050
# CHECK-NEXT: initprot: r--
5151
# CHECK-NOT: Cmd: LC_SEGMENT_64
5252

0 commit comments

Comments
 (0)