[llvm-dev] RFC - a proposal to support additional symbol metadata in ELF object files in the ARM compiler

Snider, Todd via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 30 08:17:14 PDT 2019


Hello All,

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).

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.

For example, in the following code:

#include <stdio.h>

extern int a;
int a __attribute__((location(0x1000))) = 4;

struct bstruct
{
    int f1;
    int f2;
};

struct bstruct b __attribute__((location(0x1004))) = {10, 12};
double c __attribute__((location(0x1010))) = 1.0;
char d[] __attribute__((location(0x2000)))  = {1, 2, 3, 4};
void foo(double x) __attribute((location(0x4000)));

void foo(double x) { printf("%f\n", x); }

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.

Without extending the ELF object format, how would this work?

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:

typedef struct {
       Elf32_Word     st_name;
       Elf32_Addr     st_value;
       Elf32_Word     st_size;
       unsigned char  st_info;
       unsigned char  st_other;
       Elf32_Half     st_shndx;
} Elf32_Sym;

typedef struct {
       Elf64_Word     st_name;
       unsigned char  st_info;
       unsigned char  st_other;
       Elf64_Half     st_shndx;
       Elf64_Addr     st_value;
       Elf64_Xword    st_size;
} Elf64_Sym;

The st_size and st_value fields could be used to represent attribute information about a given symbol:


  *   The st_size field can be split into an attribute ID and a symbol index for the symbol that the attribute applies to
     *   attribute ID: bits 0..7
     *   symbol index: bits 8..31
  *   The st_value field can contain the value associated with the attribute (i.e. the address argument of a location attribute)

If the compiler is generating assembly code, a new directive similar to the .eabi_attribute can be used:

        .symbol_attribute <symbol name>, <attribute kind>, <attribute value>

Where:

  *   symbol name - will unambiguously identify the symbol that the attribute/value pair applies to
  *   attribute kind - is an unsigned integer between 1 and 255 that specifies the kind of attribute to be applied to the symbol
     *   I propose a starting base set of 2 attribute IDs: used (1), location (2)
     *   the compiler will emit the integer constant that identifies the attribute kind
  *   attribute value - a value that is appropriate for the specified attribute kind

Thoughts? Comments? Concerns?

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.

~ Todd Snider

Code Generation Tools Group
Texas Instruments Incorporated


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190430/93f0b238/attachment-0001.html>


More information about the llvm-dev mailing list