Index: clang/lib/Driver/ToolChains/AVR.cpp =================================================================== --- clang/lib/Driver/ToolChains/AVR.cpp +++ clang/lib/Driver/ToolChains/AVR.cpp @@ -433,7 +433,6 @@ std::string Linker = getToolChain().GetProgramPath(getShortName()); ArgStringList CmdArgs; - AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); @@ -487,6 +486,11 @@ D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU; } + auto addInputsForThisLinker = [this, &Inputs, &Args, &CmdArgs, + &JA]() -> void { + AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); + }; + // If the family name is known, we can link with the device-specific libgcc. // Without it, libgcc will simply not be linked. This matches avr-gcc // behavior. @@ -506,6 +510,8 @@ // Add the link library specific to the MCU. CmdArgs.push_back(Args.MakeArgString(std::string("-l") + CPU)); + addInputsForThisLinker(); + CmdArgs.push_back("--end-group"); // Specify the family name as the emulation mode to use. @@ -513,6 +519,8 @@ // will assume 'avr2' and warn about the program being larger // than the bare minimum supports. CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName)); + } else { + addInputsForThisLinker(); } C.addCommand(std::make_unique(