Skip to content

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

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

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

Conversation

@Ulrond

@Ulrond Ulrond commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #256

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 branch of the Makefile used it in two places; both are now -O0.

COMPILER := $(if $(filter CPP,$(VARIANT)),g++ -ggdb -O0 -Wall, gcc -ggdb -O0 -Wall)
UT_CONTROL_COMPILER := gcc -ggdb -O0 -Wall

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

Note for reviewers: where the stray 0 file actually comes from

Every compile/link rule in ut-core appends its own -o $@ after $(COMPILER) (Makefile lines 152, 167, 172, 191, 198), and GCC lets the last -o win — gcc -ggdb -o0 -Wall -c t.c -o t.o exits 0 and produces t.o, no file named 0. So ut-core's own objects were named correctly; what was silently lost is the intended -O0 (benign in practice, as -O0 is gcc's default).

The object-naming symptom in the issue shows up downstream: UT_CONTROL_COMPILER is handed to the ut-control sub-make as CC="gcc -ggdb -o0 -Wall", and any command there that supplies no -o of its own writes a file called 0. The sibling typo in ut-control itself is rdkcentral/ut-control#130.

Verification

  • make printenv TARGET=linux now reports COMPILER [ gcc -ggdb -O0 -Wall].
  • grep -rn '\-o0' --include=Makefile --include=*.mk --include=*.sh . returns no hits.
  • Clean make TARGET=linux VARIANT=CPP under tests/: full success, ut-test links.
  • Clean make TARGET=linux under tests/: all objects compile and ut-test links. The run then stops on the pre-existing check_macros gate (30/33 macros documented in ut_cunit.h), which is source-content based and unaffected by compiler flags.
  • No file named 0 anywhere in the tree after either clean build.

Second commit: a regression guard in the tests suite

The typo itself is two characters, but it survived because no functional test could ever have caught it — gcc accepted -o0, the later -o $@ won, and -O0 is gcc's default, so every build stayed green and every binary stayed correct. 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, alongside the existing check_macros gate, and runs before the framework build so a flag typo costs seconds rather than a full compile.

Two checks:

Check What it does
scan Walks every Makefile/*.mk/*.sh for a lowercase -o glued to an optimisation level — -o0, -os, -og, -ofast. Comments are stripped before matching, so prose describing the typo does not trip it. Third-party trees (framework/, build/, cpp_libs/) are skipped.
expect Asks make printenv what COMPILER and UT_CONTROL_COMPILER actually expand to and asserts -ggdb -O0 -Wall are present. This catches the flags being dropped or overridden, not just mistyped.

Expectations apply to TARGET=linux only — arm takes its compiler from the SDK.

Verified by reintroducing -o0 on top of the fix:

Mistyped optimisation flags:
Makefile:99: COMPILER := $(if $(filter CPP,$(VARIANT)),g++ -ggdb -o0 -Wall, gcc -ggdb -o0 -Wall) ❌
Makefile:100: UT_CONTROL_COMPILER := gcc -ggdb -o0 -Wall ❌
Lowercase -o names an output file. Optimisation is -O.

Expected flags missing:
COMPILER: missing -O0 ❌ - is [gcc -ggdb -o0 -Wall]
UT_CONTROL_COMPILER: missing -O0 ❌ - is [gcc -ggdb -o0 -Wall]

Mistyped optimisation flags :: 2
Expected flag sets met :: 0 / 2

Both checks fire, make exits 1. On the fixed tree: 25 build files scanned, 0 findings, 2/2 expectations met — confirmed for TARGET=linux, VARIANT=CPP, and TARGET=arm (scan only).

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

Fixes #256
Copilot AI review requested due to automatic review settings July 27, 2026 16:33
@Ulrond
Ulrond requested a review from a team as a code owner July 27, 2026 16:33
@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.

@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:34

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

Fixes a build-flag typo in the TARGET=linux Makefile branch where -o0 (output file) was incorrectly used instead of -O0 (optimization level 0), which could cause downstream builds (notably the ut-control sub-make invocation) to emit an unintended output file named 0.

Changes:

  • Replace -o0 with -O0 in the Linux COMPILER definition.
  • Replace -o0 with -O0 in the Linux UT_CONTROL_COMPILER definition (used when invoking the ut-control sub-make).

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

Adds check_makefile_flags to the tests suite, alongside the existing
check_macros static gate.

Two checks:
  scan    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 #256 went unnoticed.
  expect  asks make printenv what COMPILER and UT_CONTROL_COMPILER
          actually expand to and asserts -ggdb -O0 -Wall are present,
          catching the flags being dropped as well as mistyped.

Runs before the framework build so a flag typo is reported in
seconds rather than after a full compile. Expectations apply to
TARGET=linux only; arm takes its compiler from the SDK.

Verified by reintroducing -o0: both checks fail, exit 1.

Refs #256
@Ulrond
Ulrond force-pushed the feature/gh256-fix-lowercase-o-optimisation-flag branch from 23e5268 to 8646879 Compare 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 1 comment.

Comment thread tests/Makefile
NC='\033[0m'

.PHONY: clean list build all
.PHONY: clean list build all check_macros check_makefile_flags
Copilot AI review requested due to automatic review settings July 27, 2026 20:56

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 1 comment.

Comment thread tests/Makefile
NC='\033[0m'

.PHONY: clean list build all
.PHONY: clean list build all check_macros check_makefile_flags
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

Status: Todo

Development

Successfully merging this pull request may close these issues.

Make file wrongly attempts to set optimisation using lowercase o

3 participants