Skip to content

Fix : gh #130 : Use -O0 not -o0 to set optimisation level for TARGET=linux - #131

Open
Ulrond wants to merge 2 commits into
developfrom
feature/gh130-fix-lowercase-o-optimisation-flag
Open

Fix : gh #130 : Use -O0 not -o0 to set optimisation level for TARGET=linux#131
Ulrond wants to merge 2 commits into
developfrom
feature/gh130-fix-lowercase-o-optimisation-flag

Conversation

@Ulrond

@Ulrond Ulrond commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #130

Applies the patch supplied by @looopTools in the issue, with authorship preserved via git am.

-o0 is not an optimisation flag — lowercase -o is "write output to this file", so -o0 asks for a file named 0. The TARGET=linux default is now -O0.

CC ?= gcc -ggdb -O0 -Wall

TARGET=arm is untouched — it takes $(CC) from the SDK and never carried the flag.

Note for reviewers: this line is currently a no-op

Worth flagging while the line is under the microscope — Makefile:117 uses ?=, which GNU make defines as ifeq ($(origin CC),undefined). Make's built-in CC = cc has origin default, never undefined, so the assignment never fires:

$ cat probe.mk
CC ?= gcc -ggdb -O0 -Wall
show:
	@echo "CC=[$(CC)] origin=$(origin CC)"
$ make -f probe.mk show
CC=[cc] origin=default

So a standalone make TARGET=linux in ut-control compiles with bare cc — no -ggdb, no -Wall, no -O0 — and when driven from ut-core, CC arrives on the command line and overrides the line regardless. This PR is therefore a correctness fix with no behavioural change on its own.

The real -o0 damage came from ut-core passing CC="gcc -ggdb -o0 -Wall" down to this sub-make; that side is fixed in rdkcentral/ut-core#258.

If maintainers want the intended defaults to actually apply, the idiom that works while still honouring environment and command-line overrides is:

ifeq ($(origin CC),default)
CC := gcc -ggdb -O0 -Wall
endif

Deliberately left out of this PR — happy to raise it separately if wanted.

Verification

  • grep -rn '\-o0' --include=Makefile --include=*.mk --include=*.sh . returns no hits.
  • Standalone make TARGET=linux on this branch builds clean, and no file named 0 appears in the tree afterwards.

Second commit: a regression guard in the tests suite

The typo is two characters, but it survived because no functional test could ever have caught it — gcc accepted -o0, a later -o $@ on the same command line won, and -O0 is gcc's default. Every build stayed green. Only a static check on the build files can see it.

tests/check_makefile_flags.py is wired into the suite as check_makefile_flags and runs before build.sh, so a flag typo costs seconds rather than a full build. It walks every Makefile/*.mk/*.sh for a lowercase -o glued to an optimisation level (-o0, -os, -og, -ofast), skipping third-party trees. Comments are stripped before matching, so prose describing the typo does not trip the check.

Verified by reintroducing -o0 on top of the fix:

Mistyped optimisation flags:
Makefile:117: CC ?= gcc -ggdb -o0 -Wall ❌
Lowercase -o names an output file. Optimisation is -O.

Build files scanned under .. :: 9
Mistyped optimisation flags :: 1
make: *** [Makefile:90: check_makefile_flags] Error 1

On the fixed tree: 9 build files scanned, 0 findings.

The value assertion is deliberately left off

The script also supports asserting what a variable actually expands to via make printenv--expect CC=-ggdb,-O0,-Wall — which is the stronger check, since it catches flags being dropped as well as mistyped. It is not wired up here, because it would fail immediately: CC ?= never fires (see above), so CC expands to bare cc. Turning it on therefore means deciding the ?= question first. The reason is recorded in a comment in tests/Makefile next to the target so the next person does not have to rediscover it.

The same script is added to ut-core in rdkcentral/ut-core#258, where the value assertion is enabled (COMPILER and UT_CONTROL_COMPILER must contain -ggdb -O0 -Wall).

-o0 was replaced with -O0 to correctly set optimisation level.
This issue only happens with build target LINUX

Fixes #130
Copilot AI review requested due to automatic review settings July 27, 2026 16:35
@Ulrond
Ulrond requested a review from a team as a code owner July 27, 2026 16:35
@Ulrond Ulrond added bug Something isn't working community-contribution Contribution from community labels Jul 27, 2026
@Ulrond Ulrond self-assigned this Jul 27, 2026
@Ulrond
Ulrond requested review from bhanucbp and kanjoe24 July 27, 2026 16:35
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
Ulrond
looopTools
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the linux-target build defaults in ut-control’s Makefile to use the correct GCC optimization flag (-O0 instead of -o0) when setting the default CC command.

Changes:

  • Fixes the linux default compiler flags to use -O0 (optimization level 0) rather than -o0 (output file option).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile
Comment on lines 116 to 118
ifeq ($(TARGET),linux)
CC ?= gcc -ggdb -o0 -Wall
CC ?= gcc -ggdb -O0 -Wall
endif
Adds check_makefile_flags to the tests suite, run before build.sh so a
flag typo is reported in seconds rather than after a full build.

It walks the build files for a lowercase -o glued to an optimisation
level (-o0, -os, -og). gcc accepts these silently and a later -o $@ on
the same command line wins, so nothing ever fails - which is why #130
went unnoticed. Comments are stripped before matching, so prose
describing the typo does not trip the check.

The script also supports asserting what a variable expands to
(--expect CC=-ggdb,-O0,-Wall) via make printenv. That is deliberately
not wired up yet: 'CC ?=' in the top level Makefile never fires, since
GNU make treats ?= as ifeq (origin CC,undefined) and the built-in CC
has origin default. The Makefile records this so the expectation can
be turned on once that is resolved.

Verified by reintroducing -o0: the check fails, exit 1.

Refs #130
Copilot AI review requested due to automatic review settings July 27, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread tests/Makefile
Comment on lines +88 to +90
check_makefile_flags:
@$(ECHOE) UT [$@]
@$(FLAGS_SCRIPT) $(ROOT_DIR)/..
Comment on lines +74 to +79
try:
with open(path, "r", encoding="utf-8", errors="replace") as handle:
lines = handle.readlines()
except OSError as error:
print(f"{RED}Error: cannot read '{path}': {error}{RESET}")
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working community-contribution Contribution from community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make file wrongly attempts to set optimisation using lowercase o

3 participants