Skip to content

[llvm-config] Quote and escape paths #97305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2024
Merged

Conversation

aganea
Copy link
Member

@aganea aganea commented Jul 1, 2024

If any of the printed paths by llvm-config contains quotes, spaces, backslashes or dollar sign characters, these paths will be quoted and the corresponding characters will be escaped.

Following discussion in #76304

Fixes #28117

@aganea aganea merged commit e8c9414 into llvm:main Jul 3, 2024
6 of 8 checks passed
@aganea aganea deleted the llvm_config_escape_paths branch July 3, 2024 12:26
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
If any of the printed paths by `llvm-config` contains quotes, spaces,
backslashes or dollar sign characters, these paths will be quoted and
the corresponding characters will be escaped.

Following discussion in llvm#76304

Fixes llvm#28117
@glandium
Copy link
Contributor

glandium commented Jul 3, 2024

It seems the "if necessary" part was not implemented, because it now quotes even when quotes are not necessary, which is likely to break a ton of things.

Edit: examples:

$ /builds/worker/fetches/clang/bin/llvm-config --libs
-l"LLVM-19git"
$ /builds/worker/fetches/clang/bin/llvm-config --cflags
-I"/builds/worker/fetches/clang/include"  -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

@glandium
Copy link
Contributor

glandium commented Jul 4, 2024

Example of subtle breakage: cctools-port ld64's support for LTO breaks for some reason because of this change.

@aganea
Copy link
Member Author

aganea commented Jul 4, 2024

Example of subtle breakage: cctools-port ld64's support for LTO breaks for some reason because of this change.

Are you able to debug what is wrong there? Maybe because they are collating path components to an already quoted path, and the bintools don't like that? (this works on Windows with cl.exe and clang-cl.exe at least).

I think that if we don't introduce a breaking change with LLVM 19 in this regards (quoted strings emitted by llvm-config), this patch will be worthless. If we add quotes only when required, it won't work (as you're pointing out) in the downstream usages. Evidently some of the paths emitted by llvm-config might not require escaping, since they are alone on a single line, and could be quoted later by consuming scripts (like --libdir or --includedir).

Any other suggestions?

+@MaskRay

@aganea aganea changed the title [llvm-config] Quote and escape paths if necessary [llvm-config] Quote and escape paths Jul 4, 2024
@glandium
Copy link
Contributor

glandium commented Jul 4, 2024

I gave one subtle example, but here's another one less subtle: https://github.com/AFLplusplus/AFLplusplus/blob/stable/GNUmakefile.llvm#L420 this simple straightforward use breaks completely (can't find includes when compiling).

@kongy
Copy link
Collaborator

kongy commented Jul 4, 2024

Can you please revert the change while investigating a fix? Our downstream ToT builder is broken because of this change.

aganea added a commit that referenced this pull request Jul 5, 2024
@aganea
Copy link
Member Author

aganea commented Jul 5, 2024

Reverted. @kongy do you have a reproducer that I could test locally by chance?

@kongy
Copy link
Collaborator

kongy commented Jul 5, 2024

Our build script invokes llvm-config and feeds the target list to ninja. With the extra unnecessary quotes, ninja does not find the correct target.

DEBUG:utils:subprocess.run:02:40:16 /tmpfs/src/git/out/stage2-install/bin/llvm-config --libs object --libnames --link-static
DEBUG:utils:subprocess.run:02:40:16 /tmpfs/src/git/prebuilts/build-tools/linux_musl-x86/bin/ninja '"libLLVMObject.a"' '"libLLVMTextAPI.a"' '"libLLVMMCParser.a"' '"libLLVMIRReader.a"' '"libLLVMAsmParser.a"' '"libLLVMMC.a"' '"libLLVMDebugInfoCodeView.a"' '"libLLVMBitReader.a"' '"libLLVMCore.a"' '"libLLVMRemarks.a"' '"libLLVMBinaryFormat.a"' '"libLLVMTargetParser.a"' '"libLLVMBitstreamReader.a"' '"libLLVMSupport.a"' '"libLLVMDemangle.a"'
ninja: error: unknown target '"libLLVMObject.a"', did you mean 'libLLVMObject.a'?

kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
If any of the printed paths by `llvm-config` contains quotes, spaces,
backslashes or dollar sign characters, these paths will be quoted and
the corresponding characters will be escaped.

Following discussion in llvm#76304

Fixes llvm#28117
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
@aganea
Copy link
Member Author

aganea commented Jul 31, 2024

While we could avoid unnecessary escaping for the libraries above, escaping paths in general (like this patch does) would need some modifications (I think) in scripts using llvm-config.

What do you all think about adding a new flag such as --escaped that allows potentially quoting and escaping paths, while keeping the old behavior when the flag is not provided?

@tothambrus11
Copy link

Another approach would have been to only add quotes when there is a space in the path. If old tooling relied on such things, it was broken anyways (there is no way of correctly splitting unless we add some hard assumptions). But --escaped is good for backwards compatibility in all cases.

@aganea
Copy link
Member Author

aganea commented Aug 13, 2024

Please see #103397

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.

Spaces in paths from llvm-config should be quoted
5 participants