Skip to content

Commit db56ba0

Browse files
alexreinkingmemfrob
authored andcommitted
Allow /STACK in #pragma comment(linker, ...)
The Halide project uses `#pragma comment(linker, "/STACK:...")` to set the stack size high enough for our embedded compiler to run in end-user programs on Windows. Unfortunately, lld-link.exe breaks on this when embedded in a COFF object, despite supporting the flag on the command line. MSVC's link.exe supports this fine. This patch extends support for this to lld-link.exe for better compatibility with MSVC projects. Differential Revision: https://reviews.llvm.org/D99680
1 parent 2d9c738 commit db56ba0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lld/COFF/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ void LinkerDriver::parseDirectives(InputFile *file) {
408408
case OPT_section:
409409
parseSection(arg->getValue());
410410
break;
411+
case OPT_stack:
412+
parseNumbers(arg->getValue(), &config->stackReserve,
413+
&config->stackCommit);
414+
break;
411415
case OPT_subsystem: {
412416
bool gotVersion = false;
413417
parseSubsystem(arg->getValue(), &config->subsystem,

lld/test/COFF/stack-drectve.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %s -o %t.obj
3+
# RUN: lld-link /out:%t.exe /entry:main %t.obj
4+
# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
5+
6+
# CHECK: SizeOfStackReserve: 20480
7+
# CHECK: SizeOfStackCommit: 12288
8+
9+
.text
10+
.globl main
11+
main:
12+
mov $42, %eax
13+
ret
14+
15+
.section .drectve,"yn"
16+
.ascii " -stack:0x5000,0x3000"

0 commit comments

Comments
 (0)