[lld] r237841 - [LLD] Add support for the -stack_size option to Darwin ld.
Lang Hames
lhames at gmail.com
Wed May 20 15:10:50 PDT 2015
Author: lhames
Date: Wed May 20 17:10:50 2015
New Revision: 237841
URL: http://llvm.org/viewvc/llvm-project?rev=237841&view=rev
Log:
[LLD] Add support for the -stack_size option to Darwin ld.
Added:
lld/trunk/test/mach-o/stack-size.yaml
Modified:
lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/Driver/DarwinLdOptions.td
lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Wed May 20 17:10:50 2015
@@ -129,6 +129,9 @@ public:
bool PIE() const { return _pie; }
void setPIE(bool pie) { _pie = pie; }
+ uint64_t stackSize() const { return _stackSize; }
+ void setStackSize(uint64_t stackSize) { _stackSize = stackSize; }
+
uint64_t baseAddress() const { return _baseAddress; }
void setBaseAddress(uint64_t baseAddress) { _baseAddress = baseAddress; }
@@ -332,6 +335,7 @@ private:
bool _outputMachOTypeStatic; // Disambiguate static vs dynamic prog
bool _doNothing; // for -help and -v which just print info
bool _pie;
+ uint64_t _stackSize;
Arch _arch;
OS _os;
uint32_t _osMinVersion;
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed May 20 17:10:50 2015
@@ -20,6 +20,7 @@
#include "lld/ReaderWriter/MachOLinkingContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/Option.h"
@@ -411,7 +412,7 @@ bool DarwinLdDriver::parse(int argc, con
return false;
} else if (baseAddress % ctx.pageSize()) {
diagnostics << "error: image_base must be a multiple of page size ("
- << llvm::format("0x%" PRIx64, ctx.pageSize()) << ")\n";
+ << "0x" << llvm::utohexstr(ctx.pageSize()) << ")\n";
return false;
}
@@ -720,6 +721,22 @@ bool DarwinLdDriver::parse(int argc, con
}
}
+ // Handle stack_size
+ if (llvm::opt::Arg *stackSize = parsedArgs->getLastArg(OPT_stack_size)) {
+ uint64_t stackSizeVal;
+ if (parseNumberBase16(stackSize->getValue(), stackSizeVal)) {
+ diagnostics << "error: stack_size expects a hex number\n";
+ return false;
+ }
+ if ((stackSizeVal % ctx.pageSize()) != 0) {
+ diagnostics << "error: stack_size must be a multiple of page size ("
+ << "0x" << llvm::utohexstr(ctx.pageSize()) << ")\n";
+ return false;
+ }
+
+ ctx.setStackSize(stackSizeVal);
+ }
+
// Handle debug info handling options: -S
if (parsedArgs->hasArg(OPT_S))
ctx.setDebugInfoMode(MachOLinkingContext::DebugInfoMode::noDebugMap);
Modified: lld/trunk/lib/Driver/DarwinLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdOptions.td?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
+++ lld/trunk/lib/Driver/DarwinLdOptions.td Wed May 20 17:10:50 2015
@@ -67,6 +67,10 @@ def pie : Flag<["-"], "pie">,
def no_pie : Flag<["-"], "no_pie">,
HelpText<"Do not create Position Independent Executable">,
Group<grp_main>;
+def stack_size : Separate<["-"], "stack_size">,
+ HelpText<"Specifies the maximum stack size for the main thread in a program. "
+ "Must be a page-size multiple. (default=8Mb)">,
+ Group<grp_main>;
// dylib executable options
def grp_dylib : OptionGroup<"opts">, HelpText<"DYLIB EXECUTABLE OPTIONS">;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Wed May 20 17:10:50 2015
@@ -142,9 +142,9 @@ MachOLinkingContext::MachOLinkingContext
: _outputMachOType(MH_EXECUTE), _outputMachOTypeStatic(false),
_doNothing(false), _pie(false), _arch(arch_unknown), _os(OS::macOSX),
_osMinVersion(0), _pageZeroSize(0), _pageSize(4096), _baseAddress(0),
- _compatibilityVersion(0), _currentVersion(0), _deadStrippableDylib(false),
- _printAtoms(false), _testingFileUsage(false), _keepPrivateExterns(false),
- _demangle(false), _archHandler(nullptr),
+ _stackSize(0x800000), _compatibilityVersion(0), _currentVersion(0),
+ _deadStrippableDylib(false), _printAtoms(false), _testingFileUsage(false),
+ _keepPrivateExterns(false), _demangle(false), _archHandler(nullptr),
_exportMode(ExportMode::globals),
_debugInfoMode(DebugInfoMode::addDebugMap), _orderFileEntries(0) {}
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h Wed May 20 17:10:50 2015
@@ -235,6 +235,7 @@ struct NormalizedFile {
bool hasUUID;
std::vector<StringRef> rpaths;
Hex64 entryAddress;
+ Hex64 stackSize;
MachOLinkingContext::OS os;
Hex64 sourceVersion;
PackedVersion minOSverson;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Wed May 20 17:10:50 2015
@@ -829,7 +829,7 @@ std::error_code MachOFileLayout::writeLo
ep->cmd = LC_MAIN;
ep->cmdsize = sizeof(entry_point_command);
ep->entryoff = _file.entryAddress - _seg1addr;
- ep->stacksize = 0;
+ ep->stacksize = _file.stackSize;
if (_swap)
swapStruct(*ep);
lc += sizeof(entry_point_command);
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Wed May 20 17:10:50 2015
@@ -1197,6 +1197,7 @@ normalizedFromAtoms(const lld::File &ato
normFile.arch = context.arch();
normFile.fileType = context.outputMachOType();
normFile.flags = util.fileFlags();
+ normFile.stackSize = context.stackSize();
normFile.installName = context.installName();
normFile.currentVersion = context.currentVersion();
normFile.compatVersion = context.compatibilityVersion();
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp?rev=237841&r1=237840&r2=237841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp Wed May 20 17:10:50 2015
@@ -688,6 +688,7 @@ struct MappingTraits<NormalizedFile> {
io.mapOptional("has-UUID", file.hasUUID, true);
io.mapOptional("rpaths", file.rpaths);
io.mapOptional("entry-point", file.entryAddress, Hex64(0));
+ io.mapOptional("stack-size", file.stackSize, Hex64(0x800000));
io.mapOptional("source-version", file.sourceVersion, Hex64(0));
io.mapOptional("OS", file.os);
io.mapOptional("min-os-version", file.minOSverson, PackedVersion(0));
Added: lld/trunk/test/mach-o/stack-size.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/stack-size.yaml?rev=237841&view=auto
==============================================================================
--- lld/trunk/test/mach-o/stack-size.yaml (added)
+++ lld/trunk/test/mach-o/stack-size.yaml Wed May 20 17:10:50 2015
@@ -0,0 +1,19 @@
+# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.9 %s -o %t -stack_size 31415926000 %p/Inputs/libSystem.yaml
+# RUN: llvm-objdump -private-headers %t | FileCheck %s
+# RUN: not lld -flavor darwin -arch x86_64 -stack_size 0x31415926530 %s >/dev/null 2> %t
+# RUN: FileCheck < %t %s --check-prefix=CHECK-ERROR-MISPAGED
+# RUN: not lld -flavor darwin -arch x86_64 -stack_size hithere %s >/dev/null 2> %t
+# RUN: FileCheck < %t %s --check-prefix=CHECK-ERROR-NOTHEX
+
+--- !native
+defined-atoms:
+ - name: _main
+ scope: global
+ content: []
+
+# CHECK: cmd LC_MAIN
+# CHECK: stacksize 3384796143616
+
+# CHECK-ERROR-MISPAGED: error: stack_size must be a multiple of page size (0x1000)
+
+# CHECK-ERROR-NOTHEX: error: stack_size expects a hex number
More information about the llvm-commits
mailing list