Skip to content

c_build_helper: Split cc command line#301

Open
OldManYellsAtCloud wants to merge 1 commit into
Mbed-TLS:mainfrom
OldManYellsAtCloud:main
Open

c_build_helper: Split cc command line#301
OldManYellsAtCloud wants to merge 1 commit into
Mbed-TLS:mainfrom
OldManYellsAtCloud:main

Conversation

@OldManYellsAtCloud
Copy link
Copy Markdown

Optionally the CC/HOSTCC environment variable can hold the command to invoke the C compiler, however this command can also contain extra arguments, not only the binary name. In this particular case Python was treating the whole value as a single binary name, and was trying to execute as such (e.g. "cc -arg1 -arg2" instead of "cc" and the arguments separately), which results in failure.

Split the compiler command into its components to invoke it correctly.

Description

In case the CC or HOSTCC environment variable contains compiler flags also (not only the compiler binary), then compilation fails, because Python treats the whole value as a single executable instead of treating it as binary + arguments. This change splits the compiler command to execute it correctly.

(This issue came up in the Yocto project, that sets compiler flags extensively - compiling mbedtls 4 due to this failed)

PR checklist

Please add the numbers (or links) of the associated pull requests for consuming branches. You can omit branches where this pull request is not needed.

  • TF-PSA-Crypto development PR provided # | not required because:
  • TF-PSA-Crypto 1.1 PR provided # | not required because:
  • mbedtls development PR provided # | not required because:
  • mbedtls 4.1 PR provided # | not required because:
  • mbedtls 3.6 PR provided # | not required because:

As far as I understand this issue needs to be fixed only in the main branch, and this repo is used as a submodule, and as such, its revision is fixed. The issue being fixed wasn't observed with previous version of mbedtls. But if I'm wrong, and there are other branches to be fixed, just LMK

Optionally the CC/HOSTCC environment variable can hold the command to
invoke the C compiler, however this command can also contain extra
arguments, not only the binary name. In this particular case Python
was treating the whole value as a single binary name, and was trying
to execute as such (e.g. "cc -arg1 -arg2" instead of "cc" and the arguments
separately), which results in failure.

Split the compiler command into its components to invoke it correctly.

Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Copy link
Copy Markdown
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM

Arguably we should go further and treat CC as shell code, but I'm happy to just resolve the basic case where CC just contains an executable name (without spaces or other special characters) and some options.

if cc is None:
cc = os.getenv('CC', 'cc')
cmd = [cc]
cmd = cc.split()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CC is commonly interpolated in a shell command line, so maybe we should go further and construct a shell command? If we do so then we should quote the file names and include directories for shell expansion in case they contain full paths that contain spaces or other special characters.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Unfortunately I'm not really sure what you are asking, what should I change - I was only trying to package the latest version only for Yocto. But if you could point me to an example where such a shell command is done already, I could definitely try doing something similar.

@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members. needs-reviewer This PR needs someone to pick it up for review priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most) labels Apr 29, 2026
@gilles-peskine-arm gilles-peskine-arm moved this to Scoped in Community Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Every commit must be reviewed by at least two team members. needs-reviewer This PR needs someone to pick it up for review priority-medium Medium priority - this can be reviewed as time permits size-xs Estimated task size: extra small (a few hours at most)

Projects

Status: Scoped
Status: In Development

Development

Successfully merging this pull request may close these issues.

2 participants