[lld-macho][easy] Fix segment max protection
authorJez Ng <jezng@fb.com>
Wed, 14 Oct 2020 19:46:49 +0000 (12:46 -0700)
committerJez Ng <jezng@fb.com>
Tue, 10 Nov 2020 20:19:28 +0000 (12:19 -0800)
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

lld/MachO/OutputSegment.cpp
lld/test/MachO/segments.s

index 07e4590..a13f9f8 100644 (file)
@@ -31,9 +31,9 @@ static uint32_t initProt(StringRef name) {
 }
 
 static uint32_t maxProt(StringRef name) {
-  if (name == segment_names::pageZero)
-    return 0;
-  return VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE;
+  assert(config->arch != AK_i386 &&
+         "TODO: i386 has different maxProt requirements");
+  return initProt(name);
 }
 
 size_t OutputSegment::numNonHiddenSections() const {
index 07ddcae..4b57f79 100644 (file)
@@ -28,7 +28,7 @@
 ## dyld3 assumes that the __TEXT segment starts from the file header
 # CHECK-NEXT:   fileoff: 0
 # CHECK-NEXT:   filesize:
-# CHECK-NEXT:   maxprot: rwx
+# CHECK-NEXT:   maxprot: r-x
 # CHECK-NEXT:   initprot: r-x
 # CHECK-NEXT:   nsects: 1
 # CHECK-NEXT:   flags: 0x0
@@ -46,7 +46,7 @@
 # CHECK-NEXT: vmsize:
 # CHECK-NEXT: fileoff: [[#%u, LINKEDIT_OFF:]]
 # CHECK-NEXT: filesize: [[#%u, LINKEDIT_SIZE:]]
-# CHECK-NEXT: maxprot: rwx
+# CHECK-NEXT: maxprot: r--
 # CHECK-NEXT: initprot: r--
 # CHECK-NOT:  Cmd: LC_SEGMENT_64