Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -132,10 +132,12 @@ UnresolvedPolicy UnresolvedSymbols; BuildIdKind BuildId = BuildIdKind::None; ELFKind EKind = ELFNoneKind; + uint64_t CommonPageSize; uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL; 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; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -657,6 +657,20 @@ Config->ImageBase = Config->Pic ? 0 : Target->DefaultImageBase; } + auto SetZOptValue = [&](StringRef Opt, uint64_t &Dest, uint64_t Default) { + if (Optional Value = getZOptionValue(Args, Opt)) { + if (Value->getAsInteger(0, Dest)) + error("invalid " + Opt + ": " + *Value); + } else { + Dest = Default; + } + }; + + // Initialize Config->CommonPageSize and Config->MaxPageSize. The default + // value is defined by the target, but it can be overriden using the option. + SetZOptValue("common-page-size", Config->CommonPageSize, Target->PageSize); + SetZOptValue("max-page-size", 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/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -1414,9 +1414,9 @@ uint64_t static getConstant(StringRef S) { if (S == "COMMONPAGESIZE") - return Target->PageSize; + return Config->CommonPageSize; if (S == "MAXPAGESIZE") - return Target->MaxPageSize; + return Config->MaxPageSize; error("unknown constant: " + S); return 0; } Index: test/ELF/linkerscript/zcommon-page-size.s =================================================================== --- /dev/null +++ test/ELF/linkerscript/zcommon-page-size.s @@ -0,0 +1,17 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: echo "SECTIONS { \ +# RUN: symbol = CONSTANT(COMMONPAGESIZE); \ +# RUN: }" > %t.script +# RUN: ld.lld -z common-page-size=0x1234 -o %t1 --script %t.script %t +# RUN: llvm-objdump -t %t1 | FileCheck %s +# RUN: not ld.lld -z common-page-size=-1234 -o %t1 --script %t.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR %s +# ERR: invalid common-page-size: -1234 + +# CHECK: 0000000000001234 *ABS* 00000000 symbol + +.global _start +_start: + nop Index: test/ELF/linkerscript/zmax-page-size.s =================================================================== --- /dev/null +++ test/ELF/linkerscript/zmax-page-size.s @@ -0,0 +1,17 @@ +# 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 +# RUN: not ld.lld -z max-page-size=-1234 -o %t1 --script %t.script %t 2>&1 \ +# RUN: | FileCheck -check-prefix=ERR %s +# ERR: invalid max-page-size: -1234 + +# CHECK: 0000000000001234 *ABS* 00000000 symbol + +.global _start +_start: + nop