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

Nick Kledzik kledzik at apple.com
Thu May 21 10:59:22 PDT 2015



On 05/20/15 03:17 PM, Lang Hames  <lhames at gmail.com> wrote: 
> 
> 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/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));
> 

The OS has a concept of a default stack size that is used when the LC_MAIN load command has the stack size field set to zero. We should support that by having the default stack-size be zero (if -stack_size is not specified).

 

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

Sad that this value (3384796143616) is different than the input value (31415926000).
 
There should be a test case that when -stack_size is not specified, the LC_MAIN has a stack size of zero.

-Nick

> 
> 
> +
> +# CHECK-ERROR-MISPAGED: error: stack_size must be a multiple of page size (0x1000)
> +
> +# CHECK-ERROR-NOTHEX: error: stack_size expects a hex number
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150521/9c2d94f5/attachment.html>


More information about the llvm-commits mailing list