diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1479,6 +1479,8 @@ 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 --- 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