Skip to content
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

Fix compile issues / code smell related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE #8663

Merged
merged 3 commits into from
Apr 8, 2020

Conversation

vomindoraan
Copy link
Contributor

@vomindoraan vomindoraan commented Apr 3, 2020

Description

As discussed in #8604, there is currently an issue with how NO_ACTION_MACRO and NO_ACTION_FUNCTION are defined when LTO is enabled using LINK_TIME_OPTIMIZATION_ENABLE/LTO_ENABLE. Namely, common.mk adds these definitions outright and has no way of checking if they already exist somewhere down the pipeline, since the makefile is processed before any headers.

ifeq ($(strip $(LINK_TIME_OPTIMIZATION_ENABLE)), yes)
ifeq ($(PLATFORM),CHIBIOS)
$(info Enabling LTO on ChibiOS-targeting boards is known to have a high likelihood of failure.)
$(info If unsure, set LINK_TIME_OPTIMIZATION_ENABLE = no.)
endif
EXTRAFLAGS += -flto
TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATION_ENABLE
TMK_COMMON_DEFS += -DNO_ACTION_MACRO
TMK_COMMON_DEFS += -DNO_ACTION_FUNCTION
endif

This forces users to check for LTO before defining the macros, which:

  1. creates an asymmetry between how NO_ACTION_MACRO/FUNCTION and other NO_ACTION_* flags are used;
  2. requires users to know about what is essentially an implementation detail;
  3. is a code smell.

At the moment, any keyboard, keymap or userspace that unconditionally defines the above flags will fail to compile with LTO_ENABLE = yes due to the flags already being defined in the makefile.

Background: The defines were originally added to common.mk in #5674, and the LTO check was added to config.h templates in #7211.

Solution

This PR solves the above issues by moving the “if LTO is enabled, legacy macro and function features should be disabled” logic from tmk_core/common.mk into tmk_core/action.h. This keeps the macros available to existing source files that check for NO_ACTION_MACRO/FUNCTION, but it removes the need to check for LTO before defining these macros in keyboard/userspace/keymap files.

Testing The following keyboards can be used for testing:
claw44
amj96
georgi
scarletbandana
tetris
pearl
uzu42
clueboard/66_hotswap
jc65/v32a
kbdfans/kbd6x
converter/usb_usb/ble
handwired/xealous/rev1
sentraq/s60_x/default

On master, they don't compile if you set LTO_ENABLE = yes. With these changes, they compile correctly.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

…O is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).
Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.
@vomindoraan vomindoraan changed the title No action macro function Disable legacy macro and function features in header instead of makefile (LTO) Apr 3, 2020
@vomindoraan vomindoraan changed the title Disable legacy macro and function features in header instead of makefile (LTO) Disable legacy macro and function features in header instead of makefile (LTO_ENABLE) Apr 3, 2020
@vomindoraan vomindoraan changed the title Disable legacy macro and function features in header instead of makefile (LTO_ENABLE) Fix compile issues / code smell related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE Apr 3, 2020
@mtei mtei mentioned this pull request Apr 5, 2020
13 tasks
@zvecr zvecr merged commit be2f581 into qmk:master Apr 8, 2020
@zvecr
Copy link
Member

zvecr commented Apr 8, 2020

Thanks!

Shinichi-Ohki added a commit to Shinichi-Ohki/qmk_firmware that referenced this pull request Apr 9, 2020
* 'master' of https://github.com/qmk/qmk_firmware: (53 commits)
  Set the correct RGB LED count on YD60MQ (qmk#8629)
  [Keymap] Updates to personal keymaps (qmk#8665)
  Fix compile issues related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE (qmk#8663)
  [Keymap] Userspace update Rgb layers code (qmk#8659)
  Add Choconum (qmk#8709)
  Add Via keymap for BM16-A (qmk#8681)
  Fix edge-case with config
  Don't hide for devs...
  Apply @skullydazed's suggestions, move 'import milc'
  Make dedicated sections for user/dev commands in docs
  Rebase on master, hide some other subcommands
  Use milc for config check, requirements fixes
  CLI: Add development mode support
  Update info.json (qmk#8723)
  format code according to conventions [skip ci]
  spi_master for AVR (qmk#8299)
  DennyTom's buttery_engine (qmk#8138)
  add via support for kira80 (qmk#8677)
  [Keyboard] Wheatfield Split75 (qmk#8511)
  Correctly handle json keymaps with ANY()
  ...
loadedsith added a commit to loadedsith/qmk_firmware that referenced this pull request Apr 9, 2020
* master: (3035 commits)
  [Keymap] Update personal userspace and keymaps (qmk#8747)
  Add PS2_MOUSE_ROTATE to compensate for device orientation (qmk#8650)
  Add RGB support in via to launchpad (qmk#8621)
  VIA support for the KBDFans KBD6x (qmk#8680)
  Set the correct RGB LED count on YD60MQ (qmk#8629)
  [Keymap] Updates to personal keymaps (qmk#8665)
  Fix compile issues related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE (qmk#8663)
  [Keymap] Userspace update Rgb layers code (qmk#8659)
  Add Choconum (qmk#8709)
  Add Via keymap for BM16-A (qmk#8681)
  Fix edge-case with config
  Don't hide for devs...
  Apply @skullydazed's suggestions, move 'import milc'
  Make dedicated sections for user/dev commands in docs
  Rebase on master, hide some other subcommands
  Use milc for config check, requirements fixes
  CLI: Add development mode support
  Update info.json (qmk#8723)
  format code according to conventions [skip ci]
  spi_master for AVR (qmk#8299)
  ...

# Conflicts:
#	layouts/community/ortho_4x12/grahampheath/keymap.c
#	lib/lufa
loadedsith added a commit to loadedsith/qmk_firmware that referenced this pull request Apr 9, 2020
* master: (208 commits)
  [Keymap] Update personal userspace and keymaps (qmk#8747)
  Add PS2_MOUSE_ROTATE to compensate for device orientation (qmk#8650)
  Add RGB support in via to launchpad (qmk#8621)
  VIA support for the KBDFans KBD6x (qmk#8680)
  Set the correct RGB LED count on YD60MQ (qmk#8629)
  [Keymap] Updates to personal keymaps (qmk#8665)
  Fix compile issues related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE (qmk#8663)
  [Keymap] Userspace update Rgb layers code (qmk#8659)
  Add Choconum (qmk#8709)
  Add Via keymap for BM16-A (qmk#8681)
  Fix edge-case with config
  Don't hide for devs...
  Apply @skullydazed's suggestions, move 'import milc'
  Make dedicated sections for user/dev commands in docs
  Rebase on master, hide some other subcommands
  Use milc for config check, requirements fixes
  CLI: Add development mode support
  Update info.json (qmk#8723)
  format code according to conventions [skip ci]
  spi_master for AVR (qmk#8299)
  ...
loadedsith added a commit to loadedsith/qmk_firmware that referenced this pull request Apr 9, 2020
* master: (208 commits)
  [Keymap] Update personal userspace and keymaps (qmk#8747)
  Add PS2_MOUSE_ROTATE to compensate for device orientation (qmk#8650)
  Add RGB support in via to launchpad (qmk#8621)
  VIA support for the KBDFans KBD6x (qmk#8680)
  Set the correct RGB LED count on YD60MQ (qmk#8629)
  [Keymap] Updates to personal keymaps (qmk#8665)
  Fix compile issues related to NO_ACTION_MACRO/FUNCTION and LTO_ENABLE (qmk#8663)
  [Keymap] Userspace update Rgb layers code (qmk#8659)
  Add Choconum (qmk#8709)
  Add Via keymap for BM16-A (qmk#8681)
  Fix edge-case with config
  Don't hide for devs...
  Apply @skullydazed's suggestions, move 'import milc'
  Make dedicated sections for user/dev commands in docs
  Rebase on master, hide some other subcommands
  Use milc for config check, requirements fixes
  CLI: Add development mode support
  Update info.json (qmk#8723)
  format code according to conventions [skip ci]
  spi_master for AVR (qmk#8299)
  ...
HokieGeek pushed a commit to HokieGeek/qmk_firmware that referenced this pull request Apr 10, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
mrlinuxfish pushed a commit to mrlinuxfish/qmk_firmware that referenced this pull request Apr 12, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
Quarren42 pushed a commit to Quarren42/qmk_firmware that referenced this pull request Apr 15, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
kylekuj pushed a commit to kylekuj/qmk_firmware that referenced this pull request Apr 21, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
@vomindoraan vomindoraan deleted the no_action_macro_function branch May 7, 2020 14:19
bitherder pushed a commit to bitherder/qmk_firmware that referenced this pull request May 15, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
drashna pushed a commit to zsa/qmk_firmware that referenced this pull request May 24, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
sowbug pushed a commit to sowbug/qmk_firmware that referenced this pull request May 24, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
fdidron pushed a commit to zsa/qmk_firmware that referenced this pull request Jun 12, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
turky pushed a commit to turky/qmk_firmware that referenced this pull request Jun 13, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
jakobaa pushed a commit to jakobaa/qmk_firmware that referenced this pull request Jul 7, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
thorstenweber83 pushed a commit to thorstenweber83/qmk_firmware that referenced this pull request Sep 2, 2020
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
…qmk#8663)

* Define NO_ACTION_MACRO/FUNCTION in header instead of makefile when LTO is enabled

Currently, boards and keymaps that define NO_ACTION_MACRO/FUNCTION unconditionally
will not compile with LTO_ENABLE (qmk#8604). This fixes the issue by moving the
definitions from common.mk to action.h, which enables us to check for previous
definitions of those macros (this cannot be done in a makefile).

* Remove LTO checks in templates

Since now NO_ACTION_MACRO/FUNCTION are defined as needed in action.h (which is
included by quantum.h), checking for LTO in keyboard and user code is no
longer required.

* Update LTO_ENABLE docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NO_ACTION_MACRO and NO_ACTION_FUNCTION when LINK_TIME_OPTIMIZATION_ENABLE is defined.
4 participants