[lld] 7ac3fcc - Allow /STACK in #pragma comment(linker, ...)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 16:01:03 PDT 2021


Author: Alex Reinking
Date: 2021-05-05T16:00:33-07:00
New Revision: 7ac3fcc526ceb36da9ed41f27f686709a5554af8

URL: https://github.com/llvm/llvm-project/commit/7ac3fcc526ceb36da9ed41f27f686709a5554af8
DIFF: https://github.com/llvm/llvm-project/commit/7ac3fcc526ceb36da9ed41f27f686709a5554af8.diff

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

Added: 
    lld/test/COFF/stack-drectve.s

Modified: 
    lld/COFF/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index cf1169211985b..e2374b52b4f9f 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -408,6 +408,10 @@ void LinkerDriver::parseDirectives(InputFile *file) {
     case OPT_section:
       parseSection(arg->getValue());
       break;
+    case OPT_stack:
+      parseNumbers(arg->getValue(), &config->stackReserve,
+                   &config->stackCommit);
+      break;
     case OPT_subsystem: {
       bool gotVersion = false;
       parseSubsystem(arg->getValue(), &config->subsystem,

diff  --git a/lld/test/COFF/stack-drectve.s b/lld/test/COFF/stack-drectve.s
new file mode 100644
index 0000000000000..0bb717eec811c
--- /dev/null
+++ b/lld/test/COFF/stack-drectve.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %s -o %t.obj
+# RUN: lld-link /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
+
+# CHECK: SizeOfStackReserve: 20480
+# CHECK: SizeOfStackCommit: 12288
+
+	.text
+	.globl main
+main:
+	mov $42, %eax
+	ret
+
+	.section	.drectve,"yn"
+	.ascii	" -stack:0x5000,0x3000"


        


More information about the llvm-commits mailing list