<html>
    <head>
      <base href="https://bugs.llvm.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 - [feature request] -fbuiltin-*"
   href="https://bugs.llvm.org/show_bug.cgi?id=47280">47280</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[feature request] -fbuiltin-*
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ndesaulniers@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, clement.courbet@gmail.com, david.bolvansky@gmail.com, dgregor@apple.com, efriedma@quicinc.com, erik.pilkington@gmail.com, hpa@zytor.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>From this thread on LKML:
<a href="https://lore.kernel.org/lkml/76071c24-ec6f-7f7a-4172-082bd574d581@zytor.com/">https://lore.kernel.org/lkml/76071c24-ec6f-7f7a-4172-082bd574d581@zytor.com/</a>

It was noted that for hosted environments that don't quite have a full libc
implementation, that they can lean on -fno-builtin-* flags in Clang to avoid
libcall optimizations where LLVM would emit calls to * which the environment
did not provide definitions of (though this differs from GCC's behavior, see
these three posts from Arvind that are a really fantastic analysis:
1. <a href="https://lore.kernel.org/lkml/20200818214146.GA3196105@rani.riverdale.lan/">https://lore.kernel.org/lkml/20200818214146.GA3196105@rani.riverdale.lan/</a>
2. <a href="https://lore.kernel.org/lkml/20200820175617.GA604994@rani.riverdale.lan/">https://lore.kernel.org/lkml/20200820175617.GA604994@rani.riverdale.lan/</a>
3. <a href="https://lore.kernel.org/lkml/20200821172935.GA1411923@rani.riverdale.lan/">https://lore.kernel.org/lkml/20200821172935.GA1411923@rani.riverdale.lan/</a>
).

Kernel developer H. Peter Anvin points out it would be helpful for embedded
environments that would use -ffreestanding to opt out of all such libcall
optimizations, to be able to opt back in (rather than opting out via
-fno-builtin-*) to certain libcall optimizations when the otherwise
freestanding implementation provided such symbols with matching semantics (ie.
the Linux kernel).

It was suggested that listing supported functions in the environment via
#pragma's (maybe in a header for codebase-wide inclusion) might be helpful.  In
particular, I think it would slot in nicely in Clang to provide -fbuiltin-*
support (there's rules in tablegen to generate support for -f-* and -fno-* from
one rule).  So `-ffreestanding -fbuiltin-strcpy` would be "disable all libcall
optimizations except related to transforming other libcalls into strcpy,
denoting the target supported no other builtins than strcpy (and the always
required mem* family).

It's not an immediate need, more so a curiosity that it's easy to opt out of
libcall optimizations, but not necessarily opt in.</pre>
        </div>
      </p>


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

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>