<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/91381>91381</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            How to pass arguments to a linking pass?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kdsjZh
      </td>
    </tr>
</table>

<pre>
    ## 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!

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVtuO2zYQ_Rr6ZSBBIn1ZP_hhLzUSYJH0kiJpXwpaHEuMKVIhKTvu1xcjyreNiwJd7HpNcjhzZubMkWQIuraIKzZ7YrOXiexj4_xqp8LXP5vJxqnjinHBuIA9-qCdBbeFykhbs-KFFY_pc9iAcpEX-RwYf9h614LsIuPLa7PR0y89hqidvT56z_iihYPzO21rcBYkvH76CJ0MgfFnODS6aqCRe4ToYINgnFSoyPD108ccHq2C93CQNtI53QJnEaSv-xbTZmx0OPvMYQwL0WtUdN4HhNaYfXuJ13nca9cHcxyQBWDzIqWabU10kGVGZZ2MDRMvRuXGKMg-G8afs4zwZRQp60xfa8vES3scIgd3MjpFa4_S1yUTL9LXe2kgYoh5BZkbvrF5QYg2fYTYIFAQj53zEaQF9N55gjU6E4-QgNC33-3OuoOFyrWttAqMvi7J9-_f2bw4FSJ9fm5kvKojXQcdoHEHWtZ6jyAhwU0lRThnNZbNJIg6UDhqJhPrOxz42Wvn4UWHqg_hLRcgIEI8ONAh9Big1XUTqesejYyoTvXYSm0Ih1TKYwjQHuHbyK38xqEFxsVsXooFXSXYW2d2AUJf1xgi9IFYx-YFZF_GBlMDzyujN9Q3MqBCUr1PdtvbJifLsWeJRVQKJxVFoMgDOVXvaV25ttNGDsNwLl97hEoGSvZbrz2Gyy0iIWibeJCqCyHKGvM3FZ6LeTEljyFqY8acj2AxUT01ciRCgK3zP_q_gpZi3AAMFVrptbtg0-E8vdreoruU4pxSrfd0fDufOHL3bTbEl1-x8071FV6ffUoTkkZ74AqFUu5gh-5Rq1IaCMSbEOFx_cr4E-NPpFK1jk2_ySvXMr5-XL92pg_093a1JK9sXnz4-NeHP74w8VJCK3cIwfW-wsxZcxwbThFJRxI34ghP2iME3XYGofOu9rI9FXnrjHGHkQk0o0yc0p4X4--VwP4f1flNWh313-if3R69rJH08kcNykx0WTWaZAb3aIZEGySEzhuVFOmyvovzHXocMrv1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