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

    <tr>
        <th>Summary</th>
        <td>
            support passing `-shared` to the linker, even on targets without known dynamic linker
        </td>
    </tr>

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

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

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

<pre>
    For embedded targets it can still be useful to compile "plugins" and load them with a custom dynamic loader.
The GNU Toolchain allows this, by using the existing switches.

Clang only conditionally passes down the correct switches to the linker, atleast `-shared` and `-static-libgcc` are affected.

An [LLVM Arm toolchain](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm) is available for reproducing the test.

``` c
__attribute__((visibility("default")))
float my_add(float a, float b);

float my_add(float a, float b) {
    return a + b;
}
```

``` bash
/opt/arm-clang/bin/clang --target=arm-none-eabi -shared -fpic -static-libgcc testlib.c
```

This fails to produce an ELF file with dynamic section (DSO), the hints are that the arguments are dropped:

```
clang: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-static-libgcc' [-Wunused-command-line-argument]
ld.lld: warning: cannot find entry symbol _start; not setting start address
```

This works (but quite suboptimal, clang doesnt know it compiles a DSO):

``` bash
/opt/arm-clang/bin/clang --target=arm-none-eabi -fpic -Wl,-shared testlib.c
```

Please enable the common logic understood by buildsystems, either by default or some sort of `-enable-dso` opt-in switch.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVUGzGjcM_jXmollmMY8HHDjwQuklaTtt2hwZra1l3XjtrSU_yr_veBeSvjRN05nM7IAt258l69MnZHbnQLRTqye1OswwSxfTLkSP4UyzJtrr7hgTUN-QtWRBMJ1JGJyAwQAszntoCDJTmz1IBBP7wXkCpfXg89kFVloDBgs-ogXpqIeLkw4QTGaJPdhrwN6ZcZ3SXN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