<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LLVM not properly shutdown in `si_pipe.c`?"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=109794">109794</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM not properly shutdown in `si_pipe.c`?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Mesa
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>git
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>x86-64 (AMD64)
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux (All)
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>minor
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Drivers/Gallium/radeonsi
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dri-devel@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zegentzy@protonmail.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>dri-devel@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>tl;dr; Shouldn't we be calling `LLVMShutdown()` somewhere?

I had a program which was calling: 
```
eglInitialize(disp, &majoir, &minor); 
eglTerminate(disp); 
eglInitialize(disp, &majoir, &minor);
```

Which lead to mesa outputting the following before continuing on normally
during the second call to `eglInitalize`:

```
mesa: for the -simplifycfg-sink-common option: may only occur zero or one
times!
mesa: for the -global-isel-abort option: may only occur zero or one times!
```

This prompted an investigation me to investigate, and with the aid of @imirkin,
I think I got the cause.

You see, in an `eglInitialize` call `radeonsi_dri.so` gets loaded, which also
loads in `libLLVM-9svn.so`, and eventually `ac_init_llvm_once()` gets called
more than once.

That's OK, for as the name implies, it only happens once.

Issue is, when `eglTerminate` is called, `radeonsi_dri.so` gets unloaded, but
not `libLLVM-9svn.so`. This means that the next time we all `eglInitialize`,
LLVM's `ManagedStatic`s will be preserved, but not our static var
`ac_init_llvm_target_once_flag`.

We can fix this by calling `LLVMShutdown` before unloading `radeonsi_dri.so`,
that way LLVM's `ManagedStatic`s are also reset.

Alas, I'm not familiar enough with the mesa codebase, so I got no clue where
the appropriate place to plop this function is. Any aid would be well
appreciated.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>