How to pass argument through clang

Hi:
I’m studying the add an optional argument with cl::opt and encountered a problem. In LLVM source code, there is a lto pass in WholeProgramDevirt.cpp with a cl::opt like below, and i add some codes to verify it.

static cl::opt
PrintSummaryDevirt(“wholeprogramdevirt-print-index-based”, cl::Hidden,
cl::init(false), cl::ZeroOrMore,
cl::desc(“Print index-based devirtualization messages”));

#codes for verifying
errs() <<“run\n”;
if (PrintSummaryDevirt) {
errs() <<" get \n";
}
errs() << “end\n”;

Can pass “wholeprogramdevirt-print-index-based” to the pass through clang?
i use command line below and found that PrintSummaryDevirt was not set to true.

…/build/bin/clang -mllvm -wholeprogramdevirt-print-index-based -flto -O3 a.c b.c -o out

output:
run
end

But the ideal output would be as follows,which means PrintSummaryDevirt was set to true.

run
get
end

So can i solve it?

Thanks

For LTO, is isn’t just “passing an argument through clang” anymore, but passing it through the linker instead.

-Wl can be used to pass arguments to the linker, but then it depends which linker you’re using: each has their own flag to pass flags to LLVM for LTO.

1 Like

Thanks, So where can i get the corresponding command for each linker? such as gold and lld…

Using -Wl,-plugin-opt=-your-arg should work for both linkers.

It’s worked successfully. Thank you:)

1 Like