Commit Graph

73 Commits (4d8127223c57cbf2db82c1bda3503ab12b447387)

Author SHA1 Message Date
Kevin Bracey 4caab1cce5 Turn on ARM linker --inline
For release and develop profiles, turn on the linker's `--inline`
optimisation. This can save a couple of hundred bytes in a typical
image.

The optimisation replaces branches to small functions with the
inlined code from those functions. And it's possible that the
out-of-line functions can be eliminated.

Setting confined to release and develop builds only, as it can lead to
invalid debug information.
2020-04-17 13:28:22 +03:00
Qinghao Shi 5822903992 update lto profile including printf wrap functions 2020-03-29 20:55:08 +01:00
Anna Bridge 83926138aa
Merge pull request #11726 from kjbracey-arm/armc6_no_static_destructors
Disable C++ static destructors in ARMC6 compiler
2020-03-27 14:14:00 +00:00
Kevin Bracey 1ecd9604f6 Disable C++ static denstructors in ARMC6 compiler
We disable C++ static destructors as best as possible in the various
toolchains, trying to eliminate unwanted destructor code. We don't want
to waste RAM or ROM on the C++-standard-specified behaviour of running
all statically-constructed objects' destructors in reverse order on
exit; we're never going to perform an orderly exit.

Techniques used include:

* `SingletonPtr` - makes an object be "lazily constructed" on first use,
  and also eliminates its destructor. Lazy construction adds ROM+RAM
  overhead.
* `__eabi_atexit` is stubbed out, preventing RAM usage by run-time
  registration of static destructors.
* GCC has `exit` wrapped to kill shutdown code
* IAR has static destructors disabled in the compiler flags

Killing static destructors in the compiler is the optimum; if we only
stub out `__eabi_atexit`, the compiler is still inserting calls to it,
and referencing the destructors in those call.

Clang 8 added the compiler option `-fno-c++-static-destructors` (and the
object attributes `[[clang::no_destroy]]` and
`[[clang::always_destroy]]` for fine control).

We can hence enable that option in ARMC6 tool profiles, matching IAR.

This option appears to exist in ARM Compiler 6.11, but generates an
apparently spurious linker error about `EthernetInterface`. It works in
ARM Compiler 6.13, so this PR needs to wait until the compiler is
updated.
2020-03-24 15:30:39 +00:00
Evelyne Donnaes 1bbe3a725f Removed minimal-printf profile 2020-03-17 13:57:48 +00:00
Filip Jagodzinski b03f974d03 GCC: Move link-time optimizer flags to extensions dir
Disable the lto for the default develop and release prifiles and move
the flags to tools/profiles/extensions/lto.json profile.

Usage:
mbed compile --profile release --profile tools/profiles/extensions/lto.json
2020-02-13 16:39:20 +01:00
Filip Jagodzinski 3e3bee4a21 GCC: Add the -u flag to keep the main() symbol
This fixes the undefined reference to 'main' that arose after adding
the "-flto" flag to compilation.

This was the case for combined "-Wl,--wrap,main" and "-flto" flags.
2020-02-13 16:39:20 +01:00
Filip Jagodzinski 516153e033 GCC: Enable link-time optimizer for develop profile 2020-02-13 16:39:20 +01:00
Filip Jagodzinski a5240da3b4 GCC: Use 'common' flags at link time
According to GCC man:
To use the link-time optimizer, -flto and optimization options should be
specified at compile time and during the final link. It is recommended
that you compile all the files participating in the same link with the
same options and also specify those options at link time.

Additionally, move the '-g3' flag out of 'common' flags in the debug
profile. Although the '-g' is correctly ignored by the linker, the
'-glevel' is not and causes a build error "ld: unrecognized option
'-g3'".
2020-02-13 16:39:20 +01:00
Filip Jagodzinski f87a8e0f52 GCC: Enable link-time optimizer for release profile 2020-02-13 16:39:19 +01:00
Maciej Bocianski 083e3e569d armc6: make lto an optional profile 2020-02-04 12:38:39 +01:00
Filip Jagodzinski 8fcb00cccd ARMC6: Enable link-time optimizer for develop profile 2020-02-04 12:29:50 +01:00
Filip Jagodzinski 0780f89011 ARMC6: Enable link-time optimizer for release profile 2020-02-04 12:29:50 +01:00
Kevin Bracey 858d02d68c
Merge pull request #12302 from michalpasztamobica/remove_libcpp_extern_template
Remove _LIBCPP_EXTERN_TEMPLATE ARMCC compilation flag
2020-01-30 15:40:40 +02:00
Michal Paszta 2bc3008534 Remove _LIBCPP_EXTERN_TEMPLATE flag 2020-01-22 17:04:19 +02:00
Kevin Bracey ea2ec8d4f6 GCC: remove -fno-delete-null-pointer-checks
For GCC we're being cautious by passing the
`-fno-delete-null-pointer-checks`. This option prevents some
optimisation opportunities, so removing it can reduce code size.

One particular optimisation loss occurs in `Callback` where a test
similar to this occurs:

    extern void myfunc();

    inline void foo(void (*fnptr)())
    {
        if (fnptr) {
            do A;
        } else {
            do B;
        }
    };

    foo(myfunc);

With `-fno-delete-null-pointer-checks`, the compiler does not assume
that `&myfunc` is non-null, and inserts the "null check" - seeing if the
address is 0. But performing that test of the address is incorrect
anyway - if myfunc actually could be at address 0, we'd still want to do
A.

Anyway, we do not have an equivalent option enabled for either Clang or
IAR, and we have performed clean-ups avoiding issues with
apparently-null vector tables in Clang already, for example #10534.

Therefore it should(TM) be safe to remove the option for GCC. We do not
have general data or code at address 0, only vectors are likely to be
there, so it does not make sense to be globally restricting code
generation for that.
2019-12-04 09:57:47 +02:00
Maciej Bocianski 683ba969b5 IAR: Enable inline linker optimizations for develop/release profile
- add --inline option to linker flags
  Some routines are so small that they can fit in the space of the
  instruction that calls the routine. Use this option to make the
  linker replace the call of a routine with the body of the routine,
  where applicable.
2019-11-21 09:05:03 +01:00
Evelyne Donnaes d9f32639eb Changed minimal-printf to call fputc so that it does not bypass the retargetting code
Removed minimal-printf-console-output
2019-08-29 11:30:34 +01:00
Anna Bridge 3ede2a9a60
Merge pull request #11126 from teetak01/optimize-debug-profile
Optimize debug profile flags for size
2019-08-15 12:53:32 +01:00
Evelyne Donnaes 5eaa922ce1 Moved minimal-printf.json to a subdirectory 2019-08-13 12:59:45 +01:00
Martin Kojtal fafd0a5480
Merge pull request #11051 from evedon/minimal-printf
Minimal printf addition
2019-08-09 09:52:36 +01:00
Evelyne Donnaes d6b197a98b Removed no-builtin-printf for uARM 2019-08-05 16:01:34 +01:00
Evelyne Donnaes 050a338771 Addressed review comments, in particular:
* Fixed wrapper functions for IAR
* Fixed and renamed profile to minimal-printf.json
* Moved minimal-printf under platform
* Removed minimal-printf/mbed_lib.json
* Modified exporter template to work with partial profile
* Prevented optimization of printf to avoid compiler function substitution
2019-08-01 12:42:24 +01:00
Evelyne Donnaes 65ab34695e Integrated minimal-printf in mbed-os 2019-08-01 12:41:59 +01:00
Teemu Takaluoma 5b8b2c95b1 Debug-profile: Use -Og level for GCC_ARM optimization
This brings massive ROM savings, and allows to use debug builds
also with larger applications (for. ex. Mesh stack).

Diff. for mbed-cloud-client-example with Wi-Sun stack.

Total Static RAM memory (data + bss): 85120(-216) bytes
Total Flash memory (text + data): 592668(-329296) bytes
2019-07-31 07:51:33 +03:00
Teemu Takaluoma f30703af16 Debug profile: Change IAR profile to use -Ol instead of -On
Total Static RAM memory (data + bss): 71179(+0) bytes
Total Flash memory (text + data): 665394(-44680) bytes
2019-07-30 09:45:07 +03:00
Teemu Takaluoma 985f981b83 Debug profile: Change ARM and uARM profile to size-optimized 2019-07-30 09:44:49 +03:00
Seppo Takalo 25198ba056
Merge pull request #11070 from kjbracey-arm/iar_exception_warning
IAR: Suppress "exceptions are disabled" warning
2019-07-23 11:42:15 +03:00
Kevin Bracey 2078575bae IAR: Suppress "exceptions are disabled" warning
IAR compiler is outputting lots of warnings about exceptions being
disabled whenever it sees a "noexcept" keyword. We know, we know.
2019-07-18 19:59:41 +03:00
Tomasz Moń 4e992cd901 GCC ARM: Increase develop and release debug level
Do not specify the debug level for develop and release profiles. Instead
rely on the compiler to choose sensible default (-g2). Note that -g1 is
minimal debugging information and does not include structure definitions
which quite heavily reduces debugging experience.

