<div dir="ltr"><div>Adding this sort of information to a section feels like a more natural way to me than trying to use special symbols. A question that is probably worth thinking about is whether this new section would encode just the new location data you require or whether it should be extensible for other metadata. The latter approach has the advantage of reducing the number of symbol references required should we continue to add more data like this, but it leads to the need to handle varying amounts of data per symbol entry which is not so nice.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 30 Apr 2019 at 19:30, Peter Collingbourne via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Todd,<div><br></div><div>In your proposal, you're storing the symbol index in the st_size field in the symbol table. One of the main problems with this sort of approach is that tools such as objcopy will reorder the symbols in the symbol table, which will invalidate any stored indexes. This is one of the reasons why I designed address-significance tables (which contain symbol indexes) to try to detect cases where a tool such as objcopy has manipulated the object file.</div><div><br></div><div>An alternative approach would be to represent the symbol attribute as a section containing:</div><div>1) The attribute data.<br></div><div>2) A relocation pointing to the symbol with the attribute.</div><div>Objcopy et al already know how to rewrite relocation sections, so this works out quite well. This is the approach that I'm taking in <a href="https://reviews.llvm.org/D60242" target="_blank">https://reviews.llvm.org/D60242</a> to associate partition names with symbols.</div><div><br></div><div>Thanks,</div><div>Peter</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 30, 2019 at 11:12 AM Snider, Todd via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Peter,<br>
<br>
Thanks for the response.<br>
<br>
If we set aside the discussion of the relationship between sections and the application of the "location" or "at" attribute for a moment, do you have any objections to the proposed method of encoding metadata information about symbols (whether they are associated with actual data objects, functions, or sections) in the ELF object file? <br>
<br>
There are other use cases that would benefit from this encoding method besides the location attribute. The used attribute is an example. There are likely to be others.<br>
<br>
I would agree with you that applying a "location" or "at" attribute to a data object or function definition must require that the compiler generate the definition of the applicable data object or function into its own section, and that section may only contain the definition of that data object or function.<br>
<br>
One of the advantages of attaching the location attribute information to the symbol is that if the symbol is associated with a common data object, then the location attribute ends up being applied to the definition that the common symbol resolves to.<br>
<br>
~ Todd<br>
<br>
-----Original Message-----<br>
From: Peter Smith [mailto:<a href="mailto:peter.smith@linaro.org" target="_blank">peter.smith@linaro.org</a>] <br>
Sent: Tuesday, April 30, 2019 10:51 AM<br>
To: Snider, Todd<br>
Cc: llvm-dev<br>
Subject: [EXTERNAL] Re: [llvm-dev] RFC - a proposal to support additional symbol metadata in ELF object files in the ARM compiler<br>
<br>
On Tue, 30 Apr 2019 at 16:17, Snider, Todd via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
><br>
><br>
> Hello All,<br>
><br>
><br>
><br>
> In ARM embedded applications, there are some compilers that support useful function and variable attributes that help the compiler communicate information about symbols to downstream object consumers (i.e. linkers).<br>
><br>
><br>
><br>
> One such attribute is the “location” attribute. This attribute can be applied to a global or local static data object or a function to indicate to the linker that the definition of the data object or function should be placed at a specific address in memory.<br>
><br>
><br>
><br>
> For example, in the following code:<br>
><br>
><br>
><br>
> #include <stdio.h><br>
><br>
><br>
><br>
> extern int a;<br>
><br>
> int a __attribute__((location(0x1000))) = 4;<br>
><br>
><br>
><br>
> struct bstruct<br>
><br>
> {<br>
><br>
> int f1;<br>
><br>
> int f2;<br>
><br>
> };<br>
><br>
><br>
><br>
> struct bstruct b __attribute__((location(0x1004))) = {10, 12};<br>
><br>
> double c __attribute__((location(0x1010))) = 1.0;<br>
><br>
> char d[] __attribute__((location(0x2000))) = {1, 2, 3, 4};<br>
><br>
> void foo(double x) __attribute((location(0x4000)));<br>
><br>
><br>
><br>
> void foo(double x) { printf("%f\n", x); }<br>
><br>
><br>
><br>
> A location attribute has been applied to several data objects and the function “foo.” The compiler would then encode information into the compiled object file that tells the downstream linker about these memory placement constraints on the data objects and function.<br>
><br>
><br>
><br>
> Without extending the ELF object format, how would this work?<br>
><br>
><br>
><br>
> I propose to encode metadata information about a symbol in special absolute symbols, “__sym_attr_metadata.<int>”, that the linker can recognize when scanning the symbol table for an incoming object file. In an ELF symbol table entry:<br>
><br>
><br>
><br>
> typedef struct {<br>
><br>
> Elf32_Word st_name;<br>
><br>
> Elf32_Addr st_value;<br>
><br>
> Elf32_Word st_size;<br>
><br>
> unsigned char st_info;<br>
><br>
> unsigned char st_other;<br>
><br>
> Elf32_Half st_shndx;<br>
><br>
> } Elf32_Sym;<br>
><br>
><br>
><br>
> typedef struct {<br>
><br>
> Elf64_Word st_name;<br>
><br>
> unsigned char st_info;<br>
><br>
> unsigned char st_other;<br>
><br>
> Elf64_Half st_shndx;<br>
><br>
> Elf64_Addr st_value;<br>
><br>
> Elf64_Xword st_size;<br>
><br>
> } Elf64_Sym;<br>
><br>
><br>
><br>
> The st_size and st_value fields could be used to represent attribute information about a given symbol:<br>
><br>
><br>
><br>
> The st_size field can be split into an attribute ID and a symbol index for the symbol that the attribute applies to<br>
><br>
> attribute ID: bits 0..7<br>
> symbol index: bits 8..31<br>
><br>
> The st_value field can contain the value associated with the attribute (i.e. the address argument of a location attribute)<br>
><br>
><br>
><br>
> If the compiler is generating assembly code, a new directive similar to the .eabi_attribute can be used:<br>
><br>
><br>
><br>
> .symbol_attribute <symbol name>, <attribute kind>, <attribute value><br>
><br>
><br>
><br>
> Where:<br>
><br>
> symbol name - will unambiguously identify the symbol that the attribute/value pair applies to<br>
> attribute kind - is an unsigned integer between 1 and 255 that specifies the kind of attribute to be applied to the symbol<br>
><br>
> I propose a starting base set of 2 attribute IDs: used (1), location (2)<br>
> the compiler will emit the integer constant that identifies the attribute kind<br>
><br>
> attribute value - a value that is appropriate for the specified attribute kind<br>
><br>
><br>
><br>
> Thoughts? Comments? Concerns?<br>
><br>
<br>
Hello Todd,<br>
<br>
Thanks for bringing this up, I've got a few comments for you based on<br>
the implementation of a similar attribute in another Embedded Compiler<br>
(<a href="http://infocenter.arm.com/help/topic/com.arm.doc.dui0472m/chr1359124981140.html" rel="noreferrer" target="_blank">http://infocenter.arm.com/help/topic/com.arm.doc.dui0472m/chr1359124981140.html</a>).<br>
In that case it was __attribute__((at(address))) but the name is not<br>
that important.<br>
<br>
The communication with the linker in that case was via section name<br>
and not symbol, from memory at(<address>) translated to a section name<br>
of .ARM.__at_<address>. For us this had some advantages:<br>
- We could use __attribute__((section(".ARM.__at_<address>"))) when<br>
the compiler didn't support the attribute, it also needed no support<br>
in the assembler. This wasn't ideal as it is nice to be able to use<br>
expressions for the address, but it gets you most of the way there.<br>
- In practice you'd likely need a separate section for each variable<br>
to avoid problems at link time. For example if you had two variables<br>
with non-contiguous locations you'd most likely not want these in the<br>
same section so this mapped quite well to something similar to<br>
__attribute__((section(name))).<br>
- We did find some properties of __attribute__((section("name")))<br>
inconvenient, especially that variables would come out as SHT_PROGBITS<br>
when in many cases the user wanted SHT_NOBITS (memory mapped<br>
peripheral), we had our custom attribute fix that.<br>
<br>
If you used a section name rather than a symbol then you may not need<br>
any backend changes and it would generalise over all ELF targets.<br>
Linker support is another question entirely though.<br>
<br>
Peter<br>
<br>
><br>
><br>
> The anticipated next steps would be to add support for the location attribute and update the ARM/ELF LLVM back-end to support encoding the used attribute with the new mechanism.<br>
><br>
><br>
><br>
> ~ Todd Snider<br>
><br>
><br>
><br>
> Code Generation Tools Group<br>
><br>
> Texas Instruments Incorporated<br>
><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-7234014545821335332gmail-m_-992781649717570663gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>