[clang] 169f60f - [clang][driver] Add avr-libc's default linker script to lld (#68507)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 14 22:48:02 PDT 2023
Author: Ben Shi
Date: 2023-10-15T13:47:56+08:00
New Revision: 169f60f7c76cb6f7d234ab5dfb2b5e367a35ccbb
URL: https://github.com/llvm/llvm-project/commit/169f60f7c76cb6f7d234ab5dfb2b5e367a35ccbb
DIFF: https://github.com/llvm/llvm-project/commit/169f60f7c76cb6f7d234ab5dfb2b5e367a35ccbb.diff
LOG: [clang][driver] Add avr-libc's default linker script to lld (#68507)
If `-fuse-ld=lld` is specified but no user linker script is offered, we
try to use avr-libc's default one for lld. (not needed for GNU ld)
Added:
clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrtiny.x
clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x
Modified:
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-ld.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index e312fa155e11bf8..2e46b25aeba75ef 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -554,8 +554,18 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("--end-group");
- // Add user specified linker script.
- Args.AddAllArgs(CmdArgs, options::OPT_T);
+ // Add avr-libc's linker script to lld by default, if it exists.
+ if (!Args.hasArg(options::OPT_T) &&
+ Linker.find("lld") != std::string::npos) {
+ std::string Path(*AVRLibcRoot + "/lib/ldscripts/");
+ Path += *FamilyName;
+ Path += ".x";
+ if (llvm::sys::fs::exists(Path))
+ CmdArgs.push_back(Args.MakeArgString("-T" + Path));
+ }
+ // Otherwise add user specified linker script to either avr-ld or lld.
+ else
+ Args.AddAllArgs(CmdArgs, options::OPT_T);
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
CmdArgs.push_back("--relax");
diff --git a/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrtiny.x b/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrtiny.x
new file mode 100644
index 000000000000000..e69de29bb2d1d64
diff --git a/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x b/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x
new file mode 100644
index 000000000000000..e69de29bb2d1d64
diff --git a/clang/test/Driver/avr-ld.c b/clang/test/Driver/avr-ld.c
index 0f12607fe9d69eb..3e4114485332fcd 100644
--- a/clang/test/Driver/avr-ld.c
+++ b/clang/test/Driver/avr-ld.c
@@ -58,6 +58,28 @@
// LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" "-plugin-opt=mcpu=atmega328"
// LINKS-NOT: "-plugin-opt=thinlto"
+// RUN: %clang -### --target=avr -mmcu=attiny40 -fuse-ld=lld --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT0 %s
+// LINKT0: {{".*lld.*"}} {{.*}} {{"-T.*avrtiny.x"}}
+// LINKT0-NOT: "-m
+
+// RUN: %clang -### --target=avr -mmcu=atxmega384c3 -fuse-ld=lld --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT1 %s
+// LINKT1: {{".*lld.*"}} {{.*}} {{"-T.*avrxmega6.x"}}
+// LINKT1-NOT: "-m
+
+// RUN: %clang -### --target=avr -mmcu=atmega328 -fuse-ld=lld --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT2 %s
+// LINKT2: {{".*lld.*"}} {{.*}} "--start-group" {{.*}} "--end-group"
+// LINKT2-NOT: "-T
+// LINKT2-NOT: "-m
+
+// RUN: %clang -### --target=avr -mmcu=attiny40 --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT3 %s
+// LINKT3: {{".*ld.*"}} {{.*}} "-mavrtiny"
+// LINKT3-NOT: "-T
+
+// RUN: %clang -### --target=avr -mmcu=attiny40 --sysroot %S/Inputs/basic_avr_tree -fuse-ld=lld -T %S/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x %s 2>&1 | FileCheck -check-prefix LINKT4 %s
+// LINKT4: {{".*lld.*"}} {{.*}} {{"-T.*avrxmega6.x"}}
+// LINKT4-NOT: {{"-T.*avrtiny.x"}}
+// LINKT4-NOT: "-m
+
// RUN: %clang -### -r --target=avr -mmcu=atmega328 --sysroot %S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKU %s
// LINKU: {{".*ld.*"}} {{.*}} "-r" {{.*}} "-mavr5"
// LINKU-NOT: "--gc-sections"
More information about the cfe-commits
mailing list