[PATCH] D145646: [clang][driver] Enable '-flto' on AVR

Ben Shi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 8 20:36:42 PST 2023


benshi001 created this revision.
benshi001 added reviewers: MaskRay, aykevl.
Herald added subscribers: Jim, inglorion, dylanmckay.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: cfe-commits, jacquesguan.
Herald added a project: clang.

Fixes https://github.com/llvm/llvm-project/issues/55940


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145646

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/test/Driver/avr-ld.c


Index: clang/test/Driver/avr-ld.c
===================================================================
--- clang/test/Driver/avr-ld.c
+++ clang/test/Driver/avr-ld.c
@@ -43,3 +43,10 @@
 
 // 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"
Index: clang/lib/Driver/ToolChains/AVR.h
===================================================================
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -36,6 +36,8 @@
   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;
 
Index: clang/lib/Driver/ToolChains/AVR.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -506,6 +506,12 @@
     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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145646.503605.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230309/a3c1c6ab/attachment.bin>


More information about the cfe-commits mailing list