[lld] 000ff30 - Warn on /align if used without /driver

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 20:14:52 PST 2019


Author: Rui Ueyama
Date: 2019-11-14T13:13:07+09:00
New Revision: 000ff301e74b216c23ee60344977b2b6692ac70c

URL: https://github.com/llvm/llvm-project/commit/000ff301e74b216c23ee60344977b2b6692ac70c
DIFF: https://github.com/llvm/llvm-project/commit/000ff301e74b216c23ee60344977b2b6692ac70c.diff

LOG: Warn on /align if used without /driver

/align is not supposed to be used without /driver, so it makes sense
to warn if only /align is passed. MSVC link.exe warns on this too.

Differential Revision: https://reviews.llvm.org/D70163

Added: 
    

Modified: 
    lld/COFF/Driver.cpp
    lld/test/COFF/align.s

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 05d60428d260..d33e86841492 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1479,6 +1479,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
     parseNumbers(arg->getValue(), &config->align);
     if (!isPowerOf2_64(config->align))
       error("/align: not a power of two: " + StringRef(arg->getValue()));
+    if (!args.hasArg(OPT_driver))
+      warn("/align specified without /driver; image may not run");
   }
 
   // Handle /aligncomm

diff  --git a/lld/test/COFF/align.s b/lld/test/COFF/align.s
index 67ca349e0030..ca005b5e42ed 100644
--- a/lld/test/COFF/align.s
+++ b/lld/test/COFF/align.s
@@ -4,6 +4,19 @@
 
 # CHECK: SectionAlignment: 32
 
+# RUN: lld-link /out:%t.exe /entry:main /align:32 %t.obj 2>&1 \
+# RUN:   | FileCheck -check-prefix=WARN1 %s
+
+# WARN1: /align specified without /driver; image may not run
+
+# RUN: lld-link /out:%t.exe /entry:main /align:32 %t.obj /driver 2>&1 \
+# RUN:   | FileCheck -check-prefix=WARN2 --allow-empty %s
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /driver 2>&1 \
+# RUN:   | FileCheck -check-prefix=WARN2 --allow-empty %s
+
+# WARN2-NOT: /align specified without /driver; image may not run
+
 --- !COFF
 header:
   Machine:         IMAGE_FILE_MACHINE_AMD64


        


More information about the llvm-commits mailing list