This is an archive of the discontinued LLVM Phabricator instance.

[LinkerWrapper] Forward `-mllvm` options to the linker wrapper
ClosedPublic

Authored by jhuber6 on Jul 9 2022, 9:23 AM.

Details

Summary

This patch adds the ability to use -mllvm options in the linker
wrapper when performing bitcode linking or the module compilation.
This is done by passing in the LLVM argument to the clang-linker-wrapper
tool. Inside the linker-wrapper tool we invoke the CommandLine parser
solely for forwarding command line options to the clang-linker-wrapper
to the LLVM tools that also use the CommandLine parser. The actual
arguments to the linker wrapper are parsed using the Opt library
instead.

For example, in the following command the CommandLine parser will attempt to
parse abc, while the opt parser takes -mllvm <arg> and ignores it so it is
not passed to the linker arguments.

clang-linker-wrapper -mllvm -abc -- <linker-args>

As far as I can tell this is the easiest way to forward arguments to
LLVM tool invocations. If there is a better way to pass these arguments
(such as through the LTO config) let me know.

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 9 2022, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2022, 9:23 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
jhuber6 requested review of this revision.Jul 9 2022, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2022, 9:23 AM
MaskRay accepted this revision.Jul 9 2022, 3:17 PM

This patch adds the ability to use -mllvm options in the linker wrapper when performing bitcode linking or the module compilation. This is done by passing in the LLVM argument to the clang-linker-wrapper ...

The description can be simplified. "This patch adds the ability to " can be simplified as "Add ..." (imperative).

The actual arguments to the linker wrapper are parsed using the Opt library instead.

It is called LLVMOption. You can also refer to it as llvm/lib/Option.

As far as I can tell this is the easiest way to forward arguments to LLVM tool invocations. If there is a better way to pass these arguments (such as through the LTO config) let me know.

This is how Clang::ConstructJob handles -mllvm, too.

clang/lib/Driver/ToolChains/Clang.cpp
8466
8467

Add A->claim();

clang/test/Driver/openmp-offload.c
676

Just add the ending "

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
74

Just keep "-" and remove "--". clang doesn't support --mllvm. There is no need making users choose different spellings.

This revision is now accepted and ready to land.Jul 9 2022, 3:17 PM
jhuber6 updated this revision to Diff 443464.Jul 9 2022, 4:11 PM

Addressing comments

This revision was landed with ongoing or failed builds.Jul 9 2022, 6:18 PM
This revision was automatically updated to reflect the committed changes.