Skip to content

[Driver][SYCL] Do not imply defaultlib msvcrt for Linux based driver on Windows #3827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2021

Conversation

mdtoguchi
Copy link
Contributor

When compiling for Windows target, we should only be adding the
defaultlib msvcrt directive when performing MSVC compatible compilations.
If adding msvcrt for Linux style compilations, we do not know if
the library should be the regular library or the debug library, as that
is determined by the use of /MD or /MDd.

When compiling for Windows target, we should only be adding the
defaultlib msvcrt directive when performing MSVC compatible compilations.
If adding msvcrt for Linux style compilations, we do not know if
the library should be the regular library or the debug library, as that
is determined by the use of /MD or /MDd.
@mdtoguchi mdtoguchi requested a review from AGindinson as a code owner May 26, 2021 20:00
@bader bader requested a review from v-klochkov May 27, 2021 07:59
Copy link
Contributor

@AGindinson AGindinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch LGTM; I double @bader's request for @v-klochkov's input here (could be some context that I'm missing).

@mdtoguchi
Copy link
Contributor Author

Always pulling in msvcrt is problematic as it can potentially conflict with msvcrtd when attempting to build a debug configured project. Maybe it can be tweaked to add msvcrtd if -D_DEBUG is also passed?

@v-klochkov
Copy link
Contributor

v-klochkov commented Jun 2, 2021

Why the description says "do not imply msvcrt for non-msvc Windows", while the change removes the msvcrt for msvc-windows? The change is done under 'if (AuxT.isWindowsMSVCEnvironment())' condition.

@@ -4663,7 +4663,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (AuxT.isWindowsMSVCEnvironment()) {
CmdArgs.push_back("-D_MT");
CmdArgs.push_back("-D_DLL");
CmdArgs.push_back("--dependent-lib=msvcrt");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is hard to tell, why the new code would work properly. It does not seem correct to me now.
The idea of the line that is removed here was to enforce dynamic MSVC RT with -fsycl switch for clang++ driver.

For CL mode the MSVC RT is set in addClangCLArgs() and CL allows either /MD (msvcrt) or /MDd (msvcrtd).
The line that was removed in this patch is for 'clang++' driver, which does not allow setting /MDd, and thus the only option for -fsycl is msvcrt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What RT is used in the patched compiler (i.e. clang++ -fsycl test.cpp)? If that is libcmt (which is by default), then there may be errors caused by using msvcrt in SYCL and libcmt in test.obj

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default library (msvcrt) used is passed to the link step via -defaultlib:

> clang++ -fsycl --target=x86_64-pc-windows-msvc ~/a.cpp -### 2>&1 | grep msvcrt "link.exe" "-out:a.exe" "-defaultlib:msvcrt" "-defaultlib:oldnames" "-defaultlib:sycl.lib" "/IGNORE:4078" "-libpath:lib/amd64" "-libpath:atlmfc/lib/amd64" "-nologo" "/tmp/a-ca1b1c.o" "/tmp/a-028002.o"

The use of the -defaultlib option is used for clang++ and the embedded default directives are used for clang-cl.

@mdtoguchi mdtoguchi changed the title [Driver][SYCL] Do not imply defaultlib msvcrt for non-MSVC Windows [Driver][SYCL] Do not imply defaultlib msvcrt for Linux based driver on Windows Jun 2, 2021
@v-klochkov
Copy link
Contributor

I still do not understand the motivation for the change.
The description says:

"If adding msvcrt for Linux style compilations, we do not know if
the library should be the regular library or the debug library, as that
is determined by the use of /MD or /MDd."

clang++ does NOT accept /MDd switch and thus there is no way to use debug msvcrtd RT, right? I would think the RT library is always regular (even with -g).

My other concern is that with the patch there is no even a warning telling user that something may go wrong if user compiles sources as below:

NOW (without patch):
ksh-3.2$ clang++ -fsycl test.cpp -c
ksh-3.2$ clang++ test.o ../builds/xmainefi2win_prod/llvm/lib/sycl.lib
LINK : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
test.o : warning LNK4217: locally defined symbol _invalid_parameter_noinfo_noreturn imported in function "void __cdecl std::_Adjust_manually_vector_aligned(void * &,unsigned __int64 &)" (?_Adjust_manually_vector_aligned@std@@YAXAEAPEAXAEA_K@Z)

With the patch:
ksh-3.2$ clang++ -fsycl test.cpp -c
ksh-3.2$ clang++ test.o ../builds/xmainefi2win_prod/llvm/lib/sycl.lib
test.o : warning LNK4217: locally defined symbol _invalid_parameter_noinfo_noreturn imported in function "void __cdecl std::_Adjust_manually_vector_aligned(void * &,unsigned __int64 &)" (?_Adjust_manually_vector_aligned@std@@YAXAEAPEAXAEA_K@Z)

ksh-3.2$ clang++ test.o ../builds/xmainefi2win_prod/llvm/lib/sycl.lib -### 2>&1 | grep defaultlib
"c:/Program files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023\bin\Hostx64\x64\link.exe" "-out:a.exe" "-defaultlib:libcmt" "-defaultlib:libmmt" "-defaultlib:oldnames" "-nologo" "test.o" "../builds/xmainefi2win_prod/llvm/lib/sycl.lib"

@v-klochkov
Copy link
Contributor

clang++ does NOT accept /MDd switch and thus there is no way to use debug msvcrtd RT, right? I would think the RT library is always regular (even with -g).

Ok, I forgot about using "-Xclang --dependent-lib=msvcrtd", which is also correct usage and interferes with the implied msvcrt.
I am not blocking the patch anymore.
Perhaps @alexbatashev would also take a look and comment.

@v-klochkov v-klochkov requested a review from alexbatashev June 2, 2021 18:55
@bader
Copy link
Contributor

bader commented Jun 3, 2021

Perhaps @alexbatashev would also take a look and comment.

@alexbatashev, ping.

@bader bader merged commit d3dc212 into intel:sycl Jun 3, 2021
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Jun 4, 2021
* sycl: (320 commits)
  [SYCL] Silence a "local variable is initialized but not referenced" warning; NFC (intel#3870)
  [SYCL] Improve SYCL_DEVICE_ALLOWLIST (intel#3826)
  [SPIR-V] Change return value of mapType function (intel#3871)
  [SYCL] Fix post-commit failure in handler.hpp from unused-parameters. (intel#3874)
  [Driver][SYCL] Do not imply defaultlib msvcrt for Linux based driver on Windows (intel#3827)
  [SYCL] Unique stable name rebase (intel#3835)
  [SYCL] Align behavior of empty command groups with SYCL2020 (intel#3822)
  [SYCL][ESIMD] Make typenames and constants consistent with SYCL API style. (intel#3850)
  [SYCL] Allow __failed_assertion to support libstdc++-11 (intel#3774)
  [SYCL] Refactor stream class handing implementation (intel#3646)
  [SYCL] Fix syntax error introduced in intel#3401 (intel#3861)
  [SYCL] SYCL 2020 sub_group algorithms (intel#3786)
  [Buildbot][NFC] Add option to use LLD as linker (intel#3866)
  Revert "Emit correct location lists with basic block sections."
  [SPIRITTAnnotations] Fix debug info for ITT calls. (intel#3829)
  [SYCL][Doc] Fix build of Sphinx docs (intel#3863)
  [SYCL][FPGA][NFC] Tidy up intel_fpga_reg codegen test (intel#3810)
  [CODEOWNERS] Fix SPIRITTAnnnotations tests ownership (intel#3859)
  [SYCL][ESIMD] Host-compile simd.cpp test, fix errors & warnings. (intel#3846)
  [SYCL] Store pointers to memory allocations instead of iterators (intel#3860)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants