diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index 9bcb8f694c12..59031ed48649 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -61,16 +61,13 @@ public: // Page size. virtual uint64_t getPageSize() const { - if (_maxPageSizeOptionSet) - return _maxPageSize; + if (_maxPageSize) + return *_maxPageSize; return 0x1000; } virtual void setMaxPageSize(uint64_t pagesize) { _maxPageSize = pagesize; - _maxPageSizeOptionSet = true; } - virtual uint64_t maxPageSize() const { return _maxPageSize; } - OutputMagic getOutputMagic() const { return _outputMagic; } uint16_t getOutputELFType() const { return _outputELFType; } uint16_t getOutputMachine() const; @@ -321,8 +318,7 @@ protected: bool _mergeRODataToTextSegment; bool _demangle; bool _alignSegments; - bool _maxPageSizeOptionSet; - uint64_t _maxPageSize; + llvm::Optional _maxPageSize; OutputMagic _outputMagic; StringRefVector _inputSearchPaths; diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 9ca5a2073e82..9e1508b9b26e 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -495,8 +495,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[], // modulo of the default page size. if ((!parseZOption(extOpt, maxPageSize)) || (maxPageSize < ctx->getPageSize()) || - (maxPageSize > ctx->maxPageSize()) || - (!maxPageSize % ctx->maxPageSize())) { + (!maxPageSize % ctx->getPageSize())) { diagnostics << "invalid option: " << extOpt << "\n"; return false; } diff --git a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp index e00424b5436a..0eccf64e1a53 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -62,8 +62,7 @@ ELFLinkingContext::ELFLinkingContext( _mergeCommonStrings(false), _runLayoutPass(true), _useShlibUndefines(true), _dynamicLinkerArg(false), _noAllowDynamicLibraries(false), _mergeRODataToTextSegment(true), - _demangle(true), _alignSegments(true), _maxPageSizeOptionSet(false), - _maxPageSize(0x10000), _outputMagic(OutputMagic::DEFAULT), + _demangle(true), _alignSegments(true), _outputMagic(OutputMagic::DEFAULT), _sysrootPath("") {} void ELFLinkingContext::addPasses(PassManager &pm) { diff --git a/lld/test/elf/X86_64/maxpagesize.test b/lld/test/elf/X86_64/maxpagesize.test index a32eaefb96fe..00774b525581 100644 --- a/lld/test/elf/X86_64/maxpagesize.test +++ b/lld/test/elf/X86_64/maxpagesize.test @@ -8,11 +8,12 @@ # RUN: --no-align-segments --noinhibit-exec -z max-page-size=0 # RUN: not lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ # RUN: --no-align-segments --noinhibit-exec -z max-page-size=0xFF -# RUN: not lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ +# RUN: lld -flavor gnu -target x86_64 %t.o -o %t1.exe -static \ # RUN: --no-align-segments --noinhibit-exec -z max-page-size=0x100000 # RUN: lld -flavor gnu -target x86_64 %t.o -o %t.exe -static \ # RUN: --no-align-segments --noinhibit-exec -z max-page-size=0x10000 # RUN: llvm-readobj -program-headers %t.exe | FileCheck %s +# RUN: llvm-readobj -program-headers %t1.exe | FileCheck %s -check-prefix=CHECKLARGE # #CHECK: VirtualAddress: 0x400000 #CHECK: PhysicalAddress: 0x400000 @@ -20,6 +21,12 @@ #CHECK: VirtualAddress: 0x400178 #CHECK: PhysicalAddress: 0x400178 #CHECK: Alignment: 65536 +#CHECKLARGE: VirtualAddress: 0x400000 +#CHECKLARGE: PhysicalAddress: 0x400000 +#CHECKLARGE: Alignment: 1048576 +#CHECKLARGE: VirtualAddress: 0x400178 +#CHECKLARGE: PhysicalAddress: 0x400178 +#CHECKLARGE: Alignment: 1048576 # object ---