<h3>Contribution description</h3>
<p>This PR is working towards adding LLVM support for the AVR platform.</p>
<p><em><strong>WARNING:</strong></em> This is work in progress and not in a shape in which it makes sense to start a code review.</p>
<p>I needed to add some workarounds for features of the avrlibc that do not compile with clang. One big pain point is that clang verifies constraints of inline assembly before eliminating dead branches, while GCC does it the other way round. E.g. something like</p>
<div class="highlight highlight-source-c position-relative overflow-auto" data-snippet-clipboard-copy-content="static inline __attribute__((always_inline)) uint8_t get_foo(void)
{
    uint8_t dest;
    if (FOO < 64) {
         __asm__(
            "in r0,%[foo] \r\n"
            : [dest] "=r"(dest)
            : [foo] "I"(foo)
        );
    }
    else {
        dest = *_SFR_MEM_ADDR(FOO);
    }
    return dest;
}
"><pre><span class="pl-k">static</span> <span class="pl-k">inline</span> <span class="pl-en">__attribute__</span>((always_inline)) uint8_t get_foo(<span class="pl-k">void</span>)
{
    <span class="pl-c1">uint8_t</span> dest;
    <span class="pl-k">if</span> (FOO < <span class="pl-c1">64</span>) {
         <span class="pl-c1">__asm__</span>(
            <span class="pl-s"><span class="pl-pds">"</span>in r0,%[foo] <span class="pl-cce">\r\n</span><span class="pl-pds">"</span></span>
            : [dest] <span class="pl-s"><span class="pl-pds">"</span>=r<span class="pl-pds">"</span></span>(dest)
            : [foo] <span class="pl-s"><span class="pl-pds">"</span>I<span class="pl-pds">"</span></span>(foo)
        );
    }
    <span class="pl-k">else</span> {
        dest = *<span class="pl-c1">_SFR_MEM_ADDR</span>(FOO);
    }
    <span class="pl-k">return</span> dest;
}</pre></div>
<p>will fail to compile for <code>FOO >= 64</code> with LLVM, despite the inline assembly never being executed in that case. The header in <code><avr/wdt.h></code> uses this a lot, so I provided versions of <code>wdt_enable()</code> etc. inline - I'm not sure if those will work on al AT(X)mega MCUs supported by RIOT, though.</p>
<p>Another issue with LLVM is that commonly used helpers like <code>__tmp_reg__</code>, <code>__SREG__</code>, <code>__SP_L__</code>, <code>__SP_H__</code> are not available. For now, I replaced them with magic numbers / register names.</p>
<h3>Testing procedure</h3>
<p><code>$ make BOARD=atmega328p TOOLCHAIN=llvm -C examples/hello-world</code> compiles and links, but cannot be flashed.</p>
<h3>Issues/PRs references</h3>
<p>Depends on:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1011912862" data-permission-text="Title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/16919" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/16919/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/16919">#16919</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1012182692" data-permission-text="Title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/16920" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/16920/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/16920">#16920</a></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="983821163" data-permission-text="Title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/16790" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/16790/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/16790">#16790</a></li>
</ul>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/RIOT-OS/RIOT/pull/16924'>https://github.com/RIOT-OS/RIOT/pull/16924</a></p>

<h4>Commit Summary</h4>
<ul>
  <li><a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/e89930da5eb0267199aa0863eb3eec7a36c762e7">cpu/avr8_common: Fix link with binutils > 2.35.2</a></li>
  <li><a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/da20c3c01eb6aa060506e8019c45b5f138c003f2">cpu/{atxmega,atmega_common}: fix invalid use of PSTR()</a></li>
  <li><a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/e975f85e17a6864967ec5bd2809dc4d5ce2e8cdd">core/rmutex: use atomic utils</a></li>
  <li><a href="https://github.com/RIOT-OS/RIOT/pull/16924/commits/f2f2e74dcefa670c4c1e1beeade67f8b8d663991">cpu/avr8_common: Add support for LLVM</a></li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-7893849aaed5d734a2f821a03184730774e66c9236cf412f38bb695c7bc598b5">core/include/rmutex.h</a>
    (9)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-972d1a11fa0788f32d0ee9a5a25a8c18e0069dae6bfd79da859d0051b39b9f6f">core/rmutex.c</a>
    (15)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-13b32538125a87e3880991aaadde56d768818f2426d44095a0595d4adcbe9070">cpu/atmega1281/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-9e51bd2aed4bfe8888cc1497ba88fef9ff90887f131330a76c2aaac013f558dd">cpu/atmega1284p/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-2004b63c34f59fda9260a11b9e37dfd800f45bfc431ef63cb72241988493398a">cpu/atmega128rfa1/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-74519d17dbf0804c3777f468a670bbb4c6cbf5220463e443cd54e065fa0ea1ac">cpu/atmega2560/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-a4bb76293ecd1a2e3aa24428f548adbdeda48ebcad4292c5851ad07b693f60a0">cpu/atmega256rfr2/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-90a4d5b248c1ac42d0fe83428fabb1403fed00839226801759ceae1de804d03c">cpu/atmega328p/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-c16e8cda0e8934aa32917807c72c9144eee83d5d19a0c4fa795bc8765beed976">cpu/atmega32u4/Makefile.include</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-ee12b5ea5b44dd1aff2c80e57e863d442e8158874248b29f8160091f676f2e25">cpu/atmega_common/atmega_cpu.c</a>
    (6)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-9c70fb3bb139ff85d3bdce1e1a186c1e3b56db6490695639a7eb8bae0f341361">cpu/atmega_common/include/atmega_gpio.h</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-42068413f02f3857fcec044e2db14a9b3ba37bc485b11cc90497666fd345ea08">cpu/atmega_common/periph/gpio.c</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-6fdac2eafef46b55ff8ee3fe31ca07189530859c7fb6f902d78b61067090829b">cpu/atmega_common/periph/pm.c</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-83fdedb9b280def25dcc9c99ee67fd8aadfcf37c2f61a0881671ae956ae310eb">cpu/atmega_common/periph/rtt.c</a>
    (1)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-6a98b470845f5751ecb8f0c086fd5f272af93d38faeee956932f6b33403e8423">cpu/atmega_common/periph/timer.c</a>
    (1)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-455a56dd958628e3e2e5c40ee672dd8ebb0a63d422cffdfadb48e4b70a805144">cpu/atmega_common/periph/wdt.c</a>
    (1)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-5141509dbd25441f15fa002348bb97881fd40223296e9db31df96352c7accf56">cpu/atxmega/Makefile.include</a>
    (6)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-41678e504b2950038f66a2ed139591974d83414edb70c5624a1638b9b4b43ed4">cpu/atxmega/atxmega_cpu.c</a>
    (6)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-580d403123555b873c2298683ce3adbde4004052d1123c84cfbd500507214b65">cpu/atxmega/periph/gpio.c</a>
    (1)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-d2d0b1d1ec6b2cf50b805323beaef4500035b3eaccaa6b866a048aba65b2e4a4">cpu/atxmega/periph/timer.c</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-32923eee76d11b140cd221a5b3fed7975a2dc5a4c5974339aaea8f9dcfefe414">cpu/avr8_common/Makefile.include</a>
    (1)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-33967ec4993d90c37bdd84c6983b6151d688bca862dd36d43d7ed79dd939527b">cpu/avr8_common/avr8_cpu.c</a>
    (3)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-03e80935d526c994442073d8a1e07c5810f37ab1ed3b24ac06a31afd54ee032b">cpu/avr8_common/include/cpu.h</a>
    (101)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-da1835a52776b7930d4e1accba9e5c23827e931969594fd2fbdc80672434be27">cpu/avr8_common/include/irq_arch.h</a>
    (6)
  </li>
  <li>
    <strong>A</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-68eb4eefd4cae59ee4cccecef705a815f267f923521b15fa268598a1f0f907cd">cpu/avr8_common/ldscripts/avr51.ld</a>
    (27)
  </li>
  <li>
    <strong>A</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-92ba7e3b03f071882eabaf5bcabe9b6520b6fbdcfaa67cb5c57d9092e197de9b">cpu/avr8_common/ldscripts/avr6.ld</a>
    (27)
  </li>
  <li>
    <strong>A</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-531c87ed5c43b2920615fbc9266ada188ee1c047eceab9bb67e5d02a3824d311">cpu/avr8_common/ldscripts/avr_common.ld</a>
    (255)
  </li>
  <li>
    <strong>A</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-b20eb0432f57e048f3b4e5b8daba0158951ee78db451b9efa100fe09f1033b3f">cpu/avr8_common/ldscripts/avrxmega6.ld</a>
    (27)
  </li>
  <li>
    <strong>A</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-38eca43e55316e5da024248e969920c2c643eeb7aa90611b73f991f9fa12456f">cpu/avr8_common/ldscripts/avrxmega7.ld</a>
    (27)
  </li>
  <li>
    <strong>D</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-f25635115ab38eff909ea37d720ce060692e76a1ed16c2f67aa9806a06a3b76b">cpu/avr8_common/ldscripts/xfa.ld</a>
    (16)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-cf99ccb406b16d7fe838a8f6c5531a45b1e24b2f1de9c091c96fa40ca0993cce">cpu/avr8_common/startup.c</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-af91b417503b9b11409ba304dc64ac74a6d8ab851edd1166ee6568c4943f31f0">cpu/avr8_common/thread_arch.c</a>
    (206)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/16924/files#diff-64c8226b6596a1634cb932a6a70b17798163cd2dd8a4263536307dd0b56c943d">makefiles/arch/avr8.inc.mk</a>
    (10)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/16924.patch'>https://github.com/RIOT-OS/RIOT/pull/16924.patch</a></li>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/16924.diff'>https://github.com/RIOT-OS/RIOT/pull/16924.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/16924">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYAIPRZPFGNQJSV2RYTUER4EXANCNFSM5FCR6KDA">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<img src="https://github.com/notifications/beacon/ABE7WYFXMO6XAZGFL3L3MB3UER4EXA5CNFSM5FCR6KDKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4PCWM2GQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/16924",
"url": "https://github.com/RIOT-OS/RIOT/pull/16924",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>