<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Nov 10, 2014 at 6:54 AM, Shankar Easwaran <span dir="ltr"><<a href="mailto:shankare@codeaurora.org" target="_blank">shankare@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: shankare<br>
Date: Mon Nov 10 08:54:43 2014<br>
New Revision: 221584<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221584&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=221584&view=rev</a><br>
Log:<br>
[ELF] Support -z max-page-size option<br>
<br>
The GNU linker allows the user to change the page size by using the option -z<br>
max-page-size.<br>
<br>
Modified:<br>
lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h<br>
lld/trunk/lib/Driver/GnuLdDriver.cpp<br>
lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp<br>
<br>
Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=221584&r1=221583&r2=221584&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=221584&r1=221583&r2=221584&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)<br>
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Mon Nov 10 08:54:43 2014<br>
@@ -58,7 +58,19 @@ public:<br>
};<br>
<br>
llvm::Triple getTriple() const { return _triple; }<br>
- virtual uint64_t getPageSize() const { return 0x1000; }<br>
+<br>
+ // Page size.<br>
+ virtual uint64_t getPageSize() const {<br>
+ if (_maxPageSizeOptionSet)<br>
+ return _maxPageSize;<br>
+ return 0x1000;<br>
+ }<br>
+ virtual void setMaxPageSize(uint64_t pagesize) {<br>
+ _maxPageSize = pagesize;<br>
+ _maxPageSizeOptionSet = true;<br>
+ }<br>
+ virtual uint64_t maxPageSize() const { return _maxPageSize; }<br>
+<br>
OutputMagic getOutputMagic() const { return _outputMagic; }<br>
uint16_t getOutputELFType() const { return _outputELFType; }<br>
uint16_t getOutputMachine() const;<br>
@@ -308,6 +320,9 @@ protected:<br>
bool _mergeRODataToTextSegment;<br>
bool _demangle;<br>
bool _alignSegments;<br>
+ bool _maxPageSizeOptionSet;<br>
+ uint64_t _maxPageSize;<br></blockquote><div><br></div><div>Maybe this is a place you want to use llvm::Optional<uint64_t> instead of having two fields for one value?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
OutputMagic _outputMagic;<br>
StringRefVector _inputSearchPaths;<br>
std::unique_ptr<Writer> _writer;<br>
<br>
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=221584&r1=221583&r2=221584&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=221584&r1=221583&r2=221584&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)<br>
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Mon Nov 10 08:54:43 2014<br>
@@ -15,6 +15,7 @@<br>
<br>
#include "lld/Driver/Driver.h"<br>
#include "lld/Driver/GnuLdInputGraph.h"<br>
+#include "lld/Support/NumParse.h"<br>
#include "llvm/ADT/ArrayRef.h"<br>
#include "llvm/ADT/Optional.h"<br>
#include "llvm/ADT/STLExtras.h"<br>
@@ -151,6 +152,22 @@ static bool parseDefsymAsAlias(StringRef<br>
return !target.empty();<br>
}<br>
<br>
+// Parses dashz options for max-page-size.<br>
+static bool parseZOption(StringRef opt, uint64_t &val) {<br>
+ size_t equalPos = opt.find('=');<br>
+ if (equalPos == 0 || equalPos == StringRef::npos)<br>
+ return false;<br>
+ StringRef value = opt.substr(equalPos + 1);<br>
+ ErrorOr<uint64_t> parsedVal = lld::parseNum(value, false /*No Extensions*/);<br>
+ if (!parsedVal)<br>
+ return false;<br>
+ // Dont allow a value of 0 for max-page-size.<br>
+ val = parsedVal.get();<br>
+ if (!val)<br>
+ return false;<br>
+ return true;<br>
+}<br>
+<br>
llvm::ErrorOr<StringRef> ELFFileNode::getPath(const LinkingContext &) const {<br>
if (_attributes._isDashlPrefix)<br>
return _elfLinkingContext.searchLibrary(_path);<br>
@@ -471,7 +488,25 @@ bool GnuLdDriver::parse(int argc, const<br>
StringRef extOpt = inputArg->getValue();<br>
if (extOpt == "muldefs")<br>
ctx->setAllowDuplicates(true);<br>
- else<br>
+ else if (extOpt.startswith("max-page-size")) {<br>
+ // Parse -z max-page-size option.<br>
+ // The default page size is considered the minimum page size the user<br>
+ // can set, check the user input if its atleast the minimum page size<br>
+ // and doesnot exceed the maximum page size allowed for the target.<br>
+ uint64_t maxPageSize = 0;<br>
+<br>
+ // Error if the page size user set is less than the maximum page size<br>
+ // and greather than the default page size and the user page size is a<br>
+ // modulo of the default page size.<br>
+ if ((!parseZOption(extOpt, maxPageSize)) ||<br>
+ (maxPageSize < ctx->getPageSize()) ||<br>
+ (maxPageSize > ctx->maxPageSize()) ||<br>
+ (!maxPageSize % ctx->maxPageSize())) {<br>
+ diagnostics << "invalid option: " << extOpt << "\n";<br>
+ return false;<br>
+ }<br>
+ ctx->setMaxPageSize(maxPageSize);<br>
+ } else<br>
diagnostics << "warning: ignoring unknown argument for -z: " << extOpt<br>
<< "\n";<br>
break;<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=221584&r1=221583&r2=221584&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=221584&r1=221583&r2=221584&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Mon Nov 10 08:54:43 2014<br>
@@ -62,7 +62,8 @@ ELFLinkingContext::ELFLinkingContext(<br>
_mergeCommonStrings(false), _runLayoutPass(true),<br>
_useShlibUndefines(true), _dynamicLinkerArg(false),<br>
_noAllowDynamicLibraries(false), _mergeRODataToTextSegment(true),<br>
- _demangle(true), _alignSegments(true), _outputMagic(OutputMagic::DEFAULT),<br>
+ _demangle(true), _alignSegments(true), _maxPageSizeOptionSet(false),<br>
+ _maxPageSize(0x10000), _outputMagic(OutputMagic::DEFAULT),<br>
_sysrootPath("") {}<br>
<br>
void ELFLinkingContext::addPasses(PassManager &pm) {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>