For develop and release profiles this results in elf file containing
structure definitions. This does not impact debug profile as it already
did use -g3 which is the highest debug level.

Compatible debuggers (eg. gdb, SEGGER Ozone) can use the extra information
to provide better debugging experience. For example, when compiled .elf is
loaded in gdb, this change makes it trivial to access internal RTX data.

Without this change on develop profile:
  (gdb) print osRtxInfo.thread.run
  'osRtxInfo' has unknown type; cast it to its declared type

With this change on develop profile:
  (gdb) print osRtxInfo.thread.run
  $1 = {curr = 0x20014F04, next = 0x20014F04}
2019-07-18 12:03:13 +02:00
Arto Kinnunen 3d65ace77a
Merge pull request #10950 from artokin/Update_freescale_K6xF_linker_files
Enable split heap in K64F/K66F devices
2019-07-08 11:46:30 +03:00
Kevin Bracey 5ab714e604 ARM linker: add --any_contingency option
When packing data into multiple regions using the `.ANY` directive,
the linker can accidentally overfill an area.

This doesn't normally happen because it defaults to
`--any_placement=worst_fit`, which puts data in the region with
most space.

When we prioritise regions with `.ANY1`/`.ANY2`, it may totally fill
an area, then fail to leave enough space for linker-generated veneers.
We've just seen this error with the new K64F linker map.

Adding `--any-contingency` makes it lower priority when a region is
98% full, avoiding this error.

The option should not have any effect on targets with scatter files
without prioritised `.ANY` directives.
2019-07-03 15:36:49 +03:00
Janne Kiiskila 7bfe0be43f Align also IAR - develop profile to be size optimized
IAR is also performance optimizing instead of size optimizing in
develop profile. Align also that (review feedback).
2019-06-12 13:54:34 +03:00
Janne Kiiskila 261e071013 Make ARMC5 develop profile also size optimized
Due to some historical reasons ARMC 5 compiler behaves very
differently compared to others (GCC, IAR, ARM C 6) as it optimizes
performance rather than size (like the others).

All compilers should behave the same way with the same profile,
thus ARM C 5 should also drive towards size (space).
2019-06-12 12:04:23 +03:00
Kevin Bracey 18ce757c07 ARMC6: Suppress "register deprecated" warning
Lots of target code, STM in particular, uses the `register` keyword, so
it'll take a little while to clean up. In the interim, some builds are
producing a lot of warnings. Suppress the warning for now, as `register`
remains legal C++14 and C11, despite C++14 deprecating it.

C++17 removes `register`, so code will need to be cleaned before any
further C++ version update.
2019-06-03 12:19:58 +03:00
Kevin Bracey b437d700b5 ARMC6: disable "reserved user-defined literal" warning
Clang warns about reserved user-defined literals by default. This
warning is not terribly helpful; compilers aren't normally in the
habit of warning about use of reserved identifiers. It can interfere
with, for example, deliberate emulation of a future standard
language feature.

The warning was promoted to an error in an mbed client build, due to a
non-C++11 "%s"name occurring in a macro. But the macro itself was never
invoked, so the misinterpretation as C++11 caused no problems other than
this warning. Killing the warning will let that code build on ARMC6.
The code already built on GCC and IAR.

If that macro ever was used, then a separate error about operator ""
name not being defined would be generated, on all 3 toolchains.
2019-05-24 16:26:15 +03:00
Kevin Bracey 5b859c47ee Set compilers to C++14 and C11
* ARMC6 and GCC are set to C++14 and C11.
* ARMC5 is set to C++11 and C99, as it's the highest it can offer.
2019-05-24 16:26:15 +03:00
Kevin Bracey 3caa480b04 GCC: remove `-fno-builtin` option
Since the year dot GCC has been passed the `-fno-builtin` option, which
eliminates all compiler knowledge of the C library, even down to basic
stuff like `memcpy` or `memset`, potentially inhibiting quite a lot of
optimisations.

Remove the option to re-enable the optimisations.

There is no record in the source as to why the option is present - maybe
we'll find out by trying to remove it. If necessary, it could be
selectively turned back on for particular functions.
2019-04-05 12:40:58 +03:00
Cruz Monrreal 2910ed54c1
Merge pull request #9277 from deepikabhavnani/flags_fixes
Sleep: error flags fix
2019-02-20 12:07:15 -06:00
deepikabhavnani 7b37b42080 Add NDEBUG flag to release profile of ARMC6 2019-01-22 11:21:33 -06:00
deepikabhavnani 30f18b67e5 Add flag "-DMBED_TRAP_ERRORS_ENABLED=1" to develop profile as well
printf was called from ISR when sleep tracing was enabled. Issue was
captured only in debug profile.
Printf is not allowed from ISR context and issues like this should be
trapped in case of debug profiles as well.
2019-01-22 10:23:18 -06:00
deepikabhavnani 8547f26872 Add missing ARMC6 flags - MBED_DEBUG and MBED_TRAP_ERRORS_ENABLED 2019-01-15 13:39:06 -06:00
Deepika 255661e55b Adding debugger awarness with Keil MDK
Main thread in Mbed OS is statically allocated and was not available in call
stack of Keil MDK. The RTX5 kernel requires statically allocated thread
information objects that are placed into a specific section to enable RTOS
thread awareness in Keil MDK. This fix is to keep main thread in specific
section of memory.
2019-01-15 12:04:39 -06:00
Jimmy Brisson b1b69d2d60 Compatibilize ArmC6 with ArmC5-built archives
### Description

Arm compiler 5 builds with "short" enums and "short" wchars. This means
that C/C++ enums will be packed into the smallest power of 2 number of
bytes by the compiler and the `wchar_t` is 2 bytes. Arm compiler 6
defaults to packing enums into 4 bytes and `wchar_t` is 4 bytes.

Further, Arm Compiler 5's `-O0` (no optimizations) bulids will actually
do some amount of optimizing, similar to Arm Compiler 6's `-O1`. I have
switched the debug profile to `-O1` for maximum compatibility with our
prior behavior.

NOTE: "Compatibilize" is a word

### Pull request type

    [x] Fix
    [ ] Refactor
    [ ] Target update
    [ ] Functionality change
    [ ] Docs update
    [ ] Test update
    [ ] Breaking change
2018-11-19 11:43:05 -06:00
Janne Kiiskila f1795e3418 IOTCORE-389 - bring back legacy alignment for Arm C6
Quite a few of the scatter files are not (yet) aligned to 8-byte
boundaries and therefore the removal of legacy alignment feature
(which is under deprecation warning, but it actually not YET
deprecated) broke quite a few builds to this error:

Error: L6244E: Exec region RW_IRAM1 address (0x200001ac) not aligned on a 8 byte boundary.

We must bring this option now back to fix the builds.

This option to ld (--legacyalign) can only be removed once all of
the scatter files have been fixed.
2018-09-06 01:04:38 +03:00
deepikabhavnani 37a5646372 Remove deprecated linker options
Resolved below warnings
Warning: L3912W: Option 'legacyalign' is deprecated.
Warning: L3912W: Option 'no_strict_wchar_size' is deprecated.
Warning: L3912W: Option 'no_strict_enum_size' is deprecated.
2018-08-16 18:14:14 -05:00
Jimmy Brisson 5f8aa893ca Partial revert of "CMSIS/RTX: Adapt Mbed OS to CMSIS/RTX device support scheme" 2018-07-11 13:49:57 +01:00
Cruz Monrreal f11d0f3be7
Merge pull request #7261 from kjbracey-arm/iar-jump-warning
IAR: Suppress C "bypasses initialization" warning
2018-06-19 21:46:14 -05:00
Kevin Bracey 81ed8014cd IAR: Suppress C "bypasses initialization" warning
By default IAR generates "transfer of control bypasses initialization"
warnings for C code - it's a legal construct that frequently occurs when
doing Linux-style "goto error". Many occurrences in Nanostack.

Suppress the warning for C only, to align with GCC and ARMCC. Have to
take care not to put it in the "common" section, as this would suppress
it for C++, where it actually is illegal.
2018-06-19 15:54:28 +03:00
Jimmy Brisson 7f0e7ce722 Add show full path option to armc6 linker
### Description
Full paths in the map file are required to have correct memap parsing.
This PR adds the option `--show_full_path` to ARMC6 in every profile.
This option only affects the map file output, so it's safe to add.
2018-06-07 11:44:03 -05:00