Skip to content

[clang][driver] Add avr-libc's default linker script to lld #68507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions clang/lib/Driver/ToolChains/AVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
22 changes: 22 additions & 0 deletions clang/test/Driver/avr-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down