Skip to content

Expand response file arguments in a single pass - #43546

Open
arpitjain099 wants to merge 1 commit into
trailofbits:masterfrom
arpitjain099:fix/response-file-expansion
Open

arpitjain099 wants to merge 1 commit into
trailofbits:masterfrom
arpitjain099:fix/response-file-expansion

Conversation

@arpitjain099

Copy link
Copy Markdown

ResponseFileMixin collects the (index, arg) pairs of every @file argument up front, then calls insert_items_at_idx once per pair. That helper replaces one element with a list of a different length, so after the first expansion every remaining index is stale. With two response files where the first expands to anything other than exactly one argument, the second replacement overwrites an unrelated argument and leaves the real @file token unexpanded.

Concretely, cc -a @args1 -b @args2 -c with args1 holding -one -uno and args2 holding -two canonicalizes to -a -one -uno -two @args2 -c: -b is gone and @args2 was never expanded. The same thing happens for two nested refs inside one response file. The existing tests only ever use a single ref, so nothing caught it.

Both loops now build the expanded list in one pass, which drops the last user of insert_items_at_idx, so I removed the helper. That also takes out the stray print(item) sitting in its inner generator, which was writing the wrapped compiler's arguments to its own stdout whenever an action was enabled (blight-cc -E @rsp src.c with BLIGHT_ACTIONS=Record emitted -E and src.c into the preprocessed output). Happy to keep insert_items_at_idx around instead if you would rather not drop it.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant