Skip to content

Commit

Permalink
[clang][driver] Enable '-flto' on AVR
Browse files Browse the repository at this point in the history
Reviewed By: MaskRay

Closes #55940

Differential Revision: https://reviews.llvm.org/D145646
  • Loading branch information
benshi001 committed Mar 22, 2023
1 parent fa0d4e1 commit 0d37efd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/AVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
}

if (D.isUsingLTO()) {
assert(!Inputs.empty() && "Must have at least one input.");
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
D.getLTOMode() == LTOK_Thin);
}

// 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.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/AVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class LLVM_LIBRARY_VISIBILITY AVRToolChain : public Generic_ELF {
std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
FileType Type) const override;

bool HasNativeLLVMSupport() const override { return true; }

protected:
Tool *buildLinker() const override;

Expand Down
14 changes: 14 additions & 0 deletions clang/test/Driver/avr-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@

// RUN: %clang -### --target=avr -mmcu=atxmega128a1 --rtlib=libgcc --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKO %s
// LINKO: {{".*ld.*"}} {{.*}} {{"-L.*avrxmega7"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x802000" "--start-group" {{.*}} "-latxmega128a1" {{.*}} "--end-group" "--relax" "-mavrxmega7"

// RUN: %clang -### --target=avr -mmcu=atmega328 -flto --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKP %s
// LINKP: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" "-plugin" {{.*}} "-plugin-opt=mcpu=atmega328"

// RUN: %clang -### --target=avr -flto --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKQ %s
// LINKQ: {{".*ld.*"}} {{.*}} "-plugin"
// LINKQ-NOT: "-plugin-opt=mcpu"

// RUN: %clang -### --target=avr -mmcu=atmega328 -flto=thin --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKR %s
// LINKR: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" "-plugin" {{.*}} "-plugin-opt=mcpu=atmega328" "-plugin-opt=thinlto"

// RUN: %clang -### --target=avr -mmcu=atmega328 -flto --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKS %s
// LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" "-plugin" {{.*}} "-plugin-opt=mcpu=atmega328"
// LINKS-NOT: "-plugin-opt=thinlto"

0 comments on commit 0d37efd

Please sign in to comment.