[LLD] Add support for the -stack_size option to Darwin ld.

llvm-svn: 237841
This commit is contained in:
Lang Hames 2015-05-20 22:10:50 +00:00
parent 267d31e137
commit 65a64c9c29
9 changed files with 52 additions and 5 deletions

View File

@ -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;

View File

@ -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, const char *argv[],
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, const char *argv[],
}
}
// 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);

View File

@ -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">;

View File

@ -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) {}

View File

@ -235,6 +235,7 @@ struct NormalizedFile {
bool hasUUID;
std::vector<StringRef> rpaths;
Hex64 entryAddress;
Hex64 stackSize;
MachOLinkingContext::OS os;
Hex64 sourceVersion;
PackedVersion minOSverson;

View File

@ -829,7 +829,7 @@ std::error_code MachOFileLayout::writeLoadCommands() {
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);

View File

@ -1197,6 +1197,7 @@ normalizedFromAtoms(const lld::File &atomFile,
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();

View File

@ -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));

View File

@ -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