-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[AVR] Handle flash RO data mapped to data space for newer devices #146244
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA, | |
// This is almost always required because otherwise avr-ld | ||
// will assume 'avr2' and warn about the program being larger | ||
// than the bare minimum supports. | ||
if (Linker.find("avr-ld") != std::string::npos && FamilyName) | ||
CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName)); | ||
if (Linker.find("avr-ld") != std::string::npos && FamilyName) { | ||
// Option to use mapped memory for modern devices with >32kB flash. | ||
// This is the only option for modern devices with <= 32kB flash, | ||
// but the larger default to a copy from flash to RAM (avr-ld version < 14) | ||
// or map the highest 32kB to RAM (avr-ld version >= 14). | ||
if (Args.hasFlag(options::OPT_mflmap, options::OPT_mrodata_in_ram, false)) { | ||
CmdArgs.push_back( | ||
Args.MakeArgString(std::string("-m") + *FamilyName + "_flmap")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not familiar with these options. Are we sure this patch has listed all the effects? gcc also seems to do something with the At the minimum, we need clang/test/Driver tests to check how a driver option influences the link options. For features, we need other tests (perhaps clang/test/CodeGen/AVR, which does not exist yet) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, so I think I need more time to understand the whole picture what gcc did. |
||
CmdArgs.push_back(Args.MakeArgString(std::string("-u"))); | ||
CmdArgs.push_back(Args.MakeArgString(std::string("__do_flmap_init"))); | ||
} else | ||
CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName)); | ||
} | ||
|
||
C.addCommand(std::make_unique<Command>( | ||
JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,11 +263,17 @@ bool AVRAsmPrinter::doFinalization(Module &M) { | |
auto *Section = cast<MCSectionELF>(TLOF.SectionForGlobal(&GO, TM)); | ||
if (Section->getName().starts_with(".data")) | ||
NeedsCopyData = true; | ||
else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) | ||
else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) { | ||
// AVRs that have a separate program memory (that's most AVRs) store | ||
// .rodata sections in RAM. | ||
NeedsCopyData = true; | ||
else if (Section->getName().starts_with(".bss")) | ||
// .rodata sections in RAM, | ||
// but XMEGA3 family maps all flash in the data space. | ||
Patryk27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Forcing pulling in __do_copy_data with 0 bytes to copy is a (minor) | ||
// waste, so we let the loader handle this for newer devices. | ||
if (!(SubTM->hasFeatureSetFamilyXMEGA2() || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we check for Feels like that's what it is supposed to do, but we use family as a proxy for the actual flag we're interested in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment, the new clang driver switch is just a feature, to select an option for All other changes (mainly adding some metadata for newer xmega devices) just gets the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless trivial (e.g. typo fix), "marked this conversation as resolved." should only be used by reviewers per suggestions on https://discourse.llvm.org/t/rfc-github-pr-resolve-conversation-button/73178 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Sorry, didn't see that tomtor is the author :) ) |
||
SubTM->hasFeatureSetFamilyXMEGA3() || | ||
SubTM->hasFeatureSetFamilyXMEGA4())) | ||
NeedsCopyData = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, for these newer devices |
||
} else if (Section->getName().starts_with(".bss")) | ||
NeedsClearBSS = true; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benshi001 If this line is relocated (moved a bit upwards) so that it is before handling user supplied linker arguments then a user could overwrite the default
-m
option.As it is the user cannot overwrite the driver generated option.