Skip to content

Builder: Phase out --relax option adding #639

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

Closed
matthijskooijman opened this issue Apr 2, 2020 · 6 comments
Closed

Builder: Phase out --relax option adding #639

matthijskooijman opened this issue Apr 2, 2020 · 6 comments
Labels
type: enhancement Proposed improvement

Comments

@matthijskooijman
Copy link
Collaborator

When building a sketch, if the MCU is set to atmega2560, ,--relax is added to the linker commandline:

func addRelaxTrickIfATMEGA2560(buildProperties *properties.Map) string {
if buildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) == "atmega2560" {
return ",--relax"
}
return constants.EMPTY_STRING
}

This is something that really should be taken care of in the platform.txt file, not in the builder, since the current code assumes to much about the platform, such as that you're actually using gcc, and that the last option on the link commandline is actually a -Wl option (otherwise things break).

This seems to stem from way back when the Arduino IDE still generated commandlines explicitly: arduino/Arduino@fa4ab4f

However, it seems that this option can be just be added to the commandline unconditionally, it is potentially helpful for any board with > 8K flash. Maybe this was different for the compiler versions used in 2011 when this was added, but I actually suspect this option was just misunderstood.

I just tried adding the option on a Uno board (which saves a few bytes on the empty sketch) and an Arduino NG with atmega8, which also accepts the option but as expected it does not make a difference.

I'll provide a PR for the AVR core in a minute.

Once that is done, I think this code should be removed from arduino-cli. How shall we approach this? I can imagine adding a check to see if the option is present in platform.txt and if not show a warning to notify core authors to update their core, except that we do not really have any machinery to toggle such warnings meaningfully (so it might just confuse users).

Since it is just an optimization (without it, some calls might end up 2 bytes longer), we could also consider just removing this?

matthijskooijman added a commit to matthijskooijman/ArduinoCore-avr that referenced this issue Apr 2, 2020
This is currently automatically added by arduino-builder/arduino-cli,
but it should really be made explicit in the platform definition. This
allows removing it from arduino-cli later, see

    arduino/arduino-cli#639

This option tells the linker to replace "call" instructions by "rcall"
instructions where possible. This option was only automatically added
for the atmega2560, but it is actually useful for any ATmega with > 8K
flash (and a no-op for boards with <= 8K flash), so it can be added to
the commandline unconditionally.

This was tested on a Uno board (which saves a few bytes on the empty
sketch) and an Arduino NG with atmega8, which also accepts the option
but as expected it does not make a difference in sketch size.
matthijskooijman added a commit to matthijskooijman/ArduinoCore-avr that referenced this issue Apr 2, 2020
This is currently automatically added by arduino-builder/arduino-cli,
but it should really be made explicit in the platform definition. This
allows removing it from arduino-cli later, see

    arduino/arduino-cli#639

This option tells the linker to replace "call" instructions by "rcall"
instructions where possible. This option was only automatically added
for the atmega2560, but it is actually useful for any ATmega with > 8K
flash (and a no-op for boards with <= 8K flash), so it can be added to
the commandline unconditionally.

This was tested on a Uno board (which saves a few bytes on the empty
sketch) and an Arduino NG with atmega8, which also accepts the option
but as expected it does not make a difference in sketch size.

Because this option is added at the end, it does not conflict with the
automatically added option (the linker commandline just gets
`-Wl,--relax,--relax` which works fine.
@matthijskooijman
Copy link
Collaborator Author

Pullrequest for ArduinoCore-AVR is here: arduino/ArduinoCore-avr#327

@rsora rsora added component/core type: enhancement Proposed improvement labels Apr 2, 2020
@facchinm
Copy link
Member

Any concern in merging this? It would also incidentally solve arduino/ArduinoCore-avr#339 (comment)

@matthijskooijman
Copy link
Collaborator Author

It would indeed "solve" that, at least until arduino/ArduinoCore-avr#327 is merged.

@facchinm
Copy link
Member

Correct, but before merging arduino/ArduinoCore-avr#327 we should check if it's still an hard requirement with latest toolchains

@cmaglie
Copy link
Member

cmaglie commented May 20, 2020

Since it is just an optimization (without it, some calls might end up 2 bytes longer), we could also consider just removing this?

If removing it doesn't break existing cores why not, do you care pushing a PR for this?

@matthijskooijman
Copy link
Collaborator Author

If removing it doesn't break existing cores why not, do you care pushing a PR for this?

I think it does not break anything (only increases flash space for function calls). I can make a PR for this, but might take a while until I get around to that.

cmaglie added a commit to cmaglie/arduino-cli that referenced this issue Jun 11, 2020
umbynos pushed a commit that referenced this issue Jun 17, 2020
This removes the --relax option, potentially producing slightly bigger code for the atmega2560. On the longer term, the AVR core should just add this option for all boards, but this is not currently the case yet because removing --relax also works around a gcc miscompilation (see arduino/ArduinoCore-avr#339).

Close: #639
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

4 participants