Skip to content
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

bootstrap: "download-ci-llvm = true" doesn't work on x86_64-pc-windows-gnu with lld #107668

Closed
petrochenkov opened this issue Feb 4, 2023 · 11 comments · Fixed by #119159
Closed
Labels
A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@petrochenkov
Copy link
Contributor

You get an error like this:

   Compiling rustc_driver v0.0.0 (C:\msys64\home\we\rust\compiler\rustc_driver)
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
...
  = note: ld.lld: error: duplicate symbol: vtable for llvm::FormalArgHandler
          >>> defined at librustc_llvm-a81737dd65a7c126.rlib(M68kCallLowering.cpp.obj)
          >>> defined at librustc_llvm-a81737dd65a7c126.rlib(PPCCallLowering.cpp.obj)
          collect2.exe: error: ld returned 1 exit status

I didn't investigate it further.

It never worked in the past and I assumed it's due to the old mingw version on CI, but it still doesn't work after #100178 and the actual error doesn't look like it's caused by a toolchain version.

@petrochenkov petrochenkov added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. labels Feb 4, 2023
@mati865
Copy link
Contributor

mati865 commented Feb 7, 2023

It happens only with LLD but i haven't investigated.
At MSYS2 we had to remove M68k to maskę it build with LLD but since 1.67 we no longer got this issue: https://github.com/msys2/MINGW-packages/pull/15256/files#diff-9d9b9deaf0bc40ce778f7bbeae62dd4b0c7a3269b7cf080ab80acfb8b5d561d9L8

@jyn514 jyn514 added the A-linkage Area: linking into static, shared libraries and binaries label Feb 17, 2023
@jyn514
Copy link
Member

jyn514 commented Feb 17, 2023

cc #39915

do either of you know what LLD is doing differently compared to LD? is this something rustc controls? It would help to have a minimization smaller than "all of rustc and llvm" ...

@jyn514 jyn514 changed the title bootstrap: "download-ci-llvm = true" doesn't work on x86_64-pc-windows-gnu bootstrap: "download-ci-llvm = true" doesn't work on x86_64-pc-windows-gnu with lld Feb 17, 2023
@mati865
Copy link
Contributor

mati865 commented Feb 19, 2023

I don't know the answer to any of those questions but this issue stopped happening at MSYS2 so it could have been some LLVM 16 change (MSYS2 uses LLVM 15 but backports important patches from LLVM 16) that fixed this problem there.

@jyn514
Copy link
Member

jyn514 commented Feb 19, 2023

Looks like we're currently using LLVM 15: https://github.com/rust-lang/llvm-project/tree/rustc/15.0-2022-12-07

@rustbot label +S-blocked

@rustbot rustbot added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 19, 2023
@mati865
Copy link
Contributor

mati865 commented Feb 19, 2023

Yup, I plan to try once #107224 is merged.

@petrochenkov
Copy link
Contributor Author

This is still an issue with LLVM 17.0.5.

@petrochenkov
Copy link
Contributor Author

There's an ODR violation in M68k's FormalArgHandler, its base class M68kIncomingValueHandler doesn't have a virtual method markPhysRegUsed while IncomingValueHandler for all other targets including PPC do.

So it's not a linker's problem, ld actually complains about this too, it just reports it as a warning instead of an error.

The simplest fix is to rename the structure (instead of adding virtual methods).

diff --git a/llvm/lib/Target/M68k/GISel/M68kCallLowering.cpp b/llvm/lib/Target/M68k/GISel/M68kCallLowering.cpp
index b0ada29d1cea..93b250656cd2 100644
--- a/llvm/lib/Target/M68k/GISel/M68kCallLowering.cpp
+++ b/llvm/lib/Target/M68k/GISel/M68kCallLowering.cpp
@@ -118,7 +118,7 @@ bool M68kCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
   CCAssignFn *AssignFn =
       TLI.getCCAssignFn(F.getCallingConv(), false, F.isVarArg());
   IncomingValueAssigner ArgAssigner(AssignFn);
-  FormalArgHandler ArgHandler(MIRBuilder, MRI);
+  M68kFormalArgHandler ArgHandler(MIRBuilder, MRI);
   return determineAndHandleAssignments(ArgHandler, ArgAssigner, SplitArgs,
                                        MIRBuilder, F.getCallingConv(),
                                        F.isVarArg());
diff --git a/llvm/lib/Target/M68k/GISel/M68kCallLowering.h b/llvm/lib/Target/M68k/GISel/M68kCallLowering.h
index a1589e96aa3d..5e05e46f4ac4 100644
--- a/llvm/lib/Target/M68k/GISel/M68kCallLowering.h
+++ b/llvm/lib/Target/M68k/GISel/M68kCallLowering.h
@@ -63,8 +63,8 @@ private:
                            ISD::ArgFlagsTy Flags) override;
 };

-struct FormalArgHandler : public M68kIncomingValueHandler {
-  FormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
+struct M68kFormalArgHandler : public M68kIncomingValueHandler {
+  M68kFormalArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
       : M68kIncomingValueHandler(MIRBuilder, MRI) {}
 };

I wish I tried to debug this a few years eariler.

@petrochenkov
Copy link
Contributor Author

Could someone submit this to LLVM?
I'm not familiar with their processes.
cc @nikic

@mati865
Copy link
Contributor

mati865 commented Nov 17, 2023

You can simply open pull request to https://github.com/llvm/llvm-project/
Otherwise I can do it this or next weekend.

@petrochenkov
Copy link
Contributor Author

Opened a pull request with the fix - llvm/llvm-project#72797

nikic pushed a commit to llvm/llvm-project that referenced this issue Dec 14, 2023
It prevents LLVM from being linked with LLD at least on Windows, with
errors like this:

```
  = note: ld.lld: error: duplicate symbol: vtable for llvm::FormalArgHandler
          >>> defined at librustc_llvm-a81737dd65a7c126.rlib(M68kCallLowering.cpp.obj)
          >>> defined at librustc_llvm-a81737dd65a7c126.rlib(PPCCallLowering.cpp.obj)
```

Binutils linker also complains about this, but only with warnings.

`FormalArgHandler` has a base class `M68kIncomingValueHandler` which
doesn't have a virtual method `markPhysRegUsed` like
`IncomingValueHandler`s for all other targets including PPC, so it
results in a conflict.
The simplest fix is to rename the `FormalArgHandler` structure (rather
than to add virtual methods for compatibility).

cc rust-lang/rust#107668
@petrochenkov
Copy link
Contributor Author

Fixed in #119159.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 20, 2023
Update LLVM submodule

to pick up "[M68k] Fix ODR violation in GISel code (rust-lang#72797)" rust-lang/llvm-project#159.

Fixes rust-lang#107668
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 20, 2023
Rollup merge of rust-lang#119159 - petrochenkov:llvmup, r=nikic

Update LLVM submodule

to pick up "[M68k] Fix ODR violation in GISel code (rust-lang#72797)" rust-lang/llvm-project#159.

Fixes rust-lang#107668
qihangkong pushed a commit to rvgpu/rvgpu-llvm that referenced this issue Apr 23, 2024
It prevents LLVM from being linked with LLD at least on Windows, with
errors like this:

```
  = note: ld.lld: error: duplicate symbol: vtable for llvm::FormalArgHandler
          >>> defined at librustc_llvm-a81737dd65a7c126.rlib(M68kCallLowering.cpp.obj)
          >>> defined at librustc_llvm-a81737dd65a7c126.rlib(PPCCallLowering.cpp.obj)
```

Binutils linker also complains about this, but only with warnings.

`FormalArgHandler` has a base class `M68kIncomingValueHandler` which
doesn't have a virtual method `markPhysRegUsed` like
`IncomingValueHandler`s for all other targets including PPC, so it
results in a conflict.
The simplest fix is to rename the `FormalArgHandler` structure (rather
than to add virtual methods for compatibility).

cc rust-lang/rust#107668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants