When nonexistent linker inputs are passed to the driver, the linker now errors out, instead of the compiler. If the linker does not run, clang now emits a "warning: linker input unused" instead of an error for nonexistent files. The motivation for this change is that I noticed that `clang-cl /winsysroot sysroot main.cc ole32.lib` emitted a "ole32.lib not found" error, even though the linker finds it just fine when I run `clang-cl /winsysroot sysroot main.cc /link ole32.lib`. The same problem occurs if running `clang-cl main.cc ole32.lib` in a non-MSVC shell. The problem is that DiagnoseInputExistence() only looked for libs in %LIB%, but MSVCToolChain uses much more involved techniques. For this particular problem, we could make DiagnoseInputExistence() ask the toolchain to see if it can find a .lib file, but in general the driver can't know what the linker will do to find files, so it shouldn't try. For example, if we implement PR24616, lld-link will look in the registry to determine a good default for %LIB% if it isn't set. This is less or a problem for the gcc driver, since .a paths there are either passed via -l flags (which honor -L), or via a qualified path (that doesn't honor -L) -- but for example ld.lld's --chroot flag can also trigger this problem. Without this patch, `clang -fuse-ld=lld -Wl,--chroot,some/dir /file.o` will complain that `/file.o` doesn't exist, even though `clang -fuse-ld=lld -Wl,--chroot,some/dir -Wl,/file.o` succeeds just fine. This implements rnk's suggestion on the old bug PR27234. Differential Revision: https://reviews.llvm.org/D109624
68 lines
3.3 KiB
C
68 lines
3.3 KiB
C
// Note: %s must be preceded by -- or bound to another option, otherwise it may
|
|
// be interpreted as a command-line option, e.g. on Mac where %s is commonly
|
|
// under /Users.
|
|
|
|
// RUN: %clang_cl /Tc%s -fuse-ld=link -### /link foo bar baz 2>&1 | FileCheck --check-prefix=LINK %s
|
|
// RUN: %clang_cl /Tc%s -fuse-ld=link -### /linkfoo bar baz 2>&1 | FileCheck --check-prefix=LINK %s
|
|
// LINK: link.exe
|
|
// LINK: "foo"
|
|
// LINK: "bar"
|
|
// LINK: "baz"
|
|
|
|
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=link -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN %s
|
|
// ASAN: link.exe
|
|
// ASAN: "-debug"
|
|
// ASAN: "-incremental:no"
|
|
// ASAN: "{{[^"]*}}clang_rt.asan-i386.lib"
|
|
// ASAN: "-wholearchive:{{.*}}clang_rt.asan-i386.lib"
|
|
// ASAN: "{{[^"]*}}clang_rt.asan_cxx-i386.lib"
|
|
// ASAN: "-wholearchive:{{.*}}clang_rt.asan_cxx-i386.lib"
|
|
// ASAN: "{{.*}}cl-link{{.*}}.obj"
|
|
|
|
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /MD /Tc%s -fuse-ld=link -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-MD %s
|
|
// ASAN-MD: link.exe
|
|
// ASAN-MD: "-debug"
|
|
// ASAN-MD: "-incremental:no"
|
|
// ASAN-MD: "{{.*}}clang_rt.asan_dynamic-i386.lib"
|
|
// ASAN-MD: "{{[^"]*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib"
|
|
// ASAN-MD: "-include:___asan_seh_interceptor"
|
|
// ASAN-MD: "-wholearchive:{{.*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib"
|
|
// ASAN-MD: "{{.*}}cl-link{{.*}}.obj"
|
|
|
|
// RUN: %clang_cl /LD -fuse-ld=link -### /Tc%s 2>&1 | FileCheck --check-prefix=DLL %s
|
|
// RUN: %clang_cl /LDd -fuse-ld=link -### /Tc%s 2>&1 | FileCheck --check-prefix=DLL %s
|
|
// DLL: link.exe
|
|
// "-dll"
|
|
|
|
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /LD /Tc%s -fuse-ld=link -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-DLL %s
|
|
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /LDd /Tc%s -fuse-ld=link -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-DLL %s
|
|
// ASAN-DLL: link.exe
|
|
// ASAN-DLL: "-dll"
|
|
// ASAN-DLL: "-debug"
|
|
// ASAN-DLL: "-incremental:no"
|
|
// ASAN-DLL: "{{.*}}clang_rt.asan_dll_thunk-i386.lib"
|
|
// ASAN-DLL: "{{.*}}cl-link{{.*}}.obj"
|
|
|
|
// RUN: %clang_cl /Zi /Tc%s -fuse-ld=link -### 2>&1 | FileCheck --check-prefix=DEBUG %s
|
|
// DEBUG: link.exe
|
|
// DEBUG: "-debug"
|
|
|
|
// Don't pass through /libpath: if it's not after a /link flag:
|
|
// RUN: %clang_cl /Tc%s /libpath:foo -fuse-ld=link -### /link /libpath:bar 2>&1 | FileCheck --check-prefix=LIBPATH %s
|
|
// LIBPATH: error: no such file or directory: '/libpath:foo'
|
|
// LIBPATH: libpath:bar
|
|
|
|
// PR27234
|
|
// RUN: %clang_cl /Tc%s nonexistent.obj -fuse-ld=link -### /link /libpath:somepath 2>&1 | FileCheck --check-prefix=NONEXISTENT %s
|
|
// RUN: %clang_cl /Tc%s nonexistent.lib -fuse-ld=link -### /link /libpath:somepath 2>&1 | FileCheck --check-prefix=NONEXISTENT %s
|
|
// RUN: %clang_cl /Tc%s nonexistent.obj -fuse-ld=link -### /winsysroot somepath 2>&1 | FileCheck --check-prefix=NONEXISTENT %s
|
|
// RUN: %clang_cl /Tc%s nonexistent.lib -fuse-ld=link -### /winsysroot somepath 2>&1 | FileCheck --check-prefix=NONEXISTENT %s
|
|
// RUN: %clang_cl /Tc%s nonexistent.obj -fuse-ld=link -### 2>&1 | FileCheck --check-prefix=NONEXISTENT %s
|
|
// RUN: %clang_cl /Tc%s nonexistent.lib -fuse-ld=link -### 2>&1 | FileCheck --check-prefix=NONEXISTENT %s
|
|
// NONEXISTENT-NOT: no such file
|
|
// NONEXISTENT: link.exe
|
|
// NONEXISTENT: nonexistent
|
|
|
|
// RUN: %clang_cl /Tc%s -fuse-ld=lld -### 2>&1 | FileCheck --check-prefix=USE_LLD %s
|
|
// USE_LLD: lld-link
|