Skip to content

ARMC6: Add a build profile extension with the link-time optimizer enabled #11874

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

Conversation

fkjagodzinski
Copy link
Member

@fkjagodzinski fkjagodzinski commented Nov 15, 2019

Description (required)

Summary of change (What the change is for and why)

Added an lto build profile extension for ARMC6 toolchain.

  • added -flto to common flags,
  • added --lto & --lto_level=Oz to ld flags.
Results

Product: ARM Compiler 6.11 Professional Component: ARM Compiler 6.11 Tool: armclang [5d3b4200]

[email protected]

Mbed OS branch commit SHA RAM (data + bss) Flash (text + data) build time details
mbed-os-5.14.1 679d248 206047 39168 739.53 blinky-679d248.txt
armc6_build-enable_lto_for_release c6a655f 205848 36601 610.81 blinky-c6a655f.txt

[email protected]

Mbed OS branch commit SHA RAM (data + bss) Flash (text + data) build time details
mbed-os-5.14.1 679d248 252457 361038 828.68 ccexample-679d248.txt
armc6_build-enable_lto_for_release c6a655f 251580 329505 835.21 ccexample-c6a655f.txt
Build commands used to produce the above results

mbed-os-example-blinky

cd $(mktemp -d)
git clone [email protected]:ARMmbed/mbed-os-example-blinky.git
cd mbed-os-example-blinky/
git checkout mbed-os-5.14.1
git clean -dxff && git reset --hard

# Define Mbed OS rev
# 1. mbed-os-5.14.1
echo 'https://github.com/ARMmbed/mbed-os/#679d24833acf0a0b5b0d528576bb37c70863bc4e' > mbed-os.lib
# 2. LTO branch on top of mbed-os-5.14.1
echo 'https://github.com/fkjagodzinski/mbed-os/#d7df3e673144232d3e162de19ec13f0472d725c6' > mbed-os.lib

mbed deploy
cd mbed-os/ && git log --oneline -1 && cd ..
time -p mbed compile -t ARM -m K64F --profile mbed-os/tools/profiles/release.json

# More details
mbed compile -t ARM -m K64F --profile mbed-os/tools/profiles/release.json --stats-depth=100

mbed-cloud-client-example

cd $(mktemp -d)
git clone [email protected]:ARMmbed/mbed-cloud-client-example.git
cd mbed-cloud-client-example/
git checkout 4.0.0 
git clean -dxff && git reset --hard
cp ../mbed_cloud_dev_credentials.c .

# Define Mbed OS rev
# 1. mbed-os-5.14.1
echo 'https://github.com/ARMmbed/mbed-os/#679d24833acf0a0b5b0d528576bb37c70863bc4e' > mbed-os.lib
# 2. LTO branch on top of mbed-os-5.14.1
echo 'https://github.com/fkjagodzinski/mbed-os/#d7df3e673144232d3e162de19ec13f0472d725c6' > mbed-os.lib

mbed deploy
cd mbed-os/ && git log --oneline -1 && cd ..
time -p mbed compile -t ARM -m K64F --profile mbed-os/tools/profiles/release.json

# More details
mbed compile -t ARM -m K64F --profile mbed-os/tools/profiles/release.json --stats-depth=100
Documentation (Details of any document updates required)

Pull request type (required)

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[x] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results (required)

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers (optional)

@jamesbeyond @kjbracey-arm @maciejbocianski


Release Notes (required for feature/major PRs)

Summary of changes

Add a build profile extension with the link-time optimizer enabled for ARMC6 toolchain.

Impact of changes
Migration actions required

@ciarmcom
Copy link
Member

@fkjagodzinski, thank you for your changes.
@maciejbocianski @jamesbeyond @kjbracey-arm @ARMmbed/mbed-os-tools @ARMmbed/mbed-os-maintainers please review.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also do it for develop?

@jamesbeyond
Copy link
Contributor

based on the original plan this is for 5.15. So now is this 5.15 or 6.0 @bulislaw @0xc0170

@fkjagodzinski fkjagodzinski changed the title ARMC6: Enable link-time optimizer for release profile ARMC6: Enable link-time optimizer for release & develop profiles Nov 22, 2019
@fkjagodzinski
Copy link
Member Author

[email protected], ARMC6, develop profile, Windows host

Mbed OS branch commit SHA RAM (data + bss) Flash (text + data) build time rebuild time
mbed-os-5.14.1 679d248 252165 406682 875.66 26.50
armc6_build-enable_lto d7df3e6 251709 390132 917.86 37.90

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2019

based on the original plan this is for 5.15. So now is this 5.15 or 6.0 @bulislaw @0xc0170

I don't recall seeing a move to 6.0 for this one. @bulislaw ?

I would mark this as Major update as it might have consequences to apps .

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 22, 2019

Set to 5.15 as agreed.

I'll trigger the first CI run

@mbed-ci
Copy link

mbed-ci commented Nov 22, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM

@jamesbeyond
Copy link
Contributor

Seems this PR only touched ARMC6 options, not sure why IAR and GCC failed. I'll try to restart CI

@mbed-ci
Copy link

mbed-ci commented Nov 24, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 25, 2019

The artifacts report green for GCC and IAR. just focus on failures in ARM:

Error: L6915E: Library reports error: Heap was used, but no heap region was defined
Finished: 0 information, 1 warning and 1 error messages.

@fkjagodzinski Please review

@maciejbocianski
Copy link
Contributor

The artifacts report green for GCC and IAR. just focus on failures in ARM:

Error: L6915E: Library reports error: Heap was used, but no heap region was defined
Finished: 0 information, 1 warning and 1 error messages.

@fkjagodzinski Please review

This error is due to lack of ARM_LIB_HEAP section in scatter file

@adbridge
Copy link
Contributor

@kjbracey-arm if the GCC version of this PR has been marked as a breaking change is this one different ?

@adbridge
Copy link
Contributor

@fkjagodzinski similarly to the GCC equivalent changes if the user has to do anything to use these changes (such as adding an additional header file), could you please fill in the impact and migration sections in the release notes accordingly ? Thanks

@fkjagodzinski
Copy link
Member Author

Added one commit from @maciejbocianski that fixes RTC_IRQHandler linker error. Thanks Maciej! 👍

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM

@kjbracey
Copy link
Contributor

That RTC_IRQHandler thing smells like a compiler/linker bug to me. Don't see why that should fail.

There is a similar trap for types that can hit LTO - you're not allowed to have duplicate type names in different files in C++. To avoid that you have to stick them in an anonymous namespace, which is the equivalent of making the type static/local.

But this seems legal to me. At least as long as you weren't including a header file declaring the external RTC_IRQHandler, which you're not.

@maciejbocianski
Copy link
Contributor

Another problem which I haven't solved yet is:
L6137E: Symbol $Sub$$calloc was not preserved by the LTO codegen but is needed by the image.

Error is visible when -DMBED_HEAP_STATS_ENABLED or -DMBED_ALL_STATS_ENABLED is defined

@fkjagodzinski
Copy link
Member Author

I've added two more fixes form https://github.com/maciejbocianski/mbed-os/commits/fix_armc6_lto. @jamesbeyond, @0xc0170 I think this is ready to pass CI now.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 29, 2019

CI started

Isn't there a better way for d71637b (using dummy value there to keep the function in) ?

Add a "used" attribute to __vector_handlers to fix ARMC6 build with
the "-flto" flag.
(Error: L6236E: No section matches selector - no section to be FIRST/LAST.)

This attribute, attached to a function/variable, means that code must be emitted
for the function even if it appears that the function is not referenced.
Add a "used" attribute to __vector_handlers to fix ARMC6 build with
the "-flto" flag.
(Error: L6236E: No section matches selector - no section to be FIRST/LAST.)

This attribute, attached to a function/variable, means that code must be emitted
for the function even if it appears that the function is not referenced.
Add a "used" attribute to __vector_handlers to fix ARMC6 build with
the "-flto" flag.
(Error: L6236E: No section matches selector - no section to be FIRST/LAST. )

This attribute, attached to a function/variable, means that code must be emitted
for the function even if it appears that the function is not referenced.
…LTO builds

Add a "used" attribute to SVCHandler_main/tfm_pendsv_do_schedule to fix ARMC6 build with
the "-flto" flag.

This attribute, attached to a function/variable, means that code must be emitted
for the function even if it appears that the function is not referenced.
@maciejbocianski maciejbocianski force-pushed the armc6_build-enable_lto_for_release branch from cd42f67 to 083e3e5 Compare February 4, 2020 11:40
@maciejbocianski
Copy link
Contributor

rebase done

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Feb 4, 2020

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 11
Build artifacts

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any docs PR for this profile extension?

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 5, 2020

@bulislaw @kjbracey-arm Please review the final version, it is be ready to go in.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, do we have docs following this PR?

@maciejbocianski
Copy link
Contributor

Looks good, do we have docs following this PR?

There is no docs yet @jamesbeyond @bulislaw

@jamesbeyond
Copy link
Contributor

There is no docs yet @jamesbeyond @bulislaw

We are prepare docs, and will be put into:
https://os.mbed.com/docs/mbed-os/v5.15/tutorials/optimizing.html

@0xc0170 0xc0170 merged commit 32675cc into ARMmbed:master Feb 5, 2020
@mergify mergify bot removed the ready for merge label Feb 5, 2020
@fkjagodzinski fkjagodzinski deleted the armc6_build-enable_lto_for_release branch February 10, 2020 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-version: 6.0.0-alpha-2 Second pre-release version of 6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants