Skip to content
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

LinkFileList generation needs to use quoting #13

Open
jakepetroules opened this issue Jan 30, 2025 · 2 comments
Open

LinkFileList generation needs to use quoting #13

jakepetroules opened this issue Jan 30, 2025 · 2 comments
Labels
good first issue Good for newcomers

Comments

@jakepetroules
Copy link
Collaborator

jakepetroules commented Jan 30, 2025

Non-Apple linkers require quoting in order to handle projects with spaces in their path.

This is handled in LdLinkerSpec when evaluating __INPUT_FILE_LIST_PATH__.

@jakepetroules jakepetroules added the good first issue Good for newcomers label Jan 30, 2025
@jakepetroules jakepetroules changed the title LinkFileLists need to use quoting LinkFileList generation needs to use quoting Jan 30, 2025
@FareesHussain
Copy link

@jakepetroules can i pick this, can you guide me through the issue

@jakepetroules
Copy link
Collaborator Author

You're welcome to try fixing it!

To give you some pointers to get started, I'd begin by looking in LinkerTools.swift near the comment "ld64 reads lines from the file using fgets, without doing any other processing."

Apple's linker needs the arguments NOT quoted, while others (at least GNU, not sure about lld) need it quoted.

You can check the type of linker using code like this:

let optionContext = await discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate)
let linkerContext = (optionContext as? DiscoveredLdLinkerToolSpecInfo)
if linkerContext?.linker == .ld64 {
    ...

You might perform quoting using code like this:

UNIXShellCommandCodec(encodingStrategy: .singleQuotes, encodingBehavior: .argumentsOnly).encode(...)

though it's worth investigating how GNU ld actually interprets quoted arguments in file lists, and whether that's by parsing through the system shell, or something else. We should then apply the reverse transformation.

Finally, you'll want to run the test suite to see if any tests need adjustment, and if necessary, introduce at least one build operation test which includes spaces in the project path such that it will trigger a build failure without your change, and builds successfully after your change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants