This is an archive of the discontinued LLVM Phabricator instance.

[lvm-windres] Try to match GNU windres regarding handling of unescaped quotes
ClosedPublic

Authored by mstorsjo on Mar 24 2023, 2:37 PM.

Details

Summary

Some background context: GNU windres invokes the preprocessor in
a subprocess. Some windres options are passed through to the
preproocessor, e.g. -D options for predefining defines.
When GNU windres passes these options onwards, it takes the options
in exact the form they are received (in argv or similar) and
assembles them into a single preprocessor command string which gets
interpreted by a shell (IIRC via the popen() function, or similar).

When LLVM invokes subprocesses, it does so via APIs that take
properly split argument vectors, to avoid needing to worry about
shell quoting/escaping/unescaping. But in the case of LLVM windres,
we have to emulate the effect of the shell parsing done by popen().

Most of the relevant cases are already taken care of here, but this
patch fixes an uncommon case encountered in
https://github.com/llvm/llvm-project/issues/57334.
(This case is uncommon since it doesn't do what one would want to;
the quotes need to be escaped more to work as intended through
the popen() shell).

Diff Detail

Event Timeline

mstorsjo created this revision.Mar 24 2023, 2:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 2:37 PM
mstorsjo requested review of this revision.Mar 24 2023, 2:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 2:37 PM

Oh, that's unfortunate.
Maybe llvm-windres should generate a warning in such case?

mati865 accepted this revision.Mar 25 2023, 1:54 AM
This revision is now accepted and ready to land.Mar 25 2023, 1:54 AM

Oh, that's unfortunate.
Maybe llvm-windres should generate a warning in such case?

Hmm, maybe... (I'd need to think about it again to sort my thoughts out about it; I had written this patch 6 months ago but never took the time to finish it to have it reviewed.)

Oh, that's unfortunate.
Maybe llvm-windres should generate a warning in such case?

Hmm, maybe... (I'd need to think about it again to sort my thoughts out about it; I had written this patch 6 months ago but never took the time to finish it to have it reviewed.)

I think I'll skip adding a warning in this case, as I think it feels somewhat out of place. Whenever debugging such uses, we should have mostly consistent behaviour between GNU windres and LLVM windres anyway. The user can see the actual preprocessing command that gets run by running windres with -v/--verbose too, which is helpful for figuring out the right amount of quoting/escaping.

This revision was landed with ongoing or failed builds.Mar 28 2023, 1:04 AM
This revision was automatically updated to reflect the committed changes.