Skip to content

Commit

Permalink
[M68k] Fix ODR violation in GISel code (#72797)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petrochenkov authored Dec 14, 2023
1 parent 2047ab0 commit 8cb8428
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
23 changes: 22 additions & 1 deletion llvm/lib/Target/M68k/GISel/M68kCallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@

using namespace llvm;

namespace {

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

struct CallReturnHandler : public M68kIncomingValueHandler {
CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
MachineInstrBuilder &MIB)
: M68kIncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}

private:
void assignValueToReg(Register ValVReg, Register PhysReg,
const CCValAssign &VA) override;

MachineInstrBuilder &MIB;
};

} // end anonymous namespace

M68kCallLowering::M68kCallLowering(const M68kTargetLowering &TLI)
: CallLowering(&TLI) {}

Expand Down Expand Up @@ -119,7 +140,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());
Expand Down
17 changes: 0 additions & 17 deletions llvm/lib/Target/M68k/GISel/M68kCallLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,6 @@ struct M68kIncomingValueHandler : public CallLowering::IncomingValueHandler {
MachinePointerInfo &MPO,
ISD::ArgFlagsTy Flags) override;
};

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

struct CallReturnHandler : public M68kIncomingValueHandler {
CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
MachineInstrBuilder &MIB)
: M68kIncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}

private:
void assignValueToReg(Register ValVReg, Register PhysReg,
const CCValAssign &VA) override;

MachineInstrBuilder &MIB;
};
} // end namespace llvm

#endif // LLVM_LIB_TARGET_M68K_GLSEL_M68KCALLLOWERING_H

0 comments on commit 8cb8428

Please sign in to comment.