<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">While slightly off topic of LLD improvement,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">volatile uint8_t __attribute__((address(0x1234))) foo;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">is slightly nicer than<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">(*(volatile uint8_t *)0x1234)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">because the latter ends up often being done in a header file as a macro, usually as something like:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">#define foo (*(volatile uint8_t *)0x1234)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The former behaves with all the language scoping rules, so a foo within a function or as a parameter has the expected<o:p></o:p></p>
<p class="MsoNormal">behavior.  The latter has all the downsides that macro usage can come with.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">On topic ā€“ Sean ā€“ I think that is a great document on linker scripts and their usage and meaning.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Kevin Smith<span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Sean Silva<br>
<b>Sent:</b> Wednesday, May 06, 2015 1:34 PM<br>
<b>To:</b> Will Newton<br>
<b>Cc:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> Re: [LLVMdev] LLD improvement plan<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, May 6, 2015 at 9:34 AM, Will Newton <<a href="mailto:will.newton@gmail.com" target="_blank">will.newton@gmail.com</a>> wrote:<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">On Wed, May 6, 2015 at 5:30 PM, Daniel Dilts <<a href="mailto:diltsman@gmail.com">diltsman@gmail.com</a>> wrote:<br>
><br>
><br>
> On Wed, May 6, 2015 at 12:51 AM, Will Newton <<a href="mailto:will.newton@gmail.com">will.newton@gmail.com</a>> wrote:<br>
>><br>
>> On Wed, May 6, 2015 at 6:22 AM, Chris Lattner <<a href="mailto:clattner@apple.com">clattner@apple.com</a>> wrote:<br>
>> > On May 5, 2015, at 6:47 PM, Daniel Dilts <<a href="mailto:diltsman@gmail.com">diltsman@gmail.com</a>> wrote:<br>
>> ><br>
>> > Take a look at how debuggers have migrated through the years.  They too<br>
>> >><br>
>> >> used to have their own script format.  Now most (all?) popular<br>
>> >> debuggers<br>
>> >> do scripting through embedding an actual programming language.  This<br>
>> >> could be a better way forward for linkers as well -- embed Python in<br>
>> >> the<br>
>> >> linker, define a Python API for linkable item placement, entry point,<br>
>> >> symbol operations, etc..., and then you also have the rest of Python at<br>
>> >> your fingertips.<br>
>> ><br>
>> ><br>
>> > I mostly care about specifying address where specific symbols will be<br>
>> > placed<br>
>> > and specifying the memory layout of the platform.   I normally use<br>
>> > __attribute__((section(""))) to place the symbols in their own sections<br>
>> > and<br>
>> > then use the linker script to place the sections at the required<br>
>> > addresses.<br>
>> > How would this be accomplished without linker scripts?<br>
>> ><br>
>> ><br>
>> > Iā€™d prefer to use an "__attribute__((address(0x1234)))ā€ myself.  That<br>
>> > way<br>
>> > you can control platform specifics with #ifdefs.<br>
>><br>
>> But that way you have to do layout by hand in C. Generally you won't<br>
>> know the size of the preceding code or data so you won't know what<br>
>> address to put things at at the granularity of a single C level<br>
>> object/function. Better to say "put this in the ROM section" and set<br>
>> the address of the ROM section once in a linker script and let the<br>
>> linker do the layout.<br>
><br>
><br>
> The real use case is on platforms, like ARM, where control registers are<br>
> mapped to a specific address range.  Then it is useful to put an object that<br>
> deals with the control registers at a specific address.<br>
> __attribute__((address(0x1234))) can be replaced with a platform specific<br>
> linker script.  Which is better?  I don't know, I haven't spent any time<br>
> comparing them.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">Why would you want to put an object at the address of some registers?<br>
You would just want a cast would you not?<br>
<br>
e.g. regs = (struct MyRegBlock *)0x1234<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This causes you to have to be constantly dereferencing, which can result in a huge amount of syntactic overhead. CMSIS does this really consistently and do a good job at it: <a href="http://www.keil.com/pack/doc/CMSIS/Core/html/group__peripheral__gr.html">http://www.keil.com/pack/doc/CMSIS/Core/html/group__peripheral__gr.html</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">But it's sort of an all-or-nothing thing to organize the peripheral headers like that, and many platforms don't (MSP430, AVR, smaller PIC's), instead preferring to have e.g. `volatile uint8_t Foo;` for each hardware register instead of
 putting things in structs.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- Sean Silva<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>