Issue 91381
Summary How to pass arguments to a linking pass?
Labels new issue
Assignees
Reporter kdsjZh
    ## version of clang

clang 17.0.6 (from apt)

## Question

I'm working on a LTO pass, which have to be loaded on LTO. And I want to pass one argument to this LTO pass. 
I tried to use mllvm, which previously works `clang -flto --ld-path=ld.lld -Wl,--load-pass-plugin=mypass.so -Wl,-mllvm,myarg1=argval test.c -o test`, but the lld report an error `-mllvm: ld.lld: Unknown command line argument xxx`. 

What I want to know is how to give a myarg1 to the mypass.so, while lld is linking?

## Prior Discussion

I see two issues might be related, but fail to address my question.

In #56137, the folks suggest using ` -Xclang -load -Xclang lib.so ` and `-Xclang -fpass-plugin=lib.so`, which is loading the pass during compilation, while my case requires the pass work in the linking stage.

#63604, still, they need to give arguments for pass work in the compilation stage, while my scenario the pass is working in linking stage, which requires giving argument to the ld.lld.

## Reproduce

To test this issue, download and compile latest AFL++ (github.com/AFLplusplus/AFLplusplus), `NO_NYX=1 make source-only`, and use clang to test any simple program in the following command:
```
clang -flto --ld-path=ld.lld -Wl,--load-pass-plugin=SanitizerCoverageLTO.so -Wl,-mllvm,-lto-coverage-level=1 helloworld.c -o helloworld
```
Here the -lto-coverage-trace-pc is a `cl::opt` that can takes an interger as argument 
```c
static cl::opt<int> ClCoverageLevel(
 "lto-coverage-level",
    cl::desc("Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, "
             "3: all blocks and critical edges"),
    cl::Hidden, cl::init(3));
```
What I want is using clang to achieve something similar to 
```
opt -load-pass-plugin=./SanitizerCoverageLTO.so -lto-coverage-level=1 helloworld.o -o testhelloworld.o

```

Thanks!

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to