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

    <tr>
        <th>Summary</th>
        <td>
            [AMDGPU][LLD][Clang] Passing arguments via `-mllvm` to pass plugin causes unknown argument in lld
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    ### Description

I'm in the process of writing a pass plugin for instrumentation of applications compiled with LLVM. While checking for function names which need to be filtered, I tried to compile a bit of CUDA and HIP code. During this, I encountered an issue when trying to pass an argument to the pass plugin.

Right now, I'm passing arguments to the pass plugin via `-mllvm [arg]`. I found the suggestion [here](https://github.com/llvm/llvm-project/issues/56137#issuecomment-1549707162) and it worked fine for basic code.

As far as I've seen, this is the only way to process arguments outside of using `opt`, right? Using `opt` would be extremely inconvenient, especially for projects with a lot of source files and dependencies. 

### Error output
For this example, I'm using the [`Bye` example](https://github.com/llvm/llvm-project/blob/main/llvm/examples/Bye/Bye.cpp) in the LLVM repository. I've removed all of the legacy registration, which should not affect the functionality.

```console
$ clang++ -fPIC -shared Bye.cpp -o Bye.so 
$ cat min.c
int main(void){}
$ clang -x hip -fplugin=./Bye.so -O3 -fpass-plugin=./Bye.so -mllvm -wave-goodbye minimal.c 
lld: error: -plugin-opt=-: lld: Unknown command line argument '-wave-goodbye'.  Try: '/opt/software/software/LLVM/16.0.6/bin/lld --help'
lld: Did you mean '--code-model'?
clang-16: error: amdgcn-link command failed with exit code 1 (use -v to see invocation)
```

Looking at the output with `clang -v`, we can see that the argument is passed to `lld`
```console 
"/opt/software/software/LLVM/16.0.6/bin/lld" -flavor gnu -m elf64_amdgpu --no-undefined -shared -plugin-opt=-amdgpu-internalize-symbols -plugin-opt=mcpu=gfx906 -plugin-opt=-wave-goodbye -o /tmp/minimal-6ad3b7/minimal-gfx906.out /tmp/minimal-f23b1b/minimal-gfx906.o
```

Trying to compile the same tool with `-x cuda` works fine. 
```console
$ clang -fuse-ld=/opt/software/software/LLVM/16.0.6/bin/ld.lld -x cuda --cuda-gpu-arch=sm_75 -fplugin=./Bye.so -fpass-plugin=./Bye.so -mllvm -wave-goodbye minimal.c -O3
clang-16: warning: CUDA version is newer than the latest partially supported version 11.8 [-Wunknown-cuda-version]
Bye: main
```

The main question here is: Is there a way to avoid passing the parameter to `lld` when working with `clang -x hip` (or `hipcc` with ROCm)? 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVk9v4zoO_zTqhZDhyInTHHJom81ugT7M4GFm33GgyLStrSx5JTlp9tMvKLlp2pk3hwJBokgkJf744x8Zgu4s4pat7tlqdyOn2Du__dafPd4cXHPeMlHlD-wwKK_HqJ1l5Y6Vd_n7kYn1ANpC7BFG7xSGAK6Fk9dR2w4kjDIEGM3UaQut86BtiH4a0EZJxkhYjqPRKv0NoNwwaoMNnHTs4enp338U8FevDYLqUT2TUTLTTlYlfSsHDHDqterBIjYQHRwQWm0iemyYeIBHiF7nk9k6SDjoSHc_fN_dgbQN_OvxKyjXYAG7ydMtsdcha6NVbrLJHEgLOoQJ4dSjhejPSdRlN6UF6bvkHO0lTN7cL66B-1N3fQTrTumKhCKJJsxmE-EXNuCoJbC65IMxxwHY6l76jq12rC4LeITWTbZJOmHqOgwJIba679EjSYnbPsYxsOqOiT0T-07HfjoUyg1M7Mni_MNH7_6DKjKxT94GJvarelGtmajShnIDPZEvVsvNulwvasHEJuGoI5ycf8YGWm0xxeogg1YZ3GsI7gK00oMMyf8jQkC0BAchDzokP5w1ZzjJc8J45tcbQG6KQTdIgZwSdqwu3RhZXZIdTxizag_f35_ByU2mIZbgS_Q4oDmDtsrZI1qNNpIuhhGVlsackwszHiGzUoJxiT3BTV4lsmFI3jc4om3QKo2hgGtv31LpH947T08fp5jP9s5np_FFDqPBN05krwgIytG6vD8jOfAq97m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