[PATCH] D24891: [ELF] Support -z max-page-size option

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 17:49:04 PDT 2016


phosek created this revision.
phosek added a reviewer: ruiu.
phosek added subscribers: llvm-commits, phosek.
phosek added a project: lld.

This option allows overriding the max page size.

https://reviews.llvm.org/D24891

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/LinkerScript.cpp
  test/ELF/zmax-page-size.s

Index: test/ELF/zmax-page-size.s
===================================================================
--- /dev/null
+++ test/ELF/zmax-page-size.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: echo "SECTIONS { \
+# RUN:         symbol = CONSTANT(MAXPAGESIZE); \
+# RUN:       }" > %t.script
+# RUN: ld.lld -z max-page-size=0x1234 -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck %s
+
+# CHECK: 0000000000001234 *ABS* 00000000 symbol
+
+.global _start
+_start:
+ nop
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1416,7 +1416,7 @@
   if (S == "COMMONPAGESIZE")
     return Target->PageSize;
   if (S == "MAXPAGESIZE")
-    return Target->MaxPageSize;
+    return Config->MaxPageSize;
   error("unknown constant: " + S);
   return 0;
 }
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -657,6 +657,14 @@
     Config->ImageBase = Config->Pic ? 0 : Target->DefaultImageBase;
   }
 
+  // Initialize Config->MaxPageSize
+  if (Optional<StringRef> Value = getZOptionValue(Args, "max-page-size")) {
+    if (Value->getAsInteger(0, Config->MaxPageSize))
+      error("invalid max page size: " + *Value);
+  } else {
+    Config->MaxPageSize = Target->MaxPageSize;
+  }
+
   // Add all files to the symbol table. After this, the symbol table
   // contains all known names except a few linker-synthesized symbols.
   for (InputFile *F : Files)
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -136,6 +136,7 @@
   uint16_t EMachine = llvm::ELF::EM_NONE;
   uint64_t EntryAddr = 0;
   uint64_t ImageBase;
+  uint64_t MaxPageSize;
   uint64_t ZStackSize = -1;
   unsigned LtoJobs;
   unsigned LtoO;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24891.72383.patch
Type: text/x-patch
Size: 1933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160924/b67e508f/attachment.bin>


More information about the llvm-commits mailing list